1 19 package org.openharmonise.him.actions.rules; 20 21 import java.util.*; 22 23 import org.openharmonise.him.*; 24 import org.openharmonise.him.harmonise.*; 25 import org.openharmonise.him.metadata.range.swing.relatedevents.*; 26 import org.openharmonise.vfs.*; 27 import org.openharmonise.vfs.authentication.*; 28 import org.openharmonise.vfs.metadata.*; 29 import org.openharmonise.vfs.metadata.value.*; 30 import org.openharmonise.vfs.servers.ServerList; 31 import org.openharmonise.workfloweditor.vfs.*; 32 33 34 42 public class isMetadataValidRule implements EnableRule { 43 44 boolean m_bComparator = true; 45 46 49 public isMetadataValidRule() { 50 super(); 51 } 53 54 57 public boolean isEnabled(VirtualFile vfFile) { 58 List props = vfFile.getProperties(); 59 60 Iterator iter = props.iterator(); 61 62 boolean bIsValid = true; 63 64 while (iter.hasNext() && bIsValid == true) { 65 PropertyInstance propInst = (PropertyInstance) iter.next(); 66 67 List vals = propInst.getValues(); 68 int nVals = 0; 69 70 for(int i=0;i<vals.size();i++) { 71 ValueInstance tmpVal = (ValueInstance) vals.get(i); 72 if(tmpVal != null) { 73 if(tmpVal instanceof DateValue) { 74 String dtVal = ((DateValue)tmpVal).getValue(); 75 76 if(dtVal != null && dtVal.length() > 0) { 77 nVals++; 78 } 79 } else { 80 nVals++; 81 } 82 83 } 84 } 85 86 List domains = propInst.getDefinition().getDomains(); 87 Iterator domIter = domains.iterator(); 88 89 while (domIter.hasNext() && bIsValid == true) { 90 Domain domain = (Domain)domIter.next(); 91 boolean bApplicableDomain = false; 92 String sFilePath = ((VersionedVirtualFile)vfFile).getLogicalPath(); 93 Iterator itor2 = domain.getPaths().iterator(); 94 while (itor2.hasNext()) { 95 String sDomainPath = (String ) itor2.next(); 96 if(sFilePath.startsWith(sDomainPath)) { 97 bApplicableDomain=true; 98 } 99 } 100 101 if(bApplicableDomain) { 102 int nMaxOccurs = -1; 103 int nMinOccurs = -1; 104 105 if (nMinOccurs < domain.getMinOccurs()) { 106 nMinOccurs = domain.getMinOccurs(); 107 } 108 if (domain.getMaxOccurs()!=-1 && nMaxOccurs > domain.getMaxOccurs()) { 109 nMaxOccurs = domain.getMaxOccurs(); 110 } 111 112 if(nMinOccurs > -1) { 113 bIsValid = nVals >= nMinOccurs; 114 } 115 116 if(bIsValid == true && nMaxOccurs > -1) { 117 bIsValid = nVals <= nMaxOccurs; 118 } 119 } 120 121 } 122 123 if(bIsValid == true) { 124 VFSUser user = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUser(); 125 126 ValidationResult result = propInst.getDefinition() 127 .getRange().validate(vals); 128 129 bIsValid = result.isValid(); 130 131 if(propInst.getDefinition().getHREF().startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS)) { 132 ArrayList stages = new ArrayList(); 133 134 VFSWorkflowModel model = new VFSWorkflowModel("", propInst.getDefinition()); 135 Iterator itor = model.getWorkflowStages().iterator(); 136 while (itor.hasNext()) { 137 VFSWorkflowStage stage = (VFSWorkflowStage) itor.next(); 138 139 Iterator itor2 = propInst.getValues().iterator(); 140 boolean bFoundVal = false; 141 while (itor2.hasNext()) { 142 ResourceValue tempValue = (ResourceValue) itor2.next(); 143 if(tempValue.getValue().equals(stage.getPath())) { 144 bFoundVal=true; 145 break; 146 } 147 } 148 if(stage.isMandatory() && !bFoundVal) { 149 bIsValid=false; 150 break; 151 } 152 } 153 } else if(propInst.getName().equals("related_events") || 154 propInst.getName().equals("Related Events")) { 155 RelatedEventRangeDisplay display = new RelatedEventRangeDisplay(propInst); 156 display.getPanel(); 157 if(!display.isMetadataValid()) { 158 bIsValid=false; 159 } 160 } 161 } 162 } 163 164 return bIsValid == m_bComparator; 165 } 166 167 170 public void setResultComparator(boolean bComparator) { 171 m_bComparator = bComparator; 172 } 173 174 } 175 | Popular Tags |