View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.rule;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
21  import org.kuali.rice.kew.api.rule.Rule;
22  import org.kuali.rice.kew.api.rule.RuleReportCriteria;
23  import org.kuali.rice.kew.api.rule.RuleService;
24  import org.kuali.rice.kew.rule.RuleBaseValues;
25  import org.kuali.rice.kew.service.KEWServiceLocator;
26  
27  import java.util.ArrayList;
28  import java.util.Collection;
29  import java.util.List;
30  
31  /**
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class RuleServiceImpl implements RuleService {
37      private static final Logger LOG = Logger.getLogger(RuleServiceImpl.class);
38  
39      @Override
40      public List<Rule> ruleReport(RuleReportCriteria ruleReportCriteria) {
41          incomingParamCheck(ruleReportCriteria, "ruleReportCriteria");
42          if ( LOG.isDebugEnabled() ) {
43          	LOG.debug("Executing rule report [responsibleUser=" + ruleReportCriteria.getResponsiblePrincipalId() + ", responsibleWorkgroup=" +
44                      ruleReportCriteria.getResponsibleGroupId() + "]");
45          }
46          Collection<RuleBaseValues> rulesFound = KEWServiceLocator.getRuleService().searchByTemplate(
47                  ruleReportCriteria.getDocumentTypeName(), ruleReportCriteria.getRuleTemplateName(),
48                  ruleReportCriteria.getRuleDescription(), ruleReportCriteria.getResponsibleGroupId(),
49                  ruleReportCriteria.getResponsiblePrincipalId(), Boolean.valueOf(ruleReportCriteria.isConsiderGroupMembership()),
50                  Boolean.valueOf(ruleReportCriteria.isIncludeDelegations()), Boolean.valueOf(ruleReportCriteria.isActive()), ruleReportCriteria.getRuleExtensions(),
51                  ruleReportCriteria.getActionRequestCodes());
52          List<org.kuali.rice.kew.api.rule.Rule> returnableRules = new ArrayList<Rule>(rulesFound.size());
53          for (RuleBaseValues rule : rulesFound) {
54              returnableRules.add(RuleBaseValues.to(rule));
55          }
56          return returnableRules;
57      }
58  
59      private void incomingParamCheck(Object object, String name) {
60          if (object == null) {
61              throw new RiceIllegalArgumentException(name + " was null");
62          } else if (object instanceof String
63                  && StringUtils.isBlank((String) object)) {
64              throw new RiceIllegalArgumentException(name + " was blank");
65          }
66      }
67  }