1 19 package org.openharmonise.rm.resources.workflow.properties.domains; 20 21 import java.sql.*; 22 import java.util.*; 23 24 import org.openharmonise.commons.dsi.*; 25 import org.openharmonise.commons.dsi.dml.*; 26 import org.openharmonise.commons.dsi.dml.functions.*; 27 import org.openharmonise.rm.DataAccessException; 28 import org.openharmonise.rm.resources.*; 29 import org.openharmonise.rm.resources.metadata.properties.Property; 30 import org.openharmonise.rm.resources.metadata.properties.domains.Domain; 31 import org.openharmonise.rm.resources.workflow.properties.WorkflowProperty; 32 33 34 41 public class WorkflowPropertyDomain extends Domain { 42 43 public static boolean validate(WorkflowProperty prop, Domain domain) throws DataAccessException { 44 boolean bIsValid = true; 45 46 List domainDetails = domain.getDetails(); 47 48 if(domainDetails.size() > 0) { 49 50 ResultSet rs = null; 51 try { 52 SelectStatement select = new SelectStatement(); 53 54 select.addSelectColumn(Domain.getColumnRef(CLMN_DOMAIN_ID, false)); 55 select.addWhereCondition(prop.getInstanceColumnRef(Property.ATTRIB_TYPE,false), "=", WorkflowProperty.class.getName()); 56 select.addJoinCondition(prop.getInstanceColumnRef(AbstractObject.ATTRIB_KEY, false), Domain.getColumnRef(CLMN_PROPERTY_KEY, false)); 57 58 ColumnRef domainDetailsCol = Domain.getDetailsColumnRef(CLMN_DOMAIN_DETAILS,false); 59 if(domainDetails.size() > 1) { 60 WhereConditionGroup wheres = new WhereConditionGroup(); 61 for (Iterator iter = domainDetails.iterator(); iter 62 .hasNext();) { 63 String detail = (String ) iter.next(); 64 wheres.addCondition(domainDetailsCol, "STARTS_WITH", detail); 65 Substring substr = new Substring(detail,new Integer (1),new Length(domainDetailsCol)); 66 wheres.addCondition(domainDetailsCol, "=", substr); 67 } 68 wheres.setStringingOperator("or"); 69 select.addWhereCondition(wheres); 70 } else { 71 WhereConditionGroup wheres = new WhereConditionGroup(); 72 73 Substring substr = new Substring((String )domainDetails.get(0),new Integer (1),new Length(domainDetailsCol)); 74 75 wheres.addCondition(domainDetailsCol, "=", substr); 76 wheres.addCondition(domainDetailsCol, "STARTS_WITH", domainDetails.get(0)); 77 78 wheres.setStringingOperator("or"); 79 select.addWhereCondition(wheres); 80 } 81 82 select.addJoinCondition(Domain.getColumnRef(CLMN_DOMAIN_ID, false), Domain.getDetailsColumnRef(CLMN_DETAILS_DOMAIN_ID, false)); 83 select.addWhereCondition(Domain.getColumnRef(CLMN_DOMAIN_OBJECT, false), "=", domain.getDomainClass()); 84 85 if(prop.getKey() != Property.NOTDBSAVED_KEY) { 86 Property liveVer = (Property) prop.getLiveVersion(); 87 if(liveVer != null) { 88 select.addWhereCondition(prop.getInstanceColumnRef(AbstractObject.ATTRIB_ID, false), "!=", liveVer.getId()); 89 select.addWhereCondition(prop.getInstanceColumnRef(AbstractEditableObject.TAG_LIVE_VERSION, false), "!=", liveVer.getId()); 90 91 } else { 92 select.addWhereCondition(prop.getInstanceColumnRef(AbstractObject.ATTRIB_ID, false), "!=", prop.getId()); 93 94 } 95 } 96 rs = prop.getDataStoreInterface().execute(select); 97 98 if(rs.next()) { 99 bIsValid = false; 100 } 101 } catch (DataStoreException e) { 102 throw new DataAccessException(e); 103 } catch (SQLException e) { 104 throw new DataAccessException(e); 105 } finally { 106 if(rs != null) { 107 try { 108 rs.close(); 109 } catch (SQLException e) { 110 throw new DataAccessException(e); 111 } 112 } 113 } 114 } 115 116 return bIsValid; 117 } 118 119 } 120 | Popular Tags |