diff --git a/atom/src/main/java/org/artificer/atom/mappers/OntologyToRdfMapper.java b/atom/src/main/java/org/artificer/atom/mappers/OntologyToRdfMapper.java index ed24cda7d..1353042a8 100644 --- a/atom/src/main/java/org/artificer/atom/mappers/OntologyToRdfMapper.java +++ b/atom/src/main/java/org/artificer/atom/mappers/OntologyToRdfMapper.java @@ -57,7 +57,7 @@ public void map(ArtificerOntology ontology, RDF rdf) { rdfClass.setComment(oclass.getComment()); if (oclass.getParent() != null) { SubClassOf subclass = new SubClassOf(); - subclass.setResource(oclass.getParent().getUri().toString()); + subclass.setResource(oclass.getParent().getUri()); rdfClass.setSubClassOf(subclass); } rdf.getClazz().add(rdfClass); diff --git a/atom/src/main/java/org/artificer/atom/mappers/RdfToOntologyMapper.java b/atom/src/main/java/org/artificer/atom/mappers/RdfToOntologyMapper.java index 68cbf5a63..7c6d11140 100644 --- a/atom/src/main/java/org/artificer/atom/mappers/RdfToOntologyMapper.java +++ b/atom/src/main/java/org/artificer/atom/mappers/RdfToOntologyMapper.java @@ -23,7 +23,6 @@ import org.w3._2002._07.owl_.Ontology; import javax.xml.namespace.QName; -import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -85,7 +84,7 @@ public void map(RDF rdf, ArtificerOntology ontology) throws Exception { oclass.setLabel(rdfClass.getLabel()); oclass.setComment(rdfClass.getComment()); String uri = base + "#" + rdfClass.getID(); //$NON-NLS-1$ - oclass.setUri(new URI(uri)); + oclass.setUri(uri); Object[] classData = new Object[] { oclass, rdfClass.getSubClassOf() != null ? rdfClass.getSubClassOf().getResource() : null }; diff --git a/common/src/main/java/org/artificer/common/ontology/ArtificerOntology.java b/common/src/main/java/org/artificer/common/ontology/ArtificerOntology.java index 3d07859fe..295bc19c7 100644 --- a/common/src/main/java/org/artificer/common/ontology/ArtificerOntology.java +++ b/common/src/main/java/org/artificer/common/ontology/ArtificerOntology.java @@ -22,10 +22,11 @@ import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.OneToMany; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.persistence.Transient; import java.io.Serializable; import java.net.URI; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -139,6 +140,13 @@ public List getRootClasses() { return rootClasses; } + /** + * @param rootClasses the rootClasses to set + */ + public void setRootClasses(List rootClasses) { + this.rootClasses = rootClasses; + } + @Transient public List getAllClasses() { List allClasses = new ArrayList(); @@ -158,13 +166,6 @@ private void addAllClasses(List allClasses, List rootClasses) { - this.rootClasses = rootClasses; - } - /** * Creates a new class within this ontology. * @param id @@ -173,11 +174,7 @@ public ArtificerOntologyClass createClass(String id) { ArtificerOntologyClass c = new ArtificerOntologyClass(); c.setId(id); String uri = this.getBase() + "#" + id; //$NON-NLS-1$ - try { - c.setUri(new URI(uri)); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } + c.setUri(uri); return c; } @@ -242,6 +239,7 @@ public void setCreatedBy(String createdBy) { /** * @return the createdOn */ + @Temporal(TemporalType.DATE) public Date getCreatedOn() { return createdOn; } @@ -270,6 +268,7 @@ public void setLastModifiedBy(String lastModifiedBy) { /** * @return the lastModifiedOn */ + @Temporal(TemporalType.DATE) public Date getLastModifiedOn() { return lastModifiedOn; } diff --git a/common/src/main/java/org/artificer/common/ontology/ArtificerOntologyClass.java b/common/src/main/java/org/artificer/common/ontology/ArtificerOntologyClass.java index 5ecdee0c9..fa7e84b0a 100644 --- a/common/src/main/java/org/artificer/common/ontology/ArtificerOntologyClass.java +++ b/common/src/main/java/org/artificer/common/ontology/ArtificerOntologyClass.java @@ -12,6 +12,7 @@ import javax.persistence.OneToMany; import java.io.Serializable; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -28,7 +29,7 @@ public class ArtificerOntologyClass implements Serializable { private String id; private String label; private String comment; - private URI uri; + private String uri; private ArtificerOntology root; private ArtificerOntologyClass parent; private List children = new ArrayList(); @@ -44,6 +45,7 @@ public void setSurrogateId(long surrogateId) { this.surrogateId = surrogateId; } + // Note: Cannot be @Id! Not guaranteed to be set by clients. public String getId() { return id; } @@ -78,7 +80,7 @@ public ArtificerOntologyClass findClass(String id) { * @param uri */ public ArtificerOntologyClass findClass(URI uri) { - if (this.uri.equals(uri)) { + if (this.uri.equals(uri.toString())) { return this; } else { for (ArtificerOntologyClass c : this.children) { @@ -158,14 +160,14 @@ public void setChildren(List children) { /** * @return the uri */ - public URI getUri() { + public String getUri() { return uri; } /** * @param uri the uri to set */ - public void setUri(URI uri) { + public void setUri(String uri) { this.uri = uri; } @@ -173,11 +175,11 @@ public void setUri(URI uri) { * Normalize the hierarchy into a list of ArtificerOntologyClasses. The returned list of * ArtificerOntologyClasses will contain this class and all ancestors. */ - public Set normalize() { - Set uris = new HashSet(); + public Set normalize() throws URISyntaxException { + Set uris = new HashSet<>(); ArtificerOntologyClass current = this; while (current != null) { - uris.add(current.getUri()); + uris.add(new URI(current.getUri())); current = current.getParent(); } return uris; diff --git a/distro/assembly/src/main/resources/ROOT/ddl/db2.sql b/distro/assembly/src/main/resources/ROOT/ddl/db2.sql index 196d51409..6e9c71622 100644 --- a/distro/assembly/src/main/resources/ROOT/ddl/db2.sql +++ b/distro/assembly/src/main/resources/ROOT/ddl/db2.sql @@ -76,11 +76,11 @@ base varchar(255), comment clob, createdBy varchar(255), - createdOn timestamp, + createdOn date, id varchar(255), label varchar(255), lastModifiedBy varchar(255), - lastModifiedOn timestamp, + lastModifiedOn date, uuid char(36), primary key (surrogateId) ); @@ -90,7 +90,7 @@ comment clob, id varchar(255), label varchar(255), - uri varchar(255) for bit data, + uri varchar(255), parent_surrogateId bigint, root_surrogateId bigint, primary key (surrogateId) diff --git a/distro/assembly/src/main/resources/ROOT/ddl/h2.sql b/distro/assembly/src/main/resources/ROOT/ddl/h2.sql index 7b65abaac..bb080b962 100644 --- a/distro/assembly/src/main/resources/ROOT/ddl/h2.sql +++ b/distro/assembly/src/main/resources/ROOT/ddl/h2.sql @@ -76,11 +76,11 @@ base varchar(255), comment clob, createdBy varchar(255), - createdOn timestamp, + createdOn date, id varchar(255), label varchar(255), lastModifiedBy varchar(255), - lastModifiedOn timestamp, + lastModifiedOn date, uuid char(36), primary key (surrogateId) ); @@ -90,7 +90,7 @@ comment clob, id varchar(255), label varchar(255), - uri binary(255), + uri varchar(255), parent_surrogateId bigint, root_surrogateId bigint, primary key (surrogateId) diff --git a/distro/assembly/src/main/resources/ROOT/ddl/mssql2012.sql b/distro/assembly/src/main/resources/ROOT/ddl/mssql2012.sql index 8c0acb371..ba7d9705b 100644 --- a/distro/assembly/src/main/resources/ROOT/ddl/mssql2012.sql +++ b/distro/assembly/src/main/resources/ROOT/ddl/mssql2012.sql @@ -76,11 +76,11 @@ base varchar(255), comment varchar(MAX), createdBy varchar(255), - createdOn datetime2, + createdOn date, id varchar(255), label varchar(255), lastModifiedBy varchar(255), - lastModifiedOn datetime2, + lastModifiedOn date, uuid char(36), primary key (surrogateId) ); @@ -90,7 +90,7 @@ comment varchar(MAX), id varchar(255), label varchar(255), - uri varbinary(255), + uri varchar(255), parent_surrogateId bigint, root_surrogateId bigint, primary key (surrogateId) diff --git a/distro/assembly/src/main/resources/ROOT/ddl/mysql5.sql b/distro/assembly/src/main/resources/ROOT/ddl/mysql5.sql index cd5aabc9f..1585121ae 100644 --- a/distro/assembly/src/main/resources/ROOT/ddl/mysql5.sql +++ b/distro/assembly/src/main/resources/ROOT/ddl/mysql5.sql @@ -76,11 +76,11 @@ base varchar(255), comment longtext, createdBy varchar(255), - createdOn datetime, + createdOn date, id varchar(255), label varchar(255), lastModifiedBy varchar(255), - lastModifiedOn datetime, + lastModifiedOn date, uuid char(36), primary key (surrogateId) ); @@ -90,7 +90,7 @@ comment longtext, id varchar(255), label varchar(255), - uri tinyblob, + uri varchar(255), parent_surrogateId bigint, root_surrogateId bigint, primary key (surrogateId) diff --git a/distro/assembly/src/main/resources/ROOT/ddl/oracle10.sql b/distro/assembly/src/main/resources/ROOT/ddl/oracle10.sql index c69ce4aba..1a7ae0e79 100644 --- a/distro/assembly/src/main/resources/ROOT/ddl/oracle10.sql +++ b/distro/assembly/src/main/resources/ROOT/ddl/oracle10.sql @@ -76,11 +76,11 @@ base varchar2(255 char), comment clob, createdBy varchar2(255 char), - createdOn timestamp, + createdOn date, id varchar2(255 char), label varchar2(255 char), lastModifiedBy varchar2(255 char), - lastModifiedOn timestamp, + lastModifiedOn date, uuid char(36), primary key (surrogateId) ); @@ -90,7 +90,7 @@ comment clob, id varchar2(255 char), label varchar2(255 char), - uri raw(255), + uri varchar2(255 char), parent_surrogateId number(19,0), root_surrogateId number(19,0), primary key (surrogateId) diff --git a/distro/assembly/src/main/resources/ROOT/ddl/postgres9.sql b/distro/assembly/src/main/resources/ROOT/ddl/postgres9.sql index fe38c0fb2..11eebd0f2 100644 --- a/distro/assembly/src/main/resources/ROOT/ddl/postgres9.sql +++ b/distro/assembly/src/main/resources/ROOT/ddl/postgres9.sql @@ -76,11 +76,11 @@ base varchar(255), comment text, createdBy varchar(255), - createdOn timestamp, + createdOn date, id varchar(255), label varchar(255), lastModifiedBy varchar(255), - lastModifiedOn timestamp, + lastModifiedOn date, uuid char(36), primary key (surrogateId) ); @@ -90,7 +90,7 @@ comment text, id varchar(255), label varchar(255), - uri bytea, + uri varchar(255), parent_surrogateId int8, root_surrogateId int8, primary key (surrogateId) diff --git a/repository/src/main/java/org/artificer/repository/AbstractPersistenceManager.java b/repository/src/main/java/org/artificer/repository/AbstractPersistenceManager.java index 0accb0db7..aca0d9f0e 100644 --- a/repository/src/main/java/org/artificer/repository/AbstractPersistenceManager.java +++ b/repository/src/main/java/org/artificer/repository/AbstractPersistenceManager.java @@ -34,33 +34,36 @@ public abstract class AbstractPersistenceManager implements PersistenceManager, @Override public URI resolve(String classifiedBy) throws ArtificerException { - URI classifiedUri = null; try { - classifiedUri = new URI(classifiedBy); - } catch (URISyntaxException e) { - throw ArtificerUserException.invalidClassifiedBy(classifiedBy); - } - Collection ontologies = getOntologies(); - for (ArtificerOntology ontology : ontologies) { - ArtificerOntologyClass sclass = ontology.findClass(classifiedBy); - if (sclass == null) { - sclass = ontology.findClass(classifiedUri); - } - if (sclass != null) { - return sclass.getUri(); + URI classifiedUri = new URI(classifiedBy); + Collection ontologies = getOntologies(); + for (ArtificerOntology ontology : ontologies) { + ArtificerOntologyClass sclass = ontology.findClass(classifiedBy); + if (sclass == null) { + sclass = ontology.findClass(classifiedUri); + } + if (sclass != null) { + return new URI(sclass.getUri()); + } } + } catch (URISyntaxException e) { + // fall through } throw ArtificerUserException.invalidClassifiedBy(classifiedBy); } @Override public Collection normalize(URI classification) throws ArtificerException { - List ontologies = getOntologies(); - for (ArtificerOntology ontology : ontologies) { - ArtificerOntologyClass sclass = ontology.findClass(classification); - if (sclass != null) { - return sclass.normalize(); + try { + List ontologies = getOntologies(); + for (ArtificerOntology ontology : ontologies) { + ArtificerOntologyClass sclass = ontology.findClass(classification); + if (sclass != null) { + return sclass.normalize(); + } } + } catch (URISyntaxException e) { + // fall through } throw ArtificerUserException.invalidClassifiedBy(classification.toString()); } diff --git a/repository/test/src/test/java/org/artificer/repository/test/ClassificationPersistenceTest.java b/repository/test/src/test/java/org/artificer/repository/test/ClassificationPersistenceTest.java index ca4ab1a16..78c3a68e2 100644 --- a/repository/test/src/test/java/org/artificer/repository/test/ClassificationPersistenceTest.java +++ b/repository/test/src/test/java/org/artificer/repository/test/ClassificationPersistenceTest.java @@ -45,7 +45,7 @@ public void testPersistClassifications() throws Exception { Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.DOCUMENT); - document.getClassifiedBy().add(ontology.findClass("China").getUri().toString()); + document.getClassifiedBy().add(ontology.findClass("China").getUri()); BaseArtifactType artifact = persistenceManager.persistArtifact(document, new ArtifactContent(artifactFileName, contentStream)); Assert.assertNotNull(artifact); diff --git a/repository/test/src/test/java/org/artificer/repository/test/OntologyPersistenceTest.java b/repository/test/src/test/java/org/artificer/repository/test/OntologyPersistenceTest.java index 2117282dd..4f720ef91 100644 --- a/repository/test/src/test/java/org/artificer/repository/test/OntologyPersistenceTest.java +++ b/repository/test/src/test/java/org/artificer/repository/test/OntologyPersistenceTest.java @@ -114,9 +114,9 @@ public void testPersistOntology_Full() throws Exception { Assert.assertEquals(0, actualJapan.getChildren().size()); Set expectedJapanNormalized = new HashSet<>(); - expectedJapanNormalized.add(actualWorld.getUri()); - expectedJapanNormalized.add(actualAsia.getUri()); - expectedJapanNormalized.add(actualJapan.getUri()); + expectedJapanNormalized.add(new URI(actualWorld.getUri())); + expectedJapanNormalized.add(new URI(actualAsia.getUri())); + expectedJapanNormalized.add(new URI(actualJapan.getUri())); Assert.assertEquals(expectedJapanNormalized, actualJapan.normalize()); }