1 package org.kuali.ole.describe.controller;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.solr.client.solrj.SolrServerException;
5 import org.kuali.asr.service.ASRHelperServiceImpl;
6 import org.kuali.ole.DocumentUniqueIDPrefix;
7 import org.kuali.ole.OLEConstants;
8 import org.kuali.ole.deliver.bo.ASRItem;
9 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
10 import org.kuali.ole.deliver.bo.OleLoanDocument;
11 import org.kuali.ole.describe.bo.DocumentSelectionTree;
12 import org.kuali.ole.describe.bo.DocumentTreeNode;
13 import org.kuali.ole.describe.bo.InstanceEditorFormDataHandler;
14 import org.kuali.ole.describe.form.EditorForm;
15 import org.kuali.ole.describe.form.WorkBibMarcForm;
16 import org.kuali.ole.describe.form.WorkInstanceOlemlForm;
17 import org.kuali.ole.describe.keyvalue.LocationValuesBuilder;
18 import org.kuali.ole.docstore.common.client.DocstoreClient;
19 import org.kuali.ole.docstore.common.document.*;
20 import org.kuali.ole.docstore.common.document.HoldingsTree;
21 import org.kuali.ole.docstore.common.document.Item;
22 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
23 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
24 import org.kuali.ole.docstore.common.document.content.enums.DocType;
25 import org.kuali.ole.docstore.common.document.content.instance.*;
26 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
27 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
28 import org.kuali.ole.docstore.common.exception.DocstoreException;
29 import org.kuali.ole.docstore.engine.client.DocstoreLocalClient;
30 import org.kuali.ole.select.bo.OLESerialReceivingDocument;
31 import org.kuali.ole.select.bo.OLESerialReceivingHistory;
32 import org.kuali.ole.select.businessobject.OleCopy;
33 import org.kuali.ole.service.impl.OLESerialReceivingServiceImpl;
34 import org.kuali.ole.sys.context.SpringContext;
35 import org.kuali.rice.core.api.config.property.ConfigurationService;
36 import org.kuali.rice.core.api.util.RiceConstants;
37 import org.kuali.rice.core.api.util.tree.Node;
38 import org.kuali.rice.kim.api.permission.PermissionService;
39 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
40 import org.kuali.rice.krad.service.BusinessObjectService;
41 import org.kuali.rice.krad.service.KRADServiceLocator;
42 import org.kuali.rice.krad.uif.UifParameters;
43 import org.kuali.rice.krad.util.GlobalVariables;
44 import org.kuali.rice.krad.util.KRADConstants;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 import javax.servlet.http.HttpServletRequest;
49 import java.text.Format;
50 import java.text.SimpleDateFormat;
51 import java.util.*;
52
53
54
55
56
57
58
59
60 public class WorkHoldingsOlemlEditor extends AbstractEditor {
61
62 private static final Logger LOG = LoggerFactory.getLogger(WorkHoldingsOlemlEditor.class);
63 private InstanceEditorFormDataHandler instanceEditorFormDataHandler = null;
64 private static WorkHoldingsOlemlEditor workHoldingsOlemlEditor = null;
65 private ItemOlemlRecordProcessor itemOlemlRecordProcessor ;
66 private ASRHelperServiceImpl asrHelperService ;
67 private BusinessObjectService businessObjectService ;
68 private DocstoreClient docstoreClient = getDocstoreLocalClient();
69
70 public static WorkHoldingsOlemlEditor getInstance() {
71 if (workHoldingsOlemlEditor == null) {
72 workHoldingsOlemlEditor = new WorkHoldingsOlemlEditor();
73 }
74 return workHoldingsOlemlEditor;
75 }
76
77 public ItemOlemlRecordProcessor getItemOlemlRecordProcessor(){
78 if(itemOlemlRecordProcessor == null){
79 itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
80 }
81 return itemOlemlRecordProcessor;
82 }
83
84
85 public ASRHelperServiceImpl getAsrHelperService(){
86 if(asrHelperService == null){
87 asrHelperService = new ASRHelperServiceImpl();
88 }
89 return asrHelperService;
90
91 }
92
93 public BusinessObjectService getBusinessObjectService(){
94 if(businessObjectService == null){
95 businessObjectService = KRADServiceLocator.getBusinessObjectService();
96 }
97 return businessObjectService;
98 }
99
100 private WorkHoldingsOlemlEditor() {
101
102 }
103
104 @Override
105 public EditorForm loadDocument(EditorForm editorForm) {
106
107
108 WorkInstanceOlemlForm workInstanceOlemlForm = new WorkInstanceOlemlForm();
109 String directory = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(org.kuali.ole.sys.OLEConstants.EXTERNALIZABLE_HELP_URL_KEY);
110 editorForm.setExternalHelpUrl(directory+"/reference/webhelp/OLE/content/ch04s01.html#_Instance_Editor_1");
111 editorForm.setHeaderText("Holdings");
112 editorForm.setHasLink(true);
113 editorForm.setShowEditorFooter(true);
114 String bibId = editorForm.getBibId();
115 List<BibTree> bibTreeList = new ArrayList();
116 Date date = new Date();
117 SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE+" HH:mm:ss");
118 String dateStr = sdf.format(date);
119 BibTree bibTree = null;
120 if (!StringUtils.isNotEmpty(bibId)) {
121 workInstanceOlemlForm.setMessage("Error: Invalid bibId id:" + bibId);
122 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "invalid.bib");
123 return workInstanceOlemlForm;
124 }
125
126 Bib bib = null;
127 try {
128 bibTree = docstoreClient.retrieveBibTree(bibId);
129 }catch (DocstoreException e) {
130 LOG.error("Exception : ", e);
131 DocstoreException docstoreException = (DocstoreException) e;
132 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
133 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
134 } else {
135 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
136 }
137 return workInstanceOlemlForm;
138 } catch (Exception e) {
139 LOG.error("Exception ", e);
140 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
141 }
142 bibTreeList.add(bibTree);
143 workInstanceOlemlForm.setBibTreeList(bibTreeList);
144 bib = bibTree.getBib();
145 editorForm.setTitle(bib.getTitle() + " / " + bib.getAuthor());
146 editorForm.setHasLink(true);
147 if (!isValidBib(bib.getContent())) {
148 workInstanceOlemlForm.setMessage("Error: Invalid bibId id:" + bibId);
149 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "invalid.bib");
150 return workInstanceOlemlForm;
151 }
152
153 String docId = editorForm.getDocId();
154 if (StringUtils.isNotEmpty(docId)) {
155 editorForm.setHoldingLocalIdentifier(DocumentUniqueIDPrefix.getDocumentId(editorForm.getDocId()));
156 Holdings holdings = null;
157 try {
158 holdings = docstoreClient.retrieveHoldings(editorForm.getDocId());
159 }catch (DocstoreException e) {
160 LOG.error("Exception : ", e);
161 DocstoreException docstoreException = (DocstoreException) e;
162 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
163 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
164 } else {
165 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
166 }
167 return workInstanceOlemlForm;
168 } catch (Exception e) {
169 LOG.error("Exception ", e);
170 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
171 } String docStoreData = holdings.getContent();
172 OleHoldings oleHoldings = null;
173 if (StringUtils.isNotEmpty(docStoreData)) {
174 oleHoldings = new HoldingOlemlRecordProcessor().fromXML(docStoreData);
175 editorForm.setStaffOnlyFlagForHoldings(holdings.isStaffOnly());
176 editorForm.setHoldingCreatedDate(holdings.getCreatedOn());
177 editorForm.setHoldingCreatedBy(holdings.getCreatedBy());
178 editorForm.setHoldingUpdatedDate(holdings.getUpdatedOn());
179 editorForm.setHoldingUpdatedBy(holdings.getUpdatedBy());
180
181
182 ensureMultipleValuesInOleHoldings(oleHoldings);
183
184 workInstanceOlemlForm.setSelectedHolding(oleHoldings);
185 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
186 } else {
187 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "ds.error.holdings.notfound");
188 workInstanceOlemlForm.setViewId("WorkHoldingsViewPage");
189 return workInstanceOlemlForm;
190 }
191
192 if (editorForm.getEditable().equalsIgnoreCase("false")) {
193 if(editorForm.getMethodToCall() != null && editorForm.getMethodToCall().equalsIgnoreCase("copy")){
194 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,"record.copy.instance.message");
195 } else {
196 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,"holdings.record.load.message");
197 }
198 } else {
199 boolean hasPermission = canEditInstance(GlobalVariables.getUserSession().getPrincipalId());
200 if (hasPermission) {
201 if(editorForm.getMethodToCall() != null && editorForm.getMethodToCall().equalsIgnoreCase("copyInstance")){
202 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,"record.copy.instance.message");
203 } else {
204 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "holdings.record.load.message");
205 }
206 } else {
207 editorForm.setHideFooter(false);
208 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.ERROR_EDIT_INSTANCE);
209 }
210 }
211 } else {
212 editorForm.setHoldingLocalIdentifier("");
213 editorForm.setHoldingUpdatedBy("");
214 editorForm.setHoldingUpdatedDate("");
215 editorForm.setStaffOnlyFlagForHoldings(false);
216 editorForm.setHoldingCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
217 editorForm.setHoldingCreatedDate(dateStr);
218 boolean hasPermission = canCreateInstance(GlobalVariables.getUserSession().getPrincipalId());
219 if (hasPermission) {
220 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "holdings.record.new.load.message");
221 } else {
222 editorForm.setHideFooter(false);
223 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.ERROR_CREATE_INSTANCE);
224 }
225 }
226 if (editorForm.getDocId() != null) {
227 OLESerialReceivingServiceImpl oleSerialReceivingService = new OLESerialReceivingServiceImpl();
228 Map<String, String> map = new HashMap<>();
229 map.put("instanceId", editorForm.getDocId());
230 List<OLESerialReceivingDocument> oleSerialReceivingDocuments = (List<OLESerialReceivingDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OLESerialReceivingDocument.class, map);
231 for (OLESerialReceivingDocument oleSerialReceivingDocument : oleSerialReceivingDocuments) {
232 if (oleSerialReceivingDocument.isActive()) {
233 editorForm.setSerialFlag(true);
234 oleSerialReceivingService.readReceivingRecordType(oleSerialReceivingDocument);
235 oleSerialReceivingService.updateEnumCaptionValues(oleSerialReceivingDocument, null);
236 if (oleSerialReceivingDocument.getOleSerialReceivingHistoryList() != null && oleSerialReceivingDocument.getOleSerialReceivingHistoryList().size() > 0) {
237 for (int serialReceivingHistoryList = 0; serialReceivingHistoryList < oleSerialReceivingDocument.getOleSerialReceivingHistoryList().size(); serialReceivingHistoryList++) {
238 oleSerialReceivingService.setEnumerationAndChronologyValues(oleSerialReceivingDocument.getOleSerialReceivingHistoryList().get(serialReceivingHistoryList));
239 }
240 }
241 if (oleSerialReceivingDocument.getUnboundLocation() != null) {
242 editorForm.setUnboundLocation(oleSerialReceivingDocument.getUnboundLocation());
243 }
244 oleSerialReceivingService.sortById(oleSerialReceivingDocument.getOleSerialReceivingHistoryList());
245 for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
246 if (oleSerialReceivingHistory.isPublicDisplay()) {
247 if (oleSerialReceivingHistory.getReceivingRecordType().equalsIgnoreCase("Main")) {
248 editorForm.getMainSerialReceivingHistoryList().add(oleSerialReceivingHistory);
249 }
250 if (oleSerialReceivingHistory.getReceivingRecordType().equalsIgnoreCase("Supplementary")) {
251 editorForm.getSupplementSerialReceivingHistoryList().add(oleSerialReceivingHistory);
252 }
253 if (oleSerialReceivingHistory.getReceivingRecordType().equalsIgnoreCase("Index")) {
254 editorForm.getIndexSerialReceivingHistoryList().add(oleSerialReceivingHistory);
255 }
256 }
257 }
258 }
259 }
260 }
261 workInstanceOlemlForm.setViewId("WorkHoldingsViewPage");
262 return workInstanceOlemlForm;
263 }
264
265 private void ensureMultipleValuesInOleHoldings(OleHoldings oleHoldings) {
266 List<ExtentOfOwnership> extentOfOwnerships = ensureAtleastOneExtentOfOwnership(
267 oleHoldings.getExtentOfOwnership());
268 oleHoldings.setExtentOfOwnership(extentOfOwnerships);
269
270 List<Note> notes = ensureAtleastOneNote(oleHoldings.getNote());
271 oleHoldings.setNote(notes);
272
273 List<Uri> uriList = ensureAtleastOneUri(oleHoldings.getUri());
274 oleHoldings.setUri(uriList);
275 }
276
277 @Override
278 public EditorForm saveDocument(EditorForm editorForm) {
279 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
280 String bibId = editorForm.getBibId();
281 List<BibTree> bibTreeList = null;
282 BibTree bibTree = null;
283 HoldingsTree holdingsTree = new HoldingsTree();
284 String editorMessage = "";
285 Bib bib = null;
286 Date date = new Date();
287 SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE+" HH:mm:ss");
288 String dateStr = sdf.format(date);
289 String user = GlobalVariables.getUserSession().getPrincipalName();
290 try {
291 bibTree = docstoreClient.retrieveBibTree(bibId);
292 }catch (DocstoreException e) {
293 LOG.error("Exception : ", e);
294 DocstoreException docstoreException = (DocstoreException) e;
295 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
296 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
297 } else {
298 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
299 }
300 return workInstanceOlemlForm;
301 } catch (Exception e) {
302 LOG.error("Exception ", e);
303 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
304 }
305 bibTreeList = new ArrayList();
306 bibTreeList.add(bibTree);
307 workInstanceOlemlForm.setBibTreeList(bibTreeList);
308 bib = bibTree.getBib();
309 editorForm.setTitle(bib.getTitle() + " / " + bib.getAuthor());
310 editorForm.setHasLink(true);
311
312 editorForm.setHeaderText("Holdings");
313 editorForm.setShowEditorFooter(true);
314 String docId = editorForm.getDocId();
315 if (StringUtils.isNotEmpty(docId)) {
316 List<HoldingsTree> holdingsTreeList = new ArrayList<>();
317 for(HoldingsTree holdingsTree1 : bibTree.getHoldingsTrees()) {
318 if(!holdingsTree1.getHoldings().getId().equals(docId)) {
319 holdingsTreeList.add(holdingsTree1);
320 }
321 }
322 bibTree.getHoldingsTrees().clear();
323 bibTree.getHoldingsTrees().addAll(holdingsTreeList);
324 Holdings holdings = new PHoldings();
325 OleHoldings holdingData = workInstanceOlemlForm.getSelectedHolding();
326 if (!isValidHoldingsData(workInstanceOlemlForm)) {
327 return workInstanceOlemlForm;
328 }
329 try {
330 String holdingXmlContent = getInstanceEditorFormDataHandler().buildHoldingContent(holdingData);
331 holdings.setContent(holdingXmlContent);
332 } catch (Exception e) {
333 LOG.error("Exception :", e);
334 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS,
335 "docstore.response", e.getMessage());
336 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
337 return workInstanceOlemlForm;
338 }
339 holdings.setId(docId);
340 holdings.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
341 holdings.setCreatedBy(editorForm.getCreatedBy());
342 holdings.setCreatedOn(editorForm.getCreatedDate());
343 holdings.setUpdatedBy(user);
344 holdings.setUpdatedOn(dateStr);
345 String holdingsCreatedDate = null;
346 Format formatter = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
347 holdingsCreatedDate = formatter.format(new Date());
348 holdings.setLastUpdated(holdingsCreatedDate);
349 holdings.setBib(bib);
350 holdings.setCategory(editorForm.getDocCategory());
351 holdings.setType(editorForm.getDocType());
352 holdings.setFormat(editorForm.getDocFormat());
353 long startTime = System.currentTimeMillis();
354 try {
355 docstoreClient.updateHoldings(holdings);
356 } catch (Exception e) {
357 LOG.error("Exception :", e);
358 DocstoreException docstoreException = (DocstoreException) e;
359 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
360 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
361 } else {
362 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
363 }
364 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
365 return workInstanceOlemlForm;
366 }
367 long endTime = System.currentTimeMillis();
368 editorForm.setSolrTime(String.valueOf((endTime-startTime)/1000));
369 editorForm.setUpdatedDate(holdings.getUpdatedOn());
370 editorForm.setUpdatedBy(holdings.getUpdatedBy());
371 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
372 editorMessage = "holdings.record.update.message";
373 workInstanceOlemlForm.setViewId("WorkHoldingsViewPage");
374 } else {
375
376 if (!isValidHoldingsData(workInstanceOlemlForm)) {
377 return workInstanceOlemlForm;
378 }
379 String content = null;
380 try {
381 content = getInstanceEditorFormDataHandler().buildHoldingContent(workInstanceOlemlForm.getSelectedHolding());
382 } catch (Exception e) {
383 LOG.error("Exception :", e);
384 e.printStackTrace();
385 return workInstanceOlemlForm;
386 }
387
388 String staffOnlyFlagForHoldings = String.valueOf(editorForm.isStaffOnlyFlagForHoldings());
389
390
391
392 Holdings holdings = new PHoldings();
393 holdings.setCategory(DocCategory.WORK.getCode());
394 holdings.setType(DocType.HOLDINGS.getCode());
395 holdings.setFormat(DocFormat.OLEML.getCode());
396 holdings.setCreatedOn(dateStr);
397 holdings.setCreatedBy(user);
398 holdings.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
399 holdings.setContent(content);
400 holdings.setBib(bib);
401
402 holdingsTree.setHoldings(holdings);
403 holdingsTree.getItems().add(getItemRecord());
404
405 long startTime = System.currentTimeMillis();
406 try {
407 docstoreClient.createHoldingsTree(holdingsTree);
408 editorForm.setDocId(holdingsTree.getHoldings().getId());
409 editorForm.setHoldingCreatedBy(holdingsTree.getHoldings().getCreatedBy());
410 editorForm.setHoldingCreatedDate(holdingsTree.getHoldings().getCreatedOn());
411 if (workInstanceOlemlForm.getBibTreeList() == null && workInstanceOlemlForm.getBibTreeList().size() == 0) {
412 bibTreeList = new ArrayList<>();
413 bibTree = new BibTree();
414 bibTree.setBib(bib);
415 bibTreeList.add(bibTree);
416 workInstanceOlemlForm.setBibTreeList(bibTreeList);
417 } else {
418 bibTreeList = workInstanceOlemlForm.getBibTreeList();
419 bibTree = bibTreeList.get(0);
420 }
421
422 List<HoldingsTree> holdingsTreeList = new ArrayList<>();
423 holdingsTreeList.add(holdingsTree);
424
425 }catch (DocstoreException e) {
426 LOG.error("Exception : ", e);
427 DocstoreException docstoreException = (DocstoreException) e;
428 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
429 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
430 } else {
431 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
432 }
433 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
434 return workInstanceOlemlForm;
435 } catch (Exception e) {
436 LOG.error("Exception ", e);
437 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
438 }
439 long endTime = System.currentTimeMillis();
440 editorForm.setSolrTime(String.valueOf((endTime-startTime)/1000));
441 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
442 editorMessage = "record.create.message";
443 }
444
445
446
447 if (processAsr(editorForm, workInstanceOlemlForm, bibTree, holdingsTree, editorMessage, bib)){
448 return workInstanceOlemlForm;
449 }
450
451 return workInstanceOlemlForm;
452 }
453
454 private boolean processAsr(EditorForm editorForm, WorkInstanceOlemlForm workInstanceOlemlForm, BibTree bibTree, HoldingsTree holdingsTree, String editorMessage, Bib bib) {
455 try {
456 if(holdingsTree.getHoldings() == null) {
457 holdingsTree = docstoreClient.retrieveHoldingsTree(editorForm.getDocId());
458 }
459 String holdingLocation = null;
460 if (workInstanceOlemlForm.getSelectedHolding() != null && workInstanceOlemlForm.getSelectedHolding().getLocation() != null && workInstanceOlemlForm.getSelectedHolding().getLocation().getLocationLevel() != null) {
461 holdingLocation = instanceEditorFormDataHandler.getLocationCode(workInstanceOlemlForm.getSelectedHolding().getLocation().getLocationLevel());
462 }
463 String callNumber;
464 String prefix;
465 if(holdingLocation != null){
466 if(getAsrHelperService().isAnASRItem(holdingLocation)){
467 List<Item> items = holdingsTree.getItems();
468 List<ASRItem> asrItems = new ArrayList<ASRItem>();
469 ASRItem asrItem = null;
470 if(items != null && items.size()>0){
471 for(Item item : items){
472 org.kuali.ole.docstore.common.document.content.instance.Item itemData = getItemOlemlRecordProcessor().fromXML(item.getContent());
473 asrItem = new ASRItem();
474 if(itemData.getAccessInformation()!=null && itemData.getAccessInformation().getBarcode()!=null){
475 asrItem.setItemBarcode(itemData.getAccessInformation().getBarcode());
476 }
477
478 Map<String,String> asrItemMap = new HashMap<String,String>();
479 asrItemMap.put("itemBarcode", asrItem.getItemBarcode());
480 List<ASRItem> existingASRItems = (List<ASRItem>)getBusinessObjectService().findMatching(ASRItem.class,asrItemMap);
481
482 if(existingASRItems.size()==0){
483 if(bib.getTitle()!=null){
484 asrItem.setTitle((bib.getTitle().length()>37)?bib.getTitle().substring(0,36):bib.getTitle());
485 }
486 if(bib.getAuthor()!=null){
487 asrItem.setAuthor((bib.getAuthor().length()>37)?bib.getAuthor().substring(0,36):bib.getAuthor());
488 }
489 if (itemData.getCallNumber() != null && itemData.getCallNumber().getNumber() != null && !itemData.getCallNumber().getNumber().isEmpty()) {
490 callNumber=(itemData.getCallNumber().getNumber().length() > 37) ? itemData.getCallNumber().getNumber().substring(0, 36) : itemData.getCallNumber().getNumber();
491 prefix=itemData.getCallNumber().getPrefix()!=null&&!itemData.getCallNumber().getPrefix().isEmpty()?itemData.getCallNumber().getPrefix():"";
492 asrItem.setCallNumber(prefix+" "+callNumber);
493 } else if(workInstanceOlemlForm.getSelectedHolding() !=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber() !=null &&
494 workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber() !=null && !workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().isEmpty()){
495 callNumber=(workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().length() > 37) ? workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().substring(0, 36) : workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber();
496 prefix=workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix()!=null&&!workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix().isEmpty()?workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix():"";
497 asrItem.setCallNumber(prefix+" "+callNumber);
498 }
499
500 asrItems.add(asrItem);
501 }
502 }
503 }
504 getBusinessObjectService().save(asrItems);
505 }
506 }
507 Holdings holdings = holdingsTree.getHoldings();
508 bibTree.getHoldingsTrees().add(holdingsTree);
509 Collections.sort(bibTree.getHoldingsTrees());
510 String docStoreData = holdings.getContent();
511 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(docStoreData);
512 workInstanceOlemlForm.setSelectedHolding(oleHoldings);
513 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
514 editorForm.setHoldingLocalIdentifier(DocumentUniqueIDPrefix.getDocumentId(holdings.getId()));
515 editorForm.setHoldingUpdatedBy(holdings.getUpdatedBy());
516 editorForm.setHoldingCreatedDate(holdings.getCreatedOn());
517 editorForm.setHoldingCreatedBy(holdings.getCreatedBy());
518 editorForm.setHoldingUpdatedDate(holdings.getUpdatedOn());
519 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, editorMessage);
520 ensureMultipleValuesInOleHoldings(oleHoldings);
521 }catch (DocstoreException e) {
522 LOG.error("Exception : ", e);
523 DocstoreException docstoreException = (DocstoreException) e;
524 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
525 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
526 } else {
527 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
528 }
529 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
530 return true;
531 } catch (Exception e) {
532 LOG.error("Exception ", e);
533 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
534 }
535 return false;
536 }
537
538 private List<Uri> ensureAtleastOneUri(List<Uri> uris) {
539 if (uris == null) {
540 uris = new ArrayList<Uri>();
541 }
542 if (uris.size() == 0) {
543 Uri uri = new Uri();
544 uris.add(uri);
545 }
546 return uris;
547 }
548
549 private List<Note> ensureAtleastOneNote(List<Note> notes) {
550 if (notes == null) {
551 notes = new ArrayList<Note>();
552 }
553 if (notes.size() == 0) {
554 Note note = new Note();
555 notes.add(note);
556 }
557 return notes;
558 }
559
560
561 private List<ExtentOfOwnership> ensureAtleastOneExtentOfOwnership(List<ExtentOfOwnership> extentOfOwnerships) {
562 if (extentOfOwnerships == null) {
563 extentOfOwnerships = new ArrayList<ExtentOfOwnership>();
564 }
565 if (extentOfOwnerships.size() == 0) {
566 ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
567 extentOfOwnership.getNote().add(new Note());
568 extentOfOwnerships.add(0, extentOfOwnership);
569 }
570 return extentOfOwnerships;
571 }
572
573
574
575
576
577
578 private InstanceEditorFormDataHandler getInstanceEditorFormDataHandler() {
579 if (null == instanceEditorFormDataHandler) {
580 instanceEditorFormDataHandler = new InstanceEditorFormDataHandler();
581 }
582 return instanceEditorFormDataHandler;
583 }
584
585 private boolean canCreateInstance(String principalId) {
586 PermissionService service = KimApiServiceLocator.getPermissionService();
587 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_ADD_INSTANCE);
588 }
589
590 private boolean canEditInstance(String principalId) {
591 PermissionService service = KimApiServiceLocator.getPermissionService();
592 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_EDIT_INSTANCE);
593 }
594
595
596
597
598
599
600 private boolean isValidHoldingsData(WorkInstanceOlemlForm workInstanceOlemlForm) {
601 OleHoldings oleHoldings = workInstanceOlemlForm.getSelectedHolding();
602 String location = null;
603 if (oleHoldings != null && oleHoldings.getLocation() != null && oleHoldings.getLocation().getLocationLevel() != null) {
604 location = oleHoldings.getLocation().getLocationLevel().getName();
605 }
606 if (location != null && location.length() != 0 && !isValidLocation(location)) {
607
608 GlobalVariables.getMessageMap().putError("documentForm.selectedHolding.location.locationLevel.name", "error.location");
609 workInstanceOlemlForm.setValidInput(false);
610 return false;
611 }
612 return true;
613 }
614
615 private boolean isValidLocation(String location) {
616
617 List<String> locationList = LocationValuesBuilder.retrieveLocationDetailsForSuggest(location);
618 if (locationList != null && locationList.size() > 0) {
619 for (String locationValue : locationList) {
620 if (locationValue.equalsIgnoreCase(location)) {
621 return true;
622 }
623 }
624 }
625 return false;
626 }
627
628 @Override
629 public EditorForm addORRemoveExtentOfOwnership(EditorForm editorForm, HttpServletRequest request) {
630 String methodName = request.getParameter("methodToCall");
631 if (methodName.equalsIgnoreCase("addExtentOfOwnership")) {
632 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
633 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
634 index++;
635 List<ExtentOfOwnership> extentOfOwnershipForUI = workInstanceOlemlForm.getSelectedHolding().getExtentOfOwnership();
636 ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
637 extentOfOwnership.getNote().add(new Note());
638 extentOfOwnershipForUI.add(index, extentOfOwnership);
639 editorForm.setDocumentForm(workInstanceOlemlForm);
640 } else if (methodName.equalsIgnoreCase("removeExtentOfOwnership")) {
641 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
642 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
643 List<ExtentOfOwnership> extentOfOwnershipForUI = workInstanceOlemlForm.getSelectedHolding().getExtentOfOwnership();
644 if (extentOfOwnershipForUI.size() > 1) {
645 extentOfOwnershipForUI.remove(index);
646 } else {
647 if (extentOfOwnershipForUI.size() == 1) {
648 extentOfOwnershipForUI.remove(index);
649 ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
650 extentOfOwnershipForUI.add(extentOfOwnership);
651 extentOfOwnership.getNote().add(new Note());
652 }
653 }
654 editorForm.setDocumentForm(workInstanceOlemlForm);
655 } else if (methodName.equalsIgnoreCase("addEOWHoldingNotes")) {
656 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
657 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
658 String selectedPath = editorForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
659 int selectedExtentIndex = Integer.parseInt(StringUtils.substring(selectedPath,
660 (StringUtils.indexOf(selectedPath, "[") + 1),
661 StringUtils.lastIndexOf(selectedPath, "]")));
662 index++;
663 List<Note> holdingsNote = workInstanceOlemlForm.getSelectedHolding().getExtentOfOwnership()
664 .get(selectedExtentIndex).getNote();
665 holdingsNote.add(index, new Note());
666 editorForm.setDocumentForm(workInstanceOlemlForm);
667 } else if (methodName.equalsIgnoreCase("removeEOWHoldingNotes")) {
668 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
669 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
670 String selectedPath = editorForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
671 int selectedExtentIndex = Integer.parseInt(StringUtils.substring(selectedPath,
672 (StringUtils.indexOf(selectedPath, "[") + 1),
673 StringUtils.lastIndexOf(selectedPath, "]")));
674 List<Note> holdingsNote = workInstanceOlemlForm.getSelectedHolding().getExtentOfOwnership()
675 .get(selectedExtentIndex).getNote();
676 if (holdingsNote.size() > 1) {
677 holdingsNote.remove(index);
678 } else {
679 if (holdingsNote.size() == 1) {
680 holdingsNote.remove(index);
681 Note note = new Note();
682 holdingsNote.add(note);
683 }
684 }
685 editorForm.setDocumentForm(workInstanceOlemlForm);
686 }
687 return editorForm;
688 }
689
690 @Override
691 public EditorForm addORRemoveAccessInformationAndHoldingsNotes(EditorForm editorForm, HttpServletRequest request) {
692 String methodName = request.getParameter("methodToCall");
693 if (methodName.equalsIgnoreCase("addAccessInformation")) {
694 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
695 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
696 index++;
697 List<Uri> accessInformation = workInstanceOlemlForm.getSelectedHolding().getUri();
698 accessInformation.add(index, new Uri());
699 editorForm.setDocumentForm(workInstanceOlemlForm);
700 } else if (methodName.equalsIgnoreCase("removeAccessInformation")) {
701 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
702 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
703 List<Uri> accessInformation = workInstanceOlemlForm.getSelectedHolding().getUri();
704 if (accessInformation.size() > 1) {
705 accessInformation.remove(index);
706 } else {
707 if (accessInformation.size() == 1) {
708 accessInformation.remove(index);
709 Uri uri = new Uri();
710 accessInformation.add(uri);
711 }
712 }
713 editorForm.setDocumentForm(workInstanceOlemlForm);
714 } else if (methodName.equalsIgnoreCase("addHoldingNotes")) {
715 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
716 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
717 index++;
718 List<Note> holdingsNote = workInstanceOlemlForm.getSelectedHolding().getNote();
719 holdingsNote.add(index, new Note());
720 editorForm.setDocumentForm(workInstanceOlemlForm);
721 } else if (methodName.equalsIgnoreCase("removeHoldingNotes")) {
722 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
723 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
724 List<Note> holdingsNote = workInstanceOlemlForm.getSelectedHolding().getNote();
725 if (holdingsNote.size() > 1) {
726 holdingsNote.remove(index);
727 } else {
728 if (holdingsNote.size() == 1) {
729 holdingsNote.remove(index);
730 Note note = new Note();
731 holdingsNote.add(note);
732 }
733 }
734 editorForm.setDocumentForm(workInstanceOlemlForm);
735 }
736 return editorForm;
737 }
738
739 private boolean isValidBib(String bibData) {
740 if (bibData.contains("collection") || bibData.contains("OAI-PMH")) {
741 return true;
742 }
743 return false;
744 }
745
746 @Override
747 public EditorForm createNewRecord(EditorForm editorForm, BibTree bibTree) {
748
749 if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkHoldingsViewPage")) {
750 editorForm.setNeedToCreateInstance(true);
751 }
752 editNewRecord(editorForm, bibTree);
753 return editorForm.getDocumentForm();
754 }
755
756
757 @Override
758 public EditorForm editNewRecord(EditorForm editorForm, BibTree bibTree) {
759 WorkInstanceOlemlForm workInstanceOlemlForm = new WorkInstanceOlemlForm();
760 if ((editorForm.getDocumentForm() instanceof WorkInstanceOlemlForm)) {
761 workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
762 workInstanceOlemlForm.setViewId(editorForm.getDocumentForm().getViewId());
763 }
764
765 workInstanceOlemlForm.setDocCategory("work");
766 workInstanceOlemlForm.setDocType("holdings");
767 workInstanceOlemlForm.setDocFormat("oleml");
768
769 if (bibTree != null && bibTree.getHoldingsTrees() != null) {
770 HoldingsTree holdingsTree = bibTree.getHoldingsTrees().get(0);
771 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
772 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
773 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent());
774 if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkHoldingsViewPage")) {
775
776 editorForm.setHeaderText("Import Bib Step-4 Item");
777
778 if (!isValidHoldingsData(workInstanceOlemlForm)) {
779 return workInstanceOlemlForm;
780 }
781 holdingsTree.getHoldings().setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
782 holdingsTree.getHoldings().setCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
783 org.kuali.ole.docstore.common.document.content.instance.Item item = itemOlemlRecordProcessor.fromXML(holdingsTree.getItems().get(0).getContent());
784 List<Note> notes = ensureAtleastOneNote(item.getNote());
785 item.setNote(notes);
786 workInstanceOlemlForm.setSelectedItem(item);
787 workInstanceOlemlForm.setViewId("WorkItemViewPage");
788
789 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,
790 "item.details.new.message");
791 } else if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkBibEditorViewPage")) {
792
793 editorForm.setHeaderText("Import Bib Step-4 Holdings");
794 workInstanceOlemlForm.setViewId("WorkHoldingsViewPage");
795
796 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,
797 "holdings.record.new.load.message");
798 workInstanceOlemlForm
799 .setSelectedHolding(oleHoldings);
800 }
801 }
802 editorForm.setDocumentForm(workInstanceOlemlForm);
803 return editorForm;
804 }
805
806 @Override
807 public EditorForm copy(EditorForm editorForm) {
808 loadDocument(editorForm);
809 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
810 workInstanceOlemlForm.getSelectedHolding().setEResourceId(workInstanceOlemlForm.geteResourceId()!=null && !workInstanceOlemlForm.geteResourceId().isEmpty()?workInstanceOlemlForm.geteResourceId():null);
811 editorForm.seteResourceId(workInstanceOlemlForm.geteResourceId()!=null && !workInstanceOlemlForm.geteResourceId().isEmpty()?workInstanceOlemlForm.geteResourceId():null);
812 editorForm.seteResourceTitle(workInstanceOlemlForm.geteResourceTitle()!=null && !workInstanceOlemlForm.geteResourceTitle().isEmpty()?workInstanceOlemlForm.geteResourceTitle():null);
813 editorForm.setDocId(null);
814 editorForm.setShowEditorFooter(false);
815 editorForm.setFromSearch(false);
816 return editorForm;
817 }
818
819 public EditorForm deleteVerify(EditorForm editorForm) {
820
821 WorkInstanceOlemlForm workInstanceOlemlForm = new WorkInstanceOlemlForm();
822 String docId = editorForm.getDocId();
823 String operation = "deleteVerify";
824
825
826
827 editorForm.setShowDeleteTree(true);
828 editorForm.setHasLink(true);
829
830 List<String> uuidList = new ArrayList<>(0);
831 uuidList.add(editorForm.getDocId());
832 DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
833 Node<DocumentTreeNode, String> docTree = null;
834 try {
835 docTree = documentSelectionTree.add(uuidList, editorForm.getDocType());
836 } catch (SolrServerException e) {
837 LOG.error("Exception :", e);
838 e.printStackTrace();
839 }
840 editorForm.getDocTree().setRootElement(docTree);
841 editorForm.setViewId("DeleteViewPage");
842 return editorForm;
843
844 }
845
846
847
848
849
850
851
852 public EditorForm delete(EditorForm editorForm) throws Exception {
853 return deleteFromDocStore(editorForm);
854 }
855
856 @Override
857 public EditorForm showBibs(EditorForm editorForm) {
858 String instanceId = "";
859 String docType = editorForm.getDocType();
860 List<Bib> bibs = new ArrayList<Bib>();
861 if ((docType.equalsIgnoreCase(DocType.HOLDINGS.getCode())) || (docType
862 .equalsIgnoreCase(DocType.ITEM.getCode()))) {
863 instanceId = editorForm.getHoldingsId();
864 }
865 if (StringUtils.isNotEmpty(instanceId)) {
866 try {
867 Holdings holdings = docstoreClient.retrieveHoldings(instanceId);
868 bibs = holdings.getBibs().getBibs();
869 } catch (Exception e) {
870 LOG.error("Exception :", e);
871 e.printStackTrace();
872 }
873 }
874 editorForm.setBibList(bibs);
875 editorForm.setViewId("ShowBibViewPage");
876 return editorForm;
877 }
878
879
880 public EditorForm bulkUpdate(EditorForm editorForm,List<String> holdingIds) {
881 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
882 String bibId = editorForm.getBibId();
883 List<BibTree> bibTreeList = new ArrayList<BibTree>();
884 BibTree bibTree = null;
885 String editorMessage = "";
886 Bib bib = null;
887 Date date = new Date();
888 SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE+" HH:mm:ss");
889 String dateStr = sdf.format(date);
890 String user = GlobalVariables.getUserSession().getPrincipalName();
891 workInstanceOlemlForm.setBibTreeList(bibTreeList);
892 editorForm.setHeaderText("Global Holdings Editor");
893 String docId = editorForm.getDocId();
894 Holdings holdings = new PHoldings();
895 OleHoldings holdingData = workInstanceOlemlForm.getSelectedHolding();
896 if (!isValidHoldingsData(workInstanceOlemlForm)) {
897 return workInstanceOlemlForm;
898 }
899 try {
900 String holdingXmlContent = getInstanceEditorFormDataHandler().buildHoldingContent(holdingData);
901 holdings.setCategory(holdingXmlContent);
902 holdings.setContent(holdingXmlContent);
903 } catch (Exception e) {
904 LOG.error("Exception :", e);
905 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS,
906 "docstore.response", e.getMessage());
907 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
908 return workInstanceOlemlForm;
909 }
910 holdings.setId(docId);
911 String canUpdateStaffOnlyFlag = "false";
912 if (editorForm.getStaffOnlyFlagInGlobalEdit() != null && editorForm.getStaffOnlyFlagInGlobalEdit().equalsIgnoreCase("Y")) {
913 canUpdateStaffOnlyFlag = "true";
914 editorForm.setStaffOnlyFlagForHoldings(true);
915 holdings.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
916 }
917 else if (editorForm.getStaffOnlyFlagInGlobalEdit() != null && editorForm.getStaffOnlyFlagInGlobalEdit().equalsIgnoreCase("N")) {
918 canUpdateStaffOnlyFlag = "true";
919 editorForm.setStaffOnlyFlagForHoldings(false);
920 holdings.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
921 }
922 holdings.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
923 holdings.setCreatedBy(editorForm.getCreatedBy());
924 holdings.setCreatedOn(editorForm.getCreatedDate());
925 holdings.setUpdatedBy(user);
926 holdings.setUpdatedOn(dateStr);
927 String holdingsCreatedDate = null;
928 Format formatter = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
929 holdingsCreatedDate = formatter.format(new Date());
930 holdings.setLastUpdated(holdingsCreatedDate);
931
932 holdings.setCategory(editorForm.getDocCategory());
933 holdings.setType(editorForm.getDocType());
934 holdings.setFormat(editorForm.getDocFormat());
935 try {
936 getDocstoreClientLocator().getDocstoreClient().bulkUpdateHoldings(holdings, holdingIds,canUpdateStaffOnlyFlag);
937 }
938 catch (DocstoreException e) {
939 LOG.error("Exception :", e);
940 DocstoreException docstoreException = (DocstoreException) e;
941 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
942 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
943 } else {
944 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
945 }
946
947 return workInstanceOlemlForm;
948 }
949 catch(Exception ne){
950 LOG.error("Exception :", ne);
951 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.submit.fail.message");
952 return workInstanceOlemlForm;
953 }
954 editorForm.setUpdatedDate(holdings.getUpdatedOn());
955 editorForm.setUpdatedBy(holdings.getUpdatedBy());
956 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
957 editorMessage = "holdings.record.update.message";
958 workInstanceOlemlForm.setViewId("WorkHoldingsViewPage");
959
960
961 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, editorMessage);
962 return workInstanceOlemlForm;
963
964 }
965
966 }