1 package org.kuali.ole.describe.controller;
2
3
4 import org.apache.commons.httpclient.HttpClient;
5 import org.apache.commons.httpclient.NameValuePair;
6 import org.apache.commons.httpclient.methods.DeleteMethod;
7 import org.apache.commons.httpclient.methods.PutMethod;
8 import org.apache.commons.io.IOUtils;
9 import org.apache.log4j.Logger;
10 import org.apache.solr.client.solrj.SolrServerException;
11 import org.kuali.ole.PropertyUtil;
12 import org.kuali.ole.describe.bo.DocumentSelectionTree;
13 import org.kuali.ole.describe.bo.DocumentTreeNode;
14 import org.kuali.ole.describe.bo.OleWorkBibDocument;
15 import org.kuali.ole.describe.form.BoundwithForm;
16 import org.kuali.ole.docstore.discovery.model.SearchCondition;
17 import org.kuali.ole.docstore.discovery.model.SearchParams;
18 import org.kuali.ole.docstore.discovery.service.QueryService;
19 import org.kuali.ole.docstore.discovery.service.QueryServiceImpl;
20 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
21 import org.kuali.ole.docstore.model.bo.WorkHoldingsDocument;
22 import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
23 import org.kuali.ole.docstore.model.bo.WorkItemDocument;
24 import org.kuali.ole.docstore.model.enums.DocCategory;
25 import org.kuali.ole.docstore.model.enums.DocFormat;
26 import org.kuali.ole.docstore.model.enums.DocType;
27 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
28 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
29 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
30 import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
31 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
32 import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
33 import org.kuali.rice.core.api.util.tree.Node;
34 import org.kuali.rice.core.api.util.tree.Tree;
35 import org.kuali.rice.krad.uif.UifParameters;
36 import org.kuali.rice.krad.web.controller.UifControllerBase;
37 import org.kuali.rice.krad.web.form.UifFormBase;
38 import org.springframework.stereotype.Controller;
39 import org.springframework.validation.BindingResult;
40 import org.springframework.web.bind.annotation.ModelAttribute;
41 import org.springframework.web.bind.annotation.RequestMapping;
42 import org.springframework.web.servlet.ModelAndView;
43
44 import javax.servlet.http.HttpServletRequest;
45 import javax.servlet.http.HttpServletResponse;
46 import java.io.IOException;
47 import java.io.InputStream;
48 import java.util.ArrayList;
49 import java.util.List;
50
51
52
53
54
55
56
57
58 @Controller
59 @RequestMapping(value = "/boundwithController")
60 public class BoundwithController extends UifControllerBase {
61
62 private static final Logger LOG = Logger.getLogger(BoundwithController.class);
63 public List<String> selectedInstancesList = new ArrayList<String>();
64 String tree1BibId = new String();
65 List<String> selectedBibsList = new ArrayList<String>();
66 List<WorkBibDocument> bibDocumentList = new ArrayList<WorkBibDocument>();
67
68 WorkInstanceDocument workInstanceDocumentForTree1 = new WorkInstanceDocument();
69
70
71 @Override
72 protected UifFormBase createInitialForm(HttpServletRequest request) {
73 return new BoundwithForm();
74 }
75
76 @Override
77 @RequestMapping(params = "methodToCall=start")
78 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
79 HttpServletRequest request, HttpServletResponse response) {
80 LOG.debug("Inside the workbenchForm start method");
81 BoundwithForm boundwithForm = (BoundwithForm) form;
82 boundwithForm.getSearchParams().setDocType("bibliographic");
83
84
85 return super.start(boundwithForm, result, request, response);
86
87 }
88
89 @RequestMapping(params = "methodToCall=search")
90 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
91 HttpServletRequest request, HttpServletResponse response) {
92 LOG.info("Inside Search Method");
93 BoundwithForm boundwithForm = (BoundwithForm) form;
94 try {
95
96
97
98 boundwithForm.getSearchParams().setDocCategory("work");
99 boundwithForm.getSearchParams().setDocFormat("marc");
100 boundwithForm.getSearchParams().setDocType("bibliographic");
101 QueryService queryService = QueryServiceImpl.getInstance();
102 SearchParams searchParams = boundwithForm.getSearchParams();
103
104 List<WorkBibDocument> workBibDocumentList = queryService.getBibDocuments(searchParams);
105 List<OleWorkBibDocument> oleWorkBibDocumentList = new ArrayList<OleWorkBibDocument>();
106
107 for (WorkBibDocument workBibDocument : workBibDocumentList) {
108 OleWorkBibDocument oleWorkBibDocument = new OleWorkBibDocument();
109 oleWorkBibDocument.setId(workBibDocument.getId());
110 oleWorkBibDocument.setTitle(workBibDocument.getTitle());
111 oleWorkBibDocument.setAuthor(workBibDocument.getAuthor());
112 oleWorkBibDocument.setPublicationDate(workBibDocument.getPublicationDate());
113 oleWorkBibDocumentList.add(oleWorkBibDocument);
114 }
115 boundwithForm.setWorkBibDocumentList(oleWorkBibDocumentList);
116
117 } catch (Exception e) {
118 e.printStackTrace();
119 }
120 return updateComponent(boundwithForm, result, request, response);
121 }
122
123
124
125
126
127
128
129
130 @RequestMapping(params = "methodToCall=clearSearch")
131 public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
132 HttpServletRequest request, HttpServletResponse response) {
133 LOG.info("Inside clearSearch Method");
134 BoundwithForm boundwithForm = (BoundwithForm) form;
135 boundwithForm.setSearchParams(new SearchParams());
136 List<SearchCondition> searchConditions = boundwithForm.getSearchParams().getSearchFieldsList();
137 searchConditions.add(new SearchCondition());
138 searchConditions.add(new SearchCondition());
139 boundwithForm.getSearchParams().setDocType("bibliographic");
140 boundwithForm.setWorkBibDocumentList(null);
141
142 return updateComponent(boundwithForm, result, request, response);
143 }
144
145 @RequestMapping(params = "methodToCall=select")
146 public ModelAndView select(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
147 HttpServletRequest request, HttpServletResponse response) {
148 BoundwithForm boundwithForm = (BoundwithForm) form;
149 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
150 String selectedRecord = boundwithForm.getWorkBibDocumentList().get(index).getId();
151 LOG.debug("selectedRecord--->" + selectedRecord);
152 return super.updateComponent(boundwithForm, result, request, response);
153 }
154
155 @RequestMapping(params = "methodToCall=selectRecords")
156 public ModelAndView selectRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
157 HttpServletRequest request, HttpServletResponse response) {
158 BoundwithForm boundwithForm = (BoundwithForm) form;
159 List<String> selectedRecordIds = new ArrayList<String>();
160 List<OleWorkBibDocument> oleWorkBibDocuments = boundwithForm.getWorkBibDocumentList();
161 for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocuments) {
162 if (oleWorkBibDocument.isSelect()) {
163 selectedRecordIds.add(oleWorkBibDocument.getId());
164 }
165 }
166 LOG.debug("selectedRecords--->" + selectedRecordIds);
167 return getUIFModelAndView(boundwithForm);
168 }
169
170
171 @RequestMapping(params = "methodToCall=copyToTree")
172 public ModelAndView copyToTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
173 HttpServletRequest request, HttpServletResponse response) throws SolrServerException {
174
175 BoundwithForm boundwithForm = (BoundwithForm) form;
176 String treeId = boundwithForm.getActionParamaterValue("treeId");
177 copyToTree(boundwithForm, treeId);
178
179 return updateComponent(boundwithForm, result, request, response);
180 }
181
182
183
184
185
186
187
188
189
190
191 @RequestMapping(params = "methodToCall=showBoundwithBibs")
192 public ModelAndView showBoundwithBibs(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
193 HttpServletRequest request, HttpServletResponse response) throws SolrServerException {
194
195 BoundwithForm boundwithForm = (BoundwithForm) form;
196
197 Tree<DocumentTreeNode, String> tree1 = boundwithForm.getLeftTree();
198 Node<DocumentTreeNode, String> rootElement = tree1.getRootElement();
199 selectCheckedNodesForTree1(boundwithForm, rootElement);
200 boundwithForm.getDocumentTreeNode().setReturnCheck(true);
201 if ((selectedInstancesList.size() > 0) && (selectedInstancesList.size() > 1)) {
202 boundwithForm.setSelectedInstance("Please select only one instance from Tree1 ");
203
204 } else if ((selectedInstancesList.size() > 0) && (selectedInstancesList.size() == 1)) {
205 boundwithForm.setSelectedInstance("Instance " + workInstanceDocumentForTree1.getHoldingsDocument().getLocationName() + "\t bound with the following bibs : ");
206 boundwithForm.getDocumentTreeNode().setReturnCheck(true);
207 LOG.info("selected instance-->" + workInstanceDocumentForTree1.getInstanceIdentifier());
208 QueryService queryService = QueryServiceImpl.getInstance();
209
210 List<String> uuidList = queryService.queryForBibs(workInstanceDocumentForTree1.getInstanceIdentifier());
211
212 DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
213 Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(uuidList, DocType.BIB.getDescription());
214 boundwithForm.getBoundwithTree().setRootElement(rootNode);
215
216 } else {
217 boundwithForm.setSelectedInstance("Please select at-least one instance from Tree1 ");
218
219 }
220 return getUIFModelAndView(boundwithForm);
221 }
222
223
224
225
226
227
228
229
230 public void copyToTree(BoundwithForm boundwithForm, String treeId) throws SolrServerException {
231 List<String> uuidList = new ArrayList<String>();
232 List<OleWorkBibDocument> oleWorkBibDocuments = ((BoundwithForm) boundwithForm).getWorkBibDocumentList();
233 for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocuments) {
234 if (oleWorkBibDocument.isSelect()) {
235 uuidList.add(oleWorkBibDocument.getId());
236 }
237 }
238
239 DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
240 Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(uuidList,DocType.BIB.getDescription());
241 LOG.info("Tree id-->" + treeId);
242 if (treeId != null)
243
244 {
245 if (treeId.equalsIgnoreCase("leftTree")) {
246 boundwithForm.getLeftTree().setRootElement(rootNode);
247 boundwithForm.setLabelText("select");
248
249 }
250 if (treeId.equalsIgnoreCase("rightTree")) {
251 boundwithForm.getRightTree().setRootElement(rootNode);
252 boundwithForm.setTree2LabelText("select");
253
254 }
255
256 }
257
258 }
259
260
261 @RequestMapping(params = "methodToCall=submitTree1CheckBoxValues")
262 public ModelAndView submitCheckBoxValues(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
263 HttpServletRequest request, HttpServletResponse response) {
264 BoundwithForm boundwithForm = (BoundwithForm) form;
265 List<DocumentTreeNode> bibDocumentList = boundwithForm.getDisplayRecordList();
266 bibDocumentList.clear();
267 DocumentTreeNode bibDocument;
268 Tree<DocumentTreeNode, String> tree2 = boundwithForm.getLeftTree();
269 Node<DocumentTreeNode, String> rootElement = tree2.getRootElement();
270 List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
271 for (Node<DocumentTreeNode, String> node : list) {
272 bibDocument = node.getData();
273 LOG.info("is tree1 selected-->" + bibDocument.isSelect());
274 if (bibDocument.isSelect()) {
275 bibDocumentList.add(bibDocument);
276 }
277 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
278 for (Node<DocumentTreeNode, String> subNode : childrenList) {
279 bibDocument = subNode.getData();
280 if (bibDocument.isSelect()) {
281 bibDocumentList.add(bibDocument);
282 }
283
284 }
285 }
286
287 return getUIFModelAndView(boundwithForm);
288 }
289
290 @RequestMapping(params = "methodToCall=submitTree2CheckBoxValues")
291 public ModelAndView submitTree2CheckBoxValues(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
292 HttpServletRequest request, HttpServletResponse response) {
293 BoundwithForm boundwithForm = (BoundwithForm) form;
294 List<DocumentTreeNode> bibDocumentList = boundwithForm.getDisplayRecordList();
295 bibDocumentList.clear();
296 DocumentTreeNode bibDocument;
297 Tree<DocumentTreeNode, String> tree2 = boundwithForm.getRightTree();
298 Node<DocumentTreeNode, String> rootElement = tree2.getRootElement();
299 List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
300 for (Node<DocumentTreeNode, String> node : list) {
301 bibDocument = node.getData();
302 LOG.info("is tree2 selected-->" + bibDocument.isSelect());
303 if (bibDocument.isSelect()) {
304
305 bibDocumentList.add(bibDocument);
306 }
307 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
308 for (Node<DocumentTreeNode, String> subNode : childrenList) {
309 bibDocument = subNode.getData();
310 if (bibDocument.isSelect()) {
311 bibDocumentList.add(bibDocument);
312 }
313
314 }
315 }
316
317 return getUIFModelAndView(boundwithForm);
318 }
319
320
321 @RequestMapping(params = "methodToCall=submitBoundwithTreeCheckBoxValues")
322 public ModelAndView submitBoundwithTreeCheckBoxValues(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
323 HttpServletRequest request, HttpServletResponse response) {
324 BoundwithForm boundwithForm = (BoundwithForm) form;
325 List<DocumentTreeNode> bibDocumentList = boundwithForm.getDisplayRecordList();
326 bibDocumentList.clear();
327 DocumentTreeNode bibDocument;
328 Tree<DocumentTreeNode, String> tree2 = boundwithForm.getBoundwithTree();
329 Node<DocumentTreeNode, String> rootElement = tree2.getRootElement();
330 List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
331 for (Node<DocumentTreeNode, String> node : list) {
332 bibDocument = node.getData();
333 LOG.info("is tree1 selected-->" + bibDocument.isSelect());
334 if (bibDocument.isSelect()) {
335 bibDocumentList.add(bibDocument);
336 }
337 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
338 for (Node<DocumentTreeNode, String> subNode : childrenList) {
339 bibDocument = subNode.getData();
340 if (bibDocument.isSelect()) {
341 bibDocumentList.add(bibDocument);
342 }
343
344 }
345 }
346
347 return getUIFModelAndView(boundwithForm);
348 }
349
350
351 @RequestMapping(params = "methodToCall=selectTreeNodes")
352 public ModelAndView selectTreeNodes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
353 HttpServletRequest request, HttpServletResponse response) throws Exception {
354 BoundwithForm boundwithForm = (BoundwithForm) form;
355 String treeId = boundwithForm.getActionParamaterValue("treeId");
356 LOG.info("treeId-->" + treeId);
357 if (treeId.equalsIgnoreCase("leftTree")) {
358 Tree<DocumentTreeNode, String> tree2 = boundwithForm.getLeftTree();
359 Node<DocumentTreeNode, String> rootElement = tree2.getRootElement();
360 selectCheckedNodesForTree1(boundwithForm, rootElement);
361 }
362 if (treeId.equalsIgnoreCase("rightTree")) {
363 Tree<DocumentTreeNode, String> tree2 = boundwithForm.getRightTree();
364 Node<DocumentTreeNode, String> rootElement = tree2.getRootElement();
365 selectCheckedNodesForTree2(boundwithForm, rootElement);
366 }
367 if (treeId.equalsIgnoreCase(("boundwithTree"))) {
368 Tree<DocumentTreeNode, String> boundwithTree = boundwithForm.getBoundwithTree();
369 Node<DocumentTreeNode, String> rootElement = boundwithTree.getRootElement();
370 selectCheckedNodesForBoundwith(boundwithForm, rootElement);
371 }
372 return getUIFModelAndView(boundwithForm);
373 }
374
375
376
377
378
379
380
381
382
383
384
385 @RequestMapping(params = "methodToCall=performBoundwith")
386 public ModelAndView performBoundwith(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
387 HttpServletResponse httpResponse, HttpServletRequest httpServletRequest) throws Exception {
388 BoundwithForm boundwithForm = (BoundwithForm) form;
389 String treeId = boundwithForm.getActionParamaterValue("treeId");
390
391 Tree<DocumentTreeNode, String> tree1 = boundwithForm.getLeftTree();
392 Node<DocumentTreeNode, String> rootElement = tree1.getRootElement();
393 selectCheckedNodesForTree1(boundwithForm, rootElement);
394
395 Tree<DocumentTreeNode, String> tree2 = boundwithForm.getRightTree();
396 Node<DocumentTreeNode, String> tree2RootElement = tree2.getRootElement();
397 selectCheckedNodesForTree2(boundwithForm, tree2RootElement);
398 boundwithForm.getDocumentTreeNode().setReturnCheck(true);
399 DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
400
401 String validateMsg = validateInput();
402 LOG.info("validate msg -->" + validateMsg);
403 if (validateMsg.contains("success")) {
404 String bindResponse = performBoundwith(boundwithForm);
405 Response response = null;
406
407 response = new ResponseHandler().toObject(bindResponse);
408
409 if ((response.getStatus() != null) && (response.getStatus().contains("Success"))) {
410 boundwithForm.setSelectedInstance("Instance " + workInstanceDocumentForTree1.getHoldingsDocument().getLocationName() + "\t bound with the following bibs : ");
411
412 List<ResponseDocument> responseDocumentList = response.getDocuments();
413 List<String> uuidList = new ArrayList<String>();
414 uuidList.add(tree1BibId);
415 for (ResponseDocument responseDocument : responseDocumentList) {
416 List<ResponseDocument> linkedResponseDocuments = responseDocument.getLinkedDocuments();
417 for (ResponseDocument linkedResponseDocument : linkedResponseDocuments) {
418 uuidList.add(linkedResponseDocument.getId());
419 }
420 }
421
422 Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(uuidList, DocType.BIB.getDescription());
423 boundwithForm.getBoundwithTree().setRootElement(rootNode);
424 boundwithForm.setBoundwithTreeLabelText("select");
425 }
426
427 } else {
428 boundwithForm.setSelectedInstance(validateMsg);
429 }
430 return getUIFModelAndView(boundwithForm);
431 }
432
433
434
435
436
437
438
439 private String performBoundwith(BoundwithForm boundwithForm) throws IOException {
440
441 String operation = "bind";
442 return getResponseFromDocStore(operation);
443
444 }
445
446 private String getResponseFromDocStore(String operation) throws IOException {
447
448 String bindResponse = null;
449
450 Request request = buildRequest(operation);
451 bindResponse = null;
452 if (validateBoundwithRequest(request)) {
453 String stringContent = new RequestHandler().toXML(request);
454 LOG.info("request-->" + stringContent);
455 String restfulUrl = PropertyUtil.getPropertyUtil().getProperty("docstore.restful.url");
456 restfulUrl = restfulUrl.concat("/") + "bind";
457 LOG.info("restful url-->" + restfulUrl);
458 HttpClient client = new HttpClient();
459 PutMethod putMethod = new PutMethod(restfulUrl);
460 NameValuePair nvp1 = new NameValuePair("stringContent", stringContent);
461 putMethod.setQueryString(new NameValuePair[]{nvp1});
462 int statusCode = client.executeMethod(putMethod);
463 InputStream inputStream = putMethod.getResponseBodyAsStream();
464 bindResponse = IOUtils.toString(inputStream, "UTF-8");
465 LOG.info("bindResponse-->" + bindResponse);
466 }
467
468
469 return bindResponse;
470
471 }
472
473 private boolean validateBoundwithRequest(Request request) {
474 boolean isValid = false;
475 List<RequestDocument> requestDocumentList = request.getRequestDocuments();
476 if ((requestDocumentList.size() > 0) && (requestDocumentList.size() == 1)) {
477 for (RequestDocument requestDocument : requestDocumentList) {
478 if (requestDocument.getType().equalsIgnoreCase(DocType.INSTANCE.getCode())) {
479 isValid = true;
480 }
481 }
482 } else {
483 isValid = false;
484 }
485
486 return isValid;
487 }
488
489 private String validateInput() {
490
491 StringBuilder validateMsg = new StringBuilder();
492 if ((selectedInstancesList.size() > 0) && (selectedInstancesList.size() == 1)) {
493 List<WorkItemDocument> itemDocumentList = workInstanceDocumentForTree1.getItemDocumentList();
494 if (itemDocumentList.size() > 1) {
495 validateMsg.append("Failed : Bound-with instance should not contain more one item");
496 } else if (selectedBibsList.size() > 0) {
497
498 validateMsg.append("success");
499 } else {
500 validateMsg.append("Failed : please select at-least one bib From Tree2");
501 }
502 } else {
503 validateMsg.append("Failed : Please select only one instance from Tree1");
504 }
505 return validateMsg.toString();
506
507 }
508
509 @RequestMapping(params = "methodToCall=unbind")
510 public ModelAndView unbind(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
511 HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
512 BoundwithForm boundwithForm = (BoundwithForm) form;
513 String operation = "unbind";
514
515 Tree<DocumentTreeNode, String> boundwithTree = boundwithForm.getBoundwithTree();
516 Node<DocumentTreeNode, String> boundwithTreerootElement = boundwithTree.getRootElement();
517 selectCheckedNodesForBoundwith(boundwithForm, boundwithTreerootElement);
518 LOG.info("Unbind status -->" + boundwithForm.getSelectedInstance());
519 if ((boundwithForm.getSelectedInstance().contains("success"))) {
520
521 DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
522 boundwithForm.setSelectedInstance("Instance " + workInstanceDocumentForTree1.getHoldingsDocument().getLocationName() + "\t bounded with the following bibs :");
523 String unbindResponse = getResponseFromDocStore(operation);
524 Response response = new ResponseHandler().toObject(unbindResponse);
525
526 List<ResponseDocument> responseDocumentList = response.getDocuments();
527 List<String> uuidList = new ArrayList<String>();
528 for (ResponseDocument responseDocument : responseDocumentList) {
529 List<ResponseDocument> linkedResponseDocuments = responseDocument.getLinkedDocuments();
530 for (ResponseDocument linkedResponseDocument : linkedResponseDocuments) {
531 uuidList.add(linkedResponseDocument.getId());
532 }
533
534
535 }
536 if (selectedBibsList != null) {
537 selectedBibsList.add(tree1BibId);
538 Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(selectedBibsList, DocType.BIB.getDescription());
539 boundwithForm.getBoundwithTree().setRootElement(rootNode);
540 boundwithForm.setBoundwithTreeLabelText("select");
541 }
542 }
543
544 return getUIFModelAndView(boundwithForm);
545 }
546
547 @RequestMapping(params = "methodToCall=delete")
548 public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
549 HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
550
551
552 BoundwithForm boundwithForm = (BoundwithForm) form;
553
554 DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
555 StringBuilder instanceIdList = new StringBuilder();
556 if (selectedInstancesList.size() > 0) {
557 for (String instanceId : selectedInstancesList) {
558 instanceIdList.append(instanceId);
559 instanceIdList.append(",");
560
561 }
562 LOG.info("selected bib list in delete -->" + selectedBibsList);
563
564 String restfulUrl = PropertyUtil.getPropertyUtil().getProperty("docstore.restful.url");
565 restfulUrl = restfulUrl.concat("/") + instanceIdList.toString();
566 HttpClient httpClient = new HttpClient();
567 DeleteMethod deleteMethod = new DeleteMethod(restfulUrl);
568 NameValuePair nvp1 = new NameValuePair("identifierType", "UUID");
569 NameValuePair nvp2 = new NameValuePair("operation", "delete");
570
571 NameValuePair category = new NameValuePair("docCategory", DocCategory.WORK.getCode());
572 NameValuePair type = new NameValuePair("docType", DocType.INSTANCE.getCode());
573 NameValuePair format = new NameValuePair("docFormat", DocFormat.OLEML.getCode());
574 deleteMethod.setQueryString(new NameValuePair[]{nvp1, nvp2, category, type, format});
575 int statusCode = httpClient.executeMethod(deleteMethod);
576 LOG.info("statusCode-->" + statusCode);
577 InputStream inputStream = deleteMethod.getResponseBodyAsStream();
578 String deleteResponse = IOUtils.toString(inputStream);
579 LOG.info("delete response-->" + deleteResponse);
580 if (deleteResponse.contains("Failed")) {
581 boundwithForm.setSelectedInstance("Unable to delete the instance " + workInstanceDocumentForTree1.getHoldingsDocument().getLocationName() + "\t \n because it exists in OLE database");
582
583 } else {
584 Response response = new ResponseHandler().toObject(deleteResponse);
585 if (response.getStatus().contains("Success")) {
586 boundwithForm.setSelectedInstance("Instance " + workInstanceDocumentForTree1.getHoldingsDocument().getLocationName() + "\t deleted from the following bibs :");
587 Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(selectedBibsList, DocType.BIB.getDescription());
588 boundwithForm.getBoundwithTree().setRootElement(rootNode);
589 boundwithForm.setBoundwithTreeLabelText("select");
590 }
591 }
592 } else {
593 boundwithForm.setSelectedInstance("Please select redundant instance to delete");
594
595 }
596 return getUIFModelAndView(boundwithForm);
597 }
598
599
600 private Request buildRequest(String operation) {
601 Request request = new Request();
602 request.setUser("ole-khuntley");
603 request.setOperation(operation);
604 RequestDocument requestDocument = new RequestDocument();
605 List<RequestDocument> requestDocumentList = new ArrayList<RequestDocument>();
606 List<RequestDocument> linkedRequestDocumentList = new ArrayList<RequestDocument>();
607
608 requestDocument.setUuid(selectedInstancesList.get(0));
609 requestDocument.setId(selectedInstancesList.get(0));
610 requestDocument.setType(DocType.INSTANCE.getCode());
611 requestDocument.setCategory(DocCategory.WORK.getCode());
612 requestDocument.setFormat(DocFormat.OLEML.getCode());
613 for (String bibId : selectedBibsList) {
614 RequestDocument linkedRequestDocument = new RequestDocument();
615 linkedRequestDocument.setUuid(bibId);
616 linkedRequestDocument.setCategory(DocCategory.WORK.getCode());
617 linkedRequestDocument.setType(DocType.BIB.getDescription());
618 linkedRequestDocument.setId(bibId);
619 linkedRequestDocument.setFormat(DocFormat.MARC.getCode());
620 linkedRequestDocumentList.add(linkedRequestDocument);
621
622 }
623 requestDocument.setLinkedRequestDocuments(linkedRequestDocumentList);
624 requestDocumentList.add(requestDocument);
625 request.setRequestDocuments(requestDocumentList);
626
627 return request;
628
629 }
630
631
632 @RequestMapping(params = "methodToCall=selectBoundwithTreeNodes")
633 public ModelAndView selectBoundwithTree1Nodes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
634 HttpServletRequest request, HttpServletResponse response) throws Exception {
635 BoundwithForm boundwithForm = (BoundwithForm) form;
636 Tree<DocumentTreeNode, String> tree2 = boundwithForm.getBoundwithTree();
637 Node<DocumentTreeNode, String> rootElement = tree2.getRootElement();
638 selectCheckedNodesForBoundwith(boundwithForm, rootElement);
639 return getUIFModelAndView(boundwithForm);
640 }
641
642
643 private void selectCheckedNodesForTree1(BoundwithForm boundwithForm, Node<DocumentTreeNode, String> rootElement) {
644 DocumentTreeNode documentTreeNode;
645 workInstanceDocumentForTree1 = new WorkInstanceDocument();
646 bibDocumentList = new ArrayList<WorkBibDocument>();
647 selectedInstancesList = new ArrayList<String>();
648 List<WorkInstanceDocument> workInstanceDocumentList = new ArrayList<WorkInstanceDocument>();
649 WorkBibDocument workBibDocumentForTree1 = new WorkBibDocument();
650 List<WorkItemDocument> workItemDocumentListForTree1 = new ArrayList<WorkItemDocument>();
651 List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
652 WorkHoldingsDocument workHoldingsDocument = new WorkHoldingsDocument();
653
654 for (Node<DocumentTreeNode, String> bibNode : list) {
655 documentTreeNode = bibNode.getData();
656 LOG.info("documentTreeNode.isSelectTree1()-->" + documentTreeNode.isSelect());
657 if (documentTreeNode.isSelect()) {
658 boundwithForm.setSelectedInstance("Failed : Please Select Instances only");
659
660
661
662
663
664
665
666
667
668
669
670
671
672 } else {
673 List<Node<DocumentTreeNode, String>> instanceList = bibNode.getChildren();
674 for (Node<DocumentTreeNode, String> instance : instanceList) {
675 documentTreeNode = instance.getData();
676 LOG.info("node1.getData()-->" + instance.getData().getTitle());
677 if (documentTreeNode.isSelect()) {
678 workBibDocumentForTree1.setId(bibNode.getNodeType());
679 workBibDocumentForTree1.setTitle(bibNode.getNodeLabel());
680 tree1BibId = bibNode.getNodeType();
681 LOG.info("documentTreeNode.isSelectTree1() in else-->" + documentTreeNode.isSelect());
682 LOG.info("inst id-->" + instance.getNodeType());
683 workInstanceDocumentForTree1.setInstanceIdentifier(instance.getNodeType());
684 selectedInstancesList.add(instance.getNodeType());
685 workHoldingsDocument.setLocationName(instance.getNodeLabel());
686 documentTreeNode.setSelect(true);
687 List<Node<DocumentTreeNode, String>> itemList = instance.getChildren();
688 for (Node<DocumentTreeNode, String> item : itemList) {
689
690 WorkItemDocument workItemDocument = new WorkItemDocument();
691 documentTreeNode = item.getData();
692 workItemDocument.setItemIdentifier(item.getNodeType());
693 workItemDocument.setCallNumber(item.getNodeLabel());
694 documentTreeNode.setSelect(true);
695 workItemDocumentListForTree1.add(workItemDocument);
696
697 }
698 workInstanceDocumentForTree1.setItemDocumentList(workItemDocumentListForTree1);
699 workInstanceDocumentForTree1.setHoldingsDocument(workHoldingsDocument);
700 workInstanceDocumentList.add(workInstanceDocumentForTree1);
701 workBibDocumentForTree1.setWorkInstanceDocumentList(workInstanceDocumentList);
702 bibDocumentList.add(workBibDocumentForTree1);
703 LOG.info("bibDocumentList size-->" + bibDocumentList.size());
704
705
706 }
707 }
708
709
710 }
711
712 }
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748 }
749
750 private void selectCheckedNodesForTree2(BoundwithForm boundwithForm, Node<DocumentTreeNode, String> rootElement) {
751 DocumentTreeNode documentTreeNode;
752 selectedBibsList = new ArrayList<String>();
753 List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
754
755 for (Node<DocumentTreeNode, String> node : list) {
756 documentTreeNode = node.getData();
757 LOG.info("documentTreeNode.isSelect()-->" + documentTreeNode.isSelect());
758 if (documentTreeNode.isSelect()) {
759 WorkBibDocument workBibDocument = new WorkBibDocument();
760 WorkHoldingsDocument workHoldingsDocument = new WorkHoldingsDocument();
761 List<WorkInstanceDocument> instanceDocumentListForTree2 = new ArrayList<WorkInstanceDocument>();
762 List<WorkItemDocument> workItemDocumentListForTree2 = new ArrayList<WorkItemDocument>();
763 workBibDocument.setId(node.getNodeType());
764 selectedBibsList.add(node.getNodeType());
765 workBibDocument.setTitle(node.getNodeLabel());
766 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
767 for (Node<DocumentTreeNode, String> subNode : childrenList) {
768 WorkInstanceDocument workInstanceDocument = new WorkInstanceDocument();
769 documentTreeNode = subNode.getData();
770 workInstanceDocument.setInstanceIdentifier(subNode.getNodeType());
771 documentTreeNode.setSelect(true);
772 workHoldingsDocument.setLocationName(subNode.getNodeLabel());
773 List<Node<DocumentTreeNode, String>> childrenList1 = subNode.getChildren();
774 for (Node<DocumentTreeNode, String> subNode1 : childrenList1) {
775 WorkItemDocument workItemDocument = new WorkItemDocument();
776 documentTreeNode = subNode1.getData();
777 workItemDocument.setItemIdentifier(subNode1.getNodeType());
778 workItemDocument.setCallNumber(subNode1.getNodeLabel());
779 workItemDocumentListForTree2.add(workItemDocument);
780 documentTreeNode.setSelect(true);
781
782 }
783 workInstanceDocument.setItemDocumentList(workItemDocumentListForTree2);
784 workInstanceDocument.setHoldingsDocument(workHoldingsDocument);
785 instanceDocumentListForTree2.add(workInstanceDocument);
786 instanceDocumentListForTree2.add(workInstanceDocumentForTree1);
787 workBibDocument.setWorkInstanceDocumentList(instanceDocumentListForTree2);
788 }
789 bibDocumentList.add(workBibDocument);
790
791 } else {
792 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
793 for (Node<DocumentTreeNode, String> node1 : childrenList) {
794 documentTreeNode = node1.getData();
795 if (documentTreeNode.isSelect()) {
796 List<Node<DocumentTreeNode, String>> childrenList1 = node1.getChildren();
797 for (Node<DocumentTreeNode, String> subNode : childrenList1) {
798 documentTreeNode = subNode.getData();
799 documentTreeNode.setSelect(true);
800
801 }
802 }
803 }
804 }
805
806 }
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842 }
843
844
845 private void selectCheckedNodesForBoundwith(BoundwithForm boundwithForm, Node<DocumentTreeNode, String> rootElement) {
846 DocumentTreeNode documentTreeNode;
847 selectedInstancesList = new ArrayList<String>();
848 selectedBibsList = new ArrayList<String>();
849 List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
850 if (boundwithForm.getBoundwithTreeLabelText().equalsIgnoreCase("select")) {
851
852
853 for (Node<DocumentTreeNode, String> node : list) {
854 documentTreeNode = node.getData();
855 if (documentTreeNode.isSelect()) {
856 boundwithForm.setSelectedInstance("Operation failed :Select Nodes at Instance level only....");
857
858
859
860
861
862
863
864
865
866
867
868
869
870 } else {
871 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
872 for (Node<DocumentTreeNode, String> node1 : childrenList) {
873 documentTreeNode = node1.getData();
874
875 if (documentTreeNode.isSelect()) {
876 LOG.info("documentTreeNode.isSelectboundwithTree() in else-->" + documentTreeNode.isSelect());
877 if (childrenList.size() > 1) {
878 selectedBibsList.add(node.getNodeType());
879 if (workInstanceDocumentForTree1.getInstanceIdentifier().equalsIgnoreCase(node1.getNodeType())) {
880 selectedInstancesList.add(node1.getNodeType());
881 boundwithForm.setSelectedInstance("Operation success");
882 }
883 } else {
884 boundwithForm.setSelectedInstance("Operation Failed :Bib record should contain atleast one instance");
885 }
886 documentTreeNode.setSelect(true);
887 List<Node<DocumentTreeNode, String>> childrenList1 = node1.getChildren();
888 for (Node<DocumentTreeNode, String> subNode : childrenList1) {
889 documentTreeNode = subNode.getData();
890 documentTreeNode.setSelect(true);
891
892 }
893 }
894 }
895 }
896 }
897 boundwithForm.setBoundwithTreeLabelText("deselect");
898 } else if (boundwithForm.getBoundwithTreeLabelText().equalsIgnoreCase("deselect")) {
899 for (Node<DocumentTreeNode, String> node : list) {
900 documentTreeNode = node.getData();
901 if (!documentTreeNode.isSelect()) {
902 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
903 for (Node<DocumentTreeNode, String> subNode : childrenList) {
904 documentTreeNode = subNode.getData();
905 documentTreeNode.setSelect(false);
906
907 List<Node<DocumentTreeNode, String>> childrenList1 = subNode.getChildren();
908 for (Node<DocumentTreeNode, String> subNode1 : childrenList1) {
909 documentTreeNode = subNode1.getData();
910 documentTreeNode.setSelect(false);
911
912 }
913
914 }
915 } else {
916 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
917 for (Node<DocumentTreeNode, String> node1 : childrenList) {
918 documentTreeNode = node1.getData();
919 if (!documentTreeNode.isSelect()) {
920 List<Node<DocumentTreeNode, String>> childrenList1 = node1.getChildren();
921 for (Node<DocumentTreeNode, String> subNode : childrenList1) {
922 documentTreeNode = subNode.getData();
923 documentTreeNode.setSelect(false);
924
925 }
926 }
927 }
928 }
929 }
930 boundwithForm.setBoundwithTreeLabelText("select");
931 }
932 }
933
934 }