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.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.actionitem.ActionItemActionListExtension;
21  import org.kuali.rice.kew.api.action.ActionItem;
22  import org.kuali.rice.kew.api.actionlist.ActionListService;
23  import org.kuali.rice.kew.service.KEWServiceLocator;
24  
25  import java.util.ArrayList;
26  import java.util.Collection;
27  import java.util.List;
28  
29  /**
30   * Reference implementation of the {@link org.kuali.rice.kew.api.actionlist.ActionListService} api.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   *
34   */
35  public class ActionListServiceNewImpl implements ActionListService {
36  
37      @Override
38      public Integer getUserActionItemCount(String principalId) {
39          incomingParamCheck(principalId, "principalId");
40          return Integer.valueOf(KEWServiceLocator.getActionListService().getCount(principalId));
41      }
42  
43      @Override
44      public List<ActionItem> getActionItemsForPrincipal(String principalId) {
45          incomingParamCheck(principalId, "principalId");
46          Collection<ActionItemActionListExtension> actionItems
47                  = KEWServiceLocator.getActionListService().getActionList(principalId, null);
48          List<ActionItem> actionItemVOs = new ArrayList<ActionItem>(actionItems.size());
49          for (org.kuali.rice.kew.actionitem.ActionItem actionItem : actionItems) {
50              actionItemVOs.add(org.kuali.rice.kew.actionitem.ActionItem.to(actionItem));
51          }
52          return actionItemVOs;
53      }
54  
55      @Override
56      public List<ActionItem> getAllActionItems(String documentId) {
57          incomingParamCheck(documentId, "documentId");
58          Collection<ActionItemActionListExtension> actionItems
59                  = KEWServiceLocator.getActionListService().getActionListForSingleDocument(documentId);
60          List<ActionItem> actionItemVOs = new ArrayList<ActionItem>(actionItems.size());
61          for (org.kuali.rice.kew.actionitem.ActionItem actionItem : actionItems) {
62              actionItemVOs.add(org.kuali.rice.kew.actionitem.ActionItem.to(actionItem));
63          }
64          return actionItemVOs;
65      }
66  
67      @Override
68      public List<ActionItem> getActionItems(String documentId, List<String> actionRequestedCodes) {
69          incomingParamCheck(documentId, "documentId");
70          List<ActionItem> actionItems = getAllActionItems(documentId);
71          List<ActionItem> matchingActionitems = new ArrayList<ActionItem>();
72          for (ActionItem actionItemVO : actionItems) {
73              if (actionRequestedCodes.contains(actionItemVO.getActionRequestCd())) {
74                  matchingActionitems.add(actionItemVO);
75              }
76          }
77          return matchingActionitems;
78      }
79  
80      private void incomingParamCheck(Object object, String name) {
81          if (object == null) {
82              throw new RiceIllegalArgumentException(name + " was null");
83          } else if (object instanceof String
84                  && StringUtils.isBlank((String) object)) {
85              throw new RiceIllegalArgumentException(name + " was blank");
86          }
87      }
88  }