1 package org.kuali.ole.service;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.ingest.pojo.OleLocationGroup;
5 import org.kuali.ole.ingest.pojo.OleLocationIngest;
6 import org.kuali.ole.describe.bo.OleLocation;
7 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
8 import org.kuali.rice.kew.api.exception.WorkflowException;
9 import org.kuali.rice.kim.api.identity.IdentityService;
10 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
11 import org.kuali.rice.krad.rules.rule.event.SaveDocumentEvent;
12 import org.kuali.rice.krad.service.BusinessObjectService;
13 import org.kuali.rice.krad.service.DocumentService;
14 import org.kuali.rice.krad.service.KRADServiceLocator;
15
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23
24
25
26 public class OleLocationServiceImpl implements OleLocationService {
27
28 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLocationServiceImpl.class);
29
30 private BusinessObjectService businessObjectService;
31 private IdentityService identityService;
32 private DocumentService documentService;
33 private OleLocationConverterService oleLocationConverterService;
34 private List<OleLocationIngest> createLocationList = new ArrayList<OleLocationIngest>();
35 private List<OleLocationIngest> updateLocationList = new ArrayList<OleLocationIngest>();
36
37
38
39
40
41 public BusinessObjectService getBusinessObjectService() {
42 if (null == businessObjectService) {
43 businessObjectService = KRADServiceLocator.getBusinessObjectService();
44 }
45 return businessObjectService;
46 }
47
48
49
50
51
52
53
54 protected static <T extends Object> T getService(String serviceName) {
55 return GlobalResourceLoader.<T>getService(serviceName);
56 }
57
58
59
60
61
62 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
63 this.businessObjectService = businessObjectService;
64 }
65
66
67
68
69
70 public IdentityService getIdentityService() {
71 return identityService;
72 }
73
74
75
76
77
78 public void setIdentityService(IdentityService identityService) {
79 this.identityService = identityService;
80 }
81
82
83
84
85
86 public DocumentService getDocumentService() {
87 return getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
88 }
89
90
91
92
93
94 public void setDocumentService(DocumentService documentService) {
95 this.documentService = documentService;
96 }
97
98
99
100
101
102
103 @Override
104 public OleLocation getLocation(String locationCode) {
105 LOG.debug("Inside the getLocation method");
106 Map<String,Object> criteria = new HashMap<String,Object>(4);
107 criteria.put(OLEConstants.PATRON_ENTITY_ACTIVE, Boolean.TRUE);
108 return businessObjectService.findByPrimaryKey(OleLocation.class, criteria);
109 }
110
111
112
113
114
115
116
117 private String saveLocationDocument(MaintenanceDocument locationDocument) throws WorkflowException {
118 getDocumentService().saveDocument(locationDocument, SaveDocumentEvent.class);
119 return locationDocument.getDocumentNumber();
120 }
121
122
123
124
125
126
127
128 private String routeLocationDocument(MaintenanceDocument locationDocument) throws WorkflowException{
129 getDocumentService().routeDocument(locationDocument, null, null);
130 return locationDocument.getDocumentNumber();
131 }
132
133
134
135
136
137
138 public boolean createLocation(OleLocation oleLocation) {
139 boolean doc = false;
140 OleLocation oleLocation1= getBusinessObjectService().save(oleLocation);
141 doc= true;
142 return doc;
143 }
144
145
146
147
148
149
150 public boolean updateLocation(OleLocation oleLocation) {
151 boolean doc = false;
152 OleLocation oleLocation1= getBusinessObjectService().save(oleLocation);
153 doc= true;
154 return doc;
155 }
156
157
158
159
160
161
162
163
164
165 private void processLocationDetails(String xmlContent) throws IOException, URISyntaxException {
166
167 OleLocationGroup oleLocationGroup =oleLocationConverterService.buildLocationFromFileContent(xmlContent);
168 List<OleLocation> existingLocationList = (List<OleLocation>) getBusinessObjectService().findAll(OleLocation.class);
169 String oleLocationCode ;
170 OleLocationIngest oleLocationIngest;
171
172 for(int i = 0;i<oleLocationGroup.getLocationGroup().size();i++){
173 oleLocationIngest = oleLocationGroup.getLocationGroup().get(i);
174 oleLocationCode = oleLocationIngest.getLocationCode();
175 for(int j=0;j<existingLocationList.size();j++){
176 if(oleLocationCode.equals(existingLocationList.get(j).getLocationCode())){
177 updateLocationList.add(oleLocationIngest);
178 }else if(!(oleLocationCode == null) || !(oleLocationCode.equals(""))){
179 createLocationList.add(oleLocationIngest);
180 }
181 }
182 }
183 }
184 }
185