Skip to content

Commit

Permalink
ARTIF-683 corrected field types in Ontology, allowing Hibernate to fu…
Browse files Browse the repository at this point in the history
…lly serialize/deserialize
  • Loading branch information
brmeyer committed Jun 8, 2015
1 parent d254c06 commit ed02665
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,6 +140,13 @@ public List<ArtificerOntologyClass> getRootClasses() {
return rootClasses;
}

/**
* @param rootClasses the rootClasses to set
*/
public void setRootClasses(List<ArtificerOntologyClass> rootClasses) {
this.rootClasses = rootClasses;
}

@Transient
public List<ArtificerOntologyClass> getAllClasses() {
List<ArtificerOntologyClass> allClasses = new ArrayList<ArtificerOntologyClass>();
Expand All @@ -158,13 +166,6 @@ private void addAllClasses(List<ArtificerOntologyClass> allClasses, List<Artific
}
}

/**
* @param rootClasses the rootClasses to set
*/
public void setRootClasses(List<ArtificerOntologyClass> rootClasses) {
this.rootClasses = rootClasses;
}

/**
* Creates a new class within this ontology.
* @param id
Expand All @@ -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;
}

Expand Down Expand Up @@ -242,6 +239,7 @@ public void setCreatedBy(String createdBy) {
/**
* @return the createdOn
*/
@Temporal(TemporalType.DATE)
public Date getCreatedOn() {
return createdOn;
}
Expand Down Expand Up @@ -270,6 +268,7 @@ public void setLastModifiedBy(String lastModifiedBy) {
/**
* @return the lastModifiedOn
*/
@Temporal(TemporalType.DATE)
public Date getLastModifiedOn() {
return lastModifiedOn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ArtificerOntologyClass> children = new ArrayList<ArtificerOntologyClass>();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -158,26 +160,26 @@ public void setChildren(List<ArtificerOntologyClass> 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;
}

/**
* Normalize the hierarchy into a list of ArtificerOntologyClasses. The returned list of
* ArtificerOntologyClasses will contain this class and all ancestors.
*/
public Set<URI> normalize() {
Set<URI> uris = new HashSet<URI>();
public Set<URI> normalize() throws URISyntaxException {
Set<URI> uris = new HashSet<>();
ArtificerOntologyClass current = this;
while (current != null) {
uris.add(current.getUri());
uris.add(new URI(current.getUri()));
current = current.getParent();
}
return uris;
Expand Down
6 changes: 3 additions & 3 deletions distro/assembly/src/main/resources/ROOT/ddl/db2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions distro/assembly/src/main/resources/ROOT/ddl/h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions distro/assembly/src/main/resources/ROOT/ddl/mssql2012.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions distro/assembly/src/main/resources/ROOT/ddl/mysql5.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions distro/assembly/src/main/resources/ROOT/ddl/oracle10.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions distro/assembly/src/main/resources/ROOT/ddl/postgres9.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArtificerOntology> 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<ArtificerOntology> 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<URI> normalize(URI classification) throws ArtificerException {
List<ArtificerOntology> ontologies = getOntologies();
for (ArtificerOntology ontology : ontologies) {
ArtificerOntologyClass sclass = ontology.findClass(classification);
if (sclass != null) {
return sclass.normalize();
try {
List<ArtificerOntology> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ public void testPersistOntology_Full() throws Exception {
Assert.assertEquals(0, actualJapan.getChildren().size());

Set<URI> 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());
}

Expand Down

0 comments on commit ed02665

Please sign in to comment.