1 19 package org.openharmonise.rm.resources.workflow.values; 20 21 import java.util.*; 22 23 import org.openharmonise.commons.cache.*; 24 import org.openharmonise.commons.dsi.AbstractDataStoreInterface; 25 import org.openharmonise.rm.*; 26 import org.openharmonise.rm.resources.*; 27 import org.openharmonise.rm.resources.lifecycle.*; 28 import org.openharmonise.rm.resources.metadata.values.ValueGroup; 29 30 31 39 public class WorkflowStageValueGroup extends ValueGroup { 40 41 private static List WORKFLOW_CHILDREN = null; 42 43 static { 44 WORKFLOW_CHILDREN = new ArrayList(); 45 WORKFLOW_CHILDREN.add(WorkflowStageValue.class.getName()); 46 WORKFLOW_CHILDREN.add(WorkflowStageValueGroup.class.getName()); 47 } 48 49 52 public WorkflowStageValueGroup() { 53 super(); 54 55 } 56 57 60 public WorkflowStageValueGroup(AbstractDataStoreInterface dbintrf) { 61 super(dbintrf); 62 63 } 64 65 69 public WorkflowStageValueGroup(AbstractDataStoreInterface dbintrf, int nId) { 70 super(dbintrf, nId); 71 72 } 73 74 79 public WorkflowStageValueGroup( 80 AbstractDataStoreInterface dbintrf, 81 int nId, 82 int nKey, 83 boolean bIsHist) { 84 super(dbintrf, nId, nKey, bIsHist); 85 86 } 87 88 92 public WorkflowStageValueGroup( 93 AbstractDataStoreInterface dbintrf, 94 boolean bIsHist) { 95 super(dbintrf, bIsHist); 96 97 } 98 99 102 public List getChildClassNames() { 103 return WORKFLOW_CHILDREN; 104 } 105 106 109 public String getParentObjectClassName() { 110 111 return super.getParentObjectClassName(); 112 } 113 114 117 public boolean isValidChild(AbstractChildObject childObj) { 118 boolean bIsValid = false; 119 120 try { 121 List children = getChildren(); 122 123 if(children.size() > 0) { 124 boolean bIsChildParent = (childObj instanceof AbstractParentObject); 125 126 AbstractChildObject firstChild = (AbstractChildObject) children.get(0); 129 130 if(bIsChildParent == true && firstChild instanceof AbstractParentObject) { 131 bIsValid = true; 132 } else if(bIsChildParent == false && (firstChild instanceof AbstractParentObject) == false) { 133 bIsValid = true; 134 } 135 } else { 136 bIsValid = super.isValidChild(childObj); 137 } 138 } catch (DataAccessException e) { 139 bIsValid = super.isValidChild(childObj); 141 } 142 143 return bIsValid; 144 } 145 146 149 protected void saveNonCoreData() throws EditException { 150 152 if(m_remove_children != null && m_remove_children.size() > 0) { 153 154 List stagesToSave = new ArrayList(); 155 try { 156 for (Iterator iter = m_remove_children.iterator(); iter.hasNext();) { 158 CachePointer tmpChildPtr = (CachePointer) iter.next(); 159 160 Object tmpObj = tmpChildPtr.getObject(); 161 162 163 if(tmpObj instanceof WorkflowStageValue) { 164 List dependantOnThis = new ArrayList(); 165 List dependants = new ArrayList(); 166 167 WorkflowStageValue stageToRemove = (WorkflowStageValue) tmpObj; 168 169 if(stageToRemove.getPendingVersions().size() == 0) { 170 171 List depends = stageToRemove.getDependencies(); 172 173 for (Iterator innerIter = m_children.iterator(); innerIter 174 .hasNext();) { 175 CachePointer innerPtr = (CachePointer) innerIter.next(); 176 177 if(tmpChildPtr != innerPtr) { 178 Object innerObj = innerPtr.getObject(); 179 180 if(innerObj instanceof WorkflowStageValue) { 181 WorkflowStageValue innerStage = (WorkflowStageValue) innerObj; 182 if(depends.contains(innerStage)) { 183 dependants.add(innerStage); 185 186 } else { 187 List innerDepends = innerStage.getDependencies(); 188 189 if(innerDepends.contains(stageToRemove)) { 190 dependantOnThis.add(innerStage); 192 } 193 } 194 } 195 } 196 } 197 198 if(dependants.size() > 0 && dependantOnThis.size() > 0) { 200 for (Iterator depIter = dependantOnThis.iterator(); depIter.hasNext();) { 201 WorkflowStageValue dependantStage = (WorkflowStageValue) depIter.next(); 202 if(dependantStage.getStatus() == Status.APPROVED) { 203 List otherDepends = dependantStage.getDependencies(); 204 205 otherDepends.remove(stageToRemove); 206 otherDepends.addAll(dependants); 207 dependantStage.setDependencies(otherDepends); 208 stagesToSave.add(dependantStage); 209 210 } else { 211 throw new EditException("WorkflowStage should be approved by now!!!"); 212 } 213 214 } 215 } 216 } 217 } 218 } 219 220 for (Iterator iter = stagesToSave.iterator(); iter.hasNext();) { 221 WorkflowStageValue tmpStage = (WorkflowStageValue) iter.next(); 222 tmpStage.save().changeStatus(Status.APPROVED); 223 } 224 } catch (DataAccessException e) { 225 throw new EditException(e); 226 } catch (PopulateException e) { 227 throw new EditException(e); 228 } catch (CacheException e) { 229 throw new EditException(e); 230 } 231 } 232 233 super.saveNonCoreData(); 234 } 235 } 236 | Popular Tags |