View Javadoc
1   package org.kuali.ole.select.controller;
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.common.client.DocstoreClientLocator;
7   import org.kuali.ole.docstore.common.document.EHoldings;
8   import org.kuali.ole.docstore.common.document.Holdings;
9   import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
10  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
11  import org.kuali.ole.select.bo.*;
12  import org.kuali.ole.select.document.*;
13  import org.kuali.ole.select.form.OLEEResourceRecordForm;
14  import org.kuali.ole.service.OLEEResourceSearchService;
15  import org.kuali.ole.service.OleLicenseRequestWebService;
16  import org.kuali.ole.sys.context.SpringContext;
17  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
18  import org.kuali.rice.krad.service.BusinessObjectService;
19  import org.kuali.rice.krad.service.KRADServiceLocator;
20  import org.kuali.rice.krad.service.KualiRuleService;
21  import org.kuali.rice.krad.uif.UifParameters;
22  import org.kuali.rice.krad.uif.container.CollectionGroup;
23  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
24  import org.kuali.rice.krad.uif.view.View;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.web.controller.TransactionalDocumentControllerBase;
27  import org.kuali.rice.krad.web.form.DocumentFormBase;
28  import org.kuali.rice.krad.web.form.TransactionalDocumentFormBase;
29  import org.kuali.rice.krad.web.form.UifFormBase;
30  import org.springframework.stereotype.Controller;
31  import org.springframework.validation.BindingResult;
32  import org.springframework.web.bind.annotation.ModelAttribute;
33  import org.springframework.web.bind.annotation.RequestMapping;
34  import org.springframework.web.bind.annotation.RequestMethod;
35  import org.springframework.web.servlet.ModelAndView;
36  
37  import javax.servlet.http.HttpServletRequest;
38  import javax.servlet.http.HttpServletResponse;
39  import java.sql.Date;
40  import java.util.*;
41  
42  /**
43   * Created with IntelliJ IDEA.
44   * User: srinivasane
45   * Date: 6/21/13
46   * Time: 12:25 PM
47   * To change this template use File | Settings | File Templates.
48   */
49  @Controller
50  @RequestMapping(value = "/oleERSController")
51  public class OLEEResourceRecordController extends TransactionalDocumentControllerBase {
52  
53  
54      /**
55       * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
56       */
57      private static final Logger LOG = Logger.getLogger(OLEEResourceRecordController.class);
58  
59      private OleLicenseRequestWebService oleLicenseRequestWebService = null;
60      private KualiRuleService kualiRuleService;
61      private BusinessObjectService businessObjectService;
62      private OLEEResourceSearchService oleEResourceSearchService = null;
63      private DocstoreClientLocator docstoreClientLocator;
64  
65      public DocstoreClientLocator getDocstoreClientLocator() {
66          if (docstoreClientLocator == null) {
67              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
68          }
69          return docstoreClientLocator;
70      }
71  
72      /**
73       * This method will return new Instance of OLEEResourceRecordForm.
74       *
75       * @param request
76       * @return OLEEResourceRecordForm.
77       */
78      @Override
79      protected TransactionalDocumentFormBase createInitialForm(HttpServletRequest request) {
80          OLEEResourceRecordForm oleeResourceRecordForm = new OLEEResourceRecordForm();
81          oleeResourceRecordForm.setStatusDate(new Date(System.currentTimeMillis()).toString());
82          oleeResourceRecordForm.setDocumentDescription(OLEConstants.OLEEResourceRecord.NEW_E_RESOURCE_REC);
83          return oleeResourceRecordForm;
84      }
85  
86      /**
87       * This method takes the initial request when click on E-Resource Record Screen.
88       *
89       * @param form
90       * @param result
91       * @param request
92       * @param response
93       * @return ModelAndView
94       */
95      @Override
96      @RequestMapping(params = "methodToCall=start")
97      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
98                                HttpServletRequest request, HttpServletResponse response) {
99          LOG.debug("Start -- Start Method of OlePatronRecordForm");
100         OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form;
101         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleeResourceRecordForm.getDocument();
102         oleeResourceRecordDocument.setStatusDate(new Date(System.currentTimeMillis()).toString());
103         return super.start(oleeResourceRecordForm, result, request, response);
104     }
105 
106     /**
107      * This method populates date of the eventlog object thereby adding to the existing list.
108      *
109      * @param uifForm
110      * @param result
111      * @param request
112      * @param response
113      * @return ModelAndView
114      */
115     @RequestMapping(params = "methodToCall=addEventLogLine")
116     public ModelAndView addEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
117                                         HttpServletRequest request, HttpServletResponse response) {
118         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
119         String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
120         CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
121                 selectedCollectionPath);
122         String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
123         Object eventObject = ObjectPropertyUtils.getPropertyValue(uifForm, addLinePath);
124         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
125         OLEEResourceEventLog oleERSEventLog = (OLEEResourceEventLog) eventObject;
126         oleERSEventLog.setEventType(OLEConstants.OleLicenseRequest.USER);
127         oleERSEventLog.setCurrentTimeStamp();
128         oleERSEventLog.setOleERSIdentifier(oleeResourceRecordDocument.getDocumentNumber());
129         return addLine(uifForm, result, request, response);
130     }
131 
132     /**
133      * This method populates date of the eventlog object thereby adding to the existing list.
134      *
135      * @param uifForm
136      * @param result
137      * @param request
138      * @param response
139      * @return ModelAndView
140      */
141     @RequestMapping(params = "methodToCall=deleteEventLogLine")
142     public ModelAndView deleteEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
143                                            HttpServletRequest request, HttpServletResponse response) {
144         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
145         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
146         String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
147         OLEEResourceEventLog oleERSEventLog = oleeResourceRecordDocument.getOleERSEventLogs().get(Integer.parseInt(selectedLineIndex));
148         //getBusinessObjectService().delete(oleERSEventLog);
149         return deleteLine(form, result, request, response);
150     }
151 
152     /**
153      * This method Creates the License Request Document and link to the E-Resource document
154      *
155      * @param form
156      * @param result
157      * @param request
158      * @param response
159      * @return ModelAndView
160      */
161     @RequestMapping(params = "methodToCall=performCreateLicenseRequest")
162     public ModelAndView performCreateLicenseRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
163                                                     HttpServletRequest request, HttpServletResponse response) {
164         LOG.debug("performCreateLicenseRequest method starts");
165         OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form;
166         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleeResourceRecordForm.getDocument();
167         OleLicenseRequestBo oleLicenseRequestBo = getOleLicenseRequestService().createLicenseRequest(
168                 oleeResourceRecordDocument.getDocumentNumber(), null);
169         OLEEResourceLicense oleeResourceLicense = new OLEEResourceLicense();
170         oleeResourceLicense.setLicenseDocumentNumber(oleLicenseRequestBo.getLicenseDocumentNumber());
171         oleeResourceLicense.setDocumentRouteHeaderValue(oleLicenseRequestBo.getDocumentRouteHeaderValue());
172        /* Map<String,String> searchCriteria = new HashMap<String,String>();
173         searchCriteria.put(OLEConstants.DOC_ID,oleLicenseRequestBo.getLicenseDocumentNumber());*/
174         /*DocumentRouteHeaderValue documentHeader= (DocumentRouteHeaderValue)  getBusinessObjectService().findByPrimaryKey
175                 (DocumentRouteHeaderValue.class,searchCriteria);*/
176         /*DocumentRouteHeaderValue documentHeader= KEWServiceLocator.getRouteHeaderService().getRouteHeader(oleLicenseRequestBo.getLicenseDocumentNumber(), true);
177         oleLicenseRequestBo.setDocumentRouteHeaderValue(documentHeader);*/
178 
179         List<OLEEResourceInstance> listOfERInstances = oleeResourceRecordDocument.getOleERSInstances();
180         List<OleLicenseRequestItemTitle> oleLicenseRequestItemTitles = new ArrayList<>();
181         for (OLEEResourceInstance oleeResourceInstance : listOfERInstances) {
182             OleLicenseRequestItemTitle oleLicenseRequestItemTitle = new OleLicenseRequestItemTitle();
183             oleLicenseRequestItemTitle.setItemUUID(oleeResourceInstance.getBibId());
184             oleLicenseRequestItemTitle.setOleLicenseRequestId(oleLicenseRequestBo.getOleLicenseRequestId());
185             oleLicenseRequestItemTitle.setOleLicenseRequestBo(oleLicenseRequestBo);
186             oleLicenseRequestItemTitles.add(oleLicenseRequestItemTitle);
187         }
188         oleLicenseRequestBo.setOleLicenseRequestItemTitles(oleLicenseRequestItemTitles);
189         oleeResourceLicense.setOleLicenseRequestBo(oleLicenseRequestBo);
190         oleeResourceRecordDocument.getOleERSLicenseRequests().add(oleeResourceLicense);
191 
192         //oleeResourceRecordDocument.
193         return getUIFModelAndView(oleeResourceRecordForm);
194     }
195 
196     /**
197      * Saves the document instance contained on the form
198      *
199      * @param form - document form base containing the document instance that will be saved
200      * @return ModelAndView
201      */
202     @Override
203     @RequestMapping(params = "methodToCall=save")
204     public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
205                              HttpServletRequest request, HttpServletResponse response) throws Exception {
206         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
207         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
208         oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString());
209         if (oleeResourceRecordDocument.getTitle() != null) {
210             if (oleeResourceRecordDocument.getTitle().length() < 40) {
211                 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle());
212             } else {
213                 String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39);
214                 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription);
215             }
216         }
217         List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes();
218         List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
219         List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes();
220         List<String> instanceId = new ArrayList<String>();
221         /*boolean oleERSFlag = false;
222         oleERSFlag &= getKualiRuleService().applyRules(new OLEMaterialTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleMaterialTypes()));
223         oleERSFlag &= getKualiRuleService().applyRules(new OLEContentTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleContentTypes()));
224         if (oleERSFlag) {
225         return getUIFModelAndView(oleERSform);
226         }*/
227         boolean flag = false;
228         boolean datesFlag = true;
229         flag = getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument);
230         datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument,oleERSform);
231         datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument,oleERSform);
232         datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument,oleERSform);
233         datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument,oleERSform);
234         if (flag) {
235             return getUIFModelAndView(oleERSform);
236         }
237         if (!datesFlag) {
238             return getUIFModelAndView(oleERSform);
239         }
240         String fileName = oleeResourceRecordDocument.getDocumentNumber();
241         if (oleERSform.isCreateInstance()) {
242             getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName);
243             oleERSform.setCreateInstance(false);
244         }
245         oleERSform.setBibId(null);
246         oleERSform.setInstanceId(null);
247         oleERSform.setLinkInstance(false);
248         if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) {
249             oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument);
250             Map<String, String> tempId = new HashMap<String, String>();
251             tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier());
252             OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
253             int instancesSize = tempDocument.getOleERSInstances().size();
254             int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size();
255             if (!oleERSform.isDefaultDatesFlag() && oleERSform.getPageId() != null && oleERSform.getPageId().equalsIgnoreCase("OLEEResourceRecordView-E-ResourceInstanceTab")) {
256                 if (tempDocument.iseInstanceFlag() && instancesSize >= instanceSize && !oleERSform.isRemoveInstanceFlag()) {
257                     try {
258                         super.reload(oleERSform, result, request, response);
259                     } catch (Exception e) {
260                         LOG.error("exception while reloading the e-resource document" + e.getMessage());
261                         throw new RuntimeException("exception while reloading the e-resource document", e);
262                     }
263                 }
264             }
265             oleERSform.setRemoveInstanceFlag(false);
266             oleERSform.setDefaultDatesFlag(false);
267         }
268         if (StringUtils.isNotBlank(oleeResourceRecordDocument.getFundCode())){
269             Map fundCodeMap=new HashMap();
270             fundCodeMap.put(OLEConstants.OLEBatchProcess.VENDOR_REF_NUMBER,oleeResourceRecordDocument.getFundCode());
271             OleVendorAccountInfo oleVendorAccountInfo = getBusinessObjectService().findByPrimaryKey(OleVendorAccountInfo.class, fundCodeMap);
272             if (oleVendorAccountInfo==null){
273                 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.FUND_CODE,OLEConstants.OLEEResourceRecord.ERROR_FUND_CODE);
274             }
275         }
276         getOleEResourceSearchService().getPOInvoiceForERS(oleeResourceRecordDocument);
277         getOleEResourceSearchService().getPOAndInvoiceItemsWithoutDuplicate(oleeResourceRecordDocument);
278         return super.save(oleERSform, result, request, response);
279     }
280 
281     /**
282      * Routes the document instance contained on the form
283      *
284      * @param form - document form base containing the document instance that will be routed
285      * @return ModelAndView
286      */
287     @RequestMapping(params = "methodToCall=route")
288     public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
289                               HttpServletRequest request, HttpServletResponse response) {
290         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
291         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
292         oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString());
293         if (oleeResourceRecordDocument.getTitle().length() < 40) {
294             oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle());
295         } else {
296             String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39);
297             oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription);
298         }
299         List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes();
300         List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
301         List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes();
302         List<String> instanceId = new ArrayList<String>();
303         /*boolean oleERSFlag = false;
304         oleERSFlag &= getKualiRuleService().applyRules(new OLEMaterialTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleMaterialTypes()));
305         oleERSFlag &= getKualiRuleService().applyRules(new OLEContentTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleContentTypes()));
306         if (oleERSFlag) {
307         return getUIFModelAndView(oleERSform);
308         }*/
309         boolean flag = false;
310         boolean datesFlag = true;
311         flag=getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument);
312         datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument,oleERSform);
313         datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument,oleERSform);
314         datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument,oleERSform);
315         datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument,oleERSform);
316         if (flag) {
317             return getUIFModelAndView(oleERSform);
318         }
319         if (!datesFlag) {
320             return getUIFModelAndView(oleERSform);
321         }
322         String fileName = oleeResourceRecordDocument.getDocumentNumber();
323         if (oleERSform.isCreateInstance()) {
324             try {
325                 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName);
326             } catch (Exception e) {
327                 e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
328             }
329             oleERSform.setCreateInstance(false);
330         }
331         oleERSform.setBibId(null);
332         oleERSform.setInstanceId(null);
333         oleERSform.setLinkInstance(false);
334         if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) {
335             oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument);
336             Map<String, String> tempId = new HashMap<String, String>();
337             tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier());
338             OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
339             int instancesSize = tempDocument.getOleERSInstances().size();
340             int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size();
341             if (tempDocument.iseInstanceFlag() && instancesSize > instanceSize && !oleERSform.isRemoveInstanceFlag()) {
342                 try {
343                     super.reload(oleERSform, result, request, response);
344                 } catch (Exception e) {
345                     LOG.error("Exception while reloading the e-resource document"+e.getMessage());
346                 }
347             }
348             oleERSform.setRemoveInstanceFlag(false);
349         }
350         if (StringUtils.isNotBlank(oleeResourceRecordDocument.getFundCode())){
351             Map fundCodeMap=new HashMap();
352             fundCodeMap.put(OLEConstants.OLEBatchProcess.VENDOR_REF_NUMBER,oleeResourceRecordDocument.getFundCode());
353             OleVendorAccountInfo oleVendorAccountInfo = getBusinessObjectService().findByPrimaryKey(OleVendorAccountInfo.class, fundCodeMap);
354             if (oleVendorAccountInfo==null){
355                 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.FUND_CODE,OLEConstants.OLEEResourceRecord.ERROR_FUND_CODE);
356             }
357         }
358         return super.route(oleERSform, result, request, response);
359     }
360 
361     /**
362      * Performs the approve workflow action on the form document instance
363      *
364      * @param form - document form base containing the document instance that will be approved
365      * @return ModelAndView
366      */
367     @Override
368     @RequestMapping(params = "methodToCall=approve")
369     public ModelAndView approve(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
370                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
371         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
372         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
373         oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString());
374         if (oleeResourceRecordDocument.getTitle().length() < 40) {
375             oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle());
376         } else {
377             String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39);
378             oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription);
379         }
380         List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes();
381         List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
382         List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes();
383         List<String> instanceId = new ArrayList<String>();
384         /*boolean oleERSFlag = false;
385         oleERSFlag &= getKualiRuleService().applyRules(new OLEMaterialTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleMaterialTypes()));
386         oleERSFlag &= getKualiRuleService().applyRules(new OLEContentTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleContentTypes()));
387         if (oleERSFlag) {
388         return getUIFModelAndView(oleERSform);
389         }*/
390         boolean flag = false;
391         boolean datesFlag = true;
392         flag=getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument);
393         datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument,oleERSform);
394         datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument,oleERSform);
395         datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument,oleERSform);
396         datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument,oleERSform);
397         if (flag) {
398             return getUIFModelAndView(oleERSform);
399         }
400         if (!datesFlag) {
401             return getUIFModelAndView(oleERSform);
402         }
403         String fileName = oleeResourceRecordDocument.getDocumentNumber();
404         if (oleERSform.isCreateInstance()) {
405             getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName);
406             oleERSform.setCreateInstance(false);
407         }
408         oleERSform.setBibId(null);
409         oleERSform.setInstanceId(null);
410         oleERSform.setLinkInstance(false);
411         if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) {
412             oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument);
413             Map<String, String> tempId = new HashMap<String, String>();
414             tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier());
415             OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
416             int instancesSize = tempDocument.getOleERSInstances().size();
417             int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size();
418             if (tempDocument.iseInstanceFlag() && instancesSize > instanceSize && !oleERSform.isRemoveInstanceFlag()) {
419                 try {
420                     super.reload(oleERSform, result, request, response);
421                 } catch (Exception e) {
422                     LOG.error("Exception while reloading the e-resource document"+e.getMessage());
423                 }
424             }
425             oleERSform.setRemoveInstanceFlag(false);
426         }
427         if (StringUtils.isNotBlank(oleeResourceRecordDocument.getFundCode())){
428             Map fundCodeMap=new HashMap();
429             fundCodeMap.put(OLEConstants.OLEBatchProcess.VENDOR_REF_NUMBER,oleeResourceRecordDocument.getFundCode());
430             OleVendorAccountInfo oleVendorAccountInfo = getBusinessObjectService().findByPrimaryKey(OleVendorAccountInfo.class, fundCodeMap);
431             if (oleVendorAccountInfo==null){
432                 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.FUND_CODE,OLEConstants.OLEEResourceRecord.ERROR_FUND_CODE);
433             }
434         }
435         return super.approve(oleERSform, result, request, response);
436     }
437 
438     /*@Override
439     @RequestMapping(params = "methodToCall=cancel")
440     public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
441                                HttpServletRequest request, HttpServletResponse response) {
442         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
443         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
444         if (oleeResourceRecordDocument != null) {
445             Map<String, String> criteriaStatusIdMap = new HashMap<String, String>();
446             criteriaStatusIdMap.put(OLEConstants.OLEEResourceRecord.STATUS_NAME, OLEConstants.OLEEResourceRecord.CANCELED);
447             List<OLEEResourceStatus> oleERSStatusList = (List<OLEEResourceStatus>) getBusinessObjectService().findMatching(OLEEResourceStatus.class, criteriaStatusIdMap);
448             if (oleERSStatusList.size() > 0) {
449                 OLEEResourceStatus oleERSStatus = oleERSStatusList.get(0);
450                 if (oleERSStatus != null) {
451                     oleeResourceRecordDocument.setStatusId(oleERSStatus.getOleEResourceStatusId());
452                     oleeResourceRecordDocument.setStatusName(oleERSStatus.getOleEResourceStatusName());
453                 }
454             }
455         }
456         try {
457             save(oleERSform, result, request, response);
458         } catch (Exception e) {
459             throw new RuntimeException(e);
460         }
461         return super.cancel(oleERSform, result, request, response);
462     }
463 */
464 
465     /**
466      * Create E-Instance document instance contained on the form
467      *
468      * @param form - document form base containing the document instance that will be routed
469      * @return ModelAndView
470      */
471     @RequestMapping(params = "methodToCall=createInstance")
472     public ModelAndView createInstance(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
473                                        HttpServletRequest request, HttpServletResponse response) {
474         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
475         oleERSform.setSelectFlag(true);
476         oleERSform.setLinkInstance(false);
477         oleERSform.setCreateInstance(true);
478         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
479         return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
480     }
481 
482     /**
483      * close the popup in instance tab
484      *
485      * @param form - document form base containing the document instance that will be routed
486      * @return ModelAndView
487      */
488     @RequestMapping(params = "methodToCall=closePopup")
489     public ModelAndView closePopup(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
490                                    HttpServletRequest request, HttpServletResponse response) {
491         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
492         return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
493     }
494 
495     /**
496      * This method takes List of UUids as parameter and creates a LinkedHashMap with instance as key and id as value. and calls
497      * Docstore's QueryServiceImpl class getWorkBibRecords method and return workBibDocument for passed instance Id.
498      *
499      * @param instanceIdsList
500      * @return List<WorkBibDocument>
501      */
502 //    private List<WorkBibDocument> getWorkBibDocuments(List<String> instanceIdsList, String docType) {
503 //        List<LinkedHashMap<String, String>> instanceIdMapList = new ArrayList<LinkedHashMap<String, String>>();
504 //        for (String instanceId : instanceIdsList) {
505 //            LinkedHashMap<String, String> instanceIdMap = new LinkedHashMap<String, String>();
506 //            instanceIdMap.put(docType, instanceId);
507 //            instanceIdMapList.add(instanceIdMap);
508 //        }
509 //
510 //        QueryService queryService = QueryServiceImpl.getInstance();
511 //        List<WorkBibDocument> workBibDocuments = new ArrayList<WorkBibDocument>();
512 //        try {
513 //            workBibDocuments = queryService.getWorkBibRecords(instanceIdMapList);
514 //        } catch (Exception ex) {
515 //            // TODO Auto-generated catch block
516 //            ex.printStackTrace();
517 //        }
518 //        return workBibDocuments;
519 //    }
520 
521     /**
522      * Called by the delete line action for a model collection. Method
523      * determines which collection the action was selected for and the line
524      * index that should be removed, then invokes the view helper service to
525      * process the action
526      */
527     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=removeInstance")
528     public ModelAndView removeInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
529                                        HttpServletRequest request, HttpServletResponse response) {
530 
531         OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) uifForm;
532         OLEEResourceRecordDocument oleEResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
533         String selectedCollectionPath = oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
534         if (StringUtils.isBlank(selectedCollectionPath)) {
535             throw new RuntimeException(OLEConstants.OLEEResourceRecord.BLANK_SELECTED_INDEX);
536         }
537         int selectedLineIndex = -1;
538         String selectedLine = oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
539         if (StringUtils.isNotBlank(selectedLine)) {
540             OLEEResourceInstance oleERSInstance = oleEResourceRecordDocument.getOleERSInstances().get(Integer.parseInt(selectedLine));
541             Map removePOMap = new HashMap();
542             removePOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_INSTANCE_ID, oleERSInstance.getInstanceId());
543             removePOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSInstance.getOleERSIdentifier());
544             List<OLEEResourcePO> oleERSPOs = (List<OLEEResourcePO>) getBusinessObjectService().findMatching(OLEEResourcePO.class, removePOMap);
545             removePOMap.remove(OLEConstants.OLEEResourceRecord.ERESOURCE_INSTANCE_ID);
546             removePOMap.put(OLEConstants.HOLDINGS_ID, oleERSInstance.getInstanceId());
547             List<OLEEResourceInvoices> oleERSInvoices = (List<OLEEResourceInvoices>) getBusinessObjectService().findMatching(OLEEResourceInvoices.class, removePOMap);
548             if (oleERSPOs.size() > 0) {
549                 if (oleERSInvoices.size()>0){
550                     for (int i = 0; i < oleERSInvoices.size(); i++) {
551                         for (int j = 0; j < oleEResourceRecordDocument.getOleERSInvoices().size(); j++) {
552                             if (oleEResourceRecordDocument.getOleERSInvoices().get(j).getOleEResInvoiceId().equals(oleERSInvoices.get(i).getOleEResInvoiceId())) {
553                                 oleEResourceRecordDocument.getOleERSInvoices().remove(j);
554                             }
555                         }
556                     }
557                 }
558                 for (int i = 0; i < oleERSPOs.size(); i++) {
559                     for (int j = 0; j < oleEResourceRecordDocument.getOleERSPOItems().size(); j++) {
560                         if (oleEResourceRecordDocument.getOleERSPOItems().get(j).getOleEResPOId().equals(oleERSPOs.get(i).getOleEResPOId())) {
561                             oleEResourceRecordDocument.getOleERSPOItems().remove(j);
562                         }
563                     }
564                 }
565             }
566             try {
567                 Holdings holdings = new EHoldings();
568                 OleHoldings oleHoldings = new OleHoldings();
569                 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleERSInstance.getInstanceId());
570                 if (holdings instanceof EHoldings) {
571                     oleHoldings = new HoldingOlemlRecordProcessor().fromXML(holdings.getContent());
572                     oleHoldings.setEResourceId(null);
573                     holdings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
574                     getDocstoreClientLocator().getDocstoreClient().updateHoldings(holdings);
575                 }
576             } catch (Exception e) {
577                 LOG.error("Illegal exception while updating instance record" + e.getMessage());
578             }
579             selectedLineIndex = Integer.parseInt(selectedLine);
580             OLEEResourceEventLog oleEResourceEventLog = new OLEEResourceEventLog();
581             oleEResourceEventLog.setCurrentTimeStamp();
582             oleEResourceEventLog.setEventUser(GlobalVariables.getUserSession().getPrincipalName());
583             oleEResourceEventLog.setEventNote(oleERSInstance.getInstanceTitle() + OLEConstants.OLEEResourceRecord.INSTANCE_ID_REMOVE_NOTE + oleERSInstance.getInstanceId() + OLEConstants.OLEEResourceRecord.REMOVE_NOTE);
584             oleEResourceEventLog.setEventType(OLEConstants.OLEEResourceRecord.SYSTEM);
585             oleEResourceRecordDocument.getOleERSEventLogs().add(oleEResourceEventLog);
586         }
587         if (selectedLineIndex == -1) {
588             throw new RuntimeException(OLEConstants.OLEEResourceRecord.BLANK_SELECTED_INDEX);
589         }
590         oleEResourceRecordForm.setRemoveInstanceFlag(true);
591         View view = oleEResourceRecordForm.getPostedView();
592         view.getViewHelperService().processCollectionDeleteLine(view, oleEResourceRecordForm, selectedCollectionPath,
593                 selectedLineIndex);
594         return getUIFModelAndView(oleEResourceRecordForm);
595     }
596 
597 
598     /**
599      * This method returns the object of OleLicesneRequestService
600      *
601      * @return oleLicenseRequestService
602      */
603     public OleLicenseRequestWebService getOleLicenseRequestService() {
604         if (oleLicenseRequestWebService == null) {
605             oleLicenseRequestWebService = GlobalResourceLoader.getService(OLEConstants.OleLicenseRequest.HELPER_SERVICE);
606         }
607         return oleLicenseRequestWebService;
608     }
609 
610     public KualiRuleService getKualiRuleService() {
611         if (kualiRuleService == null) {
612             kualiRuleService = GlobalResourceLoader.getService(OLEConstants.KUALI_RULE_SERVICE);
613         }
614         return kualiRuleService;
615     }
616 
617     public BusinessObjectService getBusinessObjectService() {
618         if (businessObjectService == null) {
619             businessObjectService = KRADServiceLocator.getBusinessObjectService();
620         }
621         return businessObjectService;
622     }
623 
624     public OLEEResourceSearchService getOleEResourceSearchService() {
625         if (oleEResourceSearchService == null) {
626             oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
627         }
628         return oleEResourceSearchService;
629     }
630 
631 
632     /**
633      * Edit Default Coverage date for E-Instance
634      *
635      * @param form - document form base containing the document instance that will be routed
636      * @return ModelAndView
637      */
638     @RequestMapping(params = "methodToCall=editDefaultCoverage")
639     public ModelAndView editDefaultCoverage(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
640                                             HttpServletRequest request, HttpServletResponse response) {
641         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
642         oleERSform.setCoverageFlag(true);
643         oleERSform.setPerpetualAccessFlag(false);
644         oleERSform.setDefaultDatesFlag(true);
645         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
646         String defaultCov = oleeResourceRecordDocument.getDummyDefaultCoverage();
647         if(defaultCov != null && !defaultCov.isEmpty()) {
648             oleeResourceRecordDocument.setCovEdited(true);
649             getOleEResourceSearchService().getDefaultCovDatesToPopup(oleeResourceRecordDocument,defaultCov);
650         }
651         return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
652     }
653 
654     /**
655      * Edit Default Perpetual date for E-Instance
656      *
657      * @param form - document form base containing the document instance that will be routed
658      * @return ModelAndView
659      */
660     @RequestMapping(params = "methodToCall=editDefaultPerpetualAccess")
661     public ModelAndView editDefaultPerpetualAccess(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
662                                                    HttpServletRequest request, HttpServletResponse response) {
663         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
664         oleERSform.setCoverageFlag(false);
665         oleERSform.setPerpetualAccessFlag(true);
666         oleERSform.setDefaultDatesFlag(true);
667         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
668         String defaultPerAcc = oleeResourceRecordDocument.getDummyDefaultPerpetualAccess();
669         if(defaultPerAcc != null && !defaultPerAcc.isEmpty()) {
670             oleeResourceRecordDocument.setPerAccEdited(true);
671             getOleEResourceSearchService().getDefaultPerAccDatesToPopup(oleeResourceRecordDocument,defaultPerAcc);
672         }
673         return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
674     }
675 
676     /**
677      * close the popup in instance tab
678      *
679      * @param form - document form base containing the document instance that will be routed
680      * @return ModelAndView
681      */
682     @RequestMapping(params = "methodToCall=closeCoverageOrPerpetualAccessDate")
683     public ModelAndView closeCoverageOrPerpetualAccessDate(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
684                                                            HttpServletRequest request, HttpServletResponse response) {
685         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
686         oleERSform.setDefaultDatesFlag(false);
687         oleERSform.setDefaultCovStartDateErrorMessage(null);
688         oleERSform.setDefaultCovEndDateErrorMessage(null);
689         oleERSform.setDefaultPerAccStartDateErrorMessage(null);
690         oleERSform.setDefaultPerAccEndDateErrorMessage(null);
691         return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
692     }
693 
694     /**
695      * refresh the instance tab
696      *
697      * @param form - document form base containing the document instance that will be routed
698      * @return ModelAndView
699      */
700     @RequestMapping(params = "methodToCall=refreshDefaultDate")
701     public ModelAndView refreshDefaultDate(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
702                                            HttpServletRequest request, HttpServletResponse response) {
703         OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
704         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
705         if(oleERSform.isCoverageFlag()) {
706             getOleEResourceSearchService().getDefaultCovergeDate(oleeResourceRecordDocument);
707             oleERSform.setCoverageFlag(false);
708         }
709         if(oleERSform.isPerpetualAccessFlag()) {
710             getOleEResourceSearchService().getDefaultPerpetualAccessDate(oleeResourceRecordDocument);
711             oleERSform.setPerpetualAccessFlag(false);
712         }
713         return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
714     }
715 
716     @RequestMapping(params = "methodToCall=addMaterialType")
717     public ModelAndView addMaterialType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
718                                            HttpServletRequest request, HttpServletResponse response) {
719         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
720         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
721         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
722         index++;
723         List<OLEMaterialTypeList> oleMaterialTypeLists=oleeResourceRecordDocument.getOleMaterialTypes();
724         oleeResourceRecordDocument.getOleMaterialTypes().add(index, new OLEMaterialTypeList());
725         oleeResourceRecordDocument.setOleMaterialTypes(oleMaterialTypeLists);
726         form.setDocument(oleeResourceRecordDocument);
727         return super.navigate(form, result, request, response);
728     }
729 
730     @RequestMapping(params = "methodToCall=removeMaterialType")
731     public ModelAndView removeMaterialType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
732                                            HttpServletRequest request, HttpServletResponse response) {
733         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
734         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
735         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
736         List<OLEMaterialTypeList> oleMaterialTypeLists=oleeResourceRecordDocument.getOleMaterialTypes();
737         if (oleMaterialTypeLists.size() > 1) {
738             oleMaterialTypeLists.remove(index);
739         }
740         form.setDocument(oleeResourceRecordDocument);
741         return super.navigate(form, result, request, response);
742     }
743 
744     @RequestMapping(params = "methodToCall=addFormatType")
745     public ModelAndView addFormatType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
746                                         HttpServletRequest request, HttpServletResponse response) {
747         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
748         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
749         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
750         index++;
751         List<OLEFormatTypeList> oleFormatTypeLists=oleeResourceRecordDocument.getOleFormatTypes();
752         oleeResourceRecordDocument.getOleFormatTypes().add(index, new OLEFormatTypeList());
753         oleeResourceRecordDocument.setOleFormatTypes(oleFormatTypeLists);
754         form.setDocument(oleeResourceRecordDocument);
755         return super.navigate(form, result, request, response);
756     }
757 
758     @RequestMapping(params = "methodToCall=removeFormatType")
759     public ModelAndView removeFormatType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
760                                            HttpServletRequest request, HttpServletResponse response) {
761         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
762         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
763         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
764         List<OLEFormatTypeList> oleFormatTypeLists=oleeResourceRecordDocument.getOleFormatTypes();
765         if (oleFormatTypeLists.size() > 1) {
766             oleFormatTypeLists.remove(index);
767         }
768         form.setDocument(oleeResourceRecordDocument);
769         return super.navigate(form, result, request, response);
770     }
771 
772     @RequestMapping(params = "methodToCall=addContentType")
773     public ModelAndView addContentType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
774                                         HttpServletRequest request, HttpServletResponse response) {
775         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
776         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
777         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
778         index++;
779         List<OLEContentTypes> oleContentTypes=oleeResourceRecordDocument.getOleContentTypes();
780         oleeResourceRecordDocument.getOleContentTypes().add(index, new OLEContentTypes());
781         oleeResourceRecordDocument.setOleContentTypes(oleContentTypes);
782         form.setDocument(oleeResourceRecordDocument);
783         return super.navigate(form, result, request, response);
784     }
785 
786     @RequestMapping(params = "methodToCall=removeContentType")
787     public ModelAndView removeContentType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
788                                            HttpServletRequest request, HttpServletResponse response) {
789         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
790         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
791         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
792         List<OLEContentTypes> oleContentTypes=oleeResourceRecordDocument.getOleContentTypes();
793         if (oleContentTypes.size() > 1) {
794             oleContentTypes.remove(index);
795         }
796         form.setDocument(oleeResourceRecordDocument);
797         return super.navigate(form, result, request, response);
798     }
799 
800 
801     @RequestMapping(params = "methodToCall=addSelectorType")
802     public ModelAndView addSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
803                                        HttpServletRequest request, HttpServletResponse response) {
804         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
805         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
806         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
807         index++;
808         List<OLEEResourceSelector> oleeResourceSelectors=oleeResourceRecordDocument.getSelectors();
809         oleeResourceRecordDocument.getSelectors().add(index, new OLEEResourceSelector());
810         oleeResourceRecordDocument.setSelectors(oleeResourceSelectors);
811         form.setDocument(oleeResourceRecordDocument);
812         return super.navigate(form, result, request, response);
813     }
814 
815     @RequestMapping(params = "methodToCall=removeSelectorType")
816     public ModelAndView removeSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
817                                           HttpServletRequest request, HttpServletResponse response) {
818         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
819         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
820         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
821         List<OLEEResourceSelector> oleeResourceSelectors=oleeResourceRecordDocument.getSelectors();
822         if (oleeResourceSelectors.size() > 1) {
823             oleeResourceSelectors.remove(index);
824         }
825         form.setDocument(oleeResourceRecordDocument);
826         return super.navigate(form, result, request, response);
827     }
828 
829     @RequestMapping(params = "methodToCall=addRequestorType")
830     public ModelAndView addRequestorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
831                                        HttpServletRequest request, HttpServletResponse response) {
832         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
833         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
834         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
835         index++;
836         List<OLEEResourceRequestor> oleeResourceRequestors=oleeResourceRecordDocument.getRequestors();
837         oleeResourceRecordDocument.getRequestors().add(index, new OLEEResourceRequestor());
838         oleeResourceRecordDocument.setRequestors(oleeResourceRequestors);
839         form.setDocument(oleeResourceRecordDocument);
840         return super.navigate(form, result, request, response);
841     }
842 
843     @RequestMapping(params = "methodToCall=removeRequestorType")
844     public ModelAndView removeRequestorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
845                                           HttpServletRequest request, HttpServletResponse response) {
846         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
847         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
848         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
849         List<OLEEResourceRequestor> oleeResourceRequestors=oleeResourceRecordDocument.getRequestors();
850         if (oleeResourceRequestors.size() > 1) {
851             oleeResourceRequestors.remove(index);
852         }
853         form.setDocument(oleeResourceRecordDocument);
854         return super.navigate(form, result, request, response);
855     }
856 
857     @RequestMapping(params = "methodToCall=addRequestorSelectorType")
858     public ModelAndView addRequestorSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
859                                        HttpServletRequest request, HttpServletResponse response) {
860         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
861         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
862         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
863         index++;
864         List<OLEEResourceReqSelComments> oleeResourceReqSelCommentses=oleeResourceRecordDocument.getReqSelComments();
865         oleeResourceRecordDocument.getReqSelComments().add(index, new OLEEResourceReqSelComments());
866         oleeResourceRecordDocument.setReqSelComments(oleeResourceReqSelCommentses);
867         form.setDocument(oleeResourceRecordDocument);
868         return super.navigate(form, result, request, response);
869     }
870 
871     @RequestMapping(params = "methodToCall=removeRequestorSelectorType")
872     public ModelAndView removeRequestorSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
873                                           HttpServletRequest request, HttpServletResponse response) {
874         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
875         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
876         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
877         List<OLEEResourceReqSelComments> oleeResourceReqSelCommentses=oleeResourceRecordDocument.getReqSelComments();
878         if (oleeResourceReqSelCommentses.size() > 1) {
879             oleeResourceReqSelCommentses.remove(index);
880         }
881         form.setDocument(oleeResourceRecordDocument);
882         return super.navigate(form, result, request, response);
883     }
884 
885     @RequestMapping(params = "methodToCall=addNoteTextSection")
886     public ModelAndView addNoteTextSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
887                                                  HttpServletRequest request, HttpServletResponse response) {
888         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
889         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
890         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
891         index++;
892         List<OLEEResourceNotes> oleeResourceNoteses=oleeResourceRecordDocument.getEresNotes();
893         oleeResourceRecordDocument.getEresNotes().add(index, new OLEEResourceNotes());
894         oleeResourceRecordDocument.setEresNotes(oleeResourceNoteses);
895         form.setDocument(oleeResourceRecordDocument);
896         return super.navigate(form, result, request, response);
897     }
898 
899     @RequestMapping(params = "methodToCall=removeNoteTextSection")
900     public ModelAndView removeNoteTextSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
901                                                     HttpServletRequest request, HttpServletResponse response) {
902         OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
903         OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
904         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
905         List<OLEEResourceNotes> oleeResourceNoteses=oleeResourceRecordDocument.getEresNotes();
906         if (oleeResourceNoteses.size() > 1) {
907             oleeResourceNoteses.remove(index);
908         }
909         form.setDocument(oleeResourceRecordDocument);
910         return super.navigate(form, result, request, response);
911     }
912 
913 
914 
915 }