1 19 package org.openharmonise.rm.workflow; 20 21 import java.sql.*; 22 import java.util.*; 23 import java.util.logging.*; 24 25 import org.openharmonise.commons.dsi.*; 26 import org.openharmonise.commons.dsi.dml.SelectStatement; 27 import org.openharmonise.rm.*; 28 import org.openharmonise.rm.factory.*; 29 import org.openharmonise.rm.metadata.*; 30 import org.openharmonise.rm.resources.*; 31 import org.openharmonise.rm.resources.metadata.properties.Property; 32 import org.openharmonise.rm.resources.metadata.properties.domains.Domain; 33 import org.openharmonise.rm.resources.workflow.properties.WorkflowProperty; 34 import org.openharmonise.rm.resources.workflow.values.WorkflowStageValue; 35 36 37 44 public class WorkflowProfile extends Profile { 45 46 public static final String WORKFLOW_PROFILE_NAME = "Workflow"; 47 48 private static final Logger m_logger = Logger.getLogger(WorkflowProfile.class.getName()); 49 50 { 51 try { 52 super.setName(WORKFLOW_PROFILE_NAME); 53 } catch (InvalidNameException e) { 54 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 56 } 57 } 58 59 62 public WorkflowProfile() { 63 super(); 64 65 } 66 67 70 public WorkflowProfile(AbstractDataStoreInterface dbintrf) { 71 super(dbintrf); 72 73 } 74 75 79 public WorkflowProfile( 80 AbstractDataStoreInterface dbintrf, 81 AbstractProfiledObject obj) { 82 super(dbintrf, obj); 83 84 } 85 86 91 public WorkflowProfile( 92 AbstractDataStoreInterface dbintrf, 93 int nId, 94 AbstractProfiledObject obj) { 95 super(dbintrf, nId, obj); 96 97 } 98 99 102 public String getName() throws DataAccessException { 103 return WORKFLOW_PROFILE_NAME; 104 } 105 106 109 public void setName(String sName) { 110 } 112 113 116 public boolean isValid(AbstractProfiledObject profObj) 117 throws DataAccessException { 118 119 return true; 121 } 122 123 128 static public List getWorkflowProperties(AbstractDataStoreInterface dsi) throws DataAccessException { 129 List wkflw_props = new ArrayList(); 130 String sClassname = WorkflowProperty.class.getName(); 131 ResultSet rs = null; 132 try { 133 SelectStatement select = new SelectStatement(); 134 135 select.addSelectColumn(AbstractObject.getColumnRef(sClassname,AbstractObject.ATTRIB_ID)); 136 137 select.addWhereCondition(AbstractObject.getColumnRef(sClassname,AbstractObject.ATTRIB_TYPE), "=",WorkflowProperty.class.getName()); 138 139 rs = dsi.execute(select); 140 141 while(rs.next()) { 142 WorkflowProperty prop = (WorkflowProperty) HarmoniseObjectFactory.instantiateHarmoniseObject(dsi, sClassname, rs.getInt(1)); 143 wkflw_props.add(prop); 144 } 145 146 } catch (DataStoreException e) { 147 throw new DataAccessException(e.getLocalizedMessage(),e); 148 } catch (SQLException e) { 149 throw new DataAccessException(e.getLocalizedMessage(),e); 150 } catch (HarmoniseFactoryException e) { 151 throw new DataAccessException(e.getLocalizedMessage(),e); 152 } finally { 153 try { 154 rs.close(); 155 } catch (SQLException e) { 156 throw new DataAccessException(e.getLocalizedMessage(),e); 157 } 158 } 159 160 return wkflw_props; 161 } 162 163 171 public static List getAvailableWorkflowProperties(AbstractProfiledObject profObj) throws DataAccessException { 172 List props = new ArrayList(); 173 174 List normProps = Domain.getAvailableProperties(profObj.getDataStoreInterface(), profObj); 175 176 Iterator iter = normProps.iterator(); 177 178 while (iter.hasNext()) { 179 Property tmpProp = (Property) iter.next(); 180 181 if(tmpProp instanceof WorkflowProperty) { 182 props.add(tmpProp); 183 } 184 } 185 186 return props; 187 } 188 189 192 public List getAvailableProperties() throws DataAccessException { 193 return getWorkflowProperties(m_dsi); 194 } 195 196 199 public void markAsNew() throws PopulateException { 200 201 try { 202 List propInsts = getPropertyInstances(); 203 204 Iterator iter = propInsts.iterator(); 205 206 while(iter.hasNext()) { 207 WorkflowPropertyInstance propInst = (WorkflowPropertyInstance) iter.next(); 208 209 List vals = propInst.getValues(); 210 211 Iterator valIter = vals.iterator(); 212 213 while (valIter.hasNext()) { 214 WorkflowStageValue stage = (WorkflowStageValue) valIter.next(); 215 216 if(stage.isInheritable() == false) { 217 propInst.removeValue(stage); 218 } 219 } 220 } 221 } catch (DataAccessException e) { 222 throw new PopulateException(e.getLocalizedMessage(),e); 223 } catch (InvalidPropertyValueException e) { 224 throw new PopulateException(e.getLocalizedMessage(),e); 225 } 226 227 super.markAsNew(); 228 } 229 230 239 public static WorkflowPropertyInstance getWorkflowPropertyInstance(AbstractProfiledObject profObj, String sPropName) throws InvalidPropertyInstanceException, DataAccessException { 240 WorkflowProfile workflowProf = (WorkflowProfile) profObj.getProfile(WORKFLOW_PROFILE_NAME); 241 return (WorkflowPropertyInstance) workflowProf.getPropertyInstance(sPropName); 242 } 243 } 244 | Popular Tags |