1 package org.kuali.ole.describe.controller;
2
3 import org.apache.log4j.Logger;
4 import org.apache.solr.client.solrj.SolrServerException;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.OleEditorResponseHandler;
7 import org.kuali.ole.describe.bo.OleWorkBibDocument;
8 import org.kuali.ole.describe.bo.OleWorkEHoldingsDocument;
9 import org.kuali.ole.describe.bo.OleWorkHoldingsDocument;
10 import org.kuali.ole.describe.form.WorkbenchForm;
11 import org.kuali.ole.describe.service.DiscoveryHelperService;
12 import org.kuali.ole.describe.service.DocstoreHelperService;
13 import org.kuali.ole.docstore.discovery.model.SearchCondition;
14 import org.kuali.ole.docstore.discovery.model.SearchParams;
15 import org.kuali.ole.docstore.discovery.service.QueryService;
16 import org.kuali.ole.docstore.discovery.service.QueryServiceImpl;
17 import org.kuali.ole.docstore.model.bo.*;
18 import org.kuali.ole.docstore.model.enums.DocCategory;
19 import org.kuali.ole.docstore.model.enums.DocFormat;
20 import org.kuali.ole.docstore.model.enums.DocType;
21 import org.kuali.ole.docstore.model.xmlpojo.ingest.Content;
22 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
23 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
24 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
25 import org.kuali.ole.docstore.model.xmlpojo.work.einstance.oleml.EHoldings;
26 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
27 import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
28 import org.kuali.ole.docstore.model.xstream.work.oleml.WorkEHoldingOlemlRecordProcessor;
29 import org.kuali.ole.pojo.OleBibRecord;
30 import org.kuali.ole.pojo.OleEditorResponse;
31 import org.kuali.ole.select.businessobject.OleCopy;
32 import org.kuali.ole.select.document.OLEEResourceRecordDocument;
33 import org.kuali.ole.select.service.impl.OleExposedWebServiceImpl;
34 import org.kuali.ole.service.OLEEResourceSearchService;
35 import org.kuali.ole.sys.context.SpringContext;
36 import org.kuali.rice.core.api.config.property.ConfigContext;
37 import org.kuali.rice.core.api.exception.RiceRuntimeException;
38 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
39 import org.kuali.rice.kim.api.identity.Person;
40 import org.kuali.rice.kim.api.identity.PersonService;
41 import org.kuali.rice.kim.api.permission.PermissionService;
42 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
43 import org.kuali.rice.krad.service.BusinessObjectService;
44 import org.kuali.rice.krad.service.DocumentService;
45 import org.kuali.rice.krad.service.KRADServiceLocator;
46 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
47 import org.kuali.rice.krad.uif.UifParameters;
48 import org.kuali.rice.krad.util.GlobalVariables;
49 import org.kuali.rice.krad.util.KRADConstants;
50 import org.kuali.rice.krad.web.controller.UifControllerBase;
51 import org.kuali.rice.krad.web.form.UifFormBase;
52 import org.springframework.stereotype.Controller;
53 import org.springframework.validation.BindingResult;
54 import org.springframework.web.bind.annotation.ModelAttribute;
55 import org.springframework.web.bind.annotation.RequestMapping;
56 import org.springframework.web.servlet.ModelAndView;
57
58 import javax.servlet.ServletException;
59 import javax.servlet.http.HttpServletRequest;
60 import javax.servlet.http.HttpServletResponse;
61 import java.io.IOException;
62 import java.io.InputStream;
63 import java.util.*;
64
65
66
67
68
69
70
71
72
73
74
75 @Controller
76 @RequestMapping(value = "/describeworkbenchcontroller")
77 public class WorkbenchController extends UifControllerBase {
78
79 private static final Logger LOG = Logger.getLogger(WorkbenchController.class);
80 private OLEEResourceSearchService oleEResourceSearchService;
81 private DocumentService documentService;
82 private int totalRecCount;
83 private int start;
84 private int pageSize;
85
86 public int getTotalRecCount() {
87 return totalRecCount;
88 }
89
90 public void setTotalRecCount(int totalRecCount) {
91 this.totalRecCount = totalRecCount;
92 }
93
94 public int getStart() {
95 return start;
96 }
97
98 public void setStart(int start) {
99 this.start = start;
100 }
101
102 public int getPageSize() {
103 return pageSize;
104 }
105
106 public void setPageSize(int pageSize) {
107 this.pageSize = pageSize;
108 }
109
110 public boolean getWorkbenchPreviousFlag() {
111 if (this.start == 0)
112 return false;
113 return true;
114 }
115
116 public boolean getWorkbenchNextFlag() {
117 if (this.start + this.pageSize < this.totalRecCount)
118 return true;
119 return false;
120 }
121
122 public String getWorkbenchPageShowEntries() {
123 return "Showing " + ((this.start == 0) ? 1 : this.start + 1) + " to "
124 + (((this.start + this.pageSize) > this.totalRecCount) ? this.totalRecCount : (this.start + this.pageSize))
125 + " of " + this.totalRecCount + " entries";
126 }
127
128 public OLEEResourceSearchService getOleEResourceSearchService() {
129 if (oleEResourceSearchService == null) {
130 oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
131 }
132 return oleEResourceSearchService;
133 }
134
135 public DocumentService getDocumentService() {
136 if (this.documentService == null) {
137 this.documentService = KRADServiceLocatorWeb.getDocumentService();
138 }
139 return this.documentService;
140 }
141
142 public void setDocumentService(DocumentService documentService) {
143 this.documentService = documentService;
144 }
145
146 boolean hasSearchPermission = false;
147 private String eResourceId;
148 private String tokenId;
149
150 @Override
151 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
152 return new WorkbenchForm();
153 }
154
155
156
157
158
159
160
161
162
163
164 @Override
165 @RequestMapping(params = "methodToCall=start")
166 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
167 HttpServletRequest request, HttpServletResponse response) {
168 LOG.debug("Inside the workbenchForm start method");
169 WorkbenchForm workbenchForm = (WorkbenchForm) form;
170 workbenchForm.setWorkBibDocumentList(null);
171 workbenchForm.setWorkHoldingsDocumentList(null);
172 workbenchForm.setWorkItemDocumentList(null);
173 workbenchForm.setWorkEHoldingsDocumentList(null);
174 workbenchForm.setShowRequestXML(false);
175 if(request.getParameter(OLEConstants.E_RESOURCE_ID) != null) {
176 eResourceId = request.getParameter(OLEConstants.E_RESOURCE_ID);
177 }
178 if(request.getParameter(OLEConstants.TOKEN_ID) != null) {
179 tokenId = request.getParameter(OLEConstants.TOKEN_ID);
180 }
181 if (workbenchForm.getSearchParams().getDocType() == null) {
182 workbenchForm.getSearchParams().setDocType(DocType.BIB.getDescription());
183 }
184 String eInstance = request.getParameter(OLEConstants.E_INSTANCE);
185 if (eInstance != null && eInstance.equalsIgnoreCase(OLEConstants.LINK_EXISTING_INSTANCE)) {
186
187 workbenchForm.setLinkExistingInstance(eInstance);
188 }
189 String docType = workbenchForm.getSearchParams().getDocType();
190 boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
191 if (!hasSearchPermission && docType.equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
192 boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
193
194 if (!hasLinkPermission) {
195 workbenchForm.setMessage("<font size='4' color='red'>" + OLEConstants.SEARCH_AUTHORIZATION_ERROR + "</font>");
196 return super.navigate(workbenchForm, result, request, response);
197 }
198
199
200
201
202
203
204 } else if (!hasSearchPermission) {
205 workbenchForm.setMessage("<font size='4' color='red'>" + OLEConstants.SEARCH_AUTHORIZATION_ERROR + "</font>");
206 return super.navigate(workbenchForm, result, request, response);
207 }
208 workbenchForm.setWorkBibDocumentList(null);
209 workbenchForm.setWorkHoldingsDocumentList(null);
210 workbenchForm.setWorkItemDocumentList(null);
211 workbenchForm.setWorkEHoldingsDocumentList(null);
212 workbenchForm.setShowRequestXML(false);
213 workbenchForm.setMessage(null);
214 GlobalVariables.getMessageMap().clearErrorMessages();
215 return super.navigate(workbenchForm, result, request, response);
216 }
217
218
219
220
221
222
223
224
225
226
227 protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, WorkbenchForm workbenchForm) {
228 return super.navigate(workbenchForm, result, request, response);
229 }
230
231
232
233
234
235
236
237
238
239
240
241 private boolean canSearch(String principalId) {
242 PermissionService service = KimApiServiceLocator.getPermissionService();
243 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.DESC_WORKBENCH_SEARCH);
244 }
245
246 private boolean canLinkBibForRequisition(String principalId) {
247 PermissionService service = KimApiServiceLocator.getPermissionService();
248 return service.hasPermission(principalId, OLEConstants.SELECT_NMSPC, OLEConstants.LINK_EXISTING_BIB);
249 }
250
251
252
253
254
255
256
257
258 @RequestMapping(params = "methodToCall=search")
259 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
260 HttpServletRequest request, HttpServletResponse response) throws Exception {
261 LOG.info("Inside Search Method");
262 WorkbenchForm workbenchForm = (WorkbenchForm) form;
263 workbenchForm.setMessage(null);
264 String docType = workbenchForm.getSearchParams().getDocType();
265 boolean hasSearchPermission = canSearch(GlobalVariables.getUserSession().getPrincipalId());
266 if (!hasSearchPermission && docType.equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
267 boolean hasLinkPermission = canLinkBibForRequisition(GlobalVariables.getUserSession().getPrincipalId());
268
269 if (!hasLinkPermission) {
270 workbenchForm.setMessage("<font size='4' color='red'>" + OLEConstants.SEARCH_AUTHORIZATION_ERROR + "</font>");
271 return super.navigate(workbenchForm, result, request, response);
272 }
273
274
275
276
277
278
279 } else if (!hasSearchPermission) {
280 workbenchForm.setMessage("<font size='4' color='red'>" + OLEConstants.SEARCH_AUTHORIZATION_ERROR + "</font>");
281 return super.navigate(workbenchForm, result, request, response);
282 }
283 workbenchForm.setShowRequestXML(false);
284 try {
285 QueryService queryService = QueryServiceImpl.getInstance();
286 SearchParams searchParams = workbenchForm.getSearchParams();
287 searchParams.setRows(workbenchForm.getPageSize());
288 searchParams.setStart(workbenchForm.getStart());
289 if (workbenchForm.getSearchParams().getDocType().equalsIgnoreCase(DocType.BIB.getDescription())) {
290 workbenchForm.getSearchParams().setDocCategory(DocCategory.WORK.getCode());
291 workbenchForm.getSearchParams().setDocFormat("ALL");
292 workbenchForm.setShowExport(true);
293 workbenchForm.setLinkToERSFlag(true);
294 List<OleWorkBibDocument> oleWorkBibDocumentList = new ArrayList<OleWorkBibDocument>();
295 List<WorkBibDocument> workBibDocumentList = queryService.getBibDocuments(searchParams);
296 if (workBibDocumentList.isEmpty()) {
297 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
298 workbenchForm.setWorkBibDocumentList(null);
299 workbenchForm.setWorkHoldingsDocumentList(null);
300 workbenchForm.setWorkItemDocumentList(null);
301 workbenchForm.setWorkEHoldingsDocumentList(null);
302 return super.navigate(workbenchForm, result, request, response);
303 }
304 for (WorkBibDocument workBibDocument : workBibDocumentList) {
305 OleWorkBibDocument oleWorkBibDocument = new OleWorkBibDocument();
306 oleWorkBibDocument.setDocFormat(workBibDocument.getDocFormat());
307 oleWorkBibDocument.setId(workBibDocument.getId());
308 oleWorkBibDocument.setTitle(workBibDocument.getTitle());
309 oleWorkBibDocument.setLocalIds(workBibDocument.getLocalIds());
310 oleWorkBibDocument.setAuthor(workBibDocument.getAuthor());
311 oleWorkBibDocument.setStaffOnlyFlag(workBibDocument.getStaffOnlyFlag());
312 oleWorkBibDocument.setPublicationDate(workBibDocument.getPublicationDate());
313 if (eResourceId != null) {
314 oleWorkBibDocument.setOleERSIdentifier(eResourceId);
315 }
316 if (tokenId != null) {
317 oleWorkBibDocument.setTokenId(tokenId);
318 }
319 oleWorkBibDocumentList.add(oleWorkBibDocument);
320 }
321 workbenchForm.setWorkBibDocumentList(oleWorkBibDocumentList);
322 workbenchForm.setWorkHoldingsDocumentList(null);
323 workbenchForm.setWorkItemDocumentList(null);
324 workbenchForm.setWorkEHoldingsDocumentList(null);
325 setPageNextPreviousAndEntriesInfo(workbenchForm);
326 request.getSession().setAttribute("oleWorkBibDocumentList", oleWorkBibDocumentList);
327
328 }
329 if (workbenchForm.getSearchParams().getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode())) {
330 workbenchForm.getSearchParams().setDocCategory(DocCategory.WORK.getCode());
331 workbenchForm.getSearchParams().setDocFormat(DocFormat.OLEML.getCode());
332 workbenchForm.setShowExport(true);
333 List<OleWorkHoldingsDocument> oleWorkHoldingsDocuments = new ArrayList<>();
334 List<WorkHoldingsDocument> workHoldingsDocuments = queryService.getHoldingDocuments(searchParams);
335 if (workHoldingsDocuments.isEmpty()) {
336 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
337 workbenchForm.setWorkBibDocumentList(null);
338 workbenchForm.setWorkHoldingsDocumentList(null);
339 workbenchForm.setWorkItemDocumentList(null);
340 workbenchForm.setWorkEHoldingsDocumentList(null);
341 return super.navigate(workbenchForm, result, request, response);
342 }
343 for (WorkHoldingsDocument workHoldingsDocument : workHoldingsDocuments) {
344 OleWorkHoldingsDocument oleWorkHoldingsDocument = new OleWorkHoldingsDocument();
345 oleWorkHoldingsDocument.setBibTitle(workHoldingsDocument.getBibTitle());
346 oleWorkHoldingsDocument.setBibIdentifier(workHoldingsDocument.getBibIdentifier());
347 oleWorkHoldingsDocument.setBibUUIDList(workHoldingsDocument.getBibUUIDList());
348 oleWorkHoldingsDocument.setCallNumber(workHoldingsDocument.getCallNumber());
349 oleWorkHoldingsDocument.setCallNumberPrefix(workHoldingsDocument.getCallNumberPrefix());
350 oleWorkHoldingsDocument.setCallNumberType(workHoldingsDocument.getCallNumberType());
351 oleWorkHoldingsDocument.setCopyNumber(workHoldingsDocument.getCopyNumber());
352 oleWorkHoldingsDocument.setHoldingsIdentifier(workHoldingsDocument.getHoldingsIdentifier());
353 oleWorkHoldingsDocument.setStaffOnlyFlag(workHoldingsDocument.getStaffOnlyFlag());
354 oleWorkHoldingsDocument.setLinkedBibCount(workHoldingsDocument.getLinkedBibCount());
355 oleWorkHoldingsDocument.setLocalId(workHoldingsDocument.getLocalId());
356 oleWorkHoldingsDocument.setLocationName(workHoldingsDocument.getLocationName());
357 oleWorkHoldingsDocument.setInstanceIdentifier(workHoldingsDocument.getInstanceIdentifier());
358 oleWorkHoldingsDocuments.add(oleWorkHoldingsDocument);
359 }
360 workbenchForm.setWorkHoldingsDocumentList(oleWorkHoldingsDocuments);
361 workbenchForm.setWorkBibDocumentList(null);
362 workbenchForm.setWorkItemDocumentList(null);
363 workbenchForm.setWorkEHoldingsDocumentList(null);
364 setPageNextPreviousAndEntriesInfo(workbenchForm);
365 }
366 if (workbenchForm.getSearchParams().getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
367 workbenchForm.getSearchParams().setDocCategory(DocCategory.WORK.getCode());
368 workbenchForm.getSearchParams().setDocFormat(DocFormat.OLEML.getCode());
369 List<WorkItemDocument> workItemDocuments = queryService.getItemDocuments(searchParams);
370 if (workItemDocuments.isEmpty()) {
371 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
372 workbenchForm.setWorkBibDocumentList(null);
373 workbenchForm.setWorkHoldingsDocumentList(null);
374 workbenchForm.setWorkItemDocumentList(null);
375 workbenchForm.setWorkEHoldingsDocumentList(null);
376 return super.navigate(workbenchForm, result, request, response);
377 }
378 workbenchForm.setWorkItemDocumentList(workItemDocuments);
379 workbenchForm.setWorkBibDocumentList(null);
380 workbenchForm.setWorkHoldingsDocumentList(null);
381 workbenchForm.setWorkEHoldingsDocumentList(null);
382 setPageNextPreviousAndEntriesInfo(workbenchForm);
383 }
384 if (workbenchForm.getSearchParams().getDocType().equalsIgnoreCase(DocType.EHOLDINGS.getCode())) {
385 workbenchForm.getSearchParams().setDocCategory(DocCategory.WORK.getCode());
386 workbenchForm.getSearchParams().setDocFormat(DocFormat.OLEML.getCode());
387 workbenchForm.setShowExport(true);
388 List<WorkEHoldingsDocument> workEHoldingsDocuments = queryService.getEHoldingsDocuments(searchParams);
389 if (workEHoldingsDocuments.isEmpty()) {
390 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.DESCRIBE_SEARCH_MESSAGE);
391 workbenchForm.setWorkBibDocumentList(null);
392 workbenchForm.setWorkHoldingsDocumentList(null);
393 workbenchForm.setWorkItemDocumentList(null);
394 workbenchForm.setWorkEHoldingsDocumentList(null);
395 return super.navigate(workbenchForm, result, request, response);
396 }
397 List<OleWorkEHoldingsDocument> oleWorkEHoldingsDocuments = new ArrayList<>();
398 for (WorkEHoldingsDocument workEHoldingsDocument : workEHoldingsDocuments) {
399 OleWorkEHoldingsDocument oleWorkEHoldingsDocument = new OleWorkEHoldingsDocument();
400 oleWorkEHoldingsDocument.setAccessStatus(workEHoldingsDocument.getAccessStatus());
401 oleWorkEHoldingsDocument.setBibIdentifier(workEHoldingsDocument.getBibIdentifier());
402 oleWorkEHoldingsDocument.setHoldingsIdentifier(workEHoldingsDocument.getHoldingsIdentifier());
403 oleWorkEHoldingsDocument.setImprint(workEHoldingsDocument.getImprint());
404 oleWorkEHoldingsDocument.setInstanceIdentifier(workEHoldingsDocument.getInstanceIdentifier());
405 oleWorkEHoldingsDocument.setLocalId(workEHoldingsDocument.getLocalId());
406 oleWorkEHoldingsDocument.setPlatForm(workEHoldingsDocument.getPlatForm());
407 oleWorkEHoldingsDocument.setStatisticalCode(workEHoldingsDocument.getStatisticalCode());
408 oleWorkEHoldingsDocument.setDocType(workEHoldingsDocument.getDocType());
409 oleWorkEHoldingsDocument.setId(workEHoldingsDocument.getId());
410 oleWorkEHoldingsDocument.setDocCategory(workEHoldingsDocument.getDocCategory());
411 oleWorkEHoldingsDocuments.add(oleWorkEHoldingsDocument);
412 }
413
414
415 workbenchForm.setWorkEHoldingsDocumentList(oleWorkEHoldingsDocuments);
416 workbenchForm.setWorkBibDocumentList(null);
417 workbenchForm.setWorkHoldingsDocumentList(null);
418 workbenchForm.setWorkItemDocumentList(null);
419 setPageNextPreviousAndEntriesInfo(workbenchForm);
420
421 }
422
423 } catch (Exception e) {
424
425 LOG.error("Workbenchcontroller Search Exception:" + e);
426 }
427
428 return navigate(workbenchForm, result, request, response);
429 }
430
431
432
433
434
435
436 public void setPageNextPreviousAndEntriesInfo(WorkbenchForm workbenchForm) {
437 this.totalRecCount = workbenchForm.getSearchParams().getTotalRecCount();
438 this.start = workbenchForm.getSearchParams().getStart();
439 this.pageSize = workbenchForm.getSearchParams().getRows();
440 workbenchForm.setPreviousFlag(getWorkbenchPreviousFlag());
441 workbenchForm.setNextFlag(getWorkbenchNextFlag());
442 workbenchForm.setPageShowEntries(getWorkbenchPageShowEntries());
443 }
444
445
446
447
448
449
450
451
452
453 @RequestMapping(params = "methodToCall=nextSearch")
454 public ModelAndView nextSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
455 HttpServletRequest request, HttpServletResponse response) throws Exception {
456
457 LOG.debug("Inside the nextSearch method");
458 WorkbenchForm workbenchForm = (WorkbenchForm) form;
459 SearchParams searchParams = workbenchForm.getSearchParams();
460 QueryService queryService = QueryServiceImpl.getInstance();
461 this.start = Math.max(0, this.start + this.pageSize);
462 searchParams.setStart(this.start);
463 if (searchParams.getDocType().equalsIgnoreCase("item")) {
464 List<WorkItemDocument> workItemDocuments = queryService.getDocuments(searchParams);
465 workbenchForm.setWorkItemDocumentList(workItemDocuments);
466 setPageNextPreviousAndEntriesInfo(workbenchForm);
467 return navigate(workbenchForm, result, request, response);
468 } else if (searchParams.getDocType().equalsIgnoreCase("holdings")) {
469 List<OleWorkHoldingsDocument> oleWorkHoldingsDocuments = queryService.getDocuments(searchParams);
470 workbenchForm.setWorkHoldingsDocumentList(oleWorkHoldingsDocuments);
471 setPageNextPreviousAndEntriesInfo(workbenchForm);
472 return navigate(workbenchForm, result, request, response);
473 } else if (searchParams.getDocType().equalsIgnoreCase("bibliographic")) {
474 List<WorkBibDocument> workBibDocuments = queryService.getDocuments(searchParams);
475 List<OleWorkBibDocument> oleWorkBibDocuments = new ArrayList<>();
476 for (WorkBibDocument workBibDocument : workBibDocuments) {
477 OleWorkBibDocument oleWorkBibDocument = new OleWorkBibDocument();
478 oleWorkBibDocument.setDocFormat(workBibDocument.getDocFormat());
479 oleWorkBibDocument.setId(workBibDocument.getId());
480 oleWorkBibDocument.setTitle(workBibDocument.getTitle());
481 oleWorkBibDocument.setLocalIds(workBibDocument.getLocalIds());
482 oleWorkBibDocument.setAuthor(workBibDocument.getAuthor());
483 oleWorkBibDocument.setStaffOnlyFlag(workBibDocument.getStaffOnlyFlag());
484 oleWorkBibDocument.setPublicationDate(workBibDocument.getPublicationDate());
485 if (eResourceId != null) {
486 oleWorkBibDocument.setOleERSIdentifier(eResourceId);
487 }
488 if (tokenId != null) {
489 oleWorkBibDocument.setTokenId(tokenId);
490 }
491 oleWorkBibDocuments.add(oleWorkBibDocument);
492 }
493 workbenchForm.setWorkBibDocumentList(oleWorkBibDocuments);
494 setPageNextPreviousAndEntriesInfo(workbenchForm);
495 return navigate(workbenchForm, result, request, response);
496 } else if (searchParams.getDocType().equalsIgnoreCase("eholdings")) {
497 List<OleWorkEHoldingsDocument> oleWorkEHoldingsDocuments = queryService.getDocuments(searchParams);
498 workbenchForm.setWorkEHoldingsDocumentList(oleWorkEHoldingsDocuments);
499 setPageNextPreviousAndEntriesInfo(workbenchForm);
500 return navigate(workbenchForm, result, request, response);
501 }
502 return navigate(workbenchForm, result, request, response);
503 }
504
505
506
507
508
509
510
511
512
513 @RequestMapping(params = "methodToCall=previousSearch")
514 public ModelAndView previousSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
515 HttpServletRequest request, HttpServletResponse response) throws Exception {
516
517 LOG.debug("Inside the previousSearch method");
518 WorkbenchForm workbenchForm = (WorkbenchForm) form;
519 SearchParams searchParams = workbenchForm.getSearchParams();
520 QueryService queryService = QueryServiceImpl.getInstance();
521 this.start = Math.max(0, this.start - this.pageSize);
522 searchParams.setStart((this.start == 0) ? 0 : this.start);
523 if (searchParams.getDocType().equalsIgnoreCase("item")) {
524 List<WorkItemDocument> workItemDocuments = queryService.getDocuments(searchParams);
525 workbenchForm.setWorkItemDocumentList(workItemDocuments);
526 setPageNextPreviousAndEntriesInfo(workbenchForm);
527 return navigate(workbenchForm, result, request, response);
528 } else if (searchParams.getDocType().equalsIgnoreCase("holdings")) {
529 List<OleWorkHoldingsDocument> oleWorkHoldingsDocuments = queryService.getDocuments(searchParams);
530 workbenchForm.setWorkHoldingsDocumentList(oleWorkHoldingsDocuments);
531 setPageNextPreviousAndEntriesInfo(workbenchForm);
532 return navigate(workbenchForm, result, request, response);
533 } else if (searchParams.getDocType().equalsIgnoreCase("bibliographic")) {
534 List<WorkBibDocument> workBibDocuments = queryService.getDocuments(searchParams);
535 List<OleWorkBibDocument> oleWorkBibDocuments = new ArrayList<>();
536 for (WorkBibDocument workBibDocument : workBibDocuments) {
537 OleWorkBibDocument oleWorkBibDocument = new OleWorkBibDocument();
538 oleWorkBibDocument.setDocFormat(workBibDocument.getDocFormat());
539 oleWorkBibDocument.setId(workBibDocument.getId());
540 oleWorkBibDocument.setTitle(workBibDocument.getTitle());
541 oleWorkBibDocument.setLocalIds(workBibDocument.getLocalIds());
542 oleWorkBibDocument.setAuthor(workBibDocument.getAuthor());
543 oleWorkBibDocument.setStaffOnlyFlag(workBibDocument.getStaffOnlyFlag());
544 oleWorkBibDocument.setPublicationDate(workBibDocument.getPublicationDate());
545 if (eResourceId != null) {
546 oleWorkBibDocument.setOleERSIdentifier(eResourceId);
547 }
548 if (tokenId != null) {
549 oleWorkBibDocument.setTokenId(tokenId);
550 }
551 oleWorkBibDocuments.add(oleWorkBibDocument);
552 }
553 workbenchForm.setWorkBibDocumentList(oleWorkBibDocuments);
554 setPageNextPreviousAndEntriesInfo(workbenchForm);
555 return navigate(workbenchForm, result, request, response);
556 } else if (searchParams.getDocType().equalsIgnoreCase("eholdings")) {
557 List<OleWorkEHoldingsDocument> oleWorkEHoldingsDocuments = queryService.getDocuments(searchParams);
558 workbenchForm.setWorkEHoldingsDocumentList(oleWorkEHoldingsDocuments);
559 setPageNextPreviousAndEntriesInfo(workbenchForm);
560 return navigate(workbenchForm, result, request, response);
561 }
562
563 return navigate(workbenchForm, result, request, response);
564
565 }
566
567
568
569
570
571
572
573
574 @RequestMapping(params = "methodToCall=clearSearch")
575 public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
576 HttpServletRequest request, HttpServletResponse response) {
577 LOG.info("Inside clearSearch Method");
578 WorkbenchForm workbenchForm = (WorkbenchForm) form;
579 workbenchForm.setSearchParams(new SearchParams());
580 List<SearchCondition> searchConditions = workbenchForm.getSearchParams().getSearchFieldsList();
581 searchConditions.add(new SearchCondition());
582 searchConditions.add(new SearchCondition());
583 workbenchForm.getSearchParams().setDocType("bibliographic");
584 workbenchForm.setWorkBibDocumentList(null);
585 workbenchForm.setWorkHoldingsDocumentList(null);
586 workbenchForm.setWorkItemDocumentList(null);
587 workbenchForm.setWorkEHoldingsDocumentList(null);
588 workbenchForm.setMessage(null);
589 return getUIFModelAndView(workbenchForm);
590
591 }
592
593 @RequestMapping(params = "methodToCall=select")
594 public ModelAndView select(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
595 HttpServletRequest request, HttpServletResponse response) {
596 WorkbenchForm workbenchForm = (WorkbenchForm) form;
597 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
598 String selectedRecord = workbenchForm.getWorkBibDocumentList().get(index).getId();
599 LOG.info("selectedRecord--->" + selectedRecord);
600 return super.navigate(workbenchForm, result, request, response);
601 }
602
603 @RequestMapping(params = "methodToCall=selectRecords")
604 public ModelAndView selectRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
605 HttpServletRequest request, HttpServletResponse response) {
606 WorkbenchForm workbenchForm = (WorkbenchForm) form;
607 List<String> selectedRecordIds = new ArrayList<String>();
608 List<OleWorkBibDocument> oleWorkBibDocuments = workbenchForm.getWorkBibDocumentList();
609 for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocuments) {
610 if (oleWorkBibDocument.isSelect()) {
611 selectedRecordIds.add(oleWorkBibDocument.getId());
612 }
613 }
614 LOG.info("selectedRecords--->" + selectedRecordIds);
615 return getUIFModelAndView(workbenchForm);
616 }
617
618
619
620
621
622
623
624
625
626
627
628
629
630 @RequestMapping(params = "methodToCall=export")
631 public ModelAndView export(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
632 HttpServletRequest request, HttpServletResponse response) throws SolrServerException, IOException, ServletException {
633 WorkbenchForm workbenchForm = (WorkbenchForm) form;
634 boolean hasPermission = canExportToRequestXml(GlobalVariables.getUserSession().getPrincipalId());
635 if (!hasPermission) {
636 workbenchForm.setMessage("<font size='4' color='red'>" + OLEConstants.SEARCH_AUTHORIZATION_ERROR + "</font>");
637 return navigate(workbenchForm, result, request, response);
638 }
639 workbenchForm.setShowRequestXML(true);
640 QueryService queryService = QueryServiceImpl.getInstance();
641 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
642 Request docStoreRequest = new Request();
643 docStoreRequest.setOperation(Request.Operation.ingest.toString());
644 docStoreRequest.setUser("ole-khuntley");
645 List<String> selectedRecordIds = new ArrayList<String>();
646 List<OleWorkBibDocument> oleWorkBibDocuments = workbenchForm.getWorkBibDocumentList();
647 for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocuments) {
648 if (oleWorkBibDocument.isSelect()) {
649 selectedRecordIds.add(oleWorkBibDocument.getId());
650 }
651 }
652 LOG.info("selectedRecords--->" + selectedRecordIds);
653 List<RequestDocument> requestDocumentList = new ArrayList<RequestDocument>();
654 for (String selectedRecordId : selectedRecordIds) {
655 RequestDocument requestDocument = new RequestDocument();
656 requestDocument.setUuid(selectedRecordId);
657 requestDocument.setId(selectedRecordId);
658 requestDocumentList.add(requestDocument);
659 }
660 List<RequestDocument> checkOutReqDocs = new ArrayList<RequestDocument>();
661 for (int i = 0; i < requestDocumentList.size(); i++) {
662 String id = requestDocumentList.get(i).getId();
663 RequestDocument requestDocument = new RequestDocument();
664 requestDocument.setCategory(DocCategory.WORK.getCode());
665 requestDocument.setType(DocType.BIB.getDescription());
666 requestDocument.setFormat(DocFormat.MARC.getCode());
667 requestDocument.setId(requestDocumentList.get(i).getId());
668 List<String> instanceIdList = new ArrayList<String>();
669 instanceIdList = queryService.queryForInstances(id);
670 LOG.debug("instance id list-->" + instanceIdList);
671 List<RequestDocument> linkedRequestDocumentList = new ArrayList<RequestDocument>();
672 for (String instanceId : instanceIdList) {
673 RequestDocument linkedReqDocument = new RequestDocument();
674 linkedReqDocument.setId(instanceId);
675 linkedReqDocument.setCategory(DocCategory.WORK.getCode());
676 linkedReqDocument.setType(DocType.INSTANCE.getCode());
677 linkedReqDocument.setFormat(DocFormat.OLEML.getCode());
678 String instanceResponse = docstoreHelperService.getContentFromDocStore(instanceId);
679 Content content = new Content();
680 if (instanceResponse.contains("Failure")) {
681 instanceResponse = new String();
682 content.setContent(instanceResponse);
683 } else {
684 Response response1 = new ResponseHandler().toObject(instanceResponse);
685
686 content.setContent(response1.getDocuments().get(0).getContent().getContent());
687 }
688 linkedReqDocument.setContent(content);
689 linkedRequestDocumentList.add(linkedReqDocument);
690 }
691 requestDocument.setLinkedRequestDocuments(linkedRequestDocumentList);
692 String bibContent = docstoreHelperService.getContentFromDocStore(requestDocumentList.get(i).getId());
693 Response bibResponse = new ResponseHandler().toObject(bibContent);
694
695 Content content = new Content();
696 if (bibResponse.getStatus().contains("Failure")) {
697 bibContent = new String();
698 content.setContent(bibContent);
699 } else {
700 content.setContent(bibResponse.getDocuments().get(0).getContent().getContent());
701 }
702
703 requestDocument.setContent(content);
704 requestDocument.setAdditionalAttributes(bibResponse.getDocuments().get(0).getAdditionalAttributes());
705 checkOutReqDocs.add(requestDocument);
706 }
707
708 docStoreRequest.setRequestDocuments(checkOutReqDocs);
709 workbenchForm.setRequestXMLTextArea(new RequestHandler().toXML(docStoreRequest));
710 return getUIFModelAndView(workbenchForm);
711 }
712
713 @RequestMapping(params = "methodToCall=submit")
714 public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
715 HttpServletRequest request, HttpServletResponse response) throws Exception {
716 WorkbenchForm workbenchForm = (WorkbenchForm) form;
717 boolean isValid = false;
718 BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
719 Map<String, String> map = new HashMap<>();
720 List<OleWorkBibDocument> oleWorkBibDocumentList = workbenchForm.getWorkBibDocumentList();
721 List<Integer> resultList = new ArrayList<>();
722 for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocumentList) {
723 if (oleWorkBibDocument.isSelect()) {
724 map.put(OLEConstants.BIB_ID, oleWorkBibDocument.getId());
725 List<OleCopy> listOfValues = (List<OleCopy>) boService.findMatching(OleCopy.class, map);
726 if (listOfValues.size() > 0 && (workbenchForm.getMessage() == null || workbenchForm.getMessage().equals(""))) {
727 for (OleCopy oleCopy : listOfValues) {
728 resultList.add(oleCopy.getReqDocNum());
729 }
730 Set<Integer> resultSet = new HashSet<>(resultList);
731 resultList = new ArrayList<>(resultSet);
732 StringBuffer reqIds = new StringBuffer("");
733 if (resultList.size() > 0) {
734 int count = 0;
735 for (; count < resultList.size() - 1; count++) {
736 reqIds.append(resultList.get(count) + ",");
737 }
738 reqIds.append(resultList.get(count));
739 }
740 workbenchForm.setMessage(OLEConstants.POPUP_MESSAGE + reqIds.toString() + OLEConstants.PROCEED_MESSAGE);
741 return getUIFModelAndView(workbenchForm);
742 }
743 workbenchForm.setMessage("");
744 processNewRecordResponseForOLE(oleWorkBibDocument, workbenchForm.getTokenId());
745 workbenchForm.setSuccessMessage(OLEConstants.LINK_SUCCESS_MESSAGE);
746 isValid = true;
747 break;
748 }
749 }
750 if (isValid == false) {
751 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.BIB_SELECT);
752 return getUIFModelAndView(workbenchForm);
753 }
754 return getUIFModelAndView(workbenchForm);
755 }
756
757 private void processNewRecordResponseForOLE(OleWorkBibDocument oleWorkBibDocument, String tokenId) throws Exception {
758 String instanceUUID = null;
759 List bibInfo = null;
760 DiscoveryHelperService discoveryHelperService = GlobalResourceLoader.getService(OLEConstants.DISCOVERY_HELPER_SERVICE);
761 OleBibRecord oleBibRecord = new OleBibRecord();
762 WorkBibDocument workBibDocument = new WorkBibDocument();
763 workBibDocument.setId(oleWorkBibDocument.getId());
764 QueryService queryService = QueryServiceImpl.getInstance();
765 workBibDocument = queryService.queryForBibTree(workBibDocument);
766 OleEditorResponse oleEditorResponse = new OleEditorResponse();
767 if (workBibDocument.getWorkInstanceDocumentList()!=null && workBibDocument.getWorkInstanceDocumentList().size()>0){
768 instanceUUID = workBibDocument.getWorkInstanceDocumentList().get(0).getInstanceIdentifier();
769 bibInfo = discoveryHelperService.getBibInformationFromInsatnceId(instanceUUID);
770 }else{
771 bibInfo = discoveryHelperService.getBibInformationFromBibId(oleWorkBibDocument.getId());
772 }
773 if (bibInfo!=null && bibInfo.size()>0){
774 oleBibRecord.setBibAssociatedFieldsValueMap((Map<String, ?>) bibInfo.get(0));
775 }
776 oleBibRecord.setLinkedInstanceId(instanceUUID);
777 oleBibRecord.setBibUUID(workBibDocument.getId());
778 oleEditorResponse.setOleBibRecord(oleBibRecord);
779 oleEditorResponse.setTokenId(tokenId);
780 OleEditorResponseHandler oleEditorResponseHandler = new OleEditorResponseHandler();
781 String editorResponseXMLForOLE = oleEditorResponseHandler.toXML(oleEditorResponse);
782 OleExposedWebServiceImpl oleExposedWebService = (OleExposedWebServiceImpl) SpringContext.getBean(OLEConstants.OLE_EXPOSED_WEB_SERVICE);
783 oleExposedWebService.addDoctoreResponse(editorResponseXMLForOLE);
784 }
785
786 public String getURL() {
787 String url = ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.OLE_EXPOSED_WEB_SERVICE_url);
788 return url;
789 }
790
791 @RequestMapping(params = "methodToCall=linkToBib")
792 public ModelAndView linkToBib(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
793 HttpServletRequest request, HttpServletResponse response) throws Exception {
794 WorkbenchForm workbenchForm = (WorkbenchForm) form;
795 BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
796 Map<String, String> map = new HashMap<>();
797 List<OleWorkBibDocument> oleWorkBibDocumentList = workbenchForm.getWorkBibDocumentList();
798 List<OleWorkEHoldingsDocument> oleWorkEHoldingsDocuments = workbenchForm.getWorkEHoldingsDocumentList();
799 List<OleWorkHoldingsDocument> oleWorkHoldingsDocuments = workbenchForm.getWorkHoldingsDocumentList();
800 List<Integer> resultList = new ArrayList<>();
801 workbenchForm.setSuccessMessage(null);
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817 if (workbenchForm.getSearchParams().getDocType().equals(OLEConstants.E_HOLDINGS_DOC_TYPE)) {
818 if (oleWorkEHoldingsDocuments != null && oleWorkEHoldingsDocuments.size() > 0) {
819 for (OleWorkEHoldingsDocument oleWorkEHoldingsDocument : oleWorkEHoldingsDocuments) {
820 if (oleWorkEHoldingsDocument.isSelect()) {
821 String eResName = "";
822 Map ersIdMap = new HashMap();
823 ersIdMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourceId);
824 OLEEResourceRecordDocument eResourceDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, ersIdMap);
825 if (eResourceDocument != null) {
826 eResName = eResourceDocument.getTitle();
827 }
828 processNewEInstanceResponse(oleWorkEHoldingsDocument, workbenchForm.getTokenId());
829 saveRecordToDocstore(oleWorkEHoldingsDocument, eResourceId, eResName);
830 workbenchForm.setSuccessMessage("");
831 break;
832 } else {
833 workbenchForm.setSuccessMessage(OLEConstants.EHOLDINGS_ERROR_MESSAGE);
834 }
835 }
836 }
837 }
838
839 else if (workbenchForm.getSearchParams().getDocType().equals(OLEConstants.HOLDINGS_DOC_TYPE)) {
840 if (oleWorkHoldingsDocuments != null && oleWorkHoldingsDocuments.size() > 0) {
841 for (OleWorkHoldingsDocument oleWorkHoldingsDocument : oleWorkHoldingsDocuments) {
842 if (oleWorkHoldingsDocument.isSelect()) {
843 processNewInstanceResponse(oleWorkHoldingsDocument, workbenchForm.getTokenId());
844 workbenchForm.setSuccessMessage("");
845 break;
846 } else {
847 workbenchForm.setSuccessMessage(OLEConstants.HOLDINGS_ERROR_MESSAGE);
848 }
849 }
850 }
851 }
852 if (eResourceId != null && !eResourceId.isEmpty()) {
853 Map<String, String> tempId = new HashMap<String, String>();
854 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourceId);
855 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
856 try {
857 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
858 tempDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(tempDocument.getDocumentNumber(), principalPerson));
859 if (tempDocument != null) {
860 try {
861 tempDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE);
862 tempDocument.seteInstanceFlag(true);
863 getOleEResourceSearchService().getNewInstance(tempDocument, tempDocument.getDocumentNumber());
864 getDocumentService().updateDocument(tempDocument);
865 } catch (Exception e) {
866 throw new RiceRuntimeException(
867 "Exception trying to save document: " + tempDocument
868 .getDocumentNumber(), e);
869 }
870 }
871 } catch (Exception e) {
872 throw new RiceRuntimeException(
873 "Exception trying to save document: " + tempDocument
874 .getDocumentNumber(), e);
875 }
876 }
877 return getUIFModelAndView(workbenchForm);
878 }
879
880 @RequestMapping(params = "methodToCall=getHoldingsList")
881 public ModelAndView getHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
882 HttpServletRequest request, HttpServletResponse response) throws Exception {
883 WorkbenchForm workbenchForm = (WorkbenchForm) form;
884 workbenchForm.setErrorMessage(null);
885 List<OleWorkHoldingsDocument> oleworkHoldingsDocumentList=new ArrayList<>();
886 List<WorkHoldingsDocument> workHoldingsDocumentList=new ArrayList<>();
887 List<OleWorkBibDocument> oleWorkBibDocumentList = workbenchForm.getWorkBibDocumentList();
888 if (oleWorkBibDocumentList != null && oleWorkBibDocumentList.size()>0){
889 for (OleWorkBibDocument oleWorkBibDocument:oleWorkBibDocumentList){
890 if (oleWorkBibDocument.isSelect()){
891 QueryService queryService = QueryServiceImpl.getInstance();
892 OleWorkBibDocument oleWorkBibDocumentResult= (OleWorkBibDocument)queryService.queryForBibTree(oleWorkBibDocument);
893 List<WorkInstanceDocument> instanceDocumentList =oleWorkBibDocumentResult.getWorkInstanceDocumentList();
894 if (instanceDocumentList.size()>0){
895 for (WorkInstanceDocument workInstanceDocument:instanceDocumentList){
896 workHoldingsDocumentList.add(workInstanceDocument.getHoldingsDocument());
897 }
898 for (WorkHoldingsDocument workHoldingsDocument : workHoldingsDocumentList) {
899 OleWorkHoldingsDocument oleWorkHoldingsDocument = new OleWorkHoldingsDocument();
900 oleWorkHoldingsDocument.setHoldingsIdentifier(workHoldingsDocument.getHoldingsIdentifier());
901 oleWorkHoldingsDocument.setBibTitle(workHoldingsDocument.getBibTitle());
902 oleWorkHoldingsDocument.setBibTitle(oleWorkBibDocument.getTitle());
903 oleWorkHoldingsDocument.setBibIdentifier(workHoldingsDocument.getBibIdentifier());
904 oleWorkHoldingsDocument.setBibUUIDList(workHoldingsDocument.getBibUUIDList());
905 oleWorkHoldingsDocument.setCallNumber(workHoldingsDocument.getCallNumber());
906 oleWorkHoldingsDocument.setCallNumberPrefix(workHoldingsDocument.getCallNumberPrefix());
907 oleWorkHoldingsDocument.setCallNumberType(workHoldingsDocument.getCallNumberType());
908 oleWorkHoldingsDocument.setCopyNumber(workHoldingsDocument.getCopyNumber());
909 oleWorkHoldingsDocument.setHoldingsIdentifier(workHoldingsDocument.getHoldingsIdentifier());
910 oleWorkHoldingsDocument.setStaffOnlyFlag(workHoldingsDocument.getStaffOnlyFlag());
911 oleWorkHoldingsDocument.setLinkedBibCount(workHoldingsDocument.getLinkedBibCount());
912 oleWorkHoldingsDocument.setLocalId(workHoldingsDocument.getLocalId());
913 oleWorkHoldingsDocument.setLocationName(workHoldingsDocument.getLocationName());
914 oleWorkHoldingsDocument.setInstanceIdentifier(workHoldingsDocument.getInstanceIdentifier());
915 oleworkHoldingsDocumentList.add(oleWorkHoldingsDocument);
916 }
917 }
918 }
919 }
920 }
921 workbenchForm.setWorkHoldingsDocumentList(oleworkHoldingsDocumentList);
922 workbenchForm.setWorkEHoldingsDocumentList(null);
923 workbenchForm.getSearchParams().setDocType(OLEConstants.HOLDINGS_DOC_TYPE);
924 return navigate(workbenchForm, result, request, response);
925 }
926 @RequestMapping(params = "methodToCall=getEHoldingsList")
927 public ModelAndView getEHoldingsList(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
928 HttpServletRequest request, HttpServletResponse response) throws Exception {
929 WorkbenchForm workbenchForm = (WorkbenchForm) form;
930 workbenchForm.setErrorMessage(null);
931 List<WorkEHoldingsDocument> workEHoldingsDocumentList=new ArrayList<>();
932 List<OleWorkEHoldingsDocument> oleWorkEHoldingsDocumentList=new ArrayList<>();
933 List<OleWorkBibDocument> oleWorkBibDocumentList = workbenchForm.getWorkBibDocumentList();
934 if (oleWorkBibDocumentList != null && oleWorkBibDocumentList.size()>0){
935 for (OleWorkBibDocument oleWorkBibDocument:oleWorkBibDocumentList){
936 if (oleWorkBibDocument.isSelect()){
937 QueryService queryService = QueryServiceImpl.getInstance();
938 OleWorkBibDocument oleWorkBibDocumentResult= (OleWorkBibDocument)queryService.queryForBibTree(oleWorkBibDocument);
939 List<WorkEInstanceDocument> eInstanceDocumentList =oleWorkBibDocumentResult.getWorkEInstanceDocumentList();
940 if (eInstanceDocumentList.size()>0){
941 for (WorkEInstanceDocument workEInstanceDocument:eInstanceDocumentList){
942 workEHoldingsDocumentList.add(workEInstanceDocument.getWorkEHoldingsDocument());
943 }
944 for (WorkEHoldingsDocument workEHoldingsDocument : workEHoldingsDocumentList) {
945 OleWorkEHoldingsDocument oleWorkEHoldingsDocument = new OleWorkEHoldingsDocument();
946 oleWorkEHoldingsDocument.setAccessStatus(workEHoldingsDocument.getAccessStatus());
947 oleWorkEHoldingsDocument.setPlatForm(workEHoldingsDocument.getPlatForm());
948 oleWorkEHoldingsDocument.setImprint(workEHoldingsDocument.getImprint());
949 oleWorkEHoldingsDocument.setStatisticalCode(workEHoldingsDocument.getStatisticalCode());
950 oleWorkEHoldingsDocument.setLocation(workEHoldingsDocument.getLocation());
951 oleWorkEHoldingsDocument.setBibIdentifier(workEHoldingsDocument.getBibIdentifier());
952 oleWorkEHoldingsDocument.setInstanceIdentifier(workEHoldingsDocument.getInstanceIdentifier());
953 oleWorkEHoldingsDocument.setHoldingsIdentifier(workEHoldingsDocument.getHoldingsIdentifier());
954 oleWorkEHoldingsDocument.setLocalId(workEHoldingsDocument.getLocalId());
955 oleWorkEHoldingsDocument.setUrl(workEHoldingsDocument.getUrl());
956 oleWorkEHoldingsDocument.seteResourceName(workEHoldingsDocument.geteResourceName());
957 oleWorkEHoldingsDocumentList.add(oleWorkEHoldingsDocument);
958 }
959 }
960 else {
961 workbenchForm.setErrorMessage("selected bib doesnt have EHoldings");
962 }
963 }
964 }
965 }
966 workbenchForm.setWorkEHoldingsDocumentList(oleWorkEHoldingsDocumentList);
967 workbenchForm.setWorkHoldingsDocumentList(null);
968 workbenchForm.getSearchParams().setDocType(OLEConstants.E_HOLDINGS_DOC_TYPE);
969 return navigate(workbenchForm, result, request, response);
970 }
971
972
973 private void saveRecordToDocstore(OleWorkEHoldingsDocument oleWorkEHoldingsDocument, String eResourceId, String eResName) throws Exception {
974 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
975 WorkEHoldingOlemlRecordProcessor workEHoldingOlemlRecordProcessor = new WorkEHoldingOlemlRecordProcessor();
976 String eHoldingsId = oleWorkEHoldingsDocument.getHoldingsIdentifier();
977 String eHoldingsContent = docstoreHelperService.getDocstoreData(eHoldingsId);
978 EHoldings eHoldings = workEHoldingOlemlRecordProcessor.fromXML(eHoldingsContent);
979 eHoldings.setEResourceId(eResourceId);
980 eHoldings.setEResourceTitle(eResName);
981 eHoldingsContent = workEHoldingOlemlRecordProcessor.toXML(eHoldings);
982 docstoreHelperService.updateInstanceRecord(eHoldingsId, DocType.EHOLDINGS.getCode(), eHoldingsContent);
983 }
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013 private void processNewEInstanceResponse(OleWorkEHoldingsDocument oleWorkEHoldingsDocument, String tokenId) throws Exception {
1014 String instanceUUID = null;
1015 String einstanceUUID = null;
1016 List bibInfo = null;
1017 DiscoveryHelperService discoveryHelperService = GlobalResourceLoader.getService(OLEConstants.DISCOVERY_HELPER_SERVICE);
1018 OleBibRecord oleBibRecord = new OleBibRecord();
1019 WorkBibDocument workBibDocument = new WorkBibDocument();
1020 workBibDocument.setId(oleWorkEHoldingsDocument.getBibIdentifier());
1021 WorkEInstanceDocument workEInstanceDocument = new WorkEInstanceDocument();
1022 workEInstanceDocument.setId(oleWorkEHoldingsDocument.getInstanceIdentifier());
1023 QueryService queryService = QueryServiceImpl.getInstance();
1024 workEInstanceDocument = queryService.queryForEInstanceTree(workEInstanceDocument);
1025 OleEditorResponse oleEditorResponse = new OleEditorResponse();
1026
1027 instanceUUID = workEInstanceDocument.getInstanceIdentifier();
1028 bibInfo = discoveryHelperService.getBibInformationFromInsatnceId(instanceUUID);
1029 oleBibRecord.setBibAssociatedFieldsValueMap((Map<String, ?>) bibInfo.get(0));
1030 oleBibRecord.setLinkedInstanceId(instanceUUID);
1031 oleBibRecord.setBibUUID(workBibDocument.getId());
1032 oleBibRecord.seteInstance(OLEConstants.E_INSTANCE);
1033 oleEditorResponse.setOleBibRecord(oleBibRecord);
1034 oleEditorResponse.setTokenId(tokenId);
1035 OleEditorResponseHandler oleEditorResponseHandler = new OleEditorResponseHandler();
1036 String editorResponseXMLForOLE = oleEditorResponseHandler.toXML(oleEditorResponse);
1037 OleExposedWebServiceImpl oleExposedWebService = (OleExposedWebServiceImpl) SpringContext.getBean(OLEConstants.OLE_EXPOSED_WEB_SERVICE);
1038 oleExposedWebService.addDoctoreResponse(editorResponseXMLForOLE);
1039 }
1040
1041 private void processNewInstanceResponse(OleWorkHoldingsDocument oleWorkHoldingsDocument, String tokenId) throws Exception {
1042 String instanceUUID = null;
1043 String einstanceUUID = null;
1044 List bibInfo = null;
1045 DiscoveryHelperService discoveryHelperService = GlobalResourceLoader.getService(OLEConstants.DISCOVERY_HELPER_SERVICE);
1046 OleBibRecord oleBibRecord = new OleBibRecord();
1047 WorkBibDocument workBibDocument = new WorkBibDocument();
1048 workBibDocument.setId(oleWorkHoldingsDocument.getBibIdentifier());
1049 WorkInstanceDocument workInstanceDocument = new WorkInstanceDocument();
1050 workInstanceDocument.setId(oleWorkHoldingsDocument.getInstanceIdentifier());
1051 QueryService queryService = QueryServiceImpl.getInstance();
1052 workInstanceDocument = queryService.queryForInstanceTree(workInstanceDocument);
1053 OleEditorResponse oleEditorResponse = new OleEditorResponse();
1054 instanceUUID = workInstanceDocument.getInstanceIdentifier();
1055 bibInfo = discoveryHelperService.getBibInformationFromInsatnceId(instanceUUID);
1056 oleBibRecord.setBibAssociatedFieldsValueMap((Map<String, ?>) bibInfo.get(0));
1057 oleBibRecord.setLinkedInstanceId(instanceUUID);
1058 oleBibRecord.setBibUUID(workBibDocument.getId());
1059 oleEditorResponse.setOleBibRecord(oleBibRecord);
1060 oleEditorResponse.setTokenId(tokenId);
1061 OleEditorResponseHandler oleEditorResponseHandler = new OleEditorResponseHandler();
1062 String editorResponseXMLForOLE = oleEditorResponseHandler.toXML(oleEditorResponse);
1063 OleExposedWebServiceImpl oleExposedWebService = (OleExposedWebServiceImpl) SpringContext.getBean(OLEConstants.OLE_EXPOSED_WEB_SERVICE);
1064 oleExposedWebService.addDoctoreResponse(editorResponseXMLForOLE);
1065 }
1066
1067 private boolean canExportToRequestXml(String principalId) {
1068 PermissionService service = KimApiServiceLocator.getPermissionService();
1069 return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.DESC_WORKBENCH_EXPORT_XML);
1070 }
1071 }