001    /**
002     * Copyright 2005-2012 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     */
016    package org.kuali.rice.kew.impl.actionlist;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
020    import org.kuali.rice.kew.actionitem.ActionItemActionListExtension;
021    import org.kuali.rice.kew.api.action.ActionItem;
022    import org.kuali.rice.kew.api.actionlist.ActionListService;
023    import org.kuali.rice.kew.service.KEWServiceLocator;
024    
025    import java.util.ArrayList;
026    import java.util.Collection;
027    import java.util.List;
028    
029    /**
030     * Reference implementation of the {@link org.kuali.rice.kew.api.actionlist.ActionListService} api.
031     *
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     *
034     */
035    public class ActionListServiceNewImpl implements ActionListService {
036    
037        @Override
038        public Integer getUserActionItemCount(String principalId) {
039            incomingParamCheck(principalId, "principalId");
040            return Integer.valueOf(KEWServiceLocator.getActionListService().getCount(principalId));
041        }
042    
043        @Override
044        public List<ActionItem> getActionItemsForPrincipal(String principalId) {
045            incomingParamCheck(principalId, "principalId");
046            Collection<ActionItemActionListExtension> actionItems
047                    = KEWServiceLocator.getActionListService().getActionList(principalId, null);
048            List<ActionItem> actionItemVOs = new ArrayList<ActionItem>(actionItems.size());
049            for (org.kuali.rice.kew.actionitem.ActionItem actionItem : actionItems) {
050                actionItemVOs.add(org.kuali.rice.kew.actionitem.ActionItem.to(actionItem));
051            }
052            return actionItemVOs;
053        }
054    
055        @Override
056        public List<ActionItem> getAllActionItems(String documentId) {
057            incomingParamCheck(documentId, "documentId");
058            Collection<ActionItemActionListExtension> actionItems
059                    = KEWServiceLocator.getActionListService().getActionListForSingleDocument(documentId);
060            List<ActionItem> actionItemVOs = new ArrayList<ActionItem>(actionItems.size());
061            for (org.kuali.rice.kew.actionitem.ActionItem actionItem : actionItems) {
062                actionItemVOs.add(org.kuali.rice.kew.actionitem.ActionItem.to(actionItem));
063            }
064            return actionItemVOs;
065        }
066    
067        @Override
068        public List<ActionItem> getActionItems(String documentId, List<String> actionRequestedCodes) {
069            incomingParamCheck(documentId, "documentId");
070            List<ActionItem> actionItems = getAllActionItems(documentId);
071            List<ActionItem> matchingActionitems = new ArrayList<ActionItem>();
072            for (ActionItem actionItemVO : actionItems) {
073                if (actionRequestedCodes.contains(actionItemVO.getActionRequestCd())) {
074                    matchingActionitems.add(actionItemVO);
075                }
076            }
077            return matchingActionitems;
078        }
079    
080        private void incomingParamCheck(Object object, String name) {
081            if (object == null) {
082                throw new RiceIllegalArgumentException(name + " was null");
083            } else if (object instanceof String
084                    && StringUtils.isBlank((String) object)) {
085                throw new RiceIllegalArgumentException(name + " was blank");
086            }
087        }
088    }