View Javadoc

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