From: <mg...@us...> - 2008-01-31 23:04:58
|
Revision: 1442 http://obo.svn.sourceforge.net/obo/?rev=1442&view=rev Author: mgibson Date: 2008-01-31 15:04:55 -0800 (Thu, 31 Jan 2008) Log Message: ----------- fixed endless loop bug Modified Paths: -------------- phenote/trunk/conf/phenote-config.rnc phenote/trunk/conf/phenote-config.xsd phenote/trunk/conf/worm.cfg phenote/trunk/jars/phenoteconfigbeans.jar phenote/trunk/src/java/phenote/config/FieldConfig.java phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java phenote/trunk/src/java/phenote/dataadapter/worm/WormConstraint.java Added Paths: ----------- phenote/trunk/src/java/phenote/dataadapter/AbstractCommitConstraint.java phenote/trunk/src/java/phenote/dataadapter/RequiredFieldConstraint.java Modified: phenote/trunk/conf/phenote-config.rnc =================================================================== --- phenote/trunk/conf/phenote-config.rnc 2008-01-31 22:46:02 UTC (rev 1441) +++ phenote/trunk/conf/phenote-config.rnc 2008-01-31 23:04:55 UTC (rev 1442) @@ -25,7 +25,8 @@ character-mode, ontologyLoading, field-panel-tabs, - comparison + comparison, + constraint-list } ## specify how the master config interacts with local/cached config @@ -183,6 +184,8 @@ ## free_text is just for backward compatibility - phase out attribute type { "FREE_TEXT" | "TERM" | "INT" | "ID" | "READ_ONLY" | "DATE" | "PICK" | "free_text" }, + ## if field is required, then commit will fail if null at commit time (null constraint) + attribute isRequired { xsd:boolean }, ## should this be another type? will there be anything readonly aside from strings? ##attribute read-only { xsd:boolean }, ## file is for single ontology - rename ontology_file? @@ -280,3 +283,10 @@ ontology* } +## a list of constraints to impose at edit or commit time +constraint-list = element constraint-list { constraint } + +## a constraint is checked at edit or compile time and throws warnings & failures +## constraints are encoded in java classes but are then enlisted here - so the class +## attribute is the actual class name, like "phenote.dataadapter.worm.WormConstraint" +constraint = element constraint { attribute class { xsd:string } } \ No newline at end of file Modified: phenote/trunk/conf/phenote-config.xsd =================================================================== --- phenote/trunk/conf/phenote-config.xsd 2008-01-31 22:46:02 UTC (rev 1441) +++ phenote/trunk/conf/phenote-config.xsd 2008-01-31 23:04:55 UTC (rev 1442) @@ -21,6 +21,7 @@ <xs:element ref="x:ontologyLoading"/> <xs:element ref="x:field-panel-tabs"/> <xs:element ref="x:comparison"/> + <xs:element ref="x:constraint-list"/> </xs:sequence> <xs:attribute name="version" use="required" type="xs:string"/> <xs:attribute name="description" use="required" type="xs:string"/> @@ -268,6 +269,11 @@ </xs:restriction> </xs:simpleType> </xs:attribute> + <xs:attribute name="isRequired" use="required" type="xs:boolean"> + <xs:annotation> + <xs:documentation>if field is required, then commit will fail if null at commit time (null constraint)</xs:documentation> + </xs:annotation> + </xs:attribute> <xs:attribute name="tab" use="required" type="xs:string"/> <xs:attribute name="file" use="required" type="xs:string"/> <xs:attribute name="filter-out" use="required" type="xs:string"/> @@ -381,4 +387,15 @@ <xs:attribute name="relationship-ontology" use="required" type="xs:string"/> </xs:complexType> </xs:element> + <xs:element name="constraint-list" type="x:constraint"/> + <xs:complexType name="constraint"> + <xs:sequence> + <xs:element ref="x:constraint"/> + </xs:sequence> + </xs:complexType> + <xs:element name="constraint"> + <xs:complexType> + <xs:attribute name="class" use="required" type="xs:string"/> + </xs:complexType> + </xs:element> </xs:schema> Modified: phenote/trunk/conf/worm.cfg =================================================================== --- phenote/trunk/conf/worm.cfg 2008-01-31 22:46:02 UTC (rev 1441) +++ phenote/trunk/conf/worm.cfg 2008-01-31 23:04:55 UTC (rev 1442) @@ -23,7 +23,7 @@ <group name="default" title="Main" container="tab" interface="default"/> - <field name="Object Type" datatag="Type" enable="true" groups="default"/> + <field name="Object Type" datatag="Type" isRequired="true" enable="true" groups="default"/> <field name="Object Name" datatag="Name" enable="true" groups="default"/> <field name="PgdbId" enable="true" copy-field="false" type="READ_ONLY" groups="default"/> <field name="Pub" datatag="Pub" enable="true" groups="default"> Modified: phenote/trunk/jars/phenoteconfigbeans.jar =================================================================== (Binary files differ) Modified: phenote/trunk/src/java/phenote/config/FieldConfig.java =================================================================== --- phenote/trunk/src/java/phenote/config/FieldConfig.java 2008-01-31 22:46:02 UTC (rev 1441) +++ phenote/trunk/src/java/phenote/config/FieldConfig.java 2008-01-31 23:04:55 UTC (rev 1442) @@ -5,6 +5,8 @@ import phenote.config.xml.FieldDocument.Field; import phenote.config.xml.OntologyDocument.Ontology; +import phenote.dataadapter.ConstraintManager; +import phenote.dataadapter.RequiredFieldConstraint; import phenote.datamodel.CharField; import phenote.datamodel.CharFieldEnum; @@ -71,6 +73,9 @@ addOntologyConfig(new OntologyConfig(ontBean,this)); // label -> default name } } + + // REQUIRED CONSTRAINT - if required then make RequiredConstraint + makeRequiredConstraint(); } // for ConfigGui @@ -106,6 +111,20 @@ private void initFieldBean() { getFieldBean(); } + /** if required then make RequiredConstraint */ + private void makeRequiredConstraint() { + if (!isRequired()) return; // its not required do nothing + RequiredFieldConstraint con = new RequiredFieldConstraint(getCharField()); + ConstraintManager.inst().addConstraint(con); + } + + /** whether field is required for commit, default false, from config bean */ + private boolean isRequired() { + if (getFieldBean().xgetIsRequired() == null) return false; //default + return getFieldBean().getIsRequired(); + } + + // --> getName? public String getLabel() { return fieldBean.getName(); } boolean hasLabel(String label) { return label.equals(getLabel()); } @@ -352,20 +371,3 @@ } - // this should come for free with new bean datamodel - /** create xml bean and add it to phenCfg for writeback */ -// void write(PhenoteConfiguration phenCfg) { -// Field f = phenCfg.addNewField(); -// f.setName(getLabel()); -// f.setSyntaxAbbrev(getSyntaxAbbrev()); -// f.setEnable(isEnabled()); -// // f.setType(getType()); // do we need this - no - maybe in future? -// // new way is to just write out with other ontol configs - delete this -// // if (isPostComp()) getPostCompRelOntCfg().writePostComp(f); -// // everything else is in ontology config -// // change here - writing out ontology element even for single ontology - phasing -// // out shoving ontology in field attribs -// // this also will have post comp rel - new way -// for (OntologyConfig oc : getOntologyConfigList()) -// oc.writeOntology(f); -// } Added: phenote/trunk/src/java/phenote/dataadapter/AbstractCommitConstraint.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/AbstractCommitConstraint.java (rev 0) +++ phenote/trunk/src/java/phenote/dataadapter/AbstractCommitConstraint.java 2008-01-31 23:04:55 UTC (rev 1442) @@ -0,0 +1,37 @@ +package phenote.dataadapter; + +import java.util.List; + +import phenote.datamodel.CharacterI; + +abstract class AbstractCommitConstraint implements Constraint { + + /** Return true if constraint should be checked at commit time to + dataadapter */ + public boolean isCommitConstraint() { + return true; + } + /** do constraint check for commit time - should char list be passed in? + return ConstraintStatus indication if constraint passed and error msg + should only be called if isCommitConstraint is true */ + public ConstraintStatus checkCommit() { + + ConstraintStatus statusBundle = ConstraintStatus.makeOK(); + + List<CharacterI> list = CharacterListManager.inst().getCharacterList().getList(); + for (CharacterI chr : list) { + ConstraintStatus charStatus = checkCharCommit(chr); + statusBundle.addStatusChild(charStatus); + } + return statusBundle; + } + + /** Check char and return ConstraintStatus */ + abstract ConstraintStatus checkCharCommit(CharacterI chr); + + + /** false - its just a commit constraint */ + public boolean isEditConstraint() { return false; } + public ConstraintStatus checkEdit() { return null; } + +} Modified: phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java 2008-01-31 22:46:02 UTC (rev 1441) +++ phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java 2008-01-31 23:04:55 UTC (rev 1442) @@ -23,7 +23,7 @@ private ConstraintManager() {} public ConstraintStatus checkCommitConstraints() { - ConstraintStatus statusList = ConstraintStatus.OK_STATUS; //? + ConstraintStatus statusList = ConstraintStatus.makeList(); //? for (Constraint c : constraintList) { if (c.isCommitConstraint()) { ConstraintStatus cs = c.checkCommit(); @@ -34,7 +34,7 @@ } public ConstraintStatus checkEditConstraints() { - ConstraintStatus statusList = ConstraintStatus.OK_STATUS; //? + ConstraintStatus statusList = ConstraintStatus.makeList(); //? for (Constraint c : constraintList) { if (c.isEditConstraint()) { ConstraintStatus cs = c.checkEdit(); Modified: phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java 2008-01-31 22:46:02 UTC (rev 1441) +++ phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java 2008-01-31 23:04:55 UTC (rev 1442) @@ -19,8 +19,15 @@ public static enum Status { OK, WARNING, FAILURE }; - public static ConstraintStatus OK_STATUS = new ConstraintStatus(Status.OK); + // causes endless loops - woops + //public static ConstraintStatus OK_STATUS = new ConstraintStatus(Status.OK); + public static ConstraintStatus makeOK() { + return new ConstraintStatus(Status.OK); + } + /** list & OK same thing really - for clarity */ + public static ConstraintStatus makeList() { return makeOK(); } + public ConstraintStatus(Status status,String message) { this(status); if (message!=null) this.message = message; @@ -49,8 +56,8 @@ if (!hasKids()) return this.status == status; else { - for (ConstraintStatus cs : kids) { - if (recursiveCheckForStatus(status)) return true; + for (ConstraintStatus kid : kids) { + if (kid.recursiveCheckForStatus(status)) return true; } return this.status == status; // ? self } Added: phenote/trunk/src/java/phenote/dataadapter/RequiredFieldConstraint.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/RequiredFieldConstraint.java (rev 0) +++ phenote/trunk/src/java/phenote/dataadapter/RequiredFieldConstraint.java 2008-01-31 23:04:55 UTC (rev 1442) @@ -0,0 +1,25 @@ +package phenote.dataadapter; + +import phenote.datamodel.CharField; +import phenote.datamodel.CharacterI; + +/** Commit Constraint that checks that field has a value, if not returns FAILURE status */ + +public class RequiredFieldConstraint extends AbstractCommitConstraint { + + private CharField charField; + + public RequiredFieldConstraint(CharField cf) { + charField = cf; + } + + ConstraintStatus checkCharCommit(CharacterI chr) { + if (!chr.hasValue(charField)) { + String m=chr+" field "+charField+" is required to have a value"; + return new ConstraintStatus(ConstraintStatus.Status.FAILURE,m); + } + else + return ConstraintStatus.makeOK(); + } + +} Modified: phenote/trunk/src/java/phenote/dataadapter/worm/WormConstraint.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/worm/WormConstraint.java 2008-01-31 22:46:02 UTC (rev 1441) +++ phenote/trunk/src/java/phenote/dataadapter/worm/WormConstraint.java 2008-01-31 23:04:55 UTC (rev 1442) @@ -52,7 +52,7 @@ return new ConstraintStatus(Status.WARNING,message); else - return ConstraintStatus.OK_STATUS; + return ConstraintStatus.makeOK(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |