1 package org.kuali.ole.describe.controller;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.commons.lang.StringUtils;
5 import org.apache.log4j.Logger;
6 import org.kuali.ole.DocumentUniqueIDPrefix;
7 import org.kuali.ole.OLEConstants;
8 import org.kuali.ole.describe.bo.*;
9 import org.kuali.ole.describe.form.*;
10 import org.kuali.ole.describe.service.DiscoveryHelperService;
11 import org.kuali.ole.docstore.common.client.DocstoreClient;
12 import org.kuali.ole.docstore.common.document.*;
13 import org.kuali.ole.docstore.common.document.HoldingsTree;
14 import org.kuali.ole.docstore.common.document.content.instance.*;
15 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
16 import org.kuali.ole.docstore.common.exception.DocstoreException;
17 import org.kuali.ole.docstore.engine.client.DocstoreLocalClient;
18 import org.kuali.ole.docstore.model.enums.DocCategory;
19 import org.kuali.ole.docstore.model.enums.DocFormat;
20 import org.kuali.ole.docstore.model.enums.DocType;
21 import org.kuali.ole.describe.bo.InstanceEditorFormDataHandler;
22 import org.kuali.ole.describe.form.InstanceEditorForm;
23 import org.kuali.ole.select.bo.OLEEditorResponse;
24 import org.kuali.ole.select.businessobject.*;
25 import org.kuali.ole.select.document.OLEEResourceInstance;
26 import org.kuali.ole.select.document.OLEEResourceRecordDocument;
27 import org.kuali.ole.service.OLEEResourceSearchService;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.rice.core.api.config.property.ConfigurationService;
30 import org.kuali.rice.core.api.exception.RiceRuntimeException;
31 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
32 import org.kuali.rice.kim.api.identity.Person;
33 import org.kuali.rice.kim.api.identity.PersonService;
34 import org.kuali.rice.krad.service.*;
35 import org.kuali.rice.krad.util.GlobalVariables;
36 import org.kuali.rice.krad.util.KRADConstants;
37 import org.kuali.rice.krad.web.form.UifFormBase;
38 import org.springframework.validation.BindingResult;
39 import org.springframework.web.bind.annotation.ModelAttribute;
40 import org.springframework.web.servlet.ModelAndView;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44 import java.sql.Date;
45 import java.util.*;
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public class WorkEInstanceOlemlEditor
61 extends AbstractEditor
62 implements DocumentEditor {
63
64 private static final Logger LOG = Logger.getLogger(WorkEInstanceOlemlEditor.class);
65
66
67 private InstanceEditorFormDataHandler instanceEditorFormDataHandler;
68 private EInstanceFormDataHandler eInstanceFormDataHandler;
69 private DiscoveryHelperService discoveryHelperService;
70 private OLEEResourceSearchService oleEResourceSearchService;
71 private DocumentService documentService;
72 private HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
73 private DocstoreClient docstoreClient = getDocstoreLocalClient();
74
75 private static WorkEInstanceOlemlEditor workEInstanceOlemlEditor = new WorkEInstanceOlemlEditor();
76
77 public static WorkEInstanceOlemlEditor getInstance() {
78 return workEInstanceOlemlEditor;
79 }
80
81 public OLEEResourceSearchService getOleEResourceSearchService() {
82 if (oleEResourceSearchService == null) {
83 oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
84 }
85 return oleEResourceSearchService;
86 }
87
88 public DocumentService getDocumentService() {
89 if (this.documentService == null) {
90 this.documentService = KRADServiceLocatorWeb.getDocumentService();
91 }
92 return this.documentService;
93 }
94
95 public void setDocumentService(DocumentService documentService) {
96 this.documentService = documentService;
97 }
98
99 private WorkEInstanceOlemlEditor() {
100 }
101
102 @Override
103 public EditorForm copy(EditorForm editorForm) {
104 loadDocument(editorForm);
105 WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
106 workEInstanceOlemlForm.getSelectedEHoldings().setEResourceId(workEInstanceOlemlForm.geteResourceId()!=null&&!workEInstanceOlemlForm.geteResourceId().isEmpty()?workEInstanceOlemlForm.geteResourceId():null);
107
108 editorForm.seteResourceId(workEInstanceOlemlForm.geteResourceId()!=null&&!workEInstanceOlemlForm.geteResourceId().isEmpty()?workEInstanceOlemlForm.geteResourceId():null);
109 editorForm.seteResourceTitle(workEInstanceOlemlForm.geteResourceTitle()!=null&&!workEInstanceOlemlForm.geteResourceTitle().isEmpty()?workEInstanceOlemlForm.geteResourceTitle():null);
110 editorForm.setDocId(null);
111 editorForm.setShowEditorFooter(false);
112 editorForm.setFromSearch(false);
113
114
115
116 return editorForm;
117 }
118
119 @Override
120 public EditorForm loadDocument(EditorForm editorForm) {
121 LOG.info("loadDocument in E-Instance Editor");
122 WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
123 String docId = editorForm.getDocId();
124 String bibId = editorForm.getBibId();
125 String tokenId = editorForm.getTokenId();
126 workEInstanceOlemlForm.setTokenId(tokenId);
127 workEInstanceOlemlForm.setBibId(bibId);
128 String docType = editorForm.getDocType();
129 editorForm.setHasLink(true);
130 if ((StringUtils.isBlank(editorForm.getTitle()))) {
131 getTitleInfo(editorForm);
132 }
133 if (editorForm.isFromDublin()) {
134 editorForm.setHasLink(false);
135 }
136 if (editorForm.getTitle() != null && editorForm.getTitle().contains("<")) {
137 String title = org.apache.commons.lang.StringEscapeUtils.escapeHtml((editorForm.getTitle()));
138 editorForm.setTitle(title);
139 }
140 editorForm.setShowEditorFooter(false);
141 editorForm.setFromSearch(false);
142 String eResId = null;
143 workEInstanceOlemlForm.seteResourceId(editorForm.geteResourceId());
144 Bib bib = null;
145 List<BibTree> bibTreeList = null;
146 BibTree bibTree = null;
147 if (StringUtils.isNotEmpty(bibId)) {
148 try {
149 bibTree = docstoreClient.retrieveBibTree(bibId);
150 bibTreeList = new ArrayList<>();
151 bibTreeList.add(bibTree);
152 bib = bibTree.getBib();
153 workEInstanceOlemlForm.setBibTreeList(bibTreeList);
154 editorForm.setTitle(bibTree.getBib().getTitle() + " / " + bibTree.getBib().getAuthor());
155 } catch (Exception e) {
156 LOG.error("Exception :", e);
157 e.printStackTrace();
158 }
159 }
160 try {
161 if (docId != null && docId.length() > 0) {
162
163
164 Holdings holdings = docstoreClient.retrieveHoldings(docId);
165 String docStoreData = holdings.getContent();
166 OleHoldings eHoldings = holdingOlemlRecordProcessor.fromXML(docStoreData);
167 if (eResId == null || eResId.length() == 0) {
168 eResId = eHoldings.getEResourceId();
169 workEInstanceOlemlForm.seteResourceId(eResId);
170 }
171 workEInstanceOlemlForm.setHoldingsId(DocumentUniqueIDPrefix.getDocumentId(holdings.getId()));
172 editorForm.setStaffOnlyFlagForHoldings(holdings.isStaffOnly());
173 getOleEResourceSearchService().getEResourcesFields(eResId, eHoldings, workEInstanceOlemlForm);
174 getOleEResourceSearchService().getEResourcesLicenseFields(eResId, workEInstanceOlemlForm);
175 if (eHoldings.getExtentOfOwnership() != null && eHoldings.getExtentOfOwnership().size() > 0
176 && eHoldings.getExtentOfOwnership().get(0).getCoverages() != null
177 && eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().size() == 0) {
178 eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().add(new Coverage());
179 }
180 if (eHoldings.getExtentOfOwnership() != null && eHoldings.getExtentOfOwnership().size() > 0
181 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses() != null
182 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().size() == 0) {
183 eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().add(new PerpetualAccess());
184 }
185 if (eHoldings.getNote() != null && eHoldings.getNote().size() == 0) {
186 eHoldings.getNote().add(new Note());
187 }
188
189 if(eHoldings.getLink().size() == 0){
190 List<Link> links = new ArrayList<>();
191 Link link = new Link();
192 link.setText("");
193 link.setUrl("");
194 links.add(link);
195 eHoldings.setLink(links);
196 }
197 workEInstanceOlemlForm.setSelectedEHoldings(eHoldings);
198
199 if(workEInstanceOlemlForm.getSelectedEHoldings() != null && workEInstanceOlemlForm.getSelectedEHoldings().getHoldingsAccessInformation() != null
200 && workEInstanceOlemlForm.getSelectedEHoldings().getHoldingsAccessInformation().getProxiedResource() != null
201 && workEInstanceOlemlForm.getSelectedEHoldings().getHoldingsAccessInformation().getProxiedResource().equalsIgnoreCase(OLEConstants.OLEEResourceRecord.ON)) {
202 workEInstanceOlemlForm.setProxiedResource(true);
203 }
204 workEInstanceOlemlForm.getSelectedEHoldings().setStatusDate(new Date(System.currentTimeMillis()).toString());
205 getEInstanceFormDataHandler().setLocationDetails(workEInstanceOlemlForm);
206 if(editorForm.getMethodToCall().equalsIgnoreCase("copy")){
207 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.copy.message");
208 }
209 else{
210 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.load.message");
211 }
212 editorForm.setHoldingCreatedDate(holdings.getCreatedOn());
213 editorForm.setHoldingCreatedBy(holdings.getCreatedBy());
214 editorForm.setHoldingUpdatedDate(holdings.getUpdatedOn());
215 editorForm.setHoldingUpdatedBy(holdings.getUpdatedBy());
216 getOleEResourceSearchService().getAcquisitionInfoFromPOAndInvoice(docId, workEInstanceOlemlForm);
217 } else {
218 OleHoldings eHoldings = new OleHoldings();
219 eHoldings.setStatusDate(new Date(System.currentTimeMillis()).toString());
220 eHoldings.setEResourceId(editorForm.geteResourceId());
221
222 getOleEResourceSearchService().getEResourcesFields(editorForm.geteResourceId(), eHoldings, workEInstanceOlemlForm);
223 getOleEResourceSearchService().getEResourcesLicenseFields(editorForm.geteResourceId(), workEInstanceOlemlForm);
224 if (eHoldings.getExtentOfOwnership() != null && eHoldings.getExtentOfOwnership().size() > 0
225 && eHoldings.getExtentOfOwnership().get(0).getCoverages() != null
226 && eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().size() == 0) {
227 eHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().add(new Coverage());
228 }
229 if (eHoldings.getExtentOfOwnership() != null && eHoldings.getExtentOfOwnership().size() > 0
230 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses() != null
231 && eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().size() == 0) {
232 eHoldings.getExtentOfOwnership().get(0).getPerpetualAccesses().getPerpetualAccess().add(new PerpetualAccess());
233 }
234 if (eHoldings.getNote() != null && eHoldings.getNote().size() == 0) {
235 eHoldings.getNote().add(new Note());
236 }
237 List<Link> links = new ArrayList<>();
238 Link link = new Link();
239 link.setText("");
240 link.setUrl("");
241 links.add(link);
242 eHoldings.setLink(links);
243 workEInstanceOlemlForm.setSelectedEHoldings(eHoldings);
244 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
245 getEInstanceFormDataHandler().setLocationDetails(workEInstanceOlemlForm);
246 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "eholdings.record.new.load.message");
247 editorForm.setHoldingCreatedDate("");
248 editorForm.setHoldingCreatedBy("");
249 }
250 } catch (DocstoreException e) {
251 LOG.error(e);
252 DocstoreException docstoreException = (DocstoreException) e;
253 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
254 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
255 } else {
256 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
257 }
258 return workEInstanceOlemlForm;
259 }
260 catch (Exception e) {
261 LOG.error("loadDocument Instance Exception:" + e);
262 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.load.fail.message ");
263 return workEInstanceOlemlForm;
264 }
265 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
266 workEInstanceOlemlForm.setIssn(bib.getIssn());
267 editorForm.seteResourceTitle(workEInstanceOlemlForm.geteResourceTitle());
268 String directory = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(org.kuali.ole.sys.OLEConstants.EXTERNALIZABLE_HELP_URL_KEY);
269 editorForm.setExternalHelpUrl(directory+"/reference/webhelp/OLE/content/ch04s01.html#_EInstanceEditor");
270 editorForm.setHeaderText("E-Holdings");
271 if (workEInstanceOlemlForm.getTokenId() != null && !workEInstanceOlemlForm.getTokenId().isEmpty()) {
272 editorForm.setTokenId(workEInstanceOlemlForm.getTokenId());
273 }
274 return workEInstanceOlemlForm;
275 }
276
277 private void getTitleInfo(EditorForm editorForm) {
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299 }
300
301 @Override
302 public EditorForm saveDocument(EditorForm editorForm) {
303 WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
304 String docId = editorForm.getDocId();
305 String docType = editorForm.getDocType();
306 String bibId = editorForm.getBibId();
307 String editorStatusMessage = "";
308 List<BibTree> bibTreeList = null;
309 BibTree bibTree = null;
310 String user = GlobalVariables.getUserSession().getPrincipalName();
311 if (StringUtils.isNotEmpty(bibId)) {
312 try {
313 bibTree = docstoreClient.retrieveBibTree(bibId);
314 bibTreeList = new ArrayList<>();
315 bibTreeList.add(bibTree);
316 workEInstanceOlemlForm.setBibTreeList(bibTreeList);
317 editorForm.setTitle(bibTree.getBib().getTitle() + " / " + bibTree.getBib().getAuthor());
318 } catch (Exception e) {
319 LOG.error("Exception :", e);
320 e.printStackTrace();
321 }
322 }
323 long startTime = System.currentTimeMillis();
324 try {
325 if (docId != null && docId.length() > 0) {
326 OleHoldings eHoldings = workEInstanceOlemlForm.getSelectedEHoldings();
327 boolean dateFlag = getOleEResourceSearchService().validateDates(eHoldings);
328 if (dateFlag) {
329 getOleEResourceSearchService().getEResourcesFields(editorForm.geteResourceId(), eHoldings, workEInstanceOlemlForm);
330 String content = getInstanceEditorFormDataHandler().buildHoldingContent(eHoldings);
331 getOleEResourceSearchService().getEResourcesLicenseFields(editorForm.geteResourceId(), workEInstanceOlemlForm);
332 Holdings eHoldingsDoc = new EHoldings();
333 eHoldingsDoc.setId(editorForm.getDocId());
334 eHoldingsDoc.setType(editorForm.getDocType());
335 eHoldingsDoc.setFormat(editorForm.getDocFormat());
336 eHoldingsDoc.setCategory(editorForm.getDocCategory());
337 eHoldingsDoc.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
338 eHoldingsDoc.setUpdatedBy(user);
339 Bib bib = new BibMarc();
340 bib.setId(workEInstanceOlemlForm.getBibId());
341 eHoldingsDoc.setBib(bib);
342 eHoldings = (OleHoldings) holdingOlemlRecordProcessor.fromXML(content);
343 eHoldings = getEHolding(editorForm, eHoldings);
344 String newContent = holdingOlemlRecordProcessor.toXML(eHoldings);
345 eHoldingsDoc.setContent(newContent);
346 docstoreClient.updateHoldings(eHoldingsDoc);
347 workEInstanceOlemlForm.getSelectedEHoldings().setHoldingsIdentifier(eHoldingsDoc.getId());
348
349 addEHoldingsToBibTree(workEInstanceOlemlForm.getBibTreeList(), eHoldingsDoc);
350 editorStatusMessage = "holdings.record.update.message";
351 } else {
352 return workEInstanceOlemlForm;
353 }
354 } else {
355 OleHoldings eHoldings = workEInstanceOlemlForm.getSelectedEHoldings();
356 boolean dateFlag = getOleEResourceSearchService().validateDates(eHoldings);
357 if (dateFlag) {
358 getOleEResourceSearchService().getEResourcesFields(editorForm.geteResourceId(), eHoldings, workEInstanceOlemlForm);
359 getOleEResourceSearchService().getEResourcesLicenseFields(editorForm.geteResourceId(), workEInstanceOlemlForm);
360 String content = getInstanceEditorFormDataHandler().buildHoldingContent(eHoldings);
361 Holdings eHoldingsDoc = new EHoldings();
362 eHoldingsDoc.setCategory(DocCategory.WORK.getCode());
363 eHoldingsDoc.setType(DocType.EHOLDINGS.getCode());
364 eHoldingsDoc.setFormat(DocFormat.OLEML.getCode());
365 eHoldingsDoc.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
366 eHoldingsDoc.setCreatedBy(user);
367 Bib bib = new BibMarc();
368 bib.setId(workEInstanceOlemlForm.getBibId());
369 eHoldingsDoc.setBib(bib);
370 eHoldings = (OleHoldings) holdingOlemlRecordProcessor.fromXML(content);
371 eHoldings = getEHolding(editorForm, eHoldings);
372 String newContent = holdingOlemlRecordProcessor.toXML(eHoldings);
373 eHoldingsDoc.setContent(newContent);
374 docstoreClient.createHoldings(eHoldingsDoc);
375 editorForm.setDocId(eHoldingsDoc.getId());
376 workEInstanceOlemlForm.setHoldingsId(DocumentUniqueIDPrefix.getDocumentId(eHoldingsDoc.getId()));
377 processResponse(eHoldingsDoc.getId(), eHoldingsDoc.getBib().getId(), editorForm.getTokenId(), editorForm.getLinkToOrderOption());
378 workEInstanceOlemlForm.getSelectedEHoldings().setHoldingsIdentifier(eHoldingsDoc.getId());
379 HoldingsTree holdingsTree = new HoldingsTree();
380 holdingsTree.setHoldings(eHoldingsDoc);
381 List<HoldingsTree> holdingsTreeList = new ArrayList<>();
382 holdingsTreeList.add(holdingsTree);
383 bibTree.getHoldingsTrees().addAll(holdingsTreeList);
384 editorStatusMessage = "record.create.message";
385 } else {
386 return workEInstanceOlemlForm;
387 }
388 }
389 if(editorForm.getDocId()!=null){
390 Holdings holdingsDoc = docstoreClient.retrieveHoldings(editorForm.getDocId());
391 editorForm.setHoldingUpdatedDate(holdingsDoc.getUpdatedOn());
392 editorForm.setHoldingUpdatedBy(holdingsDoc.getUpdatedBy());
393 editorForm.setHoldingCreatedDate(holdingsDoc.getCreatedOn());
394 editorForm.setHoldingCreatedBy(holdingsDoc.getCreatedBy());
395 }
396
397 }
398 catch (DocstoreException e) {
399 LOG.error(e);
400 DocstoreException docstoreException = (DocstoreException) e;
401 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
402 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
403 } else {
404 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
405 }
406 return workEInstanceOlemlForm;
407 }
408 catch (Exception e) {
409 LOG.error("Exception :", e);
410 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, "docstore.response", e.getMessage());
411 return workEInstanceOlemlForm;
412
413 }
414 long endTime = System.currentTimeMillis();
415 editorForm.setSolrTime(String.valueOf((endTime-startTime)/1000));
416
417 try {
418 getEInstanceFormDataHandler().setLocationDetails(workEInstanceOlemlForm);
419 String eResId = workEInstanceOlemlForm.geteResourceId();
420 editorForm.seteResourceId(null);
421 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
422
423 GlobalVariables.getMessageMap().getInfoMessages().clear();
424 if (eResId != null && !eResId.isEmpty()) {
425 Map<String, String> tempId = new HashMap<String, String>();
426 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResId);
427 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
428
429 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
430 tempDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(tempDocument.getDocumentNumber()));
431 tempDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(tempDocument.getDocumentNumber(), principalPerson));
432 if (tempDocument != null) {
433 try {
434 tempDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.CREATE_NEW_INSTANCE);
435 tempDocument.seteInstanceFlag(true);
436 for (OLEEResourceInstance oleeResourceInstance : tempDocument.getOleERSInstances()) {
437 if (oleeResourceInstance.getInstanceId().equals(editorForm.getDocId())) {
438 processResponse(editorForm.getDocId(), editorForm.getBibId(), tempDocument.getDocumentNumber(), editorForm.getLinkToOrderOption());
439 }
440 }
441 getOleEResourceSearchService().getNewInstance(tempDocument, tempDocument.getDocumentNumber());
442 getDocumentService().updateDocument(tempDocument);
443 } catch (Exception e) {
444 LOG.error("Exception :", e);
445 throw new RiceRuntimeException(
446 "Exception trying to save document: " + tempDocument
447 .getDocumentNumber(), e);
448 }
449 }
450 }
451 }
452 catch (DocstoreException e) {
453 LOG.error(e);
454 DocstoreException docstoreException = (DocstoreException) e;
455 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
456 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
457 } else {
458 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
459 }
460 return workEInstanceOlemlForm;
461 }
462 catch (Exception e) {
463 LOG.error("Exception :", e);
464 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, "docstore.response", e.getMessage());
465 return workEInstanceOlemlForm;
466 }
467 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, editorStatusMessage);
468
469 return workEInstanceOlemlForm;
470 }
471
472
473
474
475
476
477 private void addEHoldingsToBibTree(List<BibTree> bibTreeList, Holdings eHoldings) {
478 if (CollectionUtils.isNotEmpty(bibTreeList)) {
479 for (BibTree bibTree : bibTreeList) {
480 if (CollectionUtils.isNotEmpty(bibTree.getHoldingsTrees())) {
481 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
482 if (null != holdingsTree.getHoldings() && null != eHoldings) {
483 String holdingsId = holdingsTree.getHoldings().getId();
484 String eHoldingsId = eHoldings.getId();
485 if (null != holdingsId && null != eHoldingsId) {
486 if (holdingsId.equals(eHoldingsId)) {
487 holdingsTree.setHoldings(eHoldings);
488 }
489 }
490 }
491 }
492 }
493 }
494 }
495 }
496
497 public void processResponse(String instanceId, String bibId, String tokenId, String linkToOrderOption) throws Exception {
498 OLEEditorResponse oleEditorResponse = new OLEEditorResponse();
499 oleEditorResponse.setTokenId(tokenId);
500 oleEditorResponse.setLinkedInstanceId(instanceId);
501 oleEditorResponse.setBib(docstoreClient.retrieveBib(bibId));
502 oleEditorResponse.setLinkToOrderOption(linkToOrderOption);
503 HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>();
504 oleEditorResponseMap.put(tokenId, oleEditorResponse);
505 OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap);
506 }
507 public OleHoldings getEHolding(EditorForm editorForm,OleHoldings eHoldings) {
508 WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
509 if (null != eHoldings.getHoldingsAccessInformation()) {
510 if (workEInstanceOlemlForm.isProxiedResource()) {
511 eHoldings.getHoldingsAccessInformation().setProxiedResource(OLEConstants.OLEEResourceRecord.ON);
512 } else {
513 eHoldings.getHoldingsAccessInformation().setProxiedResource(OLEConstants.OLEEResourceRecord.OFF);
514 }
515 }
516 if(editorForm.getAccessLocationFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
517 eHoldings.getHoldingsAccessInformation().setAccessLocation(null);
518 }
519 if(editorForm.getStatisticalCodeFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
520 eHoldings.getStatisticalSearchingCode().setCodeValue(null);
521 }
522 if(editorForm.getNoOfUserFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
523 eHoldings.getHoldingsAccessInformation().setNumberOfSimultaneousUser(null);
524 }
525 if(editorForm.getAuthenticationTypeFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
526 eHoldings.getHoldingsAccessInformation().setAuthenticationType(null);
527 }
528 if(editorForm.getPerpetualDateEndFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
529 for(ExtentOfOwnership extentOfOwnershipList:eHoldings.getExtentOfOwnership()){
530 for(PerpetualAccess perpetualAccess:extentOfOwnershipList.getPerpetualAccesses().getPerpetualAccess()) {
531 perpetualAccess.setPerpetualAccessEndDateString(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessEndDateString())?perpetualAccess.getPerpetualAccessEndDateString():"");
532 perpetualAccess.setPerpetualAccessEndDateFormat(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessEndDateFormat())?perpetualAccess.getPerpetualAccessEndDateFormat():"");
533 perpetualAccess.setPerpetualAccessEndIssue(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessEndIssue())?perpetualAccess.getPerpetualAccessEndIssue():"");
534 perpetualAccess.setPerpetualAccessEndVolume(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessEndVolume())?perpetualAccess.getPerpetualAccessEndVolume():"");
535 perpetualAccess.setPerpetualAccessEndDate(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessEndDate())?perpetualAccess.getPerpetualAccessEndDate():"");
536 }
537 }
538 }
539 if(editorForm.getPerpetualDateStartFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
540 for(ExtentOfOwnership extentOfOwnershipList:eHoldings.getExtentOfOwnership()){
541 for(PerpetualAccess perpetualAccess:extentOfOwnershipList.getPerpetualAccesses().getPerpetualAccess()) {
542 perpetualAccess.setPerpetualAccessStartDateString(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessStartDateString())?perpetualAccess.getPerpetualAccessStartDateString():"");
543 perpetualAccess.setPerpetualAccessStartDateFormat(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessStartDateFormat())?perpetualAccess.getPerpetualAccessStartDateFormat():"");
544 perpetualAccess.setPerpetualAccessStartIssue(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessStartIssue())?perpetualAccess.getPerpetualAccessStartIssue():"");
545 perpetualAccess.setPerpetualAccessStartVolume(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessStartVolume())?perpetualAccess.getPerpetualAccessStartVolume():"");
546 perpetualAccess.setPerpetualAccessStartDate(StringUtils.isNotBlank(perpetualAccess.getPerpetualAccessStartDate())?perpetualAccess.getPerpetualAccessStartDate():"");
547 }
548 }
549 }
550 if(editorForm.getCoverageDateStartFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
551 for(ExtentOfOwnership extentOfOwnershipList:eHoldings.getExtentOfOwnership()){
552 for(Coverage coverage:extentOfOwnershipList.getCoverages().getCoverage()) {
553 coverage.setCoverageStartIssue(StringUtils.isNotBlank(coverage.getCoverageStartIssue())?coverage.getCoverageStartIssue():"");
554 coverage.setCoverageStartDateString(StringUtils.isNotBlank(coverage.getCoverageStartDateString())?coverage.getCoverageStartDateString():"");
555 coverage.setCoverageStartDateFormat(StringUtils.isNotBlank(coverage.getCoverageStartDateFormat())?coverage.getCoverageStartDateFormat():"");
556 coverage.setCoverageStartVolume(StringUtils.isNotBlank(coverage.getCoverageStartVolume())?coverage.getCoverageStartVolume():"");
557 coverage.setCoverageStartDate(StringUtils.isNotBlank(coverage.getCoverageStartDate())?coverage.getCoverageStartDate():"");
558 }
559 }
560 }
561 if(editorForm.getCoverageDateEndFlag().equalsIgnoreCase(OLEConstants.FALSE) && editorForm.geteResourceTitle() != null){
562 for(ExtentOfOwnership extentOfOwnershipList:eHoldings.getExtentOfOwnership()){
563 for(Coverage coverage:extentOfOwnershipList.getCoverages().getCoverage()) {
564 coverage.setCoverageEndIssue(StringUtils.isNotBlank(coverage.getCoverageEndIssue())?coverage.getCoverageEndIssue():"");
565 coverage.setCoverageEndDateString(StringUtils.isNotBlank(coverage.getCoverageEndDateString())?coverage.getCoverageEndDateString():"");
566 coverage.setCoverageEndDateFormat(StringUtils.isNotBlank(coverage.getCoverageEndDateFormat())?coverage.getCoverageEndDateFormat():"");
567 coverage.setCoverageEndVolume(StringUtils.isNotBlank(coverage.getCoverageEndVolume())?coverage.getCoverageEndVolume():"");
568 coverage.setCoverageEndDate(StringUtils.isNotBlank(coverage.getCoverageEndDate())?coverage.getCoverageEndDate():"");
569 }
570 }
571 }
572 return eHoldings;
573 }
574
575
576
577
578
579
580 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
581 return new WorkInstanceOlemlForm();
582 }
583
584
585
586
587
588
589
590
591
592
593 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
594 HttpServletRequest request, HttpServletResponse response) {
595 WorkInstanceOlemlForm instanceEditorForm = (WorkInstanceOlemlForm) form;
596
597
598 return null;
599 }
600
601
602
603
604
605
606
607
608
609
610
611 public ModelAndView load(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
612 HttpServletRequest request, HttpServletResponse response) {
613 WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
614 workEInstanceOlemlForm.setHideFooter(false);
615 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
616 workEInstanceOlemlForm.setMessage("Please enter details for new Item record.");
617
618
619 String uuid = request.getParameter("uuid");
620 String docType = request.getParameter("docType");
621 String docFormat = request.getParameter("docFormat");
622 String docCategory = request.getParameter("docCategory");
623 if (null == uuid || StringUtils.isEmpty(uuid)) {
624 uuid = workEInstanceOlemlForm.getUuid();
625 }
626 workEInstanceOlemlForm.setExisting("true");
627 try {
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644 } catch (Exception e) {
645 LOG.error("Exception :", e);
646 StringBuffer instanceEditorErrorMessage = new StringBuffer(OLEConstants.INSTANCE_EDITOR_LOAD_FAILURE)
647 .append(" :: \n" + e.getMessage());
648
649 LOG.error(instanceEditorErrorMessage);
650
651 }
652 return null;
653 }
654
655
656
657
658
659
660
661
662
663
664 protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response,
665 InstanceEditorForm instanceEditorForm) {
666
667 return null;
668 }
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696 private InstanceEditorFormDataHandler getInstanceEditorFormDataHandler() {
697 if (null == instanceEditorFormDataHandler) {
698 instanceEditorFormDataHandler = new InstanceEditorFormDataHandler();
699 }
700 return instanceEditorFormDataHandler;
701 }
702
703 private EInstanceFormDataHandler getEInstanceFormDataHandler() {
704 if (null == eInstanceFormDataHandler) {
705 eInstanceFormDataHandler = new EInstanceFormDataHandler();
706 }
707 return eInstanceFormDataHandler;
708 }
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732 public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
733 this.discoveryHelperService = discoveryHelperService;
734 }
735
736
737
738
739
740
741 public DiscoveryHelperService getDiscoveryHelperService() {
742 if (null == discoveryHelperService) {
743 return new DiscoveryHelperService();
744 }
745 return discoveryHelperService;
746 }
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821 @Override
822 public EditorForm delete(EditorForm editorForm) throws Exception {
823 return deleteFromDocStore(editorForm);
824 }
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873 @Override
874 public EditorForm bulkUpdate(EditorForm editorForm, List<String> ids) {
875 WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
876 String docId = editorForm.getDocId();
877 String docType = editorForm.getDocType();
878 String bibId = editorForm.getBibId();
879 String editorStatusMessage = "";
880
881
882 try {
883 OleHoldings eHoldings = workEInstanceOlemlForm.getSelectedEHoldings();
884 getOleEResourceSearchService().getEResourcesFields(editorForm.geteResourceId(), eHoldings, workEInstanceOlemlForm);
885 getOleEResourceSearchService().getEResourcesLicenseFields(editorForm.geteResourceId(), workEInstanceOlemlForm);
886 String content = getInstanceEditorFormDataHandler().buildHoldingContent(eHoldings);
887 Holdings eHoldingsDoc = new EHoldings();
888 eHoldingsDoc.setCategory(DocCategory.WORK.getCode());
889 eHoldingsDoc.setType(DocType.EHOLDINGS.getCode());
890 eHoldingsDoc.setFormat(DocFormat.OLEML.getCode());
891 String canUpdateStaffOnlyFlag = "false";
892 if (editorForm.getStaffOnlyFlagInGlobalEdit() != null && editorForm.getStaffOnlyFlagInGlobalEdit().equalsIgnoreCase("Y")) {
893 canUpdateStaffOnlyFlag = "true";
894 editorForm.setStaffOnlyFlagForHoldings(true);
895 eHoldingsDoc.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
896 }
897 else if (editorForm.getStaffOnlyFlagInGlobalEdit() != null && editorForm.getStaffOnlyFlagInGlobalEdit().equalsIgnoreCase("N")) {
898 canUpdateStaffOnlyFlag = "true";
899 editorForm.setStaffOnlyFlagForHoldings(false);
900 eHoldingsDoc.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
901 }
902 eHoldingsDoc.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
903 Bib bib = new BibMarc();
904 bib.setId(workEInstanceOlemlForm.getBibId());
905 eHoldingsDoc.setBib(bib);
906 eHoldingsDoc.setContent(content);
907 getDocstoreClientLocator().getDocstoreClient().bulkUpdateHoldings(eHoldingsDoc,ids,canUpdateStaffOnlyFlag);
908 editorForm.setDocId(eHoldingsDoc.getId());
909
910 workEInstanceOlemlForm.getSelectedEHoldings().setHoldingsIdentifier(eHoldingsDoc.getId());
911 HoldingsTree holdingsTree = new HoldingsTree();
912 holdingsTree.setHoldings(eHoldingsDoc);
913 List<HoldingsTree> holdingsTreeList = new ArrayList<>();
914 holdingsTreeList.add(holdingsTree);
915
916 editorStatusMessage = "record.create.message";
917 }
918 catch (DocstoreException e) {
919 LOG.error(e);
920 DocstoreException docstoreException = (DocstoreException) e;
921 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
922 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
923 } else {
924 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
925 }
926 return workEInstanceOlemlForm;
927 }
928 catch (Exception e) {
929 LOG.error("Exception :", e);
930 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, "docstore.response", e.getMessage());
931 return workEInstanceOlemlForm;
932
933 }
934
935
936 try {
937 getEInstanceFormDataHandler().setLocationDetails(workEInstanceOlemlForm);
938 String eResId = workEInstanceOlemlForm.geteResourceId();
939 editorForm.seteResourceId(null);
940 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
941
942 GlobalVariables.getMessageMap().getInfoMessages().clear();
943 }
944 catch (DocstoreException e) {
945 LOG.error(e);
946 DocstoreException docstoreException = (DocstoreException) e;
947 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
948 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
949 } else {
950 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
951 }
952 return workEInstanceOlemlForm;
953 }
954 catch (Exception e) {
955 LOG.error("Exception :", e);
956 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, "docstore.response", e.getMessage());
957 return workEInstanceOlemlForm;
958 }
959 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, editorStatusMessage);
960
961 return workEInstanceOlemlForm;
962 }
963
964 }