1 19 package org.openharmonise.rm.resources.workflow.values; 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.lifecycle.*; 31 import org.openharmonise.rm.resources.metadata.properties.*; 32 import org.openharmonise.rm.resources.metadata.values.Value; 33 34 35 45 public class WorkflowStageValue extends Value { 46 47 public static final String TAG_WORKFLOW_STAGE = "WorkflowStage"; 48 49 public static final String PROPNAME_ALLOWED_ROLES = "WORKFLOW_ROLES"; 50 public static final String PROPNAME_IS_MANDATORY = "WORKFLOW_MAND"; 51 public static final String PROPNAME_IS_INHERITABLE = "WORKFLOW_INHERIT"; 52 public static final String PROPNAME_DEPENDENCY = "WORKFLOW_DEPEND"; 53 public static final String PROPNAME_DEFINITION = "WORKFLOW_RELN"; 54 55 58 private static final Logger m_logger = Logger.getLogger(WorkflowStageValue.class.getName()); 59 60 63 public WorkflowStageValue() { 64 super(); 65 } 66 67 72 public WorkflowStageValue(AbstractDataStoreInterface dbintrf) { 73 super(dbintrf); 74 } 75 76 82 public WorkflowStageValue( 83 AbstractDataStoreInterface dbintrf, 84 int nId) { 85 super(dbintrf, nId); 86 } 87 88 96 public WorkflowStageValue( 97 AbstractDataStoreInterface dbintrf, 98 boolean bIsHist) 99 throws Exception { 100 super(dbintrf, bIsHist); 101 } 102 103 110 public WorkflowStageValue( 111 AbstractDataStoreInterface dbintrf, 112 int nId, 113 int nKey, 114 boolean bIsHist) { 115 super(dbintrf, nId, nKey, bIsHist); 116 } 117 118 125 public boolean isInheritable() throws DataAccessException { 126 boolean bIsInherit = false; 127 128 try { 129 GeneralPropertyInstance propInst = (GeneralPropertyInstance) getProfile().getPropertyInstance(PROPNAME_IS_INHERITABLE); 130 131 if(propInst != null) { 132 bIsInherit = propInst.getBooleanValue(); 133 } 134 135 } catch (InvalidPropertyInstanceException e) { 136 m_logger.log(Level.INFO, "Inheritable property not valid on workflow stage!", e); 139 } 140 141 return bIsInherit; 142 } 143 144 150 public List getDependencies() throws DataAccessException { 151 List depends = new ArrayList(); 152 153 try { 154 ChildObjectPropertyInstance propInst = 155 (ChildObjectPropertyInstance) getProfile().getPropertyInstance( 156 PROPNAME_DEPENDENCY); 157 if(propInst != null) { 158 depends = propInst.getValues(); 159 } 160 } catch (InvalidPropertyInstanceException e) { 161 m_logger.log(Level.INFO, "Inheritable property not valid on workflow stage!", e); 164 } 165 166 return depends; 167 } 168 169 176 public void setDependencies(List depends) throws PopulateException { 177 try { 178 ChildObjectPropertyInstance propInst = 179 (ChildObjectPropertyInstance) getProfile().getPropertyInstance( 180 PROPNAME_DEPENDENCY); 181 182 if(propInst == null) { 183 Property prop = PropertyFactory.getPropertyFromName(m_dsi, PROPNAME_DEPENDENCY); 184 propInst = (ChildObjectPropertyInstance) PropertyInstanceFactory.getPropertyInstance(m_dsi, prop); 185 getProfile().addPropertyInstance(propInst); 186 } 187 188 propInst.setValues(depends); 189 } catch (InvalidPropertyInstanceException e) { 190 m_logger.log(Level.INFO, "Inheritable property not valid on workflow stage!", e); 193 } catch (DataAccessException e) { 194 throw new PopulateException(e.getLocalizedMessage(),e); 195 } catch (HarmoniseFactoryException e) { 196 throw new PopulateException(e.getLocalizedMessage(),e); 197 } catch (InvalidPropertyValueException e) { 198 throw new PopulateException(e.getLocalizedMessage(),e); 199 } catch (ProfileException e) { 200 throw new PopulateException(e.getLocalizedMessage(),e); 201 } 202 } 203 204 211 public List getRoles() throws DataAccessException { 212 List roles = new ArrayList(); 213 214 try { 215 ChildObjectPropertyInstance propInst = 216 (ChildObjectPropertyInstance) getProfile().getPropertyInstance( 217 PROPNAME_ALLOWED_ROLES); 218 if(propInst != null) { 219 roles = propInst.getValues(); 220 } 221 } catch (InvalidPropertyInstanceException e) { 222 m_logger.log(Level.INFO, "Inheritable property not valid on workflow stage!", e); 225 } 226 227 return roles; 228 } 229 230 237 public void setRoles(List roles) throws PopulateException { 238 try { 239 ChildObjectPropertyInstance propInst = 240 (ChildObjectPropertyInstance) getProfile().getPropertyInstance( 241 PROPNAME_ALLOWED_ROLES); 242 243 if(propInst == null) { 244 Property prop = PropertyFactory.getPropertyFromName(m_dsi, PROPNAME_ALLOWED_ROLES); 245 propInst = (ChildObjectPropertyInstance) PropertyInstanceFactory.getPropertyInstance(m_dsi, prop); 246 getProfile().addPropertyInstance(propInst); 247 } 248 249 propInst.setValues(roles); 250 } catch (InvalidPropertyInstanceException e) { 251 m_logger.log(Level.INFO, "Inheritable property not valid on workflow stage!", e); 254 } catch (DataAccessException e) { 255 throw new PopulateException(e.getLocalizedMessage(),e); 256 } catch (HarmoniseFactoryException e) { 257 throw new PopulateException(e.getLocalizedMessage(),e); 258 } catch (InvalidPropertyValueException e) { 259 throw new PopulateException(e.getLocalizedMessage(),e); 260 } catch (ProfileException e) { 261 throw new PopulateException(e.getLocalizedMessage(),e); 262 } 263 } 264 265 268 public String getParentObjectClassName() { 269 return WorkflowStageValueGroup.class.getName(); 270 } 271 272 277 public boolean isMandatory() throws DataAccessException { 278 boolean bIsMandatory = false; 279 280 try { 281 GeneralPropertyInstance propInst = (GeneralPropertyInstance) getProfile().getPropertyInstance(PROPNAME_IS_MANDATORY); 282 283 if(propInst != null) { 284 bIsMandatory = propInst.getBooleanValue(); 285 } 286 287 } catch (InvalidPropertyInstanceException e) { 288 m_logger.log(Level.INFO, "Inheritable property not valid on workflow stage!", e); 291 } 292 293 return bIsMandatory; 294 } 295 296 public Editable changeStatus(Status status) throws EditException { 297 298 try { 301 Profile prof = this.getProfile(); 302 Property inheritProp = PropertyFactory.getPropertyFromName(m_dsi, PROPNAME_IS_INHERITABLE); 303 304 if(prof != null && prof.isValidProperty(inheritProp)) { 305 GeneralPropertyInstance isInherit = (GeneralPropertyInstance) prof.getPropertyInstance(inheritProp); 306 307 if(isInherit != null && isInherit.getBooleanValue() == true) { 308 List depends = this.getDependencies(); 309 310 Iterator iter = depends.iterator(); 311 312 while (iter.hasNext()) { 313 WorkflowStageValue stage = (WorkflowStageValue) iter.next(); 314 if(stage.isMandatory() == true && stage.isInheritable() == false) { 315 throw new StatusChangeNotAllowedException("Mandatory dependancies must be inheritable"); 316 } 317 } 318 319 } 320 } 321 } catch (InvalidPropertyInstanceException e) { 322 throw new EditException(e.getLocalizedMessage(),e); 323 } catch (DataAccessException e) { 324 throw new EditException(e.getLocalizedMessage(),e); 325 } catch (HarmoniseFactoryException e) { 326 throw new EditException(e.getLocalizedMessage(),e); 327 } 328 329 return super.changeStatus(status); 330 } 331 332 336 public void removeAllInstances() throws EditException { 337 ResultSet rs = null; 338 339 try { 340 SelectStatement select = new SelectStatement(); 341 342 Property prop = PropertyFactory.getPropertyFromName(m_dsi, PROPNAME_DEFINITION); 343 344 AbstractPropertyInstance propInst = PropertyInstanceFactory.getPropertyInstance(m_dsi, prop); 345 Profile prof = getProfile(); 346 propInst.setProfile(prof); 347 select.addSelectColumn(this.getInstanceColumnRef(ATTRIB_ID, false)); 348 349 select.addJoinCondition(prof.getInstanceColumnRef(Profile.ATTRIB_OBJECT_KEY, false), this.getInstanceColumnRef(ATTRIB_KEY, false)); 350 select.addJoinCondition(propInst.getInstanceColumnRef(Profile.TAG_PROFILE, false), prof.getInstanceColumnRef(ATTRIB_ID, false)); 351 352 select.addWhereCondition(propInst.getInstanceColumnRef(Property.TAG_PROPERTY, false), "=", prop.getId()); 353 select.addWhereCondition(propInst.getInstanceColumnRef(AbstractPropertyInstance.TAG_VALUE, false), "=", getId()); 354 355 rs = m_dsi.execute(select); 356 357 while(rs.next()) { 358 int nId = rs.getInt(1); 359 360 WorkflowStageValue stage = (WorkflowStageValue) HarmoniseObjectFactory.instantiateHarmoniseObject(m_dsi, WorkflowStageValue.class.getName(), nId); 361 362 if(stage != null) { 363 stage.archive(); 364 } 365 } 366 } catch (HarmoniseFactoryException e) { 367 throw new EditException(e); 368 } catch (DataAccessException e) { 369 throw new EditException(e); 370 } catch (DataStoreException e) { 371 throw new EditException(e); 372 } catch (SQLException e) { 373 throw new EditException(e); 374 } finally { 375 if(rs != null) { 376 try { 377 rs.close(); 378 } catch (SQLException e) { 379 throw new EditException(e); 380 } 381 } 382 } 383 } 384 385 388 public String getTagName() { 389 return TAG_WORKFLOW_STAGE; 390 } 391 } 392 | Popular Tags |