Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt at sbol3-11704 and sbol3-11705 #25

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package org.sbolstandard.core3.entity;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.sbolstandard.core3.util.Configuration;
import org.sbolstandard.core3.util.RDFUtil;
import org.sbolstandard.core3.util.SBOLGraphException;
import org.sbolstandard.core3.util.SBOLUtil;
import org.sbolstandard.core3.validation.IdentifiedValidator;
import org.sbolstandard.core3.validation.PropertyValidator;
import org.sbolstandard.core3.validation.ValidationMessage;
import org.sbolstandard.core3.vocabulary.DataModel;
import org.sbolstandard.core3.vocabulary.RestrictionType;

import jakarta.validation.constraints.NotNull;

Expand All @@ -33,10 +36,56 @@ protected Constraint(Resource resource) throws SBOLGraphException
@Override
public List<ValidationMessage> getValidationMessages() throws SBOLGraphException
{
ArrayList<URI> table8List = new ArrayList<URI>();
table8List.add(RestrictionType.Identity.verifyIdentical);
table8List.add(RestrictionType.Identity.differentFrom);
table8List.add(RestrictionType.Identity.replaces);
table8List.add(RestrictionType.Orientation.sameOrientationAs);
table8List.add(RestrictionType.Orientation.oppositeOrientationAs);

ArrayList<URI> table9List = new ArrayList<URI>();
table9List.add(RestrictionType.Topology.isDisjointFrom);
table9List.add(RestrictionType.Topology.strictlyContains);
table9List.add(RestrictionType.Topology.contains);
table9List.add(RestrictionType.Topology.equals);
table9List.add(RestrictionType.Topology.meets);
table9List.add(RestrictionType.Topology.covers);
table9List.add(RestrictionType.Topology.overlaps);

ArrayList<URI> table10List = new ArrayList<URI>();
table10List.add(RestrictionType.Sequential.precedes);
table10List.add(RestrictionType.Sequential.strictlyPrecedes);
table10List.add(RestrictionType.Sequential.meets);
table10List.add(RestrictionType.Sequential.overlaps);
table10List.add(RestrictionType.Sequential.contains);
table10List.add(RestrictionType.Sequential.strictlyContains);
table10List.add(RestrictionType.Sequential.equals);
table10List.add(RestrictionType.Sequential.finishes);
table10List.add(RestrictionType.Sequential.starts);

List<ValidationMessage> validationMessages=super.getValidationMessages();
validationMessages=IdentifiedValidator.assertNotEqual(this, validationMessages, this.getObject(), this.getSubject(), "{CONSTRAINT_OBJECT_AND_SUBJECT_ARE_NOT_EQUAL}", DataModel.Constraint.object);
validationMessages= IdentifiedValidator.assertEquals(this, DataModel.Constraint.subject, this.resource, this.getSubject(), validationMessages);
validationMessages= IdentifiedValidator.assertEquals(this, DataModel.Constraint.object, this.resource, this.getObject(), validationMessages);

URI restriction = this.getRestriction();
// CONSTRAINT_RESTRICTION_VALUE_FROM_TABLE_8_9_10_37
if (Configuration.getInstance().isValidateRecommendedRules()){
if(!table8List.contains(restriction) && !table9List.contains(restriction) && !table10List.contains(restriction)) {
validationMessages = addToValidations(validationMessages,new ValidationMessage("{CONSTRAINT_RESTRICTION_VALUE_FROM_TABLE_8_9_10_37}", DataModel.type));
}
}

// CONSTRAINT_RESTRICTION_TABLE8_MUST_MATCH_FEATURE
if(table8List.contains(restriction)) {
//If the restriction property of a Constraint is drawn from Table 8,
Feature subject = this.getSubject();
Feature object = this.getObject();
if(!restriction.equals(subject.getUri()) || !restriction.equals(object.getUri())) {
validationMessages = addToValidations(validationMessages,new ValidationMessage("{CONSTRAINT_RESTRICTION_TABLE8_MUST_MATCH_FEATURE}", DataModel.type));
}
}

return validationMessages;
}

Expand Down
2 changes: 2 additions & 0 deletions libSBOLj3/src/main/resources/ValidationMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ CONSTRAINT_OBJECT_NOT_NULL = Constraint.object cannot be null.
CONSTRAINT_SUBJECT_MUST_REFER_TO_A_FEATURE_OF_THE_PARENT = sbol3-11701 - The Feature referenced by the subject property of a Constraint MUST be contained by the Component that contains the Constraint.
CONSTRAINT_OBJECT_MUST_REFER_TO_A_FEATURE_OF_THE_PARENT = sbol3-11702 - The Feature referenced by the object property of a Constraint MUST be contained by the Component that contains the Constraint.
CONSTRAINT_OBJECT_AND_SUBJECT_ARE_NOT_EQUAL= sbol3-11703 - The object property of a Constraint MUST NOT refer to the same SubComponent as the subject property of the Constraint.
CONSTRAINT_RESTRICTION_VALUE_FROM_TABLE_8_9_10_37 = sbol3-11704 - The value of the restriction property of a Constraint SHOULD be drawn from Table 8, 37 Table 9, or Table 10
CONSTRAINT_RESTRICTION_TABLE8_MUST_MATCH_FEATURE = sbol3-11705 - If the restriction property of a Constraint is drawn from Table 8, then the Feature objects referred to by the subject and object properties MUST comply with the relation specified in Table 8.
CUT_AT_NOT_NULL = Cut.at cannot be null.
CUT_AT_POSITIVE_OR_ZERO = sbol3-11501 - The value of the at property of a Cut MUST be greater than or equal to zero.
EXTERNALLYDEFINED_TYPE_IN_TABLE2 = sbol3-11104 - A ExternallyDefined SHOULD have a type property from Table 2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void testConstraintReference() throws SBOLGraphException, IOException, Ex
TestUtil.validateIdentified(constraint,doc,0);
TestUtil.validateProperty(constraint, "setRestriction", new Object[] {null}, URI.class);
constraint.setRestriction(null);
TestUtil.validateIdentified(constraint,doc,1);
TestUtil.validateIdentified(constraint,doc,2);

TestUtil.validateProperty(constraint, "setObject", new Object[] {null}, Feature.class);
constraint.setObject(null);
TestUtil.validateIdentified(constraint,doc,2);
TestUtil.validateIdentified(constraint,doc,3);

TestUtil.validateProperty(constraint, "setSubject", new Object[] {null}, Feature.class);
constraint.setSubject(null);
TestUtil.validateIdentified(constraint,doc,3);
TestUtil.validateIdentified(constraint,doc,4);

constraint.setRestriction(tempRestriction);
constraint.setSubject(tempSubject);
Expand Down Expand Up @@ -94,6 +94,24 @@ public void testConstraintReference() throws SBOLGraphException, IOException, Ex
constraint.setObject(tempObject);
TestUtil.validateIdentified(constraint,doc,0);

// CONSTRAINT_RESTRICTION_VALUE_FROM_TABLE_8_9_10_37
constraint.setRestriction(null);
TestUtil.validateIdentified(constraint,doc,2);
Configuration.getInstance().setValidateRecommendedRules(false);
TestUtil.validateIdentified(constraint,doc,1);
Configuration.getInstance().setValidateRecommendedRules(true);

constraint.setRestriction(tempRestriction);
TestUtil.validateIdentified(constraint,doc,0);

// CONSTRAINT_RESTRICTION_TABLE8_MUST_MATCH_FEATURE
constraint.setRestriction(RestrictionType.Identity.verifyIdentical);
TestUtil.validateIdentified(constraint,doc,1);

constraint.setRestriction(tempRestriction);
TestUtil.validateIdentified(constraint,doc,0);



}

Expand Down