Skip to content

Commit

Permalink
hot fixes to problems found while verifying closed Jiras
Browse files Browse the repository at this point in the history
  • Loading branch information
GEGlobalResearch committed Jun 2, 2017
1 parent 390b3e1 commit 22aa48d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public final class SadlErrorMessages {
**/
public static final SadlErrorMessage MUST_BE_APPLIED_TO_LIST = new SadlErrorMessage("must_be_applied_to_list");
/**
* This changes the domain of property ''{0}'' which has an imported domain; are you sure that's what you want to do?
**/
public static final SadlErrorMessage IMPORTED_DOMAIN_CHANGE = new SadlErrorMessage("imported_domain_change");
/**
* List definition is empty. Remove empty list brackets from definition.
**/
public static final SadlErrorMessage EMPTY_LIST_DEFINITION = new SadlErrorMessage("empty_list_definition");
Expand Down Expand Up @@ -211,6 +215,10 @@ public final class SadlErrorMessages {
**/
public static final SadlErrorMessage UNIQUE_NAME = new SadlErrorMessage("unique_name");
/**
* This changes the range of property ''{0}'' which has an imported range; are you sure that's what you want to do?
**/
public static final SadlErrorMessage IMPORTED_RANGE_CHANGE = new SadlErrorMessage("imported_range_change");
/**
* translate(Name) called with a SadlResource which resolved to null; this needs to be caught in validation
**/
public static final SadlErrorMessage TRANSLATE_NAME_SADLRESOURCE = new SadlErrorMessage("translate_name_sadlresource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ validate_bin_op_error.description=Left side of operand ('0') can not be compared
variable_instead_of_prop=It is unusual to have a variable (''{0}'') rather than a defined property as rule predicate.
class_property_value_owl_full=Only OWL Full allows classes to have property values.
datatype_as_domain=Using a datatype as a domain--probably not what was intended?
datatype_as_domain.description=Normally the domain of a property is a class, not a datatype as datatypes do not normally have identity.
datatype_as_domain.description=Normally the domain of a property is a class, not a datatype as datatypes do not normally have identity.
imported_range_change=This changes the range of property ''{0}'' which has an imported range; are you sure that's what you want to do?
imported_range_change.description=Best practice is to define the range more broadly and then restrict it for particular classes.
imported_domain_change=This changes the domain of property ''{0}'' which has an imported domain; are you sure that's what you want to do?
imported_domain_change.description=Best practice is to define the domain more in its original definition rather than change it in imported models.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

import com.ge.research.sadl.builder.ConfigurationManagerForIdeFactory;
import com.ge.research.sadl.builder.IConfigurationManagerForIDE;
import com.ge.research.sadl.builder.MessageManager.SadlMessage;
import com.ge.research.sadl.errorgenerator.generator.SadlErrorMessages;
import com.ge.research.sadl.errorgenerator.messages.SadlErrorMessage;
import com.ge.research.sadl.external.ExternalEmfResource;
Expand Down Expand Up @@ -199,6 +200,7 @@
//import com.ge.research.sadl.server.SessionNotFoundException;
//import com.ge.research.sadl.server.server.SadlServerImpl;
import com.ge.research.sadl.utils.ResourceManager;
import com.google.common.math.IntMath;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
import com.hp.hpl.jena.ontology.AnnotationProperty;
Expand Down Expand Up @@ -4177,11 +4179,12 @@ else if (rngNode instanceof OntClass){
}

RDFNode propOwlType = null;
boolean existingRangeThisModel = false;
boolean rangeExists = false;
boolean addNewRange = false;
StmtIterator existingRngItr = getTheJenaModel().listStatements(prop, RDFS.range, (RDFNode)null);
if (existingRngItr.hasNext()) {
RDFNode existingRngNode = existingRngItr.next().getObject();
rangeExists = true;
// property already has a range know to this model
if (rngNode.equals(existingRngNode) || (rngResource != null && rngResource.equals(existingRngNode))) {
// do nothing-- rngNode is already in range
Expand Down Expand Up @@ -4213,14 +4216,19 @@ else if (rngNode instanceof OntClass){
}
}

boolean rangeInThisModel = false;
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.range, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
rangeInThisModel = true;
}
if (domainAndRangeAsUnionClasses) {
// in this case we want to create a union class if necessary
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.range, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
// StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.range, (RDFNode)null);
// if (inModelStmtItr.hasNext()) {
if (rangeInThisModel) {
// this model (as opposed to imports) already has a range specified
addNewRange = false;
UnionClass newUnionClass = null;
existingRangeThisModel = true;
while (inModelStmtItr.hasNext()) {
RDFNode rngThisModel = inModelStmtItr.nextStatement().getObject();
if (rngThisModel.isResource()) {
Expand Down Expand Up @@ -4252,9 +4260,7 @@ else if (rngNode instanceof OntClass){
}
} // end if existing range in this model
else {
if (existingRngNode != null) {
addWarning("This changes the range of property '" + prop.getURI() + "' which has an imported range; are you sure that's what you want to do?", context);
}
inModelStmtItr.close();
// check to see if this is something new
do {
if (existingRngNode.equals(rngNode)) {
Expand All @@ -4270,6 +4276,12 @@ else if (rngNode instanceof OntClass){
} while (existingRngNode != null);
}
} // end if domainAndRangeAsUnionClasses
else {
inModelStmtItr.close();
}
if (rangeExists && !rangeInThisModel) {
addWarning(SadlErrorMessages.IMPORTED_RANGE_CHANGE.get(nodeToString(prop)), context);
}
} // end if existing range in any model, this or imports
if (rngNode != null) {
if (rngResource != null) {
Expand Down Expand Up @@ -4382,7 +4394,7 @@ private String stmtIteratorToObjectString(StmtIterator stmtitr) {
private String nodeToString(RDFNode obj) {
StringBuilder sb = new StringBuilder();
if (obj.isURIResource()) {
sb.append(obj.toString());
sb.append(uriStringToString(obj.toString()));
}
else if (obj.canAs(UnionClass.class)){
UnionClass ucls = obj.as(UnionClass.class);
Expand Down Expand Up @@ -4700,9 +4712,9 @@ else if (instUri != null) {
// do nothing
} catch(PropertyWithoutRangeException e){
String propUri = declarationExtensions.getConceptUri(prop);
// if (!propUri.equals(SadlConstants.SADL_IMPLICIT_MODEL_IMPLIED_PROPERTY_URI)) {
if (!propUri.equals(SadlConstants.SADL_IMPLICIT_MODEL_IMPLIED_PROPERTY_URI)) {
issueAcceptor.addWarning(SadlErrorMessages.PROPERTY_WITHOUT_RANGE.get(declarationExtensions.getConcreteName(prop)), propinit);
// }
}
} catch (Exception e) {
throw new JenaProcessorException("Unexpected error checking value in range", e);
}
Expand Down Expand Up @@ -5204,8 +5216,10 @@ private boolean checkForExistingCompatibleDatatypeProperty(
private void addPropertyDomain(Property prop, OntResource cls, EObject context) throws JenaProcessorException {
boolean addNewDomain = true;
StmtIterator sitr = getTheJenaModel().listStatements(prop, RDFS.domain, (RDFNode)null);
boolean domainExists = false;
if (sitr.hasNext()) {
RDFNode existingDomain = sitr.next().getObject();
domainExists = true;
// property already has a domain known to this model
if (cls.equals(existingDomain)) {
// do nothing--cls is already in domain
Expand All @@ -5226,11 +5240,15 @@ private void addPropertyDomain(Property prop, OntResource cls, EObject context)
return;
}
}


boolean domainInThisModel = false;
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.domain, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
domainInThisModel = true;
}
if (domainAndRangeAsUnionClasses) {
// in this case we want to create a union class if necessary
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.domain, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
if (domainInThisModel) {
// this model (as opposed to imports) already has a domain specified
addNewDomain = false;
UnionClass newUnionClass = null;
Expand Down Expand Up @@ -5261,9 +5279,7 @@ private void addPropertyDomain(Property prop, OntResource cls, EObject context)
}
} // end if existing domain in this model
else {
if (existingDomain != null) {
addWarning("This changes the domain of property '" + prop.getURI() + "' which has an imported domain; are you sure that's what you want to do?", context);
}
inModelStmtItr.close();
// check to see if this is something new
do {
if (existingDomain.equals(cls)) {
Expand All @@ -5279,6 +5295,12 @@ private void addPropertyDomain(Property prop, OntResource cls, EObject context)
} while (existingDomain != null);
}
} // end if domainAndRangeAsUnionClasses
else {
inModelStmtItr.close();
}
if (domainExists && !domainInThisModel) {
addWarning(SadlErrorMessages.IMPORTED_DOMAIN_CHANGE.get(nodeToString(prop)), context);
}
} // end if existing domain in any model, this or imports
if(cls != null){
if (!domainAndRangeAsUnionClasses && cls instanceof UnionClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ private boolean handleValidationException(EObject expr, Throwable t) {
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.TYPE_CHECK_EXCEPTION.get("Null Pointer"), expr);
} else if (t instanceof DontTypeCheckException) {
return true;
} else if (t instanceof PropertyWithoutRangeException) {
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.PROPERTY_WITHOUT_RANGE.get(((PropertyWithoutRangeException)t).getPropID()), expr);
return true;
} else if (t instanceof CircularDefinitionException) {
t.printStackTrace();
}
Expand Down Expand Up @@ -1969,25 +1972,25 @@ protected TypeCheckInfo getType(SadlResource qnm) throws DontTypeCheckException,
return tci;
}
else if(conceptType.equals(OntConceptType.DATATYPE_PROPERTY)){
TypeCheckInfo propcheckinfo = getNameProperty(ConceptType.DATATYPEPROPERTY, conceptUri, expression);
TypeCheckInfo propcheckinfo = getNameProperty(qnm, ConceptType.DATATYPEPROPERTY, conceptUri, expression);
if (propcheckinfo != null) {
return propcheckinfo;
}
throw new PropertyWithoutRangeException();
throw new PropertyWithoutRangeException(declarationExtensions.getConcreteName(qnm));
}
else if(conceptType.equals(OntConceptType.CLASS_PROPERTY)){
TypeCheckInfo propcheckinfo = getNameProperty(ConceptType.OBJECTPROPERTY, conceptUri, expression);
TypeCheckInfo propcheckinfo = getNameProperty(qnm, ConceptType.OBJECTPROPERTY, conceptUri, expression);
if (propcheckinfo != null) {
return propcheckinfo;
}
throw new PropertyWithoutRangeException();
throw new PropertyWithoutRangeException(declarationExtensions.getConcreteName(qnm));
}
else if (conceptType.equals(OntConceptType.RDF_PROPERTY)) {
TypeCheckInfo rdfpropcheckinfo = getNameProperty(ConceptType.RDFPROPERTY, conceptUri, expression);
TypeCheckInfo rdfpropcheckinfo = getNameProperty(qnm, ConceptType.RDFPROPERTY, conceptUri, expression);
if (rdfpropcheckinfo != null) {
return rdfpropcheckinfo;
}
throw new PropertyWithoutRangeException();
throw new PropertyWithoutRangeException(declarationExtensions.getConcreteName(qnm));
}
else if(conceptType.equals(OntConceptType.INSTANCE)){
// this is an instance--if it is already in the ontology we can get its type. If not maybe we can get it from its declaration
Expand Down Expand Up @@ -2083,10 +2086,10 @@ private ConceptName createTypedConceptName(String conceptUri, OntConceptType con
return modelProcessor.createTypedConceptName(conceptUri, conceptType);
}

protected TypeCheckInfo getNameProperty(ConceptType propertyType, String conceptUri, EObject expression) throws DontTypeCheckException, InvalidTypeException {
protected TypeCheckInfo getNameProperty(SadlResource qnm, ConceptType propertyType, String conceptUri, EObject expression) throws DontTypeCheckException, InvalidTypeException {
OntProperty property = theJenaModel.getOntProperty(conceptUri);
if(property == null){
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.UNIDENTIFIED.toString(), expression);
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.UNIDENTIFIED.toString(), qnm != null ? qnm : expression);
if (metricsProcessor != null) {
metricsProcessor.addMarker(null, MetricsProcessor.ERROR_MARKER_URI, MetricsProcessor.UNCLASSIFIED_FAILURE_URI);
}
Expand Down Expand Up @@ -2142,7 +2145,7 @@ else if (isSadlTypedList(first)) {
while (sitr2.hasNext()) {
RDFNode psuper = sitr2.next().getObject();
if (psuper.isResource()) {
TypeCheckInfo superTCInfo = getNameProperty(propertyType, psuper.asResource().getURI(), expression);
TypeCheckInfo superTCInfo = getNameProperty(null, propertyType, psuper.asResource().getURI(), expression);
if (superTCInfo != null) {
sitr2.close();
return superTCInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ public class PropertyWithoutRangeException extends Exception {
*
*/
private static final long serialVersionUID = 1L;

private String propID = null;

public PropertyWithoutRangeException(){
super("Property does not have a range");
}

public PropertyWithoutRangeException(String pid) {
super("Property does not have a range");
propID = pid;
}

public String getPropID() {
return propID;
}
}

0 comments on commit 22aa48d

Please sign in to comment.