View Javadoc
1   package org.kuali.ole.alert.controller;
2   
3   import org.apache.commons.lang.ArrayUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.alert.bo.AlertBo;
7   import org.kuali.ole.alert.document.OleMaintenanceDocumentBase;
8   import org.kuali.ole.alert.document.OlePersistableBusinessObjectBase;
9   import org.kuali.ole.alert.document.OleTransactionalDocumentBase;
10  import org.kuali.ole.alert.service.impl.AlertHelperServiceImpl;
11  import org.kuali.ole.alert.service.impl.AlertServiceImpl;
12  import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
13  import org.kuali.ole.deliver.bo.OleDeliverRequestType;
14  import org.kuali.rice.core.api.CoreApiServiceLocator;
15  import org.kuali.rice.core.api.config.property.ConfigurationService;
16  import org.kuali.rice.kew.api.KewApiConstants;
17  import org.kuali.rice.kew.api.action.ActionRequest;
18  import org.kuali.rice.kew.role.service.RoleService;
19  import org.kuali.rice.kim.api.group.GroupService;
20  import org.kuali.rice.kim.api.identity.IdentityService;
21  import org.kuali.rice.kim.api.identity.principal.Principal;
22  import org.kuali.rice.kim.api.role.Role;
23  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24  import org.kuali.rice.kim.impl.identity.principal.PrincipalBo;
25  import org.kuali.rice.krad.bo.*;
26  import org.kuali.rice.krad.exception.UnknownDocumentIdException;
27  import org.kuali.rice.krad.maintenance.Maintainable;
28  import org.kuali.rice.krad.uif.UifConstants;
29  import org.kuali.rice.krad.uif.UifParameters;
30  import org.kuali.rice.krad.uif.container.CollectionGroup;
31  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
32  import org.kuali.rice.krad.uif.view.View;
33  import org.kuali.rice.krad.util.GlobalVariables;
34  import org.kuali.rice.krad.util.KRADConstants;
35  import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
36  import org.kuali.rice.krad.web.form.*;
37  import org.springframework.stereotype.Controller;
38  import org.springframework.validation.BindingResult;
39  import org.springframework.web.bind.annotation.ModelAttribute;
40  import org.springframework.web.bind.annotation.RequestMapping;
41  import org.springframework.web.bind.annotation.RequestMethod;
42  import org.springframework.web.servlet.ModelAndView;
43  
44  import javax.servlet.http.HttpServletRequest;
45  import javax.servlet.http.HttpServletResponse;
46  import java.sql.Date;
47  import java.util.*;
48  
49  /**
50   * Created by maheswarang on 12/18/14.
51   */
52  @Controller
53  @RequestMapping(value = "/oleMaintenance")
54  public class OleMaintenanceDocumentController extends MaintenanceDocumentController {
55      private AlertServiceImpl alertService = new AlertServiceImpl();
56      private GroupService groupService = KimApiServiceLocator.getGroupService();
57      private AlertHelperServiceImpl alertHelperService = new AlertHelperServiceImpl();
58     private org.kuali.rice.kim.api.role.RoleService roleService = KimApiServiceLocator.getRoleService();
59      @Override
60      @RequestMapping(params = "methodToCall=docHandler")
61      public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result,
62                                     HttpServletRequest request, HttpServletResponse response) throws Exception {
63  
64          // TODO getting double view if we call base, not sure how to handle
65          // so pasting in superclass code
66          // super.docHandler(formBase, request, response);
67          // * begin copy/paste from the base
68          MaintenanceDocumentForm form = (MaintenanceDocumentForm) formBase;
69  
70          // in all of the following cases we want to load the document
71          if (ArrayUtils.contains(DOCUMENT_LOAD_COMMANDS, form.getCommand()) && form.getDocId() != null) {
72              try {
73                  loadDocument(form);
74                  OlePersistableBusinessObjectBase olePersistableBusinessObjectBase = (OlePersistableBusinessObjectBase)form.getDocument().getNewMaintainableObject().getDataObject();
75                  olePersistableBusinessObjectBase.setAlertBoList(alertService.retrieveAlertList(form.getDocument().getDocumentNumber()));
76              } catch (UnknownDocumentIdException udie) {
77                  ConfigurationService kualiConfigurationService = CoreApiServiceLocator.getKualiConfigurationService();
78                  StringBuffer sb = new StringBuffer();
79                  sb.append(kualiConfigurationService.getPropertyValueAsString(KRADConstants.KRAD_URL_KEY));
80                  sb.append(kualiConfigurationService.getPropertyValueAsString(KRADConstants.KRAD_INITIATED_DOCUMENT_URL_KEY));
81                  Properties props = new Properties();
82                  props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START);
83                  GlobalVariables.getUifFormManager().removeSessionForm(form); // removeForm(form);
84                  return performRedirect(new InitiatedDocumentInfoForm(), sb.toString(), props);
85              }
86          } else if (KewApiConstants.INITIATE_COMMAND.equals(form.getCommand())) {
87              createDocument(form);
88          } else {
89              LOG.error("docHandler called with invalid parameters");
90              throw new IllegalArgumentException("docHandler called with invalid parameters");
91          }
92          // * end copy/paste from the base
93  
94          if (KewApiConstants.ACTIONLIST_COMMAND.equals(form.getCommand()) ||
95                  KewApiConstants.DOCSEARCH_COMMAND.equals(form.getCommand()) ||
96                  KewApiConstants.SUPERUSER_COMMAND.equals(form.getCommand()) ||
97                  KewApiConstants.HELPDESK_ACTIONLIST_COMMAND.equals(form.getCommand()) && form.getDocId() != null) {
98              // TODO: set state in view
99              // form.setReadOnly(true);
100             form.setMaintenanceAction((form.getDocument()).getNewMaintainableObject().getMaintenanceAction());
101 
102             // Retrieving the FileName from BO table
103             Maintainable tmpMaintainable = form.getDocument().getNewMaintainableObject();
104             if (tmpMaintainable.getDataObject() instanceof PersistableAttachment) {
105                 PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService()
106                         .retrieve((PersistableBusinessObject) tmpMaintainable.getDataObject());
107                 if (bo != null) {
108                     request.setAttribute("fileName", bo.getFileName());
109                 }
110             }
111         } else if (KewApiConstants.INITIATE_COMMAND.equals(form.getCommand())) {
112             // form.setReadOnly(false);
113             setupMaintenance(form, request, KRADConstants.MAINTENANCE_NEW_ACTION);
114         } else {
115             LOG.error("We should never have gotten to here");
116             throw new IllegalArgumentException("docHandler called with invalid parameters");
117         }
118 
119         return getUIFModelAndView(form);
120     }
121 
122 
123     /**
124      * This method is to save alert
125      *
126      * @param formBase
127      * @param result
128      * @param request
129      * @param response
130      * @return ModelAndView
131      */
132     @RequestMapping(params = "methodToCall=saveAlert")
133     public ModelAndView saveAlert(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result,
134                                   HttpServletRequest request, HttpServletResponse response) {
135         MaintenanceDocumentForm maintenanceDocumentForm = (MaintenanceDocumentForm)formBase;
136         OlePersistableBusinessObjectBase olePersistableBusinessObjectBase = (OlePersistableBusinessObjectBase)maintenanceDocumentForm.getDocument().getNewMaintainableObject().getDataObject();
137         int index = Integer.parseInt(maintenanceDocumentForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
138         olePersistableBusinessObjectBase.getAlertBoList().get(index).setEditFlag(false);
139         AlertBo alertBo = olePersistableBusinessObjectBase.getAlertBoList().get(index);
140         String status = null;
141         if(alertBo.getAlertDate()!=null){
142             Date alertDate = alertBo.getAlertDate();
143             if(alertDate.toString().equals(new Date(System.currentTimeMillis()).toString())){
144                 status = "Active";
145             }else{
146                 int dateCompare= alertBo.getAlertDate().compareTo(new Date(System.currentTimeMillis()));
147                 if(dateCompare>0){
148                     status = "Future";
149                 }else if(dateCompare<0){
150                     status="Complete";
151                 }
152             }
153         }
154         alertBo.setStatus(status);
155         return super.navigate(maintenanceDocumentForm, result, request, response);
156     }
157 
158     /**
159      * This method is to edit alert
160      *
161      * @param formBase
162      * @param result
163      * @param request
164      * @param response
165      * @return ModelAndView
166      */
167     @RequestMapping(params = "methodToCall=editAlert")
168     public ModelAndView editAlert(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result,
169                                   HttpServletRequest request, HttpServletResponse response) {
170         MaintenanceDocumentForm maintenanceDocumentForm = (MaintenanceDocumentForm)formBase;
171         OlePersistableBusinessObjectBase olePersistableBusinessObjectBase = (OlePersistableBusinessObjectBase)maintenanceDocumentForm.getDocument().getNewMaintainableObject().getDataObject();
172         int index = Integer.parseInt(maintenanceDocumentForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
173         AlertBo alertBo = olePersistableBusinessObjectBase.getAlertBoList().get(index);
174         alertBo.setEditFlag(true);
175         alertBo.setAlertModifierId(GlobalVariables.getUserSession().getPrincipalId());
176         alertBo.setAlertModifiedDate(new Date(System.currentTimeMillis()));
177         alertBo.setAlertModifierName(alertService.getName(GlobalVariables.getUserSession().getPrincipalId()));
178         return super.navigate(maintenanceDocumentForm, result, request, response);
179     }
180 
181 
182     /**
183      * This method is to delete alert
184      *
185      * @param formBase
186      * @param result
187      * @param request
188      * @param response
189      * @return ModelAndView
190      */
191     @RequestMapping(params = "methodToCall=deleteAlert")
192     public ModelAndView deleteAlert(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result,
193                                     HttpServletRequest request, HttpServletResponse response) {
194         MaintenanceDocumentForm maintenanceDocumentForm = (MaintenanceDocumentForm)formBase;
195         OlePersistableBusinessObjectBase olePersistableBusinessObjectBase = (OlePersistableBusinessObjectBase)maintenanceDocumentForm.getDocument().getNewMaintainableObject().getDataObject();
196         int index = Integer.parseInt(maintenanceDocumentForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
197         if (olePersistableBusinessObjectBase.getAlertBoList().size() > index) {
198             olePersistableBusinessObjectBase.getAlertBoList().remove(index);
199         }
200         return super.navigate(formBase, result, request, response);
201     }
202 
203 
204     /**
205      * This method is to delete alert
206      *
207      * @param formBase
208      * @param result
209      * @param request
210      * @param response
211      * @return ModelAndView
212      */
213     @RequestMapping(params = "methodToCall=approveAlert")
214     public ModelAndView approveAlert(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result,
215                                      HttpServletRequest request, HttpServletResponse response) {
216         AlertBo alertBo = null;
217         MaintenanceDocumentForm maintenanceDocumentForm = (MaintenanceDocumentForm)formBase;
218         OlePersistableBusinessObjectBase olePersistableBusinessObjectBase = (OlePersistableBusinessObjectBase)maintenanceDocumentForm.getDocument().getNewMaintainableObject().getDataObject();
219         int index = Integer.parseInt(maintenanceDocumentForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
220         olePersistableBusinessObjectBase.getAlertBoList().get(index).setAlertStatus(false);
221         olePersistableBusinessObjectBase.getAlertBoList().get(index).setAlertModifierId(GlobalVariables.getUserSession().getPrincipalId());
222         if(olePersistableBusinessObjectBase.getAlertBoList().get(index).isRepeatable()){
223             alertBo = alertHelperService.createNewAlertBo(olePersistableBusinessObjectBase.getAlertBoList().get(index));
224             olePersistableBusinessObjectBase.getAlertBoList().add(alertBo);
225         }
226         return super.navigate(formBase, result, request, response);
227     }
228 
229 
230     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAlertLine")
231     public ModelAndView addAlertLine(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result,
232                                      HttpServletRequest request, HttpServletResponse response) {
233         String selectedCollectionPath = formBase.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
234         if (StringUtils.isBlank(selectedCollectionPath)) {
235             throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
236         }
237         CollectionGroup collectionGroup = formBase.getPostedView().getViewIndex().getCollectionGroupByPath(
238                 selectedCollectionPath);
239         String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
240         Object addLine = ObjectPropertyUtils.getPropertyValue(formBase, addLinePath);
241         ModelAndView modelAndView =  super.addLine(formBase,result,request,response);
242         List<String> principalIds = new ArrayList<String>();
243         MaintenanceDocumentForm maintenanceDocumentForm = (MaintenanceDocumentForm)modelAndView.getModel().get("KualiForm");
244         OlePersistableBusinessObjectBase olePersistableBusinessObjectBase = (OlePersistableBusinessObjectBase)maintenanceDocumentForm.getDocument().getNewMaintainableObject().getDataObject();
245         AlertBo alertBo = olePersistableBusinessObjectBase.getAlertBoList().get(0);
246         olePersistableBusinessObjectBase.getAlertBoList().remove(0);
247         if(StringUtils.isBlank(alertBo.getReceivingGroupId()) && StringUtils.isBlank(alertBo.getReceivingUserId()) && StringUtils.isBlank(alertBo.getReceivingRoleId()) && StringUtils.isBlank(alertBo.getReceivingGroupId()) && StringUtils.isEmpty(alertBo.getReceivingUserName()) && StringUtils.isEmpty(alertBo.getReceivingRoleName()) && StringUtils.isEmpty(alertBo.getReceivingGroupName())){
248             GlobalVariables.getMessageMap().putErrorForSectionId("OLE-AlertSection", OLEConstants.SELECT_USER);
249             return modelAndView ;
250         }
251         alertBo.setAlertCreateDate(new Date(System.currentTimeMillis()));
252         alertBo.setAlertInitiatorId(GlobalVariables.getUserSession().getPrincipalId());
253         alertBo.setAlertInitiatorName(alertService.getName(GlobalVariables.getUserSession().getPrincipalId()));
254 
255         String status = null;
256         if(alertBo.getAlertDate()!=null){
257             Date alertDate = alertBo.getAlertDate();
258             if(alertDate.toString().equals(new Date(System.currentTimeMillis()).toString())){
259                 status = "Active";
260             }else{
261                 int dateCompare= alertBo.getAlertDate().compareTo(new Date(System.currentTimeMillis()));
262                 if(dateCompare>0){
263                     status = "Future";
264                 }else if(dateCompare<0){
265                     status="Complete";
266                 }
267             }
268         }
269         alertBo.setStatus(status);
270         alertBo.setAlertStatus(true);
271         List<AlertBo> alerts = new ArrayList<AlertBo>();
272         if(StringUtils.isNotBlank(alertBo.getReceivingUserId()) && (alertBo.getReceivingUserName() == null || (alertBo.getReceivingUserName()!=null && alertBo.getReceivingUserName().trim().isEmpty()))){
273             alertBo.setReceivingUserName(alertService.getName(alertBo.getReceivingUserId()));
274         }
275         if(StringUtils.isBlank(alertBo.getReceivingUserId())&& (alertBo.getReceivingUserName() != null && !alertBo.getReceivingUserName().trim().isEmpty())){
276             alertBo.setReceivingUserId(alertService.getPersonId(alertBo.getReceivingUserName()));
277         }
278         if(StringUtils.isNotBlank(alertBo.getReceivingUserId())){
279             principalIds.add(alertBo.getReceivingUserId());
280         }
281         alerts.addAll(alertService.getAlertBo(alertBo,principalIds,false,false));
282         principalIds = new ArrayList<String>();
283 
284 
285 
286         if(StringUtils.isNotBlank(alertBo.getReceivingGroupId()) && (alertBo.getReceivingGroupName() == null || (alertBo.getReceivingGroupName()!=null && alertBo.getReceivingGroupName().trim().isEmpty()))){
287             alertBo.setReceivingGroupName(alertService.getGroupName(alertBo.getReceivingGroupId()));
288         }
289         if(StringUtils.isBlank(alertBo.getReceivingGroupId()) && (alertBo.getReceivingGroupName() != null && !alertBo.getReceivingGroupName().trim().isEmpty())){
290             alertBo.setReceivingGroupId(alertService.getGroupId((alertBo.getReceivingUserName())));
291         }
292 
293 
294         if(StringUtils.isNotBlank(alertBo.getReceivingGroupId())){
295             List<String> memberIds = groupService.getMemberPrincipalIds(alertBo.getReceivingGroupId());
296             principalIds.addAll(memberIds);
297         }
298         alerts.addAll(alertService.getAlertBo(alertBo,principalIds,false,true));
299 
300 
301         principalIds = new ArrayList<String>();
302 
303         if(StringUtils.isNotBlank(alertBo.getReceivingRoleId()) && (alertBo.getReceivingRoleName() == null || (alertBo.getReceivingRoleName()!=null && alertBo.getReceivingRoleName().trim().isEmpty()))){
304             alertBo.setReceivingRoleName(alertService.getRoleName(alertBo.getReceivingRoleId()));
305         }
306         if(StringUtils.isBlank(alertBo.getReceivingRoleId()) && (alertBo.getReceivingRoleName() != null && !alertBo.getReceivingRoleName().trim().isEmpty())){
307             alertBo.setReceivingRoleId(alertService.getRoleId((alertBo.getReceivingRoleName())));
308         }
309 
310 
311         if(StringUtils.isNotBlank(alertBo.getReceivingRoleId())){
312             List<String> roleIds = new ArrayList<String>();
313             roleIds.add(alertBo.getReceivingRoleId());
314             Role role =  roleService.getRole(alertBo.getReceivingRoleId());
315             Collection collection  =  (Collection)roleService.getRoleMemberPrincipalIds(role.getNamespaceCode(),role.getName(),new HashMap<String,String>());
316             List<String> memberIds = new ArrayList<String>();
317             memberIds.addAll(collection);
318             principalIds.addAll(memberIds);
319         }
320 
321 
322         alerts.addAll(alertService.getAlertBo(alertBo,principalIds,true,false));
323 
324 
325         olePersistableBusinessObjectBase.getAlertBoList().addAll(alerts);
326         if(StringUtils.isBlank(alertBo.getReceivingUserId()) && StringUtils.isNotBlank(alertBo.getReceivingGroupId())){
327             olePersistableBusinessObjectBase.getAlertBoList().remove(0);
328         }
329         if(StringUtils.isNotBlank(alertBo.getReceivingUserId()) && StringUtils.isNotBlank(alertBo.getReceivingGroupId())){
330             alertBo.setReceivingGroupName(null);
331             alertBo.setReceivingGroupId(null);
332         }
333 
334         return modelAndView ;
335 
336 }
337 
338 
339 
340 /*    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAlertLine")
341     public ModelAndView addAlertLine(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result,
342                                      HttpServletRequest request, HttpServletResponse response) {
343 
344         String selectedCollectionPath = formBase.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
345         CollectionGroup collectionGroup = formBase.getPostedView().getViewIndex().getCollectionGroupByPath(
346                 selectedCollectionPath);
347         String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
348         Object addLine = ObjectPropertyUtils.getPropertyValue(formBase, addLinePath);
349         AlertBo alertBo = (AlertBo)addLine;
350         List<String> principalIds = new ArrayList<String>();
351         alertBo.setAlertCreateDate(new Date(System.currentTimeMillis()));
352         alertBo.setAlertInitiatorId(GlobalVariables.getUserSession().getPrincipalId());
353         alertBo.setAlertInitiatorName(alertService.getName(GlobalVariables.getUserSession().getPrincipalId()));
354         if(alertBo.getReceivingUserId()!=null){
355 //            principalIds.add(alertBo.getReceivingUserId());
356             alertBo.setReceivingUserName(alertService.getName(alertBo.getReceivingUserId()));
357         }
358         if(alertBo.getReceivingGroupId()!=null && !alertBo.getReceivingGroupId().trim().isEmpty()){
359             alertBo.setReceivingGroupName(alertService.getGroupName(alertBo.getReceivingGroupId()));
360         }
361 
362         if(alertBo.getReceivingGroupId()!=null){
363             List<String> memberIds = groupService.getMemberPrincipalIds(alertBo.getReceivingGroupId());
364             principalIds.addAll(memberIds);
365         }
366 
367         String status = null;
368         if(alertBo.getAlertDate()!=null){
369             Date alertDate = alertBo.getAlertDate();
370             if(alertDate.toString().equals(new Date(System.currentTimeMillis()).toString())){
371                 status = "Active";
372             }else{
373                 int dateCompare= alertBo.getAlertDate().compareTo(new Date(System.currentTimeMillis()));
374                 if(dateCompare>0){
375                     status = "Future";
376                 }else if(dateCompare<0){
377                     status="Complete";
378                 }
379             }
380         }
381         alertBo.setStatus(status);
382         alertBo.setAlertStatus(true);
383 
384         List<AlertBo> alerts = alertService.getAlertBo(alertBo,principalIds);
385        MaintenanceDocumentForm maintenanceDocumentForm = (MaintenanceDocumentForm)formBase;
386         OleMaintenanceDocumentBase oleMaintenanceDocumentBase = (OleMaintenanceDocumentBase) maintenanceDocumentForm.getDocument();
387         oleMaintenanceDocumentBase.setAlertBoList(maintenanceDocumentForm.getAddedCollectionItems());
388         oleMaintenanceDocumentBase.getAlertBoList().addAll(alerts);
389         if(alertBo.getReceivingUserId()==null && alertBo.getReceivingGroupId()!=null){
390             oleMaintenanceDocumentBase.getAlertBoList().remove(0);
391         }
392         if(alertBo.getReceivingUserId()!=null && alertBo.getReceivingGroupId()!=null){
393             alertBo.setReceivingGroupName(null);
394             alertBo.setReceivingGroupId(null);
395         }
396 
397         return getUIFModelAndView(formBase);
398 
399       *//*  MaintenanceDocumentForm maintenanceDocumentFormBase = (MaintenanceDocumentForm)formBase;
400         OleMaintenanceDocumentBase oleMaintenanceDocumentBase = (OleMaintenanceDocumentBase) maintenanceDocumentFormBase.getDocument();
401         oleMaintenanceDocumentBase.getDocumentHeader().getWorkflowDocument().getDocument().getStatus().getCode();
402 *//**//*        int index = Integer.parseInt(transactionalDocumentFormBase.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
403         oleTransactionalDocumentBase.getAlertBoList().get(index).setEditFlag(true);*//**//*
404         ModelAndView modelAndView =  super.addLine(formBase,result,request,response);
405         maintenanceDocumentFormBase = (MaintenanceDocumentForm)modelAndView.getModel().get("KualiForm");
406         List<String> principalIds = new ArrayList<String>();
407         AlertBo alertBo = oleMaintenanceDocumentBase.getAlertBoList().get(0);
408         alertBo.setAlertCreateDate(new Date(System.currentTimeMillis()));
409         alertBo.setAlertInitiatorId(GlobalVariables.getUserSession().getPrincipalId());
410         alertBo.setAlertInitiatorName(alertService.getName(GlobalVariables.getUserSession().getPrincipalId()));
411         if(alertBo.getReceivingUserId()!=null){
412 //            principalIds.add(alertBo.getReceivingUserId());
413             alertBo.setReceivingUserName(alertService.getName(alertBo.getReceivingUserId()));
414         }
415         if(alertBo.getReceivingGroupId()!=null && !alertBo.getReceivingGroupId().trim().isEmpty()){
416             alertBo.setReceivingGroupName(alertService.getGroupName(alertBo.getReceivingGroupId()));
417         }
418 
419         if(alertBo.getReceivingGroupId()!=null){
420             List<String> memberIds = groupService.getMemberPrincipalIds(alertBo.getReceivingGroupId());
421             principalIds.addAll(memberIds);
422         }
423 
424         String status = null;
425         if(alertBo.getAlertDate()!=null){
426             Date alertDate = alertBo.getAlertDate();
427             if(alertDate.toString().equals(new Date(System.currentTimeMillis()).toString())){
428                 status = "Active";
429             }else{
430                 int dateCompare= alertBo.getAlertDate().compareTo(new Date(System.currentTimeMillis()));
431                 if(dateCompare>0){
432                     status = "Future";
433                 }else if(dateCompare<0){
434                     status="Complete";
435                 }
436             }
437         }
438         alertBo.setStatus(status);
439         alertBo.setAlertStatus(true);
440 
441         List<AlertBo> alerts = alertService.getAlertBo(alertBo,principalIds);
442 
443         oleMaintenanceDocumentBase.getAlertBoList().addAll(alerts);
444         if(alertBo.getReceivingUserId()==null && alertBo.getReceivingGroupId()!=null){
445             oleMaintenanceDocumentBase.getAlertBoList().remove(0);
446         }
447         if(alertBo.getReceivingUserId()!=null && alertBo.getReceivingGroupId()!=null){
448             alertBo.setReceivingGroupName(null);
449             alertBo.setReceivingGroupId(null);
450         }
451 
452         return modelAndView ;*//*
453     }*/
454 
455 /*    @RequestMapping(params = "methodToCall=approve")
456     public ModelAndView approve(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
457                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
458 
459       //   getDocumentService().saveDocument(form.getDocument());
460         List<ActionRequest> actionRequests = form.getDocument().getDocumentHeader().getWorkflowDocument().getDocumentDetail().getActionRequests();
461 
462 
463         List<AdHocRoutePerson> adHocRouteRecipients = new ArrayList<AdHocRoutePerson>();
464         org.kuali.rice.kim.api.role.RoleService roleService = (org.kuali.rice.kim.api.role.RoleService)KimApiServiceLocator.getRoleService();
465         Role role = roleService.getRole("123456");
466         Collection<String> principalIds = (Collection<String>) roleService.getRoleMemberPrincipalIds(role.getNamespaceCode(),role.getName(),new HashMap<String, String>());
467         IdentityService identityService = KimApiServiceLocator.getIdentityService();
468         List<String> principalList = new ArrayList<String>();
469         principalList.addAll(principalIds);
470         List<Principal> principals = identityService.getPrincipals(principalList);
471         AdHocRoutePerson adHocRoutePerson;
472         if(principals!=null && principals.size()>0){
473             for(Principal principal : principals){
474                 adHocRoutePerson = new AdHocRoutePerson();
475                 adHocRoutePerson.setId(principal.getPrincipalId());
476                 adHocRoutePerson.setName(principal.getPrincipalName());
477                 adHocRoutePerson.setActionRequested("A");
478                 adHocRoutePerson.setdocumentNumber(form.getDocument().getDocumentNumber());
479                 adHocRoutePerson.setType(0);
480                 adHocRouteRecipients.add(adHocRoutePerson);
481             }
482         }
483         List<AdHocRouteRecipient>  adHocRouteRecipientList = combineAdHocRecipients(form);
484         adHocRouteRecipientList.addAll(adHocRouteRecipients);
485 
486         getDocumentService().approveDocument(form.getDocument(), "Approved by user " + role.getName(), adHocRouteRecipientList);
487         return getUIFModelAndView(form);
488     }
489 
490 
491     @RequestMapping(params = "methodToCall=save")
492     public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
493                              HttpServletRequest request, HttpServletResponse response) throws Exception {
494 
495         List<AdHocRoutePerson> adHocRouteRecipients = new ArrayList<AdHocRoutePerson>();
496         org.kuali.rice.kim.api.role.RoleService roleService = (org.kuali.rice.kim.api.role.RoleService)KimApiServiceLocator.getRoleService();
497         Role role = roleService.getRole("12345");
498           Collection<String> principalIds = (Collection<String>) roleService.getRoleMemberPrincipalIds(role.getNamespaceCode(),role.getName(),new HashMap<String, String>());
499         IdentityService identityService = KimApiServiceLocator.getIdentityService();
500         List<String> principalList = new ArrayList<String>();
501         principalList.addAll(principalIds);
502         List<Principal> principals = identityService.getPrincipals(principalList);
503 *//*        AdHocRouteWorkgroup adHocRouteWorkgroup = new AdHocRouteWorkgroup();
504         adHocRouteWorkgroup.setRecipientName(role.getName());
505         adHocRouteWorkgroup.setRecipientNamespaceCode(role.getNamespaceCode());
506         adHocRouteWorkgroup.setType(1);
507 
508         List<AdHocRouteWorkgroup> adHocRouteGroupRecipientList  = new ArrayList<AdHocRouteWorkgroup> ();
509         adHocRouteGroupRecipientList.add(adHocRouteWorkgroup);*//*
510 
511 
512         AdHocRoutePerson adHocRoutePerson;
513         if(principals!=null && principals.size()>0){
514             for(Principal principal : principals){
515                 adHocRoutePerson = new AdHocRoutePerson();
516                 adHocRoutePerson.setId(principal.getPrincipalId());
517                 adHocRoutePerson.setName(principal.getPrincipalName());
518                 adHocRoutePerson.setActionRequested("A");
519                 adHocRoutePerson.setdocumentNumber(form.getDocument().getDocumentNumber());
520                 adHocRoutePerson.setType(0);
521              adHocRouteRecipients.add(adHocRoutePerson);
522             }
523         }
524        List<AdHocRouteRecipient>  adHocRouteRecipientList = combineAdHocRecipients(form);
525         adHocRouteRecipientList.addAll(adHocRouteRecipients);
526 
527         getDocumentService().routeDocument(form.getDocument(), form.getAnnotation(), adHocRouteRecipientList);
528 
529         return getUIFModelAndView(form);
530     }*/
531 
532     @RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_EDIT)
533     public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
534                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
535 
536         setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION);
537         OlePersistableBusinessObjectBase olePersistableBusinessObjectBase = (OlePersistableBusinessObjectBase)form.getDocument().getNewMaintainableObject().getDataObject();
538         olePersistableBusinessObjectBase.setAlertBoList(alertService.retrieveAlertList(form.getDocument().getDocumentNumber()));
539         return getUIFModelAndView(form);
540     }
541 
542 }