001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.service.impl;
017
018import org.kuali.rice.kim.api.group.Group;
019import org.kuali.rice.kim.api.services.KimApiServiceLocator;
020import org.kuali.rice.krad.bo.AdHocRoutePerson;
021import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
022import org.kuali.rice.krad.document.Document;
023import org.kuali.rice.krad.service.BusinessObjectService;
024import org.kuali.rice.krad.service.DocumentAdHocService;
025import org.kuali.rice.krad.service.KRADServiceLocator;
026
027import java.util.HashMap;
028import java.util.List;
029
030/**
031 * Implementation for {@link DocumentAdHocService}.
032 *
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 *
035 */
036public class DocumentAdHocServiceImpl implements DocumentAdHocService {
037
038        /**
039         * {@inheritDoc}
040         */
041        public void addAdHocs(Document document) {
042        /* Instead of reading the doc header to see if doc is in saved status
043         * its probably easier and faster to just do this all the time and
044         * store a null when appropriate.
045         */
046        List<AdHocRoutePerson> adHocRoutePersons;
047        List<AdHocRouteWorkgroup> adHocRouteWorkgroups;
048        HashMap criteriaPerson = new HashMap();
049        HashMap criteriaWorkgroup = new HashMap();
050
051        criteriaPerson.put("documentNumber", document.getDocumentNumber());
052        criteriaPerson.put("type", AdHocRoutePerson.PERSON_TYPE);
053        adHocRoutePersons = (List) getBusinessObjectService().findMatching(AdHocRoutePerson.class, criteriaPerson);
054        criteriaWorkgroup.put("documentNumber", document.getDocumentNumber());
055        criteriaWorkgroup.put("type", AdHocRouteWorkgroup.WORKGROUP_TYPE);
056        adHocRouteWorkgroups = (List) getBusinessObjectService().findMatching(AdHocRouteWorkgroup.class, criteriaWorkgroup);
057
058        //populate group namespace and names on adHocRoutWorkgroups
059        for (AdHocRouteWorkgroup adHocRouteWorkgroup : adHocRouteWorkgroups) {
060            Group group = KimApiServiceLocator.getGroupService().getGroup(adHocRouteWorkgroup.getId());
061            adHocRouteWorkgroup.setRecipientName(group.getName());
062            adHocRouteWorkgroup.setRecipientNamespaceCode(group.getNamespaceCode());
063        }
064        document.setAdHocRoutePersons(adHocRoutePersons);
065        document.setAdHocRouteWorkgroups(adHocRouteWorkgroups);
066        }
067
068    protected BusinessObjectService getBusinessObjectService() {
069        return KRADServiceLocator.getBusinessObjectService();
070    }
071
072}