View Javadoc

1   package org.kuali.ole.describe.controller;
2   
3   import com.google.common.base.Joiner;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.describe.bo.BoundwithSelection;
6   import org.kuali.ole.describe.bo.DocumentSelectionTree;
7   import org.kuali.ole.describe.bo.DocumentTreeNode;
8   import org.kuali.ole.describe.bo.TransferRightToLeft;
9   import org.kuali.ole.describe.form.BoundwithForm;
10  import org.kuali.ole.docstore.common.document.BibTree;
11  import org.kuali.ole.docstore.common.document.Holdings;
12  import org.kuali.ole.docstore.common.exception.DocstoreException;
13  import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
14  import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
15  import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
16  import org.kuali.ole.select.util.TransferUtil;
17  import org.kuali.rice.core.api.util.tree.Node;
18  import org.kuali.rice.core.api.util.tree.Tree;
19  import org.kuali.rice.krad.util.GlobalVariables;
20  import org.kuali.rice.krad.util.KRADConstants;
21  import org.kuali.rice.krad.web.form.UifFormBase;
22  import org.springframework.stereotype.Controller;
23  import org.springframework.validation.BindingResult;
24  import org.springframework.web.bind.annotation.ModelAttribute;
25  import org.springframework.web.bind.annotation.RequestMapping;
26  import org.springframework.web.servlet.ModelAndView;
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  import java.util.ArrayList;
30  import java.util.HashMap;
31  import java.util.List;
32  
33  /**
34   * Created with IntelliJ IDEA.
35   * User: ?
36   * Date: 12/29/12
37   * Time: 12:03 PM
38   * To change this template use File | Settings | File Templates.
39   */
40  @Controller
41  @RequestMapping(value = "/transferController")
42  public class TransferController
43          extends BoundwithController {
44      private static final Logger LOG = Logger.getLogger(TransferController.class);
45  
46      @Override
47      @RequestMapping(params = "methodToCall=start")
48      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
49                                HttpServletRequest request, HttpServletResponse response) {
50          LOG.debug("Inside the workbenchForm--TransferController start method");
51          if (request.getSession().getAttribute("LeftList") != null && request.getSession().getAttribute("RightList") != null) {
52              request.getSession().removeAttribute("LeftList");
53              request.getSession().removeAttribute("RightList");
54          }
55          return super.start(form, result, request, response);
56      }
57  
58  
59      @RequestMapping(params = "methodToCall=selectRootNodeItems")
60      public ModelAndView selectRootNodeItems(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
61                                              HttpServletRequest request, HttpServletResponse response) throws Exception {
62          List<String> bibIdentifierListForTree1 = new ArrayList<String>();
63          List<String> bibInstanceListForTree1 = new ArrayList<String>();
64          List<String> bibItemListForTree1 = new ArrayList<String>();
65          List<String> bibIdentifierListForTree2 = new ArrayList<String>();
66          List<String> destBibIdentifierListForTree2 = new ArrayList<String>();
67          List<String> destInstanceIdentifierListForTree2 = new ArrayList<String>();
68          List<String> itemsSelectedListForRightTree = new ArrayList<String>();
69          List<String> bibIdentifiersSelectedListForLeftTree = new ArrayList<String>();
70          List<String> bibIdentifiersListWhenInstanceSelectedForLeftTree = new ArrayList<String>();
71          List<String> instanceIdentifiersToDelete = new ArrayList<String>();
72          boolean transferInstance = true;
73          //  StringBuffer stringBufferLeftTree=new StringBuffer();
74          //StringBuffer stringBufferRightTree=new StringBuffer();
75  
76          //String isLeftBibsSelected="false";
77          //String isRightItemsSelected="false";
78          String status1 = "";
79          String status2 = "";
80  
81          BoundwithForm transferForm = (BoundwithForm) form;
82          /*boolean hasPermission = performTransferHoldingOrItem(GlobalVariables.getUserSession().getPrincipalId());
83          if (!hasPermission) {
84              //transferForm.setMessage("<font size='3' color='red'> Current user is not authorized to perform this action.</font>");
85              GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection1", "info.authorization");
86              return navigate(transferForm, result, request, response);
87          }*/
88          transferForm.setTransferLeftTree(true);
89          transferForm.setTransferRighttree(false);
90          //transferForm.setInDelete("false");
91          transferForm.setInDeleteLeftTree("false");
92          transferForm.setInDeleteRightTree("false");
93          // List<OleWorkBibDocument>  oleWorkBibDocumentList=transferForm.getWorkBibDocumentList();
94          Tree<DocumentTreeNode, String> leftTree = transferForm.getLeftTree();
95          Node<DocumentTreeNode, String> leftTreeRootElement = leftTree.getRootElement();
96          Tree<DocumentTreeNode, String> rightTree = transferForm.getRightTree();
97          Node<DocumentTreeNode, String> rightTreeRootElement = rightTree.getRootElement();
98          List<String> bibIdentifiersToDelete = new ArrayList<String>();
99          String deleteResponseFromDocStore = "";
100 
101         status1 = selectCheckedNodesTree1(leftTreeRootElement, bibIdentifierListForTree1, bibInstanceListForTree1,
102                 bibItemListForTree1, bibIdentifiersSelectedListForLeftTree,
103                 bibIdentifiersListWhenInstanceSelectedForLeftTree, bibIdentifiersToDelete,
104                 instanceIdentifiersToDelete);
105         selectCheckedNodesTree2(rightTreeRootElement, bibIdentifierListForTree2, itemsSelectedListForRightTree,
106                 destBibIdentifierListForTree2, destInstanceIdentifierListForTree2);
107         LOG.debug("bibIdentifiersToDelete " + bibIdentifiersToDelete);
108 
109         //  isLeftBibsSelected= stringBufferLeftTree.toString();
110         //
111         if (leftTreeRootElement == null) {
112             //transferForm.setMessage("No records copied for left tree");
113             //GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO,"error.transfer.empty.records", "right");
114             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection1", "error.transfer.empty.records", "left");
115         } else if (rightTreeRootElement == null) {
116             //transferForm.setMessage("No records copied for right tree");
117             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.empty.records", "right");
118         } else if (bibIdentifiersSelectedListForLeftTree.size() > 0) {
119             //transferForm.setMessage("Bib(s) selected in Left Tree which is invalid");
120             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection1", "error.transfer.invalid", "Bib", "left");
121         } else if (bibInstanceListForTree1.size() == 0 && bibItemListForTree1.size() == 0) {
122             //transferForm.setMessage("Nothing selected in left tree");
123             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection1", "error.transfer.selected.none", "left");
124         } else if (itemsSelectedListForRightTree.size() > 0) {
125             //transferForm.setMessage("Item(s) selected in Right Tree which is invalid");
126             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.invalid", "Item", "right");
127         } else if (destBibIdentifierListForTree2.size() == 0 && destInstanceIdentifierListForTree2.size() == 0) {
128             //transferForm.setMessage("Nothing selected in right tree");
129             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.selected.none", "right");
130         } else if (bibInstanceListForTree1.size() > 0 && bibItemListForTree1.size() > 0) {
131             //transferForm.setMessage("Instances and items both selected in left tree: Transfer failed");
132             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection1", "error.transfer.selected.multiple", "Instances", "items", "left");
133         } else if (destBibIdentifierListForTree2.size() > 0 && destInstanceIdentifierListForTree2.size() > 0) {
134             //transferForm.setMessage("Bibs and instances both selected in right tree: Transfer failed");
135             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.selected.multiple", "Bibs", "instances", "right");
136         } else if (destBibIdentifierListForTree2.size() > 1) {
137             //transferForm.setMessage("Only one bib can be selected in right tree");
138             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.selected.invalid", "bib", "right");
139         } else if (destInstanceIdentifierListForTree2.size() > 1) {
140             //transferForm.setMessage("Only one instance can be selected in right tree");
141             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.selected.invalid", "instance", "right");
142         } else if (bibInstanceListForTree1.size() > 0 && destInstanceIdentifierListForTree2.size() > 0) {
143             //transferForm.setMessage("Instances of left tree cant be transferred to instances of right tree: Transfer failed");
144             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection1", "error.transfer.left", "Instances", "Instances");
145         } else if (bibItemListForTree1.size() > 0 && destBibIdentifierListForTree2.size() > 0) {
146             //transferForm.setMessage("Items of left tree cant be transferred to Bibs of right tree: Transfer failed");
147             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection1", "error.transfer.left", "Items", "Bibs");
148         }
149         //        else if(!status1.equalsIgnoreCase("success")){
150         //            System.out.println("in if checking status1");
151         //             transferForm.setMessage(status1);
152         //        }
153         else if (bibInstanceListForTree1.size() > 0) {
154             for (String bibUuid : bibIdentifiersListWhenInstanceSelectedForLeftTree) {
155                 if (destBibIdentifierListForTree2.contains(bibUuid)) {
156                     //transferForm.setMessage("Transfer of instances should not happen between same left bib and right bib. Transfer of instances failed");
157                     GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.bib");
158                     transferInstance = false;
159                     break;
160                 }
161             }
162             if (transferInstance) {
163                 String destBibIdentifier = destBibIdentifierListForTree2.get(0);
164                 if (bibIdentifiersToDelete.size() > 0) {
165                     transferForm.setDocFormat("marc");
166                     transferForm.setDocCategory("work");
167                     transferForm.setDocType("bibliographic");
168 //                    String bibIdentifiers = Joiner.on(",").join(bibIdentifiersToDelete);
169 //                    deleteResponseFromDocStore = TransferUtil.getInstance().getDeleteResponseFromDocStore("deleteVerify", bibIdentifiers,
170 //                            transferForm);
171                     transferForm.setBibInstanceListForTree1(bibInstanceListForTree1);
172                     transferForm.setDestBibIdentifier(destBibIdentifier);
173 //                    transferForm.setDeleteVerifyResponse(deleteResponseFromDocStore);
174 //                    TransferUtil.getInstance().deleteVerify(transferForm, deleteResponseFromDocStore);
175 
176                     transferForm.setDeleteVerifyResponse(TransferUtil.getInstance().checkItemExistsInOleForBibs(bibIdentifiersToDelete));
177                     transferForm.setDeleteIds(bibIdentifiersToDelete);
178                     TransferUtil.getInstance().deleteVerify(transferForm, bibIdentifiersToDelete);
179                     return getUIFModelAndView(transferForm);
180                 }
181                 TransferUtil.getInstance().transferInstances(bibInstanceListForTree1, destBibIdentifier);
182                 TransferUtil.getInstance().copyToTree(transferForm, bibIdentifierListForTree1, "leftTree");
183                 TransferUtil.getInstance().copyToTree(transferForm, bibIdentifierListForTree2, "rightTree");
184                 //transferForm.setMessage("Instances transferred successfully");
185                 GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer", "Instances");
186             }
187         } else if (bibItemListForTree1.size() > 0) {
188             String destInstanceIdentifier = destInstanceIdentifierListForTree2.get(0);
189             if (instanceIdentifiersToDelete.size() > 0) {
190                 transferForm.setDocFormat("oleml");
191                 transferForm.setDocCategory("work");
192                 transferForm.setDocType("holdings");
193 //                String instanceIdentifiers = Joiner.on(",").join(instanceIdentifiersToDelete);
194 //                deleteResponseFromDocStore = TransferUtil.getInstance().getDeleteResponseFromDocStore("deleteVerify", instanceIdentifiers,
195 //                        transferForm);
196                 transferForm.setBibItemListForTree1(bibItemListForTree1);
197                 transferForm.setDestInstanceIdentifier(destInstanceIdentifier);
198 //                transferForm.setDeleteVerifyResponse(deleteResponseFromDocStore);
199 //                TransferUtil.getInstance().deleteVerify(transferForm, deleteResponseFromDocStore);
200                 transferForm.setDeleteVerifyResponse(TransferUtil.getInstance().checkItemExistsInOleForHoldings(instanceIdentifiersToDelete));
201                 transferForm.setDeleteIds(instanceIdentifiersToDelete);
202                 TransferUtil.getInstance().deleteVerify(transferForm, instanceIdentifiersToDelete);
203                 return getUIFModelAndView(transferForm);
204                 //return deleteVerify(transferForm, deleteResponseFromDocStore);
205             }
206             TransferUtil.getInstance().transferItems(bibItemListForTree1, destInstanceIdentifier);
207             TransferUtil.getInstance().copyToTree(transferForm, bibIdentifierListForTree1, "leftTree");
208             TransferUtil.getInstance().copyToTree(transferForm, bibIdentifierListForTree2, "rightTree");
209             //transferForm.setMessage("Items transferred successfully");
210             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer", "Items");
211         } else {
212             //transferForm.setMessage("Nothing selected or Selection is wrong");
213             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "error.transfer.bib");
214         }
215         return navigate(transferForm, result, request, response);
216         //        return getUIFModelAndView(transferForm);
217     }
218 
219 //    public void delete(ResponseDocument responseDocument) {
220 //    }
221 
222     @RequestMapping(params = "methodToCall=transferRightToLeft")
223     public ModelAndView transferRightToLeft(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
224                                             HttpServletRequest request, HttpServletResponse response) throws Exception {
225         BoundwithForm transferForm = (BoundwithForm) form;
226         /*boolean hasPermission = performTransferHoldingOrItem(GlobalVariables.getUserSession().getPrincipalId());
227         if (!hasPermission) {
228             //transferForm.setMessage("<font size='3' color='red'> Current user is not authorized to perform this action.</font>");
229             GlobalVariables.getMessageMap().putErrorForSectionId("TransferTreeSection2", "info.authorization");
230             return navigate(transferForm, result, request, response);
231         }*/
232         transferForm.setInDeleteLeftTree("false");
233         transferForm.setInDeleteRightTree("false");
234         transferForm.setTransferLeftTree(false);
235         transferForm.setTransferRighttree(true);
236         TransferRightToLeft transferRightToLeft = new TransferRightToLeft();
237         transferRightToLeft.transferRightToLeft(transferForm, result, request, response);
238         return navigate(transferForm, result, request, response);
239         //        return getUIFModelAndView(transferForm);
240     }
241 
242     private String selectCheckedNodesTree1(Node<DocumentTreeNode, String> rootElement,
243                                            List<String> bibIdentifierListForTree1, List<String> bibInstanceListForTree1,
244                                            List<String> bibItemListForTree1,
245                                            List<String> bibIdentifiersSelectedListForLeftTree,
246                                            List<String> bibIdentifiersListWhenInstanceSelectedForLeftTree,
247                                            List<String> bibIdentifiersToDelete,
248                                            List<String> instanceIdentifiersToDelete) {
249 
250         BoundwithSelection boundwithSelection;
251         DocumentTreeNode documentTreeNode;
252         String status = "success";
253         String bibTitle = "";
254         int instanceCount = 0;
255         int itemCount = 0;
256         List<String> instanceidenifiersListTemp = new ArrayList<String>();
257         if (rootElement != null) {
258             List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
259             for (Node<DocumentTreeNode, String> marcNode : list) {
260                 instanceCount = 0;
261                 itemCount = 0;
262                 String instanceUUID = "";
263                 documentTreeNode = marcNode.getData();
264 
265                 bibTitle = documentTreeNode.getTitle();
266                 String bibUUID = marcNode.getNodeType();
267                 bibIdentifierListForTree1.add(bibUUID);
268                 LOG.info("documentTreeNode.isSelectTree1()-->" + documentTreeNode.isSelect());
269                 if (documentTreeNode.isSelect()) {
270                     bibIdentifiersSelectedListForLeftTree.add(bibUUID);
271                     break;
272                 }
273                 List<Node<DocumentTreeNode, String>> instanceList = marcNode.getChildren();
274                 List<Node<DocumentTreeNode, String>> itemList = null;
275                 instanceidenifiersListTemp.clear();
276                 for (Node<DocumentTreeNode, String> instanceNode : instanceList) {
277                     itemCount = 0;
278                     documentTreeNode = instanceNode.getData();
279                     instanceUUID = instanceNode.getNodeType();
280                     LOG.debug("instanceUUID out of select " + instanceUUID);
281                     if (documentTreeNode.isSelect()) {
282                         instanceCount++;
283 
284                         LOG.debug("instanceUUID " + instanceUUID);
285                         bibInstanceListForTree1.add(instanceUUID);
286                         //instanceidenifiersListTemp.add(instanceUUID);
287                         bibIdentifiersListWhenInstanceSelectedForLeftTree.add(bibUUID);
288                     }
289                     itemList = instanceNode.getChildren();
290                     for (Node<DocumentTreeNode, String> itemNode : itemList) {
291                         documentTreeNode = itemNode.getData();
292                         if (documentTreeNode.isSelect()) {
293                             itemCount++;
294                             String itemUUID = itemNode.getNodeType();
295                             LOG.debug("itemUUID " + itemUUID);
296                             bibItemListForTree1.add(itemUUID);
297                         }
298                     }  //item loop end
299                     if (instanceNode.getNumberOfChildren() > 0 && itemCount == itemList.size()) {
300                         instanceidenifiersListTemp.add(instanceUUID);
301                         //status="Instance will remain with no items if this transfer takes place. Instance must have atleast one item. Transfer failed";
302                     }
303                 } //instance loop end
304                 if (marcNode.getNumberOfChildren() > 0 && instanceCount == instanceList.size()) {
305                     bibIdentifiersToDelete.add(bibUUID);
306                     LOG.debug("in if of no instances bibIdentifierToDelete " + bibIdentifiersToDelete);
307                 }
308                 instanceIdentifiersToDelete.addAll(instanceidenifiersListTemp);
309             }  //bib loop end
310         }
311         return status;
312     }
313 
314 
315     private void selectCheckedNodesTree2(Node<DocumentTreeNode, String> rootElement,
316                                          List<String> bibIdentifierListForTree2,
317                                          List<String> itemsSelectedListForRightTree,
318                                          List<String> destBibIdentifierListForTree2,
319                                          List<String> destInstanceIdentifierListForTree2) {
320 
321         BoundwithSelection boundwithSelection;
322         DocumentTreeNode documentTreeNode;
323         if (rootElement != null) {
324             List<Node<DocumentTreeNode, String>> list = rootElement.getChildren();
325             for (Node<DocumentTreeNode, String> marcNode : list) {
326                 documentTreeNode = marcNode.getData();
327                 String bibUUID = marcNode.getNodeType();
328                 bibIdentifierListForTree2.add(bibUUID);
329                 LOG.info("documentTreeNode.isSelectTree1()-->" + documentTreeNode.isSelect());
330                 if (documentTreeNode.isSelect()) {
331                     destBibIdentifierListForTree2.add(bibUUID);
332                 }
333                 List<Node<DocumentTreeNode, String>> instanceList = marcNode.getChildren();
334                 for (Node<DocumentTreeNode, String> instanceNode : instanceList) {
335                     documentTreeNode = instanceNode.getData();
336                     if (documentTreeNode.isSelect()) {
337                         String instanceUUID = instanceNode.getNodeType();
338                         destInstanceIdentifierListForTree2.add(instanceUUID);
339                     }
340                     List<Node<DocumentTreeNode, String>> itemList = instanceNode.getChildren();
341                     for (Node<DocumentTreeNode, String> itemNode : itemList) {
342                         documentTreeNode = itemNode.getData();
343                         if (documentTreeNode.isSelect()) {
344                             String itemUUID = itemNode.getNodeType();
345                             //stringBufferRightTree.append("true");
346                             itemsSelectedListForRightTree.add(itemUUID);
347                             break;
348                         }
349                     }
350 
351                 }
352             }
353         }
354     }
355 
356     String listToCsv(List<String> listOfStrings, char separator) {
357         StringBuilder sb = new StringBuilder();
358 
359         // all but last
360         for (int i = 0; i < listOfStrings.size() - 1; i++) {
361             sb.append(listOfStrings.get(i));
362             sb.append(separator);
363         }
364         // last string, no separator
365         sb.append(listOfStrings.get(listOfStrings.size() - 1));
366         return sb.toString();
367     }
368 
369     @RequestMapping(params = "methodToCall=delete")
370     public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
371                                HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
372         StringBuilder uuidList = new StringBuilder();
373         BoundwithForm transferForm = (BoundwithForm) form;
374         DocumentSelectionTree documentSelectionTree = new DocumentSelectionTree();
375         //        uuidList.append(boundwithForm.getDocId());
376         //boundwithForm.setInDelete("false");
377         transferForm.setInDeleteLeftTree("false");
378         transferForm.setInDeleteRightTree("false");
379 //        WorkInstanceDocument workInstanceDocumentForTree1 = transferForm.getWorkInstanceDocumentForTree1();
380 
381         String deleteVerifyResponse = transferForm.getDeleteVerifyResponse();
382         if (deleteVerifyResponse.contains("Failed")) {
383             /*transferForm.setSelectedInstance(
384                     "Unable to delete the instance " + workInstanceDocumentForTree1.getHoldingsDocument()
385                                                                                    .getLocationName()
386                     + "\t \n because it exists in OLE database");*/
387 //            String message = workInstanceDocumentForTree1.getHoldingsDocument().getLocationName();
388             String message = "location";
389             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.delete.failure", message);
390         } else if (deleteVerifyResponse.contains("success")) {
391             String treeId = transferForm.getActionParamaterValue("treeId");
392             if (transferForm.getDocType().equalsIgnoreCase("bibliographic")) {
393                 if (transferForm.getDestBibIdentifier() != null && transferForm.getDestBibIdentifier().length() > 0) {
394                     TransferUtil.getInstance().transferInstances(transferForm.getBibInstanceListForTree1(),
395                             transferForm.getDestBibIdentifier());
396                     //transferForm.setMessage("Instance transferred successfully. Bib is deleted.");
397                     if (treeId.equalsIgnoreCase("leftTree")) {
398                         HashMap leftList = (HashMap) request.getSession().getAttribute("LeftList");
399                         if (leftList.size() == 1) {
400                             clearTree(transferForm, result, request, httpResponse);
401                         }
402                         GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.instance.success");
403                         GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.instance.success.bib.delete");
404                     } else {
405                         HashMap rightList = (HashMap) request.getSession().getAttribute("RightList");
406                         if (rightList.size() == 1) {
407                             clearTree(transferForm, result, request, httpResponse);
408                         }
409                         GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.instance.success");
410                         GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.instance.success.bib.delete");
411                     }
412                     getDocstoreClientLocator().getDocstoreClient().deleteBibs(transferForm.getDeleteIds());
413                 } else {
414                     TransferUtil.getInstance().transferItems(transferForm.getBibItemListForTree1(),
415                             transferForm.getDestInstanceIdentifier());
416                     //transferForm.setMessage("Item transferred successfully. Bib and Instance are deleted.");
417                     Holdings holdings = null;
418                     try {
419                         holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(transferForm.getDeleteIds().get(0));
420                     }
421                     catch (Exception e) {
422                         DocstoreException docstoreException = (DocstoreException) e;
423                         if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
424                             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
425                         } else {
426                             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
427                         }
428                     }
429                     BibTree bibTree = null;
430                     try {
431                         bibTree = getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(holdings.getBib().getId());
432                     }
433                     catch (Exception e) {
434                         DocstoreException docstoreException = (DocstoreException) e;
435                         if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
436                             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
437                         } else {
438                             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
439                         }
440                     }
441                     if(bibTree.getHoldingsTrees() != null && bibTree.getHoldingsTrees().size() > 1) {
442                         if (treeId.equalsIgnoreCase("leftTree")) {
443                             HashMap leftList = (HashMap) request.getSession().getAttribute("LeftList");
444                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.item.success");
445                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.item.success.holdings.delete");
446                         } else {
447                             HashMap rightList = (HashMap) request.getSession().getAttribute("RightList");
448                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.item.success");
449                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.item.success.holdings.delete");
450                         }
451                         try {
452                             getDocstoreClientLocator().getDocstoreClient().deleteHoldings(transferForm.getDeleteIds().get(0));
453                         }
454                         catch (Exception e) {
455                             DocstoreException docstoreException = (DocstoreException) e;
456                             if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
457                                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
458                             } else {
459                                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
460                             }
461                         }
462                     }
463                     else {
464                         if (treeId.equalsIgnoreCase("leftTree")) {
465                             HashMap leftList = (HashMap) request.getSession().getAttribute("LeftList");
466                             if (leftList.size() == 1) {
467                                 clearTree(transferForm, result, request, httpResponse);
468                             }
469                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.item.success");
470                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.item.success.bib.instance.delete");
471                         } else {
472                             HashMap rightList = (HashMap) request.getSession().getAttribute("RightList");
473                             if (rightList.size() == 1) {
474                                 clearTree(transferForm, result, request, httpResponse);
475                             }
476                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.item.success");
477                             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.item.success.bib.instance.delete");
478                         }
479                         try {
480                             getDocstoreClientLocator().getDocstoreClient().deleteBib(holdings.getBib().getId());
481                         }
482                         catch (Exception e) {
483                             DocstoreException docstoreException = (DocstoreException) e;
484                             if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
485                                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, docstoreException.getErrorCode());
486                             } else {
487                                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, e.getMessage());
488                             }
489                         }
490                     }
491                 }
492             } else if (transferForm.getDocType().equalsIgnoreCase("holdings")) {
493                 TransferUtil.getInstance().transferItems(transferForm.getBibItemListForTree1(),
494                         transferForm.getDestInstanceIdentifier());
495 
496                 if (treeId.equalsIgnoreCase("leftTree")) {
497                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.item.success");
498                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.item.success.holdings.delete");
499                 } else {
500                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer.item.success");
501                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer.item.success.holdings.delete");
502                 }
503                 for(String id : transferForm.getDeleteIds()) {
504                     getDocstoreClientLocator().getDocstoreClient().deleteHoldings(id);
505                 }
506             }
507 //            String deleteResponseFromDocStore = TransferUtil.getInstance().getDeleteResponseFromDocStore("delete", uuidList.toString(),
508 //                    transferForm);
509             transferForm.setShowBoundwithTree(false);
510         }
511         return getUIFModelAndView(transferForm);
512     }
513 
514     @RequestMapping(params = "methodToCall=OnlyTransfer")
515     public ModelAndView OnlyTransfer(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
516                                      HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
517         BoundwithForm transferForm = (BoundwithForm) form;
518         String treeId = transferForm.getActionParamaterValue("treeId");
519         if (transferForm.getDocType().equalsIgnoreCase("bibliographic")) {
520             if (transferForm.getDestBibIdentifier() != null && transferForm.getDestBibIdentifier().length() > 0) {
521                 TransferUtil.getInstance().transferInstances(transferForm.getBibInstanceListForTree1(),
522                         transferForm.getDestBibIdentifier());
523                 //transferForm.setMessage("Instance transferred successfully.");
524                 if (treeId.equalsIgnoreCase("leftTree")) {
525                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer", "Instance");
526                 } else {
527                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer", "Instance");
528                 }
529             } else {
530                 TransferUtil.getInstance().transferItems(transferForm.getBibItemListForTree1(),
531                         transferForm.getDestInstanceIdentifier());
532                 //transferForm.setMessage("Item transferred successfully.");
533                 if (treeId.equalsIgnoreCase("leftTree")) {
534                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection2", "info.transfer", "Item");
535                 } else {
536                     GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer", "Item");
537                 }
538             }
539         } else if (transferForm.getDocType().equalsIgnoreCase("instance")) {
540             TransferUtil.getInstance().transferItems(transferForm.getBibItemListForTree1(),
541                     transferForm.getDestInstanceIdentifier());
542             //transferForm.setMessage("Item transferred successfully.");
543             GlobalVariables.getMessageMap().putInfoForSectionId("TransferTreeSection1", "info.transfer", "Item");
544         }
545         //boundwithForm.setInDelete("false");
546         transferForm.setInDeleteLeftTree("false");
547         transferForm.setInDeleteRightTree("false");
548         return getUIFModelAndView(transferForm);
549     }
550 
551     /**
552      * Enable, disable the next and previous and also show the message for number of entries
553      * @param boundwithForm
554      * @return
555      */
556     public void setPageNextPreviousAndEntriesInfo(BoundwithForm boundwithForm) {
557         this.totalRecCount = boundwithForm.getSearchResponse().getTotalRecordCount();
558         this.start = boundwithForm.getSearchResponse().getStartIndex();
559         this.pageSize = boundwithForm.getSearchResponse().getPageSize();
560         boundwithForm.setPreviousFlag(getWorkbenchPreviousFlag());
561         boundwithForm.setNextFlag(getWorkbenchNextFlag());
562         boundwithForm.setPageShowEntries(getWorkbenchPageShowEntries());
563     }
564 
565 }