View Javadoc

1   /**
2    * Copyright 2005-2013 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.actionlist;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20  import org.kuali.rice.kew.actionlist.CustomActionListAttribute;
21  import org.kuali.rice.kew.actionlist.DefaultCustomActionListAttribute;
22  import org.kuali.rice.kew.api.action.ActionItem;
23  import org.kuali.rice.kew.api.action.ActionItemCustomization;
24  import org.kuali.rice.kew.doctype.bo.DocumentType;
25  import org.kuali.rice.kew.doctype.service.DocumentTypeService;
26  import org.kuali.rice.kew.framework.actionlist.ActionListCustomizationHandlerService;
27  
28  import java.util.ArrayList;
29  import java.util.Collections;
30  import java.util.HashMap;
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * Reference implementation of the ActionListCustomizationHandlerService.
36   * 
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class ActionListCustomizationHandlerServiceImpl implements ActionListCustomizationHandlerService {
40  
41      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListCustomizationHandlerServiceImpl.class);
42  
43      private DocumentTypeService documentTypeService;
44  
45      @Override
46      public List<ActionItemCustomization> customizeActionList(String principalId, List<ActionItem> actionItems)
47              throws RiceIllegalArgumentException {
48          if (StringUtils.isBlank(principalId)) {
49              throw new RiceIllegalArgumentException("principalId was null or blank");
50          }
51          if (actionItems == null) { actionItems = Collections.emptyList(); }
52  
53          List<ActionItemCustomization> actionItemCustomizations =
54                  new ArrayList<ActionItemCustomization>(actionItems.size());
55  
56          for (ActionItem actionItem : actionItems) {
57              DocumentType documentType = getDocumentTypeService().findByName(actionItem.getDocName());
58  
59              try { // try to get the custom action list attribute and convert it to an ActionItemCustomization
60                  CustomActionListAttribute customActionListAttribute = null;
61                  if (documentType != null) {
62                      customActionListAttribute = documentType.getCustomActionListAttribute();
63                  }
64  
65                  if (customActionListAttribute == null) {
66                      customActionListAttribute = getDefaultCustomActionListAttribute();
67                  }
68  
69                  ActionItemCustomization actionItemCustomization = ActionItemCustomization.Builder.create(
70                          actionItem.getId(),
71                          customActionListAttribute.getLegalActions(principalId, actionItem),
72                          customActionListAttribute.getDocHandlerDisplayParameters(principalId, actionItem)).build();
73                  // add to our results
74                  actionItemCustomizations.add(actionItemCustomization);
75  
76              } catch (Exception e) {
77                  LOG.error("Problem loading custom action list attribute for action item " + actionItem.getId(), e);
78              }
79          }
80  
81          return actionItemCustomizations;
82      }
83  
84      public DocumentTypeService getDocumentTypeService() {
85          return documentTypeService;
86      }
87  
88      public void setDocumentTypeService(DocumentTypeService documentTypeService) {
89          this.documentTypeService = documentTypeService;
90      }
91  
92      // Lazy initialization holder class (see Effective Java Item #71)
93      private static class DefaultCustomActionListAttributeHolder {
94          // lazy initing in case customizations require services for instantiation -- could happen ;-)
95          static final CustomActionListAttribute defaultCustomActionListAttribute =
96                  new DefaultCustomActionListAttribute();
97      }
98  
99      private CustomActionListAttribute getDefaultCustomActionListAttribute() {
100         return DefaultCustomActionListAttributeHolder.defaultCustomActionListAttribute;
101     }
102 }