1 package org.kuali.ole.describe.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.QualifiedDublinRecordHandler;
6 import org.kuali.ole.UnQualifiedDublinRecordHandler;
7 import org.kuali.ole.describe.bo.*;
8 import org.kuali.ole.describe.form.EditorForm;
9 import org.kuali.ole.describe.form.WorkBibDublinForm;
10 import org.kuali.ole.docstore.common.document.*;
11 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
12 import org.kuali.ole.docstore.model.enums.DocFormat;
13 import org.kuali.ole.docstore.model.enums.DocType;
14 import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
15 import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
16 import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.WorkBibDublinRecord;
17 import org.kuali.ole.describe.service.DocstoreHelperService;
18 import org.kuali.ole.pojo.dublin.unqualified.UnQualifiedDublinRecord;
19 import org.kuali.ole.sys.context.SpringContext;
20 import org.kuali.rice.core.api.config.property.ConfigurationService;
21 import org.kuali.rice.krad.service.BusinessObjectService;
22 import org.kuali.rice.krad.service.KRADServiceLocator;
23 import org.kuali.rice.krad.uif.UifParameters;
24 import org.kuali.rice.krad.util.GlobalVariables;
25 import org.kuali.rice.krad.util.KRADConstants;
26 import org.kuali.rice.krad.web.form.UifFormBase;
27 import org.springframework.validation.BindingResult;
28 import org.springframework.web.bind.annotation.ModelAttribute;
29 import org.springframework.web.bind.annotation.RequestMapping;
30 import org.springframework.web.servlet.ModelAndView;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import java.text.SimpleDateFormat;
35 import java.util.*;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class WorkBibDublinEditor
52 extends AbstractEditor
53 implements DocumentEditor {
54
55
56
57
58 private static final Logger LOG = Logger.getLogger(WorkBibDublinEditor.class);
59
60 private WorkDublinEditorFormDataHandler dublinEditorFormDataHandler;
61 private DocstoreHelperService docstoreHelperService;
62
63 private static WorkBibDublinEditor workBibDublinEditor = new WorkBibDublinEditor();
64
65 public static WorkBibDublinEditor getInstance() {
66 return workBibDublinEditor;
67 }
68
69 private WorkBibDublinEditor() {
70 }
71
72
73
74
75
76
77
78 @Override
79 public EditorForm loadDocument(EditorForm editorForm) {
80 WorkBibDublinForm dublinEditorForm = new WorkBibDublinForm();
81 String docId = editorForm.getDocId();
82 String bibId = editorForm.getBibId();
83 String docFormat = editorForm.getDocFormat();
84 editorForm.setFromDublin(true);
85 List<BibTree> bibTreeList = new ArrayList();
86 BibTree bibTree = null;
87 Bib bib = null;
88
89 String directory = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(org.kuali.ole.sys.OLEConstants.EXTERNALIZABLE_HELP_URL_KEY);
90 editorForm.setExternalHelpUrl(directory+"/reference/webhelp/OLE/content/ch04s01.html#DublinEditor");
91 editorForm.setHeaderText("Dublin");
92 if (null != docId) {
93 try {
94
95 bibTree = getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(docId);
96 bibTreeList.add(bibTree);
97 bib = bibTree.getBib();
98 dublinEditorForm.setBibTreeList(bibTreeList);
99 if (docFormat.equals(DocFormat.DUBLIN_UNQUALIFIED.getCode())) {
100 UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecordHandler().fromXML(bib.getContent());
101 editorForm.setCreatedBy(bib.getStatus());
102 editorForm.setCreatedDate(bib.getCreatedOn());
103 editorForm.setUpdatedBy(bib.getUpdatedBy());
104 editorForm.setUpdatedDate(bib.getUpdatedOn());
105 editorForm.setStatusUpdatedBy(bib.getStatusUpdatedBy());
106 editorForm.setStatusUpdatedOn(bib.getStatusUpdatedOn());
107 editorForm.setStaffOnlyFlagForBib(bib.isStaffOnly());
108 editorForm.setTitle(getDublinEditorFormDataHandler().buildDublinUnqTitleField(editorForm, unQualifiedDublinRecord));
109 editorForm.setDublinFieldList(getDublinEditorFormDataHandler().buildDublinUnqEditorFields(editorForm, unQualifiedDublinRecord));
110 BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
111 Map parentCriteria = new HashMap();
112 String bibStatusName = bib.getStatus();
113 parentCriteria.put("bibliographicRecordStatusName", bibStatusName);
114 OleBibliographicRecordStatus bibliographicRecordStatus = boService
115 .findByPrimaryKey(OleBibliographicRecordStatus.class, parentCriteria);
116 editorForm.setOleBibliographicRecordStatus(bibliographicRecordStatus);
117 } else if (docFormat.equals(DocFormat.DUBLIN_CORE.getCode())) {
118 WorkBibDublinRecord workBibDublinRecord = new QualifiedDublinRecordHandler().fromXML(bib.getContent());
119 dublinEditorForm.setDublinFieldList(getDublinEditorFormDataHandler().buildDublinEditorFields(editorForm, workBibDublinRecord));
120 }
121 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.load.message");
122 } catch (Exception e) {
123 LOG.error("Error: Could not load Bib record for id" + docId + ",Cause:" + e.getMessage(), e);
124 dublinEditorForm.setMessage("Error: Could not load Bib record for id:" + docId);
125 }
126 } else {
127 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "dublin.editor.new.message");
128 }
129
130 dublinEditorForm.setViewId("WorkBibDublinEditorViewPage");
131
132 editorForm.setHasLink(false);
133 return dublinEditorForm;
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 @Override
214 public EditorForm deleteDocument(EditorForm editorForm) {
215 return new WorkBibDublinForm();
216 }
217
218 @Override
219 public EditorForm saveDocument(EditorForm editorForm) {
220 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) editorForm.getDocumentForm();
221 String bibliographicRecordStatusCode = editorForm.getOleBibliographicRecordStatus().getBibliographicRecordStatusCode();
222 boolean staffOnlyFlag = editorForm.isStaffOnlyFlagForBib();
223 String uuid = editorForm.getDocId();
224 String bibId = editorForm.getBibId();
225 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
226 ResponseDocument responseDocument = null;
227 Date date = new Date();
228 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
229 String dateStr = sdf.format(date);
230 String user = GlobalVariables.getUserSession().getLoggedInUserPrincipalName();
231 String content = "";
232 String editorStatusMessage = "";
233 BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
234 OleBibliographicRecordStatus bibliographicRecordStatus = null;
235 if (bibliographicRecordStatusCode != null) {
236 content = getDublinEditorFormDataHandler().buildDublinRecordForDocStore(editorForm, uuid);
237 Map parentCriteria = new HashMap();
238 parentCriteria.put("bibliographicRecordStatusCode", bibliographicRecordStatusCode);
239 bibliographicRecordStatus = boService.findByPrimaryKey(OleBibliographicRecordStatus.class, parentCriteria);
240 }
241 Bib bib = null;
242 try {
243 if (uuid != null && !uuid.trim().equals("")) {
244
245 if (boService != null) {
246
247 bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(bibId);
248 bib.setStaffOnly(staffOnlyFlag);
249 bib.setContent(content);
250 if (bibliographicRecordStatus != null) {
251 bib.setStatus(bibliographicRecordStatus.getBibliographicRecordStatusName());
252 } else {
253 bib.setStatus("");
254 }
255 getDocstoreClientLocator().getDocstoreClient().updateBib(bib);
256 String bibStatusName = bib.getStatus();
257 editorForm.setCreatedBy(bib.getCreatedBy());
258 editorForm.setCreatedDate(bib.getCreatedOn());
259 editorForm.setUpdatedBy(bib.getUpdatedBy());
260 editorForm.setUpdatedDate(bib.getUpdatedOn());
261 editorForm.setStatusUpdatedOn(bib.getStatusUpdatedOn());
262 editorForm.setStatusUpdatedBy(bib.getStatusUpdatedBy());
263 Map parentCriteria = new HashMap();
264 parentCriteria.put("bibliographicRecordStatusName", bibStatusName);
265 bibliographicRecordStatus = boService.findByPrimaryKey(OleBibliographicRecordStatus.class, parentCriteria);
266 if (bibliographicRecordStatus != null) {
267 editorForm.setOleBibliographicRecordStatus(bibliographicRecordStatus);
268 }
269 editorStatusMessage = "record.update.message";
270 }
271 } else {
272 BibTree bibTree = new BibTree();
273 bib = new BibDcUnqualified();
274 bib.setCategory(DocCategory.WORK.getCode());
275 bib.setType(DocType.BIB.getCode());
276 bib.setFormat(org.kuali.ole.docstore.common.document.content.enums.DocFormat.DUBLIN_UNQUALIFIED.getCode());
277 bib.setStaffOnly(staffOnlyFlag);
278 bib.setContent(content);
279 if (bibliographicRecordStatus != null) {
280 bib.setStatus(bibliographicRecordStatus.getBibliographicRecordStatusName());
281 } else {
282 bib.setStatus("");
283 }
284 bibTree.setBib(bib);
285 HoldingsTree holdingsTree = getHoldingsTree(editorForm.geteResourceId());
286 bibTree.getHoldingsTrees().add(holdingsTree);
287
288 getDocstoreClientLocator().getDocstoreClient().createBib(bib);
289 holdingsTree.getHoldings().setBib(bib);
290 getDocstoreClientLocator().getDocstoreClient().createHoldingsTree(holdingsTree);
291 editorForm.setDocId(bib.getId());
292 editorForm.setBibId(bib.getId());
293 List<BibTree> bibTreeList = new ArrayList<>();
294 bibTreeList.add(bibTree);
295 editorForm.setBibTreeList(bibTreeList);
296 editorStatusMessage = "record.create.message";
297 dublinEditorForm.setUuid("");
298
299
300 }
301 } catch (Exception e) {
302 LOG.error("Failed to save record. Cause:" + e.getMessage(), e);
303 dublinEditorForm.setDublinFieldList(Arrays.asList(new WorkDublinEditorField()));
304 dublinEditorForm.setExistingDublinFieldList(new ArrayList<WorkDublinEditorField>());
305 editorStatusMessage = "marc.editor.failure.message";
306 }
307 dublinEditorForm.setViewId("WorkBibDublinEditorViewPage");
308 dublinEditorForm = (WorkBibDublinForm) loadDocument(editorForm);
309 GlobalVariables.getMessageMap().getInfoMessages().clear();
310 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, editorStatusMessage);
311 return dublinEditorForm;
312 }
313
314
315
316
317
318
319
320
321
322
323 @RequestMapping(params = "methodToCall=addField")
324 public ModelAndView addDublinField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
325 HttpServletRequest request, HttpServletResponse response) {
326 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
327 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
328 index++;
329 List<WorkDublinEditorField> dublinEditorFieldList = dublinEditorForm.getDublinFieldList();
330 dublinEditorFieldList.add(index, new WorkDublinEditorField());
331
332 return null;
333 }
334
335
336
337
338
339
340
341
342
343
344 @RequestMapping(params = "methodToCall=removeField")
345 public ModelAndView removeDublinField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
346 HttpServletRequest request, HttpServletResponse response) {
347 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
348 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
349 String selectedCollection = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
350 List<WorkDublinEditorField> dublinEditorFieldList = dublinEditorForm.getDublinFieldList();
351 List<WorkDublinEditorField> existingEditorFieldList;
352 if (dublinEditorFieldList.size() > 1) {
353 dublinEditorFieldList.remove(index);
354 }
355 if (selectedCollection.equalsIgnoreCase("existingDublinFieldList")) {
356 existingEditorFieldList = dublinEditorForm.getExistingDublinFieldList();
357 if (existingEditorFieldList.size() > 0) {
358 existingEditorFieldList.remove(index);
359 }
360 }
361
362 return null;
363 }
364
365
366
367
368
369
370
371
372
373
374
375
376 @RequestMapping(params = "methodToCall=submit")
377 public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
378 HttpServletRequest request, HttpServletResponse response) {
379 String responseFromDocstore = null;
380 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
381 String uuid = dublinEditorForm.getUuid();
382 String content = getDublinEditorFormDataHandler().buildDublinRecordForDocStore(form, uuid);
383 try {
384 if (uuid != null && !uuid.trim().equals("")) {
385 responseFromDocstore = getDocstoreHelperService()
386 .persistToDocstoreForEditor(content, uuid, OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
387 } else {
388 responseFromDocstore = getDocstoreHelperService()
389 .persistToDocstoreForEditor(content, null, OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
390 }
391 LOG.debug("responseFromDocstore---->" + responseFromDocstore);
392 dublinEditorForm.setDublinFieldList(Arrays.asList(new WorkDublinEditorField()));
393 dublinEditorForm.setExistingDublinFieldList(new ArrayList<WorkDublinEditorField>());
394 dublinEditorForm.setUuid("");
395
396 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.save.message");
397 } catch (Exception e) {
398 LOG.error("Failed to save record:" + e.getMessage(), e);
399 dublinEditorForm.setDublinFieldList(Arrays.asList(new WorkDublinEditorField()));
400 dublinEditorForm.setExistingDublinFieldList(new ArrayList<WorkDublinEditorField>());
401
402 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.save.fail.message");
403 }
404
405 return null;
406 }
407
408
409
410
411
412
413
414
415
416
417 @RequestMapping(params = "methodToCall=loadDublinRecord")
418 public ModelAndView loadDublinRecord(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
419 HttpServletRequest request, HttpServletResponse response) {
420 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) form;
421 String uuid = dublinEditorForm.getUuid();
422 try {
423 String docStoreData = getDocstoreHelperService().getDocstoreData(uuid);
424 UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecordHandler()
425 .fromXML(docStoreData);
426 dublinEditorForm.setExistingDublinFieldList(getDublinEditorFormDataHandler()
427 .buildDublinUnqEditorFields(dublinEditorForm,
428 unQualifiedDublinRecord));
429 dublinEditorForm.setDublinFieldList(
430 new ArrayList<WorkDublinEditorField>(Arrays.asList(new WorkDublinEditorField())));
431
432 } catch (Exception e) {
433 LOG.error("Exception:" + e.getMessage(), e);
434 }
435
436 return null;
437 }
438
439
440
441
442
443
444 private WorkDublinEditorFormDataHandler getDublinEditorFormDataHandler() {
445 if (null == dublinEditorFormDataHandler) {
446 dublinEditorFormDataHandler = new WorkDublinEditorFormDataHandler();
447 }
448 return dublinEditorFormDataHandler;
449 }
450
451
452
453
454
455
456 private DocstoreHelperService getDocstoreHelperService() {
457 if (null == docstoreHelperService) {
458 return new DocstoreHelperService();
459 }
460 return docstoreHelperService;
461 }
462
463
464
465
466
467
468 public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
469 this.docstoreHelperService = docstoreHelperService;
470 }
471
472
473
474
475
476
477
478
479
480
481 protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response,
482 WorkBibDublinForm dublinEditorForm) {
483
484 return null;
485 }
486
487 @Override
488 public EditorForm addORDeleteFields(EditorForm editorForm, HttpServletRequest request) {
489 String methodName = request.getParameter("methodToCall");
490 if (methodName.equalsIgnoreCase("addField")) {
491 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) editorForm.getDocumentForm();
492 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
493 index++;
494 List<WorkDublinEditorField> dublinEditorFieldList = editorForm.getDublinFieldList();
495 dublinEditorFieldList.add(index, new WorkDublinEditorField());
496 dublinEditorForm.setDublinFieldList(dublinEditorFieldList);
497 editorForm.setDocumentForm(dublinEditorForm);
498 } else if (methodName.equalsIgnoreCase("removeField")) {
499 WorkBibDublinForm dublinEditorForm = (WorkBibDublinForm) editorForm.getDocumentForm();
500 int index = Integer.parseInt(editorForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
501 List<WorkDublinEditorField> editorControlFieldList = editorForm.getDublinFieldList();
502 if (editorControlFieldList.size() > 1) {
503 editorControlFieldList.remove(index);
504 }
505 editorForm.setDocumentForm(dublinEditorForm);
506 }
507
508 return editorForm;
509 }
510
511 @Override
512 public EditorForm deleteVerify(EditorForm editorForm) throws Exception {
513 return null;
514 }
515
516 @Override
517 public EditorForm delete(EditorForm editorForm) throws Exception {
518 WorkBibDublinForm workBibDublinForm = new WorkBibDublinForm();
519 String docId = editorForm.getDocId();
520 String operation = "delete";
521 getResponseFromDocStore(editorForm, docId, operation);
522 return workBibDublinForm;
523 }
524
525 @Override
526 public EditorForm addORRemoveExtentOfOwnership(EditorForm editorForm, HttpServletRequest request) {
527 return null;
528 }
529
530 @Override
531 public EditorForm addORRemoveAccessInformationAndHoldingsNotes(EditorForm editorForm, HttpServletRequest request) {
532 return null;
533 }
534
535 @Override
536 public EditorForm addORRemoveItemNote(EditorForm editorForm, HttpServletRequest request) {
537 return null;
538 }
539
540 @Override
541 public EditorForm showBibs(EditorForm editorForm) {
542 return null;
543 }
544
545 public EditorForm copy(EditorForm editorForm) {
546 return null;
547 }
548
549 }