001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/api-impl/src/java/org/theospi/portfolio/workflow/impl/WorkflowManagerImpl.java $
003: * $Id: WorkflowManagerImpl.java 14543 2006-09-13 17:02:08Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.workflow.impl;
021:
022: import java.util.HashSet;
023: import java.util.Set;
024:
025: import org.sakaiproject.authz.api.SecurityService;
026: import org.sakaiproject.entity.api.EntityManager;
027: import org.sakaiproject.entity.api.Reference;
028: import org.sakaiproject.metaobj.shared.mgt.IdManager;
029: import org.sakaiproject.metaobj.shared.model.Id;
030: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
031: import org.theospi.portfolio.matrix.MatrixFunctionConstants;
032: import org.theospi.portfolio.matrix.model.WizardPageDefinition;
033: import org.theospi.portfolio.security.AuthorizationFacade;
034: import org.theospi.portfolio.shared.model.ObjectWithWorkflow;
035: import org.theospi.portfolio.wizard.model.Wizard;
036: import org.theospi.portfolio.workflow.mgt.WorkflowManager;
037: import org.theospi.portfolio.workflow.model.Workflow;
038: import org.theospi.portfolio.workflow.model.WorkflowItem;
039:
040: public class WorkflowManagerImpl extends HibernateDaoSupport implements
041: WorkflowManager {
042:
043: private AuthorizationFacade authorizationFacade;
044: private SecurityService securityService;
045: private EntityManager entityManager;
046: private IdManager idManager;
047:
048: public Workflow createNew(String description, String siteId,
049: Id securityQualifier, String securityViewFunction,
050: String securityEditFunction) {
051: // TODO Auto-generated method stub
052: return null;
053: }
054:
055: public Workflow getWorkflow(Id workflowId) {
056: Workflow workflow = (Workflow) getHibernateTemplate().get(
057: Workflow.class, workflowId);
058:
059: if (workflow == null) {
060: return null;
061: }
062: /*
063: if (workflow.getSecurityQualifier() != null) {
064: getAuthorizationFacade().checkPermission(workflow.getSecurityViewFunction(),
065: workflow.getSecurityQualifier());
066: }
067: */
068: return workflow;
069: }
070:
071: public Workflow saveWorkflow(Workflow workflow) {
072: if (workflow.isNewObject()) {
073: workflow.setNewId(workflow.getId());
074: workflow.setId(null);
075: getHibernateTemplate().save(workflow);
076: workflow.setNewObject(false);
077: } else {
078: getHibernateTemplate().saveOrUpdate(workflow);
079: }
080:
081: return workflow;
082: }
083:
084: public void deleteWorkflow(Workflow workflow) {
085: //for(Iterator iter = workflow.getItems().iterator(); iter.hasNext();) {
086: // WorkflowItem item = (WorkflowItem)iter.next();
087: // getHibernateTemplate().delete(item);
088: //}
089: workflow.getItems().clear();
090: getHibernateTemplate().delete(workflow);
091: //getHibernateTemplate().
092:
093: }
094:
095: public Reference decorateReference(Workflow workflow,
096: String reference) {
097: // TODO Auto-generated method stub
098: return null;
099: }
100:
101: public Workflow getWorkflow(String id) {
102: return getWorkflow(getIdManager().getId(id));
103: }
104:
105: public Set createEvalWorkflows(ObjectWithWorkflow obj) {
106: if (obj instanceof WizardPageDefinition)
107: return createEvalWorkflows((WizardPageDefinition) obj);
108: else
109: return createEvalWorkflows((Wizard) obj);
110: }
111:
112: protected Set createEvalWorkflows(WizardPageDefinition wpd) {
113: Set workflows = wpd.getEvalWorkflows();
114: if (wpd.getEvaluationDevice() != null
115: && wpd.getEvalWorkflows().size() == 0) {
116: Workflow w_none = new Workflow("No Workflow", wpd);
117: Workflow w_complete = new Workflow("Complete Workflow", wpd);
118: Workflow w_return = new Workflow("Return Workflow", wpd);
119:
120: Id id = wpd.getId() != null ? wpd.getId() : wpd.getNewId();
121:
122: w_complete.add(new WorkflowItem(
123: WorkflowItem.STATUS_CHANGE_WORKFLOW, id,
124: MatrixFunctionConstants.COMPLETE_STATUS));
125: w_return.add(new WorkflowItem(
126: WorkflowItem.CONTENT_LOCKING_WORKFLOW, id,
127: WorkflowItem.CONTENT_LOCKING_UNLOCK));
128: w_return.add(new WorkflowItem(
129: WorkflowItem.STATUS_CHANGE_WORKFLOW, id,
130: MatrixFunctionConstants.READY_STATUS));
131: workflows.add(w_none);
132: workflows.add(w_complete);
133: workflows.add(w_return);
134:
135: } else if (wpd.getEvaluationDevice() == null) {
136: workflows = new HashSet();
137: }
138: return workflows;
139: }
140:
141: protected Set createEvalWorkflows(Wizard wizard) {
142: Set workflows = wizard.getEvalWorkflows();
143: Id eval = wizard.getEvaluationDevice();
144: /*
145: for (Iterator iter = wizard.getSupportItems().iterator(); iter.hasNext();) {
146: WizardSupportItem wsi = (WizardSupportItem)iter.next();
147: String type = wsi.getGenericType();
148: if (type.equals(WizardFunctionConstants.EVALUATION_TYPE)) {
149: eval = wsi.getContentType();
150: break;
151: }
152: }
153: */
154: if (eval != null && wizard.getEvalWorkflows().size() == 0) {
155: Workflow w_none = new Workflow("No Workflow", wizard);
156: Workflow w_complete = new Workflow("Complete Workflow",
157: wizard);
158: Workflow w_return = new Workflow("Return Workflow", wizard);
159:
160: Id id = wizard.getId() != null ? wizard.getId() : wizard
161: .getNewId();
162:
163: w_complete.add(new WorkflowItem(
164: WorkflowItem.STATUS_CHANGE_WORKFLOW, id,
165: MatrixFunctionConstants.COMPLETE_STATUS));
166: w_return.add(new WorkflowItem(
167: WorkflowItem.CONTENT_LOCKING_WORKFLOW, id,
168: WorkflowItem.CONTENT_LOCKING_UNLOCK));
169: w_return.add(new WorkflowItem(
170: WorkflowItem.STATUS_CHANGE_WORKFLOW, id,
171: MatrixFunctionConstants.READY_STATUS));
172: workflows.add(w_none);
173: workflows.add(w_complete);
174: workflows.add(w_return);
175:
176: } else if (eval == null) {
177: workflows = new HashSet();
178: }
179: return workflows;
180: }
181:
182: /**
183: * @return Returns the authorizationFacade.
184: */
185: public AuthorizationFacade getAuthorizationFacade() {
186: return authorizationFacade;
187: }
188:
189: /**
190: * @param authorizationFacade The authorizationFacade to set.
191: */
192: public void setAuthorizationFacade(
193: AuthorizationFacade authorizationFacade) {
194: this .authorizationFacade = authorizationFacade;
195: }
196:
197: /**
198: * @return Returns the entityManager.
199: */
200: public EntityManager getEntityManager() {
201: return entityManager;
202: }
203:
204: /**
205: * @param entityManager The entityManager to set.
206: */
207: public void setEntityManager(EntityManager entityManager) {
208: this .entityManager = entityManager;
209: }
210:
211: /**
212: * @return Returns the idManager.
213: */
214: public IdManager getIdManager() {
215: return idManager;
216: }
217:
218: /**
219: * @param idManager The idManager to set.
220: */
221: public void setIdManager(IdManager idManager) {
222: this .idManager = idManager;
223: }
224:
225: /**
226: * @return Returns the securityService.
227: */
228: public SecurityService getSecurityService() {
229: return securityService;
230: }
231:
232: /**
233: * @param securityService The securityService to set.
234: */
235: public void setSecurityService(SecurityService securityService) {
236: this.securityService = securityService;
237: }
238: }
|