1 package org.kuali.ole.service;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.batch.bo.OLEBatchProcessBibDataMappingNew;
7 import org.kuali.ole.batch.bo.OLEBatchProcessProfileBo;
8 import org.kuali.ole.batch.bo.OLEBatchProcessProfileDataMappingOptionsBo;
9 import org.kuali.ole.batch.ingest.OLEBatchGOKBImport;
10 import org.kuali.ole.batch.util.BatchBibImportUtil;
11 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
12 import org.kuali.ole.docstore.common.document.Bib;
13 import org.kuali.ole.docstore.common.document.EHoldings;
14 import org.kuali.ole.docstore.common.document.Holdings;
15 import org.kuali.ole.docstore.common.document.content.bib.marc.*;
16 import org.kuali.ole.docstore.common.document.content.instance.Coverage;
17 import org.kuali.ole.docstore.common.document.content.instance.Link;
18 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
19 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
20 import org.kuali.ole.docstore.common.search.SearchParams;
21 import org.kuali.ole.docstore.common.search.SearchResponse;
22 import org.kuali.ole.docstore.common.search.SearchResult;
23 import org.kuali.ole.docstore.common.search.SearchResultField;
24 import org.kuali.ole.select.OleSelectConstant;
25 import org.kuali.ole.select.bo.*;
26 import org.kuali.ole.select.businessobject.OleCopy;
27 import org.kuali.ole.select.document.*;
28 import org.kuali.ole.select.form.OLEEResourceRecordForm;
29 import org.kuali.ole.select.gokb.*;
30 import org.kuali.ole.select.gokb.service.GokbLocalService;
31 import org.kuali.ole.select.gokb.service.GokbRdbmsService;
32 import org.kuali.ole.select.gokb.service.impl.GokbLocalServiceImpl;
33 import org.kuali.ole.select.gokb.service.impl.GokbRdbmsServiceImpl;
34 import org.kuali.ole.select.gokb.util.OleGokbXmlUtil;
35 import org.kuali.ole.service.impl.OLEEResourceSearchServiceImpl;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.ole.vnd.businessobject.*;
38 import org.kuali.ole.vnd.document.service.impl.VendorServiceImpl;
39 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
40 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
41 import org.kuali.rice.coreservice.api.parameter.Parameter;
42 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
43 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
44 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
45 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
46 import org.kuali.rice.kew.api.exception.WorkflowException;
47 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
48 import org.kuali.rice.kew.service.KEWServiceLocator;
49 import org.kuali.rice.kim.api.permission.PermissionService;
50 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
51 import org.kuali.rice.krad.dao.DocumentDao;
52 import org.kuali.rice.krad.document.Document;
53 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
54 import org.kuali.rice.krad.maintenance.MaintenanceDocumentBase;
55 import org.kuali.rice.krad.maintenance.MaintenanceLock;
56 import org.kuali.rice.krad.rules.rule.event.SaveDocumentEvent;
57 import org.kuali.rice.krad.service.BusinessObjectService;
58 import org.kuali.rice.krad.service.DocumentService;
59 import org.kuali.rice.krad.service.KRADServiceLocator;
60 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
61 import org.kuali.rice.krad.util.GlobalVariables;
62
63 import java.sql.Timestamp;
64 import java.util.*;
65
66 import static org.kuali.ole.OLEConstants.*;
67
68
69
70
71 public class OLEEResourceHelperService {
72
73 private VendorServiceImpl vendorService = null;
74 private OLEEResourceSearchServiceImpl oleeResourceSearchService = new OLEEResourceSearchServiceImpl();
75 private HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
76 private DocstoreClientLocator docstoreClientLocator;
77 private static final Logger LOG = Logger.getLogger(OLEEResourceHelperService.class);
78 private BusinessObjectService businessObjectService;
79 private DocumentService documentService;
80 private DocumentDao documentDao;
81
82 private GokbRdbmsService gokbRdbmsService;
83 private GokbLocalService gokbLocalService;
84
85 public GokbRdbmsService getGokbRdbmsService() {
86 if (null == gokbRdbmsService) {
87 return new GokbRdbmsServiceImpl();
88 }
89 return gokbRdbmsService;
90 }
91
92 public GokbLocalService getGokbLocalService() {
93 if (null == gokbLocalService) {
94 return new GokbLocalServiceImpl();
95 }
96 return gokbLocalService;
97 }
98
99 public DocstoreClientLocator getDocstoreClientLocator() {
100 if (null == docstoreClientLocator) {
101 return SpringContext.getBean(DocstoreClientLocator.class);
102 }
103 return docstoreClientLocator;
104 }
105
106 public BusinessObjectService getBusinessObjectService() {
107 if (businessObjectService == null) {
108 businessObjectService = KRADServiceLocator.getBusinessObjectService();
109 }
110 return businessObjectService;
111 }
112
113
114 public VendorServiceImpl getVendorService() {
115 if (vendorService == null) {
116 vendorService = new VendorServiceImpl();
117 }
118
119 return vendorService;
120 }
121
122 public DocumentService getDocumentService() {
123 if (this.documentService == null) {
124 this.documentService = KRADServiceLocatorWeb.getDocumentService();
125 }
126 return this.documentService;
127 }
128
129 public DocumentDao getDocumentDao(){
130 if(documentDao == null){
131 documentDao = (DocumentDao) SpringContext.getBean("documentDao");
132 }
133 return documentDao;
134 }
135
136
137
138
139
140
141 public void updateVendorInfo(OLEEResourceRecordDocument oleeResourceRecordDocument) {
142
143 List<OLEEResourceContacts> oleeResourceContactses = new ArrayList<>();
144 Map<String, VendorDetail> vendorDetailMap = new HashMap<>();
145
146
147 addVendorDetail(vendorDetailMap, oleeResourceRecordDocument.getVendorId());
148
149
150 List<OLEEResourcePO> oleeResourceItemPOs = oleeResourceRecordDocument.geteRSPOItems();
151
152 addPOItemVendors(vendorDetailMap, oleeResourceItemPOs);
153
154
155 List<OLEEResourcePO> oleeResourcePOs = oleeResourceRecordDocument.getOleERSPOItems();
156
157 addPOItemVendors(vendorDetailMap, oleeResourcePOs);
158
159
160 List<OLEEResourceInvoices> oleERSInvoices = oleeResourceRecordDocument.getOleERSInvoices();
161
162 addInvoiceVendors(vendorDetailMap, oleERSInvoices);
163
164
165 List<OLELinkedEresource> oleLinkedEresources = oleeResourceRecordDocument.getOleLinkedEresources();
166
167 addChildEResources(vendorDetailMap, oleLinkedEresources);
168
169
170
171 Set<String> vendorNumbers = vendorDetailMap.keySet();
172
173 for (String vendorNumber : vendorNumbers) {
174
175 VendorDetail vendorDetail1 = vendorDetailMap.get(vendorNumber);
176
177 StringBuffer vendorNotes = new StringBuffer();
178
179 for (VendorContact vendorContact : vendorDetail1.getVendorContacts()) {
180 OLEEResourceContacts oleeResourceContacts = new OLEEResourceContacts();
181 List<OLEPhoneNumber> olePhoneNumberList = new ArrayList<>();
182 oleeResourceContacts.setOlePhoneNumbers(olePhoneNumberList);
183 if (StringUtils.isNotBlank(vendorContact.getVendorLine2Address())) {
184 oleeResourceContacts.setContact(vendorContact.getVendorLine1Address() + "-" + vendorContact.getVendorLine2Address());
185 } else {
186 oleeResourceContacts.setContact(vendorContact.getVendorLine1Address());
187 }
188 oleeResourceContacts.setEmail(vendorContact.getVendorContactEmailAddress());
189 oleeResourceContacts.setOrganization(vendorContact.getVendorDetail().getVendorName());
190
191
192 oleeResourceContacts.setVendorHeaderGeneratedIdentifier(vendorContact.getVendorHeaderGeneratedIdentifier());
193 oleeResourceContacts.setVendorDetailAssignedIdentifier(vendorContact.getVendorDetailAssignedIdentifier());
194
195 for (VendorContactPhoneNumber vendorContactPhoneNumber : vendorContact.getVendorContactPhoneNumbers()) {
196 OLEPhoneNumber olePhoneNumber = new OLEPhoneNumber();
197 olePhoneNumber.setPhoneNumber(vendorContactPhoneNumber.getVendorPhoneNumber());
198 olePhoneNumber.setPhoneNumberType(vendorContactPhoneNumber.getVendorPhoneType().getVendorPhoneTypeDescription());
199 olePhoneNumberList.add(olePhoneNumber);
200 }
201 if (oleeResourceContacts.getOlePhoneNumbers() != null && oleeResourceContacts.getOlePhoneNumbers().size() > 0) {
202 oleeResourceContacts.setPhone(oleeResourceContacts.getOlePhoneNumbers().get(0).getPhoneNumber());
203 }
204
205 if (oleeResourceContacts.getOlePhoneNumbers() != null && oleeResourceContacts.getOlePhoneNumbers().size() > 1) {
206 oleeResourceContacts.setHasMorePhoneNo(true);
207 }
208 oleeResourceContacts.setOleERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier());
209 if (vendorDetail1.isActiveIndicator()) {
210 oleeResourceContactses.add(oleeResourceContacts);
211 }
212
213 }
214
215 }
216 oleeResourceRecordDocument.setOleERSContacts(oleeResourceContactses);
217 }
218
219 private void addVendorDetail(Map<String, VendorDetail> vendorDetailMap, String vendorId) {
220 VendorDetail vendorDetail = getVendorService().getByVendorNumber(vendorId);
221
222 if (vendorDetail == null) {
223 return;
224 }
225 vendorDetailMap.put(vendorDetail.getVendorNumber(), vendorDetail);
226 }
227
228 private void addChildEResources(Map<String, VendorDetail> vendorDetailMap, List<OLELinkedEresource> oleLinkedEresources) {
229 for (OLELinkedEresource oleLinkedEresource : oleLinkedEresources) {
230 if (oleLinkedEresource.getRelationShipType() != null && oleLinkedEresource.getRelationShipType().equals("child")) {
231 addVendorDetail(vendorDetailMap, oleLinkedEresource.getOleeResourceRecordDocument().getVendorId());
232 }
233 }
234 }
235
236 private void addInvoiceVendors(Map<String, VendorDetail> vendorDetailMap, List<OLEEResourceInvoices> oleERSInvoices) {
237 if (oleERSInvoices != null) {
238 for (OLEEResourceInvoices oleeResourceInvoices : oleERSInvoices) {
239 Map map = new HashMap();
240 map.put(OLEConstants.PURAP_DOC_IDENTIFIER, oleeResourceInvoices.getInvoiceId());
241 List<OleInvoiceDocument> oleInvoiceDocuments = (List<OleInvoiceDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleInvoiceDocument.class, map);
242 if (oleInvoiceDocuments != null && oleInvoiceDocuments.size() > 0) {
243 Map fieldValues = new HashMap();
244 fieldValues.put(OleSelectConstant.VENDOR_HEADER_GENERATED_ID, oleInvoiceDocuments.get(0).getVendorId());
245 List<VendorDetail> vendorDetails = new ArrayList<>(KRADServiceLocator.getBusinessObjectService().findMatching(VendorDetail.class, fieldValues));
246 if (vendorDetails != null) {
247 for (VendorDetail vd : vendorDetails) {
248 vendorDetailMap.put(vd.getVendorNumber(), vd);
249 }
250 }
251 }
252 }
253 }
254 }
255
256 private void addPOItemVendors(Map<String, VendorDetail> vendorDetailMap, List<OLEEResourcePO> oleeResourcePOs) {
257 if (oleeResourcePOs != null) {
258 for (OLEEResourcePO oleeResourcePO : oleeResourcePOs) {
259 Map map = new HashMap();
260 map.put(OLEConstants.PURAP_DOC_IDENTIFIER, oleeResourcePO.getOlePOItemId());
261 List<OlePurchaseOrderDocument> olePurchaseOrderDocuments = (List<OlePurchaseOrderDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class, map);
262 if (olePurchaseOrderDocuments != null && olePurchaseOrderDocuments.size() > 0) {
263 Map fieldValues = new HashMap();
264 fieldValues.put(OleSelectConstant.VENDOR_HEADER_GENERATED_ID, olePurchaseOrderDocuments.get(0).getVendorHeaderGeneratedIdentifier());
265 List<VendorDetail> vendorDetails = new ArrayList<>(KRADServiceLocator.getBusinessObjectService().findMatching(VendorDetail.class, fieldValues));
266 if (vendorDetails != null) {
267 for (VendorDetail vd : vendorDetails) {
268 vendorDetailMap.put(vd.getVendorNumber(), vd);
269 }
270 }
271 }
272 }
273 }
274 }
275
276 public void updateEHoldingsInEResource(Holdings holdings) {
277
278 try {
279 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(holdings.getId());
280 } catch (Exception e) {
281 LOG.error(e);
282 }
283 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
284 String eResourceIdentifier = oleHoldings.getEResourceId();
285 if (StringUtils.isEmpty(eResourceIdentifier)) {
286 return;
287 }
288 OLEEResourceInstance oleeResourceInstance = new OLEEResourceInstance();
289 oleeResourceInstance.setInstanceTitle(holdings.getBib().getTitle());
290 oleeResourceInstance.setOleERSIdentifier(eResourceIdentifier);
291 oleeResourceSearchService.getHoldingsField(oleeResourceInstance, oleHoldings);
292 oleeResourceInstance.setInstancePublisher(oleHoldings.getPublisher());
293 if (oleHoldings.getPlatform() != null) {
294 oleeResourceInstance.setPlatformId(oleHoldings.getPlatform().getPlatformName());
295 }
296
297 StringBuffer urls = new StringBuffer();
298 for (Link link : oleHoldings.getLink()) {
299 urls.append(link.getUrl());
300 urls.append(",");
301 }
302 if (urls.toString().contains(",")) {
303 String url = urls.substring(0, urls.lastIndexOf(","));
304 oleeResourceInstance.setUrl(url);
305 }
306 if (oleHoldings.getGokbIdentifier() != null) {
307 oleeResourceInstance.setGokbId(oleHoldings.getGokbIdentifier());
308 }
309 if(StringUtils.isNotEmpty(holdings.getBib().getIsbn())){
310 oleeResourceInstance.setIsbn(holdings.getBib().getIsbn());
311 }else{
312 oleeResourceInstance.setIsbn(holdings.getBib().getIssn());
313 }
314
315 oleeResourceInstance.setStatus(oleHoldings.getAccessStatus());
316 oleeResourceInstance.setSubscriptionStatus(oleHoldings.getSubscriptionStatus());
317 oleeResourceInstance.setBibId(holdings.getBib().getId());
318 oleeResourceInstance.setInstanceId(holdings.getId());
319 oleeResourceInstance.setInstanceFlag("false");
320
321 KRADServiceLocator.getBusinessObjectService().save(oleeResourceInstance);
322
323 OleCopy oleCopy = new OleCopy();
324 oleCopy.setBibId(holdings.getBib().getId());
325 oleCopy.setOleERSIdentifier(eResourceIdentifier != null ? eResourceIdentifier : "");
326 oleCopy.setInstanceId(holdings.getId());
327
328 KRADServiceLocator.getBusinessObjectService().save(oleCopy);
329
330 this.insertOrUpdateGokbDataMapping(oleHoldings, false);
331
332 }
333
334
335 public void deleteEHoldingsInEResource(Holdings holdings) {
336 Map<String, String> criteriaMap = new HashMap<>();
337 if (StringUtils.isNotEmpty(holdings.getId())) {
338 criteriaMap.put(OLEConstants.INSTANCE_ID, holdings.getId());
339 getBusinessObjectService().deleteMatching(OLEEResourceInstance.class, criteriaMap);
340 }
341 }
342
343
344
345
346
347 public OLEBatchProcessProfileBo getGOKBImportProfile(String batchProcessProfileId) {
348 Map<String, String> bibImportProfileMap = new HashMap<>();
349 bibImportProfileMap.put("batchProcessProfileId", batchProcessProfileId);
350 List<OLEBatchProcessProfileBo> oleBatchProcessProfileBoList = (List<OLEBatchProcessProfileBo>) KRADServiceLocator.getBusinessObjectService().findMatching(OLEBatchProcessProfileBo.class, bibImportProfileMap);
351 if (oleBatchProcessProfileBoList != null && oleBatchProcessProfileBoList.size() > 0) {
352 return oleBatchProcessProfileBoList.get(0);
353 }
354 return null;
355 }
356
357
358
359
360 public List<OLEGOKbPackage> searchGokbForPackagess(List<OleGokbTipp> oleGokbTipps, OLEEResourceRecordForm oleEResourceRecordForm) {
361 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
362 List<OLEGOKbPackage> olegoKbPackages = new ArrayList<>();
363 OLEGOKbPackage olegoKbPackage;
364 Map<Integer,OLEGOKbPackage> packageMaps = new HashMap<>();
365 Map<Integer,Integer> platformMap = new HashMap<Integer,Integer>();
366 Map<Integer,Integer> packageTippMap = new HashMap<Integer,Integer>();
367 if(oleGokbTipps != null && oleGokbTipps.size() > 0 ){
368 for(OleGokbTipp oleGokbTipp : oleGokbTipps){
369 if(oleGokbTipp.getOleGokbPackage()!=null){
370 if(!packageMaps.containsKey(oleGokbTipp.getOleGokbPackage().getGokbPackageId())){
371 packageTippMap.put(oleGokbTipp.getOleGokbPackage().getGokbPackageId(),1);
372 olegoKbPackage = buildOLEGOKBPackage(oleGokbTipp.getOleGokbPackage());
373 olegoKbPackages.add(olegoKbPackage);
374 packageMaps.put(oleGokbTipp.getOleGokbPackage().getGokbPackageId(),olegoKbPackage);
375 if(oleGokbTipp.getOleGokbPlatform()!=null){
376 platformMap.put(oleGokbTipp.getOleGokbPackage().getGokbPackageId(), oleGokbTipp.getOleGokbPlatform().getGokbPlatformId());
377 }
378 }else{
379 packageTippMap.put(oleGokbTipp.getOleGokbPackage().getGokbPackageId(),packageTippMap.get(oleGokbTipp.getOleGokbPackage().getGokbPackageId())+1);
380 if(platformMap.containsKey(oleGokbTipp.getOleGokbPackage().getGokbPackageId())){
381 oleeResourceRecordDocument.setSinglePlatform(false);
382 packageMaps.get(oleGokbTipp.getOleGokbPackage().getGokbPackageId()).setMultiplePlatform(true);
383 }
384 }
385 }
386 }
387
388 }
389
390 for(int i=0;i<olegoKbPackages.size();i++){
391 olegoKbPackages.get(i).setTiips(packageTippMap.get(olegoKbPackages.get(i).getPackageId()));
392 }
393 return olegoKbPackages;
394 }
395
396
397 private OLEGOKbPackage buildOLEGOKBPackage(OleGokbPackage oleGokbPackage){
398 OLEGOKbPackage olegoKbPackage = new OLEGOKbPackage();
399 if(oleGokbPackage.getDateCreated()!=null)
400 olegoKbPackage.setDateCreated(oleGokbPackage.getDateCreated().toString());
401 if(oleGokbPackage.getDateUpdated()!=null)
402 olegoKbPackage.setDateEntered(oleGokbPackage.getDateUpdated().toString());
403 olegoKbPackage.setGokbStatus(oleGokbPackage.getStatus());
404
405
406 olegoKbPackage.setPackageId(oleGokbPackage.getGokbPackageId());
407 olegoKbPackage.setPackageName(oleGokbPackage.getPackageName());
408
409
410 olegoKbPackage.setMultiplePlatform(true);
411 olegoKbPackage.setTiips(0);
412 return olegoKbPackage;
413 }
414
415
416
417 public List<OLEGOKbPackage> searchGokbForPackages(List<OleGokbView> oleGokbViews, OLEEResourceRecordForm oleEResourceRecordForm) {
418 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
419 List<OLEGOKbPackage> olegoKbPackages = new ArrayList<>();
420 Map<Integer, OLEGOKbPackage> packageMap = new HashMap();
421 Set<Integer> platformIds = new HashSet<>();
422
423 for (OleGokbView oleGokbView : oleGokbViews) {
424 Integer packageId = oleGokbView.getPackageId();
425
426 if (packageMap.containsKey(packageId)) {
427 OLEGOKbPackage olegoKbPackage = packageMap.get(packageId);
428 olegoKbPackage.setTiips((olegoKbPackage.getTiips() + 1));
429
430 platformIds.add(oleGokbView.getPlatformId());
431
432 if (platformIds.size() > 1) {
433 olegoKbPackage.setMultiplePlatform(true);
434 }
435
436
437 } else {
438 OLEGOKbPackage olegoKbPackage = new OLEGOKbPackage();
439 Map map = new HashMap();
440 map.put("gokbPackageId", packageId);
441 OleGokbPackage oleGokbPackage = getBusinessObjectService().findByPrimaryKey(OleGokbPackage.class, map);
442 olegoKbPackage.setPackageId(packageId);
443 if(oleGokbPackage.getDateCreated() != null)
444 olegoKbPackage.setDateCreated(oleGokbPackage.getDateCreated().toString());
445 if(oleGokbPackage.getDateUpdated() != null)
446 olegoKbPackage.setDateEntered(oleGokbPackage.getDateUpdated().toString());
447 olegoKbPackage.setPackageName(oleGokbPackage.getPackageName());
448 olegoKbPackage.setPrimaryPlatformProvider(oleGokbView.getOrgName());
449 olegoKbPackage.setPrimaryPlatform(oleGokbView.getPlatformName());
450 olegoKbPackage.setTiips(1);
451 olegoKbPackage.setGokbStatus(oleGokbView.getPackageStatus());
452 olegoKbPackages.add(olegoKbPackage);
453 packageMap.put(packageId, olegoKbPackage);
454
455 platformIds.clear();
456
457 platformIds.add(oleGokbView.getPlatformId());
458 olegoKbPackage.setMultiplePlatform(false);
459 OLEGOKbPlatform olegoKbPlatform = new OLEGOKbPlatform();
460 olegoKbPlatform.setGoKbTIPPList(getExceptedOrCurrentTippsByPlatform(oleGokbView.getPlatformId(), oleGokbView.getTitle(), oleGokbView.getPublisherId()));
461 olegoKbPlatform.setPlatformName(oleGokbView.getPlatformName());
462 olegoKbPlatform.setPlatformId(oleGokbView.getPlatformId());
463 olegoKbPlatform.setPlatformProvider(oleGokbView.getOrgName());
464 olegoKbPlatform.setStatus(oleGokbView.getPlatformStatus());
465 olegoKbPlatform.setPlatformProviderId(oleGokbView.getOrgId());
466 olegoKbPlatform.setSoftwarePlatform(oleGokbView.getSoftwarePlatform());
467 List<OLEGOKbPlatform> olegoKbPlatforms = new ArrayList<>();
468 olegoKbPlatforms.add(olegoKbPlatform);
469
470 oleeResourceRecordDocument.setGoKbPlatformList(olegoKbPlatforms);
471
472 }
473 }
474
475 return olegoKbPackages;
476 }
477
478
479 public List<OLEGOKbTIPP> getExceptedOrCurrentTippsByPlatform(Integer platformId, String title, Integer publisherId) {
480 List<OLEGOKbTIPP> olegoKbTIPPs = new ArrayList<>();
481
482 Map map = new HashMap();
483 map.put("gokbPlatformId", platformId);
484
485 List<OleGokbTipp> oleGokbTipps = (List<OleGokbTipp>) getBusinessObjectService().findMatching(OleGokbTipp.class, map);
486
487 for (OleGokbTipp oleGokbTipp : oleGokbTipps) {
488 if (StringUtils.isNotEmpty(oleGokbTipp.getStatus()) && (oleGokbTipp.getStatus().equals("Current") || oleGokbTipp.getStatus().equals("Excepted"))) {
489 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP();
490 olegoKbTIPP.setTitle(title);
491 boolean isTippExists = verifyTippExistsInOle(oleGokbTipp.getGokbTippId());
492 olegoKbTIPP.setTippExists(isTippExists);
493 olegoKbTIPP.setPublisherId(publisherId);
494 if(oleGokbTipp.getDateCreated()!=null)
495 olegoKbTIPP.setDateCreated(oleGokbTipp.getDateCreated().toString());
496 if(oleGokbTipp.getDateUpdated() != null)
497 olegoKbTIPP.setDateUpdated(oleGokbTipp.getDateUpdated().toString());
498 olegoKbTIPP.setGokbStatus(oleGokbTipp.getStatus());
499 olegoKbTIPP.setUrl(oleGokbTipp.getPlatformHostUrl());
500 if (oleGokbTipp.getEndDate() != null) {
501 olegoKbTIPP.setEndDate(oleGokbTipp.getEndDate().toString());
502 }
503 if(olegoKbTIPP.getStartDate()!=null)
504 olegoKbTIPP.setStartDate(oleGokbTipp.getStartdate().toString());
505 olegoKbTIPP.setOleGokbTipp(oleGokbTipp);
506 olegoKbTIPPs.add(olegoKbTIPP);
507 }
508 }
509
510 return olegoKbTIPPs;
511
512 }
513
514 public List<OLEGOKbTIPP> getAllTippsByPlatform(Integer platformId, String title, Integer publisherId) {
515 List<OLEGOKbTIPP> olegoKbTIPPs = new ArrayList<>();
516
517 Map map = new HashMap();
518 map.put("gokbPlatformId", platformId);
519
520 List<OleGokbTipp> oleGokbTipps = (List<OleGokbTipp>) getBusinessObjectService().findMatching(OleGokbTipp.class, map);
521
522 for (OleGokbTipp oleGokbTipp : oleGokbTipps) {
523 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP();
524 olegoKbTIPP.setTitle(title);
525 boolean isTippExists = verifyTippExistsInOle(oleGokbTipp.getGokbTippId());
526 olegoKbTIPP.setTippExists(isTippExists);
527 olegoKbTIPP.setPublisherId(publisherId);
528 olegoKbTIPP.setDateCreated(oleGokbTipp.getDateCreated().toString());
529 olegoKbTIPP.setDateUpdated(oleGokbTipp.getDateUpdated().toString());
530 olegoKbTIPP.setGokbStatus(oleGokbTipp.getStatus());
531 olegoKbTIPP.setUrl(oleGokbTipp.getPlatformHostUrl());
532 olegoKbTIPP.setEndDate(oleGokbTipp.getEndDate().toString());
533 olegoKbTIPP.setStartDate(oleGokbTipp.getStartdate().toString());
534 olegoKbTIPP.setOleGokbTipp(oleGokbTipp);
535
536
537 olegoKbTIPPs.add(olegoKbTIPP);
538 }
539
540 return olegoKbTIPPs;
541
542 }
543
544 public List<OLEGOKbTIPP> getTippsByPlatform(Integer platformId) {
545 List<OLEGOKbTIPP> olegoKbTIPPs = new ArrayList<>();
546
547 Map map = new HashMap();
548 map.put("gokbPlatformId", platformId);
549
550 List<OleGokbTipp> oleGokbTipps = (List<OleGokbTipp>) getBusinessObjectService().findMatching(OleGokbTipp.class, map);
551
552 for (OleGokbTipp gokbTipp : oleGokbTipps) {
553 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP();
554
555 map.clear();
556 map.put("gokbTitleId", gokbTipp.getGokbTitleId());
557
558 OleGokbTitle oleGokbTitle = getBusinessObjectService().findByPrimaryKey(OleGokbTitle.class, map);
559 boolean isTippExists = verifyTippExistsInOle(gokbTipp.getGokbTippId());
560 olegoKbTIPP.setTippExists(isTippExists);
561 if(oleGokbTitle!=null){
562 olegoKbTIPP.setTitle(oleGokbTitle.getTitleName());
563 olegoKbTIPP.setPublisherId(oleGokbTitle.getPublisherId());
564 }
565 if(gokbTipp.getDateCreated()!=null)
566 olegoKbTIPP.setDateCreated(gokbTipp.getDateCreated().toString());
567 if(gokbTipp.getDateUpdated()!=null)
568 olegoKbTIPP.setDateUpdated(gokbTipp.getDateUpdated().toString());
569 olegoKbTIPP.setGokbStatus(gokbTipp.getStatus());
570 olegoKbTIPP.setUrl(gokbTipp.getPlatformHostUrl());
571 if(gokbTipp.getEndDate()!=null)
572 olegoKbTIPP.setEndDate(gokbTipp.getEndDate().toString());
573 if(gokbTipp.getStartdate()!=null)
574 olegoKbTIPP.setStartDate(gokbTipp.getStartdate().toString());
575 olegoKbTIPP.setOleGokbTipp(gokbTipp);
576
577 olegoKbTIPPs.add(olegoKbTIPP);
578 }
579
580 return olegoKbTIPPs;
581
582 }
583
584
585 public List<OLEGOKbTIPP> buildOLEGOKBTIPP(List<OleGokbTipp> oleGokbTippList) {
586 List<OLEGOKbTIPP> olegoKbTIPPs = new ArrayList<>();
587 OLEGOKbTIPP olegoKbTIPP;
588 for (OleGokbTipp gokbTipp : oleGokbTippList) {
589 olegoKbTIPP = new OLEGOKbTIPP();
590 boolean isTippExists = verifyTippExistsInOle(gokbTipp.getGokbTippId());
591
592 if (!isTippExists) {
593 olegoKbTIPP.setTippExists(isTippExists);
594
595 if (gokbTipp.getOleGokbTitle() != null) {
596 olegoKbTIPP.setTitle(gokbTipp.getOleGokbTitle().getTitleName());
597 olegoKbTIPP.setPublisherId(gokbTipp.getOleGokbTitle().getPublisherId());
598 if (StringUtils.isNotEmpty(gokbTipp.getOleGokbTitle().getIssnOnline())) {
599 olegoKbTIPP.setIssn(gokbTipp.getOleGokbTitle().getIssnOnline());
600 } else {
601 olegoKbTIPP.setIssn(gokbTipp.getOleGokbTitle().getIssnPrint());
602 }
603 if(StringUtils.isNotEmpty(gokbTipp.getOleGokbTitle().getMedium())){
604 olegoKbTIPP.setType(gokbTipp.getOleGokbTitle().getMedium());
605 }
606 }
607
608 if (gokbTipp.getDateCreated() != null)
609 olegoKbTIPP.setDateCreated(gokbTipp.getDateCreated().toString());
610 if (gokbTipp.getDateUpdated() != null)
611 olegoKbTIPP.setDateUpdated(gokbTipp.getDateUpdated().toString());
612 olegoKbTIPP.setGokbStatus(gokbTipp.getStatus());
613 olegoKbTIPP.setUrl(gokbTipp.getPlatformHostUrl());
614 if (gokbTipp.getEndDate() != null)
615 olegoKbTIPP.setEndDate(gokbTipp.getEndDate().toString());
616 if (gokbTipp.getStartdate() != null)
617 olegoKbTIPP.setStartDate(gokbTipp.getStartdate().toString());
618 olegoKbTIPP.setOleGokbTipp(gokbTipp);
619 olegoKbTIPPs.add(olegoKbTIPP);
620 }
621
622 }
623
624
625 return olegoKbTIPPs;
626 }
627
628
629 private boolean verifyTippExistsInOle(Integer gokbTippId) {
630 Map map = new HashMap();
631 map.put("gokbId", gokbTippId);
632 List<OLEEResourceInstance> oleeResourceInstances = (List<OLEEResourceInstance>) getBusinessObjectService().findMatching(OLEEResourceInstance.class, map);
633 if (oleeResourceInstances != null && oleeResourceInstances.size() > 0) {
634 return true;
635 }
636 return false;
637 }
638
639 public List<OLEGOKbPlatform> getPlatformByPlackage(String packageId) {
640 List<OLEGOKbPlatform> olegoKbPlatforms = new ArrayList<>();
641
642 Map map = new HashMap();
643 map.put("gokbPackageId", packageId);
644
645 Map<Integer, OLEGOKbPlatform> platformMap = new HashMap();
646
647 List<OleGokbTipp> oleGokbTipps = (List<OleGokbTipp>) getBusinessObjectService().findMatching(OleGokbTipp.class, map);
648
649 for (OleGokbTipp oleGokbTipp : oleGokbTipps) {
650 Integer platformId = oleGokbTipp.getGokbPlatformId();
651 if (platformMap.containsKey(platformId)) {
652
653 OLEGOKbPlatform olegoKbPlatform = platformMap.get(platformId);
654 olegoKbPlatform.setNoOfTiips((olegoKbPlatform.getNoOfTiips() + 1));
655 } else {
656
657 map = new HashMap();
658 map.put("gokbPlatformId", platformId);
659 OleGokbPlatform gokbPlatform = getBusinessObjectService().findByPrimaryKey(OleGokbPlatform.class, map);
660
661 OLEGOKbPlatform olegoKbPlatform = new OLEGOKbPlatform();
662 olegoKbPlatform.setPlatformName(gokbPlatform.getPlatformName());
663 map.clear();
664 map.put("gokbOrganizationId", gokbPlatform.getPlatformProviderId());
665 OleGokbOrganization oleGokbOrganization = getBusinessObjectService().findByPrimaryKey(OleGokbOrganization.class, map);
666 if(oleGokbOrganization!=null){
667 olegoKbPlatform.setPlatformProvider(oleGokbOrganization.getOrganizationName());
668 }
669 olegoKbPlatform.setPlatformProviderId(gokbPlatform.getPlatformProviderId());
670 olegoKbPlatform.setSoftwarePlatform(gokbPlatform.getSoftwarePlatform());
671 olegoKbPlatform.setNoOfTiips(1);
672 olegoKbPlatform.setPlatformId(platformId);
673 olegoKbPlatform.setStatus(gokbPlatform.getStatus());
674 olegoKbPlatform.setPackageId(Integer.parseInt(packageId));
675 olegoKbPlatforms.add(olegoKbPlatform);
676 platformMap.put(platformId, olegoKbPlatform);
677 }
678 }
679 return olegoKbPlatforms;
680 }
681
682
683 public List<BibMarcRecord> buildBibMarcRecords(List<OLEGOKbPlatform> olegoKbPlatforms, String eResourceId, OLEBatchProcessProfileBo oleBatchProcessProfile) {
684
685 List<BibMarcRecord> bibMarcRecords = new ArrayList<>();
686
687 Map<Integer, BibMarcRecord> bibMarcRecordMap = new HashMap<>();
688
689 for (OLEGOKbPlatform olegoKbPlatform : olegoKbPlatforms) {
690 String platformName = olegoKbPlatform.getPlatformName();
691
692 String imprint = "";
693 String publisher = "";
694 List<OLEGOKbTIPP> olegoKbTIPPList = new ArrayList<>();
695 List<OLEGOKbTIPP> slecetdOlegoKbTIPPList = new ArrayList<>();
696 for (OLEGOKbTIPP olegoKbTIPP : olegoKbPlatform.getGoKbTIPPList()) {
697
698 if (olegoKbTIPP.isSelect() && olegoKbTIPP.getOleGokbTipp() != null) {
699
700 Integer titleId = olegoKbTIPP.getOleGokbTipp().getGokbTitleId();
701
702 if (bibMarcRecordMap.containsKey(olegoKbTIPP.getOleGokbTipp().getGokbTitleId())) {
703 BibMarcRecord bibMarcRecord = bibMarcRecordMap.get(titleId);
704 DataField dataField = addEHoldingsFields(olegoKbTIPP, platformName, eResourceId, imprint, publisher,oleBatchProcessProfile.getOleBatchProcessProfileMappingOptionsList().get(0).getOleBatchProcessProfileDataMappingOptionsBoList());
705 bibMarcRecord.getDataFields().add(dataField);
706 } else {
707 OleGokbTitle oleGokbTitle = getOleGokbTitle(titleId);
708 if(oleGokbTitle !=null){
709 BibMarcRecord bibMarcRecord = buildBibMarcRecord(oleGokbTitle,oleBatchProcessProfile.getOleBatchProcessBibDataMappingNewList());
710 bibMarcRecords.add(bibMarcRecord);
711 imprint = oleGokbTitle.getImprint();
712 publisher = String.valueOf(oleGokbTitle.getPublisherId());
713
714 DataField dataField = addEHoldingsFields(olegoKbTIPP, platformName, eResourceId, imprint, publisher,oleBatchProcessProfile.getOleBatchProcessProfileMappingOptionsList().get(0).getOleBatchProcessProfileDataMappingOptionsBoList());
715 bibMarcRecord.getDataFields().add(dataField);
716 bibMarcRecordMap.put(titleId, bibMarcRecord);
717 }
718 }
719 slecetdOlegoKbTIPPList.add(olegoKbTIPP);
720 }else{
721 olegoKbTIPPList.add(olegoKbTIPP);
722 }
723
724 }
725 olegoKbPlatform.setSelectedGokbTippList(slecetdOlegoKbTIPPList);
726 olegoKbPlatform.setGoKbTIPPList(olegoKbTIPPList);
727 }
728 return bibMarcRecords;
729 }
730
731 private DataField addEHoldingsFields(OLEGOKbTIPP olegoKbTIPP, String platformName, String eResourceId, String imprint, String publisher, List<OLEBatchProcessProfileDataMappingOptionsBo> oleBatchProcessProfileDataMappingOptionsBoList) {
732
733 OleGokbTipp goKbTIPP = olegoKbTIPP.getOleGokbTipp();
734 DataField dataField = getDataFieldForTipp(platformName, eResourceId, goKbTIPP, imprint, publisher, oleBatchProcessProfileDataMappingOptionsBoList);
735 return dataField;
736
737 }
738
739 public DataField getDataFieldForTipp(String platformName, String eResourceId, OleGokbTipp goKbTIPP, String imprint, String publisher, List<OLEBatchProcessProfileDataMappingOptionsBo> oleBatchProcessProfileDataMappingOptionsBoList) {
740 DataField dataField = new DataField();
741 String docField = null;
742 if (oleBatchProcessProfileDataMappingOptionsBoList.size() > 0) {
743 for (OLEBatchProcessProfileDataMappingOptionsBo oleBatchProcessProfileDataMappingOptionsBo : oleBatchProcessProfileDataMappingOptionsBoList){
744 docField = oleBatchProcessProfileDataMappingOptionsBo.getDestinationField();
745 if (EHoldings.DESTINATION_FIELD_LINK_URL.equalsIgnoreCase(docField)) {
746 dataField.setTag(oleBatchProcessProfileDataMappingOptionsBo.getSourceField().substring(0, 3));
747 break;
748 }
749 }
750 } else {
751 dataField.setTag(OLEConstants.OLEBatchProcess.CONSTANT_DATAMAPPING_FOR_EHOLDINGS);
752 }
753 DataField tempDataField = null;
754 List<SubField> subFields = new ArrayList<>();
755
756 for (OLEBatchProcessProfileDataMappingOptionsBo oleBatchProcessProfileDataMappingOptionsBo : oleBatchProcessProfileDataMappingOptionsBoList) {
757 tempDataField = BatchBibImportUtil.getDataField(oleBatchProcessProfileDataMappingOptionsBo.getSourceField());
758 docField = oleBatchProcessProfileDataMappingOptionsBo.getDestinationField();
759 for (SubField subField : tempDataField.getSubFields()) {
760 if (EHoldings.DESTINATION_FIELD_LINK_URL.equalsIgnoreCase(docField)) {
761 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getPlatformHostUrl()));
762 } else if (EHoldings.DESTINATION_FIELD_IMPRINT.equalsIgnoreCase(docField)) {
763 if (StringUtils.isNotBlank(imprint)) {
764 subFields.add(buildSubField(subField.getCode(), imprint));
765 }
766 } else if (EHoldings.DESTINATION_FIELD_ERESOURCE_ID.equalsIgnoreCase(docField)) {
767 if (StringUtils.isNotEmpty(eResourceId)) {
768 subFields.add(buildSubField(subField.getCode(), eResourceId));
769 }
770 } else if (EHoldings.DESTINATION_FIELD_PLATFORM.equalsIgnoreCase(docField)) {
771 if (StringUtils.isNotEmpty(platformName)) {
772 subFields.add(buildSubField(subField.getCode(), platformName));
773 }
774 } else if (EHoldings.DESTINATION_FIELD_GOKB_ID.equalsIgnoreCase(docField)) {
775 if (goKbTIPP.getGokbTippId() != null) {
776 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getGokbTippId().toString()));
777 }
778 } else if (EHoldings.DESTINATION_FIELD_COVERAGE_END_DATE.equalsIgnoreCase(docField)) {
779 if (goKbTIPP.getEndDate() != null) {
780 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getEndDate().toString()));
781 }
782 } else if (EHoldings.DESTINATION_FIELD_COVERAGE_END_ISSUE.equalsIgnoreCase(docField)) {
783 if (goKbTIPP.getEndIssue() != null) {
784 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getEndIssue().toString()));
785 }
786 } else if (EHoldings.DESTINATION_FIELD_COVERAGE_END_VOLUME.equalsIgnoreCase(docField)) {
787 if (goKbTIPP.getEndVolume() != null) {
788 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getEndVolume().toString()));
789 }
790 } else if (EHoldings.DESTINATION_FIELD_COVERAGE_START_DATE.equalsIgnoreCase(docField)) {
791 if (goKbTIPP.getStartdate() != null) {
792 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getStartdate().toString()));
793 }
794 } else if (EHoldings.DESTINATION_FIELD_COVERAGE_END_ISSUE.equalsIgnoreCase(docField)) {
795 if (goKbTIPP.getStartIssue() != null) {
796 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getStartIssue().toString()));
797 }
798 } else if (EHoldings.DESTINATION_FIELD_COVERAGE_START_VOLUME.equalsIgnoreCase(docField)) {
799 if (goKbTIPP.getStartVolume() != null) {
800 subFields.add(buildSubField(subField.getCode(), goKbTIPP.getStartVolume().toString()));
801 }
802 } else if (EHoldings.DESTINATION_FIELD_PUBLISHER.equalsIgnoreCase(docField)) {
803 if (publisher != null) {
804 subFields.add(buildSubField(subField.getCode(), publisher));
805 }
806 }
807 }
808 }
809 dataField.setSubFields(subFields);
810 return dataField;
811 }
812
813 private SubField buildSubField(String code, String value) {
814 SubField subField = new SubField();
815 subField.setCode(code);
816 subField.setValue(value);
817 return subField;
818 }
819
820 private BibMarcRecord buildBibMarcRecord(OleGokbTitle oleGokbTitle, List<OLEBatchProcessBibDataMappingNew> oleBatchProcessBibDataMappingNewList) {
821
822 BibMarcRecord bibMarcRecord = buildBibMarcRecordFromTitle(oleGokbTitle, oleBatchProcessBibDataMappingNewList);
823
824 return bibMarcRecord;
825 }
826
827 public BibMarcRecord buildBibMarcRecordFromTitle(OleGokbTitle oleGokbTitle, List<OLEBatchProcessBibDataMappingNew> oleBatchProcessBibDataMappingNewList) {
828 BibMarcRecord bibMarcRecord = new BibMarcRecord();
829 bibMarcRecord.setLeader("#####nam#a22######a#4500");
830
831 for (OLEBatchProcessBibDataMappingNew oleBatchProcessBibDataMappingNew : oleBatchProcessBibDataMappingNewList) {
832 String tag = oleBatchProcessBibDataMappingNew.getTag();
833 String gokbFiled = oleBatchProcessBibDataMappingNew.getGokbFieldBib();
834
835 if (gokbFiled.equalsIgnoreCase("TI Publisher ID") && oleGokbTitle.getPublisherId() > 0) {
836 bibMarcRecord.getDataFields().add(buildDataField(tag, "(PublisherID)" + oleGokbTitle.getPublisherId()));
837 } else if (gokbFiled.equalsIgnoreCase("variantName") && StringUtils.isNotEmpty(oleGokbTitle.getVariantName())) {
838 bibMarcRecord.getDataFields().add(buildDataField(tag, oleGokbTitle.getVariantName()));
839 } else if (gokbFiled.equalsIgnoreCase("name") && StringUtils.isNotEmpty(oleGokbTitle.getTitleName())) {
840 bibMarcRecord.getDataFields().add(buildDataField(tag, oleGokbTitle.getTitleName()));
841 } else if (gokbFiled.equalsIgnoreCase("GOKb UID") && oleGokbTitle.getGokbTitleId() > 0) {
842 bibMarcRecord.getDataFields().add(buildDataField(tag, "(" + OLEConstants.GOKBID + ")" + oleGokbTitle.getGokbTitleId()));
843 } else if (gokbFiled.equalsIgnoreCase("TI ISSN (Online)") && StringUtils.isNotEmpty(oleGokbTitle.getIssnOnline())) {
844 bibMarcRecord.getDataFields().add(buildDataField(tag, oleGokbTitle.getIssnOnline()));
845 } else if (gokbFiled.equalsIgnoreCase("TI ISSN (Print)") && StringUtils.isNotEmpty( oleGokbTitle.getIssnPrint())) {
846 bibMarcRecord.getDataFields().add(buildDataField(tag, oleGokbTitle.getIssnPrint()));
847 } else if (gokbFiled.equalsIgnoreCase("TI ISSN-L") && StringUtils.isNotEmpty( oleGokbTitle.getIssnL())) {
848 bibMarcRecord.getDataFields().add(buildDataField(tag, oleGokbTitle.getIssnL()));
849 } else if (gokbFiled.equalsIgnoreCase("OCLC Number") && oleGokbTitle.getOclcNumber() >0) {
850 bibMarcRecord.getDataFields().add(buildDataField(tag, "(OCLC)" + oleGokbTitle.getOclcNumber()));
851 } else if (gokbFiled.equalsIgnoreCase("TI DOI") && StringUtils.isNotEmpty(oleGokbTitle.getDoi())) {
852 bibMarcRecord.getDataFields().add(buildDataField(tag, "(DOI)" + oleGokbTitle.getDoi()));
853 } else if (gokbFiled.equalsIgnoreCase("TI Proprietary ID") && oleGokbTitle.getProprietaryId() >0) {
854 bibMarcRecord.getDataFields().add(buildDataField(tag, "(ProprietaryID)" + oleGokbTitle.getProprietaryId()));
855 } else if (gokbFiled.equalsIgnoreCase("TI SUNCAT") && StringUtils.isNotEmpty( oleGokbTitle.getSuncat())) {
856 bibMarcRecord.getDataFields().add(buildDataField(tag, "(SUNCAT)" + oleGokbTitle.getSuncat()));
857 } else if (gokbFiled.equalsIgnoreCase("TI LCCN") && StringUtils.isNotEmpty( oleGokbTitle.getLccn())) {
858 bibMarcRecord.getDataFields().add(buildDataField(tag, oleGokbTitle.getLccn()));
859 }
860 }
861
862 return bibMarcRecord;
863 }
864
865 private DataField buildDataField(String tag, String data) {
866 DataField dataField = BatchBibImportUtil.getDataField(tag);
867 for (SubField subField : dataField.getSubFields()) {
868 subField.setValue(data);
869 }
870 return dataField;
871 }
872
873
874 public List<String> getPlatformProvidersForInstance(List<OLEEResourceInstance> oleERSInstances) {
875
876 List<String> platformProviders = new ArrayList<>();
877 Set<String> platformIds = new HashSet<>();
878
879 for (OLEEResourceInstance oleeResourceInstance : oleERSInstances) {
880 if(StringUtils.isNotBlank(oleeResourceInstance.getPlatformId())){
881 platformIds.add(oleeResourceInstance.getPlatformId());
882 }
883 }
884
885 for (String platformId : platformIds) {
886 OLEPlatformRecordDocument olePlatformRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEPlatformRecordDocument.class, platformId);
887 if (olePlatformRecordDocument != null) {
888 if (olePlatformRecordDocument.getVendorHeaderGeneratedIdentifier() != null && olePlatformRecordDocument.getVendorDetailAssignedIdentifier() != null) {
889 Map vendorMap = new HashMap();
890 vendorMap.put(OLEConstants.VENDOR_HEADER_GENERATED_ID, olePlatformRecordDocument.getVendorHeaderGeneratedIdentifier());
891 vendorMap.put(OLEConstants.VENDOR_DETAILED_ASSIGNED_ID, olePlatformRecordDocument.getVendorDetailAssignedIdentifier());
892 VendorDetail vendor = getBusinessObjectService().findByPrimaryKey(VendorDetail.class, vendorMap);
893 if (vendor != null && StringUtils.isNotEmpty(vendor.getVendorName()))
894 platformProviders.add(vendor.getVendorName());
895 }
896 }
897 }
898
899 return platformProviders;
900 }
901
902
903 public void importTipps(OLEBatchProcessProfileBo gokbImportProfile, List<BibMarcRecord> bibMarcRecords) {
904
905 OLEBatchGOKBImport batchGOKBImport = new OLEBatchGOKBImport();
906 batchGOKBImport.setOleBatchProcessProfileBo(gokbImportProfile);
907
908 try {
909 batchGOKBImport.processBatch(bibMarcRecords);
910 } catch (Exception e) {
911 e.printStackTrace();
912 }
913
914 }
915
916 public void createOrUpdateVendorAndPlatform(OLEEResourceRecordDocument oleeResourceRecordDocument) {
917 for (OLEGOKbPlatform oleGoKbPlatform : oleeResourceRecordDocument.getGoKbPlatformList()) {
918
919 if (oleGoKbPlatform.getPlatformProviderId() != null) {
920 createOrUpdateVendor(oleGoKbPlatform.getPlatformProviderId(), "");
921 }
922 Set<Integer> publisherIds = new HashSet<>();
923 for (OLEGOKbTIPP oleGoKbTIPP : oleGoKbPlatform.getSelectedGokbTippList()) {
924 if (oleGoKbTIPP.getPublisherId() != null && publisherIds.add(oleGoKbTIPP.getPublisherId())) {
925 createOrUpdateVendor(oleGoKbTIPP.getPublisherId(), "");
926 }
927 }
928
929 oleeResourceSearchService.updatePublisher(oleGoKbPlatform.getSelectedGokbTippList(), oleeResourceRecordDocument);
930
931
932 if (oleGoKbPlatform.getPlatformId() != null) {
933 Map gokbMap = new HashMap();
934 gokbMap.put(OLEConstants.GOKB_ID, oleGoKbPlatform.getPlatformId());
935 List<OLEPlatformRecordDocument> platformRecordDocumentList = (List<OLEPlatformRecordDocument>) getBusinessObjectService().findMatching(OLEPlatformRecordDocument.class, gokbMap);
936 OLEPlatformRecordDocument olePlatformRecordDocument = null;
937 if (platformRecordDocumentList != null && platformRecordDocumentList.size() > 0) {
938 olePlatformRecordDocument = platformRecordDocumentList.get(0);
939 oleeResourceSearchService.updatePlatform(olePlatformRecordDocument, oleGoKbPlatform.getPlatformName(), oleGoKbPlatform.getStatus(), oleGoKbPlatform.getSoftwarePlatform(), oleGoKbPlatform.getPlatformProviderId());
940 } else {
941 olePlatformRecordDocument = oleeResourceSearchService.createPlatform(oleGoKbPlatform.getPlatformName(), oleGoKbPlatform.getPlatformId(), oleGoKbPlatform.getSoftwarePlatform(), oleGoKbPlatform.getStatus(), oleGoKbPlatform.getPlatformProviderId());
942 }
943 updatePlatformVendorAssociation(olePlatformRecordDocument);
944 }
945 }
946 }
947
948 public void createOrUpdateVendor(Integer vendorId, String logId) {
949 OleGokbOrganization oleGokbOrganization = getBusinessObjectService().findBySinglePrimaryKey(OleGokbOrganization.class, vendorId);
950 if (oleGokbOrganization != null && oleGokbOrganization.getGokbOrganizationId() != null) {
951 Map vendorMap = new HashMap();
952 vendorMap.put(OLEConstants.GOKB_ID, oleGokbOrganization.getGokbOrganizationId());
953 List<VendorDetail> vendorDetails = (List<VendorDetail>) getBusinessObjectService().findMatching(VendorDetail.class, vendorMap);
954 if (vendorDetails != null && vendorDetails.size() > 0) {
955 VendorDetail vendorDetail = vendorDetails.get(0);
956 oleeResourceSearchService.updateVendor(vendorDetail, oleGokbOrganization.getOrganizationName());
957 updateLog(logId, "", "vendorsUpdatedCount", 1);
958 } else {
959 oleeResourceSearchService.createVendor(oleGokbOrganization.getOrganizationName(), oleGokbOrganization.getGokbOrganizationId(), oleGokbOrganization.getVariantName());
960 updateLog(logId, "", "vendorsAddedCount", 1);
961 }
962 }
963 }
964
965 public List<OLEPlatformRecordDocument> fetchPlatformDetailsForEResId(String eResId) {
966 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, eResId);
967 List<OLEPlatformRecordDocument> olePlatformRecordDocuments = new ArrayList<>();
968 for (OLEEResourceInstance oleeResourceInstance : oleeResourceRecordDocument.getOleERSInstances()) {
969 OLEPlatformRecordDocument olePlatformRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEPlatformRecordDocument.class, oleeResourceInstance.getPlatformId());
970 olePlatformRecordDocuments.add(olePlatformRecordDocument);
971 }
972 return olePlatformRecordDocuments;
973 }
974
975 public void applyGokbChangesToPlatforms(String eResId, String logId) {
976 List<OLEPlatformRecordDocument> olePlatformRecordDocuments = new ArrayList<>();
977 if (eResId != null && StringUtils.isNotEmpty(eResId)) {
978 olePlatformRecordDocuments = fetchPlatformDetailsForEResId(eResId);
979 } else {
980 List<OLEPlatformRecordDocument> olePlatformRecordDocumentList = (List<OLEPlatformRecordDocument>) getBusinessObjectService().findAll(OLEPlatformRecordDocument.class);
981 for (OLEPlatformRecordDocument platformRecordDocument : olePlatformRecordDocumentList) {
982 if (platformRecordDocument.getGokbId() != null) {
983 olePlatformRecordDocuments.add(platformRecordDocument);
984 }
985 }
986 }
987 for (OLEPlatformRecordDocument platformRecordDocument : olePlatformRecordDocuments) {
988 OleGokbPlatform olegoKbPlatform = getBusinessObjectService().findBySinglePrimaryKey(OleGokbPlatform.class, platformRecordDocument.getGokbId());
989 if (olegoKbPlatform != null) {
990 if (platformRecordDocument.getGokbLastUpdatedDate() == null || olegoKbPlatform.getDateUpdated().after(platformRecordDocument.getGokbLastUpdatedDate())) {
991 Map hashmap = new HashMap();
992 hashmap.put("platformStatusId",platformRecordDocument.getStatusId());
993 List<OLEPlatformStatus> olePlatformStatusList = (List<OLEPlatformStatus>) getBusinessObjectService().findMatching(OLEPlatformStatus.class, hashmap);
994 if(olePlatformStatusList.size()>0){
995 if (olePlatformStatusList.get(0).getPlatformStatusName().equalsIgnoreCase(olegoKbPlatform.getStatus())) {
996 String details = "[" + olePlatformStatusList.get(0).getPlatformStatusName() + "]: GOKb status changed to[" + olegoKbPlatform.getStatus() + "]";
997 createToDo(eResId, "Change Platform Status", details, null);
998 }
999 }
1000 else{
1001 String details = " GOKb status changed to[" + olegoKbPlatform.getStatus() + "]";
1002 createToDo(eResId, "Change Platform Status", details, null);
1003 }
1004 if (!platformRecordDocument.getName().equalsIgnoreCase(olegoKbPlatform.getPlatformName())) {
1005 String detail = "[" + olegoKbPlatform.getPlatformName() + "] has changed form [" + platformRecordDocument.getName() + "] to [" + olegoKbPlatform.getPlatformName() + "]";
1006 createChangeLog(eResId, "Metadata change: Platform name", detail);
1007 }
1008
1009
1010 if (!platformRecordDocument.getSoftware().equalsIgnoreCase(olegoKbPlatform.getSoftwarePlatform())) {
1011 String details = "[" + platformRecordDocument.getName() + "]: Platform software has changed from [" + platformRecordDocument.getSoftware() + "] to [" + olegoKbPlatform.getStatus() + "]";
1012 createChangeLog(eResId, "Metadata change: Platform software", details);
1013 }
1014 oleeResourceSearchService.updatePlatform(platformRecordDocument, olegoKbPlatform.getPlatformName(), olegoKbPlatform.getStatus(), olegoKbPlatform.getSoftwarePlatform(), olegoKbPlatform.getPlatformProviderId());
1015 updatePlatformVendorAssociation(platformRecordDocument);
1016 updateLog(logId, eResId, "platformsUpdatedCount", 1);
1017 }
1018 }
1019 }
1020 }
1021
1022 public List<VendorDetail> fetchVendorDetailsForEResId(String eResId) {
1023
1024 List<VendorDetail> vendorDetails = new ArrayList<>();
1025 Map eResMap = new HashMap();
1026 eResMap.put("oleERSIdentifier", eResId);
1027 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, eResId);
1028 if (StringUtils.isNotEmpty(oleeResourceRecordDocument.getVendorId())) {
1029 VendorDetail vendorDetail = getBusinessObjectService().findBySinglePrimaryKey(VendorDetail.class, oleeResourceRecordDocument.getVendorId());
1030 vendorDetails.add(vendorDetail);
1031 }
1032
1033 if (StringUtils.isNotEmpty(oleeResourceRecordDocument.getPublisherId())) {
1034 Map vendorMap = new HashMap();
1035 vendorMap.put("gokbId", oleeResourceRecordDocument.getPublisherId());
1036 List<VendorDetail> publishers = (List<VendorDetail>) getBusinessObjectService().findMatching(VendorDetail.class, vendorMap);
1037
1038 if (publishers.size() > 0) {
1039 vendorDetails.add(publishers.get(0));
1040 }
1041 }
1042 for (OLEEResourceInstance oleeResourceInstance : oleeResourceRecordDocument.getOleERSInstances()) {
1043 OLEPlatformRecordDocument olePlatformRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEPlatformRecordDocument.class, oleeResourceInstance.getPlatformId());
1044 Map vendorDetailMap = new HashMap();
1045 vendorDetailMap.put("gokbId", olePlatformRecordDocument.getGokbId());
1046 List<VendorDetail> platformProviderList = (List<VendorDetail>) getBusinessObjectService().findMatching(VendorDetail.class, vendorDetailMap);
1047 if (platformProviderList.size() > 0) {
1048
1049 vendorDetails.add(platformProviderList.get(0));
1050 }
1051 }
1052 return vendorDetails;
1053 }
1054
1055
1056 public void applyGokbChangesToVendors(String eResId, String logId) {
1057 List<VendorDetail> vendorDetails = new ArrayList<>();
1058 if (eResId != null && StringUtils.isNotEmpty(eResId)) {
1059 vendorDetails = fetchVendorDetailsForEResId(eResId);
1060 } else {
1061 List<VendorDetail> vendorDetailList = (List<VendorDetail>) getBusinessObjectService().findAll(VendorDetail.class);
1062 for (VendorDetail vendorDetail : vendorDetailList) {
1063 if (vendorDetail.getGokbId() != null) {
1064 vendorDetails.add(vendorDetail);
1065 }
1066 }
1067 }
1068 for (VendorDetail vendor : vendorDetails) {
1069 OleGokbOrganization oleGokbOrganization = getBusinessObjectService().findBySinglePrimaryKey(OleGokbOrganization.class, vendor.getGokbId());
1070 if (oleGokbOrganization != null) {
1071 if (vendor.getGokbLastUpdated() == null || oleGokbOrganization.getDateUpdated().after(vendor.getGokbLastUpdated())) {
1072
1073 if (!vendor.getVendorName().equalsIgnoreCase(oleGokbOrganization.getOrganizationName())) {
1074 String details = "[" + oleGokbOrganization.getOrganizationName() + "]" + " Organization name changed from [" + vendor.getVendorName() + "] to [" + oleGokbOrganization.getOrganizationName() + "]";
1075 createChangeLog(eResId, "Change: Organization name", details);
1076 }
1077 List<String> vendorAlias = new ArrayList<>();
1078 if (vendor.getVendorAliases() != null) {
1079 for (VendorAlias vendoralias : vendor.getVendorAliases()) {
1080 vendorAlias.add(vendoralias.getVendorAliasName());
1081 }
1082 if (!vendorAlias.contains(oleGokbOrganization.getVariantName())) {
1083 String details = "[" + vendor.getVendorName() + "] " + "has new variant name ";
1084 createChangeLog(eResId, "Metadata change: New organization variant name", details);
1085 }
1086 }
1087 oleeResourceSearchService.updateVendor(vendor, oleGokbOrganization.getOrganizationName());
1088 updateLog(logId, eResId, "vendorsUpdatedCount", 1);
1089 }
1090 }
1091 }
1092 }
1093
1094 public void overwriteEresourceWithPackage(OLEEResourceRecordDocument oleeResourceRecordDocument, OleGokbPackage oleGokbPackage, String logId) {
1095 if (oleeResourceRecordDocument.getGokbPackageStatus() != null && !oleeResourceRecordDocument.getGokbPackageStatus().equalsIgnoreCase(oleGokbPackage.getStatus())) {
1096 String details = "[" + oleeResourceRecordDocument.getGokbPackageStatus() + "]: GOKb status changed to [" + oleGokbPackage.getStatus() + "]";
1097 createToDo(oleeResourceRecordDocument.getOleERSIdentifier(), "Change: Package Status", details, null);
1098 }
1099
1100 GOKbDataElement eResourceNameDataElement = getDataElement(E_RESOURCE_NAME);
1101 GOKbDataElement variantDataElement = getDataElement(VARIANT_NAME);
1102 GOKbDataElement publisherDataElement = getDataElement(PUBLISHER);
1103 GOKbDataElement packageScopeDataElement = getDataElement(PACKAGE_SCOPE);
1104 GOKbDataElement breakableDataElement = getDataElement(BREAKABLE);
1105 GOKbDataElement fixedTitleDataElement = getDataElement(FIXED_TITLE_LIST);
1106 GOKbDataElement packageTypeDataElement = getDataElement(PACKAGE_TYPE);
1107 GOKbDataElement eResourceDataElement = getDataElement(E_RESOURCE_GOKBID);
1108
1109 Map dataMapping = new HashMap();
1110 dataMapping.put("recordType", "E-Resource");
1111 dataMapping.put("recordId", oleeResourceRecordDocument.getOleERSIdentifier());
1112 List<OLEGOKbMappingValue> locallyModifiedElements = (List<OLEGOKbMappingValue>) getBusinessObjectService().findMatching(OLEGOKbMappingValue.class, dataMapping);
1113 if (locallyModifiedElements.size() == 0) {
1114 oleeResourceRecordDocument.setTitle(oleGokbPackage.getPackageName());
1115 String variantName = oleGokbPackage.getVariantName();
1116 if (StringUtils.isNotBlank(variantName)){
1117 OLEEResourceVariantTitle variantTitle = new OLEEResourceVariantTitle();
1118 variantTitle.setOleVariantTitle(variantName);
1119 oleeResourceRecordDocument.getOleEResourceVariantTitleList().add(variantTitle);
1120 }
1121 getPublisherIdFromPackageId(oleeResourceRecordDocument, oleGokbPackage.getGokbPackageId().toString());
1122 String packId = getOlePackageScopeId(oleGokbPackage.getPackageScope());
1123 if(packId != null) {
1124 oleeResourceRecordDocument.setPackageScopeId(packId);
1125 }
1126 oleeResourceRecordDocument.setBreakable(Boolean.valueOf(oleGokbPackage.getBreakable()));
1127 oleeResourceRecordDocument.setFixedTitleList(Boolean.valueOf(oleGokbPackage.getFixed()));
1128 oleeResourceRecordDocument.setGokbIdentifier(oleGokbPackage.getGokbPackageId());
1129 } else {
1130 for (OLEGOKbMappingValue localMappingValue : locallyModifiedElements) {
1131
1132 if (localMappingValue.getDataElementId().equalsIgnoreCase(eResourceNameDataElement.getDataElementId())) {
1133 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1134 oleeResourceRecordDocument.setTitle(oleGokbPackage.getPackageName());
1135 }
1136 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(variantDataElement.getDataElementId())) {
1137 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1138 String variantName = oleGokbPackage.getVariantName();
1139 if (StringUtils.isNotBlank(variantName)) {
1140 OLEEResourceVariantTitle variantTitle = new OLEEResourceVariantTitle();
1141 variantTitle.setOleVariantTitle(variantName);
1142 oleeResourceRecordDocument.getOleEResourceVariantTitleList().add(variantTitle);
1143 }
1144 }
1145 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(publisherDataElement.getDataElementId())) {
1146 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1147 getPublisherIdFromPackageId(oleeResourceRecordDocument, oleGokbPackage.getGokbPackageId().toString());
1148 }
1149 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(packageScopeDataElement.getDataElementId())) {
1150 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1151 String packId = getOlePackageScopeId(oleGokbPackage.getPackageScope());
1152 if(packId != null) {
1153 oleeResourceRecordDocument.setPackageScopeId(packId);
1154 }
1155 }
1156 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(breakableDataElement.getDataElementId())) {
1157 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1158 oleeResourceRecordDocument.setBreakable(Boolean.valueOf(oleGokbPackage.getBreakable()));
1159 }
1160 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(fixedTitleDataElement.getDataElementId())) {
1161 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1162 oleeResourceRecordDocument.setFixedTitleList(Boolean.valueOf(oleGokbPackage.getFixed()));
1163 }
1164 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(packageTypeDataElement.getDataElementId())) {
1165 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1166
1167
1168 }
1169 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(eResourceDataElement.getDataElementId())) {
1170 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1171 oleeResourceRecordDocument.setGokbIdentifier(oleGokbPackage.getGokbPackageId());
1172 }
1173 }
1174 }
1175 }
1176 oleeResourceRecordDocument.setGokbLastUpdatedDate(oleGokbPackage.getDateUpdated());
1177 oleeResourceRecordDocument.setGokbPackageStatus(oleGokbPackage.getStatus());
1178 KRADServiceLocatorWeb.getDocumentService().updateDocument(oleeResourceRecordDocument);
1179 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "eResUpdatedCount", 1);
1180 if (!oleeResourceRecordDocument.getTitle().equalsIgnoreCase(oleGokbPackage.getPackageName())) {
1181 String details = "[" + oleeResourceRecordDocument.getTitle() + "]: E-Resource name changed from [" + oleeResourceRecordDocument.getTitle() + "] to [" + oleGokbPackage.getPackageName() + "]";
1182 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Resource name", details);
1183 }
1184 if (!oleeResourceRecordDocument.getPackageScopeId().equalsIgnoreCase(oleGokbPackage.getPackageScope())) {
1185 String details = "[" + oleeResourceRecordDocument.getTitle() + "]: E-Resource scope changed from [" + oleeResourceRecordDocument.getPackageScopeId() + "] to [" + oleGokbPackage.getPackageScope() + "]";
1186 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Resource scope", details);
1187 }
1188 if (!oleGokbPackage.getBreakable().equalsIgnoreCase("Unknown")) {
1189 if (!String.valueOf(oleeResourceRecordDocument.isBreakable()).equalsIgnoreCase(oleGokbPackage.getBreakable())) {
1190 String details = "[" + oleeResourceRecordDocument.getTitle() + "]: E-Resource breakable changed from [" + oleeResourceRecordDocument.isBreakable() + "] to [" + oleGokbPackage.getBreakable() + "]";
1191 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Resource breakable", details);
1192 }
1193 }
1194 if (!oleGokbPackage.getBreakable().equalsIgnoreCase("Unknown")) {
1195 if (!String.valueOf(oleeResourceRecordDocument.isFixedTitleList()).equalsIgnoreCase(oleGokbPackage.getFixed())) {
1196 String details = "[" + oleeResourceRecordDocument.getTitle() + "]: E-Resource fixed changed from [" + oleeResourceRecordDocument.isFixedTitleList() + "] to [" + oleGokbPackage.getFixed() + "]";
1197 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Resource fixed", details);
1198 }
1199 }
1200 }
1201
1202 private String getOlePackageScopeId(String packageScope) {
1203
1204 Map map = new HashMap();
1205 map.put("olePackageScopeName", packageScope);
1206
1207 List<OLEPackageScope> packageScopes = (List<OLEPackageScope>) getBusinessObjectService().findMatching(OLEPackageScope.class, map);
1208 if(packageScopes != null && packageScopes.size() > 0) {
1209 return packageScopes.get(0).getOlePackageScopeId();
1210 }
1211 return null;
1212 }
1213
1214 public void getPublisherIdFromPackageId(OLEEResourceRecordDocument oleeResourceRecordDocument, String packageId) {
1215 Map map = new HashMap();
1216 map.put("gokbPackageId", packageId);
1217 List<OleGokbTipp> oleGokbTipps = (List<OleGokbTipp>) getBusinessObjectService().findMatching(OleGokbTipp.class, map);
1218 OleGokbTitle oleGokbTitle = getBusinessObjectService().findBySinglePrimaryKey(OleGokbTitle.class, oleGokbTipps.get(0).getGokbTitleId());
1219 if (oleGokbTitle != null && oleGokbTitle.getPublisherId() != null) {
1220 oleeResourceRecordDocument.setPublisher(oleGokbTitle.getPublisherId().toString());
1221 }
1222 }
1223
1224 public void applyGokbChangesToEresources(String eResId, String logId) {
1225 List<OLEEResourceRecordDocument> oleeResourceRecordDocuments = new ArrayList<>();
1226 if (StringUtils.isNotEmpty(eResId)) {
1227 OLEEResourceRecordDocument oleeResourceRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, eResId);
1228 oleeResourceRecordDocuments.add(oleeResourceRecordDocument);
1229 } else {
1230 oleeResourceRecordDocuments = (List<OLEEResourceRecordDocument>) getBusinessObjectService().findAll(OLEEResourceRecordDocument.class);
1231 }
1232 for (OLEEResourceRecordDocument oleeResourceRecordDocument : oleeResourceRecordDocuments) {
1233 if (oleeResourceRecordDocument.getGokbIdentifier() != null) {
1234 Map packageMap = new HashMap();
1235 packageMap.put("gokbPackageId", oleeResourceRecordDocument.getGokbIdentifier());
1236 OleGokbPackage oleGokbPackage = (OleGokbPackage) getBusinessObjectService().findBySinglePrimaryKey(OleGokbPackage.class, oleeResourceRecordDocument.getGokbIdentifier());
1237 if (oleGokbPackage != null) {
1238
1239 overwriteEresourceWithPackage(oleeResourceRecordDocument, oleGokbPackage, logId);
1240
1241 }
1242
1243 Map eholdingsMap = new HashMap();
1244 for (OLEEResourceInstance oleeResourceInstance : oleeResourceRecordDocument.getOleERSInstances()) {
1245
1246 eholdingsMap.put(oleeResourceInstance.getGokbId(), oleeResourceInstance);
1247 }
1248 Map map = new HashMap();
1249 map.put("gokbPackageId", oleGokbPackage.getGokbPackageId());
1250 List<OleGokbTipp> oleGokbTipps = (List<OleGokbTipp>) getBusinessObjectService().findMatching(OleGokbTipp.class, map);
1251 List<OleGokbTipp> oleGokbTippTobeCreated = new ArrayList<>();
1252 for (OleGokbTipp tipp : oleGokbTipps) {
1253 if (!eholdingsMap.containsKey(tipp.getGokbTippId())) {
1254 oleGokbTippTobeCreated.add(tipp);
1255
1256 } else {
1257 if (tipp.getStatus().equalsIgnoreCase("Retired")) {
1258 SearchParams searchParams = new SearchParams();
1259 searchParams.buildSearchCondition("", searchParams.buildSearchField("Biblographic", "mdf_035a", "(GOKbUID)" + tipp.getGokbTitleId()), "AND");
1260 SearchResponse searchResponse = null;
1261 try {
1262 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1263 } catch (Exception e) {
1264 e.printStackTrace();
1265 }
1266 String bibId = "";
1267 for (SearchResult searchResult : searchResponse.getSearchResults()) {
1268 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1269 if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
1270 bibId = searchResultField.getFieldValue();
1271 }
1272 }
1273 }
1274 Bib bib = null;
1275 try {
1276 bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(bibId);
1277 } catch (Exception e) {
1278 e.printStackTrace();
1279 }
1280 Holdings eHoldings = null;
1281 OLEEResourceInstance oleeResourceInstance = (OLEEResourceInstance) eholdingsMap.get(tipp.getGokbTippId());
1282 try {
1283 eHoldings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleeResourceInstance.getInstanceId());
1284 } catch (Exception e) {
1285 e.printStackTrace();
1286 }
1287 retireTippFromEresource(eHoldings, tipp, bib, oleeResourceRecordDocument, logId);
1288 } else if (tipp.getStatus().equalsIgnoreCase("Deleted")) {
1289 SearchParams searchParams = new SearchParams();
1290 searchParams.buildSearchCondition("", searchParams.buildSearchField("Biblographic", "mdf_035a", "(GOKbUID)" + tipp.getGokbTitleId()), "AND");
1291 SearchResponse searchResponse = null;
1292 try {
1293 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1294 } catch (Exception e) {
1295 e.printStackTrace();
1296 }
1297 String bibId = "";
1298 for (SearchResult searchResult : searchResponse.getSearchResults()) {
1299 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1300 if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
1301 bibId = searchResultField.getFieldValue();
1302 }
1303 }
1304 }
1305 Bib bib = null;
1306 try {
1307 bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(bibId);
1308 } catch (Exception e) {
1309 e.printStackTrace();
1310 }
1311 Holdings eHoldings = null;
1312 OLEEResourceInstance oleeResourceInstance = (OLEEResourceInstance) eholdingsMap.get(tipp.getGokbTippId());
1313 try {
1314 eHoldings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleeResourceInstance.getInstanceId());
1315 } catch (Exception e) {
1316 e.printStackTrace();
1317 }
1318 deleteTippFromEresource(eHoldings, tipp, bib, oleeResourceRecordDocument, logId);
1319 } else {
1320 SearchParams searchParams = new SearchParams();
1321 searchParams.buildSearchCondition("", searchParams.buildSearchField("Biblographic", "mdf_035a", "(GOKbUID)" + tipp.getGokbTitleId()), "AND");
1322 SearchResponse searchResponse = null;
1323 try {
1324 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1325 } catch (Exception e) {
1326 e.printStackTrace();
1327 }
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342 Holdings eHoldings = null;
1343 OLEEResourceInstance oleeResourceInstance = (OLEEResourceInstance) eholdingsMap.get(tipp.getGokbTippId());
1344 try {
1345 eHoldings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleeResourceInstance.getInstanceId());
1346 } catch (Exception e) {
1347 e.printStackTrace();
1348 }
1349
1350 overwriteEholdingsWithTipp(eHoldings, tipp, oleeResourceRecordDocument, logId);
1351 }
1352 }
1353 }
1354 if (oleGokbTippTobeCreated.size() > 0) {
1355 addTippToEresource(oleeResourceRecordDocument, oleGokbTippTobeCreated, logId);
1356 }
1357 }
1358 }
1359 }
1360
1361 public void addTippToEresource(OLEEResourceRecordDocument oleeResourceRecordDocument, List<OleGokbTipp> oleGokbTipps, String logId) {
1362
1363 if (oleeResourceRecordDocument.getGokbconfig().equalsIgnoreCase("sync")) {
1364 List<BibMarcRecord> bibMarcRecords = new ArrayList<>();
1365 OLEBatchProcessProfileBo gokbImportProfile = getGOKBImportProfile(oleeResourceRecordDocument.getGokbProfile());
1366 for (OleGokbTipp oleGokbTipp : oleGokbTipps) {
1367 OleGokbPlatform oleGokbPlatform = fetchPlatformForTipp(oleGokbTipp);
1368 createOrUpdateVendor(oleGokbPlatform.getPlatformProviderId(), logId);
1369 OleGokbTitle oleGokbTitle = getOleGokbTitle(oleGokbTipp.getGokbTitleId());
1370 if (oleGokbTitle != null) {
1371 String details = "[" + oleGokbTitle.getTitleName() + "]: E-Holdings added to OLE";
1372 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "New E-Holdings", details);
1373 createOrUpdateVendor(oleGokbTitle.getPublisherId(), logId);
1374 oleeResourceSearchService.updatePublisherDetails(oleeResourceRecordDocument, oleGokbTitle.getPublisherId());
1375 }
1376 Map gokbMap = new HashMap();
1377 gokbMap.put(OLEConstants.GOKB_ID, oleGokbPlatform.getGokbPlatformId());
1378 List<OLEPlatformRecordDocument> platformRecordDocumentList = (List<OLEPlatformRecordDocument>) getBusinessObjectService().findMatching(OLEPlatformRecordDocument.class, gokbMap);
1379 OLEPlatformRecordDocument olePlatformRecordDocument = null;
1380 if (platformRecordDocumentList != null && platformRecordDocumentList.size() > 0) {
1381 olePlatformRecordDocument = platformRecordDocumentList.get(0);
1382 olePlatformRecordDocument.setGokbLastUpdatedDate(oleGokbPlatform.getDateUpdated());
1383 oleeResourceSearchService.updatePlatform(olePlatformRecordDocument, oleGokbPlatform.getPlatformName(), oleGokbPlatform.getStatus(), oleGokbPlatform.getSoftwarePlatform(), oleGokbPlatform.getPlatformProviderId());
1384 } else {
1385 olePlatformRecordDocument = oleeResourceSearchService.createPlatform(oleGokbPlatform.getPlatformName(), oleGokbPlatform.getGokbPlatformId(), oleGokbPlatform.getSoftwarePlatform(), oleGokbPlatform.getStatus(), oleGokbPlatform.getPlatformProviderId());
1386 }
1387 if (oleeResourceRecordDocument != null) {
1388 updatePlatformVendorAssociation(olePlatformRecordDocument);
1389 }
1390 String platformName = oleGokbPlatform.getPlatformName();
1391 if (oleGokbTitle != null) {
1392 BibMarcRecord bibMarcRecord = buildBibMarcRecordFromTitle(oleGokbTitle,gokbImportProfile.getOleBatchProcessBibDataMappingNewList());
1393 String imprint = String.valueOf(oleGokbTitle.getImprint());
1394 String publisher = String.valueOf(oleGokbTitle.getPublisherId());
1395 DataField dataField = getDataFieldForTipp(platformName, oleeResourceRecordDocument.getOleERSIdentifier(), oleGokbTipp, imprint, publisher,gokbImportProfile.getOleBatchProcessProfileDataMappingOptionsBoList());
1396 bibMarcRecord.getDataFields().add(dataField);
1397 bibMarcRecords.add(bibMarcRecord);
1398 }
1399 }
1400
1401 importTipps(gokbImportProfile, bibMarcRecords);
1402 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "eHoldingsAddedCount", oleGokbTipps.size());
1403 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "bibAddedCount", oleGokbTipps.size());
1404 } else {
1405 for (OleGokbTipp oleGokbTipp : oleGokbTipps) {
1406 OleGokbTitle oleGokbTitle = getBusinessObjectService().findBySinglePrimaryKey(OleGokbTitle.class, oleGokbTipp.getGokbTitleId());
1407 String details = "[" + oleGokbTitle.getTitleName() + "]: TIPP added to GOKb package. E-Holdings not created. Review TIPP and approve to create associated E-Holdings";
1408 createToDo(oleeResourceRecordDocument.getOleERSIdentifier(), "New TIPP", details, oleGokbTipp.getGokbTippId());
1409 }
1410 }
1411
1412 }
1413
1414 private OleGokbTitle getOleGokbTitle(Integer titleId) {
1415 Map map = new HashMap();
1416 map.put("gokbTitleId", titleId);
1417 return getBusinessObjectService().findByPrimaryKey(OleGokbTitle.class, map);
1418 }
1419
1420 public OleGokbPlatform fetchPlatformForTipp(OleGokbTipp tipp) {
1421 OleGokbPlatform oleGokbPlatform = getBusinessObjectService().findBySinglePrimaryKey(OleGokbPlatform.class, tipp.getGokbPlatformId());
1422 return oleGokbPlatform;
1423 }
1424
1425 public void deleteTippFromEresource(Holdings eHolding, OleGokbTipp tipp, Bib bib, OLEEResourceRecordDocument oleeResourceRecordDocument, String logId) {
1426 if (oleeResourceRecordDocument.getGokbconfig().equalsIgnoreCase("sync")) {
1427 List<OLEEResourceInstance> oleERSInstances = oleeResourceRecordDocument.getOleERSInstances();
1428 for (OLEEResourceInstance oleeResourceInstance : oleERSInstances) {
1429 if (oleeResourceInstance.getInstanceId().equalsIgnoreCase(eHolding.getLocalId())) {
1430 Map copyMap = new HashMap();
1431 copyMap.put("instanceId", oleeResourceInstance.getInstanceId());
1432 List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService().findMatching(OleCopy.class, copyMap);
1433 if (copies.get(0).getPoItemId() != null) {
1434 String details = "[" + eHolding.getBib().getTitle() + "] TIPP deleted from GOKb package. E-Holdings could not be deleted because of an attached purchase order";
1435 createToDo(oleeResourceRecordDocument.getOleERSIdentifier(), "Deleted TIPP", details, null);
1436 } else {
1437 try {
1438 getDocstoreClientLocator().getDocstoreClient().deleteHoldings(eHolding.getLocalId());
1439 } catch (Exception e) {
1440 e.printStackTrace();
1441 }
1442 String details = "[" + eHolding.getBib().getTitle() + "]: E-Holding deleted from OLE";
1443 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Deleted E-Holdings", details);
1444 }
1445 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "eHoldingsDeletedCount", 1);
1446 }
1447 }
1448 } else {
1449 String details = "[" + eHolding.getBib().getTitle() + "] TIPP deleted from GOKb package. E-Holdings could not be deleted because of an attached purchase order";
1450 createToDo(oleeResourceRecordDocument.getOleERSIdentifier(), "Deleted TIPP", details, null);
1451 }
1452 }
1453
1454 public void retireTippFromEresource(Holdings eHolding, OleGokbTipp tipp, Bib bib, OLEEResourceRecordDocument oleeResourceRecordDocument, String logId) {
1455 if (oleeResourceRecordDocument.getGokbconfig().equalsIgnoreCase("sync")) {
1456 List<OLEEResourceInstance> oleERSInstances = oleeResourceRecordDocument.getOleERSInstances();
1457 for (OLEEResourceInstance oleeResourceInstance : oleERSInstances) {
1458 if (oleeResourceInstance.getInstanceId().equalsIgnoreCase(eHolding.getLocalId())) {
1459 Map copyMap = new HashMap();
1460 copyMap.put("instanceId", oleeResourceInstance.getInstanceId());
1461 List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService().findMatching(OleCopy.class, copyMap);
1462 if (copies.get(0).getPoItemId() != null) {
1463 String details = "[" + eHolding.getBib().getTitle() + "] TIPP retired from GOKb package. E-Holdings could not be deleted because of an attached purchase order";
1464 createToDo(oleeResourceRecordDocument.getOleERSIdentifier(), "Retired TIPP", details, null);
1465 } else {
1466 try {
1467 getDocstoreClientLocator().getDocstoreClient().deleteHoldings(eHolding.getLocalId());
1468 } catch (Exception e) {
1469 e.printStackTrace();
1470 }
1471 String details = "[" + eHolding.getBib().getTitle() + "]: E-Holding deleted from OLE";
1472 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Retired E-Holdings", details);
1473 }
1474 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "eHoldingsRetiredCount", 1);
1475 }
1476 }
1477
1478 } else {
1479 String details = "[<" + eHolding.getBib().getTitle() + ">]: TIPP retired from GOKb package. No changes to E-Holdings. Review E-Holdings to determine if action is needed";
1480 createToDo(oleeResourceRecordDocument.getOleERSIdentifier(), "Retired TIPP", details, null);
1481 }
1482 }
1483
1484 public void overwriteEholdingsWithTipp(Holdings eHolding, OleGokbTipp tipp, OLEEResourceRecordDocument oleeResourceRecordDocument, String logId) {
1485 if (eHolding.getStatus() != null && !eHolding.getStatus().equalsIgnoreCase(tipp.getStatus())) {
1486 String details = "[" + eHolding.getStatus() + "]: GOKB status changed to [" + tipp.getStatus() + "]";
1487 createToDo(oleeResourceRecordDocument.getOleERSIdentifier(), "Change: TIPP Status", details, null);
1488 }
1489 OleHoldings oleHoldings = eHolding.getContentObject();
1490 if (oleHoldings.getExtentOfOwnership() != null && oleHoldings.getExtentOfOwnership().size()>0) {
1491 GOKbDataElement coverageStartDateElement = getDataElement(coverageStartDate);
1492 GOKbDataElement coverageStartIssueElement = getDataElement(coverageStartIssue);
1493 GOKbDataElement coverageStartVolumeeElement = getDataElement(coverageStartVolume);
1494 GOKbDataElement coverageEndDateElement = getDataElement(coverageEndDate);
1495 GOKbDataElement coverageEndIssueElement = getDataElement(coverageEndIssue);
1496 GOKbDataElement coverageEndVolumeElement = getDataElement(coverageEndVolume);
1497 Map dataMapping = new HashMap();
1498 dataMapping.put("recordType", "E-Instance");
1499 dataMapping.put("recordId", oleHoldings.getHoldingsIdentifier());
1500 List<OLEGOKbMappingValue> locallyModifiedElements = (List<OLEGOKbMappingValue>) getBusinessObjectService().findMatching(OLEGOKbMappingValue.class, dataMapping);
1501 Coverage coverage = oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0);
1502 if (locallyModifiedElements.size() == 0) {
1503 coverage.setCoverageStartDate(tipp.getStartdate().toString());
1504 coverage.setCoverageStartIssue(tipp.getStartIssue());
1505 coverage.setCoverageStartVolume(tipp.getStartVolume());
1506 coverage.setCoverageEndDate(tipp.getEndDate().toString());
1507 coverage.setCoverageEndIssue(tipp.getEndIssue());
1508 coverage.setCoverageEndVolume(tipp.getEndVolume());
1509 } else {
1510 for (OLEGOKbMappingValue localMappingValue : locallyModifiedElements) {
1511
1512 if (localMappingValue.getDataElementId().equalsIgnoreCase(coverageStartDateElement.getDataElementId())) {
1513 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1514 coverage.setCoverageStartDate(tipp.getStartdate().toString());
1515 }
1516 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(coverageStartIssueElement.getDataElementId())) {
1517 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1518 coverage.setCoverageStartIssue(tipp.getStartIssue());
1519 }
1520 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(coverageStartVolumeeElement.getDataElementId())) {
1521 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1522 coverage.setCoverageStartVolume(tipp.getStartVolume());
1523 }
1524 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(coverageEndDateElement.getDataElementId())) {
1525 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1526 coverage.setCoverageEndDate(tipp.getEndDate().toString());
1527 }
1528 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(coverageEndIssueElement.getDataElementId())) {
1529 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1530 coverage.setCoverageEndIssue(tipp.getEndIssue());
1531 }
1532 } else if (localMappingValue.getDataElementId().equalsIgnoreCase(coverageEndVolumeElement.getDataElementId())) {
1533 if (StringUtils.isEmpty(localMappingValue.getLocalValue())) {
1534 coverage.setCoverageEndVolume(tipp.getEndVolume());
1535 }
1536 }
1537 }
1538 }
1539 }
1540 try {
1541 getDocstoreClientLocator().getDocstoreClient().updateHoldings(eHolding);
1542 } catch (Exception e) {
1543 e.printStackTrace();
1544 }
1545 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "eHoldingsUpdatedCount", 1);
1546 OleGokbPlatform oleGokbPlatform = fetchPlatformForTipp(tipp);
1547 addorUpdatePlatform(oleGokbPlatform, oleeResourceRecordDocument, logId);
1548 OleGokbTitle oleGokbTitle = getOleGokbTitle(tipp.getGokbTitleId());
1549 oleeResourceSearchService.updatePublisherDetails(oleeResourceRecordDocument, oleGokbTitle.getPublisherId());
1550 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "vendorsAddedCount", 1);
1551 if (oleHoldings.getExtentOfOwnership() != null && oleHoldings.getExtentOfOwnership().size()>0) {
1552 Coverage coverage = oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0);
1553 if (!coverage.getCoverageStartDate().equalsIgnoreCase(tipp.getStartdate().toString())) {
1554 String details = "[" + eHolding.getDisplayLabel() + "]]: E-Holdings start date has changed from [" + coverage.getCoverageStartDate() + "] to [" + tipp.getStartdate() + "]";
1555 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Holdings start date", details);
1556 }
1557 if (!coverage.getCoverageStartIssue().equalsIgnoreCase(tipp.getStartIssue())) {
1558 String details = "[" + eHolding.getDisplayLabel() + "]]: E-Holdings start issue has changed from [" + coverage.getCoverageStartIssue() + "] to [" + tipp.getStartIssue() + "]";
1559 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Holdings start issue", details);
1560 }
1561 if (!coverage.getCoverageStartVolume().equalsIgnoreCase(tipp.getStartVolume())) {
1562 String details = "[" + eHolding.getDisplayLabel() + "]]: E-Holdings start volume has changed from [" + coverage.getCoverageStartVolume() + "] to [" + tipp.getStartVolume() + "]";
1563 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Holdings start volume", details);
1564 }
1565 if (!coverage.getCoverageEndDate().equalsIgnoreCase(tipp.getEndDate().toString())) {
1566 String details = "[" + eHolding.getDisplayLabel() + "]]: E-Holdings end date has changed from [" + coverage.getCoverageEndDate() + "] to [" + tipp.getEndDate() + "]";
1567 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Holdings end date", details);
1568 }
1569 if (!coverage.getCoverageEndVolume().equalsIgnoreCase(tipp.getEndVolume())) {
1570 String details = "[" + eHolding.getDisplayLabel() + "]]: E-Holdings end volume has changed from [" + coverage.getCoverageEndIssue() + "] to [" + tipp.getEndVolume() + "]";
1571 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Holdings end volume", details);
1572 }
1573 if (!coverage.getCoverageEndIssue().equalsIgnoreCase(tipp.getEndIssue())) {
1574 String details = "[" + eHolding.getDisplayLabel() + "]]: E-Holdings end issue has changed from [" + coverage.getCoverageEndIssue() + "] to [" + tipp.getEndIssue() + "]";
1575 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Holdings end issue", details);
1576 }
1577 if (oleHoldings.getLink() != null) {
1578 if (!oleHoldings.getLink().get(0).getUrl().equalsIgnoreCase(tipp.getPlatformHostUrl())) {
1579 String details = "[" + eHolding.getDisplayLabel() + "]]: E-Holdings URL has changed from [" + oleHoldings.getLink().get(0).getUrl() + "] to [" + tipp.getPlatformHostUrl() + "]";
1580 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "Metadata change: E-Holdings URL", details);
1581 }
1582 }
1583 }
1584 }
1585
1586 public void addorUpdatePlatform(OleGokbPlatform oleGokbPlatform, OLEEResourceRecordDocument oleeResourceRecordDocument, String logId) {
1587
1588 Map map = new HashMap();
1589 map.put("gokbPlatformId", oleGokbPlatform.getGokbPlatformId());
1590 List<OleGokbTipp> oleGokbTipps = (List<OleGokbTipp>) getBusinessObjectService().findMatching(OleGokbTipp.class, map);
1591 OleGokbTitle oleGokbTitle = getBusinessObjectService().findBySinglePrimaryKey(OleGokbTitle.class, oleGokbTipps.get(0));
1592 oleeResourceSearchService.updatePublisherDetails(oleeResourceRecordDocument, oleGokbTitle.getPublisherId());
1593 Map gokbMap = new HashMap();
1594 gokbMap.put(OLEConstants.GOKB_ID, oleGokbPlatform.getGokbPlatformId());
1595 List<OLEPlatformRecordDocument> platformRecordDocumentList = (List<OLEPlatformRecordDocument>) getBusinessObjectService().findMatching(OLEPlatformRecordDocument.class, gokbMap);
1596 OLEPlatformRecordDocument olePlatformRecordDocument = null;
1597 if (platformRecordDocumentList != null && platformRecordDocumentList.size() > 0) {
1598 olePlatformRecordDocument = platformRecordDocumentList.get(0);
1599 oleeResourceSearchService.updatePlatform(olePlatformRecordDocument, oleGokbPlatform.getPlatformName(), oleGokbPlatform.getStatus(), oleGokbPlatform.getSoftwarePlatform(), oleGokbPlatform.getPlatformProviderId());
1600 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "platformsUpdatedCount", 1);
1601 } else {
1602 olePlatformRecordDocument = oleeResourceSearchService.createPlatform(oleGokbPlatform.getPlatformName(), oleGokbPlatform.getGokbPlatformId(), oleGokbPlatform.getSoftwarePlatform(), oleGokbPlatform.getStatus(), oleGokbPlatform.getPlatformProviderId());
1603 updateLog(logId, oleeResourceRecordDocument.getOleERSIdentifier(), "platformsAddedCount", 1);
1604 }
1605 if (olePlatformRecordDocument != null) {
1606 updatePlatformVendorAssociation(olePlatformRecordDocument);
1607 }
1608 createOrUpdateVendor(oleGokbPlatform.getPlatformProviderId(), logId);
1609
1610 }
1611
1612 public void createToDo(String eResId, String type, String details, Integer tippId) {
1613 OleGokbReview oleGokbReview = new OleGokbReview();
1614 oleGokbReview.setDetails(details);
1615 oleGokbReview.setType(type);
1616 oleGokbReview.setOleERSIdentifier(eResId);
1617 oleGokbReview.setReviewDate(new Timestamp(System.currentTimeMillis()));
1618 if (tippId != null) {
1619 oleGokbReview.setGokbTippId(tippId);
1620 }
1621 getBusinessObjectService().save(oleGokbReview);
1622 }
1623
1624 public void createChangeLog(String eResId, String type, String details) {
1625 OleGokbChangeLog oleGokbChangeLog = new OleGokbChangeLog();
1626 oleGokbChangeLog.setType(type);
1627 oleGokbChangeLog.setDetails(details);
1628 oleGokbChangeLog.setOleERSIdentifier(eResId);
1629 oleGokbChangeLog.setChangeLogDate(new Timestamp(System.currentTimeMillis()));
1630 oleGokbChangeLog.setOrigin("System");
1631 }
1632
1633 public void updatePlatformVendorAssociation(OLEPlatformRecordDocument olePlatformRecordDocument) {
1634 if (olePlatformRecordDocument != null) {
1635 Map roleMap = new HashMap();
1636 roleMap.put("associatedEntityId", olePlatformRecordDocument.getOlePlatformId());
1637 roleMap.put("vendorRoleId", "3");
1638 List<OLEVendorAssociation> vendorAssociations = (List<OLEVendorAssociation>) getBusinessObjectService().findMatching(OLEVendorAssociation.class, roleMap);
1639 if (!(vendorAssociations != null && vendorAssociations.size() > 0)) {
1640 if (olePlatformRecordDocument.getOlePlatformId() != null && olePlatformRecordDocument.getVendorHeaderGeneratedIdentifier() != null && olePlatformRecordDocument.getVendorDetailAssignedIdentifier() != null) {
1641 OLEVendorAssociation oleVendorAssociation = new OLEVendorAssociation();
1642 oleVendorAssociation.setVendorHeaderGeneratedIdentifier(olePlatformRecordDocument.getVendorHeaderGeneratedIdentifier());
1643 oleVendorAssociation.setVendorDetailAssignedIdentifier(olePlatformRecordDocument.getVendorDetailAssignedIdentifier());
1644 oleVendorAssociation.setVendorRoleId("3");
1645 oleVendorAssociation.setAssociatedEntityId(olePlatformRecordDocument.getOlePlatformId());
1646 getBusinessObjectService().save(oleVendorAssociation);
1647 }
1648 }
1649 }
1650 }
1651
1652
1653 public void insertOrUpdateGokbDataMapping(OleHoldings oleHoldings, boolean isUpdate) {
1654
1655 String holdingsId = oleHoldings.getHoldingsIdentifier();
1656
1657 if (StringUtils.isNotEmpty(oleHoldings.getEResourceId()) && StringUtils.isNotEmpty(holdingsId) && oleHoldings.getGokbIdentifier() != null) {
1658
1659 GOKbDataElement urlElement = getDataElement(url);
1660 GOKbDataElement gokbIdElement = getDataElement(gokbId);
1661
1662 if (StringUtils.isNotEmpty(gokbId)) {
1663 saveGokbMappingValue(holdingsId, gokbIdElement, String.valueOf(oleHoldings.getGokbIdentifier()), isUpdate, "E-Instance");
1664 }
1665
1666 if (oleHoldings.getLink() != null && oleHoldings.getLink().size() > 0) {
1667 saveGokbMappingValue(holdingsId, urlElement, oleHoldings.getLink().get(0).getUrl(), isUpdate, "E-Instance");
1668 }
1669
1670
1671 if (oleHoldings.getExtentOfOwnership() != null && oleHoldings.getExtentOfOwnership().get(0) != null && oleHoldings.getExtentOfOwnership().get(0).getCoverages() != null && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage() != null && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0) != null) {
1672 Coverage coverage = oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0);
1673
1674 GOKbDataElement coverageStartDateElement = getDataElement(coverageStartDate);
1675 GOKbDataElement coverageStartIssueElement = getDataElement(coverageStartIssue);
1676 GOKbDataElement coverageStartVolumeeElement = getDataElement(coverageStartVolume);
1677 GOKbDataElement coverageEndDateElement = getDataElement(coverageEndDate);
1678 GOKbDataElement coverageEndIssueElement = getDataElement(coverageEndIssue);
1679 GOKbDataElement coverageEndVolumeElement = getDataElement(coverageEndVolume);
1680
1681 String startDate = coverage.getCoverageStartDate();
1682 String startIssue = coverage.getCoverageStartIssue();
1683 String startVolume = coverage.getCoverageStartVolume();
1684 String endDate = coverage.getCoverageEndDate();
1685 String endIssue = coverage.getCoverageEndIssue();
1686 String endVolume = coverage.getCoverageEndVolume();
1687
1688 if (StringUtils.isNotEmpty(startDate)) {
1689 saveGokbMappingValue(holdingsId, coverageStartDateElement, startDate, isUpdate, "E-Instance");
1690 }
1691 if (StringUtils.isNotEmpty(startDate)) {
1692 saveGokbMappingValue(holdingsId, coverageStartIssueElement, startIssue, isUpdate, "E-Instance");
1693 }
1694 if (StringUtils.isNotEmpty(startDate)) {
1695 saveGokbMappingValue(holdingsId, coverageStartVolumeeElement, startVolume, isUpdate, "E-Instance");
1696 }
1697 if (StringUtils.isNotEmpty(startDate)) {
1698 saveGokbMappingValue(holdingsId, coverageEndDateElement, endDate, isUpdate, "E-Instance");
1699 }
1700 if (StringUtils.isNotEmpty(startDate)) {
1701 saveGokbMappingValue(holdingsId, coverageEndIssueElement, endIssue, isUpdate, "E-Instance");
1702 }
1703 if (StringUtils.isNotEmpty(startDate)) {
1704 saveGokbMappingValue(holdingsId, coverageEndVolumeElement, endVolume, isUpdate, "E-Instance");
1705 }
1706 }
1707 }
1708 }
1709
1710
1711 private void saveGokbMappingValue(String recordId, GOKbDataElement goKbDataElement, String value, boolean isUpdate, String recType) {
1712 OLEGOKbMappingValue olegoKbMappingValue = null;
1713
1714
1715 Map map = new HashMap();
1716 map.put("recordId", recordId);
1717 map.put("dataElementId", goKbDataElement.getDataElementId());
1718 List<OLEGOKbMappingValue> olegoKbMappingValues = (List<OLEGOKbMappingValue>) getBusinessObjectService().findMatching(OLEGOKbMappingValue.class, map);
1719 if (olegoKbMappingValues != null && olegoKbMappingValues.size() > 0) {
1720 olegoKbMappingValue = olegoKbMappingValues.get(0);
1721 } else {
1722 olegoKbMappingValue = new OLEGOKbMappingValue();
1723 olegoKbMappingValue.setGokbValue(value);
1724 }
1725 if (isUpdate) {
1726 olegoKbMappingValue.setLocalValue(value);
1727 }
1728
1729 olegoKbMappingValue.setGoKbDataElement(goKbDataElement);
1730 olegoKbMappingValue.setRecordId(recordId);
1731 olegoKbMappingValue.setRecordType(recType);
1732 getBusinessObjectService().save(olegoKbMappingValue);
1733 }
1734
1735 public GOKbDataElement getDataElement(String dataElementName) {
1736 Map dataElementMap = new HashMap();
1737 dataElementMap.put("dataElementName", dataElementName);
1738 List<GOKbDataElement> goKbDataElements = (List<GOKbDataElement>) getBusinessObjectService().findMatching(GOKbDataElement.class, dataElementMap);
1739 if (goKbDataElements != null && goKbDataElements.size() > 0) {
1740 return goKbDataElements.get(0);
1741 }
1742 return null;
1743 }
1744
1745 public void insertOrUpdateGokbElementsForEResource(OLEEResourceRecordDocument oleeResourceRecordDocument, boolean isUpdate) {
1746
1747
1748 String eResourceId = oleeResourceRecordDocument.getOleERSIdentifier();
1749
1750 GOKbDataElement eResourceNameDataElement = getDataElement(E_RESOURCE_NAME);
1751 GOKbDataElement variantDataElement = getDataElement(VARIANT_NAME);
1752 GOKbDataElement publisherDataElement = getDataElement(PUBLISHER);
1753 GOKbDataElement packageScopeDataElement = getDataElement(PACKAGE_SCOPE);
1754 GOKbDataElement breakableDataElement = getDataElement(BREAKABLE);
1755 GOKbDataElement fixedTitleDataElement = getDataElement(FIXED_TITLE_LIST);
1756 GOKbDataElement packageTypeDataElement = getDataElement(PACKAGE_TYPE);
1757 GOKbDataElement eResourceDataElement = getDataElement(E_RESOURCE_GOKBID);
1758
1759 if (oleeResourceRecordDocument.getGokbIdentifier() != null) {
1760
1761 String title = oleeResourceRecordDocument.getTitle();
1762 if (StringUtils.isNotEmpty(title)) {
1763 saveGokbMappingValue(eResourceId, eResourceNameDataElement, title, isUpdate, "E-Resource");
1764 }
1765
1766 List<OLEEResourceVariantTitle> oleEResourceVariantTitleList = oleeResourceRecordDocument.getOleEResourceVariantTitleList();
1767
1768 if (oleEResourceVariantTitleList != null && oleEResourceVariantTitleList.size() > 0) {
1769 saveGokbMappingValue(eResourceId, variantDataElement, oleEResourceVariantTitleList.get(0).getOleVariantTitle(), isUpdate, "E-Resource");
1770 }
1771
1772
1773 String publisher = oleeResourceRecordDocument.getPublisher();
1774 if (StringUtils.isNotEmpty(publisher)) {
1775 saveGokbMappingValue(eResourceId, publisherDataElement, publisher, isUpdate, "E-Resource");
1776 }
1777
1778 String packageScope = oleeResourceRecordDocument.getPackageScopeId();
1779 if (StringUtils.isNotEmpty(packageScope)) {
1780 saveGokbMappingValue(eResourceId, packageScopeDataElement, packageScope, isUpdate, "E-Resource");
1781 }
1782
1783 if (oleeResourceRecordDocument.isBreakable()) {
1784 saveGokbMappingValue(eResourceId, breakableDataElement, "true", isUpdate, "E-Resource");
1785 } else {
1786 saveGokbMappingValue(eResourceId, breakableDataElement, "false", isUpdate, "E-Resource");
1787 }
1788
1789 if (oleeResourceRecordDocument.isFixedTitleList()) {
1790 saveGokbMappingValue(eResourceId, fixedTitleDataElement, "true", isUpdate, "E-Resource");
1791 } else {
1792 saveGokbMappingValue(eResourceId, fixedTitleDataElement, "false", isUpdate, "E-Resource");
1793 }
1794
1795 String packageType = oleeResourceRecordDocument.getPackageTypeId();
1796
1797 if (StringUtils.isNotEmpty(packageType)) {
1798 saveGokbMappingValue(eResourceId, packageTypeDataElement, packageType, isUpdate, "E-Resource");
1799 }
1800
1801 if (oleeResourceRecordDocument.getGokbIdentifier() != null) {
1802 saveGokbMappingValue(eResourceId, eResourceDataElement, String.valueOf(oleeResourceRecordDocument.getGokbIdentifier()), isUpdate, "E-Resource");
1803 }
1804 }
1805 }
1806
1807 public void applyGOKbChangesToOle(String eResId) {
1808 OLEEResourceSynchronizationGokbLog oleeResourceSynchronizationGokbLog = null;
1809 if (StringUtils.isNotEmpty(eResId)) {
1810 oleeResourceSynchronizationGokbLog = new OLEEResourceSynchronizationGokbLog();
1811 oleeResourceSynchronizationGokbLog.setOleERSIdentifier(eResId);
1812 } else {
1813 oleeResourceSynchronizationGokbLog = new OLEEResourceSynchronizationGokbLog();
1814 }
1815 oleeResourceSynchronizationGokbLog.setStartTime(new Timestamp(System.currentTimeMillis()));
1816 getBusinessObjectService().save(oleeResourceSynchronizationGokbLog);
1817 applyGokbChangesToVendors(eResId, oleeResourceSynchronizationGokbLog.geteResSynchronizationGokbLogId());
1818 applyGokbChangesToPlatforms(eResId, oleeResourceSynchronizationGokbLog.geteResSynchronizationGokbLogId());
1819 applyGokbChangesToEresources(eResId, oleeResourceSynchronizationGokbLog.geteResSynchronizationGokbLogId());
1820 OLEEResourceSynchronizationGokbLog oleeResourceSynchronization = getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceSynchronizationGokbLog.class, oleeResourceSynchronizationGokbLog.geteResSynchronizationGokbLogId());
1821 oleeResourceSynchronizationGokbLog.setEndTime(new Timestamp(System.currentTimeMillis()));
1822 oleeResourceSynchronizationGokbLog.setUpdatedDate(new Timestamp(System.currentTimeMillis()));
1823 getBusinessObjectService().save(oleeResourceSynchronization);
1824 }
1825
1826 public void updateLog(String updateId, String eResId, String column, int value) {
1827 OLEEResourceSynchronizationGokbLog oleeResourceSynchronizationGokbLog = getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceSynchronizationGokbLog.class, updateId);
1828 if (oleeResourceSynchronizationGokbLog != null) {
1829 if (StringUtils.isNotEmpty(eResId)) {
1830 oleeResourceSynchronizationGokbLog.setOleERSIdentifier(eResId);
1831 }
1832 if (column.equalsIgnoreCase("eResUpdatedCount")) {
1833 if (oleeResourceSynchronizationGokbLog.geteHoldingsUpdatedCount() != null) {
1834 oleeResourceSynchronizationGokbLog.seteResUpdatedCount(oleeResourceSynchronizationGokbLog.geteHoldingsUpdatedCount() + value);
1835 } else {
1836 oleeResourceSynchronizationGokbLog.seteHoldingsUpdatedCount(value);
1837 }
1838 } else if (column.equalsIgnoreCase("eHoldingsAddedCount")) {
1839 if (oleeResourceSynchronizationGokbLog.geteHoldingsAddedCount() != null) {
1840 oleeResourceSynchronizationGokbLog.seteHoldingsAddedCount(oleeResourceSynchronizationGokbLog.geteHoldingsAddedCount() + value);
1841 } else {
1842 oleeResourceSynchronizationGokbLog.seteHoldingsAddedCount(value);
1843 }
1844 } else if (column.equalsIgnoreCase("eHoldingsUpdatedCount")) {
1845 if (oleeResourceSynchronizationGokbLog.getVendorsUpdatedCount() != null) {
1846 oleeResourceSynchronizationGokbLog.seteHoldingsUpdatedCount(oleeResourceSynchronizationGokbLog.getVendorsUpdatedCount() + value);
1847 } else {
1848 oleeResourceSynchronizationGokbLog.setVendorsUpdatedCount(value);
1849 }
1850 } else if (column.equalsIgnoreCase("eHoldingsRetiredCount")) {
1851 if (oleeResourceSynchronizationGokbLog.geteHoldingsRetiredCount() != null) {
1852 oleeResourceSynchronizationGokbLog.seteHoldingsRetiredCount(oleeResourceSynchronizationGokbLog.geteHoldingsRetiredCount() + value);
1853 } else {
1854 oleeResourceSynchronizationGokbLog.seteHoldingsRetiredCount(value);
1855 }
1856 } else if (column.equalsIgnoreCase("eHoldingsDeletedCount")) {
1857 if (oleeResourceSynchronizationGokbLog.geteHoldingsDeletedCount() != null) {
1858 oleeResourceSynchronizationGokbLog.seteHoldingsDeletedCount(oleeResourceSynchronizationGokbLog.geteHoldingsDeletedCount() + value);
1859 } else {
1860 oleeResourceSynchronizationGokbLog.seteHoldingsDeletedCount(value);
1861 }
1862 } else if (column.equalsIgnoreCase("eResUpdatedCount")) {
1863 if (oleeResourceSynchronizationGokbLog.geteResUpdatedCount() != null) {
1864 oleeResourceSynchronizationGokbLog.seteResUpdatedCount(oleeResourceSynchronizationGokbLog.geteResUpdatedCount() + value);
1865 } else {
1866 oleeResourceSynchronizationGokbLog.seteResUpdatedCount(value);
1867 }
1868 } else if (column.equalsIgnoreCase("bibAddedCount")) {
1869 if (oleeResourceSynchronizationGokbLog.getBibAddedCount() != null) {
1870 oleeResourceSynchronizationGokbLog.setBibAddedCount(oleeResourceSynchronizationGokbLog.getBibAddedCount() + value);
1871 } else {
1872 oleeResourceSynchronizationGokbLog.setBibAddedCount(value);
1873 }
1874 } else if (column.equalsIgnoreCase("vendorsAddedCount")) {
1875 if (oleeResourceSynchronizationGokbLog.getVendorsAddedCount() != null) {
1876 oleeResourceSynchronizationGokbLog.setVendorsAddedCount(oleeResourceSynchronizationGokbLog.getVendorsAddedCount() + value);
1877 } else {
1878 oleeResourceSynchronizationGokbLog.setVendorsAddedCount(value);
1879 }
1880 } else if (column.equalsIgnoreCase("vendorsUpdatedCount")) {
1881 if (oleeResourceSynchronizationGokbLog.getVendorsUpdatedCount() != null) {
1882 oleeResourceSynchronizationGokbLog.setVendorsUpdatedCount(oleeResourceSynchronizationGokbLog.getVendorsUpdatedCount() + value);
1883 } else {
1884 oleeResourceSynchronizationGokbLog.setVendorsUpdatedCount(value);
1885 }
1886 } else if (column.equalsIgnoreCase("platformsAddedCount")) {
1887 if (oleeResourceSynchronizationGokbLog.getPlatformsAddedCount() != null) {
1888 oleeResourceSynchronizationGokbLog.setPlatformsAddedCount(oleeResourceSynchronizationGokbLog.getPlatformsAddedCount() + value);
1889 } else {
1890 oleeResourceSynchronizationGokbLog.setPlatformsAddedCount(value);
1891 }
1892 } else if (column.equalsIgnoreCase("platformsUpdatedCount")) {
1893 if (oleeResourceSynchronizationGokbLog.getPlatformsUpdatedCount() != null) {
1894 oleeResourceSynchronizationGokbLog.setPlatformsUpdatedCount(oleeResourceSynchronizationGokbLog.getPlatformsUpdatedCount() + value);
1895 } else {
1896 oleeResourceSynchronizationGokbLog.setPlatformsUpdatedCount(value);
1897 }
1898 }
1899 getBusinessObjectService().save(oleeResourceSynchronizationGokbLog);
1900 }
1901 }
1902
1903 public void retrieveAndApplyGokbChanges(){
1904 retrieveGokbChangesFromRemote();
1905 applyGOKbChangesToOle("");
1906 }
1907
1908 public void retrieveGokbChangesFromRemote(){
1909 Timestamp lastUpdatedTime = getGokbRdbmsService().getUpdatedDate();
1910 if(lastUpdatedTime == null) {
1911 getGokbLocalService().initLocalGokb();
1912 } else {
1913 String stringFromTimeStamp = OleGokbXmlUtil.getStringFromTimeStamp(lastUpdatedTime);
1914 getGokbLocalService().updateLocalGokb(stringFromTimeStamp+"Z");
1915 }
1916 }
1917
1918
1919 public String getParameter(String applicationId, String namespace, String componentId, String parameterName) {
1920 ParameterKey parameterKey = ParameterKey.create(applicationId, namespace, componentId,parameterName);
1921 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
1922
1923 return parameter!=null?parameter.getValue():null;
1924 }
1925
1926 public void setWorkflowCompletedStatus(OLEEResourceAccessActivation oleeResourceAccess, MaintenanceDocument maintenanceDocument, boolean newDocument) throws Exception {
1927 OLEAccessActivationConfiguration oleAccessActivationConfiguration = getBusinessObjectService().findBySinglePrimaryKey(OLEAccessActivationConfiguration.class, oleeResourceAccess.getWorkflowId());
1928 if (oleAccessActivationConfiguration != null) {
1929 oleeResourceAccess.setAccessStatus(oleAccessActivationConfiguration.getWorkflowCompletionStatus());
1930 } else {
1931 oleeResourceAccess.setAccessStatus("Workflow Completed");
1932 }
1933 oleeResourceAccess.setWorkflowName(null);
1934 oleeResourceAccess.setWorkflowId(null);
1935 oleeResourceAccess.setWorkflowDescription(null);
1936 List<OLEEResourceAccessWorkflow> accessWorkflowList = oleeResourceAccess.getOleERSAccessWorkflows();
1937 OLEEResourceAccessWorkflow oleeResourceAccessWorkflow = accessWorkflowList.get(accessWorkflowList.size() - 1);
1938 oleeResourceAccessWorkflow.setStatus("Workflow Completed");
1939 oleeResourceAccessWorkflow.setCurrentOwner(maintenanceDocument.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
1940 if (newDocument) {
1941 getDocumentService().saveDocument(maintenanceDocument);
1942 } else {
1943 getDocumentService().validateAndPersistDocument((Document) maintenanceDocument, new SaveDocumentEvent(maintenanceDocument));
1944 }
1945 deleteMaintenanceLock();
1946 }
1947
1948 public void setWorkflowCompletedStatusAfterApproval(OLEEResourceAccessActivation oleeResourceAccess, MaintenanceDocument maintenanceDocument) throws Exception {
1949 ActionRequestService actionRequestService = KEWServiceLocator.getActionRequestService();
1950 DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(maintenanceDocument.getDocumentNumber());
1951 documentBo.setDocRouteStatus("S");
1952 KEWServiceLocator.getRouteHeaderService().saveRouteHeader(documentBo);
1953 OLEAccessActivationConfiguration oleAccessActivationConfiguration = getBusinessObjectService().findBySinglePrimaryKey(OLEAccessActivationConfiguration.class, oleeResourceAccess.getWorkflowId());
1954 if (oleAccessActivationConfiguration != null) {
1955 oleeResourceAccess.setAccessStatus(oleAccessActivationConfiguration.getWorkflowCompletionStatus());
1956 } else {
1957 oleeResourceAccess.setAccessStatus("Workflow Completed");
1958 }
1959 oleeResourceAccess.setWorkflowName(null);
1960 oleeResourceAccess.setWorkflowId(null);
1961 oleeResourceAccess.setWorkflowDescription(null);
1962 List<OLEEResourceAccessWorkflow> accessWorkflowList = oleeResourceAccess.getOleERSAccessWorkflows();
1963 OLEEResourceAccessWorkflow oleeResourceAccessWorkflow = accessWorkflowList.get(accessWorkflowList.size() - 1);
1964 oleeResourceAccessWorkflow.setStatus("Workflow Completed");
1965 oleeResourceAccessWorkflow.setCurrentOwner(maintenanceDocument.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
1966 getDocumentService().validateAndPersistDocument((Document) maintenanceDocument, new SaveDocumentEvent(maintenanceDocument));
1967 List<ActionRequestValue> actionRequestValueList = actionRequestService.findAllPendingRequests(maintenanceDocument.getDocumentNumber());
1968 KEWServiceLocator.getActionRequestService().deleteByDocumentId(maintenanceDocument.getDocumentNumber());
1969 KEWServiceLocator.getActionListService().deleteByDocumentId(maintenanceDocument.getDocumentNumber());
1970 ActionTakenValue actionTakenValue;
1971 for (ActionRequestValue actionRequestValue : actionRequestValueList) {
1972 if (actionRequestValue.getPrincipalId().equalsIgnoreCase(GlobalVariables.getUserSession().getPrincipalId())) {
1973 actionTakenValue = new ActionTakenValue();
1974 actionTakenValue.setAnnotation("Approved status : " + oleeResourceAccess.getAccessStatus());
1975 actionTakenValue.setActionDate(new Timestamp(System.currentTimeMillis()));
1976 actionTakenValue.setActionTaken("A");
1977 actionTakenValue.setDocumentId(actionRequestValue.getDocumentId());
1978 actionTakenValue.setPrincipalId(actionRequestValue.getPrincipalId());
1979 actionTakenValue.setDocVersion(1);
1980 KEWServiceLocator.getActionTakenService().saveActionTaken(actionTakenValue);
1981 }
1982 }
1983 deleteMaintenanceLock();
1984 }
1985
1986 public void deleteMaintenanceLock() {
1987 List<MaintenanceLock> maintenanceLocks = (List<MaintenanceLock>) getBusinessObjectService().findAll(MaintenanceLock.class);
1988 List<MaintenanceLock> deleteMaintenanceLockList = new ArrayList<MaintenanceLock>();
1989 if (maintenanceLocks != null && maintenanceLocks.size() > 0) {
1990 for (MaintenanceLock maintenanceLock : maintenanceLocks) {
1991 if (maintenanceLock.getLockingRepresentation().contains("org.kuali.ole.select.bo.OLEEResourceAccessActivation")) {
1992 deleteMaintenanceLockList.add(maintenanceLock);
1993 }
1994 }
1995 }
1996 if (deleteMaintenanceLockList.size() > 0) {
1997 getBusinessObjectService().delete(deleteMaintenanceLockList);
1998 }
1999 }
2000
2001 public void setAccessInfo(OLEEResourceRecordDocument oleeResourceRecordDocument) {
2002 if (StringUtils.isNotBlank(oleeResourceRecordDocument.getOleAccessActivationDocumentNumber())) {
2003
2004 try {
2005 boolean hasPermission = false;
2006 PermissionService service = KimApiServiceLocator.getPermissionService();
2007 if (GlobalVariables.getUserSession() != null && StringUtils.isNotBlank(GlobalVariables.getUserSession().getPrincipalId())) {
2008 hasPermission = service.hasPermission(GlobalVariables.getUserSession().getPrincipalId(), OLEConstants.SELECT_NMSPC, "Edit E-Resource Record");
2009 }
2010 MaintenanceDocumentBase maintenanceDocumentBase = (MaintenanceDocumentBase) getDocumentService().getByDocumentHeaderId(oleeResourceRecordDocument.getOleAccessActivationDocumentNumber());
2011 String accessActivationDocumentStatus = maintenanceDocumentBase.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
2012 if (!(hasPermission && accessActivationDocumentStatus.equalsIgnoreCase("s"))) {
2013 oleeResourceRecordDocument.setAccessReadOnly(true);
2014 }
2015 OLEEResourceAccessActivation oleeResourceAccessActivation = (OLEEResourceAccessActivation) maintenanceDocumentBase.getNewMaintainableObject().getDataObject();
2016 if (oleeResourceAccessActivation != null) {
2017 oleeResourceRecordDocument.setAccessStatus(oleeResourceAccessActivation.getAccessStatus());
2018 oleeResourceRecordDocument.setAuthenticationTypeId(oleeResourceAccessActivation.getAuthenticationTypeId());
2019 oleeResourceRecordDocument.setAccessLocation(oleeResourceAccessActivation.getAccessLocation());
2020 oleeResourceRecordDocument.setAccessTypeId(oleeResourceAccessActivation.getAccessTypeId());
2021 oleeResourceRecordDocument.setNumOfSimultaneousUsers(oleeResourceAccessActivation.getNumOfSimultaneousUsers());
2022 oleeResourceRecordDocument.setTechRequirements(oleeResourceAccessActivation.getTechRequirements());
2023 }
2024 } catch (WorkflowException e) {
2025 e.printStackTrace();
2026 }
2027 }
2028 }
2029
2030 public void createOrUpdateAccessWorkflow(OLEEResourceRecordDocument oleeResourceRecordDocument, boolean titleChange) {
2031 if (StringUtils.isNotBlank(oleeResourceRecordDocument.getOleAccessActivationDocumentNumber())) {
2032 try {
2033 String titleDesc = OLEConstants.ACCESS_ACTIVATION_DESCRIPTION + " for E-Resource Name : "+oleeResourceRecordDocument.getTitle();
2034 MaintenanceDocumentBase maintenanceDocumentBase = (MaintenanceDocumentBase) getDocumentService().getByDocumentHeaderId(oleeResourceRecordDocument.getOleAccessActivationDocumentNumber());
2035 String accessActivationDocumentStatus = maintenanceDocumentBase.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
2036 if (accessActivationDocumentStatus.equalsIgnoreCase("s")) {
2037 OLEEResourceAccessActivation oleeResourceAccessActivation = (OLEEResourceAccessActivation) maintenanceDocumentBase.getNewMaintainableObject().getDataObject();
2038 if (oleeResourceAccessActivation != null) {
2039 maintenanceDocumentBase.getDocumentHeader().setDocumentDescription(titleDesc);
2040 oleeResourceAccessActivation.setAuthenticationTypeId(oleeResourceRecordDocument.getAuthenticationTypeId());
2041 oleeResourceAccessActivation.setAccessLocation(oleeResourceRecordDocument.getAccessLocation());
2042 oleeResourceAccessActivation.setAccessTypeId(oleeResourceRecordDocument.getAccessTypeId());
2043 oleeResourceAccessActivation.setNumOfSimultaneousUsers(oleeResourceRecordDocument.getNumOfSimultaneousUsers());
2044 oleeResourceAccessActivation.setTechRequirements(oleeResourceRecordDocument.getTechRequirements());
2045 getDocumentService().validateAndPersistDocument((Document)maintenanceDocumentBase,new SaveDocumentEvent(maintenanceDocumentBase));
2046 }
2047 } else if(titleChange){
2048 OLEEResourceAccessActivation oleeResourceAccessActivation = (OLEEResourceAccessActivation) maintenanceDocumentBase.getNewMaintainableObject().getDataObject();
2049 if (oleeResourceAccessActivation != null) {
2050 maintenanceDocumentBase.getDocumentHeader().setDocumentDescription(titleDesc);
2051 getDocumentService().validateAndPersistDocument((Document)maintenanceDocumentBase,new SaveDocumentEvent(maintenanceDocumentBase));
2052 KEWServiceLocator.getActionListService().updateActionItemsForTitleChange(maintenanceDocumentBase.getDocumentNumber(),titleDesc);
2053 }
2054 }
2055 } catch (Exception e) {
2056 e.printStackTrace();
2057 }
2058 } else {
2059 if (StringUtils.isNotBlank(oleeResourceRecordDocument.getAccessStatus()) || StringUtils.isNotBlank(oleeResourceRecordDocument.getAuthenticationTypeId())
2060 || oleeResourceRecordDocument.getAccessLocation().size() > 0 || StringUtils.isNotBlank(oleeResourceRecordDocument.getAccessTypeId())
2061 || StringUtils.isNotBlank(oleeResourceRecordDocument.getNumOfSimultaneousUsers()) || StringUtils.isNotBlank(oleeResourceRecordDocument.getTechRequirements())) {
2062 deleteMaintenanceLock();
2063 DocumentService documentService = GlobalResourceLoader.getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
2064 try {
2065 MaintenanceDocument newDocument = (MaintenanceDocument) documentService.getNewDocument("OLE_ERES_ACCESS_MD");
2066 newDocument.getDocumentHeader().setDocumentDescription(OLEConstants.ACCESS_ACTIVATION_DESCRIPTION + " for E-Resource Name : "+oleeResourceRecordDocument.getTitle());
2067 OLEEResourceAccessActivation oleeResourceAccessActivation = (OLEEResourceAccessActivation) newDocument.getNewMaintainableObject().getDataObject();
2068 oleeResourceAccessActivation.setAuthenticationTypeId(oleeResourceRecordDocument.getAuthenticationTypeId());
2069 oleeResourceAccessActivation.setAccessLocation(oleeResourceRecordDocument.getAccessLocation());
2070 oleeResourceAccessActivation.setAccessTypeId(oleeResourceRecordDocument.getAccessTypeId());
2071 oleeResourceAccessActivation.setNumOfSimultaneousUsers(oleeResourceRecordDocument.getNumOfSimultaneousUsers());
2072 oleeResourceAccessActivation.setTechRequirements(oleeResourceRecordDocument.getTechRequirements());
2073 oleeResourceAccessActivation.setOleERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier());
2074 getDocumentService().saveDocument(newDocument);
2075 oleeResourceRecordDocument.setOleAccessActivationDocumentNumber(newDocument.getDocumentNumber());
2076 } catch (Exception e) {
2077 e.printStackTrace();
2078 }
2079 }
2080 }
2081
2082 }
2083 }