Coverage Report - org.kuali.rice.kew.rule.service.impl.RuleAttributeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleAttributeServiceImpl
0%
0/47
0%
0/14
1.923
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.rule.service.impl;
 18  
 
 19  
 import java.io.FileNotFoundException;
 20  
 import java.io.InputStream;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collection;
 23  
 import java.util.List;
 24  
 
 25  
 import org.jdom.Element;
 26  
 import org.kuali.rice.core.api.impex.ExportDataSet;
 27  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 28  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 29  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 30  
 import org.kuali.rice.kew.rule.dao.RuleAttributeDAO;
 31  
 import org.kuali.rice.kew.rule.service.RuleAttributeService;
 32  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 33  
 import org.kuali.rice.kew.xml.RuleAttributeXmlParser;
 34  
 import org.kuali.rice.kew.xml.export.RuleAttributeXmlExporter;
 35  
 
 36  
 
 37  0
 public class RuleAttributeServiceImpl implements RuleAttributeService {
 38  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleAttributeServiceImpl.class);
 39  
 
 40  
     private static final String RULE_ATTRIBUTE_NAME_REQUIRED = "rule.attribute.name.required";
 41  
     private static final String RULE_ATTRIBUTE_CLASS_REQUIRED = "rule.attribute.className.required";
 42  
 
 43  
     private static final String XML_FILE_NOT_FOUND = "general.error.filenotfound";
 44  
     private static final String XML_PARSE_ERROR = "general.error.parsexml";
 45  
 
 46  
     private RuleAttributeDAO ruleAttributeDAO;
 47  
 
 48  
     public void save(RuleAttribute ruleAttribute) {
 49  0
         validate(ruleAttribute);
 50  0
         KEWServiceLocator.getDocumentTypeService().clearCacheForAttributeUpdate(ruleAttribute);
 51  0
         getRuleAttributeDAO().save(ruleAttribute);
 52  0
     }
 53  
 
 54  
     public void delete(String ruleAttributeId) {
 55  0
         getRuleAttributeDAO().delete(ruleAttributeId);
 56  0
     }
 57  
 
 58  
     public List<RuleAttribute> findByRuleAttribute(RuleAttribute ruleAttribute) {
 59  0
         return getRuleAttributeDAO().findByRuleAttribute(ruleAttribute);
 60  
     }
 61  
 
 62  
     public RuleAttribute findByRuleAttributeId(String ruleAttributeId) {
 63  0
         return getRuleAttributeDAO().findByRuleAttributeId(ruleAttributeId);
 64  
     }
 65  
 
 66  
     public List<RuleAttribute> findAll() {
 67  0
         return getRuleAttributeDAO().getAllRuleAttributes();
 68  
     }
 69  
 
 70  
     public RuleAttribute findByName(String name) {
 71  0
             return getRuleAttributeDAO().findByName(name);
 72  
     }
 73  
 
 74  
     public RuleAttributeDAO getRuleAttributeDAO() {
 75  0
         return ruleAttributeDAO;
 76  
     }
 77  
 
 78  
     public void setRuleAttributeDAO(RuleAttributeDAO ruleAttributeDAO) {
 79  0
         this.ruleAttributeDAO = ruleAttributeDAO;
 80  0
     }
 81  
 
 82  
     private void validate(RuleAttribute ruleAttribute) {
 83  0
         LOG.debug("validating ruleAttribute");
 84  0
         Collection errors = new ArrayList();
 85  0
         if (ruleAttribute.getName() == null || ruleAttribute.getName().trim().equals("")) {
 86  0
             errors.add(new WorkflowServiceErrorImpl("Please enter a rule attribute name.", RULE_ATTRIBUTE_NAME_REQUIRED));
 87  0
             LOG.error("Rule attribute name is missing");
 88  
         } else {
 89  0
                 ruleAttribute.setName(ruleAttribute.getName().trim());
 90  0
             if (ruleAttribute.getRuleAttributeId() == null) {
 91  0
                 RuleAttribute nameInUse = findByName(ruleAttribute.getName());
 92  0
                 if (nameInUse != null) {
 93  0
                     errors.add(new WorkflowServiceErrorImpl("Rule attribute name already in use", "routetemplate.ruleattribute.name.duplicate"));
 94  0
                     LOG.error("Rule attribute name already in use");
 95  
                 }
 96  
             }
 97  
         }
 98  0
         if (ruleAttribute.getClassName() == null || ruleAttribute.getClassName().trim().equals("")) {
 99  0
             errors.add(new WorkflowServiceErrorImpl("Please enter a rule attribute class name.", RULE_ATTRIBUTE_CLASS_REQUIRED));
 100  0
             LOG.error("Rule attribute class name is missing");
 101  
         } else {
 102  0
                 ruleAttribute.setClassName(ruleAttribute.getClassName().trim());
 103  
         }
 104  
 
 105  0
         LOG.debug("end validating ruleAttribute");
 106  0
         if (!errors.isEmpty()) {
 107  0
             throw new WorkflowServiceErrorException("RuleAttribute Validation Error", errors);
 108  
         }
 109  0
     }
 110  
 
 111  
     public void loadXml(InputStream inputStream, String principalId) {
 112  0
         RuleAttributeXmlParser parser = new RuleAttributeXmlParser();
 113  
         try {
 114  0
             parser.parseRuleAttributes(inputStream);
 115  0
         } catch(FileNotFoundException e) {
 116  0
             throw new WorkflowServiceErrorException("XML file not found", new WorkflowServiceErrorImpl("Rule Attribute XML file not found", XML_FILE_NOT_FOUND) );
 117  0
             } catch (Exception e) { //any other exception
 118  0
             LOG.error("Error loading xml file", e);
 119  0
             throw new WorkflowServiceErrorException("Error loading xml file", new WorkflowServiceErrorImpl("Error loading xml file", XML_PARSE_ERROR));
 120  0
         }
 121  0
     }
 122  
 
 123  
     public Element export(ExportDataSet dataSet) {
 124  0
         RuleAttributeXmlExporter exporter = new RuleAttributeXmlExporter();
 125  0
         return exporter.export(dataSet);
 126  
     }
 127  
     
 128  
         @Override
 129  
         public boolean supportPrettyPrint() {
 130  0
                 return true;
 131  
         }
 132  
 
 133  
         public RuleAttribute findByClassName(String className) {
 134  0
                 return this.ruleAttributeDAO.findByClassName(className);
 135  
         }
 136  
 }