View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.service.impl;
17  
18  import org.kuali.rice.kim.api.group.Group;
19  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
20  import org.kuali.rice.krad.bo.AdHocRoutePerson;
21  import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
22  import org.kuali.rice.krad.document.Document;
23  import org.kuali.rice.krad.service.BusinessObjectService;
24  import org.kuali.rice.krad.service.DocumentAdHocService;
25  import org.kuali.rice.krad.service.KRADServiceLocator;
26  
27  import java.util.HashMap;
28  import java.util.List;
29  
30  /**
31   * Implementation for {@link DocumentAdHocService}
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class DocumentAdHocServiceImpl implements DocumentAdHocService {
37  
38  	/**
39  	 * {@inheritDoc}
40  	 */
41  	public void addAdHocs(Document document) {
42          /* Instead of reading the doc header to see if doc is in saved status
43           * its probably easier and faster to just do this all the time and
44           * store a null when appropriate.
45           */
46          List<AdHocRoutePerson> adHocRoutePersons;
47          List<AdHocRouteWorkgroup> adHocRouteWorkgroups;
48          HashMap criteriaPerson = new HashMap();
49          HashMap criteriaWorkgroup = new HashMap();
50  
51          criteriaPerson.put("documentNumber", document.getDocumentNumber());
52          criteriaPerson.put("type", AdHocRoutePerson.PERSON_TYPE);
53          adHocRoutePersons = (List) getBusinessObjectService().findMatching(AdHocRoutePerson.class, criteriaPerson);
54          criteriaWorkgroup.put("documentNumber", document.getDocumentNumber());
55          criteriaWorkgroup.put("type", AdHocRouteWorkgroup.WORKGROUP_TYPE);
56          adHocRouteWorkgroups = (List) getBusinessObjectService().findMatching(AdHocRouteWorkgroup.class, criteriaWorkgroup);
57  
58          //populate group namespace and names on adHocRoutWorkgroups
59          for (AdHocRouteWorkgroup adHocRouteWorkgroup : adHocRouteWorkgroups) {
60              Group group = KimApiServiceLocator.getGroupService().getGroup(adHocRouteWorkgroup.getId());
61              adHocRouteWorkgroup.setRecipientName(group.getName());
62              adHocRouteWorkgroup.setRecipientNamespaceCode(group.getNamespaceCode());
63          }
64          document.setAdHocRoutePersons(adHocRoutePersons);
65          document.setAdHocRouteWorkgroups(adHocRouteWorkgroups);
66  	}
67  
68      /**
69       * gets the {@link BusinessObjectService} from {@code KRADServiceLocator}
70       * @return
71       */
72      protected BusinessObjectService getBusinessObjectService() {
73      	return KRADServiceLocator.getBusinessObjectService();
74      }
75  
76  }