1 package org.kuali.ole.describe.controller;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.commons.lang3.StringUtils;
5 import org.apache.log4j.Logger;
6 import org.apache.solr.client.solrj.SolrServerException;
7 import org.kuali.ole.DocumentUniqueIDPrefix;
8 import org.kuali.asr.service.ASRHelperServiceImpl;
9 import org.kuali.ole.OLEConstants;
10 import org.kuali.ole.OLEParameterConstants;
11 import org.kuali.ole.deliver.bo.ASRItem;
12 import org.kuali.ole.deliver.bo.OLELoanIntransitRecordHistory;
13 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
14 import org.kuali.ole.deliver.bo.OleLoanDocument;
15 import org.kuali.ole.deliver.calendar.service.DateUtil;
16 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
17 import org.kuali.ole.describe.bo.DocumentSelectionTree;
18 import org.kuali.ole.describe.bo.DocumentTreeNode;
19 import org.kuali.ole.describe.bo.InstanceEditorFormDataHandler;
20 import org.kuali.ole.describe.form.EditorForm;
21 import org.kuali.ole.describe.form.WorkBibMarcForm;
22 import org.kuali.ole.describe.form.WorkInstanceOlemlForm;
23 import org.kuali.ole.describe.keyvalue.LocationValuesBuilder;
24 import org.kuali.ole.docstore.common.client.DocstoreClient;
25 import org.kuali.ole.docstore.common.document.*;
26 import org.kuali.ole.docstore.common.document.HoldingsTree;
27 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
28 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
29 import org.kuali.ole.docstore.common.document.content.enums.DocType;
30 import org.kuali.ole.docstore.common.document.content.instance.*;
31 import org.kuali.ole.docstore.common.document.content.instance.Item;
32 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
33 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
34 import org.kuali.ole.docstore.common.exception.DocstoreException;
35 import org.kuali.ole.docstore.engine.client.DocstoreLocalClient;
36 import org.kuali.ole.select.bo.OLEDonor;
37 import org.kuali.ole.select.bo.OLELinkPurapDonor;
38 import org.kuali.ole.select.businessobject.OleCopy;
39 import org.kuali.ole.select.document.OlePurchaseOrderDocument;
40 import org.kuali.ole.sys.context.SpringContext;
41 import org.kuali.ole.utility.Constants;
42 import org.kuali.rice.core.api.config.property.ConfigurationService;
43 import org.kuali.rice.core.api.datetime.DateTimeService;
44 import org.kuali.rice.core.api.util.RiceConstants;
45 import org.kuali.rice.core.api.util.tree.Node;
46 import org.kuali.rice.kim.api.permission.PermissionService;
47 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
48 import org.kuali.rice.krad.service.BusinessObjectService;
49 import org.kuali.rice.krad.service.KRADServiceLocator;
50 import org.kuali.rice.krad.uif.UifParameters;
51 import org.kuali.rice.krad.util.GlobalVariables;
52 import org.kuali.rice.krad.util.KRADConstants;
53
54 import javax.servlet.http.HttpServletRequest;
55 import java.text.DateFormat;
56 import java.text.Format;
57 import java.text.ParseException;
58 import java.text.SimpleDateFormat;
59 import java.util.*;
60
61
62
63
64
65
66
67
68 public class WorkItemOlemlEditor extends AbstractEditor {
69
70 private static final Logger LOG = Logger.getLogger(WorkItemOlemlEditor.class);
71 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
72 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
73 ASRHelperServiceImpl asrHelperService = new ASRHelperServiceImpl();
74 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
75
76 private static WorkItemOlemlEditor workItemOlemlEditor = null;
77 private InstanceEditorFormDataHandler instanceEditorFormDataHandler = null;
78
79 DocstoreClient docstoreClient = getDocstoreLocalClient();
80
81 private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService;
82
83 private OleDeliverRequestDocumentHelperServiceImpl getOleDeliverRequestDocumentHelperService() {
84 if (oleDeliverRequestDocumentHelperService == null) {
85 oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
86 }
87 return oleDeliverRequestDocumentHelperService;
88 }
89
90 public static WorkItemOlemlEditor getInstance() {
91 if (workItemOlemlEditor == null) {
92 workItemOlemlEditor = new WorkItemOlemlEditor();
93 }
94 return workItemOlemlEditor;
95 }
96
97 private WorkItemOlemlEditor() {
98
99 }
100
101 @Override
102 public EditorForm loadDocument(EditorForm editorForm) {
103 WorkInstanceOlemlForm workInstanceOlemlForm = new WorkInstanceOlemlForm();
104 String directory = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(org.kuali.ole.sys.OLEConstants.EXTERNALIZABLE_HELP_URL_KEY);
105 editorForm.setExternalHelpUrl(directory+"/reference/webhelp/OLE/content/ch04s01.html#_Item");
106 editorForm.setHeaderText("Item");
107 editorForm.setHasLink(true);
108 String bibId = editorForm.getBibId();
109 String holdingsId = editorForm.getInstanceId();
110 String docId = editorForm.getDocId();
111 OleHoldings oleHoldings = new OleHoldings();
112 String docStoreData = null;
113 List<BibTree> bibTreeList = new ArrayList<>();
114 Date date = new Date();
115 SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE+" HH:mm:ss");
116 String dateStr = sdf.format(date);
117 BibTree bibTree = null;
118 try {
119 bibTree = docstoreClient.retrieveBibTree(bibId);
120 bibTreeList.add(bibTree);
121 workInstanceOlemlForm.setBibTreeList(bibTreeList);
122 if (!org.kuali.ole.docstore.model.enums.DocFormat.DUBLIN_UNQUALIFIED.getCode().equals(bibTree.getBib().getFormat())) {
123 editorForm.setTitle(bibTree.getBib().getTitle() + " / " + bibTree.getBib().getAuthor());
124 }
125 Holdings holdings = docstoreClient.retrieveHoldings(holdingsId);
126 oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
127 workInstanceOlemlForm.setSelectedHolding(oleHoldings);
128 } catch (DocstoreException e) {
129 LOG.error(e);
130 DocstoreException docstoreException = (DocstoreException) e;
131 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
132 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
133 } else {
134 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
135 }
136 return workInstanceOlemlForm;
137 } catch (Exception e) {
138 LOG.error("Exception ", e);
139 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
140 }
141
142 try {
143 if (StringUtils.isNotEmpty(docId)) {
144 editorForm.setItemLocalIdentifier(DocumentUniqueIDPrefix.getDocumentId(docId));
145 org.kuali.ole.docstore.common.document.Item itemDocument = docstoreClient.retrieveItem(editorForm.getDocId());
146 docStoreData = itemDocument.getContent();
147 Item item = itemOlemlRecordProcessor.fromXML(docStoreData);
148 ensureAccessInformation(item);
149
150 if (item != null && item.getItemStatusEffectiveDate() != null) {
151 String[] itemStatusEffectiveDate = item.getItemStatusEffectiveDate().split(" ");
152 item.setItemStatusEffectiveDate(itemStatusEffectiveDate[0]);
153 }
154 String itemStatus = null;
155 if (item.getItemStatus() != null && item.getItemStatus().getCodeValue() != null) {
156 itemStatus = item.getItemStatus().getCodeValue();
157 workInstanceOlemlForm.setOldItemStatus(itemStatus);
158 }
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 String itemProperty = getInstanceEditorFormDataHandler().getParameter("OLE-DESC", "Describe", "ITEM_STATUS_READONLY");
194 String[] itemArray = itemProperty.split(",");
195 for (String status : itemArray) {
196 if (status.equalsIgnoreCase(itemStatus)) {
197 workInstanceOlemlForm.setItemStatusNonEditable(true);
198 break;
199 }
200 workInstanceOlemlForm.setItemStatusNonEditable(false);
201 }
202 itemProperty = getInstanceEditorFormDataHandler().getParameter("OLE-DESC", "Describe", "EDIT_HOLDINGS_INFO_IN_ITEM_SCREEN");
203 boolean editable;
204 if (itemProperty != null) {
205 editable = Boolean.valueOf(itemProperty);
206 workInstanceOlemlForm.setHoldingsDataInItemReadOnly(editable);
207 }
208 editorForm.setStaffOnlyFlagForItem(itemDocument.isStaffOnly());
209 editorForm.setItemCreatedDate(itemDocument.getCreatedOn());
210 editorForm.setItemCreatedBy(itemDocument.getCreatedBy());
211 editorForm.setItemUpdatedDate(itemDocument.getUpdatedOn());
212 editorForm.setItemUpdatedBy(itemDocument.getUpdatedBy());
213
214 List<Note> notes = ensureAtleastOneNote(item.getNote());
215 item.setNote(notes);
216 workInstanceOlemlForm.setSelectedItem(item);
217 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
218 workInstanceOlemlForm.setViewId("WorkItemViewPage");
219 if (item.getAccessInformation()!=null && StringUtils.isNotEmpty(item.getAccessInformation().getBarcode())) {
220 Map map = new HashMap();
221 map.put("itemBarcode", item.getAccessInformation().getBarcode());
222 List<OLELoanIntransitRecordHistory> oleLoanIntransitRecordHistories = (List<OLELoanIntransitRecordHistory>) KRADServiceLocator.getBusinessObjectService().findMatching(OLELoanIntransitRecordHistory.class, map);
223 if (CollectionUtils.isNotEmpty(oleLoanIntransitRecordHistories)) {
224 editorForm.setOleLoanIntransitRecordHistories(oleLoanIntransitRecordHistories);
225 }
226 }
227
228 if (editorForm.getEditable().equalsIgnoreCase("false")) {
229 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "item.record.load.message");
230 } else {
231 boolean hasPermission = canEditItem(GlobalVariables.getUserSession().getPrincipalId());
232 if (hasPermission) {
233 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "item.record.load.message");
234 } else {
235 editorForm.setHideFooter(false);
236 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.ERROR_EDIT_ITEM);
237 }
238 }
239 } else {
240
241 Item item = new Item();
242 String itemProperty = getInstanceEditorFormDataHandler().getParameter("OLE-DESC", "Describe", "EDIT_HOLDINGS_INFO_IN_ITEM_SCREEN");
243 String[] itemArray = null;
244 if (itemProperty != null) {
245 itemArray = itemProperty.split(",");
246 }
247 if (itemArray != null) {
248 for (String status : itemArray) {
249 if (status.equalsIgnoreCase("TRUE")) {
250 workInstanceOlemlForm.setHoldingsDataInItemReadOnly(true);
251 } else if (status.equalsIgnoreCase("FALSE")) {
252 workInstanceOlemlForm.setHoldingsDataInItemReadOnly(false);
253 }
254 }
255 }
256 List<Note> notes = ensureAtleastOneNote(item.getNote());
257 item.setNote(notes);
258 ensureAccessInformation(item);
259 workInstanceOlemlForm.setSelectedItem(item);
260 this.addItemInformation(editorForm);
261 editorForm.setStaffOnlyFlagForItem(false);
262 editorForm.setItemCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
263 editorForm.setItemCreatedDate(dateStr);
264 editorForm.setItemUpdatedBy(null);
265 editorForm.setItemUpdatedDate(null);
266 workInstanceOlemlForm.setViewId("WorkItemViewPage");
267 boolean hasPermission = canCreateItem(GlobalVariables.getUserSession().getPrincipalId());
268 if (hasPermission) {
269 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,
270 "item.details.new.message");
271 } else {
272 editorForm.setHideFooter(false);
273 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.ERROR_CREATE_ITEM);
274 }
275 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
276 }
277 } catch (DocstoreException e) {
278 LOG.error(e);
279 DocstoreException docstoreException = (DocstoreException) e;
280 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
281 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
282 } else {
283 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
284 }
285 return workInstanceOlemlForm;
286 } catch (Exception e) {
287 LOG.error("Exception ", e);
288 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
289 }
290 return workInstanceOlemlForm;
291 }
292
293 private void ensureAccessInformation(Item item) {
294 if(item.getAccessInformation() == null) {
295 AccessInformation accessInformation = new AccessInformation();
296 Uri uri = new Uri();
297 uri.setValue("");
298 uri.setResolvable("");
299 accessInformation.setUri(uri);
300 item.setAccessInformation(accessInformation);
301 }
302 }
303
304 @Override
305 public EditorForm saveDocument(EditorForm editorForm) {
306 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
307 Item itemData = workInstanceOlemlForm.getSelectedItem();
308 Date date = new Date();
309 SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATE_FORMAT);
310 String dateStr = sdf.format(date);
311 String user = GlobalVariables.getUserSession().getLoggedInUserPrincipalName();
312 String docId = editorForm.getDocId();
313 String instanceId = editorForm.getInstanceId();
314 String editorMessage = "";
315 String callNumber;
316 String prefix;
317 Bib bib = null;
318
319 editorForm.setHeaderText("Item");
320 try {
321 bib = docstoreClient.retrieveBib(editorForm.getBibId());
322 if (!org.kuali.ole.docstore.model.enums.DocFormat.DUBLIN_UNQUALIFIED.getCode().equals(bib.getFormat())) {
323 editorForm.setTitle(bib.getTitle() + " / " + bib.getAuthor());
324 }
325 } catch (DocstoreException e) {
326 LOG.error(e);
327 DocstoreException docstoreException = (DocstoreException) e;
328 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
329 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
330 } else {
331 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
332 }
333 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
334 return workInstanceOlemlForm;
335 } catch (Exception e) {
336 LOG.error("Exception ", e);
337 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
338 }
339
340 try {
341 if (StringUtils.isNotEmpty(docId)) {
342
343 if (editorForm.getItemStatusSelection().equals("true")) {
344 Format formatter = new SimpleDateFormat("MM/dd/yyyy");
345 itemData.setItemStatusEffectiveDate(formatter.format(new Date()));
346 }
347 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
348 if (!itemData.isClaimsReturnedFlag()) {
349 itemData.setClaimsReturnedNote(null);
350 itemData.setClaimsReturnedFlagCreateDate(null);
351 } else {
352 addClaimsReturnedItemHistory(itemData, user);
353 getOleDeliverRequestDocumentHelperService().cancelPendingRequestForClaimsReturnedItem(itemData.getItemIdentifier());
354 }
355
356 if(itemData.isItemDamagedStatus()){
357 addItemDamagedHistory(itemData, user);
358 }
359 try {
360 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemData.getItemIdentifier());
361 ItemOlemlRecordProcessor itemOlemlRecordProcessor1 = new ItemOlemlRecordProcessor();
362 org.kuali.ole.docstore.common.document.content.instance.Item oleItem = itemOlemlRecordProcessor1.fromXML(item.getContent());
363 MissingPieceItemRecord missingPieceItemRecord = new MissingPieceItemRecord();
364 List<MissingPieceItemRecord> missingPieceItemRecordList = new ArrayList<>();
365 if (itemData.isMissingPieceFlag() && !oleItem.isMissingPieceFlag()) {
366 missingPieceItemRecord.setMissingPieceFlagNote(itemData.getMissingPieceFlagNote());
367 missingPieceItemRecord.setMissingPieceCount(itemData.getMissingPiecesCount());
368 String parsedDate = df.format((new Date()));
369 missingPieceItemRecord.setMissingPieceDate(parsedDate);
370 missingPieceItemRecord.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
371 missingPieceItemRecord.setPatronBarcode(null);
372 missingPieceItemRecord.setPatronId(itemData.getCurrentBorrower());
373 missingPieceItemRecord.setItemId(itemData.getItemIdentifier());
374 if (itemData.getMissingPieceItemRecordList() != null && itemData.getMissingPieceItemRecordList().size() > 0) {
375 itemData.getMissingPieceItemRecordList().add(missingPieceItemRecord);
376 } else {
377 missingPieceItemRecordList.add(missingPieceItemRecord);
378 itemData.setMissingPieceItemRecordList(missingPieceItemRecordList);
379 }
380
381
382 } else {
383 if (itemData.isMissingPieceFlag() && oleItem.isMissingPieceFlag()) {
384 Map<String, String> map = new HashMap<>();
385 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(itemData.getItemIdentifier()));
386 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord> missingPieceItemRecordList1 = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord>) KRADServiceLocator.getBusinessObjectService()
387 .findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord.class, map, "missingPieceItemId", true);
388 List<MissingPieceItemRecord> missingPieceItemRecords = new ArrayList<>();
389 for (int index = 0; index < missingPieceItemRecordList1.size(); index++) {
390 MissingPieceItemRecord missingPieceItemRecord1 = new MissingPieceItemRecord();
391 if (index == missingPieceItemRecordList1.size() - 1) {
392 DateFormat dfs = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
393 String missingPieceItemDate = dfs.format((new Date()));
394 missingPieceItemRecord1.setMissingPieceDate(missingPieceItemDate);
395 missingPieceItemRecord1.setMissingPieceCount(itemData.getMissingPiecesCount());
396 missingPieceItemRecord1.setPatronBarcode(null);
397 missingPieceItemRecord1.setPatronId(itemData.getCurrentBorrower());
398 missingPieceItemRecord1.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
399 missingPieceItemRecord1.setItemId(itemData.getItemIdentifier());
400 missingPieceItemRecord1.setMissingPieceFlagNote(itemData.getMissingPieceFlagNote());
401 missingPieceItemRecords.add(missingPieceItemRecord1);
402
403 } else {
404 if (missingPieceItemRecordList1.get(index).getMissingPieceDate() != null && !missingPieceItemRecordList1.get(index).getMissingPieceDate().toString().isEmpty()) {
405 SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
406 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
407 Date missingPieceItemDate = null;
408 try {
409 missingPieceItemDate = format2.parse(missingPieceItemRecordList1.get(index).getMissingPieceDate().toString());
410 } catch (org.kuali.ole.sys.exception.ParseException e) {
411 LOG.error("format string to Date " + e);
412 }
413 missingPieceItemRecord1.setMissingPieceDate(format1.format(missingPieceItemDate).toString());
414 }
415 missingPieceItemRecord1.setMissingPieceFlagNote(missingPieceItemRecordList1.get(index).getMissingPieceFlagNote());
416 missingPieceItemRecord1.setMissingPieceCount(missingPieceItemRecordList1.get(index).getMissingPieceCount());
417 missingPieceItemRecord1.setOperatorId(missingPieceItemRecordList1.get(index).getOperatorId());
418 missingPieceItemRecord1.setPatronBarcode(missingPieceItemRecordList1.get(index).getPatronBarcode());
419 missingPieceItemRecord1.setPatronId(missingPieceItemRecordList1.get(index).getPatronId());
420 missingPieceItemRecord1.setItemId(missingPieceItemRecordList1.get(index).getItemId());
421 missingPieceItemRecords.add(missingPieceItemRecord1);
422 }
423 }
424 itemData.setMissingPieceItemRecordList(missingPieceItemRecords);
425 }
426 }
427 } catch (Exception e) {
428 LOG.error("Exception ", e);
429 }
430 workInstanceOlemlForm.setViewId("WorkItemViewPage");
431 if (!isValidItemData(workInstanceOlemlForm)) {
432
433 return workInstanceOlemlForm;
434 }
435
436 String itemId = editorForm.getDocId();
437 itemData.setItemIdentifier(itemId);
438 String itemXmlContent = getInstanceEditorFormDataHandler().buildItemContent(itemData);
439
440 ItemOleml itemOleml = new ItemOleml();
441 itemOleml.setContent(itemXmlContent);
442 itemOleml.setId(itemId);
443 itemOleml.setType(editorForm.getDocType());
444 itemOleml.setFormat(editorForm.getDocFormat());
445 itemOleml.setUpdatedBy(user);
446 itemOleml.setUpdatedOn(dateStr);
447 itemOleml.setStaffOnly(editorForm.isStaffOnlyFlagForItem());
448 itemOleml.setCategory(editorForm.getDocCategory());
449 long startTime = System.currentTimeMillis();
450 try {
451 docstoreClient.updateItem(itemOleml);
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
461 Holdings holdings = null;
462 try {
463 holdings = docstoreClient.retrieveHoldings(editorForm.getInstanceId());
464 } catch (Exception e1) {
465 LOG.error("Exception :", e1);
466 docstoreException = (DocstoreException) e1;
467 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
468 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
469 } else {
470 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
471 }
472 }
473 String docStoreData = holdings.getContent();
474 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(docStoreData);
475 workInstanceOlemlForm.setSelectedHolding(oleHoldings);
476
477 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
478 return workInstanceOlemlForm;
479 } catch (Exception e) {
480 LOG.error("Exception ", e);
481 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
482 }
483 long endTime = System.currentTimeMillis();
484 editorForm.setSolrTime(String.valueOf((endTime - startTime) / 1000));
485 if(itemData.getLocation()!=null){
486 String location = instanceEditorFormDataHandler.getLocationCode(itemData.getLocation().getLocationLevel());
487 if(asrHelperService.isAnASRItem(location)){
488
489 Map<String,String> asrItemMap = new HashMap<String,String>();
490 asrItemMap.put("itemBarcode",itemData.getAccessInformation().getBarcode());
491 List<ASRItem> asrItems = (List<ASRItem>)businessObjectService.findMatching(ASRItem.class,asrItemMap);
492 if(asrItems.size()==0){
493 ASRItem asrItem = new ASRItem();
494 if(itemData.getAccessInformation()!=null && itemData.getAccessInformation().getBarcode()!=null){
495 asrItem.setItemBarcode(itemData.getAccessInformation().getBarcode());
496 }
497 if(bib.getTitle()!=null){
498 asrItem.setTitle((bib.getTitle().length()>37)?bib.getTitle().substring(0,36):bib.getTitle());
499 }
500 if(bib.getAuthor()!=null){
501 asrItem.setAuthor((bib.getAuthor().length()>37)?bib.getAuthor().substring(0,36):bib.getAuthor());
502 }
503 if (itemData.getCallNumber() != null && itemData.getCallNumber().getNumber() != null && !itemData.getCallNumber().getNumber().isEmpty()){
504 callNumber=(itemData.getCallNumber().getNumber().length() > 37) ? itemData.getCallNumber().getNumber().substring(0, 36) : itemData.getCallNumber().getNumber();
505 prefix=itemData.getCallNumber().getPrefix()!=null&&!itemData.getCallNumber().getPrefix().isEmpty()?itemData.getCallNumber().getPrefix():"";
506 asrItem.setCallNumber(prefix+" "+callNumber);
507 }
508 else if(workInstanceOlemlForm.getSelectedHolding()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber()!=null && !workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().isEmpty()){
509 callNumber=(workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().length() > 37) ? workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().substring(0, 36) : workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber();
510 prefix=workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix()!=null&&!workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix().isEmpty()?workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix():"";
511 asrItem.setCallNumber(prefix+" "+callNumber);
512 }
513 businessObjectService.save(asrItem);
514 }
515 }
516 }else if(workInstanceOlemlForm.getSelectedHolding().getLocation()!=null){
517 OleHoldings oleHoldings = workInstanceOlemlForm.getSelectedHolding();
518 String location = oleHoldings.getLocation().getLocationLevel().getName();
519 if(asrHelperService.isAnASRItem(location)){
520 Map<String,String> asrItemMap = new HashMap<String,String>();
521 asrItemMap.put("itemBarcode",itemData.getAccessInformation().getBarcode());
522 List<ASRItem> asrItems = (List<ASRItem>)businessObjectService.findMatching(ASRItem.class,asrItemMap);
523 if(asrItems.size()==0){
524 ASRItem asrItem = new ASRItem();
525 if(itemData.getAccessInformation()!=null && itemData.getAccessInformation().getBarcode()!=null){
526 asrItem.setItemBarcode(itemData.getAccessInformation().getBarcode());
527 }
528 if(bib.getTitle()!=null){
529 asrItem.setTitle((bib.getTitle().length()>37)?bib.getTitle().substring(0,36):bib.getTitle());
530 }
531 if(bib.getAuthor()!=null){
532 asrItem.setAuthor((bib.getAuthor().length()>37)?bib.getAuthor().substring(0,36):bib.getAuthor());
533 }
534 if (itemData.getCallNumber() != null && itemData.getCallNumber().getNumber() != null && !itemData.getCallNumber().getNumber().isEmpty()){
535 callNumber=(itemData.getCallNumber().getNumber().length() > 37) ? itemData.getCallNumber().getNumber().substring(0, 36) : itemData.getCallNumber().getNumber();
536 prefix=itemData.getCallNumber().getPrefix()!=null&&!itemData.getCallNumber().getPrefix().isEmpty()?itemData.getCallNumber().getPrefix():"";
537 asrItem.setCallNumber(prefix+" "+callNumber);
538 }
539 else if(workInstanceOlemlForm.getSelectedHolding()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber()!=null && !workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().isEmpty()){
540 callNumber=(workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().length() > 37) ? workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().substring(0, 36) : workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber();
541 prefix=workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix()!=null&&!workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix().isEmpty()?workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix():"";
542 asrItem.setCallNumber(prefix+" "+callNumber);
543
544 }
545 businessObjectService.save(asrItem);
546 }
547 }
548 }
549 String itemProperty = getInstanceEditorFormDataHandler().getParameter("OLE-DESC", "Describe", "EDIT_HOLDINGS_INFO_IN_ITEM_SCREEN");
550 String[] itemArray = null;
551 if (itemProperty != null) {
552 itemArray = itemProperty.split(",");
553 }
554 for (String status : itemArray) {
555 if (status.equalsIgnoreCase("TRUE")) {
556 workInstanceOlemlForm.setHoldingsDataInItemReadOnly(true);
557 } else if (status.equalsIgnoreCase("FALSE")) {
558 workInstanceOlemlForm.setHoldingsDataInItemReadOnly(false);
559 }
560 }
561 String holdingId = workInstanceOlemlForm.getSelectedHolding().getHoldingsIdentifier();
562 OleHoldings holdingData = workInstanceOlemlForm.getSelectedHolding();
563 String holdingXmlContent = getInstanceEditorFormDataHandler().buildHoldingContent(holdingData);
564 Holdings holdings = docstoreClient.retrieveHoldings(holdingId);
565 holdings.setBib(bib);
566 holdings.setContent(holdingXmlContent);
567 holdings.setCategory(editorForm.getDocCategory());
568 holdings.setType(DocType.HOLDINGS.getCode());
569 holdings.setFormat(editorForm.getDocFormat());
570 docstoreClient.updateHoldings(holdings);
571 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
572 if (!isValidHoldingsData(workInstanceOlemlForm)) {
573 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
574 return workInstanceOlemlForm;
575 }
576 editorMessage = "item.record.update.message";
577
578 } else {
579
580 if (!isValidItemData(workInstanceOlemlForm)) {
581
582 return workInstanceOlemlForm;
583 }
584 String staffOnlyFlagForItem = String.valueOf(editorForm.isStaffOnlyFlagForItem());
585 Item oleItem = workInstanceOlemlForm.getSelectedItem();
586 String itemXmlContent = getInstanceEditorFormDataHandler().buildItemContent(oleItem, staffOnlyFlagForItem);
587 ItemOleml itemDoc = new ItemOleml();
588 itemDoc.setCategory(DocCategory.WORK.getCode());
589 itemDoc.setType(DocType.ITEM.getCode());
590 itemDoc.setFormat(DocFormat.OLEML.getCode());
591 itemDoc.setCreatedOn(dateStr);
592 itemDoc.setCreatedBy(user);
593 itemDoc.setStaffOnly(editorForm.isStaffOnlyFlagForItem());
594 itemDoc.setContent(itemXmlContent);
595 Holdings holdings = new PHoldings();
596 holdings.setId(editorForm.getInstanceId());
597 itemDoc.setHolding(holdings);
598 long startTime = System.currentTimeMillis();
599 try {
600 docstoreClient.createItem(itemDoc);
601 } catch (Exception e) {
602 LOG.error("Exception :", e);
603 DocstoreException docstoreException = (DocstoreException) e;
604 String errorCode = docstoreException.getErrorCode();
605 if (StringUtils.isNotEmpty(errorCode)) {
606 Map<String, String> paramsMap = docstoreException.getErrorParams();
607 if (paramsMap != null && paramsMap.size() > 0 && paramsMap.containsKey("barcode")) {
608 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, errorCode, paramsMap.get("barcode"));
609 } else {
610 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, errorCode);
611 }
612 } else {
613 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
614 }
615
616 try {
617 holdings = docstoreClient.retrieveHoldings(editorForm.getInstanceId());
618 } catch (Exception e1) {
619 LOG.error("Exception :", e1);
620 docstoreException = (DocstoreException) e1;
621 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
622 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
623 } else {
624 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
625 }
626 }
627 String docStoreData = holdings.getContent();
628 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(docStoreData);
629 workInstanceOlemlForm.setSelectedHolding(oleHoldings);
630
631 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
632 return workInstanceOlemlForm;
633 }
634 long endtime = System.currentTimeMillis();
635 editorForm.setSolrTime(String.valueOf((endtime-startTime)/1000));
636 if(oleItem.getLocation()!=null){
637 String location = oleItem.getLocation().getLocationLevel().getName();
638 if (asrHelperService.isAnASRItem(location)) {
639 Map<String, String> asrItemMap = new HashMap<String, String>();
640 asrItemMap.put("itemBarcode", oleItem.getAccessInformation().getBarcode());
641 List<ASRItem> asrItems = (List<ASRItem>) businessObjectService.findMatching(ASRItem.class, asrItemMap);
642 if (asrItems.size() == 0) {
643 ASRItem asrItem = new ASRItem();
644 if (oleItem.getAccessInformation() != null && oleItem.getAccessInformation().getBarcode() != null) {
645 asrItem.setItemBarcode(oleItem.getAccessInformation().getBarcode());
646 }
647 if (bib.getTitle() != null) {
648 asrItem.setTitle((bib.getTitle().length() > 37) ? bib.getTitle().substring(0, 36) : bib.getTitle());
649 }
650 if (bib.getAuthor() != null) {
651 asrItem.setAuthor((bib.getAuthor().length() > 37) ? bib.getAuthor().substring(0, 36) : bib.getAuthor());
652 }
653 if (oleItem.getCallNumber() != null && oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().isEmpty()){
654 callNumber=(oleItem.getCallNumber().getNumber().length() > 37) ? oleItem.getCallNumber().getNumber().substring(0, 36) : oleItem.getCallNumber().getNumber();
655 prefix=oleItem.getCallNumber().getPrefix()!=null&&!oleItem.getCallNumber().getPrefix().isEmpty()?oleItem.getCallNumber().getPrefix():"";
656 asrItem.setCallNumber(prefix+" "+callNumber);
657 }
658 else if(workInstanceOlemlForm.getSelectedHolding()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber()!=null && !workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().isEmpty()){
659 callNumber=(workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().length() > 37) ? workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().substring(0, 36) : workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber();
660 prefix=workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix()!=null&&!workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix().isEmpty()?workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix():"";
661 asrItem.setCallNumber(prefix+" "+callNumber);
662 }
663 businessObjectService.save(asrItem);
664 }
665 }
666 }else if(workInstanceOlemlForm.getSelectedHolding().getLocation()!=null){
667 OleHoldings oleHoldings = workInstanceOlemlForm.getSelectedHolding();
668 String location = oleHoldings.getLocation().getLocationLevel().getName();
669 if (asrHelperService.isAnASRItem(location)) {
670 Map<String, String> asrItemMap = new HashMap<String, String>();
671 asrItemMap.put("itemBarcode", oleItem.getAccessInformation().getBarcode());
672 List<ASRItem> asrItems = (List<ASRItem>) businessObjectService.findMatching(ASRItem.class, asrItemMap);
673 if (asrItems.size() == 0) {
674 ASRItem asrItem = new ASRItem();
675 if (oleItem.getAccessInformation() != null && oleItem.getAccessInformation().getBarcode() != null) {
676 asrItem.setItemBarcode(oleItem.getAccessInformation().getBarcode());
677 }
678 if (bib.getTitle() != null) {
679 asrItem.setTitle((bib.getTitle().length() > 37) ? bib.getTitle().substring(0, 36) : bib.getTitle());
680 }
681 if (bib.getAuthor() != null) {
682 asrItem.setAuthor((bib.getAuthor().length() > 37) ? bib.getAuthor().substring(0, 36) : bib.getAuthor());
683 }
684 if (oleItem.getCallNumber() != null && oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().isEmpty()){
685 callNumber=(oleItem.getCallNumber().getNumber().length() > 37) ? oleItem.getCallNumber().getNumber().substring(0, 36) : oleItem.getCallNumber().getNumber();
686 prefix=oleItem.getCallNumber().getPrefix()!=null&&!oleItem.getCallNumber().getPrefix().isEmpty()?oleItem.getCallNumber().getPrefix():"";
687 asrItem.setCallNumber(prefix+" "+callNumber);
688 }
689 else if(workInstanceOlemlForm.getSelectedHolding()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber()!=null && workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber()!=null && !workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().isEmpty()){
690 callNumber=(workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().length() > 37) ? workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber().substring(0, 36) : workInstanceOlemlForm.getSelectedHolding().getCallNumber().getNumber();
691 prefix=workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix()!=null&&!workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix().isEmpty()?workInstanceOlemlForm.getSelectedHolding().getCallNumber().getPrefix():"";
692 asrItem.setCallNumber(prefix+" "+callNumber);
693
694 }
695 businessObjectService.save(asrItem);
696 }
697 }
698 }
699 editorForm.setDocId(itemDoc.getId());
700 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
701 editorMessage = "item.record.load.message";
702 }
703 } catch (Exception e) {
704 LOG.error("Exception :", e);
705 DocstoreException docstoreException = (DocstoreException) e;
706 if (StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
707 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
708 } else {
709 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
710 }
711 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
712 return workInstanceOlemlForm;
713 }
714 org.kuali.ole.docstore.common.document.Item itemDocument = null;
715 try {
716 Holdings holdings = null;
717 try {
718 holdings = docstoreClient.retrieveHoldings(editorForm.getInstanceId());
719 } catch (Exception e) {
720 LOG.error("Exception :", e);
721 DocstoreException docstoreException = (DocstoreException) e;
722 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
723 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
724 } else {
725 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
726 }
727 }
728 String docStoreData = holdings.getContent();
729 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(docStoreData);
730 workInstanceOlemlForm.setSelectedHolding(oleHoldings);
731 try {
732 itemDocument = docstoreClient.retrieveItem(editorForm.getDocId());
733 } catch (DocstoreException e) {
734 LOG.error(e);
735 DocstoreException docstoreException = (DocstoreException) e;
736 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
737 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
738 } else {
739 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
740 }
741 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
742 return workInstanceOlemlForm;
743 } catch (Exception e) {
744 LOG.error("Exception ", e);
745 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
746 }
747 Item item = itemOlemlRecordProcessor.fromXML(itemDocument.getContent());
748 editorForm.setItemLocalIdentifier(DocumentUniqueIDPrefix.getDocumentId(item.getItemIdentifier()));
749 editorForm.setItemCreatedBy(itemDocument.getCreatedBy());
750 editorForm.setItemCreatedDate(itemDocument.getCreatedOn());
751 editorForm.setItemUpdatedBy(itemDocument.getUpdatedBy());
752 editorForm.setItemUpdatedDate(itemDocument.getUpdatedOn());
753 workInstanceOlemlForm.setSelectedItem(item);
754 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
755 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, editorMessage);
756 } catch (Exception e) {
757 LOG.error("Exception :", e);
758 GlobalVariables.getMessageMap().clearErrorMessages();
759 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "record.submit.fail.message");
760 }
761 if (StringUtils.isNotBlank(workInstanceOlemlForm.getSelectedItem().getPurchaseOrderLineItemIdentifier())) {
762 Map poMap = new HashMap();
763 poMap.put(OLEConstants.PURAP_DOC_IDENTIFIER, workInstanceOlemlForm.getSelectedItem().getPurchaseOrderLineItemIdentifier());
764 OlePurchaseOrderDocument olePurchaseOrderDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePurchaseOrderDocument.class, poMap);
765 if (olePurchaseOrderDocument != null) {
766 String poId = olePurchaseOrderDocument.getDocumentNumber();
767 Map<String, String> map = new HashMap<>();
768 map.put(org.kuali.ole.sys.OLEConstants.OleCopy.PO_DOC_NUM, poId);
769 KRADServiceLocator.getBusinessObjectService().deleteMatching(OLELinkPurapDonor.class, map);
770 if (workInstanceOlemlForm.getSelectedItem().getDonorInfo().size() > 0) {
771 for (DonorInfo donorInfo : workInstanceOlemlForm.getSelectedItem().getDonorInfo()) {
772 if (donorInfo.getDonorCode() != null && !donorInfo.getDonorCode().isEmpty()) {
773 map.clear();
774 map.put(OLEConstants.DONOR_CODE, donorInfo.getDonorCode());
775 OLELinkPurapDonor newOleLinkPurapDonor = new OLELinkPurapDonor();
776 List<OLEDonor> oleDonors = (List<OLEDonor>) KRADServiceLocator.getBusinessObjectService().findMatching(OLEDonor.class, map);
777 map.clear();
778 if (StringUtils.isNotBlank(workInstanceOlemlForm.getSelectedItem().getItemIdentifier())) {
779 map.put(OLEConstants.OleDeliverRequest.ITEM_UUID, workInstanceOlemlForm.getSelectedItem().getItemIdentifier());
780 }
781 map.put(org.kuali.ole.sys.OLEConstants.OleCopy.PO_DOC_NUM, poId);
782 List<OleCopy> oleCopy = (List<OleCopy>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCopy.class, map);
783 if (oleCopy != null && oleCopy.size() > 0) {
784 newOleLinkPurapDonor.setCorrectionItemId(oleCopy.get(0).getCorrectionItemId());
785 newOleLinkPurapDonor.setReqItemId(oleCopy.get(0).getReqItemId());
786 newOleLinkPurapDonor.setPoDocNum(oleCopy.get(0).getPoDocNum());
787 newOleLinkPurapDonor.setReceivingItemId(oleCopy.get(0).getReceivingItemId());
788 newOleLinkPurapDonor.setDonorId(oleDonors.get(0).getDonorId());
789 newOleLinkPurapDonor.setDonorCode(donorInfo.getDonorCode());
790 newOleLinkPurapDonor.setPoItemId(oleCopy.get(0).getPoItemId());
791 KRADServiceLocator.getBusinessObjectService().save(newOleLinkPurapDonor);
792 }
793 map.clear();
794 }
795 }
796 }
797 }
798 }
799
800 removeDocumentFromTree(editorForm);
801
802 addItemToBibTree(workInstanceOlemlForm.getBibTreeList(), itemDocument);
803 return workInstanceOlemlForm;
804 }
805
806 private void addItemDamagedHistory(Item itemData, String user) throws Exception {
807 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
808 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemData.getItemIdentifier());
809 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
810 Item oleItem = itemOlemlRecordProcessor.fromXML(item.getContent());
811 ItemDamagedRecord itemDamagedRecord = new ItemDamagedRecord();
812 List<ItemDamagedRecord> itemDamagedRecords = new ArrayList<>();
813 if(!oleItem.isItemDamagedStatus()){
814 itemDamagedRecord.setDamagedItemNote(itemData.getDamagedItemNote());
815 itemDamagedRecord.setDamagedItemDate(df.format(getDateTimeService().getCurrentDate()));
816 itemDamagedRecord.setPatronBarcode(null);
817 itemDamagedRecord.setDamagedPatronId(itemData.getCurrentBorrower());
818 itemDamagedRecord.setOperatorId(user);
819 itemDamagedRecord.setItemId(itemData.getItemIdentifier());
820 if(itemData.getItemDamagedRecords() != null && itemData.getItemDamagedRecords().size() > 0){
821 itemData.getItemDamagedRecords().add(itemDamagedRecord);
822 } else {
823 itemDamagedRecords.add(itemDamagedRecord);
824 itemData.setItemDamagedRecords(itemDamagedRecords);
825 }
826 } else {
827 Map<String,String> map = new HashMap<>();
828 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(itemData.getItemIdentifier()));
829 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord> itemDamagedRecordList = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord>) KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemDamagedRecord.class, map, "itemDamagedId", true);
830 List<ItemDamagedRecord> damagedRecordList = new ArrayList<>();
831 if(CollectionUtils.isNotEmpty(itemDamagedRecordList)){
832 for(int index=0 ; index < itemDamagedRecordList.size() ; index++){
833 ItemDamagedRecord damagedRecord = new ItemDamagedRecord();
834 if(index == itemDamagedRecordList.size()-1){
835 damagedRecord.setDamagedItemNote(itemData.getDamagedItemNote());
836 damagedRecord.setDamagedItemDate(df.format(getDateTimeService().getCurrentDate()));
837 damagedRecord.setPatronBarcode(null);
838 damagedRecord.setDamagedPatronId(itemData.getCurrentBorrower());
839 damagedRecord.setOperatorId(user);
840 damagedRecord.setItemId(itemData.getItemIdentifier());
841 } else {
842 if (itemDamagedRecordList.get(index).getDamagedItemDate() != null && !itemDamagedRecordList.get(index).getDamagedItemDate().toString().isEmpty()) {
843 SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
844 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
845 Date itemDamagedDate = null;
846 try {
847 itemDamagedDate = format2.parse(itemDamagedRecordList.get(index).getDamagedItemDate().toString());
848 } catch (ParseException e) {
849 LOG.error("format string to Date " + e);
850 }
851 damagedRecord.setDamagedItemDate(format1.format(itemDamagedDate).toString());
852 }
853 damagedRecord.setDamagedItemNote(itemDamagedRecordList.get(index).getDamagedItemNote());
854 damagedRecord.setPatronBarcode(itemDamagedRecordList.get(index).getPatronBarcode());
855 damagedRecord.setDamagedPatronId(itemDamagedRecordList.get(index).getDamagedPatronId());
856 damagedRecord.setOperatorId(itemDamagedRecordList.get(index).getOperatorId());
857 damagedRecord.setItemId(itemDamagedRecordList.get(index).getItemId());
858 }
859 damagedRecordList.add(damagedRecord);
860 }
861 itemData.setItemDamagedRecords(damagedRecordList);
862 }
863 }
864 }
865
866 private void addClaimsReturnedItemHistory(Item itemData, String user) throws Exception {
867 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
868 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemData.getItemIdentifier());
869 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
870 Item oleItem = itemOlemlRecordProcessor.fromXML(item.getContent());
871 ItemClaimsReturnedRecord itemClaimsReturnedRecord = new ItemClaimsReturnedRecord();
872 List<ItemClaimsReturnedRecord> itemClaimsReturnedRecords = new ArrayList<>();
873 if(!oleItem.isClaimsReturnedFlag()){
874 itemClaimsReturnedRecord.setClaimsReturnedNote(itemData.getClaimsReturnedNote());
875 if (itemData.getClaimsReturnedFlagCreateDate() != null && !itemData.getClaimsReturnedFlagCreateDate().isEmpty()) {
876 itemClaimsReturnedRecord.setClaimsReturnedFlagCreateDate(itemData.getClaimsReturnedFlagCreateDate());
877 }
878 else{
879 itemClaimsReturnedRecord.setClaimsReturnedFlagCreateDate(df.format(getDateTimeService().getCurrentDate()));
880 }
881 itemClaimsReturnedRecord.setClaimsReturnedOperatorId(user);
882 itemClaimsReturnedRecord.setItemId(itemData.getItemIdentifier());
883 itemClaimsReturnedRecord.setClaimsReturnedPatronBarcode(null);
884 itemClaimsReturnedRecord.setClaimsReturnedPatronId(itemData.getCurrentBorrower());
885 if(itemData.getItemClaimsReturnedRecords() != null && itemData.getItemClaimsReturnedRecords().size() > 0){
886 itemData.getItemClaimsReturnedRecords().add(itemClaimsReturnedRecord);
887 }
888 else{
889 itemClaimsReturnedRecords.add(itemClaimsReturnedRecord);
890 itemData.setItemClaimsReturnedRecords(itemClaimsReturnedRecords);
891 }
892 } else{
893 Map<String,String> map = new HashMap<>();
894 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(itemData.getItemIdentifier()));
895 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord> claimsReturnedRecordList = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord>) KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemClaimsReturnedRecord.class, map, "claimsReturnedId", true);
896 List<ItemClaimsReturnedRecord> itemClaimsReturnedRecordList = new ArrayList<>();
897 if(CollectionUtils.isNotEmpty(claimsReturnedRecordList)){
898 for(int index=0 ; index < claimsReturnedRecordList.size() ; index++){
899 ItemClaimsReturnedRecord claimsReturnedRecord = new ItemClaimsReturnedRecord();
900 if(index == claimsReturnedRecordList.size()-1){
901 if (itemData.getClaimsReturnedFlagCreateDate() != null && !itemData.getClaimsReturnedFlagCreateDate().isEmpty()) {
902 claimsReturnedRecord.setClaimsReturnedFlagCreateDate(itemData.getClaimsReturnedFlagCreateDate());
903 }
904 else{
905 claimsReturnedRecord.setClaimsReturnedFlagCreateDate(df.format(getDateTimeService().getCurrentDate()));
906 }
907 claimsReturnedRecord.setClaimsReturnedNote(itemData.getClaimsReturnedNote());
908 claimsReturnedRecord.setClaimsReturnedPatronBarcode(null);
909 claimsReturnedRecord.setClaimsReturnedPatronId(itemData.getCurrentBorrower());
910 claimsReturnedRecord.setClaimsReturnedOperatorId(user);
911 claimsReturnedRecord.setItemId(itemData.getItemIdentifier());
912 } else {
913 if (claimsReturnedRecordList.get(index).getClaimsReturnedFlagCreateDate().toString() != null) {
914 SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
915 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
916 Date claimsReturnedDate = null;
917 try {
918 claimsReturnedDate = format2.parse(claimsReturnedRecordList.get(index).getClaimsReturnedFlagCreateDate().toString());
919 } catch (ParseException e) {
920 LOG.error("format string to Date " + e);
921 }
922 claimsReturnedRecord.setClaimsReturnedFlagCreateDate(format1.format(claimsReturnedDate).toString());
923 }
924 claimsReturnedRecord.setClaimsReturnedNote(claimsReturnedRecordList.get(index).getClaimsReturnedNote());
925 claimsReturnedRecord.setClaimsReturnedPatronBarcode(claimsReturnedRecordList.get(index).getClaimsReturnedPatronBarcode());
926 claimsReturnedRecord.setClaimsReturnedPatronId(claimsReturnedRecordList.get(index).getClaimsReturnedPatronId());
927 claimsReturnedRecord.setClaimsReturnedOperatorId(claimsReturnedRecordList.get(index).getClaimsReturnedOperatorId());
928 claimsReturnedRecord.setItemId(claimsReturnedRecordList.get(index).getItemId());
929 }
930 itemClaimsReturnedRecordList.add(claimsReturnedRecord);
931 }
932 itemData.setItemClaimsReturnedRecords(itemClaimsReturnedRecordList);
933 }
934 }
935 }
936
937
938
939
940
941
942 private void addItemToBibTree(List<BibTree> bibTreeList, org.kuali.ole.docstore.common.document.Item selectedItemDocument) {
943 if (CollectionUtils.isNotEmpty(bibTreeList)) {
944 for (BibTree bibTree : bibTreeList) {
945 if (CollectionUtils.isNotEmpty(bibTree.getHoldingsTrees())) {
946 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
947 if (null != holdingsTree.getHoldings() && null != selectedItemDocument.getHolding()) {
948 String holdingsId = holdingsTree.getHoldings().getId();
949 String selectedItemHoldingsId = selectedItemDocument.getHolding().getId();
950 if (null != holdingsId && null != selectedItemHoldingsId) {
951 if (holdingsId.equals(selectedItemHoldingsId)) {
952 holdingsTree.setHoldings(selectedItemDocument.getHolding());
953 holdingsTree.getItems().add(selectedItemDocument);
954 }
955 }
956 }
957 }
958 }
959 }
960 }
961 }
962
963 @Override
964 public EditorForm createNewRecord(EditorForm editorForm, BibTree bibTree) {
965
966 if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkHoldingsViewPage")) {
967 editorForm.setNeedToCreateInstance(true);
968 }
969 editNewRecord(editorForm, bibTree);
970 return editorForm.getDocumentForm();
971 }
972
973 @Override
974 public EditorForm editNewRecord(EditorForm editorForm, BibTree bibTree) {
975 WorkInstanceOlemlForm workInstanceOlemlForm = new WorkInstanceOlemlForm();
976 if ((editorForm.getDocumentForm() instanceof WorkInstanceOlemlForm)) {
977 workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
978 workInstanceOlemlForm.setViewId(editorForm.getDocumentForm().getViewId());
979 }
980
981 workInstanceOlemlForm.setDocCategory("work");
982 workInstanceOlemlForm.setDocType("item");
983 workInstanceOlemlForm.setDocFormat("oleml");
984
985 if (bibTree != null && bibTree.getHoldingsTrees() != null) {
986 HoldingsTree holdingsTree = bibTree.getHoldingsTrees().get(0);
987 if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkHoldingsViewPage")) {
988
989 editorForm.setHeaderText("Import Bib Step-4 Item");
990
991 if (!isValidHoldingsData(workInstanceOlemlForm)) {
992 return workInstanceOlemlForm;
993 }
994 holdingsTree.getHoldings().setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
995 holdingsTree.getHoldings().setCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
996 Item item = itemOlemlRecordProcessor.fromXML(holdingsTree.getItems().get(0).getContent());
997 List<Note> notes = ensureAtleastOneNote(item.getNote());
998 item.setNote(notes);
999 workInstanceOlemlForm.setSelectedItem(item);
1000 workInstanceOlemlForm.setViewId("WorkItemViewPage");
1001
1002 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,
1003 "item.details.new.message");
1004 } else if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkItemViewPage")) {
1005 if (!isValidItemData(workInstanceOlemlForm)) {
1006 return workInstanceOlemlForm;
1007 }
1008 Item item = workInstanceOlemlForm.getSelectedItem();
1009 Map<String, String> mapObject = new HashMap<String, String>();
1010 String staffOnlyFlagForItem = String.valueOf(editorForm.isStaffOnlyFlagForItem());
1011 try {
1012 String holdingXmlContent = getInstanceEditorFormDataHandler()
1013 .buildHoldingContent(workInstanceOlemlForm.getSelectedHolding());
1014 holdingsTree.getHoldings().setContent(holdingXmlContent);
1015
1016 String itemXmlContent = getInstanceEditorFormDataHandler().buildItemContent(item, staffOnlyFlagForItem);
1017 holdingsTree.getItems().get(0).setContent(itemXmlContent);
1018
1019 } catch (Exception e) {
1020 LOG.error("Exception :", e);
1021 StringBuffer instanceEditorErrorMessage = new StringBuffer(
1022 OLEConstants.INSTANCE_EDITOR_FAILURE).append(" :: \n" + e.getMessage());
1023 workInstanceOlemlForm.setMessage(instanceEditorErrorMessage.toString());
1024 LOG.error(instanceEditorErrorMessage);
1025 }
1026 }
1027 }
1028 editorForm.setDocumentForm(workInstanceOlemlForm);
1029 return editorForm;
1030 }
1031
1032 @Override
1033 public String saveDocument(BibTree bibTree, EditorForm editorForm) {
1034 String responseFromDocstore = "success";
1035 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
1036 if (bibTree != null) {
1037 try {
1038 docstoreClient.createBibTree(bibTree);
1039 } catch (DocstoreException e) {
1040 LOG.error(e);
1041 DocstoreException docstoreException = (DocstoreException) e;
1042 if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
1043 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
1044 } else {
1045 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
1046 }
1047 } catch (Exception e) {
1048 LOG.error("Exception ", e);
1049 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,"docstore.response", e.getMessage() );
1050 }
1051 }
1052 editorForm.setDocumentForm(workInstanceOlemlForm);
1053 return responseFromDocstore;
1054 }
1055
1056
1057
1058
1059
1060
1061
1062 private InstanceEditorFormDataHandler getInstanceEditorFormDataHandler() {
1063 if (null == instanceEditorFormDataHandler) {
1064 instanceEditorFormDataHandler = new InstanceEditorFormDataHandler();
1065 }
1066 return instanceEditorFormDataHandler;
1067 }
1068
1069 private List<Note> ensureAtleastOneNote(List<Note> notes) {
1070 if (notes == null) {
1071 notes = new ArrayList<Note>();
1072 }
1073 if (notes.size() == 0) {
1074 Note note = new Note();
1075 notes.add(note);
1076 }
1077 return notes;
1078 }
1079
1080 private boolean canCreateItem(String principalId) {
1081 PermissionService service = KimApiServiceLocator.getPermissionService();
1082 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_ADD_ITEM);
1083 }
1084
1085 private boolean canEditItem(String principalId) {
1086 PermissionService service = KimApiServiceLocator.getPermissionService();
1087 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.INSTANCE_EDITOR_EDIT_ITEM);
1088 }
1089
1090 private void addItemInformation(EditorForm editorForm) {
1091
1092 }
1093
1094
1095
1096
1097
1098
1099
1100 private boolean isValidItemData(WorkInstanceOlemlForm workInstanceOlemlForm) {
1101 Item item = workInstanceOlemlForm.getSelectedItem();
1102 boolean isValidItem = true;
1103
1104 String oldItemStatus = workInstanceOlemlForm.getOldItemStatus();
1105 String itemStatus = item.getItemStatus().getCodeValue();
1106 String itemProperty = getInstanceEditorFormDataHandler()
1107 .getParameter(OLEConstants.DESC_NMSPC, OLEConstants.DESCRIBE_COMPONENT, OLEParameterConstants.ITEM_STATUS_READONLY);
1108 String[] itemArray = itemProperty.split(",");
1109
1110 if ((org.apache.commons.lang.StringUtils.isNotEmpty(itemStatus)) && (!itemStatus.equals(oldItemStatus))) {
1111 for (String status : itemArray) {
1112 if (status.equalsIgnoreCase(itemStatus)) {
1113
1114
1115 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "invalid.item.status");
1116 return false;
1117 }
1118 }
1119 }
1120 String location = "";
1121 String holdingsLocation = "";
1122 if (item.getLocation() != null) {
1123 location = item.getLocation().getLocationLevel().getName();
1124 }
1125 OleHoldings holdings = workInstanceOlemlForm.getSelectedHolding();
1126 if (holdings.getLocation() != null) {
1127 holdingsLocation = holdings.getLocation().getLocationLevel().getName();
1128 }
1129
1130
1131
1132 if ( workInstanceOlemlForm.getGlobalEditFlag().equalsIgnoreCase("false") &&
1133 (item.getItemStatus() == null || item.getItemStatus().getCodeValue() == "" ||
1134 item.getItemStatus().getCodeValue().length() < 0)) {
1135
1136 GlobalVariables.getMessageMap().putError("documentForm.selectedItem.itemStatus.codeValue", "error.item.status.required");
1137 workInstanceOlemlForm.setValidInput(false);
1138 isValidItem = false;
1139 }
1140
1141
1142 if (workInstanceOlemlForm.getGlobalEditFlag().equalsIgnoreCase("false") &&
1143 (item.getItemType() == null || item.getItemType().getCodeValue() == null || item.getItemType().getCodeValue()=="" || item.getItemType().getCodeValue().length()==0 || item.getItemType().getCodeValue().length() < 0)) {
1144
1145
1146 GlobalVariables.getMessageMap().putError("documentForm.selectedItem.itemType.codeValue", "error.item.type.required");
1147 workInstanceOlemlForm.setValidInput(false);
1148 isValidItem = false;
1149 }
1150
1151 if (holdingsLocation != null && holdingsLocation.length() != 0 && !isValidLocation(holdingsLocation)) {
1152
1153 GlobalVariables.getMessageMap().putError("documentForm.selectedHolding.location.locationLevel.name", "error.location");
1154 workInstanceOlemlForm.setValidInput(false);
1155 isValidItem = false;
1156 }
1157
1158 if (location != null && location.length() != 0 && !isValidLocation(location)) {
1159
1160
1161 GlobalVariables.getMessageMap().putError("documentForm.selectedItem.location.locationLevel.name", "error.location");
1162 workInstanceOlemlForm.setValidInput(false);
1163 isValidItem = false;
1164 }
1165
1166 boolean hasPermission = canUpdateItemStatus(GlobalVariables.getUserSession().getPrincipalId());
1167 if (hasPermission) {
1168
1169
1170
1171
1172
1173 } else {
1174
1175
1176 GlobalVariables.getMessageMap().putError("documentForm.selectedItem.itemStatus", "error.item.type.authorization");
1177 return false;
1178 }
1179 return isValidItem;
1180 }
1181
1182 private boolean isValidLocation(String location) {
1183
1184 List<String> locationList = LocationValuesBuilder.retrieveLocationDetailsForSuggest(location);
1185 if (locationList != null && locationList.size() > 0) {
1186 for (String locationValue : locationList) {
1187 if (locationValue.equalsIgnoreCase(location)) {
1188 return true;
1189 }
1190 }
1191 }
1192 return false;
1193 }
1194
1195 private boolean canUpdateItemStatus(String principalId) {
1196 LOG.debug("Inside the canUpdateItemStatus method");
1197 PermissionService service = KimApiServiceLocator.getPermissionService();
1198 return service.hasPermission(principalId, OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.CAN_UPDATE_IEM_STATUS);
1199 }
1200
1201
1202
1203
1204
1205
1206
1207 private boolean isValidHoldingsData(WorkInstanceOlemlForm workInstanceOlemlForm) {
1208 OleHoldings oleHoldings = workInstanceOlemlForm.getSelectedHolding();
1209 String location = null;
1210 if (oleHoldings != null && oleHoldings.getLocation() != null && oleHoldings.getLocation().getLocationLevel() != null) {
1211 location = oleHoldings.getLocation().getLocationLevel().getName();
1212 }
1213 if (location != null && location.length() != 0 && !isValidLocation(location)) {
1214
1215 GlobalVariables.getMessageMap().putError("documentForm.selectedHolding.location.locationLevel.name", "error.location");
1216 workInstanceOlemlForm.setValidInput(false);
1217 return false;
1218 }
1219 return true;
1220 }
1221
1222
1223 public EditorForm deleteVerify(EditorForm editorForm) {
1224
1225 String docId = editorForm.getDocId();
1226 String operation = "deleteVerify";
1227
1228
1229
1230 editorForm.setShowDeleteTree(true);
1231 editorForm.setHasLink(true);
1232
1233 List<String> uuidList = new ArrayList<>(0);
1234 uuidList.add(editorForm.getDocId());
1235 DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
1236 Node<DocumentTreeNode, String> docTree = null;
1237 try {
1238 docTree = documentSelectionTree.add(uuidList, editorForm.getDocType());
1239 } catch (SolrServerException e) {
1240 LOG.error("Exception :", e);
1241 e.printStackTrace();
1242 }
1243 editorForm.getDocTree().setRootElement(docTree);
1244 editorForm.setViewId("DeleteViewPage");
1245 return editorForm;
1246
1247 }
1248
1249
1250
1251
1252
1253
1254
1255 public EditorForm delete(EditorForm editorForm) throws Exception {
1256 return deleteFromDocStore(editorForm);
1257 }
1258
1259 @Override
1260 public EditorForm addORRemoveItemNote(EditorForm editorForm, HttpServletRequest request) {
1261 String methodName = request.getParameter("methodToCall");
1262 if (methodName.equalsIgnoreCase("addItemNote")) {
1263 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
1264 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1265 index++;
1266 List<Note> itemNote = workInstanceOlemlForm.getSelectedItem().getNote();
1267 itemNote.add(index, new Note());
1268 editorForm.setDocumentForm(workInstanceOlemlForm);
1269 } else if (methodName.equalsIgnoreCase("removeItemNote")) {
1270 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
1271 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1272 List<Note> itemNote = workInstanceOlemlForm.getSelectedItem().getNote();
1273 if (itemNote.size() > 1) {
1274 itemNote.remove(index);
1275 } else {
1276 if (itemNote.size() == 1) {
1277 itemNote.remove(index);
1278 Note note = new Note();
1279 itemNote.add(note);
1280 }
1281 }
1282 editorForm.setDocumentForm(workInstanceOlemlForm);
1283 }
1284 return editorForm;
1285 }
1286
1287 @Override
1288 public EditorForm bulkUpdate(EditorForm editorForm, List<String> ids) {
1289 WorkInstanceOlemlForm workInstanceOlemlForm = (WorkInstanceOlemlForm) editorForm.getDocumentForm();
1290 Date date = new Date();
1291 SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE+" HH:mm:ss");
1292 String dateStr = sdf.format(date);
1293 String user = GlobalVariables.getUserSession().getLoggedInUserPrincipalName();
1294 String docId = editorForm.getDocId();
1295 String instanceId = editorForm.getInstanceId();
1296 String editorMessage = "";
1297 Bib bib = null;
1298 editorForm.setHeaderText("Global Edit - Item");
1299
1300 try {
1301
1302 workInstanceOlemlForm.setGlobalEditFlag("true");
1303 if (!isValidItemData(workInstanceOlemlForm)) {
1304 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
1305 return workInstanceOlemlForm;
1306 }
1307 String staffOnlyFlagForItem = String.valueOf(editorForm.isStaffOnlyFlagForItem());
1308 Item oleItem = workInstanceOlemlForm.getSelectedItem();
1309 String itemXmlContent = getInstanceEditorFormDataHandler().buildItemContent(oleItem, staffOnlyFlagForItem);
1310 ItemOleml itemDoc = new ItemOleml();
1311 itemDoc.setCategory(DocCategory.WORK.getCode());
1312 itemDoc.setType(DocType.ITEM.getCode());
1313 itemDoc.setFormat(DocFormat.OLEML.getCode());
1314 itemDoc.setCreatedOn(dateStr);
1315 itemDoc.setCreatedBy(user);
1316 String canUpdateStaffOnlyFlag = "false";
1317 if (editorForm.getStaffOnlyFlagInGlobalEdit() != null && editorForm.getStaffOnlyFlagInGlobalEdit().equalsIgnoreCase("Y")) {
1318 canUpdateStaffOnlyFlag = "true";
1319 editorForm.setStaffOnlyFlagForItem(true);
1320 itemDoc.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
1321 }
1322 else if (editorForm.getStaffOnlyFlagInGlobalEdit() != null && editorForm.getStaffOnlyFlagInGlobalEdit().equalsIgnoreCase("N")) {
1323 canUpdateStaffOnlyFlag = "true";
1324 editorForm.setStaffOnlyFlagForItem(false);
1325 itemDoc.setStaffOnly(editorForm.isStaffOnlyFlagForHoldings());
1326 }
1327 itemDoc.setStaffOnly(editorForm.isStaffOnlyFlagForItem());
1328 itemDoc.setContent(itemXmlContent);
1329
1330
1331
1332 try {
1333 getDocstoreClientLocator().getDocstoreClient().bulkUpdateItem(itemDoc,ids,canUpdateStaffOnlyFlag);
1334 } catch (Exception e) {
1335 LOG.error("Exception :", e);
1336 DocstoreException docstoreException = (DocstoreException) e;
1337 String errorCode = docstoreException.getErrorCode();
1338 if (StringUtils.isNotEmpty(errorCode)) {
1339 Map<String, String> paramsMap = docstoreException.getErrorParams();
1340 if (paramsMap != null && paramsMap.size() > 0 && paramsMap.containsKey("barcode")) {
1341 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, errorCode, paramsMap.get("barcode"));
1342 } else {
1343 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, errorCode);
1344 }
1345 } else {
1346 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
1347 }
1348 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
1349 return workInstanceOlemlForm;
1350 }
1351 editorForm.setDocId(itemDoc.getId());
1352 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
1353 editorMessage = "item.record.load.message";
1354
1355 } catch (Exception e) {
1356 LOG.error("Exception :", e);
1357 DocstoreException docstoreException = (DocstoreException) e;
1358 if (StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
1359 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
1360 } else {
1361 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
1362 }
1363 getInstanceEditorFormDataHandler().setLocationDetails(workInstanceOlemlForm);
1364 return workInstanceOlemlForm;
1365 }
1366 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, editorMessage);
1367 return workInstanceOlemlForm;
1368 }
1369
1370 public DateTimeService getDateTimeService() {
1371 return (DateTimeService)SpringContext.getService("dateTimeService");
1372 }
1373 }