Add generics to LinksDao and sub-classes; organize import statments.
This commit is contained in:
parent
51be987287
commit
1a9e53f7bf
2 changed files with 50 additions and 53 deletions
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Link;
|
import edu.cornell.mannlib.vitro.webapp.beans.Link;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface LinksDao {
|
public interface LinksDao {
|
||||||
|
|
||||||
|
@ -26,6 +27,6 @@ public interface LinksDao {
|
||||||
|
|
||||||
public abstract void addPrimaryLinkToIndividual(Individual entity);
|
public abstract void addPrimaryLinkToIndividual(Individual entity);
|
||||||
|
|
||||||
public abstract void addLinksToIndividualsInObjectPropertyStatement(List /* of ObjectPropertyStatement*/objPropertyStmts);
|
public abstract void addLinksToIndividualsInObjectPropertyStatement(List<ObjectPropertyStatement> objPropertyStmts);
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,7 +9,6 @@ import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,9 +17,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.ObjectProperty;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
@ -32,7 +29,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.Link;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.LinksDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.LinksDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
|
|
||||||
public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
|
|
||||||
|
@ -48,16 +44,16 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLinksToIndividual(Individual individual) {
|
public void addLinksToIndividual(Individual individual) {
|
||||||
List linksList = new ArrayList<Link>();
|
List<Link> linksList = new ArrayList<Link>();
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
com.hp.hpl.jena.ontology.Individual entInd = getOntModel().getIndividual(individual.getURI());
|
com.hp.hpl.jena.ontology.Individual entInd = getOntModel().getIndividual(individual.getURI());
|
||||||
if (ADDITIONAL_LINK != null) {
|
if (ADDITIONAL_LINK != null) {
|
||||||
ClosableIterator links = getOntModel().listStatements(entInd,ADDITIONAL_LINK,(Resource)null);
|
ClosableIterator<Statement> links = getOntModel().listStatements(entInd,ADDITIONAL_LINK,(Resource)null);
|
||||||
try {
|
try {
|
||||||
while (links.hasNext()) {
|
while (links.hasNext()) {
|
||||||
try {
|
try {
|
||||||
Resource linkRes = (Resource) ((Statement) links.next()).getObject();
|
Resource linkRes = (Resource) links.next().getObject();
|
||||||
linksList.add(linkFromLinkResource(linkRes, ADDITIONAL_LINK));
|
linksList.add(linkFromLinkResource(linkRes, ADDITIONAL_LINK));
|
||||||
} catch (ClassCastException cce) {/*no thanks; we don't want any*/}
|
} catch (ClassCastException cce) {/*no thanks; we don't want any*/}
|
||||||
}
|
}
|
||||||
|
@ -91,16 +87,16 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPrimaryLinkToIndividual(Individual individual) {
|
public void addPrimaryLinkToIndividual(Individual individual) {
|
||||||
List linksList = new ArrayList<Link>();
|
List<Link> linksList = new ArrayList<Link>();
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
com.hp.hpl.jena.ontology.Individual entInd = getOntModel().getIndividual(individual.getURI());
|
com.hp.hpl.jena.ontology.Individual entInd = getOntModel().getIndividual(individual.getURI());
|
||||||
if (PRIMARY_LINK != null) {
|
if (PRIMARY_LINK != null) {
|
||||||
ClosableIterator links = getOntModel().listStatements(entInd,PRIMARY_LINK,(Resource)null);
|
ClosableIterator<Statement> links = getOntModel().listStatements(entInd,PRIMARY_LINK,(Resource)null);
|
||||||
try {
|
try {
|
||||||
while (links.hasNext()) {
|
while (links.hasNext()) {
|
||||||
try {
|
try {
|
||||||
Resource linkRes = (Resource) ((Statement) links.next()).getObject();
|
Resource linkRes = (Resource) links.next().getObject();
|
||||||
linksList.add(linkFromLinkResource(linkRes,PRIMARY_LINK));
|
linksList.add(linkFromLinkResource(linkRes,PRIMARY_LINK));
|
||||||
} catch (ClassCastException cce) {/*no thanks; we don't want any*/}
|
} catch (ClassCastException cce) {/*no thanks; we don't want any*/}
|
||||||
}
|
}
|
||||||
|
@ -128,9 +124,9 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linksList.size()>0) {
|
if (linksList.size()>0) {
|
||||||
Iterator iter = linksList.iterator();
|
Iterator<Link> iter = linksList.iterator();
|
||||||
if (iter.hasNext()) { // take the first only
|
if (iter.hasNext()) { // take the first only
|
||||||
individual.setPrimaryLink((Link)iter.next());
|
individual.setPrimaryLink(iter.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,11 +136,11 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addLinksToIndividualsInObjectPropertyStatement(List objectPropertyStatements) {
|
public void addLinksToIndividualsInObjectPropertyStatement(List<ObjectPropertyStatement> objectPropertyStatements) {
|
||||||
if (objectPropertyStatements != null) {
|
if (objectPropertyStatements != null) {
|
||||||
Iterator objectPropertyStatementsIt = objectPropertyStatements.iterator();
|
Iterator<ObjectPropertyStatement> objectPropertyStatementsIt = objectPropertyStatements.iterator();
|
||||||
while (objectPropertyStatementsIt.hasNext()) {
|
while (objectPropertyStatementsIt.hasNext()) {
|
||||||
ObjectPropertyStatement ops = (ObjectPropertyStatement) objectPropertyStatementsIt.next();
|
ObjectPropertyStatement ops = objectPropertyStatementsIt.next();
|
||||||
if (ops.getSubject() != null && ops.getSubject() instanceof Individual)
|
if (ops.getSubject() != null && ops.getSubject() instanceof Individual)
|
||||||
addLinksToIndividual((Individual)ops.getSubject());
|
addLinksToIndividual((Individual)ops.getSubject());
|
||||||
if (ops.getObject() != null && ops.getObject() instanceof Individual)
|
if (ops.getObject() != null && ops.getObject() instanceof Individual)
|
||||||
|
@ -271,10 +267,10 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
private Link linkFromLinkResource(Resource linkRes, com.hp.hpl.jena.ontology.ObjectProperty whichLinkProp) {
|
private Link linkFromLinkResource(Resource linkRes, com.hp.hpl.jena.ontology.ObjectProperty whichLinkProp) {
|
||||||
Link link = new Link();
|
Link link = new Link();
|
||||||
link.setURI(linkRes.getURI());
|
link.setURI(linkRes.getURI());
|
||||||
ClosableIterator typesIt = linkRes.listProperties(RDF.type);
|
ClosableIterator<Statement> typesIt = linkRes.listProperties(RDF.type);
|
||||||
try {
|
try {
|
||||||
while (typesIt.hasNext()) {
|
while (typesIt.hasNext()) {
|
||||||
Statement st = (Statement) typesIt.next();
|
Statement st = typesIt.next();
|
||||||
try {
|
try {
|
||||||
Resource typeRes = (Resource) st.getObject();
|
Resource typeRes = (Resource) st.getObject();
|
||||||
if (!typeRes.getURI().equalsIgnoreCase(LINK.getURI())) { // TODO: remove IgnoreCase ; there because some serializations use "link" instead of "Link"
|
if (!typeRes.getURI().equalsIgnoreCase(LINK.getURI())) { // TODO: remove IgnoreCase ; there because some serializations use "link" instead of "Link"
|
||||||
|
@ -287,10 +283,10 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
}
|
}
|
||||||
if (LINK_ANCHOR != null) {
|
if (LINK_ANCHOR != null) {
|
||||||
try {
|
try {
|
||||||
ClosableIterator anchorStatements = getOntModel().listStatements(linkRes, LINK_ANCHOR, (Literal)null);
|
ClosableIterator<Statement> anchorStatements = getOntModel().listStatements(linkRes, LINK_ANCHOR, (Literal)null);
|
||||||
try {
|
try {
|
||||||
if (anchorStatements.hasNext()) {
|
if (anchorStatements.hasNext()) {
|
||||||
Literal l = (Literal) ((Statement)anchorStatements.next()).getObject();
|
Literal l = (Literal) anchorStatements.next().getObject();
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
link.setAnchor(l.getString());
|
link.setAnchor(l.getString());
|
||||||
}
|
}
|
||||||
|
@ -302,10 +298,10 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
}
|
}
|
||||||
if (LINK_URL != null) {
|
if (LINK_URL != null) {
|
||||||
try {
|
try {
|
||||||
ClosableIterator UrlStatements = getOntModel().listStatements(linkRes, LINK_URL, (Literal)null);
|
ClosableIterator<Statement> UrlStatements = getOntModel().listStatements(linkRes, LINK_URL, (Literal)null);
|
||||||
try {
|
try {
|
||||||
if (UrlStatements.hasNext()) {
|
if (UrlStatements.hasNext()) {
|
||||||
Literal l = (Literal) ((Statement)UrlStatements.next()).getObject();
|
Literal l = (Literal) UrlStatements.next().getObject();
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
if( (l.getDatatype() != null) && XSDDatatype.XSDanyURI.equals(l.getDatatype()) ) {
|
if( (l.getDatatype() != null) && XSDDatatype.XSDanyURI.equals(l.getDatatype()) ) {
|
||||||
try {
|
try {
|
||||||
|
@ -324,10 +320,10 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
}
|
}
|
||||||
if (LINK_DISPLAYRANK != null) {
|
if (LINK_DISPLAYRANK != null) {
|
||||||
try {
|
try {
|
||||||
ClosableIterator rankStatements = getOntModel().listStatements(linkRes, LINK_DISPLAYRANK, (Literal)null);
|
ClosableIterator<Statement> rankStatements = getOntModel().listStatements(linkRes, LINK_DISPLAYRANK, (Literal)null);
|
||||||
try {
|
try {
|
||||||
if (rankStatements.hasNext()) {
|
if (rankStatements.hasNext()) {
|
||||||
Literal l = (Literal) ((Statement)rankStatements.next()).getObject();
|
Literal l = (Literal) rankStatements.next().getObject();
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
if (l.getDatatype()==XSDDatatype.XSDinteger) {
|
if (l.getDatatype()==XSDDatatype.XSDinteger) {
|
||||||
link.setDisplayRank(String.valueOf(l.getInt()));
|
link.setDisplayRank(String.valueOf(l.getInt()));
|
||||||
|
@ -345,10 +341,10 @@ public class LinksDaoJena extends JenaBaseDao implements LinksDao {
|
||||||
} catch (ClassCastException e) {}
|
} catch (ClassCastException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClosableIterator stmtIt = getOntModel().listStatements(null, (com.hp.hpl.jena.rdf.model.Property)whichLinkProp, linkRes); // jena Property, not vitro Property
|
ClosableIterator<Statement> stmtIt = getOntModel().listStatements(null, (com.hp.hpl.jena.rdf.model.Property)whichLinkProp, linkRes); // jena Property, not vitro Property
|
||||||
try {
|
try {
|
||||||
if (stmtIt.hasNext()) {
|
if (stmtIt.hasNext()) {
|
||||||
Statement stmt = (Statement) stmtIt.next();
|
Statement stmt = stmtIt.next();
|
||||||
Resource indRes = stmt.getSubject();
|
Resource indRes = stmt.getSubject();
|
||||||
link.setEntityURI(indRes.getURI());
|
link.setEntityURI(indRes.getURI());
|
||||||
ObjectPropertyStatement op = new ObjectPropertyStatementImpl();
|
ObjectPropertyStatement op = new ObjectPropertyStatementImpl();
|
||||||
|
|
Loading…
Add table
Reference in a new issue