001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.kuali.workflow.workgroup;
018:
019: import java.io.FileNotFoundException;
020: import java.io.InputStream;
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.List;
024:
025: import org.jdom.Element;
026: import org.kuali.workflow.workgroup.dao.WorkgroupTypeDAO;
027:
028: import edu.iu.uis.eden.WorkflowServiceErrorException;
029: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
030: import edu.iu.uis.eden.export.ExportDataSet;
031: import edu.iu.uis.eden.user.WorkflowUser;
032: import edu.iu.uis.eden.xml.export.RuleTemplateXmlExporter;
033:
034: /**
035: * Basic implementation of the WorkgroupTypeService.
036: *
037: * @author ewestfal
038: */
039: public class WorkgroupTypeServiceImpl implements WorkgroupTypeService {
040:
041: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
042: .getLogger(WorkgroupTypeServiceImpl.class);
043:
044: private static final String XML_FILE_NOT_FOUND = "general.error.filenotfound";
045: private static final String XML_PARSE_ERROR = "general.error.parsexml";
046:
047: private WorkgroupTypeDAO workgroupTypeDAO;
048:
049: public WorkgroupType findById(Long workgroupTypeId) {
050: return getWorkgroupTypeDAO().findById(workgroupTypeId);
051: }
052:
053: public WorkgroupType findByName(String workgroupTypeName) {
054: return getWorkgroupTypeDAO().findByName(workgroupTypeName);
055: }
056:
057: public List<WorkgroupType> findAllActive() {
058: Collection workgroupTypes = getWorkgroupTypeDAO().findAll(true);
059: return new ArrayList<WorkgroupType>(workgroupTypes);
060: }
061:
062: public List<WorkgroupType> findAll() {
063: Collection workgroupTypes = getWorkgroupTypeDAO()
064: .findAll(false);
065: return new ArrayList<WorkgroupType>(workgroupTypes);
066: }
067:
068: public void save(WorkgroupType workgroupType) {
069: getWorkgroupTypeDAO().save(workgroupType);
070: }
071:
072: public WorkgroupTypeDAO getWorkgroupTypeDAO() {
073: return workgroupTypeDAO;
074: }
075:
076: public void setWorkgroupTypeDAO(WorkgroupTypeDAO workgroupTypeDAO) {
077: this .workgroupTypeDAO = workgroupTypeDAO;
078: }
079:
080: public void loadXml(InputStream inputStream, WorkflowUser user) {
081: try {
082: WorkgroupTypeXmlParser parser = new WorkgroupTypeXmlParser();
083: parser.setWorkgroupTypeService(this );
084: List<WorkgroupType> workgroupTypes = parser
085: .parseWorkgroupTypes(inputStream);
086: for (WorkgroupType workgroupType : workgroupTypes) {
087: save(workgroupType);
088: }
089: } catch (FileNotFoundException e) {
090: throw new WorkflowServiceErrorException(
091: "XML file not found", new WorkflowServiceErrorImpl(
092: "Rule Attribute XML file not found",
093: XML_FILE_NOT_FOUND));
094: } catch (Exception e) { //any other exception
095: LOG.error("Error loading xml file", e);
096: throw new WorkflowServiceErrorException(
097: "Error loading xml file",
098: new WorkflowServiceErrorImpl(
099: "Error loading xml file", XML_PARSE_ERROR));
100: }
101: }
102:
103: public List<WorkgroupType> search(Long id, String name,
104: String label, String description, Boolean active) {
105: Collection results = getWorkgroupTypeDAO().search(id, name,
106: label, description, active);
107: return new ArrayList<WorkgroupType>(results);
108: }
109:
110: public Element export(ExportDataSet dataSet) {
111: WorkgroupTypeXmlExporter exporter = new WorkgroupTypeXmlExporter();
112: return exporter.export(dataSet);
113: }
114:
115: }
|