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