View Javadoc

1   package org.kuali.ole.license.controller;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.PropertyUtil;
6   import org.kuali.ole.editor.service.OleWebServiceProvider;
7   import org.kuali.ole.ingest.pojo.MatchBo;
8   import org.kuali.ole.license.bo.*;
9   import org.kuali.ole.service.OleLicenseRequestService;
10  import org.kuali.ole.service.OleRequisitionWebService;
11  import org.kuali.ole.service.impl.OleLicenseRequestServiceImpl;
12  import org.kuali.rice.core.api.config.property.ConfigurationService;
13  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
14  import org.kuali.rice.core.api.util.RiceKeyConstants;
15  import org.kuali.rice.kew.actionitem.ActionItem;
16  import org.kuali.rice.kew.actionlist.service.ActionListService;
17  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
18  import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
19  import org.kuali.rice.kew.api.action.ActionRequest;
20  import org.kuali.rice.kew.service.KEWServiceLocator;
21  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
22  import org.kuali.rice.krad.service.KRADServiceLocator;
23  import org.kuali.rice.krad.uif.UifConstants;
24  import org.kuali.rice.krad.uif.UifParameters;
25  import org.kuali.rice.krad.uif.container.CollectionGroup;
26  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  import org.kuali.rice.krad.util.KRADConstants;
29  import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
30  import org.kuali.rice.krad.web.form.DocumentFormBase;
31  import org.kuali.rice.krad.web.form.MaintenanceForm;
32  import org.kuali.rice.krad.web.form.UifFormBase;
33  import org.kuali.rice.krms.api.KrmsApiServiceLocator;
34  import org.kuali.rice.krms.api.engine.*;
35  import org.kuali.rice.krms.impl.repository.AgendaBo;
36  import org.springframework.stereotype.Controller;
37  import org.springframework.util.FileCopyUtils;
38  import org.springframework.validation.BindingResult;
39  import org.springframework.web.bind.annotation.ModelAttribute;
40  import org.springframework.web.bind.annotation.RequestMapping;
41  import org.springframework.web.multipart.MultipartFile;
42  import org.springframework.web.servlet.ModelAndView;
43  
44  import javax.servlet.http.HttpServletRequest;
45  import javax.servlet.http.HttpServletResponse;
46  import java.io.*;
47  import java.sql.Timestamp;
48  import java.util.*;
49  
50  /**
51   * OleLicenseRequestController is the controller class for License Request Maintenance Document.
52   */
53  @Controller
54  @RequestMapping(value = "/oleLicenseRequest")
55  public class OleLicenseRequestController extends MaintenanceDocumentController {
56  
57      private OleLicenseRequestService oleLicenseRequestService;
58      private final static String RULE_EVALUATED = "Rule Evaluated";
59      private final static String ROUTED_EXTERNAL = "Routed External";
60  
61      private OleLicenseRequestService getOleLicenseRequestService() {
62          if(oleLicenseRequestService == null) {
63              oleLicenseRequestService = new OleLicenseRequestServiceImpl();
64          }
65          return oleLicenseRequestService;
66      }
67  
68      /**
69       *  This method populates date of the eventlog object thereby adding to the existing list.
70       * @param uifForm
71       * @param result
72       * @param request
73       * @param response
74       * @return ModelAndView
75       */
76      @RequestMapping(params = "methodToCall=addEventLogLine")
77      public ModelAndView addEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
78                                  HttpServletRequest request, HttpServletResponse response) {
79          MaintenanceForm form = (MaintenanceForm) uifForm;
80          String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
81          CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
82                  selectedCollectionPath);
83          String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
84          Object eventObject = ObjectPropertyUtils.getPropertyValue(uifForm, addLinePath);
85          OleEventLogBo oleEventLogBo = (OleEventLogBo) eventObject;
86          //oleEventLogBo.setEventType("user");
87          oleEventLogBo.setCurrentTimeStamp();
88          return addLine(uifForm, result, request, response);
89      }
90  
91      /**
92       *  This method sets appropriate LicenseRequestStatusCode and gets the UUIDs for the agreement document from the docstore 
93       *   	(ingesting into the docstore) and proceeds with normal routing.
94       * @param form
95       * @param result
96       * @param result
97       * @param request
98       * @param response
99       * @return ModelAndView
100      */
101     @Override
102     @RequestMapping(params = "methodToCall=route")
103     public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
104                               HttpServletRequest request, HttpServletResponse response) {
105 
106         MaintenanceForm maintenanceForm = (MaintenanceForm) form;
107         OleLicenseRequestService oleLicenseRequestService = getOleLicenseRequestService();
108         MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
109         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)document.getNewMaintainableObject().getDataObject();
110         OleLicenseRequestBo oldLicenseRequestBo = (OleLicenseRequestBo)document.getOldMaintainableObject().getDataObject();
111         if (oldLicenseRequestBo != null && oleLicenseRequestBo.getLocationId() != null) {
112             if(oldLicenseRequestBo.getLocationId() != null &&
113                     oleLicenseRequestBo.getLocationId() != OLEConstants.OleLicenseRequest.LICENSE_INITIAL_LOCATON &&
114                     !oleLicenseRequestBo.getLocationId().equals(oldLicenseRequestBo.getLocationId())) {
115                 Map criteria = new HashMap();
116                 criteria.put("id",oleLicenseRequestBo.getLocationId());
117                 OleLicenseRequestLocation location = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleLicenseRequestLocation.class,
118                         criteria);
119                 OleEventLogBo oleEventLogBo = new OleEventLogBo();
120                 oleEventLogBo.setEventType("location : " +location.getDescription());
121                 oleEventLogBo.setCurrentTimeStamp();
122                 oleEventLogBo.setCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
123                 oleEventLogBo.setEventDescription(ROUTED_EXTERNAL);
124                 oleLicenseRequestBo.getEventLogs().add(oleEventLogBo);
125             }
126         }
127         HashMap<String,String> licenses = new HashMap<String, String>();
128         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_IN_NEGO,OLEConstants.OleLicenseRequest.LICENSE_IN_NEGO_VALUE);
129         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_IN_PROCESS,OLEConstants.OleLicenseRequest.LICENSE_IN_PROCESS_VALUE);
130         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_INITIAL_WORKFLOW,OLEConstants.OleLicenseRequest.LICENSE_NEEDED);
131         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_RECEIVED,
132                 OLEConstants.OleLicenseRequest.LICENSE_COMPLETE_RETURN);
133         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_REQUESTED,OLEConstants.OleLicenseRequest.LICENSE_REQUESTED_VALUE);
134         if(licenses.containsKey(oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode())){
135             oleLicenseRequestBo.setLicenseRequestStatusCode(licenses.get(oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode()));
136             document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
137                     getLicenseRequestName(licenses.get(oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode())));
138             performWorkflowAction(form, UifConstants.WorkflowAction.SAVE, true);
139             assignActionRequests(document.getDocumentHeader().getDocumentNumber(),oleLicenseRequestBo.getAssignee());
140             return close(form,result,request,response);
141         }
142         //oleLicenseRequestBo.setAgreementId(UUID.randomUUID().toString());
143         //oleLicenseRequestBo.setRequisitionDocNumber("3014");
144         oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.LICENSE_NEEDED);
145         document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
146                 getLicenseRequestName(OLEConstants.OleLicenseRequest.LICENSE_NEEDED));
147         List<OleAgreementDocumentMetadata> agreementDocuments = oleLicenseRequestBo.getAgreementDocumentMetadataList();
148         List<OleAgreementDocumentMetadata> newAgreementDocuments = new ArrayList<OleAgreementDocumentMetadata>();
149         List<OleAgreementDocumentMetadata> checkInAgreementDocuments = new ArrayList<OleAgreementDocumentMetadata>();
150         if(agreementDocuments.size() > 0) {
151             for(OleAgreementDocumentMetadata agreementDocument : agreementDocuments) {
152                 if(isNewAgreementDocument(agreementDocument))
153                     newAgreementDocuments.add(agreementDocument);
154                 else
155                     checkInAgreementDocuments.add(agreementDocument);
156             }
157         }
158         List<OleAgreementDocumentMetadata> agreementDocumentMetadataList = new ArrayList<OleAgreementDocumentMetadata>();
159         if(newAgreementDocuments.size() > 0) {
160             agreementDocumentMetadataList.addAll(oleLicenseRequestService.processIngestAgreementDocuments(newAgreementDocuments));
161         }
162         if(checkInAgreementDocuments.size() > 0) {
163             agreementDocumentMetadataList.addAll(oleLicenseRequestService.processCheckInAgreementDocuments(checkInAgreementDocuments));
164         }
165         oleLicenseRequestBo.setAgreementDocumentMetadataList(agreementDocumentMetadataList);
166         String licenseRequestWorkflowTypeCode = oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode();
167         if(licenseRequestWorkflowTypeCode.equalsIgnoreCase(OLEConstants.OleLicenseRequest.SIGNATORY_ONLY))  {
168             oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.PENDING_SIGNATURE);
169             document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
170                     getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
171         }else if(licenseRequestWorkflowTypeCode.equalsIgnoreCase(OLEConstants.OleLicenseRequest.REVIEW_ONLY))  {
172             oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.PENDING_REVIEW);
173             document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
174                     getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
175         }else if(licenseRequestWorkflowTypeCode.equalsIgnoreCase(OLEConstants.OleLicenseRequest.APPROVE_ONLY))  {
176             oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.PENDING_APPROVAL);
177             document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
178                     getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
179         }else if(licenseRequestWorkflowTypeCode.equalsIgnoreCase(OLEConstants.OleLicenseRequest.FULL_APPROVAL)
180                 || licenseRequestWorkflowTypeCode.equalsIgnoreCase(OLEConstants.OleLicenseRequest.ADDENDUM)){
181             oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.PENDING_REVIEW);
182             document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
183                     getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
184         }
185 
186         boolean valid = false;
187         EngineResults engineResult = executeEngineResults(oleLicenseRequestBo);
188         List<ResultEvent> allResults = engineResult.getAllResults();
189         for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) {
190             ResultEvent resultEvent = resultEventIterator.next();
191             if (resultEvent.getType().equals(RULE_EVALUATED)) {
192                 valid |= resultEvent.getResult();
193             }
194         }
195         if(!valid){
196             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.LICENSE_RULE_VAILDATIONS);
197         }
198 
199         String currentUser = GlobalVariables.getUserSession().getPrincipalName();
200         if(currentUser.equalsIgnoreCase(oleLicenseRequestBo.getAssignee()) && oleLicenseRequestBo.getEventLogs().size()<1){
201             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.LICENSE_EVENT_LOG_CHECK );
202         }
203         if(oleLicenseRequestBo.getLinkedAgreement() != null & oleLicenseRequestBo.getAgreementId() == null) {
204             String agreementcontent = oleLicenseRequestService.getAgreementContent(oleLicenseRequestBo.getLinkedAgreement());
205             if(agreementcontent != null) {
206                 oleLicenseRequestBo.setAgreementId(oleLicenseRequestService.ingestAgreementContent(agreementcontent));
207                 oleLicenseRequestBo.setLinkedAgreement("");
208             }
209             else {
210                 LOG.error("Error while retrieving the onixpl content");
211             }
212         }
213         //modelAndView = super.route(form, result, request, response);
214 
215         return super.route(form, result, request, response);
216     }
217 
218     /**
219      * This method is to return the License Request Status
220      */
221     private String getLicenseRequestName(String licenseRequestCode) {
222         String licenseRequestStatusName = "";
223         Map criteria = new HashMap();
224         criteria.put("code",licenseRequestCode);
225         OleLicenseRequestStatus licenseRequestStatus = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleLicenseRequestStatus.class,
226                 criteria);
227         licenseRequestStatusName = licenseRequestStatus.getName();
228         return licenseRequestStatusName;
229     }
230 
231     /**
232      *
233      * This method assigns specified document to the selector.
234      */
235     private void assignActionRequests(String routeHeaderId,String selectedUserId){
236         LOG.debug("Inside assignActionRequests of LicenseRequestDocument");
237        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
238         ActionListService actionListSrv = KEWServiceLocator.getActionListService();
239         ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
240         List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
241         for(ActionRequestValue actionRequest:actionReqValues){
242             List<ActionItem> actionItems = actionRequest.getActionItems();
243             for(ActionItem actionItem:actionItems){
244                 actionItem.setPrincipalId(selectedUserId);
245                 actionItem.setDateAssigned(currentTime);
246                 actionListSrv.saveActionItem(actionItem);
247             }
248             actionRequest.setPrincipalId(selectedUserId);
249             actionRequest.setCreateDate(currentTime);
250             //actionRequest.setAnnotation("KR-LIC Owner");
251             actionReqSrv.saveActionRequest(actionRequest);
252         }
253         LOG.debug("Leaving assignActionRequests of LicenseRequestDocument");
254     }
255 
256 
257     /**
258      * Performs the approve workflow action on the document
259      *
260      * @param form - document form base containing the document instance that will be approved
261      * @return ModelAndView
262      */
263     @RequestMapping(params = "methodToCall=approve")
264     public ModelAndView approve(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
265                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
266         MaintenanceForm oldMaintenanceForm = (MaintenanceForm) form;
267         MaintenanceDocument oldDocument= (MaintenanceDocument) oldMaintenanceForm.getDocument();
268         OleLicenseRequestBo oldOleLicenseRequestBo = (OleLicenseRequestBo)oldDocument.getNewMaintainableObject().getDataObject();
269         OleLicenseRequestBo oldLicenseRequestBo = (OleLicenseRequestBo)oldDocument.getOldMaintainableObject().getDataObject();
270         if (oldLicenseRequestBo != null && oldOleLicenseRequestBo.getLocationId() != null) {
271             if(oldLicenseRequestBo.getLocationId() != null &&
272                     oldOleLicenseRequestBo.getLocationId().equals(OLEConstants.OleLicenseRequest.LICENSE_INITIAL_LOCATON) &&
273                     !oldOleLicenseRequestBo.getLocationId().equals(oldLicenseRequestBo.getLocationId())) {
274                 Map criteria = new HashMap();
275                 criteria.put("id",oldOleLicenseRequestBo.getLocationId());
276                 OleLicenseRequestLocation location = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleLicenseRequestLocation.class,
277                         criteria);
278                 OleEventLogBo oleEventLogBo = new OleEventLogBo();
279                 oleEventLogBo.setEventType("location : " +location.getDescription());
280                 oleEventLogBo.setCurrentTimeStamp();
281                 oleEventLogBo.setCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
282                 oleEventLogBo.setEventDescription(ROUTED_EXTERNAL);
283                 oldOleLicenseRequestBo.getEventLogs().add(oleEventLogBo);
284             }
285         }
286         //Ingesting the Agreement Documents
287         List<OleAgreementDocumentMetadata> agreementDocuments = oldOleLicenseRequestBo.getAgreementDocumentMetadataList();
288         OleLicenseRequestService oleLicenseRequestService = getOleLicenseRequestService();
289         List<OleAgreementDocumentMetadata> newAgreementDocuments = new ArrayList<OleAgreementDocumentMetadata>();
290         List<OleAgreementDocumentMetadata> checkInAgreementDocuments = new ArrayList<OleAgreementDocumentMetadata>();
291         if(agreementDocuments.size() > 0) {
292             for(OleAgreementDocumentMetadata agreementDocument : agreementDocuments) {
293                 if(isNewAgreementDocument(agreementDocument))
294                     newAgreementDocuments.add(agreementDocument);
295                 else
296                     checkInAgreementDocuments.add(agreementDocument);
297             }
298         }
299         List<OleAgreementDocumentMetadata> agreementDocumentMetadataList = new ArrayList<OleAgreementDocumentMetadata>();
300         if(newAgreementDocuments.size() > 0) {
301             agreementDocumentMetadataList.addAll(oleLicenseRequestService.processIngestAgreementDocuments(newAgreementDocuments));
302         }
303         if(checkInAgreementDocuments.size() > 0) {
304             agreementDocumentMetadataList.addAll(oleLicenseRequestService.processCheckInAgreementDocuments(checkInAgreementDocuments));
305         }
306         oldOleLicenseRequestBo.setAgreementDocumentMetadataList(agreementDocumentMetadataList);
307 
308         List<ActionRequest> oldActionRequests = oldDocument.getDocumentHeader().getWorkflowDocument().getDocumentDetail().getActionRequests();
309         String oldRoleName="";
310         for(ActionRequest oldActionRequest : oldActionRequests){
311             if(oldActionRequest.getStatus().getCode().equalsIgnoreCase("A")){
312                 oldRoleName = oldActionRequest.getQualifiedRoleNameLabel()!=null?oldActionRequest.getQualifiedRoleNameLabel():"No Role";
313             }
314         }
315         boolean validRule = false;
316         EngineResults engineResult = executeEngineResults((OleLicenseRequestBo)oldDocument.getNewMaintainableObject().getDataObject());
317         List<ResultEvent> allResults = engineResult.getAllResults();
318         for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) {
319             ResultEvent resultEvent = resultEventIterator.next();
320             if (resultEvent.getType().equals(RULE_EVALUATED)) {
321                 validRule |= resultEvent.getResult();
322             }
323         }
324         if(!validRule){
325             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.LICENSE_RULE_VAILDATIONS);
326         }
327         String currentUser = GlobalVariables.getUserSession().getPrincipalName();
328         boolean eventLogCheck = currentUser.equalsIgnoreCase(oldOleLicenseRequestBo.getAssignee()) && oldOleLicenseRequestBo.getEventLogs().size()<1;
329         if(eventLogCheck){
330             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.LICENSE_EVENT_LOG_CHECK );
331         }
332         if(!validRule || eventLogCheck){
333             return getUIFModelAndView(form);
334         }
335         //form.setAnnotation(oldRoleName);
336         performWorkflowAction(form, UifConstants.WorkflowAction.APPROVE, true);
337         MaintenanceForm maintenanceForm = (MaintenanceForm) form;
338         MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
339         List<ActionRequest> actionRequests = document.getDocumentHeader().getWorkflowDocument().getDocumentDetail().getActionRequests();
340         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)document.getNewMaintainableObject().getDataObject();
341         for(ActionRequest actionRequest :actionRequests){
342             String roleName = actionRequest!=null && actionRequest.getQualifiedRoleNameLabel()!=null?actionRequest.getQualifiedRoleNameLabel():"No Role";
343             if(roleName.equalsIgnoreCase(oldRoleName)){
344                 if(roleName.equalsIgnoreCase(OLEConstants.OleLicenseRequest.SIGNATORY_ROLE_NM) && actionRequest.getStatus().getCode().equalsIgnoreCase("D")){
345                     oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.SIGNATORY_COMPLETE);
346                     document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
347                             getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
348                     form.setAnnotation(OLEConstants.OleLicenseRequest.SIGNATORY_ROLE_NM);
349                     getDocumentService().saveDocument(document);
350                 }else if(roleName.equalsIgnoreCase(OLEConstants.OleLicenseRequest.LICENSE_MNGR_ROLE_NM) && actionRequest.getStatus().getCode().equalsIgnoreCase("D")){
351                     if( oldOleLicenseRequestBo.getLicenseRequestWorkflowTypeCode().equalsIgnoreCase(OLEConstants.OleLicenseRequest.SIGNATORY_ONLY)){
352                         oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.PENDING_SIGNATURE);
353                         document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
354                                 getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
355                     }else if(oldOleLicenseRequestBo.getLicenseRequestWorkflowTypeCode().equalsIgnoreCase(OLEConstants.OleLicenseRequest.REVIEW_ONLY)){
356                         oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.PENDING_REVIEW);
357                         document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
358                                 getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
359                     } else if(oldOleLicenseRequestBo.getLicenseRequestWorkflowTypeCode().equalsIgnoreCase(OLEConstants.OleLicenseRequest.APPROVE_ONLY)){
360                         oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.PENDING_APPROVAL);
361                         document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
362                                 getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
363                     }else{
364                         oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.UNIVERSITY_COMPLETE);
365                         document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
366                                 getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
367                     }
368                     form.setAnnotation(OLEConstants.OleLicenseRequest.LICENSE_MNGR_ROLE_NM);
369                     getDocumentService().saveDocument(document);
370                 }else if(roleName.equalsIgnoreCase(OLEConstants.OleLicenseRequest.REVIEWER_ROLE_NM) && actionRequest.getStatus().getCode().equalsIgnoreCase("D")){
371                     oleLicenseRequestBo.setLicenseRequestStatusCode(
372                             oldOleLicenseRequestBo.getLicenseRequestWorkflowTypeCode().equalsIgnoreCase(OLEConstants.OleLicenseRequest.FULL_APPROVAL)?
373                                     OLEConstants.OleLicenseRequest.PENDING_UNIVERSITY:OLEConstants.OleLicenseRequest.REVIEW_COMPLETE);
374                     document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
375                             getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
376                     form.setAnnotation(OLEConstants.OleLicenseRequest.REVIEWER_ROLE_NM);
377                     getDocumentService().saveDocument(document);
378                 }else if(roleName.equalsIgnoreCase(OLEConstants.OleLicenseRequest.APPROVER_ROLE_NM) && actionRequest.getStatus().getCode().equalsIgnoreCase("D")){
379                     oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.LICENSE_COMPLETE);
380                     document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
381                             getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
382                     form.setAnnotation(OLEConstants.OleLicenseRequest.APPROVER_ROLE_NM);
383                     getDocumentService().saveDocument(document);
384                     OleWebServiceProvider oleWebServiceProvider = (OleWebServiceProvider) GlobalResourceLoader.getService(OLEConstants.OLE_WEB_SERVICE_PROVIDER);
385 
386                     OleRequisitionWebService oleRequisitionWebService =
387                             (OleRequisitionWebService) oleWebServiceProvider.
388                                     getService("org.kuali.ole.service.OleRequisitionWebService", "oleRequisitionWebService", getURL());
389 
390                     oleRequisitionWebService.updateRequisitionStatus(oleLicenseRequestBo.getRequisitionDocNumber(),OLEConstants.OleLicenseRequest.LICENSE_COMPLETE_RETURN );
391                 }
392             }
393         }
394         return returnToPrevious(form);
395     }
396     /**
397      * Performs the disapprove workflow action on the document 
398      *
399      * @param form - document form base containing the document instance that will be disapproved
400      * @return ModelAndView
401      */
402     @RequestMapping(params = "methodToCall=disapprove")
403     public ModelAndView disapprove(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
404                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
405         MaintenanceForm maintenanceForm = (MaintenanceForm) form;
406         MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
407         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)document.getNewMaintainableObject().getDataObject();
408         if(oleLicenseRequestBo.getEventLogs().size()<1){
409             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.LICENSE_DISAPPROVE_VALIDATIONS);
410             return getUIFModelAndView(form);
411         }
412         oleLicenseRequestBo.setLicenseRequestStatusCode(OLEConstants.OleLicenseRequest.NEGOTIATION_FAILED);
413         document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(
414                 getLicenseRequestName(oleLicenseRequestBo.getLicenseRequestStatusCode()));
415         getDocumentService().saveDocument(document);
416         performWorkflowAction(form, UifConstants.WorkflowAction.DISAPPROVE, true);
417 
418         OleWebServiceProvider oleWebServiceProvider = (OleWebServiceProvider) GlobalResourceLoader.getService(OLEConstants.OLE_WEB_SERVICE_PROVIDER);
419 
420         OleRequisitionWebService oleRequisitionWebService =
421                 (OleRequisitionWebService) oleWebServiceProvider.
422                         getService("org.kuali.ole.service.OleRequisitionWebService", "oleRequisitionWebService", getURL());
423 
424         oleRequisitionWebService.updateRequisitionStatus(oleLicenseRequestBo.getRequisitionDocNumber(), OLEConstants.OleLicenseRequest.LICENSE_NEGOTIATION_FAILED);
425         return returnToPrevious(form);
426     }
427 
428     public String getURL() {
429         String url = PropertyUtil.getPropertyUtil().getProperty("oleRequisitionWebService.url");
430         return url;
431     }
432     /**
433      * Perform
434      * @param oleLicenseRequestBo
435      * @return EngineResults
436      */
437     private EngineResults executeEngineResults(OleLicenseRequestBo oleLicenseRequestBo){
438         Engine engine =  KrmsApiServiceLocator.getEngine();
439         EngineResults engineResult =null;
440         HashMap<String, Object> agendaValue = new HashMap<String, Object>();
441         agendaValue.put("nm", OLEConstants.OleLicenseRequest.LICENSE_AGENDA_NM);
442         List<AgendaBo> agendaBos = (List<AgendaBo>) KRADServiceLocator.getBusinessObjectService().findMatching(AgendaBo.class, agendaValue);
443         if(agendaBos!=null && agendaBos.size()>0){
444             AgendaBo agendaBo = agendaBos.get(0);
445             HashMap<String, String> map = new HashMap<String, String>();
446             map.put("AGENDA_NAME", agendaBo.getName());
447             List<MatchBo> matchBos = (List<MatchBo>) KRADServiceLocator.getBusinessObjectService().findMatching(MatchBo.class, map);
448 
449             SelectionCriteria selectionCriteria =
450                     SelectionCriteria.createCriteria(null, getSelectionContext(agendaBo.getContext().getName()), getAgendaContext(OLEConstants.OleLicenseRequest.LICENSE_AGENDA_NM));
451 
452             ExecutionOptions executionOptions = new ExecutionOptions();
453             executionOptions.setFlag(ExecutionFlag.LOG_EXECUTION, true);
454 
455             Facts.Builder factBuilder = Facts.Builder.create();
456 
457             String licenseType = getLicenseType(oleLicenseRequestBo.getLicenseRequestTypeId());
458             String workflowName = getWorkFlowName(oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode()) ;
459             String agreementMethod =oleLicenseRequestBo.getAgreementMethod();
460             HashMap<String,Object> termValues = new HashMap<String, Object>() ;
461 
462             termValues.put("licenseType",licenseType);
463             termValues.put("agreementMethod",agreementMethod);
464             termValues.put("workflowName",workflowName);
465 
466 
467 
468             for (Iterator<MatchBo> matchBoIterator = matchBos.iterator(); matchBoIterator.hasNext(); ) {
469                 MatchBo matchBo = matchBoIterator.next();
470                 factBuilder.addFact(matchBo.getTermName(), termValues.get((matchBo.getTermName())));
471             }
472 
473 
474             engineResult = engine.execute(selectionCriteria, factBuilder.build(), executionOptions);
475         }
476         return engineResult;
477     }
478 
479     /**
480      *   This method returns selectionContext using contextName.
481      * @param contextName
482      * @return Map
483      */
484     protected Map<String, String> getSelectionContext(String contextName) {
485         Map<String, String> selector = new HashMap<String, String>();
486         selector.put(OLEConstants.NAMESPACE_CODE_SELECTOR, "OLE");
487         selector.put(OLEConstants.NAME_SELECTOR, contextName);
488         return selector;
489     }
490 
491     /**
492      *    This method returns agendaContext using agendaName.
493      * @param agendaName
494      * @return Map
495      */
496     protected Map<String, String> getAgendaContext(String agendaName) {
497         Map<String, String> selector = new HashMap<String, String>();
498         selector.put(OLEConstants.NAME_SELECTOR, agendaName);
499         return selector;
500     }
501 
502     /**
503      * This method returns LicenseType using licenseRequestTypeId.
504      * @param licenseRequestTypeId
505      * @return Map
506      */
507     private String getLicenseType(String licenseRequestTypeId){
508         OleLicenseRequestType oleLicenseRequestType = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OleLicenseRequestType.class, licenseRequestTypeId);
509         return oleLicenseRequestType.getName();
510     }
511 
512     /**
513      *   This method returns WorkFlowName using licenseRequestWorkflowTypeCode.
514      * @param licenseRequestWorkflowTypeCode
515      * @return
516      */
517     private String getWorkFlowName(String licenseRequestWorkflowTypeCode){
518         OleLicenseRequestWorkflowType oleLicenseRequestWorkflowType = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OleLicenseRequestWorkflowType.class, licenseRequestWorkflowTypeCode);
519         return oleLicenseRequestWorkflowType.getName();
520     }
521 
522     /**
523      * This method will add the agreement document to the existing list and also stores the attachment 
524      *   to the specified path.
525      *
526      * @param uifForm - MaintenanceForm
527      * @return ModelAndView
528      */	
529     @RequestMapping(params = "methodToCall=insertAgreementDocument")
530     public ModelAndView insertAgreementDocument(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
531                                                 HttpServletRequest request, HttpServletResponse response) {
532 
533         MaintenanceForm form = (MaintenanceForm) uifForm;
534         MultipartFile attachmentFile = form.getAttachmentFile();
535         if(attachmentFile.getOriginalFilename()!= null && !attachmentFile.getOriginalFilename().isEmpty()) {
536             String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
537             CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
538                     selectedCollectionPath);
539             String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
540             Object eventObject = ObjectPropertyUtils.getPropertyValue(uifForm, addLinePath);
541             OleAgreementDocumentMetadata oleAgreementDocumentMetadata = (OleAgreementDocumentMetadata)eventObject;
542             oleAgreementDocumentMetadata.setCurrentTimeStamp();
543             String userName = GlobalVariables.getUserSession().getPrincipalName();
544             oleAgreementDocumentMetadata.setUploadedBy(userName);
545 
546             if (attachmentFile != null && !StringUtils.isBlank(attachmentFile.getOriginalFilename())) {
547                 if (attachmentFile.getSize() == 0) {
548                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS,
549                             RiceKeyConstants.ERROR_UPLOADFILE_EMPTY, attachmentFile.getOriginalFilename());
550                 } else {
551                     try {
552                         oleAgreementDocumentMetadata.setAgreementFileName(attachmentFile.getOriginalFilename());
553                         oleAgreementDocumentMetadata.setAgreementMimeType(attachmentFile.getContentType());
554                         storeAgreementAttachment(attachmentFile);
555                         MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
556                         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)document.getNewMaintainableObject().getDataObject();
557                         OleEventLogBo oleEventLogBo = new OleEventLogBo();
558                         oleEventLogBo.setEventType("file");
559                         oleEventLogBo.setCurrentTimeStamp();
560                         oleEventLogBo.setCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
561                         oleEventLogBo.setEventDescription("doc upload - " +attachmentFile.getOriginalFilename());
562                         oleLicenseRequestBo.getEventLogs().add(oleEventLogBo);
563                     }
564                     catch(Exception e) {
565                         LOG.error("Error while storing the Agreement Document");
566                     }
567                 }
568             }
569         }
570         else {
571             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OleLicenseRequest.ERROR_FILE_NOT_FOUND);
572         }
573 
574         return addLine(form, result, request, response);
575     }
576 
577      /**
578      * This method will deletes the agreement document from the existing list 
579      *
580      * @param uifForm - MaintenanceForm
581      * @return ModelAndView
582      */	
583     @RequestMapping(params = "methodToCall=deleteAgreementDocument")
584     public ModelAndView deleteAgreementDocument(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
585                                                 HttpServletRequest request, HttpServletResponse response) {
586         MaintenanceForm form = (MaintenanceForm) uifForm;
587         MultipartFile attachmentFile = form.getAttachmentFile();
588         try {
589             deleteAgreementAttachment(attachmentFile);
590         } catch (Exception e) {
591             LOG.error("Error while deleting the Agreement Document");
592         }
593         return deleteLine(uifForm, result, request, response);
594     }
595 
596      /**
597      * This method will download the agreement document from the docstore if it is already ingested 
598      *   otherwise will download from the temprovary location.
599      *
600      * @param uifForm - MaintenanceForm
601      * @return ModelAndView
602      */	
603     @RequestMapping(params = "methodToCall=downloadAgreement")
604     public ModelAndView downloadAgreement(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
605                                           HttpServletRequest request,
606                                           HttpServletResponse response) {
607         String selectedLineIndex = uifForm.getActionParamaterValue("selectedLineIndex");
608         MaintenanceForm maintenanceForm = (MaintenanceForm) uifForm;
609         MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
610         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)document.getNewMaintainableObject().getDataObject();
611 
612         OleAgreementDocumentMetadata oleAgreementDocumentMetadata = oleLicenseRequestBo.getAgreementDocumentMetadataList().get(Integer.parseInt(selectedLineIndex));
613         File file;
614         try {
615             if(oleAgreementDocumentMetadata.getAgreementUUID() == null) {
616                 file = new File( getKualiConfigurationService().getPropertyValueAsString(
617                         KRADConstants.ATTACHMENTS_PENDING_DIRECTORY_KEY)+OLEConstants.OleLicenseRequest.AGREEMENT_TMP_LOCATION+
618                         File.separator+oleAgreementDocumentMetadata.getAgreementFileName()) ;
619 
620             }
621             else {
622                 OleLicenseRequestService oleLicenseRequestService = getOleLicenseRequestService();
623                 file = oleLicenseRequestService.downloadAgreementDocumentFromDocstore(oleAgreementDocumentMetadata);
624 
625             }
626             response.setContentType(oleAgreementDocumentMetadata.getAgreementMimeType());
627             response.setContentLength((int) file.length());
628             response.setHeader("Expires", "0");
629             response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
630             response.setHeader("Pragma", "public");
631             response.setHeader("Content-Disposition",
632                     "attachment; filename=\"" + oleAgreementDocumentMetadata.getAgreementFileName()+ "\"");
633             InputStream fis = new BufferedInputStream(new FileInputStream(file));
634             FileCopyUtils.copy(fis, response.getOutputStream());
635 
636         }
637         catch (Exception e) {
638             LOG.error("Error while retrieving the attachment");
639         }
640         finally {
641             OleEventLogBo oleEventLogBo = new OleEventLogBo();
642             oleEventLogBo.setEventType("agreement document");
643             oleEventLogBo.setCurrentTimeStamp();
644             oleEventLogBo.setCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
645             oleEventLogBo.setEventDescription("Agreement Document Downloaded");
646             oleLicenseRequestBo.getEventLogs().add(oleEventLogBo);
647             performWorkflowAction(maintenanceForm, UifConstants.WorkflowAction.SAVE, true);
648         }
649 
650         return null;
651     }
652 
653      /**
654      * This method will populate the url which will be used to view the related Requisition Document 
655      *
656      * @param uifForm - MaintenanceForm
657      * @return ModelAndView
658      */	
659     @RequestMapping(params = "methodToCall=viewRelatedDocument")
660     public ModelAndView viewRelatedDocument(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
661                                             HttpServletRequest request,
662                                             HttpServletResponse response) {
663         ModelAndView modelAndView = new ModelAndView();
664         MaintenanceForm maintenanceForm = (MaintenanceForm) uifForm;
665         String oleurl = PropertyUtil.getPropertyUtil().getProperty("ole.url") ;
666         String olePortal = oleurl.substring(0,oleurl.indexOf("portal.jsp"));
667         String requisitionDocNumber = request.getParameter(OLEConstants.OleLicenseRequest.REQUISITION_DOC_NUM);
668         String redirectUrl = olePortal+OLEConstants.OleLicenseRequest.KEW_DOC_HANDLER
669                 +requisitionDocNumber;
670         GlobalVariables.getUifFormManager().removeForm(uifForm);
671         modelAndView = new ModelAndView(REDIRECT_PREFIX + redirectUrl);
672 
673         return modelAndView;
674     }
675 
676      /**
677      * This method store the uploaded agreement document to the specified location
678      *
679      * @return ModelAndView
680      */	
681     private void storeAgreementAttachment(MultipartFile agreementFile) throws IOException {
682         String location = "";
683         location  = getKualiConfigurationService().getPropertyValueAsString(
684                 KRADConstants.ATTACHMENTS_PENDING_DIRECTORY_KEY)+OLEConstants.OleLicenseRequest.AGREEMENT_TMP_LOCATION;
685 
686         File dirLocation = new File(location);
687         if(!dirLocation.exists()) {
688             boolean  success = dirLocation.mkdirs();
689             if(!success)
690                 LOG.error("Could not generate directory for File at: " + dirLocation.getAbsolutePath());
691         }
692         location = location+File.separator+agreementFile.getOriginalFilename();
693         InputStream fileContents = agreementFile.getInputStream();
694         File fileOut = new File(location);
695         FileOutputStream streamOut = null;
696         BufferedOutputStream bufferedStreamOut = null;
697         try {
698             streamOut = new FileOutputStream(fileOut);
699             bufferedStreamOut = new BufferedOutputStream(streamOut);
700             int c;
701             while ((c = fileContents.read()) != -1) {
702                 bufferedStreamOut.write(c);
703             }
704         }
705         finally {
706             bufferedStreamOut.close();
707             streamOut.close();
708         }
709 
710     }
711 
712     /**
713      *   This method true if the agreement document is new.
714      * @param agreementDocumentMetadata
715      * @return boolean
716      */
717     private boolean isNewAgreementDocument (OleAgreementDocumentMetadata agreementDocumentMetadata) {
718         return agreementDocumentMetadata.getAgreementUUID() == null;
719     }
720     /**
721      * Saves the document instance contained on the form
722      *
723      * @param form - document form base containing the document instance that will be saved
724      * @return ModelAndView
725      */
726     @RequestMapping(params = "methodToCall=save")
727     public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
728                              HttpServletRequest request, HttpServletResponse response) throws Exception {
729         MaintenanceForm maintenanceForm = (MaintenanceForm) form;
730         MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
731         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)document.getNewMaintainableObject().getDataObject();
732         List<OleAgreementDocumentMetadata> agreementDocuments = oleLicenseRequestBo.getAgreementDocumentMetadataList();
733         OleLicenseRequestService oleLicenseRequestService = getOleLicenseRequestService();
734         List<OleAgreementDocumentMetadata> newAgreementDocuments = new ArrayList<OleAgreementDocumentMetadata>();
735         List<OleAgreementDocumentMetadata> checkInAgreementDocuments = new ArrayList<OleAgreementDocumentMetadata>();
736         if(agreementDocuments.size() > 0) {
737             for(OleAgreementDocumentMetadata agreementDocument : agreementDocuments) {
738                 if(isNewAgreementDocument(agreementDocument))
739                     newAgreementDocuments.add(agreementDocument);
740                 else
741                     checkInAgreementDocuments.add(agreementDocument);
742             }
743         }
744         List<OleAgreementDocumentMetadata> agreementDocumentMetadataList = new ArrayList<OleAgreementDocumentMetadata>();
745         if(newAgreementDocuments.size() > 0) {
746             agreementDocumentMetadataList.addAll(oleLicenseRequestService.processIngestAgreementDocuments(newAgreementDocuments));
747         }
748         if(checkInAgreementDocuments.size() > 0) {
749             agreementDocumentMetadataList.addAll(oleLicenseRequestService.processCheckInAgreementDocuments(checkInAgreementDocuments));
750         }
751         oleLicenseRequestBo.setAgreementDocumentMetadataList(agreementDocumentMetadataList);
752         HashMap<String,String> licenses = new HashMap<String, String>();
753         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_IN_NEGO,OLEConstants.OleLicenseRequest.LICENSE_IN_NEGO_VALUE);
754         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_IN_PROCESS,OLEConstants.OleLicenseRequest.LICENSE_IN_PROCESS_VALUE);
755         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_INITIAL_WORKFLOW,OLEConstants.OleLicenseRequest.LICENSE_NEEDED);
756         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_RECEIVED,
757                 OLEConstants.OleLicenseRequest.LICENSE_COMPLETE_RETURN);
758         licenses.put(OLEConstants.OleLicenseRequest.LICENSE_REQUESTED,OLEConstants.OleLicenseRequest.LICENSE_REQUESTED_VALUE);
759         if(licenses.containsKey(oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode())){
760             if (oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode().equals(OLEConstants.OleLicenseRequest.LICENSE_RECEIVED)) {
761                 OleEventLogBo oleEventLogBo = new OleEventLogBo();
762                 oleEventLogBo.setEventType("license received");
763                 oleEventLogBo.setCurrentTimeStamp();
764                 oleEventLogBo.setCreatedBy(GlobalVariables.getUserSession().getPrincipalName());
765                 oleEventLogBo.setEventDescription("status change");
766                 oleLicenseRequestBo.getEventLogs().add(oleEventLogBo);
767             }
768             oleLicenseRequestBo.setLicenseRequestStatusCode(licenses.get(oleLicenseRequestBo.getLicenseRequestWorkflowTypeCode()));
769             performWorkflowAction(form, UifConstants.WorkflowAction.SAVE, true);;
770         }
771         return super.save(form,result,request,response);
772     }
773 
774     /**
775      * This method is used to view the agreement linked to the license request
776      * @param uifForm
777      * @param result
778      * @param request
779      * @param response
780      * @return
781      */
782     @RequestMapping(params = "methodToCall=viewAgreement")
783     public ModelAndView viewAgreement(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
784                                       HttpServletRequest request,
785                                       HttpServletResponse response) {
786         ModelAndView modelAndView = new ModelAndView();
787         MaintenanceForm maintenanceForm = (MaintenanceForm) uifForm;
788         MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
789         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)document.getNewMaintainableObject().getDataObject();
790         String url = PropertyUtil.getPropertyUtil().getProperty("docstore.url") ;
791         if(oleLicenseRequestBo != null) {
792             String redirectUrl = url+"?docAction=checkOut&uuid="+oleLicenseRequestBo.getAgreementId();
793             //GlobalVariables.getUifFormManager().removeForm(uifForm);
794             modelAndView = new ModelAndView(REDIRECT_PREFIX + redirectUrl);
795         }
796         else
797             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.AGREEMENT_ERROR);
798         return modelAndView;
799     }
800 
801     private ConfigurationService getKualiConfigurationService() {
802         return KRADServiceLocator.getKualiConfigurationService();
803     }
804 
805     private void deleteAgreementAttachment(MultipartFile agreementFile) throws IOException {
806         String location = "";
807         location  = getKualiConfigurationService().getPropertyValueAsString(
808                 KRADConstants.ATTACHMENTS_PENDING_DIRECTORY_KEY)+OLEConstants.OleLicenseRequest.AGREEMENT_TMP_LOCATION + File.separator+agreementFile.getOriginalFilename();
809         File attachmentFile = new File(location);
810         attachmentFile.delete();
811     }
812 
813 }