View Javadoc
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   * Created with IntelliJ IDEA.
49   * User: pp7788
50   * Date: 12/11/12
51   * Time: 2:38 PM
52   * To change this template use File | Settings | File Templates.
53   */
54  
55  /**
56   * InstanceEditorController is the controller class for Instance Editor
57   */
58  //@Controller
59  //@RequestMapping(value = "/instanceeditor")
60  public class WorkEInstanceOlemlEditor
61          extends AbstractEditor
62          implements DocumentEditor {
63  
64      private static final Logger LOG = Logger.getLogger(WorkEInstanceOlemlEditor.class);
65  
66      //    private DocstoreHelperService docstoreHelperService;
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 //        workEInstanceOlemlForm.getSelectedEHoldings().setEResourceTitle(null);
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         //editorForm.setMessage("Record copied successfully");
115         //GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "info.einstance.copy.success");
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                 //getOleEResourceSearchService().getAccessLocationFromEInstance(eHoldings, workEInstanceOlemlForm);
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 //        WorkBibDocument workBibDocument = new WorkBibDocument();
279 //        workBibDocument.setId(editorForm.getBibId());
280 //        QueryService queryService = QueryServiceImpl.getInstance();
281 //        WorkBibDocument document = null;
282 //        try {
283 //            document = queryService.buildBibDocumentInfo(workBibDocument);
284 //        } catch (Exception e) {
285 //            LOG.error("Failed to get Title / Author details : " + e.getMessage());
286 //        }
287 //        StringBuilder titleBuilder = new StringBuilder();
288 //        if (document != null) {
289 //            titleBuilder.append(document.getTitle());
290 //            titleBuilder.append("/");
291 //            if (document.getAuthor() != null) {
292 //                titleBuilder.append(document.getAuthor());
293 //            }
294 //            if (workBibDocument.getDocFormat().equalsIgnoreCase("dublinunq")) {
295 //                editorForm.setFromDublin(true);
296 //            }
297 //            editorForm.setTitle(org.apache.commons.lang.StringEscapeUtils.escapeHtml(titleBuilder.toString()));
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                     // To add updated EHoldings to bib tree
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      * This methods adds the updated EHoldings to the bib tree to build left pane tree.
474      * @param bibTreeList
475      * @param eHoldings
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      * This method creates a instance of InstanceEditorForm
576      *
577      * @param httpServletRequest
578      * @return InstanceEditorForm
579      */
580     protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
581         return new WorkInstanceOlemlForm();
582     }
583 
584     /**
585      * This method takes the initial request when click on InstanceEditor Screen.
586      *
587      * @param form
588      * @param result
589      * @param request
590      * @param response
591      * @return ModelAndView
592      */
593     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
594                               HttpServletRequest request, HttpServletResponse response) {
595         WorkInstanceOlemlForm instanceEditorForm = (WorkInstanceOlemlForm) form;
596         //ModelAndView modelAndView = super.start(instanceEditorForm, result, request, response);
597         // return getUIFModelAndView(instanceEditorForm, "WorkHoldingsViewPage");
598         return null;
599     }
600 
601 
602     /**
603      * This method will fetch the holding/Item records based on the AdditionalAttributes.
604      *
605      * @param form
606      * @param result
607      * @param request
608      * @param response
609      * @return ModelAndView
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         //EditorForm workInstanceOlemlForm = (WorkInstanceOlemlForm) form;
618         //WorkInstanceOlemlForm workInstanceOlemlForm = new WorkInstanceOlemlForm();
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               /*if (workEInstanceOlemlForm.getInstanceId() != null && workEInstanceOlemlForm.getInstanceId().length() > 0) {
629                 String docStoreData = getDocstoreHelperService().getDocstoreData(docCategory,docType,docFormat,workEInstanceOlemlForm.getInstanceId());
630                 InstanceCollection instanceCollection = new WorkEInstanceOlemlRecordProcessor().fromXML(docStoreData);
631                 workEInstanceOlemlForm.setSelectedEInstance(instanceCollection.getEInstance().get(0));
632             }
633             String docStoreData = getDocstoreHelperService().getDocstoreData(docCategory,docType,docFormat,uuid);
634             if (docType.equalsIgnoreCase("eHoldings")) {
635                 EHoldings oleHoldings = new WorkEHoldingOlemlRecordProcessor().fromXML(docStoreData);
636                 workEInstanceOlemlForm.setSelectedEHoldings(oleHoldings);
637                 //return getUIFModelAndView(workInstanceOlemlForm,"WorkHoldingsViewPage");
638             }
639             else {
640                 InstanceCollection instanceCollection = new WorkEInstanceOlemlRecordProcessor().fromXML(docStoreData);
641                 workEInstanceOlemlForm.setSelectedEHoldings(instanceCollection.getEInstance().get(0).getEHoldings());
642                 //return getUIFModelAndView(workInstanceOlemlForm,"WorkHoldingsViewPage");
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             //workInstanceOlemlForm.setMessage(instanceEditorErrorMessage.toString());
649             LOG.error(instanceEditorErrorMessage);
650             //return getUIFModelAndView(workInstanceOlemlForm);
651         }
652         return null;
653     }
654 
655     /**
656      * Used for Test-case
657      *
658      * @param result
659      * @param request
660      * @param response
661      * @param instanceEditorForm
662      * @return ModelAndView
663      */
664     protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response,
665                                      InstanceEditorForm instanceEditorForm) {
666         //return super.updateComponent(instanceEditorForm, result, request, response);
667         return null;
668     }
669 
670 //    /**
671 //     * Gets the docstoreHelperService attribute
672 //     *
673 //     * @return Returns DocstoreHelperService
674 //     */
675 //    private DocstoreHelperService getDocstoreHelperService() {
676 //        if (null == docstoreHelperService) {
677 //            return new DocstoreHelperService();
678 //        }
679 //        return docstoreHelperService;
680 //    }
681 
682 //    /**
683 //     * Sets the docstoreHelperService attribute values.
684 //     *
685 //     * @param docstoreHelperService
686 //     */
687 //    public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
688 //        this.docstoreHelperService = docstoreHelperService;
689 //    }
690 
691     /**
692      * Gets the InstanceEditorFormDataHandler attribute.
693      *
694      * @return Returns InstanceEditorFormDataHandler.
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 //     * This method returns AdditionalAttributes instance from the list of Extension.
713 //     * @param extensionList
714 //     * @return AdditionalAttributes
715 //     */
716 //    private AdditionalAttributes getFirstAdditionalAttributes(List<Extension> extensionList) {
717 //        for (Extension ext : extensionList) {
718 //            for (Object obj : ext.getContent()) {
719 //                if (obj instanceof AdditionalAttributes) {
720 //                    return (AdditionalAttributes) obj;
721 //                }
722 //            }
723 //        }
724 //        return null;
725 //    }
726 
727     /**
728      * Sets the discoveryHelperService attribute value.
729      *
730      * @param discoveryHelperService
731      */
732     public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
733         this.discoveryHelperService = discoveryHelperService;
734     }
735 
736     /**
737      * Gets the discoveryHelperService attribute.
738      *
739      * @return Returns DiscoveryHelperService.
740      */
741     public DiscoveryHelperService getDiscoveryHelperService() {
742         if (null == discoveryHelperService) {
743             return new DiscoveryHelperService();
744         }
745         return discoveryHelperService;
746     }
747 
748     /*@RequestMapping(params = "methodToCall=addExtentOfOwnership")
749     public ModelAndView addExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
750                                              HttpServletRequest request, HttpServletResponse response) {
751         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
752         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
753         index++;
754         List<ExtentOfOwnership> extentOfOwnershipForUI = instanceEditorForm.getSelectedHolding().getExtentOfOwnership();
755         extentOfOwnershipForUI.add(index, new ExtentOfOwnership());
756         return super.updateComponent(instanceEditorForm, result, request, response);
757     }
758 
759     @RequestMapping(params = "methodToCall=removeExtentOfOwnership")
760     public ModelAndView removeExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
761                                                 HttpServletRequest request, HttpServletResponse response) {
762         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
763         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
764         List<ExtentOfOwnership> extentOfOwnershipForUI = instanceEditorForm.getSelectedHolding().getExtentOfOwnership();
765         if (extentOfOwnershipForUI.size() > 1)
766             extentOfOwnershipForUI.remove(index);
767         return super.updateComponent(instanceEditorForm, result, request, response);
768     }*/
769 
770 
771   /*  */
772 
773     /**
774      * Shows the linked Bibs corresponging to Holdings/Item
775      *
776      * @param editorForm
777      * @return
778      *//*
779     @Override
780     public EditorForm showBibs(EditorForm editorForm) {
781         WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
782         QueryService queryService = QueryServiceImpl.getInstance();
783         List<String> bibUUIDList = new ArrayList<String>();
784         String instanceId = "";
785         String docType = editorForm.getDocType();
786         List<WorkBibDocument> workBibDocumentList = new ArrayList<WorkBibDocument>();
787         try {
788 
789             if ((docType.equalsIgnoreCase(DocType.INSTANCE.getCode()) || docType
790                     .equalsIgnoreCase(DocType.HOLDINGS.getCode())) || (docType
791                     .equalsIgnoreCase(DocType.ITEM.getCode()))) {
792                 instanceId = editorForm.getInstanceId();
793             }
794             if (StringUtils.isNotEmpty(instanceId)) {
795                 bibUUIDList = queryService.queryForBibs(instanceId);
796             }
797             DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
798             if (bibUUIDList != null && bibUUIDList.size() > 0) {
799                 for (String bibUUID : bibUUIDList) {
800                     WorkBibDocument workBibDocument = new WorkBibDocument();
801                     workBibDocument.setId(bibUUID);
802                     workBibDocument = docstoreHelperService.getInfoForBibTree(workBibDocument);
803                     workBibDocumentList.add(workBibDocument);
804                 }
805             }
806 
807             editorForm.setWorkBibDocumentList(workBibDocumentList);
808         } catch (SolrServerException e) {
809             LOG.error("Exception:" + e.getMessage(), e);
810         }
811         workEInstanceOlemlForm.setViewId("ShowBibViewPage");
812         return workEInstanceOlemlForm;
813     }*/
814 
815     /**
816      * This method deletes the EHoldings record from docstore by the doc id.
817      * @param editorForm
818      * @return
819      * @throws Exception
820      */
821     @Override
822     public EditorForm delete(EditorForm editorForm) throws Exception {
823         return deleteFromDocStore(editorForm);
824     }
825 
826     /*@Override
827     public EditorForm delete(EditorForm editorForm) throws Exception {
828         WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
829         String operation = OLEConstants.DELETE;
830         BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
831         //Map<String, String> map = new HashMap<>();
832         //Map<String, String> uuidMap = new HashMap<>();
833         //map.put("bibId", editorForm.getBibId());
834         //List<OleCopy> listOfValues = (List<OleCopy>) boService.findMatching(OleCopy.class, map);
835 
836         //if (listOfValues != null && listOfValues.size() > 0) {
837         //    GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DELETE_PURCHASE_ORDER_FAIL_MESSAGE, "Bib");
838         //    return workEInstanceOlemlForm;
839         //}
840 
841         getResponseFromDocStore(editorForm, editorForm.getDocId(), operation);
842         GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, OLEConstants.RECORD_DELETE_MESSAGE);
843 
844        *//* if (responseXml.contains("Success")) {
845             GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.delete.message");
846             workEInstanceOlemlForm.setShowDeleteTree(false);
847             workEInstanceOlemlForm.setHasLink(false);
848         } else {
849             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "record.delete.fail.message");
850         }*//*
851         removeDocumentFromTree(editorForm);
852         editorForm.setShowDeleteTree(false);
853         editorForm.setHasLink(false);
854         workEInstanceOlemlForm.setViewId(OLEConstants.DELETE_VIEW_PAGE);
855         return workEInstanceOlemlForm;
856     }*/
857 
858     /*public boolean validateRequiredFields(WorkEInstanceOlemlForm workEInstanceOlemlForm) {
859         List<Coverage> coverages = workEInstanceOlemlForm.getSelectedEHoldings().getExtentOfOwnership().getCoverages().getCoverage();
860         if (coverages.size() > 0) {
861             for (Coverage coverage : coverages) {
862                 String date = coverage.getCoverageStartDate();
863                 if (date != null && !date.isEmpty()) {
864                     return true;
865                 }
866             }
867         } else {
868             return false;
869         }
870         return false;
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         //List<BibTree> bibTreeList = null;
881         //BibTree bibTree = null;
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            // processResponse(eHoldingsDoc.getId(), eHoldingsDoc.getBib().getId(), editorForm.getTokenId());
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             //bibTree.getHoldingsTrees().addAll(holdingsTreeList);
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 }