1   package org.kuali.ole.describe.controller;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.apache.log4j.Logger;
5   import org.apache.solr.client.solrj.SolrServerException;
6   import org.kuali.ole.DocumentUniqueIDPrefix;
7   import org.kuali.ole.OLEConstants;
8   import org.kuali.ole.describe.bo.*;
9   import org.kuali.ole.describe.form.BoundwithForm;
10  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
11  import org.kuali.ole.docstore.common.document.*;
12  import org.kuali.ole.docstore.common.document.config.DocFieldConfig;
13  import org.kuali.ole.docstore.common.document.config.DocFormatConfig;
14  import org.kuali.ole.docstore.common.document.config.DocTypeConfig;
15  import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig;
16  import org.kuali.ole.docstore.common.exception.DocstoreException;
17  import org.kuali.ole.docstore.common.search.*;
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.Request;
22  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
23  import org.kuali.ole.select.util.TransferUtil;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.core.api.util.tree.Node;
26  import org.kuali.rice.core.api.util.tree.Tree;
27  import org.kuali.rice.kim.api.permission.PermissionService;
28  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29  import org.kuali.rice.krad.uif.UifParameters;
30  import org.kuali.rice.krad.util.GlobalVariables;
31  import org.kuali.rice.krad.util.KRADConstants;
32  import org.kuali.rice.krad.web.controller.UifControllerBase;
33  import org.kuali.rice.krad.web.form.UifFormBase;
34  import org.springframework.stereotype.Controller;
35  import org.springframework.util.CollectionUtils;
36  import org.springframework.validation.BindingResult;
37  import org.springframework.web.bind.annotation.ModelAttribute;
38  import org.springframework.web.bind.annotation.RequestMapping;
39  import org.springframework.web.servlet.ModelAndView;
40  
41  import javax.servlet.http.HttpServletRequest;
42  import javax.servlet.http.HttpServletResponse;
43  import java.util.*;
44  
45  
46  
47  
48  
49  
50  
51  
52  @Controller
53  @RequestMapping(value = "/boundwithController")
54  public class BoundwithController extends OLESearchController {
55  
56      private DocstoreClientLocator docstoreClientLocator;
57  
58      public DocstoreClientLocator getDocstoreClientLocator() {
59          if (null == docstoreClientLocator) {
60              return SpringContext.getBean(DocstoreClientLocator.class);
61          }
62          return docstoreClientLocator;
63      }
64      DocumentSearchConfig documentSearchConfig = DocumentSearchConfig.getDocumentSearchConfig();
65      private static final Logger LOG = Logger.getLogger(BoundwithController.class);
66      public int totalRecCount;
67      public int start;
68      public int pageSize;
69  
70      public int getTotalRecCount() {
71          return totalRecCount;
72      }
73  
74      public void setTotalRecCount(int totalRecCount) {
75          this.totalRecCount = totalRecCount;
76      }
77  
78      public int getStart() {
79          return start;
80      }
81  
82      public void setStart(int start) {
83          this.start = start;
84      }
85  
86      public int getPageSize() {
87          return pageSize;
88      }
89  
90      public void setPageSize(int pageSize) {
91          this.pageSize = pageSize;
92      }
93  
94      public boolean getWorkbenchPreviousFlag() {
95          if (this.start == 0)
96              return false;
97          return true;
98      }
99  
100     public boolean getWorkbenchNextFlag() {
101         if (this.start + this.pageSize < this.totalRecCount)
102             return true;
103         return false;
104     }
105 
106     public String getWorkbenchPageShowEntries() {
107         return "Showing " + ((this.start == 0) ? 1 : this.start + 1) + " to "
108                 + (((this.start + this.pageSize) > this.totalRecCount) ? this.totalRecCount : (this.start + this.pageSize))
109                 + " of " + this.totalRecCount + " entries";
110     }
111 
112 
113     @Override
114     protected UifFormBase createInitialForm(HttpServletRequest request) {
115         return new BoundwithForm();
116     }
117 
118     protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, BoundwithForm boundwithForm) {
119         return super.navigate(boundwithForm, result, request, response);
120     }
121 
122     
123 
124 
125 
126 
127     
128 
129 
130 
131 
132     private boolean canPerformTransfer(String principalId) {
133         PermissionService service = KimApiServiceLocator.getPermissionService();
134         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.TRANSFER_HOLDING_OR_ITEM);
135     }
136 
137     private boolean canPerformBoundWith(String principalId) {
138         PermissionService service = KimApiServiceLocator.getPermissionService();
139         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.BOUND_WITH);
140     }
141 
142     private boolean canPerformAnalytics(String principalId) {
143         PermissionService service = KimApiServiceLocator.getPermissionService();
144         return service.hasPermission(principalId, OLEConstants.CAT_NAMESPACE, OLEConstants.ANALYTICS_PERMISSION);
145     }
146 
147     @RequestMapping(params = "methodToCall=clear")
148     public ModelAndView clear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
149                               HttpServletRequest request, HttpServletResponse response) {
150         LOG.info("Inside clearSearch Method");
151         BoundwithForm boundwithForm = (BoundwithForm) form;
152         boundwithForm.setHoldingsList(null);
153         boundwithForm.setItemList(null);
154         boundwithForm.setSearchResultDisplayRowList(null);
155         boundwithForm.setPageSize(10);
156         boundwithForm.setPreviousFlag(false);
157         boundwithForm.setNextFlag(false);
158         for(SearchCondition searchCondition : boundwithForm.getSearchConditions()) {
159             searchCondition.getSearchField().setFieldName("");
160             searchCondition.getSearchField().setFieldValue("");
161         }
162         if (boundwithForm.getSearchResultDisplayRowList() != null && boundwithForm.getSearchResultDisplayRowList().size() > 0) {
163             boundwithForm.getSearchResultDisplayRowList().clear();
164         }
165         if(boundwithForm.getSearchParams() != null && boundwithForm.getSearchParams().getFacetFields() != null) {
166             boundwithForm.getSearchParams().getFacetFields().clear();
167         }
168         if(boundwithForm.getFacetResultFields() != null) {
169             boundwithForm.getFacetResultFields().clear();
170         }
171 
172         return navigate(boundwithForm, result, request, response);
173     }
174 
175     @Override
176     @RequestMapping(params = "methodToCall=start")
177     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
178                               HttpServletRequest request, HttpServletResponse response) {
179         LOG.debug("Inside the boundwithForm start method");
180         boolean hasPermission = false;
181         if (request.getSession().getAttribute(OLEConstants.LEFT_LIST) != null && request.getSession().getAttribute(OLEConstants.RIGHT_LIST) != null) {
182             request.getSession().removeAttribute(OLEConstants.LEFT_LIST);
183             request.getSession().removeAttribute(OLEConstants.RIGHT_LIST);
184         }
185         BoundwithForm boundwithForm = (BoundwithForm) form;
186         boundwithForm.getSearchConditions().clear();
187         SearchCondition searchCondition = new SearchCondition();
188         searchCondition.setOperator("AND");
189         boundwithForm.getSearchConditions().add(searchCondition);
190 
191 
192         boundwithForm.setSearchTypeField("Boundwith");
193          if (boundwithForm.getSearchResultDisplayRowList() != null && boundwithForm.getSearchResultDisplayRowList().size() > 0) {
194             boundwithForm.getSearchResultDisplayRowList().clear();
195         }
196         if(boundwithForm.getSearchParams() != null && boundwithForm.getSearchParams().getFacetFields() != null) {
197             boundwithForm.getSearchParams().getFacetFields().clear();
198         }
199 
200         if(boundwithForm.getFacetResultFields() != null) {
201             boundwithForm.getFacetResultFields().clear();
202         }
203           if(boundwithForm.getSearchParams() != null) {
204                 boundwithForm.getSearchParams().getSearchConditions().clear();
205                 boundwithForm.getSearchParams().getSearchResultFields().clear();
206                 boundwithForm.setStart(0);
207         }
208         request.getSession().setAttribute("selectedFacetResults", null);
209         if(StringUtils.isEmpty(boundwithForm.getSearchType())) {
210             boundwithForm.setSearchType("search");
211         }
212         if (boundwithForm.getDocType() == null) {
213             boundwithForm.setDocType(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode());
214         }
215 
216         if (boundwithForm.getViewId().equalsIgnoreCase("TransferView")) {
217             hasPermission = canPerformTransfer(GlobalVariables.getUserSession().getPrincipalId());
218         } else if (boundwithForm.getViewId().equalsIgnoreCase("BoundwithView")) {
219             hasPermission = canPerformBoundWith(GlobalVariables.getUserSession().getPrincipalId());
220         } else if (boundwithForm.getViewId().equalsIgnoreCase(OLEConstants.ANALYTICS_VIEW)) {
221             hasPermission = canPerformAnalytics(GlobalVariables.getUserSession().getPrincipalId());
222         } else if (boundwithForm.getViewId().equalsIgnoreCase(OLEConstants.ANALYTICS_SUMMARY_VIEW)) {
223             hasPermission = canPerformAnalytics(GlobalVariables.getUserSession().getPrincipalId());
224         }
225         if (!hasPermission) {
226             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.ERROR_AUTHORIZATION);
227             return navigate(boundwithForm, result, request, response);
228         }
229         boundwithForm.setWorkBibDocumentList(null);
230 
231         boundwithForm.setWorkHoldingsDocumentList(null);
232         boundwithForm.setWorkItemDocumentList(null);
233         boundwithForm.setWorkEHoldingsDocumentList(null);
234         boundwithForm.setMessage(null);
235         boundwithForm.setSearchResultDisplayRowList(null);
236 
237         List<Integer> pageSizes = documentSearchConfig.getPageSizes();
238         if(!pageSizes.isEmpty() || pageSizes.size() > 0) {
239             boundwithForm.setPageSize(pageSizes.get(0));
240         }
241         boundwithForm.setHoldingsList(null);
242         boundwithForm.setItemList(null);
243         GlobalVariables.getMessageMap().clearErrorMessages();
244         return navigate(boundwithForm, result, request, response);
245 
246     }
247 
248     
249 
250 
251 
252 
253 
254 
255     private void setShowPageSizeEntries(BoundwithForm boundwithForm) {
256         List<Integer> pageSizes = documentSearchConfig.getPageSizes();
257         if (org.apache.commons.collections.CollectionUtils.isEmpty(pageSizes)) {
258             pageSizes.add(10);
259             pageSizes.add(25);
260             pageSizes.add(50);
261             pageSizes.add(100);
262         }
263         boundwithForm.setShowPageSize(pageSizes.toString());
264     }
265 
266 
267 
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
286 
287 
288 
289 
290 
291 
292 
293 
294 
295 
296 
297 
298 
299 
300 
301 
302 
303 
304 
305 
306 
307 
308 
309 
310 
311 
312 
313 
314 
315 
316 
317 
318 
319 
320 
321 
322 
323 
324 
325 
326 
327 
328 
329 
330 
331 
332 
333 
334 
335 
336 
337 
338 
339 
340 
341 
342 
343 
344 
345 
346 
347 
348 
349 
350 
351 
352 
353 
354 
355 
356 
357 
358 
359 
360 
361 
362 
363 
364 
365 
366 
367 
368 
369 
370 
371 
372 
373 
374 
375 
376 
377 
378 
379 
380 
381 
382 
383 
384 
385     
386 
387 
388 
389 
390 
391 
392     @RequestMapping(params = "methodToCall=clearSearch")
393     public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
394                                     HttpServletRequest request, HttpServletResponse response) {
395         LOG.info("Inside clearSearch Method");
396         BoundwithForm boundwithForm = (BoundwithForm) form;
397         GlobalVariables.getMessageMap().clearErrorMessages();
398         boundwithForm.setSearchParams(new SearchParams());
399         boundwithForm.setBibList(null);
400         boundwithForm.setHoldingsList(null);
401         boundwithForm.setItemList(null);
402         boundwithForm.setSearchResultDisplayRowList(null);
403         boundwithForm.setPageSize(10);
404         boundwithForm.setPreviousFlag(false);
405         boundwithForm.setNextFlag(false);
406         for(SearchCondition searchCondition : boundwithForm.getSearchConditions()) {
407             searchCondition.getSearchField().setFieldName("");
408             searchCondition.getSearchField().setFieldValue("");
409         }
410         if (boundwithForm.getSearchResultDisplayRowList() != null && boundwithForm.getSearchResultDisplayRowList().size() > 0) {
411             boundwithForm.getSearchResultDisplayRowList().clear();
412         }
413         if(boundwithForm.getSearchParams() != null && boundwithForm.getSearchParams().getFacetFields() != null) {
414             boundwithForm.getSearchParams().getFacetFields().clear();
415         }
416         if(boundwithForm.getFacetResultFields() != null) {
417             boundwithForm.getFacetResultFields().clear();
418         }
419 
420         return navigate(boundwithForm, result, request, response);
421     }
422 
423     
424 
425 
426 
427 
428 
429 
430 
431     @RequestMapping(params = "methodToCall=select")
432     public ModelAndView select(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
433                                HttpServletRequest request, HttpServletResponse response) {
434         BoundwithForm boundwithForm = (BoundwithForm) form;
435         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
436         String selectedRecord = boundwithForm.getBibList().get(index).getId();
437         LOG.debug("selectedRecord--->" + selectedRecord);
438         return super.navigate(boundwithForm, result, request, response);
439     }
440 
441     
442 
443 
444 
445 
446 
447 
448     @RequestMapping(params = "methodToCall=unSelectAll")
449     public ModelAndView unSelectAll(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
450                                     HttpServletRequest request, HttpServletResponse response) {
451         BoundwithForm boundwithForm = (BoundwithForm) form;
452         
453 
454 
455 
456 
457 
458         if (!CollectionUtils.isEmpty(boundwithForm.getSearchResultDisplayRowList())) {
459             for(SearchResultDisplayRow searchResultDisplayRow : boundwithForm.getSearchResultDisplayRowList()){
460                 if(searchResultDisplayRow.isSelect()){
461                     searchResultDisplayRow.setSelect(false);
462                 }
463             }
464         }
465         return navigate(boundwithForm, result, request, response);
466     }
467 
468     
469 
470 
471 
472 
473 
474 
475     @RequestMapping(params = "methodToCall=unSelectAllFromLeftTree")
476     public ModelAndView unSelectAllFormLeftTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
477                                                 HttpServletRequest request, HttpServletResponse response) {
478         BoundwithForm boundwithForm = (BoundwithForm) form;
479         Tree<DocumentTreeNode, String> tree = boundwithForm.getLeftTree();
480         unselectDataInTree(tree);
481         return navigate(boundwithForm, result, request, response);
482     }
483 
484     private void unselectDataInTree(Tree<DocumentTreeNode, String> tree) {
485         DocumentTreeNode bibDocument;
486         Node<DocumentTreeNode, String> rootElement = tree.getRootElement();
487         List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
488         for (Node<DocumentTreeNode, String> node : list) {
489             bibDocument = node.getData();
490             LOG.info("is tree1 selected-->" + bibDocument.isSelect());
491             if (bibDocument.isSelect()) {
492                 bibDocument.setSelect(false);
493             }
494             List<Node<DocumentTreeNode, String>> childrenInstanceList = node.getChildren();
495             for (Node<DocumentTreeNode, String> instanceNode : childrenInstanceList) {
496                 bibDocument = instanceNode.getData();
497                 if (bibDocument.isSelect()) {
498                     bibDocument.setSelect(false);
499                 }
500                 List<Node<DocumentTreeNode, String>> childrenItemList = instanceNode.getChildren();
501                 for (Node<DocumentTreeNode, String> itemNode : childrenItemList) {
502                     bibDocument = itemNode.getData();
503                     if (bibDocument.isSelect()) {
504                         bibDocument.setSelect(false);
505                     }
506                 }
507 
508             }
509         }
510 
511     }
512 
513     
514 
515 
516 
517 
518 
519 
520     @RequestMapping(params = "methodToCall=unSelectAllFromRightTree")
521     public ModelAndView unSelectAllFormRightTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
522                                                  HttpServletRequest request, HttpServletResponse response) {
523         BoundwithForm boundwithForm = (BoundwithForm) form;
524         Tree<DocumentTreeNode, String> tree = boundwithForm.getRightTree();
525         unselectDataInTree(tree);
526         return navigate(boundwithForm, result, request, response);
527     }
528 
529     
530 
531 
532 
533 
534 
535 
536     @RequestMapping(params = "methodToCall=refreshLeftTree")
537     public ModelAndView refreshLeftTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
538                                         HttpServletRequest request, HttpServletResponse response) {
539         BoundwithForm boundwithForm = (BoundwithForm) form;
540         Map<String, String> uuidLeftList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.LEFT_LIST);
541         if (uuidLeftList == null) {
542             uuidLeftList = new HashMap<String, String>();
543         }
544         Collection<String> uuids = uuidLeftList.values();
545         DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
546         Node<DocumentTreeNode, String> rootNode = null;
547         try {
548             rootNode = documentSelectionTree.add(uuids, DocType.BIB.getDescription(),true);
549         } catch (SolrServerException e) {
550             
551             LOG.error("refreshLeftTree Exception:" + e);
552         }
553         boundwithForm.getLeftTree().setRootElement(rootNode);
554         return navigate(boundwithForm, result, request, response);
555     }
556 
557     
558 
559 
560 
561 
562 
563 
564     @RequestMapping(params = "methodToCall=refreshRightTree")
565     public ModelAndView refreshRightTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
566                                          HttpServletRequest request, HttpServletResponse response) {
567         BoundwithForm boundwithForm = (BoundwithForm) form;
568         Map<String, String> uuidRightList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.RIGHT_LIST);
569         if (uuidRightList == null) {
570             uuidRightList = new HashMap<String, String>();
571         }
572         Collection<String> uuids = uuidRightList.values();
573         DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
574         Node<DocumentTreeNode, String> rootNode = null;
575         try {
576             rootNode = documentSelectionTree.add(uuids, DocType.BIB.getDescription(),true);
577         } catch (SolrServerException e) {
578             
579             LOG.error("refreshRightTree Exception:" + e);
580         }
581         boundwithForm.getRightTree().setRootElement(rootNode);
582         return navigate(boundwithForm, result, request, response);
583     }
584 
585     
586 
587 
588 
589 
590 
591 
592 
593     @RequestMapping(params = "methodToCall=removeFromLeftTree")
594     public ModelAndView removeFromLeftTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
595                                            HttpServletRequest request, HttpServletResponse response) throws SolrServerException {
596         BoundwithForm boundwithForm = (BoundwithForm) form;
597         Map<String, String> uuidLeftList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.LEFT_LIST);
598         if (uuidLeftList == null) {
599             uuidLeftList = new HashMap<String, String>();
600         }
601         DocumentTreeNode bibDocument;
602         Tree<DocumentTreeNode, String> tree = boundwithForm.getLeftTree();
603         Node<DocumentTreeNode, String> rootElement = tree.getRootElement();
604         List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
605         for (Node<DocumentTreeNode, String> node : list) {
606             bibDocument = node.getData();
607             if (bibDocument.isSelect()) {
608                 uuidLeftList.remove(DocumentUniqueIDPrefix.getDocumentId(node.getNodeType()));
609             }
610         }
611         request.getSession().setAttribute(OLEConstants.LEFT_LIST, uuidLeftList);
612         Collection<String> uuids = uuidLeftList.values();
613         DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
614         Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(uuids, DocType.BIB.getDescription(),true);
615         boundwithForm.getLeftTree().setRootElement(rootNode);
616         return navigate(boundwithForm, result, request, response);
617     }
618 
619     
620 
621 
622 
623 
624 
625 
626 
627     @RequestMapping(params = "methodToCall=removeFromRightTree")
628     public ModelAndView removeFromRightTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
629                                             HttpServletRequest request, HttpServletResponse response) throws SolrServerException {
630         BoundwithForm boundwithForm = (BoundwithForm) form;
631         Map<String, String> uuidRightList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.RIGHT_LIST);
632         if (uuidRightList == null) {
633             uuidRightList = new HashMap<String, String>();
634         }
635         DocumentTreeNode bibDocument;
636         Tree<DocumentTreeNode, String> tree = boundwithForm.getRightTree();
637         Node<DocumentTreeNode, String> rootElement = tree.getRootElement();
638         List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
639         for (Node<DocumentTreeNode, String> node : list) {
640             bibDocument = node.getData();
641             if (bibDocument.isSelect()) {
642                 uuidRightList.remove(DocumentUniqueIDPrefix.getDocumentId(node.getNodeType()));
643             }
644         }
645         request.getSession().setAttribute(OLEConstants.RIGHT_LIST, uuidRightList);
646         Collection<String> uuids = uuidRightList.values();
647         DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
648         Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(uuids, DocType.BIB.getDescription(),true);
649         boundwithForm.getRightTree().setRootElement(rootNode);
650         return navigate(boundwithForm, result, request, response);
651     }
652 
653     
654 
655 
656 
657 
658 
659 
660     @RequestMapping(params = "methodToCall=selectRecords")
661     public ModelAndView selectRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
662                                       HttpServletRequest request, HttpServletResponse response) {
663         BoundwithForm boundwithForm = (BoundwithForm) form;
664         List<String> selectedRecordIds = new ArrayList<String>();
665         List<OleWorkBibDocument> oleWorkBibDocuments = boundwithForm.getWorkBibDocumentList();
666         for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocuments) {
667             if (oleWorkBibDocument.isSelect()) {
668                 selectedRecordIds.add(oleWorkBibDocument.getId());
669             }
670         }
671         return getUIFModelAndView(boundwithForm);
672     }
673 
674     
675 
676 
677 
678 
679 
680 
681 
682     @RequestMapping(params = "methodToCall=copyToTree")
683     public ModelAndView copyToTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
684                                    HttpServletRequest request, HttpServletResponse response) throws SolrServerException {
685 
686         BoundwithForm boundwithForm = (BoundwithForm) form;
687         String treeId = boundwithForm.getActionParamaterValue(OLEConstants.TREE_ID);
688         if (boundwithForm.getViewId().equalsIgnoreCase(OLEConstants.ANALYTICS_VIEW) || boundwithForm.getViewId().equalsIgnoreCase("BoundwithView")) {
689             Map<String, String> uuidLeftList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.LEFT_LIST);
690             Map<String, String> uuidRightList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.RIGHT_LIST);
691             if (!validateAnalyticsSelection(boundwithForm, uuidLeftList, uuidRightList, treeId)) {
692                 return super.navigate(boundwithForm, result, request, response);
693             }
694         }
695         copyToTree(boundwithForm, treeId, request);
696         return navigate(boundwithForm, result, request, response);
697     }
698 
699     private Boolean validateAnalyticsSelection(BoundwithForm boundwithForm, Map<String, String> uuidLeftList, Map<String, String> uuidRightList, String treeId) {
700         Collection<String> leftTreeUuids = null;
701         Collection<String> rightTreeUuids = null;
702         Collection<String> selectedRecordsUuidsList = null;
703         String docType = boundwithForm.getDocType();
704         if (StringUtils.isNotBlank(docType) && (DocType.HOLDINGS.getCode().equalsIgnoreCase(docType)
705                 || DocType.ITEM.getCode().equalsIgnoreCase(docType)
706                 || DocType.EHOLDINGS.getCode().equalsIgnoreCase(docType)
707                 || DocType.LICENSE.getCode().equalsIgnoreCase(docType))) {
708             GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.ANALYTICS_SELECTION_SECTION, OLEConstants.ERROR_SELECT_ONLY_BIBS);
709         }
710         if (treeId.equalsIgnoreCase(OLEConstants.LEFT_TREE)) {
711             if (!CollectionUtils.isEmpty(uuidLeftList)) {
712                 if (boundwithForm.getViewId().equalsIgnoreCase("BoundwithView")){
713                     GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.LEFT_TREE_SECTION, OLEConstants.ERROR_BOUNDWITH_SELECT_BIBS);
714                 } else {
715                     GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.ANALYTICS_SELECTION_SECTION, OLEConstants.ERROR_SELECT_ONLY_ONE_BIB_SERIES);
716                 }
717 
718             } else {
719                 uuidLeftList = selectedRecordsUuids(boundwithForm.getActionParamaterValue(OLEConstants.TREE_ID), boundwithForm);
720                 if (uuidLeftList.size() > 1) {
721                     if (boundwithForm.getViewId().equalsIgnoreCase("BoundwithView")){
722                         GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.LEFT_TREE_SECTION, OLEConstants.ERROR_BOUNDWITH_SELECT_BIBS);
723                     } else {
724                         GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.ANALYTICS_SELECTION_SECTION, OLEConstants.ERROR_SELECT_ONLY_ONE_BIB_SERIES);
725                     }
726                 }
727                 if (!CollectionUtils.isEmpty(uuidRightList)) {
728                     rightTreeUuids = uuidRightList.values();
729                     selectedRecordsUuidsList = selectedRecordsUuids(treeId, boundwithForm).values();
730                     for (String uuid : selectedRecordsUuidsList) {
731                         if (rightTreeUuids.contains(uuid)) {
732                             if (boundwithForm.getViewId().equalsIgnoreCase("BoundwithView")){
733                                 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.BOUNDWITH_SELECTION_SECTION, OLEConstants.ERROR_BOUNDWITH_SELECT_BIBS_TREE2);
734                             } else {
735                                 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.ANALYTICS_SELECTION_SECTION, OLEConstants.ERROR_SELECT_BIB_IS_SERIES);
736                             }
737                         }
738                     }
739                 }
740             }
741 
742         } else if (treeId.equalsIgnoreCase(OLEConstants.RIGHT_TREE) && !CollectionUtils.isEmpty(uuidLeftList)) {
743             leftTreeUuids = uuidLeftList.values();
744             selectedRecordsUuidsList = selectedRecordsUuids(treeId, boundwithForm).values();
745             for (String uuid : selectedRecordsUuidsList) {
746                 if (leftTreeUuids.contains(uuid)) {
747                     if (boundwithForm.getViewId().equalsIgnoreCase("BoundwithView")){
748                         GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.BOUNDWITH_SELECTION_SECTION, OLEConstants.ERROR_BOUNDWITH_SELECT_BIBS_TREE1);
749                     } else {
750                         GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.ANALYTICS_SELECTION_SECTION, OLEConstants.ERROR_SELECT_BIB_IS_ANALYTIC);
751                     }
752                 }
753             }
754         }
755         int errorCount = GlobalVariables.getMessageMap().getErrorCount();
756         if (errorCount > 0) {
757             return false;
758         } else {
759             return true;
760         }
761     }
762 
763     private Map<String, String> selectedRecordsUuids(String treeId, BoundwithForm boundwithForm) {
764         Map<String, String> uuidList = new HashMap<String, String>();
765         List<SearchResultDisplayRow> searchResultDisplayRowList = boundwithForm.getSearchResultDisplayRowList();
766         if (searchResultDisplayRowList != null && searchResultDisplayRowList.size() > 0) {
767             for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRowList) {
768                 if (searchResultDisplayRow.isSelect()) {
769                     if (treeId.equalsIgnoreCase(OLEConstants.LEFT_TREE)) {
770                         uuidList.put(searchResultDisplayRow.getLocalId(), searchResultDisplayRow.getLocalId());
771                     }
772                     if (treeId.equalsIgnoreCase(OLEConstants.RIGHT_TREE)) {
773                         uuidList.put(searchResultDisplayRow.getLocalId(), searchResultDisplayRow.getLocalId());
774                     }
775                 }
776             }
777         }
778         return uuidList;
779     }
780 
781     
782 
783 
784 
785 
786 
787 
788 
789     @RequestMapping(params = "methodToCall=clearTree")
790     public ModelAndView clearTree(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
791                                   HttpServletRequest request, HttpServletResponse response) throws SolrServerException {
792 
793         BoundwithForm boundwithForm = (BoundwithForm) form;
794         String treeId = boundwithForm.getActionParamaterValue(OLEConstants.TREE_ID);
795         DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
796         Map<String, String> newMap = new HashMap<String, String>();
797         Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(newMap.values(), DocType.BIB.getDescription(),true);
798         if (treeId.equalsIgnoreCase(OLEConstants.LEFT_TREE)) {
799             request.getSession().setAttribute(OLEConstants.LEFT_LIST, newMap);
800             boundwithForm.getLeftTree().setRootElement(rootNode);
801         } else if (treeId.equalsIgnoreCase(OLEConstants.RIGHT_TREE)) {
802             request.getSession().setAttribute(OLEConstants.RIGHT_LIST, newMap);
803             boundwithForm.getRightTree().setRootElement(rootNode);
804         }
805         return navigate(boundwithForm, result, request, response);
806     }
807 
808     private void copyToTree(BoundwithForm boundwithForm, String treeId, HttpServletRequest request) throws SolrServerException {
809         Collection<String> uuids = null;
810 
811         Map<String, String> uuidLeftList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.LEFT_LIST);
812 
813         if (uuidLeftList == null) {
814             uuidLeftList = new HashMap<String, String>();
815         }
816         Map<String, String> uuidRightList = (Map<String, String>) request.getSession().getAttribute(OLEConstants.RIGHT_LIST);
817 
818         if (uuidRightList == null) {
819             uuidRightList = new HashMap<String, String>();
820         }
821 
822         List<SearchResultDisplayRow> searchResultDisplayRowList = ((BoundwithForm) boundwithForm).getSearchResultDisplayRowList();
823         if (searchResultDisplayRowList != null && searchResultDisplayRowList.size() > 0) {
824             for (SearchResultDisplayRow searchResultDisplayRow : searchResultDisplayRowList) {
825                 if (searchResultDisplayRow.isSelect()) {
826                     if (treeId.equalsIgnoreCase(OLEConstants.LEFT_TREE)) {
827                         uuidLeftList.put(searchResultDisplayRow.getLocalId(), searchResultDisplayRow.getLocalId());
828                         uuids = uuidLeftList.values();
829                     }
830                     if (treeId.equalsIgnoreCase(OLEConstants.RIGHT_TREE)) {
831                         uuidRightList.put(searchResultDisplayRow.getLocalId(), searchResultDisplayRow.getLocalId());
832                         uuids = uuidRightList.values();
833                     }
834                     searchResultDisplayRow.setSelect(false);
835                 }
836             }
837 
838             request.getSession().setAttribute(OLEConstants.LEFT_LIST, uuidLeftList);
839             request.getSession().setAttribute(OLEConstants.RIGHT_LIST, uuidRightList);
840 
841             DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
842             Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(uuids, boundwithForm.getDocType(),true);
843             LOG.info("Tree id-->" + treeId);
844             if (treeId != null) {
845                 if (treeId.equalsIgnoreCase(OLEConstants.LEFT_TREE)) {
846                     boundwithForm.setShowLeftTree(true);
847                     boundwithForm.getLeftTree().setRootElement(rootNode);
848                     boundwithForm.setLabelText("select");
849                 }
850                 if (treeId.equalsIgnoreCase(OLEConstants.RIGHT_TREE)) {
851                     boundwithForm.setShowRightTree(true);
852                     boundwithForm.getRightTree().setRootElement(rootNode);
853                     boundwithForm.setTree2LabelText("select");
854                 }
855             }
856         }
857 
858     }
859 
860     
861 
862 
863 
864 
865 
866 
867 
868 
869 
870     @RequestMapping(params = "methodToCall=showBoundwithBibs")
871     public ModelAndView showBoundwithBibs(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
872                                           HttpServletRequest request, HttpServletResponse response) throws Exception {
873         BoundwithForm boundwithForm = (BoundwithForm) form;
874 
875         Tree<DocumentTreeNode, String> tree1 = boundwithForm.getLeftTree();
876         Node<DocumentTreeNode, String> rootElement = tree1.getRootElement();
877         if (rootElement != null) {
878             selectCheckedNodesForTree1(boundwithForm, rootElement);
879             boundwithForm.setShowBoundwithTree(true);
880         }
881         boundwithForm.getDocumentTreeNode().setReturnCheck(true);
882         List<String> selectedInstancesList = boundwithForm.getSelectedHoldings();
883         List<String> boundwithBibs = new ArrayList<>();
884         String holdingsId = boundwithForm.getBibTree().getHoldingsTrees().get(0).getHoldings().getId();
885         Holdings holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(holdingsId);
886         if ((selectedInstancesList.size() > 0) && (selectedInstancesList.size() > 1)) {
887             GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithTreeSection1", "error.boundwith.tree1");
888             boundwithForm.setShowBoundwithTree(false);
889         } else if ((selectedInstancesList.size() > 0) && (selectedInstancesList.size() == 1)) {
890             String locationName = null;
891             locationName = holdings.getLocationName();
892             if (locationName != null) {
893                 if (locationName.contains("<")) {
894                     GlobalVariables.getMessageMap().putInfoForSectionId("BoundwithResultsSection", "info.boundwith.success", locationName.substring(0, locationName.indexOf("<")));
895                 } else {
896                     GlobalVariables.getMessageMap().putInfoForSectionId("BoundwithResultsSection", "info.boundwith.success", locationName);
897                 }
898             }
899             boundwithForm.getDocumentTreeNode().setReturnCheck(true);
900             LOG.info("selected instance-->" + holdings.getId());
901 
902             if (holdings.isBoundWithBib()) {
903                 for (Bib bib : holdings.getBibs().getBibs()) {
904                     boundwithBibs.add(bib.getId());
905                 }
906             } else {
907                 boundwithBibs.add(holdings.getBib().getId());
908             }
909             DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
910             Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(boundwithBibs, DocType.BIB.getDescription(),true);
911             boundwithForm.getBoundwithTree().setRootElement(rootNode);
912             boundwithForm.setShowBoundwithTree(true);
913         } else {
914             GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithTreeSection1", "error.boundwith.tree1");
915             boundwithForm.setShowBoundwithTree(false);
916         }
917         boundwithForm.setSelectedHoldings(null);
918         return getUIFModelAndView(boundwithForm);
919     }
920 
921 
922 
923 
924 
925 
926 
927 
928 
929 
930 
931 
932 
933 
934 
935 
936 
937 
938 
939 
940 
941 
942 
943 
944 
945 
946 
947 
948 
949 
950 
951 
952 
953 
954 
955 
956 
957 
958 
959 
960 
961 
962 
963 
964 
965 
966 
967 
968 
969 
970 
971 
972 
973 
974 
975 
976 
977 
978 
979 
980 
981 
982 
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 
1014 
1015 
1016 
1017 
1018 
1019     
1020 
1021 
1022 
1023 
1024 
1025 
1026 
1027 
1028 
1029 
1030 
1031 
1032 
1033 
1034 
1035 
1036 
1037 
1038 
1039 
1040 
1041 
1042 
1043 
1044     
1045 
1046 
1047 
1048 
1049 
1050 
1051 
1052 
1053     @RequestMapping(params = "methodToCall=performBoundwith")
1054     public ModelAndView performBoundwith(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1055                                          HttpServletResponse httpResponse, HttpServletRequest httpServletRequest) throws Exception {
1056         BoundwithForm boundwithForm = (BoundwithForm) form;
1057         
1058 
1059 
1060 
1061 
1062         Tree<DocumentTreeNode, String> tree1 = boundwithForm.getLeftTree();
1063         Node<DocumentTreeNode, String> rootElement = tree1.getRootElement();
1064         selectCheckedNodesForTree1(boundwithForm, rootElement);
1065 
1066         Tree<DocumentTreeNode, String> tree2 = boundwithForm.getRightTree();
1067         Node<DocumentTreeNode, String> tree2RootElement = tree2.getRootElement();
1068         selectCheckedNodesForTree2(boundwithForm, tree2RootElement);
1069         boundwithForm.getDocumentTreeNode().setReturnCheck(true);
1070         String validateMsg = validateInput(boundwithForm);
1071         LOG.info("validate msg -->" + validateMsg);
1072         if (validateMsg.contains("success")) {
1073             performBoundwith(boundwithForm);
1074         } 
1075 
1076 
1077         return navigate(boundwithForm, result, httpServletRequest, httpResponse);
1078     }
1079 
1080 
1081     
1082 
1083 
1084 
1085 
1086 
1087 
1088 
1089     @RequestMapping(params = "methodToCall=unbind")
1090     public ModelAndView unbind(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1091                                HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
1092         BoundwithForm boundwithForm = (BoundwithForm) form;
1093         
1094 
1095 
1096 
1097 
1098 
1099 
1100 
1101 
1102 
1103 
1104 
1105 
1106 
1107 
1108 
1109 
1110 
1111 
1112 
1113 
1114 
1115 
1116 
1117 
1118 
1119 
1120 
1121 
1122 
1123         return getUIFModelAndView(boundwithForm);
1124     }
1125 
1126     
1127 
1128 
1129 
1130 
1131 
1132 
1133 
1134     @RequestMapping(params = "methodToCall=deleteVerify")
1135     public ModelAndView deleteVerify(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1136                                      HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
1137 
1138         BoundwithForm boundwithForm = (BoundwithForm) form;
1139         boundwithForm.setInDelete("false");
1140         Tree<DocumentTreeNode, String> boundwithTree = boundwithForm.getBoundwithTree();
1141         Node<DocumentTreeNode, String> rootElement = boundwithTree.getRootElement();
1142         selectCheckedNodesForTree1(boundwithForm, rootElement);
1143         List<String> selectedInstancesList = boundwithForm.getSelectedHoldings();
1144 
1145         if (selectedInstancesList!=null && selectedInstancesList.size() > 0) {
1146             boundwithForm.setDocCategory(DocCategory.WORK.getCode());
1147             boundwithForm.setDocType(DocType.HOLDINGS.getCode());
1148             boundwithForm.setDocFormat(DocFormat.OLEML.getCode());
1149             String deleteResponse = TransferUtil.getInstance().checkItemExistsInOleForHoldings(selectedInstancesList);
1150             LOG.info("delete response-->" + deleteResponse);
1151             boolean isBoundwith = TransferUtil.getInstance().checkItemIsBoundWith(selectedInstancesList);
1152             boundwithForm.setDeleteVerifyResponse(deleteResponse);
1153             if (!isBoundwith) {
1154                 if (boundwithForm.getDeleteVerifyResponse().equalsIgnoreCase("success")) {
1155                     boundwithForm.setInDelete("true");
1156                     DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
1157                     Node<DocumentTreeNode, String> docTree = documentSelectionTree.add(selectedInstancesList, boundwithForm.getDocType(),true);
1158                     boundwithForm.getDeleteConfirmationTree().setRootElement(docTree);
1159                 } else {
1160                     GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "error.boundwith.delete.instance");
1161                 }
1162             } else {
1163                 GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "info.boundwith.delete.failure");
1164             }
1165         }
1166 
1167 
1168         return getUIFModelAndView(boundwithForm);
1169     }
1170 
1171     
1172 
1173 
1174 
1175 
1176 
1177 
1178 
1179     @RequestMapping(params = "methodToCall=delete")
1180     public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1181                                HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
1182         BoundwithForm boundwithForm = (BoundwithForm) form;
1183         boundwithForm.setInDelete("true");
1184         DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
1185         String deleteVerifyResponse = boundwithForm.getDeleteVerifyResponse();
1186         if (deleteVerifyResponse.contains("Failed")) {
1187             GlobalVariables.getMessageMap().putInfoForSectionId("BoundwithResultsSection", "error.boundwith.delete.instance");
1188         } else if (deleteVerifyResponse.contains("success")) {
1189             List<String> selectedHoldings = boundwithForm.getSelectedHoldings();
1190             for (String id : selectedHoldings) {
1191                 getDocstoreClientLocator().getDocstoreClient().deleteHoldings(id);
1192             }
1193             Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(boundwithForm.getSelectedBibs(), DocType.BIB.getDescription(),true);
1194             boundwithForm.getBoundwithTree().setRootElement(rootNode);
1195             boundwithForm.setShowBoundwithTree(true);
1196             GlobalVariables.getMessageMap().putInfoForSectionId("BoundwithResultsSection", "info.boundwith.delete.success");
1197             boundwithForm.setInDelete("false");
1198         }
1199         return getUIFModelAndView(boundwithForm);
1200     }
1201 
1202     
1203 
1204 
1205 
1206 
1207 
1208 
1209 
1210     @RequestMapping(params = "methodToCall=selectBoundwithTreeNodes")
1211     public ModelAndView selectBoundwithTree1Nodes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1212                                                   HttpServletRequest request, HttpServletResponse response) throws Exception {
1213         BoundwithForm boundwithForm = (BoundwithForm) form;
1214         Tree<DocumentTreeNode, String> tree2 = boundwithForm.getBoundwithTree();
1215         Node<DocumentTreeNode, String> rootElement = tree2.getRootElement();
1216         selectCheckedNodesForBoundwith(boundwithForm, rootElement);
1217         return getUIFModelAndView(boundwithForm);
1218     }
1219 
1220     private void performBoundwith(BoundwithForm boundwithForm) {
1221         try {
1222             getDocstoreClientLocator().getDocstoreClient().boundWithBibs(boundwithForm.getSelectedHoldingsFromTree1().get(0), boundwithForm.getSelectedBibsFromTree2());
1223             boundwithForm.setShowBoundwithTree(true);
1224             List<String> uuidList = new ArrayList<String>();
1225             uuidList = boundwithForm.getSelectedBibs();
1226             uuidList.add(boundwithForm.getTree1BibId());
1227             DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
1228             Node<DocumentTreeNode, String> rootNode = documentSelectionTree.add(uuidList, DocType.BIB.getDescription(),true);
1229             boundwithForm.getBoundwithTree().setRootElement(rootNode);
1230             GlobalVariables.getMessageMap().putInfo("BoundwithResultsSection", "info.boundwith.success", boundwithForm.getMessage());
1231             boundwithForm.setBoundwithTreeLabelText("select");
1232         } catch (DocstoreException e) {
1233             GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection",e.getErrorCode());
1234             boundwithForm.setShowBoundwithTree(false);
1235         }
1236         catch (Exception e) {
1237             GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "error.boundwith.failed", e.getMessage());
1238             boundwithForm.setShowBoundwithTree(false);
1239         }
1240         boundwithForm.setSelectedHoldings(null);
1241         
1242         
1243 
1244     }
1245 
1246     
1247 
1248 
1249 
1250 
1251 
1252 
1253 
1254 
1255 
1256 
1257 
1258 
1259 
1260 
1261 
1262 
1263 
1264 
1265 
1266 
1267 
1268 
1269 
1270     private boolean validateBoundwithRequest(Request request) {
1271         boolean isValid = false;
1272         List<RequestDocument> requestDocumentList = request.getRequestDocuments();
1273         if ((requestDocumentList.size() > 0) && (requestDocumentList.size() == 1)) {
1274             for (RequestDocument requestDocument : requestDocumentList) {
1275                 if (requestDocument.getType().equalsIgnoreCase(DocType.INSTANCE.getCode())) {
1276                     isValid = true;
1277                 }
1278             }
1279         } else {
1280             isValid = false;
1281         }
1282         return isValid;
1283     }
1284 
1285     private String validateInput(BoundwithForm boundwithForm) {
1286         String validate = validate(boundwithForm);
1287         StringBuilder validateMsg = new StringBuilder();
1288         if(validate.startsWith("failiure")){
1289             boundwithForm.setShowBoundwithTree(false);
1290             validateMsg.append(validate);
1291             return validateMsg.toString();
1292         }else if(validate.startsWith("success")){
1293             GlobalVariables.getMessageMap().clearErrorMessages();
1294         }
1295         List<String> selectedHoldingsFromTree1 = boundwithForm.getSelectedHoldingsFromTree1();
1296         List<String> selectedBibs = boundwithForm.getSelectedBibsFromTree2();
1297         if(selectedHoldingsFromTree1!=null && selectedBibs!=null){
1298             if ((selectedHoldingsFromTree1.size() > 0) && (selectedHoldingsFromTree1.size() == 1)) {
1299                 List<Item> items = boundwithForm.getBibTree().getHoldingsTrees().get(0).getItems();
1300                 if (items.size() > 1) {
1301                     GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "error.boundwith.more.items.failure");
1302                 } else if (selectedBibs.size() > 0) {
1303                     validateMsg.append("success");
1304                 } else {
1305                     
1306                 }
1307             } else {
1308                 GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "error.boundwith.tree1");
1309             }
1310         }
1311         return validateMsg.toString();
1312     }
1313 
1314    
1315 
1316 
1317 
1318 
1319 
1320 
1321 
1322 
1323 
1324 
1325 
1326 
1327 
1328 
1329 
1330 
1331 
1332 
1333     
1334 
1335 
1336 
1337 
1338 
1339 
1340 
1341 
1342 
1343 
1344 
1345 
1346 
1347 
1348 
1349 
1350 
1351 
1352 
1353 
1354 
1355 
1356 
1357 
1358 
1359 
1360 
1361 
1362 
1363 
1364 
1365 
1366 
1367 
1368 
1369 
1370 
1371 
1372 
1373 
1374 
1375 
1376 
1377 
1378 
1379 
1380 
1381 
1382 
1383 
1384 
1385 
1386 
1387 
1388 
1389 
1390 
1391 
1392 
1393 
1394 
1395 
1396 
1397     
1398 
1399 
1400 
1401 
1402 
1403 
1404 
1405 
1406 
1407 
1408 
1409 
1410 
1411 
1412 
1413 
1414 
1415 
1416 
1417 
1418 
1419 
1420 
1421 
1422 
1423 
1424 
1425 
1426 
1427 
1428 
1429 
1430 
1431     private void selectCheckedNodesForTree1(BoundwithForm boundwithForm, Node<DocumentTreeNode, String> rootElement) {
1432         DocumentTreeNode documentTreeNode;
1433         BibTree bibTree = new BibTree();
1434         HoldingsTree holdingsTree = new HoldingsTree();
1435         Holdings holdings = new Holdings();
1436         Set<String> selectedBibsList = new HashSet<String>();
1437         List<String> selectedBibs = new ArrayList<String>();
1438         List<String> selectedBibsFromTree1 = new ArrayList<String>();
1439         List<String> selectedInstancesList = new ArrayList<String>();
1440         List<String> selectedHoldings = new ArrayList<String>();
1441         List<String> selectedHoldingsFromTree1 = new ArrayList<String>();
1442         String tree1BibId = null;
1443         Bib bib = new Bib();
1444         List<Item> items = new ArrayList<Item>();
1445         List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
1446         for (Node<DocumentTreeNode, String> bibNode : list) {
1447             documentTreeNode = bibNode.getData();
1448             LOG.info("documentTreeNode.isSelectTree1()-->" + documentTreeNode.isSelect());
1449             if (documentTreeNode.isSelect()) {
1450                 GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "error.select.instance");
1451             } else {
1452                 List<Node<DocumentTreeNode, String>> instanceList = bibNode.getChildren();
1453                 for (Node<DocumentTreeNode, String> instance : instanceList) {
1454                     documentTreeNode = instance.getData();
1455                     LOG.info("node1.getData()-->" + instance.getData().getTitle());
1456                     if (documentTreeNode.isSelect()) {
1457                         bib.setId(bibNode.getNodeType());
1458                         selectedBibsList.add(bibNode.getNodeType());
1459                         selectedBibs.add(bibNode.getNodeType());
1460                         selectedBibsFromTree1.add(bibNode.getNodeType());
1461                         bib.setTitle(bibNode.getNodeLabel());
1462                         tree1BibId = bibNode.getNodeType();
1463                         boundwithForm.setTree1BibId(tree1BibId);
1464                         LOG.info("documentTreeNode.isSelectTree1() in else-->" + documentTreeNode.isSelect());
1465                         LOG.info("inst id-->" + instance.getNodeType());
1466                         holdings.setId(instance.getNodeType());
1467                         selectedInstancesList.add(instance.getNodeType());
1468                         selectedHoldings.add(instance.getNodeType());
1469                         selectedHoldingsFromTree1.add(instance.getNodeType());
1470                         holdings.setLocationName(instance.getNodeLabel());
1471                         boundwithForm.setMessage(instance.getNodeLabel());
1472                         documentTreeNode.setSelect(true);
1473                         List<Node<DocumentTreeNode, String>> itemList = instance.getChildren();
1474                         for (Node<DocumentTreeNode, String> item : itemList) {
1475                             Item itemDoc = new Item();
1476                             documentTreeNode = item.getData();
1477                             itemDoc.setId(item.getNodeType());
1478                             itemDoc.setCallNumber(item.getNodeLabel());
1479                             documentTreeNode.setSelect(true);
1480                             items.add(itemDoc);
1481                         }
1482                         holdingsTree.getItems().addAll(items);
1483                         holdingsTree.setHoldings(holdings);
1484                         bibTree.getHoldingsTrees().add(holdingsTree);
1485                         bibTree.setBib(bib);
1486                         boundwithForm.setBibTree(bibTree);
1487                         boundwithForm.setSelectedBibsList(selectedBibsList);
1488                         boundwithForm.setSelectedInstancesList(selectedInstancesList);
1489                         boundwithForm.setSelectedBibs(selectedBibs);
1490                         boundwithForm.setSelectedHoldings(selectedHoldings);
1491                         boundwithForm.setSelectedBibsFromTree1(selectedBibs);
1492                         boundwithForm.setSelectedHoldingsFromTree1(selectedHoldings);
1493                     }
1494                 }
1495             }
1496         }
1497     }
1498 
1499     private String validate(BoundwithForm boundwithForm){
1500         String string = new String();
1501         Tree<DocumentTreeNode, String> leftTree = boundwithForm.getLeftTree();
1502         DocumentTreeNode documentTreeNode;
1503         int count = 0;
1504         List<Node<DocumentTreeNode, String>> list = leftTree.getRootElement().getChildren();
1505         for (Node<DocumentTreeNode, String> bibNode : list) {
1506             documentTreeNode = bibNode.getData();
1507             
1508             
1509 
1510 
1511 
1512                 List<Node<DocumentTreeNode, String>> instanceList = bibNode.getChildren();
1513                 for (Node<DocumentTreeNode, String> instance : instanceList) {
1514                     documentTreeNode = instance.getData();
1515                     if(documentTreeNode.isSelect()){
1516                         count++;
1517                     }
1518                     
1519 
1520 
1521 
1522 
1523 
1524 
1525 
1526 
1527 
1528 
1529 
1530 
1531 
1532 
1533 
1534 
1535                 }
1536             if(count==0){
1537                 GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "error.select.instance");
1538                 string = new String("failiure");
1539             }
1540             
1541         }
1542         List<Node<DocumentTreeNode, String>> rightlist = boundwithForm.getRightTree().getRootElement().getChildren();
1543         count = 0;
1544         for (Node<DocumentTreeNode, String> bibNode : rightlist) {
1545             documentTreeNode = bibNode.getData();
1546             if (documentTreeNode.isSelect()) {
1547                 count ++;
1548             }
1549         }
1550         if(count == 0) {
1551             GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithResultsSection", "error.boundwith.select.bib");
1552             string = new String("failiure");
1553         }
1554         return string;
1555     }
1556 
1557 
1558     private void selectCheckedNodesForTree2(BoundwithForm boundwithForm, Node<DocumentTreeNode, String> rootElement) {
1559         DocumentTreeNode documentTreeNode;
1560         BibTree bibTree = new BibTree();
1561         HoldingsTree holdingsTree = new HoldingsTree();
1562         Set<String> selectedBibsList = new HashSet<String>();
1563         ArrayList<String> setSelectedBibsFromTree2 = new ArrayList<String>();
1564         ArrayList<String> selectedBibs = new ArrayList<String>();
1565         if(rootElement!=null){
1566             List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
1567             for (Node<DocumentTreeNode, String> node : list) {
1568                 documentTreeNode = node.getData();
1569                 LOG.info("documentTreeNode.isSelect()-->" + documentTreeNode.isSelect());
1570                 if (documentTreeNode.isSelect()) {
1571                     Bib bib = new Bib();
1572                     Holdings holdings = new Holdings();
1573                     List<Item> items = new ArrayList<Item>();
1574                     bib.setId(node.getNodeType());
1575                     selectedBibsList.add(node.getNodeType());
1576                     selectedBibs.add(node.getNodeType());
1577                     setSelectedBibsFromTree2.add(node.getNodeType());
1578                     bib.setTitle(node.getNodeLabel());
1579                     List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
1580                     for (Node<DocumentTreeNode, String> subNode : childrenList) {
1581                         documentTreeNode = subNode.getData();
1582                         holdings.setId(subNode.getNodeType());
1583                         documentTreeNode.setSelect(true);
1584                         holdings.setLocationName(subNode.getNodeLabel());
1585                         List<Node<DocumentTreeNode, String>> childrenList1 = subNode.getChildren();
1586                         for (Node<DocumentTreeNode, String> subNode1 : childrenList1) {
1587                             Item item = new Item();
1588                             documentTreeNode = subNode1.getData();
1589                             item.setId(subNode1.getNodeType());
1590                             item.setCallNumber(subNode1.getNodeLabel());
1591                             items.add(item);
1592                             documentTreeNode.setSelect(true);
1593                         }
1594                     }
1595                     boundwithForm.setSelectedBibsList(selectedBibsList);
1596                     boundwithForm.setSelectedBibsFromTree2(setSelectedBibsFromTree2);
1597                     boundwithForm.setSelectedBibs(selectedBibs);
1598                     holdingsTree.getItems().addAll(items);
1599                     holdingsTree.setHoldings(holdings);
1600                     bibTree.getHoldingsTrees().add(holdingsTree);
1601                     bibTree.setBib(bib);
1602                 } else {
1603                     List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
1604                     for (Node<DocumentTreeNode, String> node1 : childrenList) {
1605                         documentTreeNode = node1.getData();
1606                         if (documentTreeNode.isSelect()) {
1607                             List<Node<DocumentTreeNode, String>> childrenList1 = node1.getChildren();
1608                             for (Node<DocumentTreeNode, String> subNode : childrenList1) {
1609                                 documentTreeNode = subNode.getData();
1610                                 documentTreeNode.setSelect(true);
1611 
1612                             }
1613                         }
1614                     }
1615                 }
1616             }
1617         }
1618     }
1619 
1620     private void selectCheckedNodesForBoundwith(BoundwithForm boundwithForm, Node<DocumentTreeNode, String> rootElement) {
1621         DocumentTreeNode documentTreeNode;
1622         List<String> selectedInstancesList = new ArrayList<String>();
1623         Set<String> selectedBibsList = new HashSet<String>();
1624         List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
1625         for (Node<DocumentTreeNode, String> node : list) {
1626             documentTreeNode = node.getData();
1627             if (documentTreeNode.isSelect()) {
1628                 GlobalVariables.getMessageMap().putErrorForSectionId("BoundwithTreeSection1", "error.select.node.instance");
1629 
1630             } else {
1631                 List<Node<DocumentTreeNode, String>> childrenList = node.getChildren();
1632                 for (Node<DocumentTreeNode, String> node1 : childrenList) {
1633                     documentTreeNode = node1.getData();
1634 
1635                     if (documentTreeNode.isSelect()) {
1636                         LOG.info("documentTreeNode.isSelectboundwithTree() in else-->" + documentTreeNode.isSelect());
1637                         selectedBibsList.add(node.getNodeType());
1638                         selectedInstancesList.add(node1.getNodeType());
1639                         boundwithForm.setSelectedBibsList(selectedBibsList);
1640                         boundwithForm.setSelectedInstancesList(selectedInstancesList);
1641                         documentTreeNode.setSelect(true);
1642                         List<Node<DocumentTreeNode, String>> childrenList1 = node1.getChildren();
1643                         for (Node<DocumentTreeNode, String> subNode : childrenList1) {
1644                             documentTreeNode = subNode.getData();
1645                             documentTreeNode.setSelect(true);
1646 
1647                         }
1648                     }
1649                 }
1650             }
1651         }
1652     }
1653 
1654     
1655 
1656 
1657 
1658 
1659 
1660 
1661     public SearchResultDisplayFields getDisplayFields(BoundwithForm boundwithForm) {
1662         SearchResultDisplayFields searchResultDisplayFields = new SearchResultDisplayFields();
1663         searchResultDisplayFields.buildSearchResultDisplayFields(documentSearchConfig.getDocTypeConfigs(),boundwithForm.getDocType());
1664         return searchResultDisplayFields;
1665     }
1666 
1667     public void setPageNextPreviousAndEntriesInfo(BoundwithForm boundwithForm) {
1668         this.totalRecCount = boundwithForm.getSearchResponse().getTotalRecordCount();
1669         this.start = boundwithForm.getSearchResponse().getStartIndex();
1670         this.pageSize = boundwithForm.getSearchResponse().getPageSize();
1671         boundwithForm.setPreviousFlag(getWorkbenchPreviousFlag());
1672         boundwithForm.setNextFlag(getWorkbenchNextFlag());
1673         boundwithForm.setPageShowEntries(getWorkbenchPageShowEntries());
1674     }
1675 
1676     @RequestMapping(params = "methodToCall=facetSearch")
1677     public ModelAndView facetSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1678                                     HttpServletRequest request, HttpServletResponse response) {
1679         BoundwithForm boundwithForm = (BoundwithForm) form;
1680         String docType = request.getParameter("docType");
1681         String selectedFacet = request.getParameter("selectedFacet");
1682         String selectedFacetName = request.getParameter("selectedFacetName");
1683         boundwithForm.setDocType(docType);
1684         if(boundwithForm.getSearchParams() == null) {
1685             SearchParams searchParams = (SearchParams) request.getSession().getAttribute("searchParams");
1686             boundwithForm.setSearchParams(searchParams);
1687         }
1688         boundwithForm.getSearchParams().getFacetFields().addAll(getFacetFields(boundwithForm.getDocType()));
1689         boundwithForm.getSearchParams().setFacetPrefix("");
1690         boundwithForm.getSearchParams().setFacetLimit(documentSearchConfig.getFacetPageSizeShort());
1691         FacetCondition facetCondition = new FacetCondition();
1692         facetCondition.setFieldName(selectedFacetName);
1693         facetCondition.setFieldValue(selectedFacet);
1694         boundwithForm.getSearchParams().getFacetConditions().add(facetCondition);
1695         boundwithForm.setSearchType("search");
1696         GlobalVariables.getMessageMap().clearErrorMessages();
1697         return search(boundwithForm, result, request, response);
1698     }
1699     public Set<String> getFacetFields(String docType) {
1700         Set<String> facetFields = new TreeSet<String>();
1701         for(DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
1702             if(docTypeConfig.getName().equalsIgnoreCase(docType)) {
1703                 for( DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
1704                     if(docFormatConfig.getName().equalsIgnoreCase(org.kuali.ole.docstore.common.document.content.enums.DocFormat.MARC.getCode())) {
1705                         for(DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
1706                             if (docFieldConfig.getName().endsWith("_facet") && docFieldConfig.getDocType().getName().equalsIgnoreCase(docType)) {
1707                                 facetFields.add(docFieldConfig.getName());
1708                             }
1709                         }
1710                     }
1711                 }
1712             }
1713         }
1714         return facetFields;
1715     }
1716 
1717 
1718 @RequestMapping(params = "methodToCall=addLineField")
1719 public ModelAndView addLineField(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1720                                  HttpServletRequest request, HttpServletResponse response) {
1721 
1722     String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
1723     if (StringUtils.isBlank(selectedCollectionPath)) {
1724         throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
1725     }
1726     BoundwithForm boundwithForm = (BoundwithForm) uifForm;
1727     int index = Integer.parseInt(boundwithForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1728     if(boundwithForm.getSearchConditions().get(index).getSearchField().getFieldName().isEmpty()&&
1729             boundwithForm.getSearchConditions().get(index).getSearchField().getFieldValue().isEmpty()){
1730         return getUIFModelAndView(uifForm);
1731     }
1732     List<SearchCondition> searchConditions = boundwithForm.getSearchConditions();
1733     index++;
1734     SearchCondition searchCondition=new SearchCondition();
1735     searchCondition.setOperator("AND");
1736     searchConditions.add(index,searchCondition);
1737     return getUIFModelAndView(uifForm);
1738 }
1739 
1740     @RequestMapping(params = "methodToCall=deleteLineField")
1741     public ModelAndView deleteLineField(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1742                                         HttpServletRequest request, HttpServletResponse response) {
1743 
1744         String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
1745         if (StringUtils.isBlank(selectedCollectionPath)) {
1746             throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
1747         }
1748         BoundwithForm boundwithForm = (BoundwithForm) uifForm;
1749         int index = Integer.parseInt(boundwithForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1750         List<SearchCondition> searchConditions = boundwithForm.getSearchConditions();
1751         if (searchConditions.size() > 1) {
1752             searchConditions.remove(index);
1753         }
1754         return getUIFModelAndView(uifForm);
1755     }
1756 
1757 }