various and sundry small DAO improvements
This commit is contained in:
parent
5fea873ed2
commit
d7da587aa7
17 changed files with 130 additions and 116 deletions
|
@ -441,14 +441,14 @@ public class OperationController extends BaseEditController {
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
log.error(this.getClass().getName()+" encountered exception performing two-stage update");
|
log.error(this.getClass().getName()+" encountered exception performing two-stage update");
|
||||||
Throwable innerE = e.getTargetException();
|
Throwable innerE = e.getTargetException();
|
||||||
log.error(innerE);
|
log.error(innerE, innerE);
|
||||||
if (innerE.getMessage()!=null) {
|
if (innerE.getMessage()!=null) {
|
||||||
log.error(innerE.getMessage());
|
//log.error(innerE.getMessage());
|
||||||
epo.setAttribute("globalErrorMsg",innerE.getMessage());
|
epo.setAttribute("globalErrorMsg",innerE.getMessage());
|
||||||
}
|
}
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
} catch (IllegalAccessException iae) {
|
} catch (IllegalAccessException iae) {
|
||||||
log.error(iae);
|
log.error(iae, iae);
|
||||||
epo.setAttribute("globalErrorMessage", "Illegal access - see error logs.");
|
epo.setAttribute("globalErrorMessage", "Illegal access - see error logs.");
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -459,15 +459,15 @@ public class OperationController extends BaseEditController {
|
||||||
log.error(this.getClass().getName()+" encountered exception performing edit action");
|
log.error(this.getClass().getName()+" encountered exception performing edit action");
|
||||||
Throwable innerE = e.getTargetException();
|
Throwable innerE = e.getTargetException();
|
||||||
//innerE.printStackTrace();
|
//innerE.printStackTrace();
|
||||||
log.error(innerE);
|
log.error(innerE, innerE);
|
||||||
if (innerE.getMessage()!=null) {
|
if (innerE.getMessage()!=null) {
|
||||||
//System.out.println(innerE.getMessage());
|
//System.out.println(innerE.getMessage());
|
||||||
log.error(innerE.getMessage());
|
//log.error(innerE.getMessage());
|
||||||
epo.setAttribute("globalErrorMsg",innerE.getMessage());
|
epo.setAttribute("globalErrorMsg",innerE.getMessage());
|
||||||
}
|
}
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
} catch (IllegalAccessException iae) {
|
} catch (IllegalAccessException iae) {
|
||||||
log.error(iae);
|
log.error(iae, iae);
|
||||||
epo.setAttribute("globalErrorMessage", "Illegal access - see error logs.");
|
epo.setAttribute("globalErrorMessage", "Illegal access - see error logs.");
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,6 @@ public interface ObjectPropertyStatement {
|
||||||
|
|
||||||
public String toString();
|
public String toString();
|
||||||
|
|
||||||
public boolean isSubjectOriented();
|
|
||||||
|
|
||||||
public void setSubjectOriented(boolean subjectOriented);
|
|
||||||
|
|
||||||
public String getSubjectURI();
|
public String getSubjectURI();
|
||||||
|
|
||||||
public void setSubjectURI(String subjectURI);
|
public void setSubjectURI(String subjectURI);
|
||||||
|
|
|
@ -18,9 +18,7 @@ public class ObjectPropertyStatementImpl implements ObjectPropertyStatement
|
||||||
|
|
||||||
private String propertyURI = null;
|
private String propertyURI = null;
|
||||||
private ObjectProperty property = null;
|
private ObjectProperty property = null;
|
||||||
private String qualifier = null;
|
|
||||||
private boolean subjectOriented = true; //is the range the item of interest?
|
private boolean subjectOriented = true; //is the range the item of interest?
|
||||||
private String description = null; //generated desc based on subjectOriented during sql query.
|
|
||||||
|
|
||||||
public ObjectPropertyStatementImpl() { }
|
public ObjectPropertyStatementImpl() { }
|
||||||
|
|
||||||
|
@ -37,23 +35,7 @@ public class ObjectPropertyStatementImpl implements ObjectPropertyStatement
|
||||||
String prop = (getProperty()!=null)?getProperty().getDomainPublic():"by propURI"+getPropertyURI();
|
String prop = (getProperty()!=null)?getProperty().getDomainPublic():"by propURI"+getPropertyURI();
|
||||||
String ran = (getObject()!= null)?getObject().getName():"objectURI:"+getObjectURI();
|
String ran = (getObject()!= null)?getObject().getName():"objectURI:"+getObjectURI();
|
||||||
String dom = (getSubject()!= null)?getSubject().getName():"subjectURI:"+getSubjectURI();
|
String dom = (getSubject()!= null)?getSubject().getName():"subjectURI:"+getSubjectURI();
|
||||||
String orent = (isSubjectOriented() )?"subject oriented":"object oriented";
|
return "Object Property Statements: "+dom+" "+prop+" to "+ran+" ";
|
||||||
return "Object Property Statements: "+dom+" "+prop+" to "+ran+" "+orent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement#isSubjectOriented()
|
|
||||||
*/
|
|
||||||
public boolean isSubjectOriented() {
|
|
||||||
return subjectOriented;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement#setSubjectOriented(boolean)
|
|
||||||
*/
|
|
||||||
public void setSubjectOriented(boolean subjectOriented) {
|
|
||||||
this.subjectOriented = subjectOriented;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -100,6 +82,11 @@ public class ObjectPropertyStatementImpl implements ObjectPropertyStatement
|
||||||
*/
|
*/
|
||||||
public void setSubject(Individual subject) {
|
public void setSubject(Individual subject) {
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
|
if (subject == null || subject.isAnonymous()) {
|
||||||
|
setSubjectURI(null);
|
||||||
|
} else {
|
||||||
|
setSubjectURI(subject.getURI());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,6 +123,11 @@ public class ObjectPropertyStatementImpl implements ObjectPropertyStatement
|
||||||
*/
|
*/
|
||||||
public void setObject(Individual object) {
|
public void setObject(Individual object) {
|
||||||
this.object = object;
|
this.object = object;
|
||||||
|
if (object == null || object.isAnonymous()) {
|
||||||
|
setObjectURI(null);
|
||||||
|
} else {
|
||||||
|
setObjectURI(object.getURI());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -133,9 +133,15 @@ public class VClass extends BaseResourceBean implements Comparable<VClass>
|
||||||
* Sorts alphabetically by name
|
* Sorts alphabetically by name
|
||||||
*/
|
*/
|
||||||
public int compareTo (VClass o1) {
|
public int compareTo (VClass o1) {
|
||||||
|
if (this.getName() == null) {
|
||||||
|
return 1;
|
||||||
|
} else if (o1.getName() == null) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
Collator collator = Collator.getInstance();
|
Collator collator = Collator.getInstance();
|
||||||
return collator.compare(this.getName(),o1.getName());
|
return collator.compare(this.getName(),o1.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the VClass to a string
|
* Converts the VClass to a string
|
||||||
|
|
|
@ -39,7 +39,7 @@ public interface WebappDaoFactory {
|
||||||
|
|
||||||
public Set<String> getNonuserNamespaces();
|
public Set<String> getNonuserNamespaces();
|
||||||
|
|
||||||
public String[] getPreferredLanguages();
|
public List<String> getPreferredLanguages();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BJL23 2008-05-20: Putting this here for lack of a more logical place.
|
* BJL23 2008-05-20: Putting this here for lack of a more logical place.
|
||||||
|
|
|
@ -2,30 +2,29 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class WebappDaoFactoryConfig {
|
public class WebappDaoFactoryConfig {
|
||||||
|
|
||||||
private String[] preferredLanguages;
|
private List<String> preferredLanguages;
|
||||||
private String defaultNamespace;
|
private String defaultNamespace;
|
||||||
private Set<String> nonUserNamespaces;
|
private Set<String> nonUserNamespaces;
|
||||||
|
|
||||||
public WebappDaoFactoryConfig() {
|
public WebappDaoFactoryConfig() {
|
||||||
preferredLanguages = new String[3];
|
preferredLanguages = Arrays.asList("en-US", "en", "EN");
|
||||||
preferredLanguages[0] = "en-US";
|
|
||||||
preferredLanguages[1] = "en";
|
|
||||||
preferredLanguages[2] = "EN";
|
|
||||||
defaultNamespace = "http://vitro.mannlib.cornell.edu/ns/default#";
|
defaultNamespace = "http://vitro.mannlib.cornell.edu/ns/default#";
|
||||||
nonUserNamespaces = new HashSet<String>();
|
nonUserNamespaces = new HashSet<String>();
|
||||||
nonUserNamespaces.add(VitroVocabulary.vitroURI);
|
nonUserNamespaces.add(VitroVocabulary.vitroURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getPreferredLanguages() {
|
public List<String> getPreferredLanguages() {
|
||||||
return this.preferredLanguages;
|
return this.preferredLanguages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferredLanguages(String[] pl) {
|
public void setPreferredLanguages(List<String> pl) {
|
||||||
this.preferredLanguages = pl;
|
this.preferredLanguages = pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,6 @@ public class ObjectPropertyStatementFiltering implements ObjectPropertyStatement
|
||||||
return innerStmt.getSubjectURI();
|
return innerStmt.getSubjectURI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSubjectOriented() {
|
|
||||||
return innerStmt.isSubjectOriented();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setObject(Individual object) {
|
public void setObject(Individual object) {
|
||||||
innerStmt.setObject(object);
|
innerStmt.setObject(object);
|
||||||
}
|
}
|
||||||
|
@ -80,10 +76,6 @@ public class ObjectPropertyStatementFiltering implements ObjectPropertyStatement
|
||||||
innerStmt.setSubject(subject);
|
innerStmt.setSubject(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubjectOriented(boolean subjectOriented) {
|
|
||||||
innerStmt.setSubjectOriented(subjectOriented);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubjectURI(String subjectURI) {
|
public void setSubjectURI(String subjectURI) {
|
||||||
innerStmt.setSubjectURI(subjectURI);
|
innerStmt.setSubjectURI(subjectURI);
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
|
||||||
return innerWebappDaoFactory.getNonuserNamespaces();
|
return innerWebappDaoFactory.getNonuserNamespaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getPreferredLanguages() {
|
public List<String> getPreferredLanguages() {
|
||||||
return innerWebappDaoFactory.getPreferredLanguages();
|
return innerWebappDaoFactory.getPreferredLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,9 +187,10 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (uri != null && !uri.equals(currRes.getURI())) {
|
if (uri != null && !uri.equals(currRes.getURI())) {
|
||||||
Individual ent = makeIndividual(uri, label);
|
try {
|
||||||
if (ent != null) {
|
ents.add(makeIndividual(uri, label));
|
||||||
ents.add(ent);
|
} catch (IndividualNotFoundException e) {
|
||||||
|
// don't add
|
||||||
}
|
}
|
||||||
uri = currRes.getURI();
|
uri = currRes.getURI();
|
||||||
label = null;
|
label = null;
|
||||||
|
@ -201,9 +202,10 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
label = labelLit.getLexicalForm();
|
label = labelLit.getLexicalForm();
|
||||||
}
|
}
|
||||||
if (!rs.hasNext()) {
|
if (!rs.hasNext()) {
|
||||||
Individual ent = makeIndividual(uri, label);
|
try {
|
||||||
if (ent != null) {
|
ents.add(makeIndividual(uri, label));
|
||||||
ents.add(ent);
|
} catch (IndividualNotFoundException e) {
|
||||||
|
// don't add
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,8 +239,12 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
if (currRes.isAnon()) {
|
if (currRes.isAnon()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
filteredIndividualList.add(
|
filteredIndividualList.add(
|
||||||
makeIndividual(currRes.getURI(), null));
|
makeIndividual(currRes.getURI(), null));
|
||||||
|
} catch (IndividualNotFoundException e) {
|
||||||
|
// don't add
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
@ -247,7 +253,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
return filteredIndividualList;
|
return filteredIndividualList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Individual makeIndividual(String uri, String label) {
|
private Individual makeIndividual(String uri, String label) throws IndividualNotFoundException {
|
||||||
Individual ent = new IndividualSDB(uri,
|
Individual ent = new IndividualSDB(uri,
|
||||||
this.dwf, datasetMode, getWebappDaoFactory(),
|
this.dwf, datasetMode, getWebappDaoFactory(),
|
||||||
SKIP_INITIALIZATION);
|
SKIP_INITIALIZATION);
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
DatasetWrapperFactory datasetWrapperFactory,
|
DatasetWrapperFactory datasetWrapperFactory,
|
||||||
SDBDatasetMode datasetMode,
|
SDBDatasetMode datasetMode,
|
||||||
WebappDaoFactoryJena wadf,
|
WebappDaoFactoryJena wadf,
|
||||||
boolean skipInitialization) {
|
boolean skipInitialization) throws IndividualNotFoundException {
|
||||||
this.individualURI = individualURI;
|
this.individualURI = individualURI;
|
||||||
this.datasetMode = datasetMode;
|
this.datasetMode = datasetMode;
|
||||||
this.dwf = datasetWrapperFactory;
|
this.dwf = datasetWrapperFactory;
|
||||||
|
@ -176,7 +176,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
public IndividualSDB(String individualURI,
|
public IndividualSDB(String individualURI,
|
||||||
DatasetWrapperFactory datasetWrapperFactory,
|
DatasetWrapperFactory datasetWrapperFactory,
|
||||||
SDBDatasetMode datasetMode,
|
SDBDatasetMode datasetMode,
|
||||||
WebappDaoFactoryJena wadf) {
|
WebappDaoFactoryJena wadf) throws IndividualNotFoundException {
|
||||||
this(individualURI,
|
this(individualURI,
|
||||||
datasetWrapperFactory,
|
datasetWrapperFactory,
|
||||||
datasetMode,
|
datasetMode,
|
||||||
|
@ -184,7 +184,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
!SKIP_INITIALIZATION);
|
!SKIP_INITIALIZATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IndividualNotFoundException extends RuntimeException {}
|
public class IndividualNotFoundException extends Exception {}
|
||||||
|
|
||||||
private void setUpURIParts(OntResource ind) {
|
private void setUpURIParts(OntResource ind) {
|
||||||
if (ind != null) {
|
if (ind != null) {
|
||||||
|
@ -464,8 +464,24 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) {
|
if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), this.dwf, datasetMode, webappDaoFactory);
|
Individual subj = null;
|
||||||
Individual obj = new IndividualSDB(((OntResource) s.getObject().as(OntResource.class)).getURI(), this.dwf, datasetMode, webappDaoFactory);
|
try {
|
||||||
|
subj = new IndividualSDB(
|
||||||
|
((OntResource) s.getSubject().as(OntResource.class))
|
||||||
|
.getURI(),
|
||||||
|
this.dwf, datasetMode, webappDaoFactory);
|
||||||
|
} catch (IndividualNotFoundException e) {
|
||||||
|
// leave null subject
|
||||||
|
}
|
||||||
|
Individual obj = null;
|
||||||
|
try {
|
||||||
|
obj = new IndividualSDB(
|
||||||
|
((OntResource) s.getObject().as(OntResource.class))
|
||||||
|
.getURI(),
|
||||||
|
this.dwf, datasetMode, webappDaoFactory);
|
||||||
|
} catch (IndividualNotFoundException e) {
|
||||||
|
// leave null object
|
||||||
|
}
|
||||||
ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI());
|
ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI());
|
||||||
// We don't want to filter out statements simply because we
|
// We don't want to filter out statements simply because we
|
||||||
// can't find a type for the property, so we'll just make a
|
// can't find a type for the property, so we'll just make a
|
||||||
|
@ -517,6 +533,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
while (values.hasNext()) {
|
while (values.hasNext()) {
|
||||||
result = values.next();
|
result = values.next();
|
||||||
RDFNode value = result.get("object");
|
RDFNode value = result.get("object");
|
||||||
|
try {
|
||||||
if (value.canAs(OntResource.class)) {
|
if (value.canAs(OntResource.class)) {
|
||||||
relatedIndividuals.add(
|
relatedIndividuals.add(
|
||||||
new IndividualSDB(
|
new IndividualSDB(
|
||||||
|
@ -526,6 +543,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
datasetMode,
|
datasetMode,
|
||||||
webappDaoFactory) );
|
webappDaoFactory) );
|
||||||
}
|
}
|
||||||
|
} catch (IndividualNotFoundException e) {
|
||||||
|
// don't add to the list
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
@ -555,9 +575,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
QuerySolution result = results.next();
|
QuerySolution result = results.next();
|
||||||
RDFNode value = result.get("object");
|
RDFNode value = result.get("object");
|
||||||
if (value != null && value.canAs(OntResource.class)) {
|
if (value != null && value.canAs(OntResource.class)) {
|
||||||
|
try {
|
||||||
return new IndividualSDB(
|
return new IndividualSDB(
|
||||||
((OntResource) value.as(OntResource.class)).getURI(),
|
((OntResource) value.as(OntResource.class)).getURI(),
|
||||||
dwf, datasetMode, webappDaoFactory);
|
dwf, datasetMode, webappDaoFactory);
|
||||||
|
} catch (IndividualNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
|
|
||||||
protected String DEFAULT_NAMESPACE;
|
protected String DEFAULT_NAMESPACE;
|
||||||
protected Set<String> NONUSER_NAMESPACES;
|
protected Set<String> NONUSER_NAMESPACES;
|
||||||
protected String[] PREFERRED_LANGUAGES;
|
protected List<String> PREFERRED_LANGUAGES;
|
||||||
|
|
||||||
/* ******************* constructor ************************* */
|
/* ******************* constructor ************************* */
|
||||||
|
|
||||||
|
@ -501,7 +501,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error in updatePropertyDateValue");
|
log.error("Error in updatePropertyDateValue", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,8 +552,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error in updatePropertyDateTimeValue");
|
log.error("Error in updatePropertyDateTimeValue", e);
|
||||||
log.error(e, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -767,7 +766,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
if (label.isLiteral()) {
|
if (label.isLiteral()) {
|
||||||
Literal labelLit = ((Literal)label);
|
Literal labelLit = ((Literal)label);
|
||||||
String labelLanguage = labelLit.getLanguage();
|
String labelLanguage = labelLit.getLanguage();
|
||||||
if ( (labelLanguage==null) && (lang==null) ) {
|
if ( (labelLanguage == null) && (lang == null || lang.isEmpty()) ) {
|
||||||
return labelLit;
|
return labelLit;
|
||||||
}
|
}
|
||||||
if ( (lang != null) && (lang.equals(labelLanguage)) ) {
|
if ( (lang != null) && (lang.equals(labelLanguage)) ) {
|
||||||
|
@ -857,6 +856,10 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
Literal label = null;
|
Literal label = null;
|
||||||
List<RDFNode> labels = r.listPropertyValues(p).toList();
|
List<RDFNode> labels = r.listPropertyValues(p).toList();
|
||||||
|
|
||||||
|
if (labels.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Sort by lexical value to guarantee consistent results
|
// Sort by lexical value to guarantee consistent results
|
||||||
Collections.sort(labels, new Comparator<RDFNode>() {
|
Collections.sort(labels, new Comparator<RDFNode>() {
|
||||||
public int compare(RDFNode left, RDFNode right) {
|
public int compare(RDFNode left, RDFNode right) {
|
||||||
|
@ -871,8 +874,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (int i=0; i<PREFERRED_LANGUAGES.length; i++) {
|
for (String lang : PREFERRED_LANGUAGES) {
|
||||||
String lang = PREFERRED_LANGUAGES[i];
|
|
||||||
label = getLabel(lang,labels);
|
label = getLabel(lang,labels);
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
break;
|
break;
|
||||||
|
@ -880,12 +882,21 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
}
|
}
|
||||||
if ( label == null && alsoTryNoLang ) {
|
if ( label == null && alsoTryNoLang ) {
|
||||||
label = getLabel("", labels);
|
label = getLabel("", labels);
|
||||||
|
// accept any label as a last resort
|
||||||
|
if (label == null) {
|
||||||
|
for (RDFNode labelNode : labels) {
|
||||||
|
if (labelNode instanceof Literal) {
|
||||||
|
label = ((Literal) labelNode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getDefaultLanguage() {
|
protected String getDefaultLanguage() {
|
||||||
return PREFERRED_LANGUAGES[0];
|
return PREFERRED_LANGUAGES.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class OntologyDaoJena extends JenaBaseDao implements OntologyDao {
|
||||||
try {
|
try {
|
||||||
com.hp.hpl.jena.ontology.Ontology o = ontModel.createOntology(adjustOntologyURI(ontology.getURI()));
|
com.hp.hpl.jena.ontology.Ontology o = ontModel.createOntology(adjustOntologyURI(ontology.getURI()));
|
||||||
if (ontology.getName() != null && ontology.getName().length()>0) {
|
if (ontology.getName() != null && ontology.getName().length()>0) {
|
||||||
o.setLabel(ontology.getName(), PREFERRED_LANGUAGES[0]);
|
o.setLabel(ontology.getName(), getDefaultLanguage());
|
||||||
}
|
}
|
||||||
if (ontology.getPrefix() != null && ontology.getPrefix().length()>0) {
|
if (ontology.getPrefix() != null && ontology.getPrefix().length()>0) {
|
||||||
addPropertyStringValue(o,ONTOLOGY_PREFIX_ANNOT,ontology.getPrefix(),ontModel);
|
addPropertyStringValue(o,ONTOLOGY_PREFIX_ANNOT,ontology.getPrefix(),ontModel);
|
||||||
|
|
|
@ -9,6 +9,9 @@ import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
|
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
|
||||||
import com.hp.hpl.jena.ontology.AnnotationProperty;
|
import com.hp.hpl.jena.ontology.AnnotationProperty;
|
||||||
import com.hp.hpl.jena.ontology.CardinalityRestriction;
|
import com.hp.hpl.jena.ontology.CardinalityRestriction;
|
||||||
|
@ -59,6 +62,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
||||||
|
|
||||||
public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
|
|
||||||
|
protected static final Log log = LogFactory.getLog(VClassDaoJena.class);
|
||||||
|
|
||||||
public VClassDaoJena(WebappDaoFactoryJena wadf) {
|
public VClassDaoJena(WebappDaoFactoryJena wadf) {
|
||||||
super(wadf);
|
super(wadf);
|
||||||
}
|
}
|
||||||
|
@ -446,11 +451,12 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
List<VClass> classes = new ArrayList<VClass>();
|
List<VClass> classes = new ArrayList<VClass>();
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
ClosableIterator<OntClass> classIt = getOntModel().listClasses();
|
ClosableIterator<Individual> classIt = getOntModel().listIndividuals(OWL.Class);
|
||||||
try {
|
try {
|
||||||
while (classIt.hasNext()) {
|
while (classIt.hasNext()) {
|
||||||
try {
|
try {
|
||||||
OntClass cls = classIt.next();
|
Individual classInd = classIt.next();
|
||||||
|
OntClass cls = (OntClass) classInd.as(OntClass.class);
|
||||||
if (!cls.isAnon() && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
|
if (!cls.isAnon() && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
|
||||||
classes.add(new VClassJena(cls,getWebappDaoFactory()));
|
classes.add(new VClassJena(cls,getWebappDaoFactory()));
|
||||||
}
|
}
|
||||||
|
@ -481,11 +487,15 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
*/
|
*/
|
||||||
private Iterator<OntClass> smarterListHierarchyRootClasses(OntModel ontModel, String ontologyURI) {
|
private Iterator<OntClass> smarterListHierarchyRootClasses(OntModel ontModel, String ontologyURI) {
|
||||||
List<OntClass> rootClassList = new ArrayList<OntClass>();
|
List<OntClass> rootClassList = new ArrayList<OntClass>();
|
||||||
ClosableIterator ci = ontModel.listClasses();
|
ClosableIterator<Individual> ci = ontModel.listIndividuals(OWL.Class);
|
||||||
try {
|
try {
|
||||||
for (ClosableIterator i = ci ; i.hasNext(); ) {
|
for (ClosableIterator<Individual> i = ci ; i.hasNext(); ) {
|
||||||
try {
|
try {
|
||||||
OntClass ontClass = (OntClass) i.next();
|
Individual classInd = i.next();
|
||||||
|
// if (!classInd.canAs(OntClass.class)) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
OntClass ontClass = (OntClass) classInd.as(OntClass.class);
|
||||||
boolean isRoot = true;
|
boolean isRoot = true;
|
||||||
for (Iterator<RDFNode> j = ontClass.listPropertyValues(RDFS.subClassOf); j.hasNext(); ) {
|
for (Iterator<RDFNode> j = ontClass.listPropertyValues(RDFS.subClassOf); j.hasNext(); ) {
|
||||||
Resource res = (Resource) j.next();
|
Resource res = (Resource) j.next();
|
||||||
|
@ -510,7 +520,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
rootClassList.add(ontClass);
|
rootClassList.add(ontClass);
|
||||||
}
|
}
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
log.error(cce);
|
log.error(cce, cce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
return config.getDefaultNamespace();
|
return config.getDefaultNamespace();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getPreferredLanguages() {
|
public List<String> getPreferredLanguages() {
|
||||||
return config.getPreferredLanguages();
|
return config.getPreferredLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -638,18 +638,6 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
|
||||||
// Un-implemented methods
|
// Un-implemented methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSubjectOriented() {
|
|
||||||
throw new RuntimeException(
|
|
||||||
"ObjectPropertyStatement.isSubjectOriented() not implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSubjectOriented(boolean subjectOriented) {
|
|
||||||
throw new RuntimeException(
|
|
||||||
"ObjectPropertyStatement.setSubjectOriented() not implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSubjectURI(String subjectURI) {
|
public void setSubjectURI(String subjectURI) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
|
|
@ -55,16 +55,6 @@ public class ObjectPropertyStatementDaoStub implements
|
||||||
.getObjectURI());
|
.getObjectURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSubjectOriented() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSubjectOriented(boolean subjectOriented) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSubjectURI() {
|
public String getSubjectURI() {
|
||||||
return s;
|
return s;
|
||||||
|
|
|
@ -169,7 +169,7 @@ return this.objectPropertyStatementDao; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPreferredLanguages() {
|
public List<String> getPreferredLanguages() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"WebappDaoFactory.getPreferredLanguages() not implemented.");
|
"WebappDaoFactory.getPreferredLanguages() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue