View Javadoc

1   /**
2    * Copyright 2005-2011 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.kew.impl.peopleflow;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20  import org.kuali.rice.core.api.uif.RemotableAttributeField;
21  import org.kuali.rice.kew.api.KewApiServiceLocator;
22  import org.kuali.rice.kew.api.peopleflow.PeopleFlowDefinition;
23  import org.kuali.rice.kew.api.repository.type.KewTypeDefinition;
24  import org.kuali.rice.kew.framework.peopleflow.PeopleFlowTypeService;
25  import org.kuali.rice.krad.maintenance.MaintainableImpl;
26  import org.kuali.rice.krad.uif.container.Container;
27  import org.kuali.rice.krad.uif.view.View;
28  import org.kuali.rice.krad.web.form.MaintenanceForm;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * Custom view helper for the people flow maintenance document to retrieve the type attribute remotable fields
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class PeopleFlowMaintainableImpl extends MaintainableImpl {
39  
40      /**
41       * Invokes the {@link org.kuali.rice.kew.api.repository.type.KewTypeRepositoryService} to retrieve the remotable
42       * field definitions for the attributes associated with the selected type
43       *
44       * @param view - view instance
45       * @param model - object containing the form data, from which the selected type will be pulled
46       * @param container - container that holds the remotable fields
47       * @return List<RemotableAttributeField> instances for the type attributes, or empty list if not attributes exist
48       */
49      public List<RemotableAttributeField> retrieveTypeAttributes(View view, Object model, Container container) {
50          List<RemotableAttributeField> remoteFields = new ArrayList<RemotableAttributeField>();
51  
52          PeopleFlowBo peopleFlow =
53                  (PeopleFlowBo) ((MaintenanceForm) model).getDocument().getNewMaintainableObject().getDataObject();
54  
55          // retrieve the type service and invoke to get the remotable field definitions
56          String typeId = peopleFlow.getTypeId();
57          if (StringUtils.isNotBlank(typeId)) {
58              KewTypeDefinition typeDefinition = KewApiServiceLocator.getKewTypeRepositoryService().getTypeById(typeId);
59              PeopleFlowTypeService peopleFlowTypeService = GlobalResourceLoader.<PeopleFlowTypeService>getService(
60                      typeDefinition.getServiceName());
61              remoteFields = peopleFlowTypeService.getAttributeFields(typeId);
62          }
63  
64          return remoteFields;
65      }
66  
67      /**
68       * Set the attribute bo list from the map of attribute key/value pairs and then calls
69       * {@link org.kuali.rice.kew.api.peopleflow.PeopleFlowService} to save the people flow instance
70       */
71      @Override
72      public void saveDataObject() {
73          ((PeopleFlowBo) getDataObject()).updateAttributeBoValues();
74  
75          PeopleFlowDefinition peopleFlowDefinition = PeopleFlowBo.to(((PeopleFlowBo) getDataObject()));
76          if (StringUtils.isNotBlank(peopleFlowDefinition.getId())) {
77              KewApiServiceLocator.getPeopleFlowService().updatePeopleFlow(peopleFlowDefinition);
78          } else {
79              KewApiServiceLocator.getPeopleFlowService().createPeopleFlow(peopleFlowDefinition);
80          }
81      }
82  }