View Javadoc

1   package org.kuali.ole.editor.contoller;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
7   import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
8   import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.*;
9   import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
10  import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkInstanceOlemlRecordProcessor;
11  import org.kuali.ole.editor.bo.InstanceEditorFormDataHandler;
12  import org.kuali.ole.editor.bo.InstanceRecordMetaData;
13  import org.kuali.ole.editor.bo.MarcEditorControlField;
14  import org.kuali.ole.editor.bo.MarcEditorDataField;
15  import org.kuali.ole.editor.form.InstanceEditorForm;
16  import org.kuali.ole.editor.service.DiscoveryHelperService;
17  import org.kuali.ole.editor.service.DocstoreHelperService;
18  import org.kuali.rice.krad.uif.UifParameters;
19  import org.kuali.rice.krad.web.controller.UifControllerBase;
20  import org.kuali.rice.krad.web.form.UifFormBase;
21  import org.springframework.stereotype.Controller;
22  import org.springframework.validation.BindingResult;
23  import org.springframework.web.bind.annotation.ModelAttribute;
24  import org.springframework.web.bind.annotation.RequestMapping;
25  import org.springframework.web.bind.annotation.RequestMethod;
26  import org.springframework.web.servlet.ModelAndView;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  import java.util.*;
31  
32  /**
33   * InstanceEditorController is the controller class for Instance Editor
34   */
35  @Controller
36  @RequestMapping(value = "/instanceeditor")
37  
38  public class InstanceEditorController extends UifControllerBase {
39  
40      private DocstoreHelperService docstoreHelperService;
41      private InstanceEditorFormDataHandler instanceEditorFormDataHandler;
42      private DiscoveryHelperService discoveryHelperService;
43  
44      private static final Logger LOG = Logger.getLogger(InstanceEditorController.class);
45  
46      /**
47       *   This method creates a instance of InstanceEditorForm
48       * @param httpServletRequest
49       * @return  InstanceEditorForm
50       */
51      @Override
52      protected InstanceEditorForm createInitialForm(HttpServletRequest httpServletRequest) {
53          return new InstanceEditorForm();
54      }
55  
56      /**
57       * This method takes the initial request when click on InstanceEditor Screen.
58       * @param form
59       * @param result
60       * @param request
61       * @param response
62       * @return  ModelAndView
63       */
64      @Override
65      @RequestMapping(params = "methodToCall=start")
66      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
67                                HttpServletRequest request, HttpServletResponse response) {
68          InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
69          return super.start(instanceEditorForm, result, request, response);
70      }
71  
72      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
73      public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
74                                   HttpServletRequest request, HttpServletResponse response) {
75          InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
76          String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
77  
78          return getUIFModelAndView(instanceEditorForm, pageId);
79      }
80  
81      /**
82       *  This method will fetch the holding/Item records based on the AdditionalAttributes.
83       * @param form
84       * @param result
85       * @param request
86       * @param response
87       * @return  ModelAndView
88       */
89      @RequestMapping(params = "methodToCall=loadInstanceRecord")
90      public ModelAndView loadInstanceRecord(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
91                                             HttpServletRequest request, HttpServletResponse response) {
92          InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
93          String instanceIdentifier = request.getParameter("uuid");
94          if (null == instanceIdentifier || StringUtils.isEmpty(instanceIdentifier)) {
95              instanceIdentifier = instanceEditorForm.getUuid();
96          }
97          instanceEditorForm.setExisting("true");
98          try {
99              String docStoreData = getDocstoreHelperService().getDocstoreData(instanceIdentifier);
100             InstanceCollection instanceCollection = new WorkInstanceOlemlRecordProcessor().fromXML(docStoreData);
101             instanceEditorForm.setInstance(instanceCollection.getInstance().get(0));
102             instanceEditorForm.setSelectedHolding(instanceEditorForm.getInstance().getOleHoldings());
103             if(instanceEditorForm.getInstance().getItems().getItem().size()>0)
104                 instanceEditorForm.setSelectedItem(instanceEditorForm.getInstance().getItems().getItem().get(0));
105             if(instanceEditorForm.getInstance().getSourceHoldings() != null) {
106                 instanceEditorForm.setSelectedSourceHolding(
107                         getInstanceEditorFormDataHandler().buildSourceHoldingForUI(instanceEditorForm));
108             }
109 
110             getInstanceEditorFormDataHandler().setLocationDetails(instanceEditorForm);
111             //Building Left Pane hierarchy
112             getInstanceEditorFormDataHandler().buildLeftPaneData(instanceEditorForm);
113 
114             //Building MetaData fields
115             if (instanceEditorForm.getInstance().getSourceHoldings() != null) {
116                 getInstanceEditorFormDataHandler().setMetaData(instanceEditorForm, OLEConstants.SOURCEHOLDINGS_DOC_TYPE);
117             } else {
118                 getInstanceEditorFormDataHandler().setMetaData(instanceEditorForm, OLEConstants.HOLDING_DOC_TYPE);
119             }
120             if(instanceEditorForm.getInstance().getItems().getItem().size()>0)
121                 getInstanceEditorFormDataHandler().setMetaData(instanceEditorForm, OLEConstants.ITEM_DOC_TYPE);
122 
123             /*StringBuffer instanceEditorSuccessMessage = new StringBuffer(OLEConstants.INSTANCE_EDITOR_LOAD_SUCCESS);
124             instanceEditorForm.setMessage(instanceEditorSuccessMessage.toString());*/
125         } catch (Exception e) {
126             StringBuffer instanceEditorErrorMessage = new StringBuffer(OLEConstants.INSTANCE_EDITOR_LOAD_FAILURE).append(" :: \n" + e.getMessage());
127             instanceEditorForm.setMessage(instanceEditorErrorMessage.toString());
128             LOG.error(instanceEditorErrorMessage);
129         }
130         return getUIFModelAndView(instanceEditorForm, OLEConstants.HOLDINGS_PAGE);
131     }
132 
133     /**
134      *  This method will ingest new record to docStore if uuid is null else it will update exisiting record.
135      *  and nullify the form.
136      * @param form
137      * @param result
138      * @param request
139      * @param response
140      * @return  ModelAndView
141      */
142     @RequestMapping(params = "methodToCall=submit")
143     public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
144                                HttpServletRequest request, HttpServletResponse response) {
145         String responseFromDocstore = null;
146         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
147         String uuid = instanceEditorForm.getUuid();
148         String instanceEditorSuccessMessage = "";
149         try {
150             if (uuid != null && !uuid.trim().equals("")) {
151                 OleHoldings holdingData = instanceEditorForm.getInstance().getOleHoldings();
152                 String holdingId = instanceEditorForm.getInstance().getOleHoldings().getHoldingsIdentifier();
153                 String holdingXmlContent = getInstanceEditorFormDataHandler().buildHoldingContent(holdingData);
154                 String holdingRecordUpdateResponse =
155                         getDocstoreHelperService().updateInstanceRecord(holdingId, OLEConstants.HOLDING_DOC_TYPE, holdingXmlContent);
156 
157                 for (int item = 0; item < instanceEditorForm.getInstance().getItems().getItem().size(); item++) {
158                     Item itemData = instanceEditorForm.getInstance().getItems().getItem().get(item);
159                     String itemId = instanceEditorForm.getInstance().getItems().getItem().get(item).getItemIdentifier();
160                     String itemXmlContent = getInstanceEditorFormDataHandler().buildItemContent(itemData);
161                     if (itemId == null) {   //New Item
162                         //TODO: Change logic to get Instance UUID. As we are loading existing Instance Identifier, we are getting directly from form
163                         String instanceUuid = uuid;
164                         String itemRecordUpdateResponse =
165                                 getDocstoreHelperService().createItemForInstanceRecord(instanceUuid, OLEConstants.ITEM_DOC_TYPE, itemXmlContent);
166                     } else {
167                         String itemRecordUpdateResponse =
168                                 getDocstoreHelperService().updateInstanceRecord(itemId, OLEConstants.ITEM_DOC_TYPE, itemXmlContent);
169                     }
170                 }
171 
172                 if (instanceEditorForm.getInstance().getSourceHoldings() != null) {
173                     SourceHoldings sourceHoldings = getInstanceEditorFormDataHandler().buildSourceHoldings(instanceEditorForm);
174                     String sourceHoldingId = sourceHoldings.getHoldingsIdentifier();
175                     String sourceHoldinXml  =  getInstanceEditorFormDataHandler().buildSourceHoldingContent(sourceHoldings);
176                     String sourceHoldingUpdateResponse =
177                             getDocstoreHelperService().updateInstanceRecord(sourceHoldingId, "sourceHoldings", sourceHoldinXml);
178                 }
179                 loadInstanceRecord(instanceEditorForm, result, request, response);
180                 instanceEditorSuccessMessage = new String(OLEConstants.INSTANCE_EDITOR_SUCCESS);
181             }  else {
182                 Instance instance = new Instance();
183                 instanceEditorForm.setInstance(instance);
184                 Item oleItem = instanceEditorForm.getSelectedItem();
185                 Items items = new Items();
186                 items.setItem(Arrays.asList(oleItem));
187                 instanceEditorForm.getInstance().setItems(items);
188                 instanceEditorForm.getSelectedHolding().setPrimary("true");
189                 instanceEditorForm.getInstance().setOleHoldings(instanceEditorForm.getSelectedHolding());
190                 String content =  getInstanceEditorFormDataHandler().buildInstanceRecordForDocStore(instanceEditorForm, uuid);
191                 responseFromDocstore = getDocstoreHelperService().
192                         instanceRecordCallToDocstore(content, null, OLEConstants.OLEML_FORMAT);
193 
194                 //Refreshing Editor after creating new instance record to load created instance uuid.
195                 Response dsResponse = new org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler().toObject(responseFromDocstore);
196                 if (dsResponse.getStatus().toLowerCase().contains(OLEConstants.OLE_DOCSTORE_RESPONSE_STATUS)) {
197                     String responseUUID = dsResponse.getDocuments().get(0).getUuid();
198                     instanceEditorForm.setUuid(responseUUID);
199                     loadInstanceRecord(instanceEditorForm, result, request, response);
200                     instanceEditorSuccessMessage = OLEConstants.INSTANCE_EDITOR_SUCCESS;
201                 } else {
202                     instanceEditorSuccessMessage = OLEConstants.INSTANCE_EDITOR_FAILURE;
203                 }
204             }
205             //instanceEditorForm.setUuid("");
206             instanceEditorForm.setMessage(instanceEditorSuccessMessage);
207         } catch (Exception e) {
208             StringBuffer instanceEditorErrorMessage = new StringBuffer(OLEConstants.INSTANCE_EDITOR_FAILURE).append(" :: \n" + e.getMessage());
209             instanceEditorForm.setMessage(instanceEditorErrorMessage.toString());
210             LOG.error(instanceEditorErrorMessage);
211         }
212         return getUIFModelAndView(form);
213     }
214 
215     /**
216      *   This Method will update the Left Pane hierarchy details.
217      * @param form
218      * @param result
219      * @param request
220      * @param response
221      * @return  ModelAndView
222      */
223     @RequestMapping(params = "methodToCall=updateLeftPane")
224     public ModelAndView updateLeftPane(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
225                                        HttpServletRequest request, HttpServletResponse response) {
226         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
227         String hiddenVal = instanceEditorForm.getHdnUuid();
228         int hdnIndex = instanceEditorForm.getHdnIndex();
229         instanceEditorForm.setSelectedItem(instanceEditorForm.getInstance().getItems().getItem().get(hdnIndex));
230         DiscoveryHelperService discoveryHelperService = getDiscoveryHelperService();
231 
232         List responseFromSOLR =  discoveryHelperService.getResponseFromSOLR("id", hiddenVal);
233         LOG.info("solr response:"+responseFromSOLR.toString());
234         LOG.info("solr response size:"+responseFromSOLR.size());
235         String docType = null;
236         for (Iterator iterator = responseFromSOLR.iterator(); iterator.hasNext(); ) {
237             Map map = (Map) iterator.next();
238             if (map.containsKey(OLEConstants.DOC_TYPE)) {
239                 String list = (String) map.get(OLEConstants.DOC_TYPE);
240                 docType = list;
241                 break;
242             }
243         }
244         if ((docType.toString().equals(OLEConstants.ITEM_DOC_TYPE))) {
245             getInstanceEditorFormDataHandler().setMetaData(instanceEditorForm, OLEConstants.ITEM_DOC_TYPE);
246 
247             return getUIFModelAndView(instanceEditorForm, OLEConstants.ITEM_PAGE);
248         } else {
249             return getUIFModelAndView(instanceEditorForm, OLEConstants.HOLDINGS_PAGE);
250         }
251     }
252 
253     /**
254      * This method adds the existingItem records from docStore in to oleItems and it will be set in InstanceEditorForm.
255      * @param form
256      * @param result
257      * @param request
258      * @param response
259      * @return ModelAndView
260      */
261     @RequestMapping(method = RequestMethod.POST,params = "methodToCall=addNewItem")
262     public ModelAndView addItemRecord(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
263                                       HttpServletRequest request, HttpServletResponse response){
264         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
265         List<Item> existingItemsFromDoc = instanceEditorForm.getInstance().getItems().getItem();
266         List<Item> oleItems = new ArrayList<Item>();
267 
268         for(int i=0;i<existingItemsFromDoc.size();i++){
269             oleItems.add(existingItemsFromDoc.get(i));
270         }
271         oleItems.add(new Item());
272         instanceEditorForm.setItemRecordMetaData(new InstanceRecordMetaData());
273         instanceEditorForm.getInstance().getItems().setItem(oleItems);
274         instanceEditorForm.setHdnIndex(oleItems.size());
275         int hdnIndex = instanceEditorForm.getHdnIndex();
276         instanceEditorForm.setSelectedItem(instanceEditorForm.getInstance().getItems().getItem().get(hdnIndex-1));
277         return getUIFModelAndView(instanceEditorForm, OLEConstants.ITEM_PAGE);
278     }
279 
280 
281     @RequestMapping(method =  RequestMethod.POST,params = "methodToCall=deleteInstance")
282     public ModelAndView deleteInstance(@ModelAttribute("KualiForm") UifFormBase form,BindingResult result,HttpServletRequest request,HttpServletResponse response) throws Exception {
283         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
284         Instance instance = instanceEditorForm.getInstance();
285         LOG.info("instance-->"+instance.getInstanceIdentifier());
286         StringBuffer instanceEditorSuccessMessage = new StringBuffer(OLEConstants.INSTANCE_EDITOR_DELETE_SUCCESS);
287         instanceEditorForm.setMessage(instanceEditorSuccessMessage.toString());
288         String deleteResponse = getDocstoreHelperService().deleteInstanceRecord(instance);
289         LOG.info("delete response-->" + deleteResponse);
290         Response responseObj = new ResponseHandler().toObject(deleteResponse);
291         if (responseObj.getStatus().toLowerCase().contains(OLEConstants.OLE_DOCSTORE_RESPONSE_STATUS)) {
292             instanceEditorForm.setMessage(OLEConstants.INSTANCE_EDITOR_DELETE_SUCCESS);
293         }
294         else {
295             instanceEditorForm.setMessage(OLEConstants.INSTANCE_EDITOR_DELETE_FAILURE);
296         }
297         return getUIFModelAndView(instanceEditorForm, OLEConstants.HOLDINGS_PAGE);
298     }
299 
300     /**
301      * This method will get new itemData
302      * @param form
303      * @param result
304      * @param request
305      * @param response
306      * @return
307      */
308     @RequestMapping(method = RequestMethod.POST,params = "methodToCall=getNewItemData")
309     public ModelAndView getNewItemData(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
310                                        HttpServletRequest request, HttpServletResponse response){
311         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
312         List<Item> existingItemsFromDoc = instanceEditorForm.getInstance().getItems().getItem();
313         List<Item> oleItems = new ArrayList<Item>();
314 
315         for(int i=0;i<existingItemsFromDoc.size();i++){
316             oleItems.add(existingItemsFromDoc.get(i));
317         }
318         instanceEditorForm.setHdnIndex(oleItems.size());
319         int hdnIndex = instanceEditorForm.getHdnIndex();
320         instanceEditorForm.setSelectedItem(instanceEditorForm.getInstance().getItems().getItem().get(hdnIndex-1));
321         return getUIFModelAndView(instanceEditorForm, OLEConstants.ITEM_PAGE);
322     }
323 
324     /**
325      *  Used for Test-case
326      * @param result
327      * @param request
328      * @param response
329      * @param instanceEditorForm
330      * @return ModelAndView
331      */
332     protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, InstanceEditorForm instanceEditorForm) {
333         return super.updateComponent(instanceEditorForm, result, request, response);
334     }
335 
336     /**
337      *  Gets the docstoreHelperService attribute
338      * @return  Returns DocstoreHelperService
339      */
340     private DocstoreHelperService getDocstoreHelperService() {
341         if (null == docstoreHelperService) {
342             return new DocstoreHelperService();
343         }
344         return docstoreHelperService;
345     }
346 
347     /**
348      *    Sets the docstoreHelperService attribute values.
349      * @param docstoreHelperService
350      */
351     public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
352         this.docstoreHelperService = docstoreHelperService;
353     }
354 
355     /**
356      *  Gets the InstanceEditorFormDataHandler attribute.
357      * @return Returns InstanceEditorFormDataHandler.
358      */
359     private InstanceEditorFormDataHandler getInstanceEditorFormDataHandler() {
360         if (null == instanceEditorFormDataHandler) {
361             instanceEditorFormDataHandler = new InstanceEditorFormDataHandler();
362         }
363         return instanceEditorFormDataHandler;
364     }
365 
366     /**
367      *  This method returns AdditionalAttributes instance from the list of Extension.
368      * @param extensionList
369      * @return  AdditionalAttributes
370      */
371     private AdditionalAttributes getFirstAdditionalAttributes(List<Extension> extensionList) {
372         for (Extension ext : extensionList) {
373             for (Object obj : ext.getContent()) {
374                 if (obj instanceof AdditionalAttributes) {
375                     return (AdditionalAttributes) obj;
376                 }
377             }
378         }
379         return null;
380     }
381 
382     /**
383      * Sets the discoveryHelperService attribute value.
384      * @param discoveryHelperService
385      */
386     public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
387         this.discoveryHelperService = discoveryHelperService;
388     }
389 
390     /**
391      *  Gets the discoveryHelperService attribute.
392      * @return Returns DiscoveryHelperService.
393      */
394     public DiscoveryHelperService getDiscoveryHelperService() {
395         if (null == discoveryHelperService) {
396             return new DiscoveryHelperService();
397         }
398         return discoveryHelperService;
399     }
400 
401     /*@RequestMapping(params = "methodToCall=addExtentOfOwnership")
402     public ModelAndView addExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
403                                              HttpServletRequest request, HttpServletResponse response) {
404         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
405         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
406         index++;
407         List<ExtentOfOwnership> extentOfOwnershipForUI = instanceEditorForm.getSelectedHolding().getExtentOfOwnership();
408         extentOfOwnershipForUI.add(index, new ExtentOfOwnership());
409         return super.updateComponent(instanceEditorForm, result, request, response);
410     }
411 
412     @RequestMapping(params = "methodToCall=removeExtentOfOwnership")
413     public ModelAndView removeExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
414                                                 HttpServletRequest request, HttpServletResponse response) {
415         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
416         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
417         List<ExtentOfOwnership> extentOfOwnershipForUI = instanceEditorForm.getSelectedHolding().getExtentOfOwnership();
418         if (extentOfOwnershipForUI.size() > 1)
419             extentOfOwnershipForUI.remove(index);
420         return super.updateComponent(instanceEditorForm, result, request, response);
421     }*/
422 
423     @RequestMapping(params = "methodToCall=addAccessInformation")
424     public ModelAndView addAccessInformation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
425                                              HttpServletRequest request, HttpServletResponse response) {
426         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
427         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
428         index++;
429         List<Uri> accessInformation = instanceEditorForm.getSelectedHolding().getUri();
430         accessInformation.add(index, new Uri());
431         return super.updateComponent(instanceEditorForm, result, request, response);
432     }
433 
434     @RequestMapping(params = "methodToCall=removeAccessInformation")
435     public ModelAndView removeAccessInformation(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
436                                                 HttpServletRequest request, HttpServletResponse response) {
437         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
438         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
439         List<Uri> accessInformation = instanceEditorForm.getSelectedHolding().getUri();
440         if (accessInformation.size() > 1)
441             accessInformation.remove(index);
442         return super.updateComponent(instanceEditorForm, result, request, response);
443     }
444 
445     @RequestMapping(params = "methodToCall=addHoldingNotes")
446     public ModelAndView addHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
447                                         HttpServletRequest request, HttpServletResponse response) {
448         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
449         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
450         index++;
451         List<Note> holdingsNote = instanceEditorForm.getSelectedHolding().getNote();
452         holdingsNote.add(index, new Note());
453         return super.updateComponent(instanceEditorForm, result, request, response);
454     }
455 
456     @RequestMapping(params = "methodToCall=removeHoldingNotes")
457     public ModelAndView removeHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
458                                            HttpServletRequest request, HttpServletResponse response) {
459         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
460         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
461         List<Note> holdingsNote = instanceEditorForm.getSelectedHolding().getNote();
462         if (holdingsNote.size() > 1)
463             holdingsNote.remove(index);
464         return super.updateComponent(instanceEditorForm, result, request, response);
465     }
466 
467     /**
468      * This method will add the controlField record based on the selected Line index and updates the component.
469      * @param form
470      * @param result
471      * @param request
472      * @param response
473      * @return  ModelAndView
474      */
475     @RequestMapping(params = "methodToCall=addControlField")
476     public ModelAndView addControlField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
477                                         HttpServletRequest request, HttpServletResponse response) {
478         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
479         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
480         index++;
481         List<MarcEditorControlField> marcEditorControlFieldList = instanceEditorForm.getSelectedSourceHolding().getControlFields();
482         marcEditorControlFieldList.add(index, new MarcEditorControlField());
483         return super.updateComponent(instanceEditorForm, result, request, response);
484     }
485 
486     /**
487      *  This method will remove the controlField based on the index position and updates the component.
488      * @param form
489      * @param result
490      * @param request
491      * @param response
492      * @return  ModelAndView
493      */
494     @RequestMapping(params = "methodToCall=removeControlField")
495     public ModelAndView removeControlField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
496                                            HttpServletRequest request, HttpServletResponse response) {
497         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
498         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
499         List<MarcEditorControlField> editorControlFieldList = instanceEditorForm.getSelectedSourceHolding().getControlFields();
500         if (editorControlFieldList.size() > 1)
501             editorControlFieldList.remove(index);
502         return super.updateComponent(instanceEditorForm, result, request, response);
503     }
504 
505     /**
506      *  This method will add the datField record based on the selected Line index and updates the component.
507      * @param form
508      * @param result
509      * @param request
510      * @param response
511      * @return ModelAndView
512      */
513     @RequestMapping(params = "methodToCall=addDataField")
514     public ModelAndView addDataField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
515                                      HttpServletRequest request, HttpServletResponse response) {
516         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
517         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
518         index++;
519         List<MarcEditorDataField> editorDataFieldList = instanceEditorForm.getSelectedSourceHolding().getDataFields();
520         editorDataFieldList.add(index, new MarcEditorDataField());
521         return super.updateComponent(instanceEditorForm, result, request, response);
522     }
523 
524     /**
525      *    This method will remove the dataField based on the index position and updates the component.
526      * @param form
527      * @param result
528      * @param request
529      * @param response
530      * @return ModelAndView
531      */
532     @RequestMapping(params = "methodToCall=removeDataField")
533     public ModelAndView removeDataField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
534                                         HttpServletRequest request, HttpServletResponse response) {
535         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
536         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
537         List<MarcEditorDataField> marcEditorDataFieldList = instanceEditorForm.getSelectedSourceHolding().getDataFields();
538         if (marcEditorDataFieldList.size() > 1)
539             marcEditorDataFieldList.remove(index);
540         return super.updateComponent(instanceEditorForm, result, request, response);
541     }
542 
543     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteItem")
544     public ModelAndView deleteItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
545                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
546         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
547         String id = instanceEditorForm.getDeleteItemId();
548         String[] ids = id.split("_");
549         String itemUuid = ids[0];
550         String docstoreResponse = getDocstoreHelperService().deleteItemrecord(itemUuid);
551         Response responseObj = new ResponseHandler().toObject(docstoreResponse);
552         if (responseObj.getStatus().toLowerCase().contains(OLEConstants.OLE_DOCSTORE_RESPONSE_STATUS)) {
553             instanceEditorForm.setMessage(OLEConstants.INSTANCE_EDITOR_DELETE_SUCCESS);
554             loadInstanceRecord(instanceEditorForm, result, request, response);
555         }
556         else {
557             instanceEditorForm.setMessage(OLEConstants.INSTANCE_EDITOR_DELETE_FAILURE);
558         }
559         return getUIFModelAndView(instanceEditorForm, OLEConstants.HOLDINGS_PAGE);
560     }
561 
562     @RequestMapping(params = "methodToCall=addExtentOfOwnership")
563     public ModelAndView addExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
564                                              HttpServletRequest request, HttpServletResponse response) {
565         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
566         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
567         index++;
568         List<ExtentOfOwnership> extentOfOwnershipForUI = instanceEditorForm.getSelectedHolding().getExtentOfOwnership();
569         ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
570         extentOfOwnership.getNote().add(new Note());
571         extentOfOwnershipForUI.add(index, extentOfOwnership);
572         return super.updateComponent(instanceEditorForm, result, request, response);
573     }
574 
575     @RequestMapping(params = "methodToCall=removeExtentOfOwnership")
576     public ModelAndView removeExtentOfOwnership(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
577                                                 HttpServletRequest request, HttpServletResponse response) {
578         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
579         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
580         List<ExtentOfOwnership> extentOfOwnershipForUI = instanceEditorForm.getSelectedHolding().getExtentOfOwnership();
581         if (extentOfOwnershipForUI.size() > 1) {
582             extentOfOwnershipForUI.remove(index);
583         }
584         return super.updateComponent(instanceEditorForm, result, request, response);
585     }
586 
587     @RequestMapping(params = "methodToCall=addEOWHoldingNotes")
588     public ModelAndView addEOWHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
589                                            HttpServletRequest request, HttpServletResponse response) {
590         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
591         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
592         String selectedPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
593         int selectedExtentIndex = Integer.parseInt(StringUtils.substring(selectedPath,
594                                                                          (StringUtils.indexOf(selectedPath, "[") + 1),
595                                                                          StringUtils.lastIndexOf(selectedPath, "]")));
596         index++;
597         List<Note> holdingsNote = instanceEditorForm.getSelectedHolding().getExtentOfOwnership()
598                                                     .get(selectedExtentIndex).getNote();
599         holdingsNote.add(index, new Note());
600         return super.updateComponent(instanceEditorForm, result, request, response);
601     }
602 
603     @RequestMapping(params = "methodToCall=removeEOWHoldingNotes")
604     public ModelAndView removeEOWHoldingNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
605                                               HttpServletRequest request, HttpServletResponse response) {
606         InstanceEditorForm instanceEditorForm = (InstanceEditorForm) form;
607         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
608         String selectedPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
609         int selectedExtentIndex = Integer.parseInt(StringUtils.substring(selectedPath,
610                                                                          (StringUtils.indexOf(selectedPath, "[") + 1),
611                                                                          StringUtils.lastIndexOf(selectedPath, "]")));
612         List<Note> holdingsNote = instanceEditorForm.getSelectedHolding().getExtentOfOwnership()
613                                                     .get(selectedExtentIndex).getNote();
614         if (holdingsNote.size() > 1) {
615             holdingsNote.remove(index);
616         }
617         return super.updateComponent(instanceEditorForm, result, request, response);
618     }
619 
620 }
621