NIH VIVO Release 1.2 maintenance branch

This commit is contained in:
jeb228 2011-02-10 19:08:03 +00:00
commit a0617b0b61
287 changed files with 8261 additions and 4423 deletions

View file

@ -6,9 +6,13 @@ REQUIRED ELEMENTS
----------------- -----------------
- list-view-config: root element - list-view-config: root element
- query: the sparql query used to retrieve the data - query-base: sparql query used to retrieve data for an uncollated property
- query-collated: sparql query used to retrieve data for a collated property
- template: the name of the template used to display a single property statement - template: the name of the template used to display a single property statement
Note: both query-base and query-collated must be included to support the collation checkbox
on the back end Object Property Edit form.
----------------- -----------------
OPTIONAL ELEMENTS OPTIONAL ELEMENTS
@ -22,9 +26,15 @@ OPTIONAL ELEMENTS
THE QUERY THE QUERY
--------- ---------
-------------------------- -----------------
General query requirements Construct queries
-------------------------- -----------------
- forthcoming -
---------------------------------
General select query requirements
---------------------------------
- Use a SELECT DISTINCT clause rather than a simple SELECT. There can still be cases where - Use a SELECT DISTINCT clause rather than a simple SELECT. There can still be cases where
the same individual is retrieved more than once, if there are multiple solutions to the the same individual is retrieved more than once, if there are multiple solutions to the
@ -43,9 +53,6 @@ due to the possibility of incomplete data. Make sure the query does the followin
display the local name in the absence of the linked individual. Alternatively, this can be display the local name in the absence of the linked individual. Alternatively, this can be
retrieved in the template using the localname(uri) method. retrieved in the template using the localname(uri) method.
- Each assertion or set of optional assertions must reference a different graph variable, so that
no requirement about which assertions are in the same graph is imposed (unless this is desired
in a specific case).
--------------------------- ---------------------------
Query for collated property Query for collated property
@ -54,20 +61,16 @@ Query for collated property
- Include a ?subclass variable, named as such, in the SELECT clause. If the ?subclass variable - Include a ?subclass variable, named as such, in the SELECT clause. If the ?subclass variable
is missing, the property will be displayed without collation. is missing, the property will be displayed without collation.
- ?subclass must be the first term in the ORDER BY clause - ?subclass must be the first term in the ORDER BY clause.
- Include the following in the WHERE clause, substituting in the relevant variables for - Include the following in the WHERE clause, substituting in the relevant variables for
?infoResource and core:InformationResource: ?infoResource and core:InformationResource:
OPTIONAL { GRAPH ?g4 { ?subclass rdfs:subClassOf core:InformationResource } OPTIONAL { GRAPH ?g4 { ?subclass rdfs:subClassOf core:InformationResource }
GRAPH ?g5 { ?infoResource a ?subclass } GRAPH ?g5 { ?infoResource a ?subclass }
FILTER (?g5 != <http://vitro.mannlib.cornell.edu/default/inferred-tbox> &&
?g5 != <http://vitro.mannlib.cornell.edu/default/vitro-kb-inf> )
} }
The filter blocks the retrieval of inferred type statements, so that, for example, we get - Postprocessing removes all but the most specific subclass value from the query result set.
subclass bibo:Book but not bibo:Document, assuming the latter is inferred. If both have been
asserted, we will get both.
---------------------- ----------------------
Datetimes in the query Datetimes in the query

View file

@ -72,7 +72,7 @@ public class InfoResponseParser {
throws Exception { throws Exception {
Matcher matcher = pattern.matcher(infoResponse); Matcher matcher = pattern.matcher(infoResponse);
if (!matcher.find()) { if (!matcher.find()) {
throw new Exception("no match with '" + pattern + "'."); throw new Exception("no match with '" + pattern + "'. Is your Subversion client out of date?");
} }
String value = matcher.group(groupIndex); String value = matcher.group(groupIndex);

View file

@ -70,7 +70,15 @@ public class RevisionInfoBuilder {
} }
String release = assembleReleaseNameFromSubversion(); String release = assembleReleaseNameFromSubversion();
if (release == null) {
return null;
}
String revision = obtainRevisionLevelFromSubversion(); String revision = obtainRevisionLevelFromSubversion();
if (revision == null) {
return null;
}
return buildLine(release, revision); return buildLine(release, revision);
} }

View file

@ -159,5 +159,8 @@ webapp/web/js/selectivizr.js
# PROBLEM: Can't find any info on licensing. # PROBLEM: Can't find any info on licensing.
webapp/web/js/jquery_plugins/supersleight.js webapp/web/js/jquery_plugins/supersleight.js
# See /doc/3rd-party-licenses.txt for LICENSE file
webapp/web/js/raphael/*
# See /doc/3rd-party-licenses.txt for LICENSE file # See /doc/3rd-party-licenses.txt for LICENSE file
webapp/web/js/sparql/prototype.js webapp/web/js/sparql/prototype.js

View file

@ -171,7 +171,7 @@
</listener> </listener>
<listener> <listener>
<listener-class>edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache</listener-class> <listener-class>edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache$Setup</listener-class>
</listener> </listener>
<!-- <!--
@ -315,6 +315,24 @@
<url-pattern>/SearchIndex</url-pattern> <url-pattern>/SearchIndex</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet>
<servlet-name>SimpleReasonerRecomputeController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.SimpleReasonerRecomputeController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleReasonerRecomputeController</servlet-name>
<url-pattern>/RecomputeInferences</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SDBSetupController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.SDBSetupController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SDBSetupController</servlet-name>
<url-pattern>/sdbsetup</url-pattern>
</servlet-mapping>
<servlet> <servlet>
<servlet-name>MenuN3EditController</servlet-name> <servlet-name>MenuN3EditController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.MenuN3EditController</servlet-class> <servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.MenuN3EditController</servlet-class>
@ -1505,3 +1523,8 @@
</web-app> </web-app>
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>

View file

@ -25,6 +25,7 @@ import edu.cornell.mannlib.vedit.util.FormUtils;
import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
public class BaseEditController extends VitroHttpServlet { public class BaseEditController extends VitroHttpServlet {
@ -159,14 +160,13 @@ public class BaseEditController extends VitroHttpServlet {
try { try {
ontModel = (OntModel) request.getSession().getAttribute(MODEL_ATTR_NAME); ontModel = (OntModel) request.getSession().getAttribute(MODEL_ATTR_NAME);
} catch (Exception e) {} } catch (Exception e) {
// ignoring any problems here - we're not really expecting
// this attribute to be populated anyway
}
if ( ontModel == null ) { if ( ontModel == null ) {
try { ontModel = (OntModel) ModelContext.getBaseOntModelSelector(ctx).getTBoxModel();
ontModel = (OntModel) ctx.getAttribute(MODEL_ATTR_NAME);
} catch (Exception e) {
throw new RuntimeException("Could not find OntModel in context attribute '"+MODEL_ATTR_NAME+"'");
}
} }
return ontModel; return ontModel;

View file

@ -215,7 +215,10 @@ public class OperationController extends BaseEditController {
Object newObj = null; Object newObj = null;
if (epo.getOriginalBean() != null) { // we're updating or deleting an existing bean if (epo.getOriginalBean() != null) { // we're updating or deleting an existing bean
if (epo.getImplementationClass() != null) { if (epo.getImplementationClass() != null) {
newObj = OperationUtils.cloneBean(epo.getOriginalBean(), epo.getImplementationClass()); newObj = OperationUtils.cloneBean(
epo.getOriginalBean(),
epo.getImplementationClass(),
epo.getBeanClass());
} else { } else {
newObj = OperationUtils.cloneBean(epo.getOriginalBean()); newObj = OperationUtils.cloneBean(epo.getOriginalBean());
} }

View file

@ -67,7 +67,7 @@ public class OperationUtils{
* @return * @return
*/ */
public static Object cloneBean (Object bean) { public static Object cloneBean (Object bean) {
return cloneBean(bean, bean.getClass()); return cloneBean(bean, bean.getClass(), bean.getClass());
} }
/** /**
@ -76,39 +76,61 @@ public class OperationUtils{
* @param bean * @param bean
* @return * @return
*/ */
public static Object cloneBean (Object bean, Class beanClass){ public static Object cloneBean (Object bean, Class beanClass, Class iface){
Object newBean = null; Object newBean = null;
try { try {
newBean = beanClass.newInstance(); newBean = beanClass.newInstance();
Method[] beanMeths = beanClass.getMethods(); Method[] beanMeths = iface.getMethods();
for (int i=0; i<beanMeths.length ; ++i){ for (int i=0; i<beanMeths.length ; ++i) {
String methName = beanMeths[i].getName(); Method beanMeth = beanMeths[i];
if (methName.indexOf("get")==0){ String methName = beanMeth.getName();
if (methName.startsWith("get")
&& beanMeth.getParameterTypes().length == 0 ) {
String fieldName = methName.substring(3,methName.length()); String fieldName = methName.substring(3,methName.length());
Class returnType = beanMeths[i].getReturnType(); Class returnType = beanMeth.getReturnType();
try { try {
Class[] args = new Class[1]; Class[] args = new Class[1];
args[0] = returnType; args[0] = returnType;
Method setterMethod = beanClass.getMethod("set"+fieldName,args); Method setterMethod = iface.getMethod("set"+fieldName,args);
try { try {
Object fieldVal = beanMeths[i].invoke(bean,(Object[])null); Object fieldVal = beanMeth.invoke(bean,(Object[])null);
try { try {
Object[] setArgs = new Object[1]; Object[] setArgs = new Object[1];
setArgs[0] = fieldVal; setArgs[0] = fieldVal;
setterMethod.invoke(newBean,setArgs); setterMethod.invoke(newBean,setArgs);
} catch (IllegalAccessException iae) { } catch (IllegalAccessException iae) {
log.error("edu.cornell.mannlib.vitro.edit.utils.OperationUtils encountered IllegalAccessException invoking "+setterMethod.getName()); log.error(OperationUtils.class.getName() +
".cloneBean() " +
" encountered IllegalAccessException " +
" invoking " +
setterMethod.getName(), iae);
throw new RuntimeException(iae);
} catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) {
log.error("edu.cornell.mannlib.vitro.edit.utils.OperationUtils encountered InvocationTargetException invoking "+setterMethod.getName()); log.error(OperationUtils.class.getName() +
log.error(ite.getTargetException().getClass().toString()); ".cloneBean() " +
" encountered InvocationTargetException"
+ " invoking "
+ setterMethod.getName(), ite);
throw new RuntimeException(ite);
} }
} catch (IllegalAccessException iae) { } catch (IllegalAccessException iae) {
log.error(OperationUtils.class.getName()+" encountered IllegalAccessException invoking "+beanMeths[i].getName()); log.error(OperationUtils.class.getName() +
".cloneBean() encountered " +
" IllegalAccessException invoking " +
beanMeths[i].getName(), iae);
throw new RuntimeException(iae);
} catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) {
log.error(OperationUtils.class.getName()+" encountered InvocationTargetException invoking "+beanMeths[i].getName()); log.error(OperationUtils.class.getName() +
log.error(ite.getTargetException().getClass().toString()); ".cloneBean() encountered " +
} catch (IllegalArgumentException iae) { " InvocationTargetException invoking " +
// log.error(OperationUtils.class.getName()+" found that "+beanMeths[i].getName()+" requires one or more arguments. Skipping."); beanMeths[i].getName(), ite);
throw new RuntimeException(ite);
} catch (IllegalArgumentException iae) {
log.error(OperationUtils.class.getName() +
".cloneBean() encountered " +
" IllegalArgumentException invoking " +
beanMeths[i].getName(), iae);
throw new RuntimeException(iae);
} }
} catch (NoSuchMethodException nsme){ } catch (NoSuchMethodException nsme){
// ignore this field because there is no setter method // ignore this field because there is no setter method

View file

@ -35,6 +35,9 @@ import org.apache.commons.logging.LogFactory;
* to a value like <code>/usr/local/vitro/stuff/deploy.properties</code> for a * to a value like <code>/usr/local/vitro/stuff/deploy.properties</code> for a
* file, or like <code>deploy.properties</code> for a resource in the classpath. * file, or like <code>deploy.properties</code> for a resource in the classpath.
* *
* When the properties file is loaded, the values are trimmed to remove leading
* or trailing white space, since such white space is almost always an error.
*
* @author jeb228 * @author jeb228
*/ */
public class ConfigurationProperties { public class ConfigurationProperties {
@ -144,7 +147,10 @@ public class ConfigurationProperties {
Map<String, String> newMap = new HashMap<String, String>(); Map<String, String> newMap = new HashMap<String, String>();
for (Enumeration<?> keys = props.keys(); keys.hasMoreElements();) { for (Enumeration<?> keys = props.keys(); keys.hasMoreElements();) {
String key = (String) keys.nextElement(); String key = (String) keys.nextElement();
newMap.put(key, props.getProperty(key)); String value = props.getProperty(key);
// While we're copying, remove leading and trailing white space.
String trimmed = value.trim();
newMap.put(key, trimmed);
} }
log.info("Configuration properties are: " + newMap); log.info("Configuration properties are: " + newMap);

View file

@ -130,6 +130,7 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory {
if (uri == null) { if (uri == null) {
log.debug("Could not find an Individual with a netId of " log.debug("Could not find an Individual with a netId of "
+ username); + username);
return null;
} }
Individual ind = indDao.getIndividualByURI(uri); Individual ind = indDao.getIndividualByURI(uri);

View file

@ -9,6 +9,8 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
/** /**
* Setups context so that Identifiers for Individuals associated with Users are * Setups context so that Identifiers for Individuals associated with Users are
* added to requests. * added to requests.
@ -22,6 +24,11 @@ public class UserToIndIdentifierFactorySetup implements ServletContextListener{
private static final Log log = LogFactory.getLog(UserToIndIdentifierFactorySetup.class.getName()); private static final Log log = LogFactory.getLog(UserToIndIdentifierFactorySetup.class.getName());
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
ServletContext sc = sce.getServletContext(); ServletContext sc = sce.getServletContext();
ServletIdentifierBundleFactory ServletIdentifierBundleFactory
.addIdentifierBundleFactory(sc, new UserToIndIdentifierFactory()); .addIdentifierBundleFactory(sc, new UserToIndIdentifierFactory());

View file

@ -115,6 +115,7 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com
String getImageUrl(); String getImageUrl();
String getThumbUrl(); String getThumbUrl();
boolean hasThumb();
String getUrl(); String getUrl();
void setUrl(String url); void setUrl(String url);

View file

@ -501,4 +501,8 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
return getURI() + " " + getName(); return getURI() + " " + getName();
} }
} }
public boolean hasThumb() {
return getThumbUrl() != null && ! getThumbUrl().isEmpty();
}
} }

View file

@ -51,27 +51,19 @@ public class Property extends BaseResourceBean {
* Sorts Property objects, by property rank, then alphanumeric. * Sorts Property objects, by property rank, then alphanumeric.
* @author bdc34 * @author bdc34
*/ */
public static class DisplayComparatorIgnoringPropertyGroup implements Comparator { public static class DisplayComparatorIgnoringPropertyGroup implements Comparator {
public int compare(Object o1, Object o2) { public int compare(Object o1, Object o2) {
//log.warn("starting property display comparator; ignoring group "); //log.warn("starting property display comparator; ignoring group ");
Property p1 = o1 == null ? null : (Property) o1; Property p1 = o1 == null ? null : (Property) o1;
Property p2 = o2 == null ? null : (Property) o2; Property p2 = o2 == null ? null : (Property) o2;
if (p1==null || p2==null) { if (p1==null || p2==null) {
log.error("Null property passed to DisplayComparatorIgnoringPropertyGroup");
return 0; return 0;
} }
//log.warn("comparing property "+p1.getLocalName()+" (rank "+determineDisplayRank(p1)+") to property "+p2.getLocalName()+" (rank "+determineDisplayRank(p2)+") ..."); //log.warn("comparing property "+p1.getLocalName()+" (rank "+determineDisplayRank(p1)+") to property "+p2.getLocalName()+" (rank "+determineDisplayRank(p2)+") ...");
int diff = determineDisplayRank(p1) - determineDisplayRank(p2); int diff = determineDisplayRank(p1) - determineDisplayRank(p2);
if (diff==0) { if (diff==0) {
String p1Str = p1.getLabel() == null ? p1.getURI() : p1.getLabel(); String p1Str = p1.getLabel() == null ? p1.getURI() : p1.getLabel();
if (p1.getLabel()==null) { String p2Str = p2.getLabel() == null ? p2.getURI() : p2.getLabel();
log.warn("null edit label for property "+p1.getURI());
}
String p2Str = p2.getLabel() == null ? p2.getURI() : p2.getLabel();
if (p2.getLabel() == null) {
log.warn("null edit label for property "+p2.getURI());
}
return p1Str.compareTo(p2Str); return p1Str.compareTo(p2Str);
} }
return diff; return diff;

View file

@ -110,7 +110,7 @@ public class EntityController extends VitroHttpServlet {
return; return;
} catch (Throwable e) { } catch (Throwable e) {
log.error(e); log.error(e, e);
req.setAttribute("javax.servlet.jsp.jspException",e); req.setAttribute("javax.servlet.jsp.jspException",e);
RequestDispatcher rd = req.getRequestDispatcher("/error.jsp"); RequestDispatcher rd = req.getRequestDispatcher("/error.jsp");
rd.forward(req, res); rd.forward(req, res);
@ -505,7 +505,14 @@ public class EntityController extends VitroHttpServlet {
String url = fileInfo.getBytestreamAliasUrl(); String url = fileInfo.getBytestreamAliasUrl();
log.debug("Alias URL for '" + entity.getURI() + "' is '" + url + "'"); log.debug("Alias URL for '" + entity.getURI() + "' is '" + url + "'");
return url;
if (entity.getURI().equals(url)) {
// Avoid a tight loop; if the alias URL is equal to the URI, then
// don't recognize it as a File Bytestream.
return null;
} else {
return url;
}
} }
private Model getRDF(Individual entity, OntModel contextModel, Model newModel, int recurseDepth ) { private Model getRDF(Individual entity, OntModel contextModel, Model newModel, int recurseDepth ) {

View file

@ -181,17 +181,23 @@ public class EntityListController extends VitroHttpServlet {
//execute lucene query for individuals of the specified type //execute lucene query for individuals of the specified type
IndexSearcher index = LuceneIndexFactory.getIndexSearcher(context); IndexSearcher index = LuceneIndexFactory.getIndexSearcher(context);
TopDocs docs = index.search(query, null, TopDocs docs = null;
try{
docs = index.search(query, null,
ENTITY_LIST_CONTROLLER_MAX_RESULTS, ENTITY_LIST_CONTROLLER_MAX_RESULTS,
new Sort(Entity2LuceneDoc.term.NAMEUNANALYZED)); new Sort(Entity2LuceneDoc.term.NAMELOWERCASE));
}catch(Throwable th){
if( docs == null ){ log.error("Could not run search. " + th.getMessage());
log.error("Search of lucene index returned null"); docs = null;
throw new ServletException("Search of lucene index returned null");
} }
if( docs == null )
throw new ServletException("Could not run search in EntityListController");
//get list of individuals for the search results //get list of individuals for the search results
int size = docs.totalHits; int size = docs.totalHits;
log.debug("Number of search results: " + size);
// don't get all the results, only get results for the requestedSize // don't get all the results, only get results for the requestedSize
List<Individual> individuals = new ArrayList<Individual>(INDIVIDUALS_PER_PAGE); List<Individual> individuals = new ArrayList<Individual>(INDIVIDUALS_PER_PAGE);
int individualsAdded = 0; int individualsAdded = 0;
@ -267,7 +273,7 @@ public class EntityListController extends VitroHttpServlet {
Query alphaQuery = null; Query alphaQuery = null;
if( alpha != null && !"".equals(alpha) && alpha.length() == 1){ if( alpha != null && !"".equals(alpha) && alpha.length() == 1){
alphaQuery = alphaQuery =
new PrefixQuery(new Term(Entity2LuceneDoc.term.NAMEUNANALYZED, alpha.toLowerCase())); new PrefixQuery(new Term(Entity2LuceneDoc.term.NAMELOWERCASE, alpha.toLowerCase()));
query.add(alphaQuery,BooleanClause.Occur.MUST); query.add(alphaQuery,BooleanClause.Occur.MUST);
} }

View file

@ -19,6 +19,15 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
@ -44,12 +53,15 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao;
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc;
import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneIndexFactory;
import edu.cornell.mannlib.vitro.webapp.web.ContentType; import edu.cornell.mannlib.vitro.webapp.web.ContentType;
public class EntityURLController extends VitroHttpServlet { public class EntityURLController extends VitroHttpServlet {
private static final Log log = LogFactory.getLog(EntityURLController.class.getName()); private static final Log log = LogFactory.getLog(EntityURLController.class.getName());
public static final int ENTITY_LIST_CONTROLLER_MAX_RESULTS = 30000;
public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
@ -84,21 +96,45 @@ public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOExc
return; return;
} }
List<Individual> inds = (List<Individual>)getServletContext().getAttribute("inds"); String classUri = (String) getServletContext().getAttribute("classuri");
Model model = ModelFactory.createDefaultModel(); BooleanQuery query = new BooleanQuery();
if(inds != null){ query.add(
System.out.println("Into the loop"); new TermQuery( new Term(Entity2LuceneDoc.term.RDFTYPE, classUri)),
Iterator<Individual> itr = (Iterator<Individual>)inds.iterator(); BooleanClause.Occur.MUST );
Individual ind = null;
Resource resource = null; IndexSearcher index = LuceneIndexFactory.getIndexSearcher(getServletContext());
while(itr.hasNext()){ TopDocs docs = index.search(query, null,
ind = itr.next(); ENTITY_LIST_CONTROLLER_MAX_RESULTS,
resource = ResourceFactory.createResource(ind.getURI()); new Sort(Entity2LuceneDoc.term.NAMELOWERCASE));
RDFNode node = (RDFNode) ResourceFactory.createResource((String) getServletContext().getAttribute("classuri"));
model.add(resource, RDF.type, node); if( docs == null ){
} log.error("Search of lucene index returned null");
} throw new ServletException("Search of lucene index returned null");
}
int ii = 0;
int size = docs.totalHits;
Resource resource = null;
RDFNode node = null;
Model model = ModelFactory.createDefaultModel();
while( ii < size ){
ScoreDoc hit = docs.scoreDocs[ii];
if (hit != null) {
Document doc = index.doc(hit.doc);
if (doc != null) {
String uri = doc.getField(Entity2LuceneDoc.term.URI).stringValue();
resource = ResourceFactory.createResource(uri);
node = (RDFNode) ResourceFactory.createResource(classUri);
model.add(resource, RDF.type, node);
} else {
log.warn("no document found for lucene doc id " + hit.doc);
}
} else {
log.debug("hit was null");
}
ii++;
}
String format = ""; String format = "";
if(contentType != null){ if(contentType != null){
if ( RDFXML_MIMETYPE.equals(contentType.getMediaType())) if ( RDFXML_MIMETYPE.equals(contentType.getMediaType()))

View file

@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.controller;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -573,53 +574,52 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
String path = context.getRealPath(FEDORA_PROPERTIES); String path = context.getRealPath(FEDORA_PROPERTIES);
try{ try{
InputStream in = new FileInputStream(new File( path )); InputStream in = new FileInputStream(new File( path ));
if( in == null ){ props.load( in );
log.error("No fedora.properties file found,"+ fedoraUrl = props.getProperty("fedoraUrl");
"it should be located at " + path); adminUser = props.getProperty("adminUser");
status.append("<h1>Fedora configuration failed.</h1>\n"); adminPassword = props.getProperty("adminPassword");
status.append("<p>No fedora.properties file found,"+ pidNamespace = props.getProperty("pidNamespace");
"it should be located at " + path + "</p>\n");
configured = false; if( fedoraUrl == null || adminUser == null || adminPassword == null ){
} else { if( fedoraUrl == null ){
props.load( in ); log.error("'fedoraUrl' not found in properties file");
fedoraUrl = props.getProperty("fedoraUrl"); status.append("<p>'fedoraUrl' not found in properties file.</p>\n");
adminUser = props.getProperty("adminUser");
adminPassword = props.getProperty("adminPassword");
pidNamespace = props.getProperty("pidNamespace");
if( fedoraUrl == null || adminUser == null || adminPassword == null ){
if( fedoraUrl == null ){
log.error("'fedoraUrl' not found in properties file");
status.append("<p>'fedoraUrl' not found in properties file.</p>\n");
}
if( adminUser == null ) {
log.error("'adminUser' was not found in properties file, the " +
"user name of the fedora admin is needed to access the " +
"fedora API-M services.");
status.append("<p>'adminUser' was not found in properties file, the " +
"user name of the fedora admin is needed to access the " +
"fedora API-M services.</p>\n");
}
if( adminPassword == null ){
log.error("'adminPassword' was not found in properties file, the " +
"admin password is needed to access the fedora API-M services.");
status.append("<p>'adminPassword' was not found in properties file, the " +
"admin password is needed to access the fedora API-M services.</p>\n");
}
if( pidNamespace == null ){
log.error("'pidNamespace' was not found in properties file, the " +
"PID namespace indicates which namespace to use when creating " +
"new fedor digital objects.");
status.append("<p>'pidNamespace' was not found in properties file, the " +
"PID namespace indicates which namespace to use when creating " +
"new fedor digital objects.</p>\n");
}
fedoraUrl = null; adminUser = null; adminPassword = null;
configured = false;
} else {
configured = true;
} }
if( adminUser == null ) {
log.error("'adminUser' was not found in properties file, the " +
"user name of the fedora admin is needed to access the " +
"fedora API-M services.");
status.append("<p>'adminUser' was not found in properties file, the " +
"user name of the fedora admin is needed to access the " +
"fedora API-M services.</p>\n");
}
if( adminPassword == null ){
log.error("'adminPassword' was not found in properties file, the " +
"admin password is needed to access the fedora API-M services.");
status.append("<p>'adminPassword' was not found in properties file, the " +
"admin password is needed to access the fedora API-M services.</p>\n");
}
if( pidNamespace == null ){
log.error("'pidNamespace' was not found in properties file, the " +
"PID namespace indicates which namespace to use when creating " +
"new fedor digital objects.");
status.append("<p>'pidNamespace' was not found in properties file, the " +
"PID namespace indicates which namespace to use when creating " +
"new fedor digital objects.</p>\n");
}
fedoraUrl = null; adminUser = null; adminPassword = null;
configured = false;
} else {
configured = true;
} }
}catch(FileNotFoundException e) {
log.error("No fedora.properties file found,"+
"it should be located at " + path);
status.append("<h1>Fedora configuration failed.</h1>\n");
status.append("<p>No fedora.properties file found,"+
"it should be located at " + path + "</p>\n");
configured = false;
return;
}catch(Exception ex){ }catch(Exception ex){
status.append("<p>Fedora configuration failed.</p>\n"); status.append("<p>Fedora configuration failed.</p>\n");
status.append("<p>Exception while loading" + path + "</p>\n"); status.append("<p>Exception while loading" + path + "</p>\n");

View file

@ -8,6 +8,7 @@ import java.io.Writer;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
@ -32,14 +33,18 @@ import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord; import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
/** /**
@ -60,22 +65,64 @@ public class JSONServlet extends VitroHttpServlet {
super.doGet(req, resp); super.doGet(req, resp);
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
if(vreq.getParameter("getEntitiesByVClass") != null ){ try{
if( vreq.getParameter("resultKey") == null) { if(vreq.getParameter("getEntitiesByVClass") != null ){
getEntitiesByVClass(req, resp); if( vreq.getParameter("resultKey") == null) {
getEntitiesByVClass(req, resp);
return;
} else {
getEntitiesByVClassContinuation( req, resp);
return;
}
}else if( vreq.getParameter("getN3EditOptionList") != null ){
doN3EditOptionList(req,resp);
return; return;
} else { }else if( vreq.getParameter("getLuceneIndividualsByVClass") != null ){
getEntitiesByVClassContinuation( req, resp); getLuceneIndividualsByVClass(req,resp);
return;
}else if( vreq.getParameter("getVClassesForVClassGroup") != null ){
getVClassesForVClassGroup(req,resp);
return; return;
} }
}else if( vreq.getParameter("getN3EditOptionList") != null ){ }catch(Exception ex){
doN3EditOptionList(req,resp); log.warn(ex,ex);
return; }
}else if( vreq.getParameter("getLuceneIndividualsByVClass") != null ){ }
getLuceneIndividualsByVClass(req,resp);
private void getVClassesForVClassGroup(HttpServletRequest req, HttpServletResponse resp) throws IOException, JSONException {
JSONObject map = new JSONObject();
VitroRequest vreq = new VitroRequest(req);
String vcgUri = vreq.getParameter("classgroupUri");
if( vcgUri == null ){
log.debug("no URI passed for classgroupUri");
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return; return;
} }
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(getServletContext());
VClassGroup vcg = vcgc.getGroup(vreq.getPortalId(), vcgUri);
if( vcg == null ){
log.debug("Could not find vclassgroup: " + vcgUri);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
ArrayList<JSONObject> classes = new ArrayList<JSONObject>(vcg.size());
for( VClass vc : vcg){
JSONObject vcObj = new JSONObject();
vcObj.put("name", vc.getName());
vcObj.put("URI", vc.getURI());
vcObj.put("entityCount", vc.getEntityCount());
classes.add(vcObj);
}
map.put("classes", classes);
map.put("classGroupName", vcg.getPublicName());
map.put("classGroupUri", vcg.getURI());
resp.setCharacterEncoding("UTF-8");
resp.setContentType("application/json;charset=UTF-8");
Writer writer = resp.getWriter();
writer.write(map.toString());
} }
private void getLuceneIndividualsByVClass( HttpServletRequest req, HttpServletResponse resp ){ private void getLuceneIndividualsByVClass( HttpServletRequest req, HttpServletResponse resp ){

View file

@ -2,9 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.controller; package edu.cornell.mannlib.vitro.webapp.controller;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,15 +23,13 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.dao.UserDao; import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
public class MailUsersServlet extends VitroHttpServlet { public class MailUsersServlet extends VitroHttpServlet {
//private static final Logger LOG = Logger.getLogger(ContactMailServlet.class); private static final Log log = LogFactory.getLog(MailUsersServlet.class);
public static HttpServletRequest request; public static HttpServletRequest request;
public static HttpServletRequest response; public static HttpServletRequest response;
@ -55,9 +51,9 @@ public class MailUsersServlet extends VitroHttpServlet {
private String getSmtpHostFromProperties() { private String getSmtpHostFromProperties() {
String host = ConfigurationProperties.getProperty("Vitro.smtpHost"); String host = ConfigurationProperties.getProperty("Vitro.smtpHost");
if (host != null && !host.equals("")) { if (host != null && !host.equals("")) {
//LOG.info("Found Vitro.smtpHost value of " + host); log.debug("Found Vitro.smtpHost value of " + host);
} else { } else {
System.out.println("No Vitro.smtpHost specified"); log.warn("No Vitro.smtpHost specified");
} }
return (host != null && host.length() > 0) ? host : null; return (host != null && host.length() > 0) ? host : null;
} }
@ -187,7 +183,7 @@ public class MailUsersServlet extends VitroHttpServlet {
try { try {
// Construct the message // Construct the message
MimeMessage msg = new MimeMessage( s ); MimeMessage msg = new MimeMessage( s );
//System.out.println("trying to send message from servlet"); log.debug("trying to send message from servlet");
// Set the from address // Set the from address
msg.setFrom( new InternetAddress( webuseremail )); msg.setFrom( new InternetAddress( webuseremail ));
@ -211,7 +207,7 @@ public class MailUsersServlet extends VitroHttpServlet {
// set the Date: header // set the Date: header
msg.setSentDate( new Date() ); msg.setSentDate( new Date() );
//System.out.println("sending from servlet"); log.debug("sending from servlet");
//if (!probablySpam) //if (!probablySpam)
Transport.send( msg ); // try to send the message via smtp - catch error exceptions Transport.send( msg ); // try to send the message via smtp - catch error exceptions
@ -219,20 +215,13 @@ public class MailUsersServlet extends VitroHttpServlet {
} catch (AddressException e) { } catch (AddressException e) {
status = "Please supply a valid email address."; status = "Please supply a valid email address.";
System.out.println("Error - status is " + status); log.debug("Error - status is " + status);
//outFile.println( status );
//outFile.println( e.getMessage() );
} catch (SendFailedException e) { } catch (SendFailedException e) {
status = "The system was unable to deliver your mail. Please try again later. [SEND FAILED]"; status = "The system was unable to deliver your mail. Please try again later. [SEND FAILED]";
System.out.println("Error - status is " + status); log.error("Error - status is " + status);
//outFile.println( status );
//outFile.println( e.getMessage() );
} catch (MessagingException e) { } catch (MessagingException e) {
status = "The system was unable to deliver your mail. Please try again later. [MESSAGING]"; status = "The system was unable to deliver your mail. Please try again later. [MESSAGING]";
System.out.println("Error - status is " + status); log.error("Error - status is " + status, e);
//outFile.println( status );
//outFile.println( e.getMessage() );
e.printStackTrace();
} }
//outFile.flush(); //outFile.flush();

View file

@ -55,13 +55,13 @@ public class TabController extends VitroHttpServlet {
if (leadingTab.getTabId()==portal.getRootTabId()) { if (leadingTab.getTabId()==portal.getRootTabId()) {
request.setAttribute("homePageRequested", "true"); request.setAttribute("homePageRequested", "true");
request.setAttribute("title", portal.getAppName()); request.setAttribute("title", portal.getAppName());
// This will break Datastar, but this may be gone by the time Datastar integrates new Vitro code
RequestDispatcher rd = request.getRequestDispatcher("/home"); RequestDispatcher rd = request.getRequestDispatcher("/home");
rd.forward(request, response); rd.forward(request, response);
return; return;
} }
else else {
request.setAttribute("title",leadingTab.getTitle()); request.setAttribute("title",leadingTab.getTitle());
}
String body = leadingTab.getBody(); String body = leadingTab.getBody();
if( body != null && body.startsWith("JSPBody:") ) if( body != null && body.startsWith("JSPBody:") )

View file

@ -247,10 +247,10 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
}else if( sortField.equalsIgnoreCase("sunset") ){ }else if( sortField.equalsIgnoreCase("sunset") ){
sort = new Sort(Entity2LuceneDoc.term.SUNSET); sort = new Sort(Entity2LuceneDoc.term.SUNSET);
}else{ }else{
sort = new Sort(Entity2LuceneDoc.term.NAMEUNANALYZED); sort = new Sort(Entity2LuceneDoc.term.NAMELOWERCASE);
} }
} else { } else {
sort = new Sort(Entity2LuceneDoc.term.NAMEUNANALYZED); sort = new Sort(Entity2LuceneDoc.term.NAMELOWERCASE);
} }
if( depth > 1 && "rand()".equalsIgnoreCase(sortField) ){ if( depth > 1 && "rand()".equalsIgnoreCase(sortField) ){
@ -426,24 +426,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
} }
typeQuery.add(tabQueries,BooleanClause.Occur.MUST); typeQuery.add(tabQueries,BooleanClause.Occur.MUST);
} }
} }
String flag2Set = tab.getFlag2Set();
if( tab.getFlag2Set() != null && ! tab.getFlag2Set().isEmpty()){
if( flag2Set != null && ! "".equals(flag2Set)){
BooleanQuery flag2Query = new BooleanQuery();
for( String flag2Value : flag2Set.split(",")){
if( flag2Value != null ){
String value = flag2Value.replace(",", "");
if(!value.isEmpty()){
flag2Query.add(new TermQuery(new Term(Entity2LuceneDoc.term.FLAG2,value)),
BooleanClause.Occur.SHOULD);
}
}
}
typeQuery.add(flag2Query, BooleanClause.Occur.MUST);
}
}
} }
//make query for manually linked individuals //make query for manually linked individuals
@ -482,7 +465,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
Query alphaQuery = null; Query alphaQuery = null;
if( alpha != null && !"".equals(alpha) && alpha.length() == 1){ if( alpha != null && !"".equals(alpha) && alpha.length() == 1){
alphaQuery = alphaQuery =
new PrefixQuery(new Term(Entity2LuceneDoc.term.NAMEUNANALYZED, alpha.toLowerCase())); new PrefixQuery(new Term(Entity2LuceneDoc.term.NAMELOWERCASE, alpha.toLowerCase()));
query.add(alphaQuery,BooleanClause.Occur.MUST); query.add(alphaQuery,BooleanClause.Occur.MUST);
} }
@ -539,7 +522,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
for(int page = 1; page < requiredPages && page <= MAX_PAGES ; page++ ){ for(int page = 1; page < requiredPages && page <= MAX_PAGES ; page++ ){
records.add( new PageRecord( "page=" + page, Integer.toString(page), Integer.toString(page), selectedPage == page ) ); records.add( new PageRecord( "page=" + page, Integer.toString(page), Integer.toString(page), selectedPage == page ) );
} }
records.add( new PageRecord( "page="+ MAX_PAGES+1, Integer.toString(MAX_PAGES+1), "more...", false)); records.add( new PageRecord( "page="+ (MAX_PAGES+1), Integer.toString(MAX_PAGES+1), "more...", false));
}else if( requiredPages > MAX_PAGES && selectedPage+1 > MAX_PAGES && selectedPage < requiredPages - MAX_PAGES){ }else if( requiredPages > MAX_PAGES && selectedPage+1 > MAX_PAGES && selectedPage < requiredPages - MAX_PAGES){
//the selected pages is in the middle of the list of page //the selected pages is in the middle of the list of page
int startPage = selectedPage - MAX_PAGES / 2; int startPage = selectedPage - MAX_PAGES / 2;

View file

@ -92,53 +92,65 @@ public class VitroHttpServlet extends HttpServlet {
HttpServletResponse response) { HttpServletResponse response) {
LogoutRedirector.recordRestrictedPageUri(request); LogoutRedirector.recordRestrictedPageUri(request);
if (LoginStatusBean.getBean(request).isLoggedIn()) { if (LoginStatusBean.getBean(request).isLoggedIn()) {
log.trace("Logged in. No minimum level.");
return true; return true;
} else { } else {
log.trace("Not logged in. No minimum level.");
redirectToLoginPage(request, response); redirectToLoginPage(request, response);
return false; return false;
} }
} }
/** /**
* If not logged in at the required level, redirect them to the appropriate page. * If not logged in at the required level, redirect them to the appropriate
* page.
*/ */
public static boolean checkLoginStatus(HttpServletRequest request, public static boolean checkLoginStatus(HttpServletRequest request,
HttpServletResponse response, int minimumLevel) { HttpServletResponse response, int minimumLevel) {
LogoutRedirector.recordRestrictedPageUri(request); LogoutRedirector.recordRestrictedPageUri(request);
if (LoginStatusBean.getBean(request).isLoggedInAtLeast(minimumLevel)) { LoginStatusBean statusBean = LoginStatusBean.getBean(request);
if (statusBean.isLoggedInAtLeast(minimumLevel)) {
log.trace("Security level " + statusBean.getSecurityLevel()
+ " is sufficient for minimum of " + minimumLevel);
return true; return true;
} else if (LoginStatusBean.getBean(request).isLoggedIn()) { } else if (statusBean.isLoggedIn()) {
log.trace("Security level " + statusBean.getSecurityLevel()
+ " is insufficient for minimum of " + minimumLevel);
redirectToInsufficientAuthorizationPage(request, response); redirectToInsufficientAuthorizationPage(request, response);
return false; return false;
} else { } else {
log.trace("Not logged in; not sufficient for minimum of "
+ minimumLevel);
redirectToLoginPage(request, response); redirectToLoginPage(request, response);
return false; return false;
} }
} }
/** /**
* Logged in, but with insufficent authorization. Send them to the * Logged in, but with insufficent authorization. Send them to the home page
* home page with a message. They won't be coming back. * with a message. They won't be coming back.
*/ */
private static void redirectToInsufficientAuthorizationPage( public static void redirectToInsufficientAuthorizationPage(
HttpServletRequest request, HttpServletResponse response) { HttpServletRequest request, HttpServletResponse response) {
try { try {
DisplayMessage.setMessage(request, INSUFFICIENT_AUTHORIZATION_MESSAGE); DisplayMessage.setMessage(request,
INSUFFICIENT_AUTHORIZATION_MESSAGE);
response.sendRedirect(request.getContextPath()); response.sendRedirect(request.getContextPath());
} catch (IOException e) { } catch (IOException e) {
log.error("Could not redirect to show insufficient authorization."); log.error("Could not redirect to show insufficient authorization.");
} }
} }
/** /**
* Not logged in. Send them to the login page, and then back to the page * Not logged in. Send them to the login page, and then back to the page
* that invoked this. * that invoked this.
*/ */
public static void redirectToLoginPage(HttpServletRequest request, public static void redirectToLoginPage(HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
String returnUrl = assembleUrlToReturnHere(request); String returnUrl = assembleUrlToReturnHere(request);
String loginUrlWithReturn = assembleLoginUrlWithReturn(request, returnUrl); String loginUrlWithReturn = assembleLoginUrlWithReturn(request,
returnUrl);
try { try {
response.sendRedirect(loginUrlWithReturn); response.sendRedirect(loginUrlWithReturn);
} catch (IOException ioe) { } catch (IOException ioe) {
@ -155,8 +167,8 @@ public class VitroHttpServlet extends HttpServlet {
} }
} }
private static String assembleLoginUrlWithReturn(HttpServletRequest request, private static String assembleLoginUrlWithReturn(
String afterLoginUrl) { HttpServletRequest request, String afterLoginUrl) {
String encodedAfterLoginUrl = afterLoginUrl; String encodedAfterLoginUrl = afterLoginUrl;
try { try {
encodedAfterLoginUrl = URLEncoder.encode(afterLoginUrl, "UTF-8"); encodedAfterLoginUrl = URLEncoder.encode(afterLoginUrl, "UTF-8");
@ -166,9 +178,10 @@ public class VitroHttpServlet extends HttpServlet {
return request.getContextPath() + Controllers.AUTHENTICATE return request.getContextPath() + Controllers.AUTHENTICATE
+ "?afterLogin=" + encodedAfterLoginUrl; + "?afterLogin=" + encodedAfterLoginUrl;
} }
/** /**
* If logging is set to the TRACE level, dump the HTTP headers on the request. * If logging is set to the TRACE level, dump the HTTP headers on the
* request.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@ -177,7 +190,8 @@ public class VitroHttpServlet extends HttpServlet {
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
HttpServletRequest request = (HttpServletRequest) req; HttpServletRequest request = (HttpServletRequest) req;
Enumeration<String> names = request.getHeaderNames(); Enumeration<String> names = request.getHeaderNames();
log.trace("----------------------request:" + request.getRequestURL()); log.trace("----------------------request:"
+ request.getRequestURL());
while (names.hasMoreElements()) { while (names.hasMoreElements()) {
String name = names.nextElement(); String name = names.nextElement();
if (!BORING_HEADERS.contains(name)) { if (!BORING_HEADERS.contains(name)) {
@ -194,5 +208,5 @@ public class VitroHttpServlet extends HttpServlet {
Arrays.asList(new String[] { "host", "user-agent", "accept", Arrays.asList(new String[] { "host", "user-agent", "accept",
"accept-language", "accept-encoding", "accept-charset", "accept-language", "accept-encoding", "accept-charset",
"keep-alive", "connection" })); "keep-alive", "connection" }));
} }

View file

@ -164,7 +164,7 @@ public class BasicAuthenticator extends Authenticator {
LoginStatusBean lsb = new LoginStatusBean(userUri, username, LoginStatusBean lsb = new LoginStatusBean(userUri, username,
securityLevel, authSource); securityLevel, authSource);
LoginStatusBean.setBean(session, lsb); LoginStatusBean.setBean(session, lsb);
log.info("Adding status bean: " + lsb); log.debug("Adding status bean: " + lsb);
} }
/** /**

View file

@ -0,0 +1,54 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* This sits in the session to say that a login is in process.
*
* Authenticate sets the flag each time it redirects to the login widget, and
* the login widget inspects the flag and resets it.
*
* If ever the login widget finds that the flag is already reset, it knows that
* the user navigated to the widget directly, rather than coming through
* Authenticate, and so it discards any existing LoginProcessBean as obsolete.
*/
public class LoginInProcessFlag {
private static final String ATTRIBUTE_NAME = LoginInProcessFlag.class
.getName();
/**
* Set the flag, saying that a login session is in process.
*/
public static void set(HttpServletRequest request) {
if (request == null) {
throw new NullPointerException("request may not be null.");
}
request.getSession().setAttribute(ATTRIBUTE_NAME, Boolean.TRUE);
}
/**
* Check to see whether the flag is set. Reset it.
*/
public static boolean checkAndReset(HttpServletRequest request) {
if (request == null) {
throw new NullPointerException("request may not be null.");
}
HttpSession session = request.getSession(false);
if (session == null) {
return false;
}
Object flag = session.getAttribute(ATTRIBUTE_NAME);
if (flag == null) {
return false;
}
session.removeAttribute(ATTRIBUTE_NAME);
return true;
}
}

View file

@ -34,6 +34,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginInProcessFlag;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.Message; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.Message;
@ -89,6 +90,9 @@ public class Authenticate extends VitroHttpServlet {
VitroRequest vreq = new VitroRequest(request); VitroRequest vreq = new VitroRequest(request);
try { try {
if (loginProcessIsRestarting(vreq)) {
LoginProcessBean.removeBean(vreq);
}
if (loginProcessPagesAreEmpty(vreq)) { if (loginProcessPagesAreEmpty(vreq)) {
recordLoginProcessPages(vreq); recordLoginProcessPages(vreq);
} }
@ -138,6 +142,23 @@ public class Authenticate extends VitroHttpServlet {
} }
/**
* The after-login page or the return flag are supplied only on the first
* step in the process. If we see either of them, we conclude that the user
* has re-started the login.
*/
private boolean loginProcessIsRestarting(HttpServletRequest request) {
if (isAfterLoginParameterSet(request)) {
log.debug("after-login parameter is set: restarting the login.");
return true;
}
if (isReturnParameterSet(request)) {
log.debug("return parameter is set: restarting the login.");
return true;
}
return false;
}
/** /**
* Once these URLs have been set, don't change them. * Once these URLs have been set, don't change them.
*/ */
@ -191,6 +212,10 @@ public class Authenticate extends VitroHttpServlet {
} }
} }
private boolean isAfterLoginParameterSet(HttpServletRequest request) {
return (null != request.getParameter(PARAMETER_AFTER_LOGIN));
}
private boolean isReturnParameterSet(HttpServletRequest request) { private boolean isReturnParameterSet(HttpServletRequest request) {
return (null != request.getParameter(PARAMETER_RETURN)); return (null != request.getParameter(PARAMETER_RETURN));
} }
@ -451,6 +476,8 @@ public class Authenticate extends VitroHttpServlet {
throws IOException { throws IOException {
log.debug("logging in."); log.debug("logging in.");
LoginInProcessFlag.set(vreq);
String loginProcessPage = LoginProcessBean.getBean(vreq) String loginProcessPage = LoginProcessBean.getBean(vreq)
.getLoginPageUrl(); .getLoginPageUrl();
response.sendRedirect(loginProcessPage); response.sendRedirect(loginProcessPage);

View file

@ -1,56 +1,56 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.edit; package edu.cornell.mannlib.vitro.webapp.controller.edit;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections.map.ListOrderedMap; import org.apache.commons.collections.map.ListOrderedMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.beans.DynamicField; import edu.cornell.mannlib.vedit.beans.DynamicField;
import edu.cornell.mannlib.vedit.beans.DynamicFieldRow; import edu.cornell.mannlib.vedit.beans.DynamicFieldRow;
import edu.cornell.mannlib.vedit.beans.EditProcessObject; import edu.cornell.mannlib.vedit.beans.EditProcessObject;
import edu.cornell.mannlib.vedit.beans.FormObject; import edu.cornell.mannlib.vedit.beans.FormObject;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vedit.beans.Option; import edu.cornell.mannlib.vedit.beans.Option;
import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vedit.forwarder.PageForwarder; import edu.cornell.mannlib.vedit.forwarder.PageForwarder;
import edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder; import edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder;
import edu.cornell.mannlib.vedit.util.FormUtils; import edu.cornell.mannlib.vedit.util.FormUtils;
import edu.cornell.mannlib.vedit.validator.impl.RequiredFieldValidator; import edu.cornell.mannlib.vedit.validator.impl.RequiredFieldValidator;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.edit.utils.RoleLevelOptionsSetup; import edu.cornell.mannlib.vitro.webapp.controller.edit.utils.RoleLevelOptionsSetup;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.listener.impl.IndividualDataPropertyStatementProcessor; import edu.cornell.mannlib.vitro.webapp.edit.listener.impl.IndividualDataPropertyStatementProcessor;
public class EntityRetryController extends BaseEditController { public class EntityRetryController extends BaseEditController {
@ -86,7 +86,7 @@ public class EntityRetryController extends BaseEditController {
WebappDaoFactory wadf = (vreq.getAssertionsWebappDaoFactory()!=null) ? vreq.getAssertionsWebappDaoFactory() : vreq.getFullWebappDaoFactory(); WebappDaoFactory wadf = (vreq.getAssertionsWebappDaoFactory()!=null) ? vreq.getAssertionsWebappDaoFactory() : vreq.getFullWebappDaoFactory();
LoginStatusBean loginBean = LoginStatusBean.getBean(request); LoginStatusBean loginBean = LoginStatusBean.getBean(request);
WebappDaoFactory myWebappDaoFactory = wadf.getUserAwareDaoFactory(loginBean.getUserURI()); WebappDaoFactory myWebappDaoFactory = wadf.getUserAwareDaoFactory(loginBean.getUserURI());
IndividualDao ewDao = myWebappDaoFactory.getIndividualDao(); IndividualDao ewDao = myWebappDaoFactory.getIndividualDao();
@ -326,7 +326,8 @@ public class EntityRetryController extends BaseEditController {
request.setAttribute("title","Individual Editing Form"); request.setAttribute("title","Individual Editing Form");
request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+portal.getThemeDir()+"css/edit.css\"/>"); request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+portal.getThemeDir()+"css/edit.css\"/>");
request.setAttribute("scripts", "/js/edit/entityRetry.js"); request.setAttribute("scripts", "/js/edit/entityRetry.js");
request.setAttribute("bodyAttr"," onLoad=\"monikerInit()\""); // NC Commenting this out for now. Going to pass on DWR for moniker and use jQuery instead
// request.setAttribute("bodyAttr"," onLoad=\"monikerInit()\"");
request.setAttribute("_action",action); request.setAttribute("_action",action);
request.setAttribute("unqualifiedClassName","Individual"); request.setAttribute("unqualifiedClassName","Individual");
setRequestAttributes(request,epo); setRequestAttributes(request,epo);
@ -339,24 +340,24 @@ public class EntityRetryController extends BaseEditController {
log.error(e.getStackTrace()); log.error(e.getStackTrace());
} }
} }
private List<Option> getMonikerOptionsList(Individual entity, private List<Option> getMonikerOptionsList(Individual entity,
IndividualDao indDao) { IndividualDao indDao) {
ArrayList<Option> monikerOpts = new ArrayList<Option>(); ArrayList<Option> monikerOpts = new ArrayList<Option>();
monikerOpts.add(new Option("", "none", (entity.getMoniker() == null))); monikerOpts.add(new Option("", "none", (entity.getMoniker() == null)));
if (entity.getVClassURI() != null) { if (entity.getVClassURI() != null) {
List<String> monikers = indDao.monikers(entity.getVClassURI()); List<String> monikers = indDao.monikers(entity.getVClassURI());
if (monikers != null) { if (monikers != null) {
for (String moniker : monikers) { for (String moniker : monikers) {
monikerOpts.add(new Option( monikerOpts.add(new Option(
moniker, moniker, moniker, moniker,
moniker.equals(entity.getMoniker()))); moniker.equals(entity.getMoniker())));
} }
} }
} }
monikerOpts.add(new Option("", "[new moniker]")); monikerOpts.add(new Option("", "[new moniker]"));
return monikerOpts; return monikerOpts;
} }
public void doGet (HttpServletRequest request, HttpServletResponse response) { public void doGet (HttpServletRequest request, HttpServletResponse response) {

View file

@ -135,16 +135,17 @@ public class N3MultiPartUpload extends VitroHttpServlet {
EditConfiguration editConfig = EditConfiguration.getConfigFromSession( EditConfiguration editConfig = EditConfiguration.getConfigFromSession(
session, request); session, request);
if (editConfig == null) {
RequestDispatcher rd = request
.getRequestDispatcher("/edit/messages/noEditConfigFound.jsp");
rd.forward(request, resp);
return;
}
EditSubmission submission = EditSubmission submission =
new EditSubmission(request.getParameterMap(), editConfig, request.getFiles()); new EditSubmission(request.getParameterMap(), editConfig, request.getFiles());
EditN3Generator n3Subber = editConfig.getN3Generator(); EditN3Generator n3Subber = editConfig.getN3Generator();
if (editConfig == null) {
RequestDispatcher rd = request
.getRequestDispatcher("/edit/messages/noEditConfigFound.jsp");
rd.forward(request, resp);
}
// check for form validation errors // check for form validation errors
Map<String, String> errors = submission.getValidationErrors(); Map<String, String> errors = submission.getValidationErrors();
EditSubmission.putEditSubmissionInSession(session, submission); EditSubmission.putEditSubmissionInSession(session, submission);

View file

@ -64,7 +64,7 @@ public class PortalRetryController extends BaseEditController {
if (!epo.getUseRecycledBean()){ if (!epo.getUseRecycledBean()){
if (request.getParameter("id") != null) { if (request.getParameter("id") != null) {
int id = Integer.parseInt(request.getParameter("id")); int id = Integer.parseInt(request.getParameter("id"));
if (id > 0) { if (id >= 0) {
try { try {
portalForEditing = (Portal)pDao.getPortal(id); portalForEditing = (Portal)pDao.getPortal(id);
action = "update"; action = "update";

View file

@ -67,7 +67,7 @@ public class Properties2PropertiesOperationController extends
try { try {
response.sendRedirect(defaultLandingPage); response.sendRedirect(defaultLandingPage);
} catch (IOException e) { } catch (IOException e) {
log.error(e); log.error(e, e);
} }
return; return;
} }

View file

@ -249,6 +249,9 @@ public class RefactorOperationController extends BaseEditController {
ontModel.leaveCriticalSection(); ontModel.leaveCriticalSection();
} }
// there are no statements to delete, but we want indexes updated appropriately
request.getFullWebappDaoFactory().getIndividualDao().deleteIndividual(oldURIStr);
String redirectStr = null; String redirectStr = null;
/* we can't go back to the referer, because the URI is now different. */ /* we can't go back to the referer, because the URI is now different. */

View file

@ -175,10 +175,11 @@ public class UserRetryController extends BaseEditController {
request.setAttribute("formOnSubmit", "return validatePw(this);"); request.setAttribute("formOnSubmit", "return validatePw(this);");
request.setAttribute("formOnCancel", "forceCancel(this.form);"); request.setAttribute("formOnCancel", "forceCancel(this.form);");
} }
else { else {
request.setAttribute("formOnSubmit", "return validateUserFields(this);"); request.setAttribute("formOnSubmit", "return validateUserFields(this);");
request.setAttribute("formOnCancel", "forceCancel(this.form);"); request.setAttribute("formOnCancel", "forceCancelTwo(this.form);");
} }
request.setAttribute("formJsp","/templates/edit/specific/user_retry.jsp"); request.setAttribute("formJsp","/templates/edit/specific/user_retry.jsp");
request.setAttribute("scripts","/templates/edit/specific/user_retry_head.jsp"); request.setAttribute("scripts","/templates/edit/specific/user_retry_head.jsp");
request.setAttribute("title","User Account Editing Form"); request.setAttribute("title","User Account Editing Form");

View file

@ -43,56 +43,51 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateMo
public class BrowseController extends FreemarkerHttpServlet { public class BrowseController extends FreemarkerHttpServlet {
static final long serialVersionUID=2006030721126L; static final long serialVersionUID=2006030721126L;
private static final Log log = LogFactory.getLog(BrowseController.class); private static final Log log = LogFactory.getLog(BrowseController.class);
private static final String TEMPLATE_DEFAULT = "classGroups.ftl"; private static final String TEMPLATE_DEFAULT = "classGroups.ftl";
@Override @Override
protected String getTitle(String siteName, VitroRequest vreq) { protected String getTitle(String siteName, VitroRequest vreq) {
return "Index to " + siteName + " Contents"; return "Index of Contents";
} }
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
String message = null; String message = null;
String templateName = TEMPLATE_DEFAULT; String templateName = TEMPLATE_DEFAULT;
if( vreq.getParameter("clearcache") != null ) //mainly for debugging if ( vreq.getParameter("clearcache") != null ) //mainly for debugging
clearGroupCache(); clearGroupCache();
int portalId = vreq.getPortalId(); int portalId = vreq.getPortalId();
List<VClassGroup> groups = null; List<VClassGroup> groups = null;
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(getServletContext()); VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(getServletContext());
if( vcgc == null ){ if ( vcgc == null ) {
log.error("Could not get VClassGroupCache"); log.error("Could not get VClassGroupCache");
message = "The system is not configured correctly. Please check your logs for error messages."; message = "The system is not configured correctly. Please check your logs for error messages.";
}else{ } else {
groups =vcgc.getGroups( vreq.getPortalId()); groups =vcgc.getGroups( vreq.getPortalId());
if (groups == null || groups.isEmpty()) { List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size());
message = "There are not yet any items in the system."; for (VClassGroup group : groups) {
vcgroups.add(new VClassGroupTemplateModel(group));
} }
else { body.put("classGroups", vcgroups);
List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size()); }
for (VClassGroup group : groups) {
vcgroups.add(new VClassGroupTemplateModel(group)); if (message != null) {
} body.put("message", message);
body.put("classGroups", vcgroups); templateName = Template.TITLED_MESSAGE.toString();
} }
}
if (message != null) {
body.put("message", message);
templateName = Template.TITLED_MESSAGE.toString();
}
return new TemplateResponseValues(templateName, body); return new TemplateResponseValues(templateName, body);
} }
protected void clearGroupCache(){ protected void clearGroupCache(){
VClassGroupCache.getVClassGroupCache(getServletContext()).clearGroupCache(); VClassGroupCache.getVClassGroupCache(getServletContext()).clearGroupCache();
} }
} }

View file

@ -163,4 +163,4 @@ public class FreemarkerConfigurationLoader {
} }
} }

View file

@ -34,6 +34,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils; import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil; import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil;
import edu.cornell.mannlib.vitro.webapp.web.PortalWebUtil; import edu.cornell.mannlib.vitro.webapp.web.PortalWebUtil;
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.User; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.User;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Scripts; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Scripts;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Stylesheets; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Stylesheets;
@ -49,8 +50,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(FreemarkerHttpServlet.class); private static final Log log = LogFactory.getLog(FreemarkerHttpServlet.class);
public static final String PAGE_TEMPLATE_TYPE = "page"; public static final String PAGE_TEMPLATE_TYPE = "page";
public static final String BODY_TEMPLATE_TYPE = "body"; public static final String BODY_TEMPLATE_TYPE = "body";
@ -242,16 +242,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
// Define the URLs that are accessible to the templates. Note that we do not create menus here, // Define the URLs that are accessible to the templates. Note that we do not create menus here,
// because we want the templates to be free to define the link text and where the links are displayed. // because we want the templates to be free to define the link text and where the links are displayed.
private final Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder) { private final Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder, VitroRequest vreq) {
// The urls that are accessible to the templates.
// NB We are not using our menu object mechanism to build menus here, because we want the
// view to control which links go where, and the link text and title.
Map<String, String> urls = new HashMap<String, String>(); Map<String, String> urls = new HashMap<String, String>();
urls.put("home", urlBuilder.getHomeUrl()); urls.put("home", urlBuilder.getHomeUrl());
// Templates use this to construct urls. // Templates use this to construct urls.
urls.put("base", urlBuilder.contextPath); urls.put("base", UrlBuilder.contextPath);
urls.put("about", urlBuilder.getPortalUrl(Route.ABOUT)); urls.put("about", urlBuilder.getPortalUrl(Route.ABOUT));
if (ContactMailServlet.getSmtpHostFromProperties() != null) { if (ContactMailServlet.getSmtpHostFromProperties() != null) {
@ -264,13 +261,24 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN)); urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN));
urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons")); // deprecated urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons")); // deprecated
urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images")); urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images"));
urls.put("images", urlBuilder.getUrl("/images")); urls.put("images", UrlBuilder.getUrl("/images"));
urls.put("theme", urlBuilder.getUrl(themeDir)); urls.put("theme", UrlBuilder.getUrl(themeDir));
urls.put("index", urlBuilder.getUrl("/browse")); urls.put("index", UrlBuilder.getUrl("/browse"));
urls.put("currentPage", getCurrentPageUrl(vreq));
return urls; return urls;
} }
private String getCurrentPageUrl(HttpServletRequest request) {
String path = request.getServletPath().replaceFirst("/", "");
String pathInfo = request.getPathInfo();
if (pathInfo != null) {
path += pathInfo;
}
path = normalizeServletName(path);
return UrlBuilder.getUrl(path);
}
protected BeansWrapper getNonDefaultBeansWrapper(int exposureLevel) { protected BeansWrapper getNonDefaultBeansWrapper(int exposureLevel) {
BeansWrapper wrapper = new DefaultObjectWrapper(); BeansWrapper wrapper = new DefaultObjectWrapper();
// Too bad exposure levels are ints instead of enum values; what happens if // Too bad exposure levels are ints instead of enum values; what happens if
@ -312,7 +320,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
* Add any Java directives the templates should have access to. * Add any Java directives the templates should have access to.
* This is public and static so that these may be used by other classes during * This is public and static so that these may be used by other classes during
* the transition from JSP to Freemarker. * the transition from JSP to Freemarker.
* @return
*/ */
public static Map<String, Object> getDirectives() { public static Map<String, Object> getDirectives() {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
@ -325,9 +332,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
return map; return map;
} }
protected Map<String, Object> getMethods() { public static Map<String, Object> getMethods() {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("profileUrl", new edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod()); map.put("profileUrl", new edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod());
map.put("localName", new edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod());
return map; return map;
} }
@ -353,14 +361,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
String themeDir = getThemeDir(portal); String themeDir = getThemeDir(portal);
UrlBuilder urlBuilder = new UrlBuilder(portal); UrlBuilder urlBuilder = new UrlBuilder(portal);
map.put("urls", getUrls(themeDir, urlBuilder)); map.put("urls", getUrls(themeDir, urlBuilder, vreq));
map.put("themeDir", themeDir); map.put("themeDir", themeDir);
map.put("currentTheme", themeDir.substring(themeDir.lastIndexOf('/')+1));
map.put("stylesheets", getStylesheetList(themeDir)); map.put("stylesheets", getStylesheetList(themeDir));
map.put("scripts", getScriptList(themeDir)); map.put("scripts", getScriptList(themeDir));
map.put("headScripts", getScriptList(themeDir)); map.put("headScripts", getScriptList(themeDir));
map.put("currentPage", vreq.getServletPath().replaceFirst("/", ""));
map.putAll(getDirectives()); map.putAll(getDirectives());
map.putAll(getMethods()); map.putAll(getMethods());
@ -393,14 +400,21 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
map.put("flash", flashMessage); map.put("flash", flashMessage);
} }
// Let the page template know which page it's processing. // Let the page template know which page it's processing.
map.put("currentPage", vreq.getServletPath().replaceFirst("/", "")); map.put("currentServlet", normalizeServletName(vreq.getServletPath().replaceFirst("/", "")));
// Allow template to send domain name to JavaScript (needed for AJAX calls) // Allow template to send domain name to JavaScript (needed for AJAX calls)
map.put("requestedPage", vreq.getRequestURL().toString()); map.put("requestedPage", vreq.getRequestURL().toString());
return map; return map;
} }
private String normalizeServletName(String name) {
// Return a uniform value for the home page.
// Note that if servletName is "index.jsp", it must be the home page,
// since we don't get here on other tabs.
return (name.length() == 0 || name.equals("index.jsp")) ? "home" : name;
}
private TabMenu getTabMenu(VitroRequest vreq) { private TabMenu getTabMenu(VitroRequest vreq) {
int portalId = vreq.getPortal().getPortalId(); int portalId = vreq.getPortal().getPortalId();

View file

@ -11,6 +11,7 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
import freemarker.template.Configuration; import freemarker.template.Configuration;
@ -20,6 +21,10 @@ public class FreemarkerSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) { public void contextInitialized(ServletContextEvent event) {
if (AbortStartup.isStartupAborted(event.getServletContext())) {
return;
}
ServletContext sc = event.getServletContext(); ServletContext sc = event.getServletContext();
sc.setAttribute("themeToConfigMap", new HashMap<String, Configuration>()); sc.setAttribute("themeToConfigMap", new HashMap<String, Configuration>());
BaseTemplateModel.setServletContext(sc); BaseTemplateModel.setServletContext(sc);

View file

@ -9,6 +9,8 @@ import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.beans.Tab;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
@ -44,11 +46,20 @@ public class HomePageController extends FreemarkerHttpServlet {
if(pageData != null) if(pageData != null)
body.putAll(pageData); body.putAll(pageData);
} }
// Get the home tab content for themes that display deprecated tabs
body.put("homeTabContent", getHomeTabContent(vreq));
// Add home page data to body here
return new TemplateResponseValues(BODY_TEMPLATE, body); return new TemplateResponseValues(BODY_TEMPLATE, body);
} }
// Get the home tab content for themes that display deprecated tabs
private String getHomeTabContent(VitroRequest vreq) {
Portal portal = vreq.getPortal();
int tabId = portal.getRootTabId();
Tab tab = vreq.getWebappDaoFactory().getTabDao().getTab(tabId,0,vreq.getAppBean());
return tab.getBody();
}
@Override @Override
protected String getTitle(String siteName, VitroRequest vreq) { protected String getTitle(String siteName, VitroRequest vreq) {

View file

@ -53,8 +53,9 @@ public class ImageUploadController extends FreemarkerHttpServlet {
private static final String DEFAULT_NAMESPACE = ConfigurationProperties private static final String DEFAULT_NAMESPACE = ConfigurationProperties
.getProperty("Vitro.defaultNamespace"); .getProperty("Vitro.defaultNamespace");
public static final String DUMMY_THUMBNAIL_URL = "/images/placeholders/person.thumbnail.jpg"; public static final String DUMMY_THUMBNAIL_PERSON_URL = "/images/placeholders/person.thumbnail.jpg";
public static final String DUMMY_THUMBNAIL_NON_PERSON_URL = "/images/placeholders/non.person.thumbnail.jpg";
/** Limit file size to 6 megabytes. */ /** Limit file size to 6 megabytes. */
public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024; public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024;
@ -389,7 +390,14 @@ public class ImageUploadController extends FreemarkerHttpServlet {
entity.getURI()); entity.getURI());
TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_NEW); TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_NEW);
rv.put(BODY_THUMBNAIL_URL, UrlBuilder.getUrl(DUMMY_THUMBNAIL_URL));
// rjy7 We should not be referencing particular ontology values here, and ideally
// the template would add the placeholder url to the edit link, since it already
// knows which placeholder it's using. However, this requires a significantly more
// complex implementation, so keeping it simple for now.
String dummyThumbnailUrl = entity.isVClass("http://xmlns.com/foaf/0.1/Person") ?
DUMMY_THUMBNAIL_PERSON_URL : DUMMY_THUMBNAIL_NON_PERSON_URL;
rv.put(BODY_THUMBNAIL_URL, UrlBuilder.getUrl(dummyThumbnailUrl));
rv.put(BODY_FORM_ACTION, formAction); rv.put(BODY_FORM_ACTION, formAction);
rv.put(BODY_CANCEL_URL, cancelUrl); rv.put(BODY_CANCEL_URL, cancelUrl);
rv.put(BODY_TITLE, "Upload image" + forName(entity)); rv.put(BODY_TITLE, "Upload image" + forName(entity));

View file

@ -30,7 +30,7 @@ import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
@ -47,17 +47,16 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Res
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery; import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
import edu.cornell.mannlib.vitro.webapp.web.ContentType; import edu.cornell.mannlib.vitro.webapp.web.ContentType;
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod; import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel;
import freemarker.ext.beans.BeansWrapper; import freemarker.ext.beans.BeansWrapper;
@ -124,6 +123,7 @@ public class IndividualController extends FreemarkerHttpServlet {
body.put("title", individual.getName()); body.put("title", individual.getName());
body.put("relatedSubject", getRelatedSubject(vreq)); body.put("relatedSubject", getRelatedSubject(vreq));
body.put("namespaces", namespaces); body.put("namespaces", namespaces);
body.put("temporalVisualizationEnabled", getTemporalVisualizationFlag());
IndividualTemplateModel itm = getIndividualTemplateModel(vreq, individual); IndividualTemplateModel itm = getIndividualTemplateModel(vreq, individual);
/* We need to expose non-getters in displaying the individual's property list, /* We need to expose non-getters in displaying the individual's property list,
@ -132,15 +132,14 @@ public class IndividualController extends FreemarkerHttpServlet {
* into the data model: no real data can be modified. * into the data model: no real data can be modified.
*/ */
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(itm)); body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(itm));
body.put("headContent", getRdfLinkTag(itm)); body.put("headContent", getRdfLinkTag(itm));
body.put("localName", new IndividualLocalNameMethod());
String template = getIndividualTemplate(individual); String template = getIndividualTemplate(individual, vreq);
return new TemplateResponseValues(template, body); return new TemplateResponseValues(template, body);
} catch (Throwable e) { } catch (Throwable e) {
log.error(e); log.error(e, e);
return new ExceptionResponseValues(e); return new ExceptionResponseValues(e);
} }
} }
@ -205,35 +204,37 @@ public class IndividualController extends FreemarkerHttpServlet {
// Determine whether the individual has a custom display template based on its class membership. // Determine whether the individual has a custom display template based on its class membership.
// If not, return the default individual template. // If not, return the default individual template.
private String getIndividualTemplate(Individual individual) { private String getIndividualTemplate(Individual individual, VitroRequest vreq) {
@SuppressWarnings("unused") @SuppressWarnings("unused")
String vclassName = "unknown"; String vclassName = "unknown";
String customTemplate = null; String customTemplate = null;
if( individual.getVClass() != null ){ // First check vclass
if( individual.getVClass() != null ){
vclassName = individual.getVClass().getName(); vclassName = individual.getVClass().getName();
List<VClass> clasList = individual.getVClasses(true); List<VClass> directClasses = individual.getVClasses(true);
for (VClass clas : clasList) { for (VClass vclass : directClasses) {
customTemplate = clas.getCustomDisplayView(); customTemplate = vclass.getCustomDisplayView();
if (customTemplate != null) { if (customTemplate != null) {
if (customTemplate.length()>0) { if (customTemplate.length()>0) {
vclassName = clas.getName(); // reset entity vclassname to name of class where a custom view; this call has side-effects vclassName = vclass.getName(); // reset entity vclassname to name of class where a custom view; this call has side-effects
log.debug("Found direct class [" + clas.getName() + "] with custom view " + customTemplate + "; resetting entity vclassName to this class"); log.debug("Found direct class [" + vclass.getName() + "] with custom view " + customTemplate + "; resetting entity vclassName to this class");
break; break;
} else { } else {
customTemplate = null; customTemplate = null;
} }
} }
} }
if (customTemplate == null) { //still // If no custom template defined, check other vclasses
clasList = individual.getVClasses(false); if (customTemplate == null) {
for (VClass clas : clasList) { List<VClass> inferredClasses = individual.getVClasses(false);
customTemplate = clas.getCustomDisplayView(); for (VClass vclass : inferredClasses) {
customTemplate = vclass.getCustomDisplayView();
if (customTemplate != null) { if (customTemplate != null) {
if (customTemplate.length()>0) { if (customTemplate.length()>0) {
// note that NOT changing entity vclassName here yet // note that NOT changing entity vclassName here yet
log.debug("Found inferred class [" + clas.getName() + "] with custom view " + customTemplate); log.debug("Found inferred class [" + vclass.getName() + "] with custom view " + customTemplate);
break; break;
} else { } else {
customTemplate = null; customTemplate = null;
@ -241,6 +242,28 @@ public class IndividualController extends FreemarkerHttpServlet {
} }
} }
} }
// If still no custom template defined, and inferencing is asynchronous (under RDB), check
// the superclasses of the vclass for a custom template specification.
if (customTemplate == null && SimpleReasoner.isABoxReasoningAsynchronous(getServletContext())) {
log.debug("Checking superclasses for custom template specification because ABox reasoning is asynchronous");
for (VClass directVClass : directClasses) {
VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao();
List<String> superClassUris = vcDao.getAllSuperClassURIs(directVClass.getURI());
for (String uri : superClassUris) {
VClass vclass = vcDao.getVClassByURI(uri);
customTemplate = vclass.getCustomDisplayView();
if (customTemplate != null) {
if (customTemplate.length()>0) {
// note that NOT changing entity vclassName here
log.debug("Found superclass [" + vclass.getName() + "] with custom view " + customTemplate);
break;
} else {
customTemplate = null;
}
}
}
}
}
} else if (individual.getVClassURI() != null) { } else if (individual.getVClassURI() != null) {
log.debug("Individual " + individual.getURI() + " with class URI " + log.debug("Individual " + individual.getURI() + " with class URI " +
individual.getVClassURI() + ": no class found with that URI"); individual.getVClassURI() + ": no class found with that URI");
@ -515,9 +538,21 @@ public class IndividualController extends FreemarkerHttpServlet {
String url = fileInfo.getBytestreamAliasUrl(); String url = fileInfo.getBytestreamAliasUrl();
log.debug("Alias URL for '" + entity.getURI() + "' is '" + url + "'"); log.debug("Alias URL for '" + entity.getURI() + "' is '" + url + "'");
return url;
if (entity.getURI().equals(url)) {
// Avoid a tight loop; if the alias URL is equal to the URI, then
// don't recognize it as a File Bytestream.
return null;
} else {
return url;
}
} }
private boolean getTemporalVisualizationFlag() {
String property = ConfigurationProperties.getProperty("visualization.temporal");
return ! "disabled".equals(property);
}
private Model getRDF(Individual entity, OntModel contextModel, Model newModel, int recurseDepth ) { private Model getRDF(Individual entity, OntModel contextModel, Model newModel, int recurseDepth ) {
Resource subj = newModel.getResource(entity.getURI()); Resource subj = newModel.getResource(entity.getURI());

View file

@ -106,7 +106,6 @@ public class IndividualListController extends FreemarkerHttpServlet {
} }
body.put("title", title); body.put("title", title);
body.put("redirecturl", vreq.getContextPath()+"/entityurl/"); body.put("redirecturl", vreq.getContextPath()+"/entityurl/");
getServletContext().setAttribute("inds", inds);
getServletContext().setAttribute("classuri", vclass.getURI()); getServletContext().setAttribute("classuri", vclass.getURI());
} }

View file

@ -35,6 +35,7 @@ public class MenuN3EditController extends FreemarkerHttpServlet {
menuN3 = vreq.getWebappDaoFactory().getDisplayModelDao() menuN3 = vreq.getWebappDaoFactory().getDisplayModelDao()
.getDisplayModel(getServletContext()); .getDisplayModel(getServletContext());
data.put("menuN3", menuN3); data.put("menuN3", menuN3);
data.put("cancelUrl", "/siteAdmin");
} catch (Exception e) { } catch (Exception e) {
data.put("errorMessage",e.getMessage()); data.put("errorMessage",e.getMessage());
} }

View file

@ -30,7 +30,7 @@ import com.hp.hpl.jena.rdf.model.StmtIterator;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import freemarker.template.Configuration; import freemarker.template.Configuration;
public class NavigationController extends FreemarkerHttpServlet { public class NavigationController extends FreemarkerHttpServlet {

View file

@ -70,7 +70,7 @@ public class PageController extends FreemarkerHttpServlet{
ResponseValues rv = new TemplateResponseValues(getTemplate( mapForTemplate ), mapForTemplate); ResponseValues rv = new TemplateResponseValues(getTemplate( mapForTemplate ), mapForTemplate);
return rv; return rv;
} catch (Throwable e) { } catch (Throwable e) {
log.error(e); log.error(e, e);
return new ExceptionResponseValues(e); return new ExceptionResponseValues(e);
} }
} }

View file

@ -0,0 +1,126 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.sdb.Store;
import com.hp.hpl.jena.sdb.StoreDesc;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupSDB;
public class SDBSetupController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog(
SDBSetupController.class);
private static final String SDB_SETUP_FTL = "sdbSetup.ftl";
protected ResponseValues processRequest(VitroRequest vreq) {
// Due to requiresLoginLevel(), we don't get here unless logged in as DBA
if (!LoginStatusBean.getBean(vreq)
.isLoggedInAtLeast(LoginStatusBean.DBA)) {
return new RedirectResponseValues(UrlBuilder.getUrl(Route.LOGIN));
}
Map<String, Object> body = new HashMap<String, Object>();
String messageStr = "";
try {
JenaDataSourceSetupSDB jenaDataSourceSetupSDB = new JenaDataSourceSetupSDB();
Boolean done = (Boolean)getServletContext().getAttribute("done");
String setupsignal = (String) vreq.getParameter("setupsignal");
if (done!=null && done) {
messageStr = "SDB is currently being set up.";
} else{
String sdbsetup = (String)getServletContext().getAttribute("sdbsetup");
if(sdbsetup == null || sdbsetup.equals("showButton") || setupsignal == null){
body.put("link", "show");
messageStr = null;
getServletContext().setAttribute("sdbsetup", "yes");
if(getServletContext().getAttribute("sdbstatus")!=null)
body.put("sdbstatus",getServletContext().getAttribute("sdbstatus"));
else
body.put("sdbstatus"," ");
}
else if(setupsignal!=null && setupsignal.equals("setup")){
new Thread(new SDBSetupRunner(jenaDataSourceSetupSDB)).start();
messageStr = "SDB setup started.";
getServletContext().setAttribute("sdbsetup", "showButton");
}
}
} catch (Exception e) {
log.error("Error setting up SDB store", e);
body.put("errorMessage",
"Error setting up SDB store: " +
e.getMessage());
return new ExceptionResponseValues(
SDB_SETUP_FTL, body, e);
}
body.put("message", messageStr);
return new TemplateResponseValues(SDB_SETUP_FTL, body);
}
private class SDBSetupRunner implements Runnable {
private JenaDataSourceSetupSDB jenaDataSourceSetupSDB;
final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
public SDBSetupRunner(JenaDataSourceSetupSDB jenaDataSourceSetupSDB) {
this.jenaDataSourceSetupSDB = jenaDataSourceSetupSDB;
}
public void run() {
Boolean done = true;
getServletContext().setAttribute("done",done);
StoreDesc storeDesc = jenaDataSourceSetupSDB.makeStoreDesc();
BasicDataSource bds = jenaDataSourceSetupSDB.makeDataSourceFromConfigurationProperties();
Store store = null;
try {
store = JenaDataSourceSetupSDB.connectStore(bds, storeDesc);
} catch (SQLException e) {
log.error("Error while getting the sdb store with given store description and basic data source", e);
}
OntModel memModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
if (memModel == null) {
memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
log.warn("WARNING: no database connected. Changes will disappear after context restart.");
}
OntModel inferenceModel = (OntModel)getServletContext().getAttribute("inferenceOntModel");
if(inferenceModel == null){
inferenceModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
}
if (store!=null) {
log.info("Setting up SDB store.");
try{
jenaDataSourceSetupSDB.setupSDB(getServletContext(), store, memModel, inferenceModel);
getServletContext().setAttribute("sdbstatus","SDB setup done successfully");
}
catch(Exception e){
getServletContext().setAttribute("sdbstatus",e.getMessage());
}
log.info("SDB setup complete.");
}
done = false;
getServletContext().setAttribute("done",done);
}
}
}

View file

@ -24,6 +24,8 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog( private static final Log log = LogFactory.getLog(
SimpleReasonerRecomputeController.class); SimpleReasonerRecomputeController.class);
private static final String RECOMPUTE_INFERENCES_FTL = "recomputeInferences.ftl";
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
// Due to requiresLoginLevel(), we don't get here unless logged in as DBA // Due to requiresLoginLevel(), we don't get here unless logged in as DBA
if (!LoginStatusBean.getBean(vreq) if (!LoginStatusBean.getBean(vreq)
@ -40,13 +42,23 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
if (simpleReasoner == null) { if (simpleReasoner == null) {
messageStr = "No SimpleReasoner has been set up."; messageStr = "No SimpleReasoner has been set up.";
} else { } else {
String signal = (String) vreq.getParameter("signal");
if (simpleReasoner.isRecomputing()) { if (simpleReasoner.isRecomputing()) {
messageStr = messageStr =
"The SimpleReasoner is currently in the process of " + "The SimpleReasoner is currently in the process of " +
"recomputing inferences."; "recomputing inferences.";
} else { } else{
new Thread(new Recomputer(simpleReasoner)).start(); String restart = (String)getServletContext().getAttribute("restart");
messageStr = "Recomputation of inferences started"; if(restart == null || restart.equals("showButton") || signal == null){
body.put("link", "show");
messageStr = null;
getServletContext().setAttribute("restart", "yes");
}
else if(signal!=null && signal.equals("Recompute")){
new Thread(new Recomputer(simpleReasoner)).start();
messageStr = "Recomputation of inferences started";
getServletContext().setAttribute("restart", "showButton");
}
} }
} }
@ -55,12 +67,13 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
body.put("errorMessage", body.put("errorMessage",
"There was an error while recomputing inferences: " + "There was an error while recomputing inferences: " +
e.getMessage()); e.getMessage());
return new ExceptionResponseValues( return new ExceptionResponseValues(
Template.ERROR_MESSAGE.toString(), body, e); RECOMPUTE_INFERENCES_FTL, body, e);
} }
body.put("message", messageStr); body.put("message", messageStr);
return new TemplateResponseValues(Template.MESSAGE.toString(), body); body.put("redirecturl",vreq.getContextPath()+"/RecomputeInferences");
return new TemplateResponseValues(RECOMPUTE_INFERENCES_FTL, body);
} }
private class Recomputer implements Runnable { private class Recomputer implements Runnable {

View file

@ -92,7 +92,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
// Create map for data input entry form options list // Create map for data input entry form options list
List classGroups = wadf.getVClassGroupDao().getPublicGroupsWithVClasses(true,true,false); // order by displayRank, include uninstantiated classes, don't get the counts of individuals List classGroups = wadf.getVClassGroupDao().getPublicGroupsWithVClasses(true,true,false); // order by displayRank, include uninstantiated classes, don't get the counts of individuals
boolean classGroupDisplayAssumptionsMeet = checkClassGroupDisplayAssumptions(classGroups); //boolean classGroupDisplayAssumptionsMet = checkClassGroupDisplayAssumptions(classGroups);
Set<String> seenGroupNames = new HashSet<String>(); Set<String> seenGroupNames = new HashSet<String>();
@ -102,10 +102,10 @@ public class SiteAdminController extends FreemarkerHttpServlet {
VClassGroup group = (VClassGroup)classGroupIt.next(); VClassGroup group = (VClassGroup)classGroupIt.next();
List opts = FormUtils.makeOptionListFromBeans(group.getVitroClassList(),"URI","PickListName",null,null,false); List opts = FormUtils.makeOptionListFromBeans(group.getVitroClassList(),"URI","PickListName",null,null,false);
if( seenGroupNames.contains(group.getPublicName() )){ if( seenGroupNames.contains(group.getPublicName() )){
//have a duplicat classgroup name, stick in the URI //have a duplicate classgroup name, stick in the URI
orderedClassGroups.put(group.getPublicName() + " ("+group.getURI()+")", opts); orderedClassGroups.put(group.getPublicName() + " ("+group.getURI()+")", opts);
}else if( group.getPublicName() == null ){ }else if( group.getPublicName() == null ){
//have an unlabeled group, use stick in the URI //have an unlabeled group, stick in the URI
orderedClassGroups.put("unnamed group ("+group.getURI()+")", opts); orderedClassGroups.put("unnamed group ("+group.getURI()+")", opts);
}else{ }else{
orderedClassGroups.put(group.getPublicName(),opts); orderedClassGroups.put(group.getPublicName(),opts);
@ -199,11 +199,11 @@ public class SiteAdminController extends FreemarkerHttpServlet {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
Map<String, String> urls = new HashMap<String, String>(); Map<String, String> urls = new HashMap<String, String>();
urls.put("ingest", urlBuilder.getUrl("/ingest")); urls.put("ingest", UrlBuilder.getUrl("/ingest"));
urls.put("rdfData", urlBuilder.getPortalUrl("/uploadRDFForm")); urls.put("rdfData", urlBuilder.getPortalUrl("/uploadRDFForm"));
urls.put("rdfExport", urlBuilder.getPortalUrl("/export")); urls.put("rdfExport", urlBuilder.getPortalUrl("/export"));
urls.put("sparqlQuery", urlBuilder.getUrl("/admin/sparqlquery")); urls.put("sparqlQuery", UrlBuilder.getUrl("/admin/sparqlquery"));
urls.put("sparqlQueryBuilder", urlBuilder.getUrl("/admin/sparqlquerybuilder")); urls.put("sparqlQueryBuilder", UrlBuilder.getUrl("/admin/sparqlquerybuilder"));
map.put("urls", urls); map.put("urls", urls);
return map; return map;
@ -218,33 +218,33 @@ public class SiteAdminController extends FreemarkerHttpServlet {
* Check the assumptions and use the URIs as the key if the assumptions are not * Check the assumptions and use the URIs as the key if the assumptions are not
* meet. see issue NIHVIVO-1635. * meet. see issue NIHVIVO-1635.
*/ */
private boolean checkClassGroupDisplayAssumptions( List<VClassGroup> groups){ // private boolean checkClassGroupDisplayAssumptions( List<VClassGroup> groups){
//Assumption A: all of the classgroups have a non-null rdfs:label // //Assumption A: all of the classgroups have a non-null rdfs:label
//Assumption B: none of the classgroups have the same rdfs:label // //Assumption B: none of the classgroups have the same rdfs:label
//the assumption that all classgroups have only one rdfs:label is not checked // //the assumption that all classgroups have only one rdfs:label is not checked
boolean rvalue = true; // boolean rvalue = true;
Set<String> seenPublicNames = new HashSet<String>(); // Set<String> seenPublicNames = new HashSet<String>();
//
for( VClassGroup group :groups ){ // for( VClassGroup group :groups ){
//check Assumption A // //check Assumption A
if( group.getPublicName() == null){ // if( group.getPublicName() == null){
rvalue = false; // rvalue = false;
break; // break;
} // }
//
//check Assumption B // //check Assumption B
if( seenPublicNames.contains(group.getPublicName()) ){ // if( seenPublicNames.contains(group.getPublicName()) ){
rvalue = false; // rvalue = false;
break; // break;
} // }
seenPublicNames.add(group.getPublicName()); // seenPublicNames.add(group.getPublicName());
} // }
//
//
if( !rvalue ) // if( !rvalue )
log.error("The rdfs:labels on the classgroups in the system do " + // log.error("The rdfs:labels on the classgroups in the system do " +
"not meet the display assumptions. Falling back to alternative."); // "not meet the display assumptions. Falling back to alternative.");
return rvalue; // return rvalue;
} // }
} }

View file

@ -26,16 +26,14 @@ public class TemplateProcessingHelper {
private Configuration config = null; private Configuration config = null;
private HttpServletRequest request = null; private HttpServletRequest request = null;
private ServletContext context = null; private ServletContext context = null;
//private Map<String, Object> templateDataModel = null;
TemplateProcessingHelper(Configuration config, HttpServletRequest request, ServletContext context) { public TemplateProcessingHelper(Configuration config, HttpServletRequest request, ServletContext context) {
this.config = config; this.config = config;
this.request = request; this.request = request;
this.context = context; this.context = context;
//this.templateDataModel = new HashMap<String, Object>();
} }
protected StringWriter processTemplate(String templateName, Map<String, Object> map) { public StringWriter processTemplate(String templateName, Map<String, Object> map) {
Template template = getTemplate(templateName); Template template = getTemplate(templateName);
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
processTemplate(template, map, sw); processTemplate(template, map, sw);
@ -57,6 +55,13 @@ public class TemplateProcessingHelper {
// can be used in directives. // can be used in directives.
env.setCustomAttribute("request", request); env.setCustomAttribute("request", request);
env.setCustomAttribute("context", context); env.setCustomAttribute("context", context);
// Define a setup template to be included by every page template
String templateType = (String) map.get("templateType");
if (FreemarkerHttpServlet.PAGE_TEMPLATE_TYPE.equals(templateType)) {
env.include(getTemplate("pageSetup.ftl"));
}
env.process(); env.process();
} catch (TemplateException e) { } catch (TemplateException e) {
log.error("Template Exception creating processing environment", e); log.error("Template Exception creating processing environment", e);
@ -65,8 +70,9 @@ public class TemplateProcessingHelper {
} }
} }
// In fact, we can put StringWriter objects directly into the data model, so perhaps we should eliminate the processTemplateToString() methods. // For cases where we need a String instead of a StringWriter. StringWriter objects can be put in the template data model,
protected String processTemplateToString(String templateName, Map<String, Object> map) { // but we can use this method from a jsp, for example.
public String processTemplateToString(String templateName, Map<String, Object> map) {
return processTemplate(templateName, map).toString(); return processTemplate(templateName, map).toString();
} }

View file

@ -2,21 +2,15 @@
package edu.cornell.mannlib.vitro.webapp.controller.freemarker; package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import freemarker.template.Configuration;
/** /**
* Freemarker controller and template sandbox. * Freemarker controller and template sandbox.

View file

@ -15,9 +15,8 @@ import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl; import org.openrdf.model.impl.URIImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.filters.PortalPickerFilter; import edu.cornell.mannlib.vitro.webapp.filters.PortalPickerFilter;
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils; import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
@ -186,6 +185,10 @@ public class UrlBuilder {
} }
} }
public ParamMap(List<String> strings) {
this((String[]) strings.toArray());
}
public ParamMap(Map<String, String> map) { public ParamMap(Map<String, String> map) {
putAll(map); putAll(map);
} }
@ -239,7 +242,15 @@ public class UrlBuilder {
private static String addParams(String url, ParamMap params, String glue) { private static String addParams(String url, ParamMap params, String glue) {
for (String key: params.keySet()) { for (String key: params.keySet()) {
url += glue + key + "=" + urlEncode(params.get(key)); String value = params.get(key);
// rjy7 Some users might require nulls to be converted to empty
// string, others to eliminate params with null values.
// Here we convert to empty string to prevent an exception
// from UrlEncoder.encode() when passed a null. Callers are advised
// to remove null values or convert to empty strings, whichever
// is desired in the particular instance.
value = (value == null) ? "" : urlEncode(value);
url += glue + key + "=" + value;
glue = "&"; glue = "&";
} }
return url; return url;
@ -259,7 +270,7 @@ public class UrlBuilder {
} }
public static String getIndividualProfileUrl(String individualUri, WebappDaoFactory wadf) { public static String getIndividualProfileUrl(String individualUri, WebappDaoFactory wadf) {
Individual individual = wadf.getIndividualDao().getIndividualByURI(individualUri); Individual individual = new IndividualImpl(individualUri);
return getIndividualProfileUrl(individual, individualUri, wadf); return getIndividualProfileUrl(individual, individualUri, wadf);
} }
@ -291,24 +302,24 @@ public class UrlBuilder {
return profileUrl; return profileUrl;
} }
public static String urlEncode(String url) { public static String urlEncode(String str) {
String encoding = "ISO-8859-1"; String encoding = "ISO-8859-1";
String encodedUrl = null; String encodedUrl = null;
try { try {
encodedUrl = URLEncoder.encode(url, encoding); encodedUrl = URLEncoder.encode(str, encoding);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error("Error encoding url " + url + " with encoding " + encoding + ": Unsupported encoding."); log.error("Error encoding url " + str + " with encoding " + encoding + ": Unsupported encoding.");
} }
return encodedUrl; return encodedUrl;
} }
public static String urlDecode(String url) { public static String urlDecode(String str) {
String encoding = "ISO-8859-1"; String encoding = "ISO-8859-1";
String decodedUrl = null; String decodedUrl = null;
try { try {
decodedUrl = URLDecoder.decode(url, encoding); decodedUrl = URLDecoder.decode(str, encoding);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error("Error decoding url " + url + " with encoding " + encoding + ": Unsupported encoding."); log.error("Error decoding url " + str + " with encoding " + encoding + ": Unsupported encoding.");
} }
return decodedUrl; return decodedUrl;
} }

View file

@ -380,7 +380,7 @@ public class JenaAdminActions extends BaseEditController {
try { try {
taxonomyModel.write(response.getOutputStream()); taxonomyModel.write(response.getOutputStream());
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
} }
} }
} }

View file

@ -4,31 +4,26 @@ package edu.cornell.mannlib.vitro.webapp.controller.jena;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils; import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class JenaExportController extends BaseEditController { public class JenaExportController extends BaseEditController {
@ -91,8 +86,6 @@ public class JenaExportController extends BaseEditController {
Model model = null; Model model = null;
OntModel ontModel = ModelFactory.createOntologyModel(); OntModel ontModel = ModelFactory.createOntologyModel();
boolean limitToInferred = false;
Model inferenceModel = null;
if(!subgraphParam.equalsIgnoreCase("tbox") && !subgraphParam.equalsIgnoreCase("abox") && !subgraphParam.equalsIgnoreCase("full")){ if(!subgraphParam.equalsIgnoreCase("tbox") && !subgraphParam.equalsIgnoreCase("abox") && !subgraphParam.equalsIgnoreCase("full")){
ontologyURI = subgraphParam; ontologyURI = subgraphParam;
@ -104,43 +97,110 @@ public class JenaExportController extends BaseEditController {
} }
String mode = (JenaDataSourceSetupBase.isSDBActive()) ? "SDB" : "RDB";
if( "abox".equals(subgraphParam)){ if( "abox".equals(subgraphParam)){
model = ModelFactory.createDefaultModel(); model = ModelFactory.createDefaultModel();
if("inferred".equals(assertedOrInferredParam)){ if("inferred".equals(assertedOrInferredParam)){
model = xutil.extractABox(dataset, INFERENCE_GRAPH); if(mode.equals("RDB")){
Dataset jenaDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("jenaOntModel"));
Dataset inferenceDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("inferenceOntModel"));
model = xutil.extractABox(jenaDataset,inferenceDataset,null);
}
else{
model = ModelContext.getInferenceOntModelSelector(getServletContext()).getABoxModel();
}
} }
else if("full".equals(assertedOrInferredParam)){ else if("full".equals(assertedOrInferredParam)){
model = xutil.extractABox(dataset, FULL_GRAPH); if(mode.equals("RDB")){
model = xutil.extractABox((OntModel)getServletContext().getAttribute("jenaOntModel"));
}
else{
model = ModelContext.getUnionOntModelSelector(getServletContext()).getABoxModel();
}
} }
else{ else if("asserted".equals(assertedOrInferredParam)){
model = xutil.extractABox(dataset, ASSERTIONS_GRAPH); if(mode.equals("RDB")){
Dataset jenaDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("jenaOntModel"));
Dataset baseDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("baseOntModel"));
model = xutil.extractABox(jenaDataset,baseDataset,null);
}
else{
model = ModelContext.getBaseOntModelSelector(getServletContext()).getABoxModel();
}
} }
} }
else if("tbox".equals(subgraphParam)){ else if("tbox".equals(subgraphParam)){
if("inferred".equals(assertedOrInferredParam)){ if ("inferred".equals(assertedOrInferredParam)) {
model = xutil.extractTBox(dataset, ontologyURI,INFERENCE_GRAPH); // the extraction won't work on just the inferred graph,
} // so we'll extract the whole ontology and then include
else if("full".equals(assertedOrInferredParam)){ // only those statements that are in the inferred graph
model = xutil.extractTBox(dataset, ontologyURI, FULL_GRAPH); Model tempModel = xutil.extractTBox(
} ModelContext.getUnionOntModelSelector(
else{ getServletContext()).getTBoxModel(), ontologyURI);
model = xutil.extractTBox(dataset, ontologyURI, ASSERTIONS_GRAPH); Model inferenceModel = ModelContext.getInferenceOntModelSelector(
} getServletContext()).getTBoxModel();
inferenceModel.enterCriticalSection(Lock.READ);
try {
model = tempModel.intersection(inferenceModel);
} finally {
inferenceModel.leaveCriticalSection();
}
} else if ("full".equals(assertedOrInferredParam)) {
model = xutil.extractTBox(
ModelContext.getUnionOntModelSelector(
getServletContext()).getTBoxModel(), ontologyURI);
} else {
model = xutil.extractTBox(
ModelContext.getBaseOntModelSelector(
getServletContext()).getTBoxModel(), ontologyURI);
}
// if("inferred".equals(assertedOrInferredParam)){
// model = xutil.extractTBox(dataset, ontologyURI,INFERENCE_GRAPH);
// }
// else if("full".equals(assertedOrInferredParam)){
// model = xutil.extractTBox(dataset, ontologyURI, FULL_GRAPH);
// }
// else{
// model = xutil.extractTBox(dataset, ontologyURI, ASSERTIONS_GRAPH);
// }
} }
else if("full".equals(subgraphParam)){ else if("full".equals(subgraphParam)){
if("inferred".equals(assertedOrInferredParam)){ if("inferred".equals(assertedOrInferredParam)){
ontModel = xutil.extractTBox(dataset, ontologyURI,INFERENCE_GRAPH); ontModel = xutil.extractTBox(dataset, ontologyURI,INFERENCE_GRAPH);
ontModel.addSubModel(xutil.extractABox(dataset, INFERENCE_GRAPH)); if(mode.equals("RDB")){
Dataset jenaDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("jenaOntModel"));
Dataset inferenceDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("inferenceOntModel"));
ontModel.addSubModel(xutil.extractABox(jenaDataset, inferenceDataset, null));
}
else{
ontModel.addSubModel(ModelContext.getInferenceOntModelSelector(getServletContext()).getABoxModel());
ontModel.addSubModel(ModelContext.getInferenceOntModelSelector(getServletContext()).getTBoxModel());
}
} }
else if("full".equals(assertedOrInferredParam)){ else if("full".equals(assertedOrInferredParam)){
ontModel = xutil.extractTBox(dataset, ontologyURI, FULL_GRAPH); ontModel = xutil.extractTBox(dataset, ontologyURI, FULL_GRAPH);
ontModel.addSubModel(xutil.extractABox(dataset, FULL_GRAPH)); if(mode.equals("RDB")){
ontModel.addSubModel(xutil.extractABox((OntModel)getServletContext().getAttribute("jenaOntModel")));
}
else{
ontModel.addSubModel(ModelContext.getUnionOntModelSelector(getServletContext()).getABoxModel());
ontModel.addSubModel(ModelContext.getUnionOntModelSelector(getServletContext()).getTBoxModel());
ontModel.addSubModel(ModelContext.getUnionOntModelSelector(getServletContext()).getApplicationMetadataModel());
}
} }
else{ else{
ontModel = xutil.extractTBox(dataset, ontologyURI, ASSERTIONS_GRAPH); ontModel = xutil.extractTBox(dataset, ontologyURI, ASSERTIONS_GRAPH);
ontModel.addSubModel(xutil.extractABox(dataset, ASSERTIONS_GRAPH)); if(mode.equals("RDB")){
Dataset jenaDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("jenaOntModel"));
Dataset baseDataset = DatasetFactory.create((OntModel)getServletContext().getAttribute("baseOntModel"));
ontModel.addSubModel(xutil.extractABox(jenaDataset,baseDataset,null));
}
else{
ontModel.addSubModel(ModelContext.getBaseOntModelSelector(getServletContext()).getABoxModel());
ontModel.addSubModel(ModelContext.getBaseOntModelSelector(getServletContext()).getTBoxModel());
ontModel.addSubModel(ModelContext.getBaseOntModelSelector(getServletContext()).getApplicationMetadataModel());
}
} }
} }

View file

@ -8,6 +8,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -27,6 +28,7 @@ import javax.servlet.ServletContextEvent;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -79,6 +81,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSpecialModelMaker; import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSpecialModelMaker;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupSDB; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupSDB;
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils; import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor; import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
@ -130,7 +133,18 @@ public class JenaIngestController extends BaseEditController {
if ("listModels".equals(actionStr)) { if ("listModels".equals(actionStr)) {
String modelT = (String)getServletContext().getAttribute("modelT"); String modelT = (String)getServletContext().getAttribute("modelT");
String info = (String)getServletContext().getAttribute("info"); String info = (String)getServletContext().getAttribute("info");
if(modelT==null || modelT.equals("rdb")){ if(modelT == null){
boolean initialSwitch = new JenaDataSourceSetupBase().isSDBActive();
if(initialSwitch){
VitroJenaSDBModelMaker vsmm = (VitroJenaSDBModelMaker) getServletContext().getAttribute("vitroJenaSDBModelMaker");
vreq.getSession().setAttribute("vitroJenaModelMaker", vsmm);
modelT = "sdb";
}
else{
modelT = "rdb";
}
}
if(modelT.equals("rdb")){
request.setAttribute("modelType", "rdb"); request.setAttribute("modelType", "rdb");
request.setAttribute("infoLine", "RDB models"); request.setAttribute("infoLine", "RDB models");
} }
@ -340,7 +354,11 @@ public class JenaIngestController extends BaseEditController {
String jdbcUrl = vreq.getParameter("jdbcUrl"); String jdbcUrl = vreq.getParameter("jdbcUrl");
String tripleStore = vreq.getParameter("tripleStore"); String tripleStore = vreq.getParameter("tripleStore");
if (jdbcUrl != null) { if (jdbcUrl != null) {
doConnectDB(vreq); try {
doConnectDB(vreq);
} catch (SQLException sqle) {
throw new RuntimeException("Unable to connect to DB", sqle);
}
if ("SDB".equals(tripleStore)) { if ("SDB".equals(tripleStore)) {
getServletContext().setAttribute("modelT", "sdb"); getServletContext().setAttribute("modelT", "sdb");
getServletContext().setAttribute("info", "SDB models"); getServletContext().setAttribute("info", "SDB models");
@ -744,14 +762,13 @@ public class JenaIngestController extends BaseEditController {
else{ else{
destination.add(utils.renameBNodesByPattern(source, namespaceEtc, vreq.getJenaOntModel(), pattern, property)); destination.add(utils.renameBNodesByPattern(source, namespaceEtc, vreq.getJenaOntModel(), pattern, property));
} }
if(csv2rdf){ if(csv2rdf && property!=null){
ClosableIterator closeIt = destination.listSubjects(); ClosableIterator closeIt = destination.listSubjects();
Property prop = ResourceFactory.createProperty(property); Property prop = ResourceFactory.createProperty(property);
try { try {
for (Iterator it = closeIt; it.hasNext();) { for (Iterator it = closeIt; it.hasNext();) {
Resource res = (Resource) it.next(); Resource res = (Resource) it.next();
if (res.isAnon()) { if (res.isAnon()) {
// now we do something hacky to get the same resource in the outModel, since there's no getResourceById();
ClosableIterator closfIt = destination.listStatements(res,prop,(RDFNode)null); ClosableIterator closfIt = destination.listStatements(res,prop,(RDFNode)null);
Statement stmt = null; Statement stmt = null;
try { try {
@ -773,6 +790,21 @@ public class JenaIngestController extends BaseEditController {
csv2rdf = false; csv2rdf = false;
getServletContext().setAttribute("csv2rdf", csv2rdf); getServletContext().setAttribute("csv2rdf", csv2rdf);
} }
else if(csv2rdf && property == null){
ClosableIterator closeIt = destination.listSubjects();
try {
for (Iterator it = closeIt; it.hasNext();) {
Resource res = (Resource) it.next();
if (res.isAnon()) {
destination.removeAll(res,(Property)null,(RDFNode)null);
}
}
} finally {
closeIt.close();
}
csv2rdf = false;
getServletContext().setAttribute("csv2rdf", csv2rdf);
}
} finally { } finally {
destination.leaveCriticalSection(); destination.leaveCriticalSection();
@ -858,7 +890,7 @@ public class JenaIngestController extends BaseEditController {
return tempModel.size(); return tempModel.size();
} }
public void doConnectDB(VitroRequest vreq) { public void doConnectDB(VitroRequest vreq) throws SQLException {
String jdbcUrl = vreq.getParameter("jdbcUrl"); String jdbcUrl = vreq.getParameter("jdbcUrl");
String username = vreq.getParameter("username"); String username = vreq.getParameter("username");
String password = vreq.getParameter("password"); String password = vreq.getParameter("password");
@ -870,40 +902,48 @@ public class JenaIngestController extends BaseEditController {
jdbcUrl += "useUnicode=yes&characterEncoding=utf8"; jdbcUrl += "useUnicode=yes&characterEncoding=utf8";
} }
dbTypeObj = DatabaseType.fetch(dbType); dbTypeObj = DatabaseType.fetch(dbType);
loadDriver(dbTypeObj); String driver = loadDriver(dbTypeObj);
System.out.println("Connecting to DB at "+jdbcUrl); System.out.println("Connecting to DB at "+jdbcUrl);
StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ; StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ;
SDBConnection conn = new SDBConnection(jdbcUrl, username, password) ; BasicDataSource bds = JenaDataSourceSetup.makeBasicDataSource(
Store store = SDBFactory.connectStore(conn, storeDesc); driver, jdbcUrl, username, password);
VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(store); try {
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, dbType); VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(storeDesc, bds);
getServletContext().setAttribute("vitroJenaSDBModelMaker", vsmm); VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, dbType);
getServletContext().setAttribute("vitroJenaModelMaker", vjmm); getServletContext().setAttribute("vitroJenaSDBModelMaker", vsmm);
if("SDB".equals(tripleStore)) getServletContext().setAttribute("vitroJenaModelMaker", vjmm);
vreq.getSession().setAttribute("vitroJenaModelMaker",vsmm); if("SDB".equals(tripleStore))
else vreq.getSession().setAttribute("vitroJenaModelMaker",vsmm);
vreq.getSession().setAttribute("vitroJenaModelMaker",vjmm); else
vreq.getSession().setAttribute("vitroJenaModelMaker",vjmm);
} catch (SQLException sqle) {
throw new RuntimeException("Unable to create SDB ModelMaker", sqle);
}
} }
private void loadDriver(DatabaseType dbType) { private String loadDriver(DatabaseType dbType) {
if (DatabaseType.MySQL.equals(dbType)) { String driverName = JDBC.getDriver(dbType);
JDBC.loadDriverMySQL(); JDBC.loadDriver(driverName);
} else if (DatabaseType.DB2.equals(dbType)) { return driverName;
JDBC.loadDriverDB2();
} else if (DatabaseType.Derby.equals(dbType)) { // if (DatabaseType.MySQL.equals(dbType)) {
JDBC.loadDriverDerby(); // JDBC.loadDriverMySQL();
} else if (DatabaseType.H2.equals(dbType)) { // } else if (DatabaseType.DB2.equals(dbType)) {
JDBC.loadDriverH2(); // JDBC.loadDriverDB2();
} else if (DatabaseType.HSQLDB.equals(dbType)) { // } else if (DatabaseType.Derby.equals(dbType)) {
JDBC.loadDriverHSQL(); // JDBC.loadDriverDerby();
} else if (DatabaseType.Oracle.equals(dbType)) { // } else if (DatabaseType.H2.equals(dbType)) {
JDBC.loadDriverOracle(); // JDBC.loadDriverH2();
} else if (DatabaseType.PostgreSQL.equals(dbType)) { // } else if (DatabaseType.HSQLDB.equals(dbType)) {
JDBC.loadDriverPGSQL(); // JDBC.loadDriverHSQL();
} else if (DatabaseType.SQLServer.equals(dbType)) { // } else if (DatabaseType.Oracle.equals(dbType)) {
JDBC.loadDriverSQLServer(); // JDBC.loadDriverOracle();
} // } else if (DatabaseType.PostgreSQL.equals(dbType)) {
// JDBC.loadDriverPGSQL();
// } else if (DatabaseType.SQLServer.equals(dbType)) {
// JDBC.loadDriverSQLServer();
// }
} }
/*public void doExecuteCsv2Rdf(VitroRequest vreq) { /*public void doExecuteCsv2Rdf(VitroRequest vreq) {

View file

@ -131,8 +131,7 @@ public class LoginProcessBean {
MLevel.ERROR); MLevel.ERROR);
public static final Message USING_OLD_PASSWORD = new Message( public static final Message USING_OLD_PASSWORD = new Message(
"Please choose a different password from the " "Your new password cannot match the current one.", MLevel.ERROR);
+ "temporary one provided initially.", MLevel.ERROR);
private final String format; private final String format;
private final MLevel messageLevel; private final MLevel messageLevel;

View file

@ -65,7 +65,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
return doTemplate(vreq, showLoginScreen(vreq)); return doTemplate(vreq, showLoginScreen(vreq));
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
return doTemplate(vreq, showError(e)); return doTemplate(vreq, showError(e));
} }
} }
@ -89,7 +89,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
return showLoginScreen(vreq); return showLoginScreen(vreq);
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
return showError(e); return showError(e);
} }
} }

View file

@ -2,17 +2,28 @@
package edu.cornell.mannlib.vitro.webapp.dao; package edu.cornell.mannlib.vitro.webapp.dao;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property; 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.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
public class DisplayVocabulary { public class DisplayVocabulary {
/** <p>The ontology model that holds the vocabulary terms</p> */
private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
/* Namespace for display vocabulary */ /* Namespace for display vocabulary */
public static final String DISPLAY_NS = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#"; public static final String DISPLAY_NS = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#";
private static final String NS = DISPLAY_NS; private static final String NS = DISPLAY_NS;
/* Individuals */
public static final String PRIMARY_LUCENE_INDEX_URI = NS + "PrimaryLuceneIndex";
/* Page types */ /* Page types */
public static final String PAGE_TYPE = NS + "Page"; public static final String PAGE_TYPE = NS + "Page";
public static final String HOME_PAGE_TYPE = NS + "HomePage"; public static final String HOME_PAGE_TYPE = NS + "HomePage";
@ -22,11 +33,73 @@ public class DisplayVocabulary {
public static final String FOR_CLASSGROUP = NS + "forClassGroup"; public static final String FOR_CLASSGROUP = NS + "forClassGroup";
/* Data Properties */ /* Data Properties */
public static final String URL_MAPPING = NS + "urlMapping"; public static final DatatypeProperty URL_MAPPING = m_model.createDatatypeProperty(NS + "urlMapping");
public static final String TITLE = NS + "title"; public static final String TITLE = NS + "title";
public static final String REQUIRES_BODY_TEMPLATE = NS + "requiresBodyTemplate"; public static final DatatypeProperty REQUIRES_BODY_TEMPLATE = m_model.createDatatypeProperty(NS + "requiresBodyTemplate");
/* URIs for storing menu.n3 */ /* URIs for storing menu.n3 */
public static final String MENU_TEXT_RES = NS + "MenuText"; public static final String MENU_TEXT_RES = NS + "MenuText";
public static final String HAS_TEXT_REPRESENTATION = NS + "hasMenuText"; public static final String HAS_TEXT_REPRESENTATION = NS + "hasMenuText";
/** <p>The namespace of the vocabulary as a string</p>
* @see #NS */
public static String getURI() {return NS;}
/** <p>The namespace of the vocabulary as a resource</p> */
public static final Resource NAMESPACE = m_model.createResource( NS );
public static final ObjectProperty REQUIRES_VALUES = m_model.createObjectProperty( NS + "requiresValues" );
public static final ObjectProperty TO_PAGE = m_model.createObjectProperty( NS + "toPage" );
public static final ObjectProperty EXCLUDE_CLASS = m_model.createObjectProperty( NS + "excludeClass" );
public static final ObjectProperty INCLUDE_CLASS = m_model.createObjectProperty( NS + "includeClass" );
/** <p>Java package and class name. ex edu.cornell.mannlib.vitro.webapps.functions.ExampleFunction</p> */
public static final DatatypeProperty JAVA_CLASS_NAME = m_model.createDatatypeProperty( NS + "javaClassName" );
public static final DatatypeProperty MENU_POSITION = m_model.createDatatypeProperty( NS + "menuPosition" );
public static final DatatypeProperty PARAMETER_NAME = m_model.createDatatypeProperty( NS + "parameterName" );
public static final DatatypeProperty PARAMETER_VALUE = m_model.createDatatypeProperty( NS + "parameterValue" );
//public static final DatatypeProperty REQUIRES_BODY_TEMPLATE = m_model.createDatatypeProperty( NS + "requiresBodyTemplate" );
/** <p>Values from HttpRequest.getPathInfo() will be mapped to values from urlMapping.</p> */
//public static final DatatypeProperty URL_MAPPING = m_model.createDatatypeProperty( NS + "urlMapping" );
/** <p>This represents a menu item or other general navigation item.</p> */
public static final OntClass NAVIGATION_ELEMENT = m_model.createClass( NS + "NavigationElement" );
/** <p>Class of pages.</p> */
public static final OntClass PAGE = m_model.createClass( NS + "Page" );
/* URIs for some individuals in the dispaly ontology */
//public static final Individual EVENTS = m_model.createIndividual( NS + "Events", PAGE );
//public static final Individual EVENTS_MENU_ITEM = m_model.createIndividual( NS + "EventsMenuItem", NAVIGATION_ELEMENT );
//public static final Individual HOME = m_model.createIndividual( NS + "Home", PAGE );
//public static final Individual HOME_MENU_ITEM = m_model.createIndividual( NS + "HomeMenuItem", NAVIGATION_ELEMENT );
//public static final Individual ORGANIZATIONS = m_model.createIndividual( NS + "Organizations", PAGE );
//public static final Individual ORGANIZATIONS_MENU_ITEM = m_model.createIndividual( NS + "OrganizationsMenuItem", NAVIGATION_ELEMENT );
//public static final Individual PEOPLE = m_model.createIndividual( NS + "People", PAGE );
//public static final Individual PEOPLE_MENU_ITEM = m_model.createIndividual( NS + "PeopleMenuItem", NAVIGATION_ELEMENT );
//public static final Individual PUBLICATIONS = m_model.createIndividual( NS + "Publications", PAGE );
//public static final Individual PUBLICATIONS_MENU_ITEM = m_model.createIndividual( NS + "PublicationsMenuItem", NAVIGATION_ELEMENT );
} }

View file

@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.dao;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
@ -31,4 +32,6 @@ public interface ObjectPropertyStatementDao {
int insertNewObjectPropertyStatement(ObjectPropertyStatement objPropertyStmt ); int insertNewObjectPropertyStatement(ObjectPropertyStatement objPropertyStmt );
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String query); public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String query);
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String query, Set<String> constructQueries);
} }

View file

@ -29,6 +29,8 @@ public class VitroVocabulary {
public static final String OWL = "http://www.w3.org/2002/07/owl#"; public static final String OWL = "http://www.w3.org/2002/07/owl#";
public static final String OWL_ONTOLOGY = OWL+"Ontology"; public static final String OWL_ONTOLOGY = OWL+"Ontology";
public static final String OWL_THING = OWL+"Thing"; public static final String OWL_THING = OWL+"Thing";
public static final String AFN = "http://jena.hpl.hp.com/ARQ/function#";
public static final String label = vitroURI + "label"; public static final String label = vitroURI + "label";

View file

@ -138,4 +138,6 @@ public interface WebappDaoFactory {
public PageDao getPageDao(); public PageDao getPageDao();
public MenuDao getMenuDao(); public MenuDao getMenuDao();
public void close();
} }

View file

@ -646,4 +646,10 @@ public class IndividualFiltering implements Individual {
// Since the statements have been filtered, we can just take the first individual without filtering. // Since the statements have been filtered, we can just take the first individual without filtering.
return stmts.isEmpty() ? null : stmts.get(0).getObject(); return stmts.isEmpty() ? null : stmts.get(0).getObject();
} }
@Override
public boolean hasThumb() {
return _innerIndividual.hasThumb();
}
} }

View file

@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.dao.filtering;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import net.sf.jga.algorithms.Filter; import net.sf.jga.algorithms.Filter;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
@ -88,6 +89,14 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
String subjectUri, String propertyUri, String query) { String subjectUri, String propertyUri, String query) {
return innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, query); return innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, query);
} }
@Override
// RY What about filtering?
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri, String propertyUri, String query, Set<String> queryStrings) {
return innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, query, queryStrings);
}
// @Override // @Override

View file

@ -316,4 +316,9 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
public DisplayModelDao getDisplayModelDao(){ public DisplayModelDao getDisplayModelDao(){
return innerWebappDaoFactory.getDisplayModelDao(); return innerWebappDaoFactory.getDisplayModelDao();
} }
@Override
public void close() {
innerWebappDaoFactory.close();
}
} }

View file

@ -81,12 +81,12 @@ public class HiddenFromDisplayBelowRoleLevelFilter extends VitroFiltersImpl {
@SuppressWarnings("serial") @SuppressWarnings("serial")
private class RoleFilter<E extends ResourceBean> extends UnaryFunctor<E,Boolean>{ private class RoleFilter<E extends ResourceBean> extends UnaryFunctor<E,Boolean>{
@Override @Override
public Boolean fn(E resource) { public Boolean fn(E resource) {
log.debug("checking hidden status for \"" + resource.getURI() + "\"");
try{ try{
if( resource == null ) if( resource == null )
return canViewOddItems(); return canViewOddItems();
else else
log.debug("checking hidden status for \"" + resource.getURI() + "\"");
return sameLevelOrHigher( resource.getHiddenFromDisplayBelowRoleLevel() ); return sameLevelOrHigher( resource.getHiddenFromDisplayBelowRoleLevel() );
}catch(RuntimeException th){ }catch(RuntimeException th){
log.warn("Error checking hidden status for " + resource, th); log.warn("Error checking hidden status for " + resource, th);
@ -99,9 +99,11 @@ public class HiddenFromDisplayBelowRoleLevelFilter extends VitroFiltersImpl {
private class IndividualRoleFilter extends UnaryFunctor<Individual,Boolean>{ private class IndividualRoleFilter extends UnaryFunctor<Individual,Boolean>{
@Override @Override
public Boolean fn(Individual ind){ public Boolean fn(Individual ind){
if( ind == null ) {
log.debug("checking hidden status for null Individual");
return canViewOddItems();
}
log.debug("checking hidden status for Individual \"" + ind.getName() + "\""); log.debug("checking hidden status for Individual \"" + ind.getName() + "\"");
if( ind == null )
return canViewOddItems();
try{ try{
if( ! sameLevelOrHigher( ind.getHiddenFromDisplayBelowRoleLevel() ) ) if( ! sameLevelOrHigher( ind.getHiddenFromDisplayBelowRoleLevel() ) )
@ -136,9 +138,9 @@ public class HiddenFromDisplayBelowRoleLevelFilter extends VitroFiltersImpl {
extends UnaryFunctor<E,Boolean>{ extends UnaryFunctor<E,Boolean>{
@Override @Override
public Boolean fn(E dPropStmt) { public Boolean fn(E dPropStmt) {
if( dPropStmt == null ) return false; //don't know why this would happen
log.debug("checking hidden status for data property statement \"" + dPropStmt.getDatapropURI() + "\""); log.debug("checking hidden status for data property statement \"" + dPropStmt.getDatapropURI() + "\"");
try { try {
if( dPropStmt == null ) return false; //don't know why this would happen
String propUri = dPropStmt.getDatapropURI(); String propUri = dPropStmt.getDatapropURI();
DataProperty prop = null; DataProperty prop = null;
if( dataPropertyMap.containsKey(propUri) ){ if( dataPropertyMap.containsKey(propUri) ){
@ -188,9 +190,11 @@ public class HiddenFromDisplayBelowRoleLevelFilter extends VitroFiltersImpl {
extends UnaryFunctor<E,Boolean>{ extends UnaryFunctor<E,Boolean>{
@Override @Override
public Boolean fn(E stmt) { public Boolean fn(E stmt) {
log.debug("checking hidden status for object property statement \"" + stmt.getPropertyURI() + "\""); if( stmt == null ) {
if( stmt == null ) log.debug("checking hidden status for null object property statement");
return false; return false;
}
log.debug("checking hidden status for object property statement \"" + stmt.getPropertyURI() + "\"");
try { try {
ObjectProperty prop = stmt.getProperty(); ObjectProperty prop = stmt.getProperty();

View file

@ -163,13 +163,18 @@ public class ProhibitedFromUpdateBelowRoleLevelFilter extends VitroFiltersImpl {
try { try {
ObjectProperty prop = stmt.getProperty(); ObjectProperty prop = stmt.getProperty();
if( prop == null ) if (prop == null) {
prop = wdf.getObjectPropertyDao().getObjectPropertyByURI( stmt.getPropertyURI() ); prop = wdf.getObjectPropertyDao().getObjectPropertyByURI(stmt.getPropertyURI());
if( prop == null ) }
if( ! canViewOddItems() ){ return false; } if (prop == null) {
else if (!canViewOddItems()) {
if( sameLevelOrHigher( prop.getProhibitedFromUpdateBelowRoleLevel()) == false) return false;
return false; }
} else {
if (sameLevelOrHigher(prop.getProhibitedFromUpdateBelowRoleLevel()) == false) {
return false;
}
}
Individual subject = Individual subject =
(stmt.getSubject() != null ? stmt.getSubject() : wdf.getIndividualDao().getIndividualByURI( stmt.getSubjectURI())); (stmt.getSubject() != null ? stmt.getSubject() : wdf.getIndividualDao().getIndividualByURI( stmt.getSubjectURI()));

View file

@ -44,14 +44,12 @@ public class VitroFilterUtils {
* Gets a filter that filters out any resource * Gets a filter that filters out any resource
* that has a annotation of hiddenFromDisplayBelowRoleLevel higher than current user's role level * that has a annotation of hiddenFromDisplayBelowRoleLevel higher than current user's role level
*/ */
public static VitroFilters getDisplayFilterByRoleLevel(RoleLevel role, WebappDaoFactory wdf){ public static VitroFilters getDisplayFilterByRoleLevel(RoleLevel role, WebappDaoFactory wdf){
log.info("initializing HiddenFromDisplayBelowRoleLevelFilter");
return new HiddenFromDisplayBelowRoleLevelFilter(role, wdf); return new HiddenFromDisplayBelowRoleLevelFilter(role, wdf);
} }
/* bdc34: Currently, this is not called from anywhere in the code. */ /* bdc34: Currently, this is not called from anywhere in the code. */
public static VitroFilters getUpdateFilterByRoleLevel(RoleLevel role, WebappDaoFactory wdf){ public static VitroFilters getUpdateFilterByRoleLevel(RoleLevel role, WebappDaoFactory wdf){
log.info("initializing ProhibitedFromUpdateBelowRoleLevelFilter");
return new ProhibitedFromUpdateBelowRoleLevelFilter(role, wdf); return new ProhibitedFromUpdateBelowRoleLevelFilter(role, wdf);
} }

View file

@ -8,6 +8,7 @@ import java.util.List;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.listeners.StatementListener; import com.hp.hpl.jena.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
import com.hp.hpl.jena.rdf.model.NodeIterator; import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
@ -26,14 +27,20 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
Integer portalCount = null; Integer portalCount = null;
List<String> externallyLinkedNamespaces = null; List<String> externallyLinkedNamespaces = null;
ModelChangedListener modelChangedListener = null;
public ApplicationDaoJena(WebappDaoFactoryJena wadf) { public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
getOntModelSelector().getDisplayModel().register( modelChangedListener = new ExternalNamespacesChangeListener();
new ExternalNamespacesChangeListener()); getOntModelSelector().getDisplayModel().register(modelChangedListener);
} }
public void close() {
if (modelChangedListener != null) {
getOntModelSelector().getDisplayModel().unregister(modelChangedListener);
}
}
public boolean isFlag1Active() { public boolean isFlag1Active() {
boolean somePortalIsFiltering=false; boolean somePortalIsFiltering=false;
if (portalCount == null) { if (portalCount == null) {

View file

@ -24,11 +24,8 @@ import com.hp.hpl.jena.ontology.ProfileException;
import com.hp.hpl.jena.ontology.Restriction; import com.hp.hpl.jena.ontology.Restriction;
import com.hp.hpl.jena.ontology.SomeValuesFromRestriction; import com.hp.hpl.jena.ontology.SomeValuesFromRestriction;
import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
@ -46,7 +43,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Ontology; import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
@ -67,11 +63,12 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
* value does not contain all of these namespaces. * value does not contain all of these namespaces.
*/ */
protected static final List<String> EXCLUDED_NAMESPACES = Arrays.asList( protected static final List<String> EXCLUDED_NAMESPACES = Arrays.asList(
// Don't need to exclude these, because they are not owl:DatatypeProperty
//"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
//"http://www.w3.org/2000/01/rdf-schema#",
"http://www.w3.org/2002/07/owl#",
"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#", "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#",
"http://vitro.mannlib.cornell.edu/ns/vitro/public#", "http://vitro.mannlib.cornell.edu/ns/vitro/public#"
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"http://www.w3.org/2000/01/rdf-schema#",
"http://www.w3.org/2002/07/owl#"
); );
/* /*
@ -86,21 +83,21 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
} }
propertyFilters = "FILTER (" + StringUtils.join(namespaceFilters, " && ") + ")\n"; propertyFilters = "FILTER (" + StringUtils.join(namespaceFilters, " && ") + ")\n";
} }
protected static final String dataPropertyQueryString = protected static final String DATA_PROPERTY_QUERY_STRING =
PREFIXES + "\n" + prefixes + "\n" +
"SELECT DISTINCT ?property WHERE { \n" + "SELECT DISTINCT ?property WHERE { \n" +
" GRAPH ?g1 { ?subject ?property ?object } \n" + " GRAPH ?g1 { ?subject ?property ?object } \n" +
" GRAPH ?g2 { ?property rdf:type owl:DatatypeProperty } \n" + " GRAPH ?g2 { ?property rdf:type owl:DatatypeProperty } \n" +
propertyFilters + propertyFilters +
"}"; "}";
static protected Query dataPropertyQuery; protected static Query dataPropertyQuery;
static { static {
try { try {
dataPropertyQuery = QueryFactory.create(dataPropertyQueryString); dataPropertyQuery = QueryFactory.create(DATA_PROPERTY_QUERY_STRING);
} catch(Throwable th){ } catch(Throwable th){
log.error("could not create SPARQL query for dataPropertyQueryString " + th.getMessage()); log.error("could not create SPARQL query for DATA_PROPERTY_QUERY_STRING " + th.getMessage());
log.error(dataPropertyQueryString); log.error(DATA_PROPERTY_QUERY_STRING);
} }
} }
@ -421,9 +418,10 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
public Collection<DataProperty> getAllPossibleDatapropsForIndividual(String individualURI) { public Collection<DataProperty> getAllPossibleDatapropsForIndividual(String individualURI) {
Individual ind = getWebappDaoFactory().getIndividualDao().getIndividualByURI(individualURI); Individual ind = getWebappDaoFactory().getIndividualDao().getIndividualByURI(individualURI);
Collection<DataProperty> dpColl = new ArrayList<DataProperty>(); Collection<DataProperty> dpColl = new ArrayList<DataProperty>();
List<String> vclassURIs = getVClassURIs(ind);
try { try {
for (VClass currClass : ind.getVClasses(true)) { for (VClass currClass : ind.getVClasses( DIRECT )) {
List<DataProperty> currList = getDatapropsForClass(currClass.getURI()); List<DataProperty> currList = getDatapropsForClass(currClass.getURI());
for (Iterator<DataProperty> dpIter = currList.iterator(); dpIter.hasNext();) { for (Iterator<DataProperty> dpIter = currList.iterator(); dpIter.hasNext();) {
DataProperty dp = (DataProperty) dpIter.next(); DataProperty dp = (DataProperty) dpIter.next();
@ -447,7 +445,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
// now change range datatype based on individual // now change range datatype based on individual
// TODO: rethink all these methods to reduce inefficiency // TODO: rethink all these methods to reduce inefficiency
for (DataProperty dp : dpColl) { for (DataProperty dp : dpColl) {
dp.setRangeDatatypeURI(getRequiredDatatypeURI(ind, dp)); dp.setRangeDatatypeURI(getRequiredDatatypeURI(ind, dp, vclassURIs));
} }
} }
} catch (ProfileException pe) { } catch (ProfileException pe) {
@ -469,59 +467,68 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
); );
} }
public String getRequiredDatatypeURI(Individual individual, DataProperty dataprop) { private String getRequiredDatatypeURI(Individual individual, DataProperty dataprop, List<String> vclassURIs) {
OntModel ontModel = getOntModelSelector().getFullModel(); OntModel ontModel = getOntModelSelector().getTBoxModel();
String datatypeURI = dataprop.getRangeDatatypeURI(); String datatypeURI = dataprop.getRangeDatatypeURI();
List<String> vclassURIs = null;
if (reasoningAvailable()) { ontModel.enterCriticalSection(Lock.READ);
vclassURIs = new ArrayList<String>(); try {
for (VClass vc : individual.getVClasses(INDIRECT)) { // get universal restrictions applicable to data property
if (vc.getURI() != null) { Iterator<Resource> restIt = ontModel.listSubjectsWithProperty(OWL.onProperty, ontModel.getResource(dataprop.getURI()));
vclassURIs.add(vc.getURI()); while (restIt.hasNext()) {
} Resource restRes = restIt.next();
} if (restRes.canAs(Restriction.class)) {
} else { Restriction rest = (Restriction) restRes.as(Restriction.class);
vclassURIs = getSupertypeURIs(individual); if (rest.isAllValuesFromRestriction()) {
} AllValuesFromRestriction avfrest = rest.asAllValuesFromRestriction();
ontModel.enterCriticalSection(Lock.READ); if (avfrest.getAllValuesFrom() != null) {
try { // check if the individual has the restriction as one of its types
// get universal restrictions applicable to data property if (!individual.isAnonymous() &&
Iterator<Resource> restIt = ontModel.listSubjectsWithProperty(OWL.onProperty, ontModel.getResource(dataprop.getURI())); ontModel.contains(ontModel.getResource(individual.getURI()),
while (restIt.hasNext()) { RDF.type,
Resource restRes = restIt.next(); rest)
if (restRes.canAs(Restriction.class)) { ) {
Restriction rest = (Restriction) restRes.as(Restriction.class); datatypeURI = avfrest.getAllValuesFrom().getURI();
if (rest.isAllValuesFromRestriction()) { break;
AllValuesFromRestriction avfrest = rest.asAllValuesFromRestriction(); } else {
if (avfrest.getAllValuesFrom() != null) { // check if the restriction applies to one of the individual's types
// check if the individual has the restriction as one of its types List<Resource> equivOrSubResources = new ArrayList<Resource>();
if (!individual.isAnonymous() && equivOrSubResources.addAll(ontModel.listSubjectsWithProperty(RDFS.subClassOf, rest).toList());
ontModel.contains(ontModel.getResource(individual.getURI()), equivOrSubResources.addAll(ontModel.listSubjectsWithProperty(OWL.equivalentClass, rest).toList());
RDF.type, for(Resource equivOrSubRes : equivOrSubResources) {
rest) if (!equivOrSubRes.isAnon() && vclassURIs.contains(equivOrSubRes.getURI())) {
) { datatypeURI = avfrest.getAllValuesFrom().getURI();
datatypeURI = avfrest.getAllValuesFrom().getURI(); break;
break; }
} else { }
// check if the restriction applies to one of the individual's types }
List<Resource> equivOrSubResources = new ArrayList<Resource>(); }
equivOrSubResources.addAll(ontModel.listSubjectsWithProperty(RDFS.subClassOf, rest).toList()); }
equivOrSubResources.addAll(ontModel.listSubjectsWithProperty(OWL.equivalentClass, rest).toList()); }
for(Resource equivOrSubRes : equivOrSubResources) { }
if (!equivOrSubRes.isAnon() && vclassURIs.contains(equivOrSubRes.getURI())) { } finally {
datatypeURI = avfrest.getAllValuesFrom().getURI(); ontModel.leaveCriticalSection();
break; }
} return datatypeURI;
} }
}
} public String getRequiredDatatypeURI(Individual individual, DataProperty dataprop) {
} return getRequiredDatatypeURI(individual,dataprop,getVClassURIs(individual));
} }
}
} finally { private List<String> getVClassURIs(Individual individual){
ontModel.leaveCriticalSection(); List<String> vclassURIs = null;
} if (reasoningAvailable()) {
return datatypeURI; vclassURIs = new ArrayList<String>();
for (VClass vc : individual.getVClasses(INDIRECT)) {
if (vc.getURI() != null) {
vclassURIs.add(vc.getURI());
}
}
} else {
vclassURIs = getSupertypeURIs(individual);
}
return vclassURIs;
} }
private boolean DIRECT = true; private boolean DIRECT = true;
@ -746,9 +753,9 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
* into the new one in a future release. * into the new one in a future release.
*/ */
public List<DataProperty> getDataPropertyList(String subjectUri) { public List<DataProperty> getDataPropertyList(String subjectUri) {
log.debug("dataPropertyQueryString:\n" + dataPropertyQueryString); log.debug("Data property query string:\n" + DATA_PROPERTY_QUERY_STRING);
log.debug("dataPropertyQuery:\n" + dataPropertyQuery); log.debug("Data property query:\n" + dataPropertyQuery);
ResultSet results = getPropertyQueryResults(subjectUri, dataPropertyQuery); Iterator<QuerySolution> results = getPropertyQueryResults(subjectUri, dataPropertyQuery);
List<DataProperty> properties = new ArrayList<DataProperty>(); List<DataProperty> properties = new ArrayList<DataProperty>();
while (results.hasNext()) { while (results.hasNext()) {
QuerySolution sol = results.next(); QuerySolution sol = results.next();

View file

@ -42,7 +42,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
protected static final String dataPropertyValueQueryString = protected static final String DATA_PROPERTY_VALUE_QUERY_STRING =
"SELECT ?value WHERE { \n" + "SELECT ?value WHERE { \n" +
" GRAPH ?g {\n" + " GRAPH ?g {\n" +
" ?subject ?property ?value . \n" + " ?subject ?property ?value . \n" +
@ -52,10 +52,10 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
static protected Query dataPropertyValueQuery; static protected Query dataPropertyValueQuery;
static { static {
try { try {
dataPropertyValueQuery = QueryFactory.create(dataPropertyValueQueryString); dataPropertyValueQuery = QueryFactory.create(DATA_PROPERTY_VALUE_QUERY_STRING);
} catch(Throwable th){ } catch(Throwable th){
log.error("could not create SPARQL query for dataPropertyQueryString " + th.getMessage()); log.error("could not create SPARQL query for DATA_PROPERTY_VALUE_QUERY_STRING " + th.getMessage());
log.error(dataPropertyValueQueryString); log.error(DATA_PROPERTY_VALUE_QUERY_STRING);
} }
} }
@ -65,26 +65,40 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
this.dwf = dwf; this.dwf = dwf;
} }
public void deleteDataPropertyStatement(DataPropertyStatement dataPropertyStmt) {
deleteDataPropertyStatement(dataPropertyStmt, getOntModelSelector().getABoxModel());
}
public void deleteDataPropertyStatement( DataPropertyStatement dataPropertyStatement, OntModel ontModel ) public void deleteDataPropertyStatement( DataPropertyStatement dataPropertyStatement )
{ {
try { OntModel ontModel = getOntModelSelector().getABoxModel();
ontModel.enterCriticalSection(Lock.WRITE); try {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,dataPropertyStatement.getIndividualURI())); ontModel.enterCriticalSection(Lock.WRITE);
com.hp.hpl.jena.ontology.Individual ind = ontModel.getIndividual(dataPropertyStatement.getIndividualURI()); getOntModel().getBaseModel().notifyEvent(
Property prop = ontModel.getProperty(dataPropertyStatement.getDatapropURI()); new IndividualUpdateEvent(
Literal l = jenaLiteralFromDataPropertyStatement(dataPropertyStatement, ontModel); getWebappDaoFactory().getUserURI(),
if (ind != null && prop != null && l != null) { true,
ontModel.getBaseModel().remove(ind, prop, l); dataPropertyStatement.getIndividualURI()));
} com.hp.hpl.jena.ontology.Individual ind = ontModel.getIndividual(
} finally { dataPropertyStatement.getIndividualURI());
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),false,dataPropertyStatement.getIndividualURI())); OntModel tboxModel = getOntModelSelector().getTBoxModel();
ontModel.leaveCriticalSection(); tboxModel.enterCriticalSection(Lock.READ);
try {
} Property prop = tboxModel.getProperty(
dataPropertyStatement.getDatapropURI());
Literal l = jenaLiteralFromDataPropertyStatement(
dataPropertyStatement, ontModel);
if (ind != null && prop != null && l != null) {
ontModel.getBaseModel().remove(ind, prop, l);
}
} finally {
tboxModel.leaveCriticalSection();
}
} finally {
getOntModel().getBaseModel().notifyEvent(
new IndividualUpdateEvent(
getWebappDaoFactory().getUserURI(),
false,
dataPropertyStatement.getIndividualURI()));
ontModel.leaveCriticalSection();
}
} }
public Individual fillExistingDataPropertyStatementsForIndividual( Individual entity/*, boolean allowAnyNameSpace*/) public Individual fillExistingDataPropertyStatementsForIndividual( Individual entity/*, boolean allowAnyNameSpace*/)
@ -143,19 +157,29 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
deleteDataPropertyStatementsForIndividualByDataProperty(individualURI, dataPropertyURI, getOntModelSelector().getABoxModel()); deleteDataPropertyStatementsForIndividualByDataProperty(individualURI, dataPropertyURI, getOntModelSelector().getABoxModel());
} }
public void deleteDataPropertyStatementsForIndividualByDataProperty(String individualURI, String dataPropertyURI, OntModel ontModel) { public void deleteDataPropertyStatementsForIndividualByDataProperty(
String individualURI,
String dataPropertyURI,
OntModel ontModel) {
ontModel.enterCriticalSection(Lock.WRITE); ontModel.enterCriticalSection(Lock.WRITE);
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,individualURI)); getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(
getWebappDaoFactory().getUserURI(),
true,
individualURI));
try { try {
Resource indRes = ontModel.getResource(individualURI); Resource indRes = ResourceFactory.createResource(individualURI);
DatatypeProperty datatypeProperty = ontModel.getDatatypeProperty(dataPropertyURI); Property datatypeProperty = ResourceFactory.createProperty(
if (indRes != null && datatypeProperty != null) { dataPropertyURI);
ontModel.removeAll(indRes, datatypeProperty, (Literal)null); ontModel.removeAll(indRes, datatypeProperty, (Literal)null);
}
} finally { } finally {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),false,individualURI)); getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(
getWebappDaoFactory().getUserURI(),
false,
individualURI));
ontModel.leaveCriticalSection(); ontModel.leaveCriticalSection();
} }
} }
public void deleteDataPropertyStatementsForIndividualByDataProperty(Individual individual, DataProperty dataProperty) { public void deleteDataPropertyStatementsForIndividualByDataProperty(Individual individual, DataProperty dataProperty) {
@ -296,12 +320,12 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
@Override @Override
public List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri) { public List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri) {
log.debug("dataPropertyValueQueryString:\n" + dataPropertyValueQueryString); log.debug("Data property value query string:\n" + DATA_PROPERTY_VALUE_QUERY_STRING);
log.debug("dataPropertyValueQuery:\n" + dataPropertyValueQuery); log.debug("Data property value:\n" + dataPropertyValueQuery);
QuerySolutionMap bindings = new QuerySolutionMap(); QuerySolutionMap initialBindings = new QuerySolutionMap();
bindings.add("subject", ResourceFactory.createResource(subjectUri)); initialBindings.add("subject", ResourceFactory.createResource(subjectUri));
bindings.add("property", ResourceFactory.createResource(propertyUri)); initialBindings.add("property", ResourceFactory.createResource(propertyUri));
// Run the SPARQL query to get the properties // Run the SPARQL query to get the properties
List<Literal> values = new ArrayList<Literal>(); List<Literal> values = new ArrayList<Literal>();
@ -310,7 +334,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
QueryExecution qexec = QueryExecutionFactory.create( QueryExecution qexec = QueryExecutionFactory.create(
dataPropertyValueQuery, dataset, bindings); dataPropertyValueQuery, dataset, initialBindings);
ResultSet results = qexec.execSelect(); ResultSet results = qexec.execSelect();
while (results.hasNext()) { while (results.hasNext()) {

View file

@ -31,15 +31,21 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
implements DataPropertyStatementDao { implements DataPropertyStatementDao {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public DataPropertyStatementDaoSDB(DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf) { public DataPropertyStatementDaoSDB(
DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super (datasetWrapperFactory, wadf); super (datasetWrapperFactory, wadf);
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
this.datasetMode = datasetMode;
} }
@Override @Override
@ -51,12 +57,14 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
} }
else else
{ {
String[] graphVars = { "?g" };
String query = String query =
"CONSTRUCT { \n" + "CONSTRUCT { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" + " <" + entity.getURI() + "> ?p ?o . \n" +
"} WHERE { GRAPH ?g { \n" + "} WHERE { GRAPH ?g { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" + " <" + entity.getURI() + "> ?p ?o . \n" +
" FILTER(isLiteral(?o)) \n" + " FILTER(isLiteral(?o)) \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"} }" ; "} }" ;
Model results = null; Model results = null;
DatasetWrapper w = dwf.getDatasetWrapper(); DatasetWrapper w = dwf.getDatasetWrapper();

View file

@ -45,15 +45,22 @@ import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualSDB.IndividualNotFoundException;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class IndividualDaoSDB extends IndividualDaoJena { public class IndividualDaoSDB extends IndividualDaoJena {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
private WebappDaoFactoryJena wadf; private WebappDaoFactoryJena wadf;
public IndividualDaoSDB(DatasetWrapperFactory dwf, WebappDaoFactoryJena wadf) { public IndividualDaoSDB(DatasetWrapperFactory dwf,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
this.dwf = dwf; this.dwf = dwf;
this.datasetMode = datasetMode;
} }
protected DatasetWrapper getDatasetWrapper() { protected DatasetWrapper getDatasetWrapper() {
@ -61,7 +68,12 @@ public class IndividualDaoSDB extends IndividualDaoJena {
} }
protected Individual makeIndividual(String individualURI) { protected Individual makeIndividual(String individualURI) {
return new IndividualSDB(individualURI, this.dwf, getWebappDaoFactory()); try {
return new IndividualSDB(individualURI, this.dwf, datasetMode, getWebappDaoFactory());
} catch (IndividualNotFoundException e) {
// If the individual does not exist, return null.
return null;
}
} }
private static final Log log = LogFactory.getLog(IndividualDaoSDB.class.getName()); private static final Log log = LogFactory.getLog(IndividualDaoSDB.class.getName());
@ -97,38 +109,57 @@ public class IndividualDaoSDB extends IndividualDaoJena {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = {"?g", "?h", "?i"};
String query = String query =
"SELECT DISTINCT ?ind ?label ?moniker " + "SELECT DISTINCT ?ind ?label ?moniker " +
"WHERE " + "WHERE " +
"{ GRAPH ?g { \n" + "{ \n" +
" ?ind a <" + theClass.getURI() + "> \n" + "{ \n" +
"} \n" + " ?ind a <" + theClass.getURI() + "> . \n" +
"OPTIONAL { GRAPH ?h { ?ind <" + RDFS.label.getURI() + "> ?label } }\n" + " ?ind <" + RDFS.label.getURI() + "> ?label \n" +
"OPTIONAL { GRAPH ?i { ?ind <" + VitroVocabulary.MONIKER + "> ?moniker } } \n" + "} \n" +
"} ORDER BY ?label"; "UNION { \n" +
" ?ind a <" + theClass.getURI() + "> . \n" +
" ?ind <" + VitroVocabulary.MONIKER + "> ?moniker \n" +
"} \n" +
"} ORDER BY ?ind ?label";
ResultSet rs =QueryExecutionFactory.create( ResultSet rs =QueryExecutionFactory.create(
QueryFactory.create(query), dataset) QueryFactory.create(query), dataset)
.execSelect(); .execSelect();
Resource res = null; String uri = null;
String label = null;
String moniker = null;
while (rs.hasNext()) { while (rs.hasNext()) {
QuerySolution sol = rs.nextSolution(); QuerySolution sol = rs.nextSolution();
Resource currRes = sol.getResource("ind"); Resource currRes = sol.getResource("ind");
if ((res == null || !res.equals(currRes)) if (currRes.isAnon()) {
&& !currRes.isAnon()) { continue;
res = currRes;
Individual ent = new IndividualSDB(currRes.getURI(),
this.dwf, getWebappDaoFactory(),
SKIP_INITIALIZATION);
Literal label = sol.getLiteral("label");
if (label != null) {
ent.setName(label.getLexicalForm());
}
Literal moniker = sol.getLiteral("moniker");
if (moniker != null) {
ent.setMoniker(moniker.getLexicalForm());
}
ents.add(ent);
} }
if (uri != null && !uri.equals(currRes.getURI())) {
Individual ent = makeIndividual(uri, label, moniker);
if (ent != null) {
ents.add(ent);
}
uri = currRes.getURI();
label = null;
moniker = null;
} else if (uri == null) {
uri = currRes.getURI();
}
Literal labelLit = sol.getLiteral("label");
if (labelLit != null) {
label = labelLit.getLexicalForm();
}
Literal monikerLit = sol.getLiteral("moniker");
if (monikerLit != null) {
moniker = monikerLit.getLexicalForm();
}
if (!rs.hasNext()) {
Individual ent = makeIndividual(uri, label, moniker);
if (ent != null) {
ents.add(ent);
}
}
} }
} finally { } finally {
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
@ -149,13 +180,22 @@ public class IndividualDaoSDB extends IndividualDaoJena {
return ents; return ents;
} }
private Individual makeIndividual(String uri, String label, String moniker) {
Individual ent = new IndividualSDB(uri,
this.dwf, datasetMode, getWebappDaoFactory(),
SKIP_INITIALIZATION);
ent.setName(label);
ent.setMoniker(moniker);
return ent;
}
@Override @Override
public Individual getIndividualByURI(String entityURI) { public Individual getIndividualByURI(String entityURI) {
if( entityURI == null || entityURI.length() == 0 ) { if( entityURI == null || entityURI.length() == 0 ) {
return null; return null;
} else { } else {
return makeIndividual(entityURI); return makeIndividual(entityURI);
} }
} }
@ -300,11 +340,13 @@ public class IndividualDaoSDB extends IndividualDaoJena {
final List<String> list = final List<String> list =
new LinkedList<String>(); new LinkedList<String>();
String query = "SELECT ?ind WHERE { \n" + // get all labeled resources from any non-tbox and non-metadata graphs.
String query = "SELECT DISTINCT ?ind WHERE { \n" +
" GRAPH ?g { ?ind <" + RDFS.label.getURI() + "> ?label } \n" + " GRAPH ?g { ?ind <" + RDFS.label.getURI() + "> ?label } \n" +
" FILTER (?g != <" + JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL + "> " +
" && !regex(str(?g),\"tbox\")) \n " +
"}"; "}";
Query q = QueryFactory.create(query); Query q = QueryFactory.create(query);
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
@ -324,70 +366,21 @@ public class IndividualDaoSDB extends IndividualDaoJena {
w.close(); w.close();
} }
// getOntModel().enterCriticalSection(Lock.READ);
// try {
// ClosableIterator allIndIt = getOntModel().listIndividuals();
// try {
// while (allIndIt.hasNext()) {
// com.hp.hpl.jena.ontology.Individual ind = (com.hp.hpl.jena.ontology.Individual) allIndIt.next();
//
//
//
// //don't include anything that lacks a label, issue VIVO-119.
// if( getLabel(ind) == null )
// continue;
//
//
// boolean userVisible = true;
// //Check for non-user visible types, maybe this should be an annotation?
// ClosableIterator typeIt = ind.listRDFTypes(false);
// try {
// while (typeIt.hasNext()) {
// Resource typeRes = (Resource) typeIt.next();
// String type = typeRes.getURI();
// // brute forcing this until we implement a better strategy
// if (VitroVocabulary.PORTAL.equals(type) ||
// VitroVocabulary.TAB.equals(type) ||
// VitroVocabulary.TAB_INDIVIDUALRELATION.equals(type) ||
// VitroVocabulary.LINK.equals(type) ||
// VitroVocabulary.KEYWORD.equals(type) ||
// VitroVocabulary.KEYWORD_INDIVIDUALRELATION.equals(type) ||
// VitroVocabulary.CLASSGROUP.equals(type) ||
// VitroVocabulary.PROPERTYGROUP.equals(type) ||
// VitroVocabulary.APPLICATION.equals(type)) {
// userVisible = false;
// break;
// }
// if( OWL.ObjectProperty.getURI().equals(type) ||
// OWL.DatatypeProperty.getURI().equals(type) ||
// OWL.AnnotationProperty.getURI().equals(type) ||
// RDF.type.getURI().equals(type) ){
// userVisible = false;
// break;
// }
// }
// } finally {
// typeIt.close();
// }
// if (userVisible) {
// list.add(ind);
// }
//
// }
// } finally {
// allIndIt.close();
// }
// } finally {
// getOntModel().leaveCriticalSection();
// }
if (list.size() >0){ if (list.size() >0){
log.info("Number of individuals from source: " + list.size());
return new Iterator(){ return new Iterator(){
Iterator<String> innerIt = list.iterator(); Iterator<String> innerIt = list.iterator();
public boolean hasNext() { public boolean hasNext() {
return innerIt.hasNext(); return innerIt.hasNext();
} }
public Object next() { public Object next() {
return makeIndividual(innerIt.next()); String indURI = innerIt.next();
Individual ind = makeIndividual(indURI);
if (ind != null) {
return ind;
} else {
return new IndividualImpl(indURI);
}
} }
public void remove() { public void remove() {
//not used //not used
@ -407,7 +400,10 @@ public class IndividualDaoSDB extends IndividualDaoJena {
Iterator indIt = cls.listInstances(); Iterator indIt = cls.listInstances();
while (indIt.hasNext()) { while (indIt.hasNext()) {
com.hp.hpl.jena.ontology.Individual ind = (com.hp.hpl.jena.ontology.Individual) indIt.next(); com.hp.hpl.jena.ontology.Individual ind = (com.hp.hpl.jena.ontology.Individual) indIt.next();
ents.add(makeIndividual(ind.getURI())); Individual ent = makeIndividual(ind.getURI());
if (ent != null) {
ents.add(ent);
}
} }
return ents.iterator(); return ents.iterator();
} finally { } finally {
@ -456,7 +452,10 @@ public class IndividualDaoSDB extends IndividualDaoJena {
typeIt.close(); typeIt.close();
} }
if (userVisible) { if (userVisible) {
ents.add(makeIndividual(ent.getURI())); Individual ind = makeIndividual(ent.getURI());
if (ind != null) {
ents.add(ind);
}
} }
} }
} }

View file

@ -342,28 +342,10 @@ public class IndividualJena extends IndividualImpl implements Individual {
try { try {
moniker = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().MONIKER); moniker = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().MONIKER);
if (moniker == null) { if (moniker == null) {
try { //Changing behavior to moniker because it is taking extra time to get the vclass
// trying to deal with the fact that an entity may have more than 1 VClass //alternative if the moniker isn't filled out. That time is wasted if the vclass alternative isn't desired.
List<VClass> clasList = this.getVClasses(true); //see NIHVIVO-2001
if (clasList == null || clasList.size() < 2) { moniker = "";
moniker = getVClass().getName();
} else {
VClass preferredClass = null;
for (VClass clas : clasList) {
if (clas.getCustomDisplayView() != null && clas.getCustomDisplayView().length()>0) {
// arbitrarily deciding that the preferred class (could be >1) is one with a custom view
preferredClass = clas;
log.debug("Found direct class ["+clas.getName()+"] with custom view "+clas.getCustomDisplayView()+"; resetting entity vClass to this class");
}
}
if (preferredClass == null) {
// no basis for selecting a preferred class name to use
moniker = null; // was this.getVClass().getName();
} else {
moniker = preferredClass.getName();
}
}
} catch (Exception e) {}
} }
return moniker; return moniker;
} finally { } finally {
@ -1043,7 +1025,7 @@ public class IndividualJena extends IndividualImpl implements Individual {
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
} }
} }

View file

@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,30 +18,29 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.util.iterator.ClosableIterator;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
@ -59,6 +56,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils; import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
@ -72,12 +70,17 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private Float _searchBoostJena = null; private Float _searchBoostJena = null;
private boolean retreivedNullRdfsLabel = false; private boolean retreivedNullRdfsLabel = false;
private DatasetWrapperFactory dwf = null; private DatasetWrapperFactory dwf = null;
private SDBDatasetMode datasetMode =
SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
private String individualURI = null; private String individualURI = null;
private Model model = null; private Model model = null;
private Boolean _hasThumb = null;
public IndividualSDB(String individualURI, public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory, DatasetWrapperFactory datasetWrapperFactory,
WebappDaoFactoryJena wadf, Model initModel) { SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf,
Model initModel) {
this.individualURI = individualURI; this.individualURI = individualURI;
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
@ -114,9 +117,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
public IndividualSDB(String individualURI, public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory, DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf, WebappDaoFactoryJena wadf,
boolean skipInitialization) { boolean skipInitialization) {
this.individualURI = individualURI; this.individualURI = individualURI;
this.datasetMode = datasetMode;
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
if (skipInitialization) { if (skipInitialization) {
@ -132,19 +137,18 @@ public class IndividualSDB extends IndividualImpl implements Individual {
"CONSTRUCT " + "CONSTRUCT " +
"{ <"+individualURI+"> <" + RDFS.label.getURI() + "{ <"+individualURI+"> <" + RDFS.label.getURI() +
"> ?ooo. \n" + "> ?ooo. \n" +
"<"+individualURI+"> a ?type . \n" + // "<"+individualURI+"> a ?type . \n" +
"<"+individualURI+"> <" + VitroVocabulary.MONIKER + "<"+individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker \n" + "> ?moniker \n" +
"} WHERE {" + "} WHERE {" +
"{ GRAPH ?g { \n" +
"{ <"+individualURI+"> <" + RDFS.label.getURI() + "{ <"+individualURI+"> <" + RDFS.label.getURI() +
"> ?ooo } \n" + "> ?ooo } \n" +
"UNION { GRAPH ?h { <" + "UNION { <" +
individualURI+"> <" + VitroVocabulary.MONIKER + individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker } } \n" + "> ?moniker \n" +
"} } \n" + "} \n" +
"UNION { GRAPH ?i { <" // "UNION { <"
+ individualURI + "> a ?type } } \n" + // + individualURI + "> a ?type } \n" +
"}"; "}";
model = QueryExecutionFactory.create( model = QueryExecutionFactory.create(
QueryFactory.create(getStatements), dataset) QueryFactory.create(getStatements), dataset)
@ -157,20 +161,50 @@ public class IndividualSDB extends IndividualImpl implements Individual {
OntModel ontModel = ModelFactory.createOntologyModel( OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM, model); OntModelSpec.OWL_MEM, model);
if (model.isEmpty() && noTriplesFor(individualURI)) {
throw new IndividualNotFoundException();
}
this.ind = ontModel.createOntResource(individualURI); this.ind = ontModel.createOntResource(individualURI);
} }
setUpURIParts(ind); setUpURIParts(ind);
this.webappDaoFactory = wadf; this.webappDaoFactory = wadf;
} }
private static final boolean SKIP_INITIALIZATION = true; private boolean noTriplesFor(String individualURI) {
String ask = "ASK { <" + individualURI + "> ?p ?o }";
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
Query askQuery = QueryFactory.create(ask, Syntax.syntaxARQ);
QueryExecution qe = QueryExecutionFactory.create(askQuery, dataset);
try {
return !qe.execAsk();
} finally {
qe.close();
}
} finally {
dataset.getLock().leaveCriticalSection();
w.close();
}
}
static final boolean SKIP_INITIALIZATION = true;
public IndividualSDB(String individualURI, public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory, DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) { WebappDaoFactoryJena wadf) {
this(individualURI, datasetWrapperFactory, wadf, !SKIP_INITIALIZATION); this(individualURI,
datasetWrapperFactory,
datasetMode,
wadf,
!SKIP_INITIALIZATION);
} }
public class IndividualNotFoundException extends RuntimeException {}
private void setUpURIParts(OntResource ind) { private void setUpURIParts(OntResource ind) {
if (ind != null) { if (ind != null) {
if (ind.isAnon()) { if (ind.isAnon()) {
@ -293,8 +327,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
int portalid = FlagMathUtils.numeric2Portalid(numericPortal); int portalid = FlagMathUtils.numeric2Portalid(numericPortal);
String portalTypeUri = VitroVocabulary.vitroURI + String portalTypeUri = VitroVocabulary.vitroURI +
"Flag1Value" + portalid + "Thing"; "Flag1Value" + portalid + "Thing";
String Ask = "ASK { GRAPH ?g { <" + this.individualURI + String Ask = "ASK { <" + this.individualURI +
"> <" +RDF.type+ "> <" + portalTypeUri +">} }"; "> <" +RDF.type+ "> <" + portalTypeUri +">} ";
if(!QueryExecutionFactory.create( if(!QueryExecutionFactory.create(
QueryFactory.create(Ask), dataset).execAsk()) { QueryFactory.create(Ask), dataset).execAsk()) {
return false; return false;
@ -308,162 +342,208 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
private void doFlag1() { private void doFlag1() {
String getObjects = null; if( webappDaoFactory.getPortalDao().isSinglePortal() ){
Model tempModel = ModelFactory.createDefaultModel(); flag1Set = "0";
OntModel ontModel = ModelFactory.createOntologyModel( flag1Numeric = 1;
OntModelSpec.OWL_MEM); }else{
DatasetWrapper w = getDatasetWrapper(); String getObjects = null;
Dataset dataset = w.getDataset(); Model tempModel = ModelFactory.createDefaultModel();
dataset.getLock().enterCriticalSection(Lock.READ); OntModel ontModel = ModelFactory.createOntologyModel(
try { OntModelSpec.OWL_MEM);
ClosableIterator typeIt = null; DatasetWrapper w = getDatasetWrapper();
int portalNumeric = 0; Dataset dataset = w.getDataset();
String portalSet = ""; dataset.getLock().enterCriticalSection(Lock.READ);
try{ try {
getObjects = ClosableIterator typeIt = null;
"CONSTRUCT{<" + this.individualURI + "> <" + int portalNumeric = 0;
RDF.type + "> ?object}" + String portalSet = "";
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + try{
RDF.type + "> ?object} }"; getObjects =
tempModel = QueryExecutionFactory.create( "CONSTRUCT{<" + this.individualURI + "> <" +
QueryFactory.create( RDF.type + "> ?object}" +
getObjects), dataset).execConstruct(); "WHERE{ <" + this.individualURI + "> <" +
ontModel.add(tempModel.listStatements()); RDF.type + "> ?object }";
OntResource ontRes = ontModel.createOntResource( tempModel = QueryExecutionFactory.create(
this.individualURI); QueryFactory.create(
typeIt = ontRes.getOntModel().listStatements( getObjects), dataset).execConstruct();
ontRes, RDF.type ,(String) null); ontModel.add(tempModel.listStatements());
while (typeIt.hasNext()) { OntResource ontRes = ontModel.createOntResource(
Statement stmt = (Statement) typeIt.next(); this.individualURI);
Resource type = (Resource)stmt.getObject(); typeIt = ontRes.getOntModel().listStatements(
String typeName = type.getLocalName(); ontRes, RDF.type ,(String) null);
if(type.getNameSpace() != null while (typeIt.hasNext()) {
&& type.getNameSpace().equals( Statement stmt = (Statement) typeIt.next();
VitroVocabulary.vitroURI) Resource type = (Resource)stmt.getObject();
&& typeName.indexOf("Flag1Value")==0) { String typeName = type.getLocalName();
try { if(type.getNameSpace() != null
int portalNumber = Integer.decode( && type.getNameSpace().equals(
typeName.substring(10,typeName.length()-5)); VitroVocabulary.vitroURI)
portalNumeric = portalNumeric | (1 << portalNumber); && typeName.indexOf("Flag1Value")==0) {
if (portalSet.length() > 0) { try {
portalSet+=","; int portalNumber = Integer.decode(
typeName.substring(10,typeName.length()-5));
portalNumeric = portalNumeric | (1 << portalNumber);
if (portalSet.length() > 0) {
portalSet+=",";
}
portalSet+=Integer.toString(portalNumber);
} catch (Exception e) {
log.warn("could not convert into a " +
"portal id:'" + typeName + "' " + e.getMessage());
} }
portalSet+=Integer.toString(portalNumber); }
} catch (Exception e) {}
} }
}finally{
if( typeIt != null ) typeIt.close() ;
} }
}finally{ flag1Set = portalSet;
if( typeIt != null ) typeIt.close() ; flag1Numeric = portalNumeric;
} } finally {
flag1Set = portalSet; tempModel.close();
flag1Numeric = portalNumeric; ontModel.close();
} finally { dataset.getLock().leaveCriticalSection();
tempModel.close(); w.close();
ontModel.close(); }
dataset.getLock().leaveCriticalSection();
w.close();
} }
} }
private void doFlag2() { private void doFlag2() {
String getObjects = null; if( webappDaoFactory.getPortalDao().isSinglePortal() ){
Model tempModel = ModelFactory.createDefaultModel(); flag2Set = "";
OntModel ontModel = ModelFactory.createOntologyModel( flag2Numeric = 0 ;
OntModelSpec.OWL_MEM); }else{
DatasetWrapper w = getDatasetWrapper(); String getObjects = null;
Dataset dataset = w.getDataset(); Model tempModel = ModelFactory.createDefaultModel();
dataset.getLock().enterCriticalSection(Lock.READ); OntModel ontModel = ModelFactory.createOntologyModel(
try { OntModelSpec.OWL_MEM);
ClosableIterator typeIt=null; DatasetWrapper w = getDatasetWrapper();
String flagSet = ""; Dataset dataset = w.getDataset();
try{ dataset.getLock().enterCriticalSection(Lock.READ);
getObjects = try {
"CONSTRUCT{<" + this.individualURI + "> <" + ClosableIterator typeIt=null;
RDF.type + "> ?object}" + String flagSet = "";
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + try{
RDF.type + "> ?object} }"; getObjects =
tempModel = QueryExecutionFactory.create( "CONSTRUCT{<" + this.individualURI + "> <" +
QueryFactory.create( RDF.type + "> ?object}" +
getObjects), dataset).execConstruct(); "WHERE{ <" + this.individualURI + "> <" +
ontModel.add(tempModel.listStatements()); RDF.type + "> ?object }";
OntResource ontRes = ontModel.createOntResource( tempModel = QueryExecutionFactory.create(
this.individualURI); QueryFactory.create(
typeIt = ontRes.getOntModel().listStatements( getObjects), dataset).execConstruct();
ontRes, RDF.type ,(String) null); ontModel.add(tempModel.listStatements());
while (typeIt.hasNext()) { OntResource ontRes = ontModel.createOntResource(
Statement stmt = (Statement) typeIt.next(); this.individualURI);
Resource type = (Resource)stmt.getObject(); typeIt = ontRes.getOntModel().listStatements(
String typeName = type.getLocalName(); ontRes, RDF.type ,(String) null);
if(type.getNameSpace() != null while (typeIt.hasNext()) {
&& type.getNameSpace().equals( Statement stmt = (Statement) typeIt.next();
VitroVocabulary.vitroURI) Resource type = (Resource)stmt.getObject();
&& typeName.indexOf("Flag2Value")==0) { String typeName = type.getLocalName();
try { if(type.getNameSpace() != null
String flagValue = && type.getNameSpace().equals(
((WebappDaoFactoryJena) webappDaoFactory) VitroVocabulary.vitroURI)
.getFlag2ClassLabelMap().get(type); && typeName.indexOf("Flag2Value")==0) {
if (flagSet.length() > 0) { try {
flagSet+=","; String flagValue =
((WebappDaoFactoryJena) webappDaoFactory)
.getFlag2ClassLabelMap().get(type);
if (flagSet.length() > 0) {
flagSet+=",";
}
flagSet+=flagValue;
} catch (Exception e) {
log.error(e,e);
} }
flagSet+=flagValue; }
} catch (Exception e) {} }
}finally{
if( typeIt != null ) typeIt.close() ;
}
flag2Set = flagSet;
} finally {
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
}
}
}
public Date getSunrise() {
if( this.sunrise == null ){
String[] graphVars = { "?g" };
String queryStr =
"SELECT ?value " +
"WHERE { GRAPH ?g { <" + individualURI + "> " +
"<" + webappDaoFactory.getJenaBaseDao().SUNRISE + "> " +
"?value} \n" +
//WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try{
ResultSet rs = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset)
.execSelect();
if( rs.hasNext()){
QuerySolution qs = rs.nextSolution();
if( qs.get("value") != null ){
Literal value = qs.get("value").asLiteral();
RDFDatatype datatype = value.getDatatype();
XSDDateTime xsdDt = (XSDDateTime)datatype.parse( value.getLexicalForm() );
sunrise = xsdDt.asCalendar().getTime();
}
}
}catch(Exception ex){
log.error("could not get sunrise: " + ex.getMessage(),ex);
}finally{
dataset.getLock().leaveCriticalSection();
w.close();
}
}
return sunrise;
}
public Date getSunset() {
if( this.sunset == null ){
String[] graphVars = { "?g" };
String queryStr =
"SELECT ?value " +
"WHERE { GRAPH ?g { <" + individualURI + "> " +
"<"+webappDaoFactory.getJenaBaseDao().SUNSET+"> ?value} }";
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try{
ResultSet rs = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset)
.execSelect();
if( rs.hasNext()){
QuerySolution qs = rs.nextSolution();
if( qs.get("value") != null ){
Literal value = qs.get("value").asLiteral();
RDFDatatype datatype = value.getDatatype();
XSDDateTime xsdDt = (XSDDateTime)datatype.parse( value.getLexicalForm() );
sunset = xsdDt.asCalendar().getTime();
} }
} }
}catch(Exception ex){
log.error("could not get sunset: " + ex.getMessage(),ex);
}finally{ }finally{
if( typeIt != null ) typeIt.close() ; dataset.getLock().leaveCriticalSection();
w.close();
} }
flag2Set = flagSet; }
} finally { return sunset;
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
}
}
public Date getSunrise() {
if (sunrise != null) {
return sunrise;
} else {
ind.getOntModel().enterCriticalSection(Lock.READ);
try {
sunrise = webappDaoFactory.getJenaBaseDao()
.getPropertyDateTimeValue(
ind,webappDaoFactory.getJenaBaseDao().SUNRISE);
return sunrise;
} finally {
ind.getOntModel().leaveCriticalSection();
}
}
}
public Date getSunset() {
if (sunset != null) {
return sunset;
} else {
ind.getOntModel().enterCriticalSection(Lock.READ);
try {
sunset = webappDaoFactory.getJenaBaseDao()
.getPropertyDateTimeValue(
ind,webappDaoFactory.getJenaBaseDao().SUNSET);
return sunset;
} finally {
ind.getOntModel().leaveCriticalSection();
}
}
} }
public Date getTimekey() { public Date getTimekey() {
if (timekey != null) { if (timekey != null) {
return timekey; return timekey;
} else { } else {
constructProperty(ind, VitroVocabulary.TIMEKEY);
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
timekey = webappDaoFactory.getJenaBaseDao() timekey = webappDaoFactory.getJenaBaseDao()
@ -508,41 +588,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
.getPropertyStringValue( .getPropertyStringValue(
ind,webappDaoFactory.getJenaBaseDao().MONIKER); ind,webappDaoFactory.getJenaBaseDao().MONIKER);
if (moniker == null) { if (moniker == null) {
try { //Changing behavior to moniker because it is taking extra time to get the vclass
// trying to deal with the fact that an entity //alternative if the moniker isn't filled out. That time is wasted if the vclass alternative isn't desired.
// may have more than 1 VClass //see NIHVIVO-2001
List<VClass> clasList = this.getVClasses(true); moniker = "";
if (clasList == null || clasList.size() < 2) { }
moniker = getVClass().getName();
} else {
VClass preferredClass = null;
for (VClass clas : clasList) {
if (clas.getCustomDisplayView() != null
&& clas.getCustomDisplayView()
.length()>0) {
// arbitrarily deciding that the
// preferred class (could be >1)
// is one with a custom view
preferredClass = clas;
log.debug("Found direct class [" +
clas.getName() +
"] with custom view " +
clas.getCustomDisplayView() +
"; resetting entity vClass " +
"to this class");
}
}
if (preferredClass == null) {
// no basis for selecting a preferred
// class name to use
moniker = null;
// was this.getVClass().getName();
} else {
preferredClass.getName();
}
}
} catch (Exception e) {}
}
return moniker; return moniker;
} finally { } finally {
ind.getOntModel().leaveCriticalSection(); ind.getOntModel().leaveCriticalSection();
@ -554,7 +604,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (this.blurb != null) { if (this.blurb != null) {
return blurb; return blurb;
} else { } else {
constructProperty(ind, VitroVocabulary.BLURB);
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
blurb = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().BLURB); blurb = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().BLURB);
@ -570,7 +620,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (this.description != null) { if (this.description != null) {
return description; return description;
} else { } else {
constructProperty(ind, VitroVocabulary.DESCRIPTION);
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
description = webappDaoFactory.getJenaBaseDao() description = webappDaoFactory.getJenaBaseDao()
@ -584,34 +634,68 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
} }
private synchronized void constructProperty(OntResource ind, String propertyURI) {
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
String[] graphVars = { "?g" };
String queryStr =
"CONSTRUCT { <"+ind.getURI()+"> <" + propertyURI + "> ?value } \n" +
"WHERE { GRAPH ?g { \n" +
"<" + ind.getURI() +"> <" + propertyURI + "> ?value } \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"\n} ";
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(
query, dataset);
qe.execConstruct(ind.getModel());
} finally {
dataset.getLock().leaveCriticalSection();
w.close();
}
}
public Float getSearchBoost(){ public Float getSearchBoost(){
if( this._searchBoostJena != null ){ if( this._searchBoostJena != null ){
return this._searchBoostJena; return this._searchBoostJena;
}else{ }else{
String[] graphVars = { "?g" };
String getPropertyValue = String getPropertyValue =
"SELECT ?value" + "SELECT ?value \n" +
"WHERE { GRAPH ?g { <" + individualURI + ">" + "WHERE { GRAPH ?g { \n" +
webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT + "<" +individualURI+ "> <" +webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT+ "> ?value }\n" +
"?value} }"; WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + "\n" +
"}";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try{ try{
try { ResultSet rs = QueryExecutionFactory.create(
searchBoost = QueryFactory.create(getPropertyValue),
((Literal)QueryExecutionFactory.create( dataset).execSelect();
QueryFactory.create(getPropertyValue), dataset)
.execSelect()).getFloat(); if(rs.hasNext()){
} catch (Exception e) { QuerySolution qs = rs.nextSolution();
searchBoost = null; if(qs.get("value") !=null){
} Literal value = qs.get("value").asLiteral();
return searchBoost; searchBoost = Float.parseFloat(value.getLexicalForm());
return searchBoost;
}
}
else{
return null;
}
} catch (Exception e){
log.error(e,e);
return null;
}finally{ }finally{
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();
} }
} }
return null;
} }
@Override @Override
@ -660,6 +744,35 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.imageInfo.getThumbnail().getBytestreamAliasUrl(); return this.imageInfo.getThumbnail().getBytestreamAliasUrl();
} }
@Override
public boolean hasThumb(){
if( _hasThumb != null ){
return _hasThumb;
}else{
String[] graphVars = { "?g" };
String ask =
"ASK { GRAPH ?g " +
" { <" + individualURI + "> <http://vitro.mannlib.cornell.edu/ns/vitro/public#mainImage> ?mainImage . \n" +
" ?mainImage <http://vitro.mannlib.cornell.edu/ns/vitro/public#thumbnailImage> ?thumbImage . }\n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try{
_hasThumb = QueryExecutionFactory.create(QueryFactory.create(ask), dataset).execAsk();
}catch(Exception ex){
_hasThumb = false;
log.error(ex,ex);
}finally{
dataset.getLock().leaveCriticalSection();
w.close();
}
return _hasThumb;
}
}
public String getAnchor() { public String getAnchor() {
if (this.anchor != null) { if (this.anchor != null) {
return anchor; return anchor;
@ -686,6 +799,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String graphVars[] = { "?g" };
StringBuffer selectPrimaryLinkQueryBuff = new StringBuffer().append( StringBuffer selectPrimaryLinkQueryBuff = new StringBuffer().append(
"SELECT ?url ?anchor \n" ).append( "SELECT ?url ?anchor \n" ).append(
"WHERE{ GRAPH ?g { \n " ).append( "WHERE{ GRAPH ?g { \n " ).append(
@ -696,7 +810,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
).append( ).append(
" ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n" " ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n"
).append( ).append(
"} }"); "} \n")
.append(WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode))
.append("}");
QueryExecution qexec = QueryExecutionFactory.create( QueryExecution qexec = QueryExecutionFactory.create(
QueryFactory.create(selectPrimaryLinkQueryBuff.toString()) QueryFactory.create(selectPrimaryLinkQueryBuff.toString())
, dataset); , dataset);
@ -809,9 +925,12 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = { "?g" };
String valuesOfProperty = String valuesOfProperty =
"CONSTRUCT{<" + this.individualURI + "> <" + propertyURI + "> ?object}" + "CONSTRUCT{<" + this.individualURI + "> <" + propertyURI + "> ?object}" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }"; "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
tempModel = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execConstruct(); tempModel = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execConstruct();
ontModel.add(tempModel.listStatements()); ontModel.add(tempModel.listStatements());
Resource ontRes = ontModel.getResource(this.individualURI); Resource ontRes = ontModel.getResource(this.individualURI);
@ -821,8 +940,8 @@ 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, webappDaoFactory); Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), this.dwf, datasetMode, webappDaoFactory);
Individual obj = new IndividualSDB(((OntResource) s.getObject().as(OntResource.class)).getURI(), this.dwf, webappDaoFactory); Individual obj = new IndividualSDB(((OntResource) s.getObject().as(OntResource.class)).getURI(), this.dwf, datasetMode, webappDaoFactory);
ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI()); ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI());
if (subj != null && obj != null && op != null) { if (subj != null && obj != null && op != null) {
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(); ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
@ -855,10 +974,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = { "?g" };
String valuesOfProperty = String valuesOfProperty =
"SELECT ?object" + "SELECT ?object" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
propertyURI + "> ?object} }"; propertyURI + "> ?object} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
ResultSet values = QueryExecutionFactory.create( ResultSet values = QueryExecutionFactory.create(
QueryFactory.create(valuesOfProperty), dataset) QueryFactory.create(valuesOfProperty), dataset)
.execSelect(); .execSelect();
@ -871,7 +993,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
new IndividualSDB( new IndividualSDB(
((OntResource) value.as(OntResource.class)) ((OntResource) value.as(OntResource.class))
.getURI(), .getURI(),
this.dwf, webappDaoFactory) ); this.dwf,
datasetMode,
webappDaoFactory) );
} }
} }
} finally { } finally {
@ -890,21 +1014,30 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = { "?g" };
String valueOfProperty = String valueOfProperty =
"SELECT ?object" + "SELECT ?object " +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
propertyURI + "> ?object} }"; propertyURI + "> ?object} \n" +
ResultSet results = QueryExecutionFactory.create( WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
QueryFactory.create(valueOfProperty), dataset).execSelect(); "}";
QuerySolution result = results.next(); QueryExecution qe = QueryExecutionFactory.create(
RDFNode value = result.get("object"); QueryFactory.create(valueOfProperty), dataset);
if (value != null && value.canAs(OntResource.class)) { try {
return new IndividualSDB( ResultSet results = qe.execSelect();
((OntResource) value.as(OntResource.class)).getURI(), if (results.hasNext()) {
dwf, webappDaoFactory); QuerySolution result = results.next();
} else { RDFNode value = result.get("object");
return null; if (value != null && value.canAs(OntResource.class)) {
} return new IndividualSDB(
((OntResource) value.as(OntResource.class)).getURI(),
dwf, datasetMode, webappDaoFactory);
}
}
return null;
} finally {
qe.close();
}
} finally { } finally {
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();
@ -1070,8 +1203,14 @@ public class IndividualSDB extends IndividualImpl implements Individual {
((direct) ((direct)
? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>" ? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>"
: "?g") : "?g")
+ " { <" + this.individualURI +"> <" +RDF.type+ "> ?types \n" + + " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n" ;
"} } \n";
if (!direct) {
String[] graphVars = { "?g" };
getTypes += WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode);
}
getTypes += "} \n";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
@ -1306,7 +1445,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
} }
} }

View file

@ -142,7 +142,6 @@ public class JenaBaseDao extends JenaBaseDaoCon {
protected void addPropertyStringValue(Resource res, Property dataprop, String value, Model model) { protected void addPropertyStringValue(Resource res, Property dataprop, String value, Model model) {
if (res != null && dataprop != null && value != null && value.length()>0) { if (res != null && dataprop != null && value != null && value.length()>0) {
model.add(res, dataprop, value, XSDDatatype.XSDstring); model.add(res, dataprop, value, XSDDatatype.XSDstring);
System.out.println("JenaBaseDao" + value);
} }
} }
@ -476,7 +475,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error in updatePropertyDateTimeValue"); log.error("Error in updatePropertyDateTimeValue");
log.error(e); log.error(e, e);
} }
} }
@ -657,9 +656,10 @@ public class JenaBaseDao extends JenaBaseDaoCon {
label = tryPropertyForPreferredLanguages( r, RDFS.label, ALSO_TRY_NO_LANG ); label = tryPropertyForPreferredLanguages( r, RDFS.label, ALSO_TRY_NO_LANG );
// try vitro:label with preferred languages // try vitro:label with preferred languages
if ( label == null ) { // Commenting out for NIHVIVO-1962
/* if ( label == null ) {
label = tryPropertyForPreferredLanguages( r, r.getModel().getProperty(VitroVocabulary.label), ALSO_TRY_NO_LANG ); label = tryPropertyForPreferredLanguages( r, r.getModel().getProperty(VitroVocabulary.label), ALSO_TRY_NO_LANG );
} } */
} finally { } finally {
r.getOntModel().leaveCriticalSection(); r.getOntModel().leaveCriticalSection();
} }

View file

@ -148,8 +148,12 @@ public class JenaModelUtils {
private final OntModelSpec DEFAULT_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM; private final OntModelSpec DEFAULT_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
public OntModel extractTBox( Model inputModel) { public OntModel extractTBox( Model inputModel) {
Dataset dataset = DatasetFactory.create(inputModel); return extractTBox(inputModel, null);
return extractTBox( dataset,null,null ); }
public OntModel extractTBox( Model inputModel, String namespace ) {
Dataset dataset = DatasetFactory.create(inputModel);
return extractTBox( dataset, namespace, null );
} }
public OntModel extractTBox( Dataset dataset, String namespace, String graphURI ) { public OntModel extractTBox( Dataset dataset, String namespace, String graphURI ) {
@ -242,11 +246,11 @@ private final OntModelSpec DEFAULT_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
public Model extractABox(Model inputModel){ public Model extractABox(Model inputModel){
Dataset dataset = DatasetFactory.create(inputModel); Dataset dataset = DatasetFactory.create(inputModel);
return extractABox(dataset, null); return extractABox(dataset, null, null);
} }
public Model extractABox( Dataset dataset, String graphURI ) { public Model extractABox( Dataset unionDataset, Dataset baseOrInfDataset, String graphURI ) {
Model aboxModel = ModelFactory.createDefaultModel(); Model aboxModel = ModelFactory.createDefaultModel();
// iterate through all classes and DESCRIBE each of their instances // iterate through all classes and DESCRIBE each of their instances
@ -257,45 +261,44 @@ private final OntModelSpec DEFAULT_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
//OntModel ontModel = ( inputModel instanceof OntModel ) //OntModel ontModel = ( inputModel instanceof OntModel )
//? (OntModel)inputModel //? (OntModel)inputModel
//: ModelFactory.createOntologyModel( DEFAULT_ONT_MODEL_SPEC, inputModel ); //: ModelFactory.createOntologyModel( DEFAULT_ONT_MODEL_SPEC, inputModel );
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel ontModel = extractTBox(unionDataset, null, graphURI);
Model model = ModelFactory.createDefaultModel();
String getStatements =
"CONSTRUCT " +
"{ ?p ?o ?a \n" +
"} WHERE {" +
"GRAPH ?g { \n" +
"{ ?p ?o ?a } \n" +
"} \n" +
"}";
try{
dataset.getLock().enterCriticalSection(Lock.READ);
model = QueryExecutionFactory.create(QueryFactory.create(getStatements), dataset).execConstruct();
}
finally{
dataset.getLock().leaveCriticalSection();
}
ontModel.add(model.listStatements());
try { try {
ontModel.enterCriticalSection(Lock.READ); ontModel.enterCriticalSection(Lock.READ);
Iterator classIt = ontModel.listNamedClasses(); Iterator classIt = ontModel.listNamedClasses();
QueryExecution qe = null;
while ( classIt.hasNext() ) { while ( classIt.hasNext() ) {
OntClass ontClass = (OntClass) classIt.next(); OntClass ontClass = (OntClass) classIt.next();
if ( !(ontClass.getNameSpace().startsWith(OWL.getURI()) ) //if ( !(ontClass.getNameSpace().startsWith(OWL.getURI()) )
&& !(ontClass.getNameSpace().startsWith(VitroVocabulary.vitroURI)) ) { // && !(ontClass.getNameSpace().startsWith(VitroVocabulary.vitroURI)) ) {
if(!(ontClass.getNameSpace().startsWith(OWL.getURI()))){
String queryStr = makeDescribeQueryStr( ontClass.getURI(), null, graphURI ); String queryStr = makeDescribeQueryStr( ontClass.getURI(), null, graphURI );
Query aboxSparqlQuery = QueryFactory.create(queryStr); Query aboxSparqlQuery = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(aboxSparqlQuery,dataset); if(baseOrInfDataset != null){
try { qe = QueryExecutionFactory.create(aboxSparqlQuery,baseOrInfDataset);
dataset.getLock().enterCriticalSection(Lock.READ); }
qe.execDescribe(aboxModel); // puts the statements about each resource into aboxModel. else{
} finally { qe = QueryExecutionFactory.create(aboxSparqlQuery,unionDataset);
dataset.getLock().leaveCriticalSection(); }
if(baseOrInfDataset != null){
try {
baseOrInfDataset.getLock().enterCriticalSection(Lock.READ);
qe.execDescribe(aboxModel); // puts the statements about each resource into aboxModel.
} finally {
baseOrInfDataset.getLock().leaveCriticalSection();
}
}
else{
try {
unionDataset.getLock().enterCriticalSection(Lock.READ);
qe.execDescribe(aboxModel); // puts the statements about each resource into aboxModel.
} finally {
unionDataset.getLock().leaveCriticalSection();
}
} }
} }

View file

@ -155,7 +155,7 @@ public class KeywordDaoJena extends JenaBaseDao implements KeywordDao {
try { try {
keywordURI = webappDaoFactory.getIndividualDao().insertNewIndividual(keywordIndividual); keywordURI = webappDaoFactory.getIndividualDao().insertNewIndividual(keywordIndividual);
} catch (InsertException e) { } catch (InsertException e) {
log.error(e); log.error(e, e);
} }
log.debug("KeywordDaoJena.insertNewKeyword() : "+keywordURI); log.debug("KeywordDaoJena.insertNewKeyword() : "+keywordURI);

View file

@ -189,7 +189,7 @@ public class ModelAuditor implements ModelChangedListener {
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
} }
} }

View file

@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
public class ModelContext { public class ModelContext {
@ -75,4 +76,26 @@ public class ModelContext {
ctx.setAttribute(INFERENCE_ONT_MODEL, ontModel); ctx.setAttribute(INFERENCE_ONT_MODEL, ontModel);
} }
/**
* Register a listener to the models needed to get changes to:
* class membership
* inferred class membership
* class group membership,
* object properties,
* data properties,
* inferred object properties,
* rdfs:label annotations
* This listener does not need:
* other annotations
* change to TBox
*/
public static void registerListenerForChanges(ServletContext ctx, ModelChangedListener ml){
ModelContext.getJenaOntModel(ctx).register(ml);
ModelContext.getBaseOntModel(ctx).register(ml);
ModelContext.getInferenceOntModel(ctx).register(ml);
ModelContext.getUnionOntModelSelector(ctx).getABoxModel().register(ml);
ModelContext.getBaseOntModelSelector(ctx).getABoxModel().register(ml);
ModelContext.getInferenceOntModelSelector(ctx).getABoxModel().register(ml);
}
} }

View file

@ -53,15 +53,11 @@ import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectPropertyDao { public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectPropertyDao {
private static final Log log = LogFactory.getLog(ObjectPropertyDaoJena.class.getName()); private static final Log log = LogFactory.getLog(ObjectPropertyDaoJena.class.getName());
/* This may be the intent behind JenaBaseDao.NONUSER_NAMESPACES, but that
* value does not contain all of these namespaces.
*/
protected static final List<String> EXCLUDED_NAMESPACES = Arrays.asList( protected static final List<String> EXCLUDED_NAMESPACES = Arrays.asList(
//"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#", // Don't need to exclude these, because they are not owl:ObjectProperty
//"http://vitro.mannlib.cornell.edu/ns/vitro/public#", //"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#", //"http://www.w3.org/2000/01/rdf-schema#",
"http://www.w3.org/2000/01/rdf-schema#",
"http://www.w3.org/2002/07/owl#" "http://www.w3.org/2002/07/owl#"
); );
/* /*
@ -75,43 +71,43 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
namespaceFilters.add("(afn:namespace(?property) != \"" + s + "\")"); namespaceFilters.add("(afn:namespace(?property) != \"" + s + "\")");
} }
// A hack to include the vitro:primaryLink and vitro:additionalLink properties in the list // A hack to include the vitro:primaryLink and vitro:additionalLink properties in the list
namespaceFilters.add("( ?property = <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#primaryLink> ||" + namespaceFilters.add("( ?property = vitro:primaryLink ||" +
"?property = <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#additionalLink> ||" + "?property = vitro:additionalLink ||" +
"afn:namespace(?property) != \"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#\" )"); "afn:namespace(?property) != \"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#\" )");
propertyFilters = "FILTER (" + StringUtils.join(namespaceFilters, " && ") + ")\n"; propertyFilters = "FILTER (" + StringUtils.join(namespaceFilters, " && ") + ")\n";
} }
protected static final String objectPropertyQueryString = protected static final String OBJECT_PROPERTY_QUERY_STRING =
PREFIXES + "\n" + prefixes + "\n" +
"SELECT DISTINCT ?property WHERE { \n" + "SELECT DISTINCT ?property WHERE { \n" +
" GRAPH ?g1 { ?subject ?property ?object } \n" + " GRAPH ?g1 { ?subject ?property ?object } \n" +
" GRAPH ?g2 { ?property rdf:type owl:ObjectProperty } \n" + " GRAPH ?g2 { ?property rdf:type owl:ObjectProperty } \n" +
propertyFilters + propertyFilters +
"}"; "}";
static protected Query objectPropertyQuery; protected static Query objectPropertyQuery;
static { static {
try { try {
objectPropertyQuery = QueryFactory.create(objectPropertyQueryString); objectPropertyQuery = QueryFactory.create(OBJECT_PROPERTY_QUERY_STRING);
} catch(Throwable th){ } catch(Throwable th){
log.error("could not create SPARQL query for objectPropertyQueryString " + th.getMessage()); log.error("could not create SPARQL query for OBJECT_PROPERTY_QUERY_STRING " + th.getMessage());
log.error(objectPropertyQueryString); log.error(OBJECT_PROPERTY_QUERY_STRING);
} }
} }
static protected String listViewConfigFileQueryString = protected static final String LIST_VIEW_CONFIG_FILE_QUERY_STRING =
"PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#>" + "PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#>" +
"SELECT ?property ?filename WHERE { \n" + "SELECT ?property ?filename WHERE { \n" +
" ?property display:listViewConfigFile ?filename . \n" + " ?property display:listViewConfigFile ?filename . \n" +
"}"; "}";
static protected Query listViewConfigFileQuery; protected static Query listViewConfigFileQuery;
static { static {
try { try {
listViewConfigFileQuery = QueryFactory.create(listViewConfigFileQueryString); listViewConfigFileQuery = QueryFactory.create(LIST_VIEW_CONFIG_FILE_QUERY_STRING);
} catch(Throwable th){ } catch(Throwable th){
log.error("could not create SPARQL query for listViewConfigFileQueryString " + th.getMessage()); log.error("could not create SPARQL query for LIST_VIEW_CONFIG_FILE_QUERY_STRING " + th.getMessage());
log.error(listViewConfigFileQueryString); log.error(LIST_VIEW_CONFIG_FILE_QUERY_STRING);
} }
} }
@ -888,9 +884,9 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
* into the new one in a future release. * into the new one in a future release.
*/ */
public List<ObjectProperty> getObjectPropertyList(String subjectUri) { public List<ObjectProperty> getObjectPropertyList(String subjectUri) {
log.debug("objectPropertyQueryString:\n" + objectPropertyQueryString); log.debug("Object property query string:\n" + OBJECT_PROPERTY_QUERY_STRING);
log.debug("objectPropertyQuery:\n" + objectPropertyQuery); log.debug("Object property query:\n" + objectPropertyQuery);
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery); Iterator<QuerySolution> results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
List<ObjectProperty> properties = new ArrayList<ObjectProperty>(); List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
while (results.hasNext()) { while (results.hasNext()) {
QuerySolution soln = results.next(); QuerySolution soln = results.next();

View file

@ -3,9 +3,11 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -20,6 +22,8 @@ import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.QuerySolutionMap; import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property; 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.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
@ -246,6 +250,17 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
return 0; return 0;
} }
@Override
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri,
String propertyUri,
String queryString) {
return getObjectPropertyStatementsForIndividualByProperty(
subjectUri, propertyUri, null);
}
@Override @Override
/* /*
* SPARQL-based method for getting values related to a single object property. * SPARQL-based method for getting values related to a single object property.
@ -254,7 +269,14 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
* custom queries that could request any data in addition to just the object of the statement. * custom queries that could request any data in addition to just the object of the statement.
* However, we do need to get the object of the statement so that we have it to create editing links. * However, we do need to get the object of the statement so that we have it to create editing links.
*/ */
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String queryString) { public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri,
String propertyUri,
String queryString,
Set<String> constructQueryStrings ) {
Model constructedModel = constructModelForSelectQueries(
subjectUri, propertyUri, constructQueryStrings);
log.debug("Query string for object property " + propertyUri + ": " + queryString); log.debug("Query string for object property " + propertyUri + ": " + queryString);
@ -264,11 +286,14 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
} catch(Throwable th){ } catch(Throwable th){
log.error("Could not create SPARQL query for query string. " + th.getMessage()); log.error("Could not create SPARQL query for query string. " + th.getMessage());
log.error(queryString); log.error(queryString);
return Collections.emptyList();
} }
QuerySolutionMap bindings = new QuerySolutionMap(); // RY One oddity here is that SDB adds the bound variables to the query select terms,
bindings.add("subject", ResourceFactory.createResource(subjectUri)); // even if they're not included in the query.
bindings.add("property", ResourceFactory.createResource(propertyUri)); QuerySolutionMap initialBindings = new QuerySolutionMap();
initialBindings.add("subject", ResourceFactory.createResource(subjectUri));
initialBindings.add("property", ResourceFactory.createResource(propertyUri));
// Run the SPARQL query to get the properties // Run the SPARQL query to get the properties
List<Map<String, String>> list = new ArrayList<Map<String, String>>(); List<Map<String, String>> list = new ArrayList<Map<String, String>>();
@ -277,8 +302,13 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
QueryExecution qexec = QueryExecutionFactory.create(
query, dataset, bindings); QueryExecution qexec = (constructedModel == null)
? QueryExecutionFactory.create(
query, dataset, initialBindings)
: QueryExecutionFactory.create(
query, constructedModel, initialBindings);
ResultSet results = qexec.execSelect(); ResultSet results = qexec.execSelect();
while (results.hasNext()) { while (results.hasNext()) {
@ -293,4 +323,59 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
return list; return list;
} }
private Model constructModelForSelectQueries(String subjectUri,
String propertyUri,
Set<String> constructQueries) {
if (constructQueries == null) {
return null;
}
Model constructedModel = ModelFactory.createDefaultModel();
for (String queryString : constructQueries) {
log.debug("CONSTRUCT query string for object property " +
propertyUri + ": " + queryString);
Query query = null;
try {
query = QueryFactory.create(queryString, Syntax.syntaxARQ);
} catch(Throwable th){
log.error("Could not create CONSTRUCT SPARQL query for query " +
"string. " + th.getMessage());
log.error(queryString);
return constructedModel;
}
QuerySolutionMap initialBindings = new QuerySolutionMap();
initialBindings.add(
"subject", ResourceFactory.createResource(subjectUri));
initialBindings.add(
"property", ResourceFactory.createResource(propertyUri));
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
DatasetWrapper w = dwf.getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
QueryExecution qe = QueryExecutionFactory.create(
query, dataset, initialBindings);
try {
qe.execConstruct(constructedModel);
} finally {
qe.close();
}
} finally {
dataset.getLock().leaveCriticalSection();
w.close();
}
}
return constructedModel;
}
} }

View file

@ -27,17 +27,22 @@ 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.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualSDB.IndividualNotFoundException;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class ObjectPropertyStatementDaoSDB extends public class ObjectPropertyStatementDaoSDB extends
ObjectPropertyStatementDaoJena implements ObjectPropertyStatementDao { ObjectPropertyStatementDaoJena implements ObjectPropertyStatementDao {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public ObjectPropertyStatementDaoSDB( public ObjectPropertyStatementDaoSDB(
DatasetWrapperFactory dwf, DatasetWrapperFactory dwf,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) { WebappDaoFactoryJena wadf) {
super (dwf, wadf); super (dwf, wadf);
this.dwf = dwf; this.dwf = dwf;
this.datasetMode = datasetMode;
} }
@Override @Override
@ -48,15 +53,17 @@ public class ObjectPropertyStatementDaoSDB extends
Map<String, ObjectProperty> uriToObjectProperty = new HashMap<String,ObjectProperty>(); Map<String, ObjectProperty> uriToObjectProperty = new HashMap<String,ObjectProperty>();
String query = "CONSTRUCT { \n" + String query = "CONSTRUCT { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" + " <" + entity.getURI() + "> ?p ?o . \n" +
" ?o a ?oType . \n" + // " ?o a ?oType . \n" +
" ?o <" + RDFS.label.getURI() + "> ?oLabel . \n" + // " ?o <" + RDFS.label.getURI() + "> ?oLabel . \n" +
" ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker \n" + // " ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker \n" +
"} WHERE { GRAPH ?g { \n" + "} WHERE { \n" +
" <" + entity.getURI() + "> ?p ?o \n" + " { <" + entity.getURI() + "> ?p ?o } \n" +
" OPTIONAL { GRAPH ?h { ?o a ?oType } } \n" + // " UNION { <" + entity.getURI() + "> ?p ?o . ?o a ?oType } \n" +
" OPTIONAL { GRAPH ?i { ?o <" + RDFS.label.getURI() + "> ?oLabel } } \n" + // " UNION { <" + entity.getURI() + "> ?p ?o . \n" +
" OPTIONAL { GRAPH ?j { ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } } \n" + // " ?o <" + RDFS.label.getURI() + "> ?oLabel } \n" +
"} }"; // " UNION { <" + entity.getURI() + "> ?p ?o . \n " +
// " ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } \n" +
"}";
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
Model m = null; Model m = null;
DatasetWrapper w = dwf.getDatasetWrapper(); DatasetWrapper w = dwf.getDatasetWrapper();
@ -90,48 +97,46 @@ public class ObjectPropertyStatementDaoSDB extends
ObjectPropertyStatement objPropertyStmt = new ObjectPropertyStatementImpl(); ObjectPropertyStatement objPropertyStmt = new ObjectPropertyStatementImpl();
objPropertyStmt.setSubjectURI(entity.getURI()); objPropertyStmt.setSubjectURI(entity.getURI());
objPropertyStmt.setSubject(entity); objPropertyStmt.setSubject(entity);
try { objPropertyStmt.setObjectURI(((Resource)st.getObject()).getURI());
objPropertyStmt.setObjectURI(((Resource)st.getObject()).getURI());
} catch (Throwable t) {
t.printStackTrace();
}
objPropertyStmt.setPropertyURI(st.getPredicate().getURI()); objPropertyStmt.setPropertyURI(st.getPredicate().getURI());
try { Property prop = st.getPredicate();
Property prop = st.getPredicate(); if( uriToObjectProperty.containsKey(prop.getURI())){
if( uriToObjectProperty.containsKey(prop.getURI())){ objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI()));
objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI())); }else{
}else{ ObjectProperty p = getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURI(prop.getURI());
ObjectProperty p = getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURI(prop.getURI()); if( p != null ){
if( p != null ){ uriToObjectProperty.put(prop.getURI(), p);
uriToObjectProperty.put(prop.getURI(), p); objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI()));
objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI())); }else{
}else{ //if ObjectProperty not found in ontology, skip it
//if ObjectProperty not found in ontology, skip it continue;
continue; }
} }
}
} catch (Throwable g) {
//do not add statement to list
log.debug("exception while trying to get object property for statement list, statement skipped.", g);
continue;
}
if (objPropertyStmt.getObjectURI() != null) { if (objPropertyStmt.getObjectURI() != null) {
Individual objInd = new IndividualSDB( //this might throw IndividualNotFoundException
objPropertyStmt.getObjectURI(), Individual objInd = new IndividualSDB(
this.dwf, objPropertyStmt.getObjectURI(),
getWebappDaoFactory(), this.dwf,
m); datasetMode,
objPropertyStmt.setObject(objInd); getWebappDaoFactory());
objPropertyStmt.setObject(objInd);
} }
//add object property statement to list for Individual //only add statement to list if it has its values filled out
if ((objPropertyStmt.getSubjectURI() != null) if ( (objPropertyStmt.getSubjectURI() != null)
&& (objPropertyStmt.getPropertyURI() != null) && (objPropertyStmt.getPropertyURI() != null)
&& (objPropertyStmt.getObject() != null)){ && (objPropertyStmt.getObject() != null) ) {
objPropertyStmtList.add(objPropertyStmt); objPropertyStmtList.add(objPropertyStmt);
} }
} catch (Throwable t) {
t.printStackTrace(); } catch (IndividualNotFoundException t) {
log.error(t,t);
continue;
} catch (Throwable t){
log.error(t,t);
continue;
} }
} }
} }

View file

@ -3,11 +3,12 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -36,19 +37,31 @@ import edu.cornell.mannlib.vitro.webapp.beans.Property;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
protected static final Log log = LogFactory.getLog(PropertyDaoJena.class.getName()); protected static final Log log = LogFactory.getLog(PropertyDaoJena.class.getName());
protected static final String PREFIXES = private static final Map<String, String> NAMESPACES = new HashMap<String, String>() {{
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + put("afn", VitroVocabulary.AFN);
//"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" + put("owl", VitroVocabulary.OWL);
"PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" + put("rdf", VitroVocabulary.RDF);
"PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>"; put("rdfs", VitroVocabulary.RDFS);
put("vitro", VitroVocabulary.vitroURI);
put("vitroPublic", VitroVocabulary.VITRO_PUBLIC);
}};
private DatasetWrapperFactory dwf; protected static String prefixes = "";
static {
for (String key : NAMESPACES.keySet()) {
prefixes += "PREFIX " + key + ": <" + NAMESPACES.get(key) + ">\n";
}
log.debug("Query prefixes: " + prefixes);
}
protected DatasetWrapperFactory dwf;
public PropertyDaoJena(DatasetWrapperFactory dwf, public PropertyDaoJena(DatasetWrapperFactory dwf,
WebappDaoFactoryJena wadf) { WebappDaoFactoryJena wadf) {
@ -117,7 +130,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} catch (Exception cce) {} } catch (Exception cce) {}
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
} finally { } finally {
getOntModel().leaveCriticalSection(); getOntModel().leaveCriticalSection();
} }
@ -158,7 +171,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} catch (Exception cce) {} } catch (Exception cce) {}
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
} finally { } finally {
getOntModel().leaveCriticalSection(); getOntModel().leaveCriticalSection();
} }
@ -238,7 +251,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e, e);
} finally { } finally {
getOntModel().leaveCriticalSection(); getOntModel().leaveCriticalSection();
} }
@ -389,21 +402,32 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return classSet; return classSet;
} }
protected ResultSet getPropertyQueryResults(String subjectUri, Query query) { protected Iterator<QuerySolution> getPropertyQueryResults(String subjectUri, Query query) {
log.debug("SPARQL query:\n" + query.toString()); log.debug("SPARQL query:\n" + query.toString());
// Bind the subject's uri to the ?subject query term // Bind the subject's uri to the ?subject query term
QuerySolutionMap subjectBinding = new QuerySolutionMap(); QuerySolutionMap subjectBinding = new QuerySolutionMap();
subjectBinding.add("subject", subjectBinding.add("subject",
ResourceFactory.createResource(subjectUri)); ResourceFactory.createResource(subjectUri));
// Run the SPARQL query to get the properties // Run the SPARQL query to get the properties
System.out.println(dwf.getClass().getName());
DatasetWrapper w = dwf.getDatasetWrapper(); DatasetWrapper w = dwf.getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
QueryExecution qexec = QueryExecutionFactory.create( QueryExecution qexec = QueryExecutionFactory.create(
query, dataset, subjectBinding); query, dataset, subjectBinding);
return qexec.execSelect(); try {
ResultSet rs = qexec.execSelect();
// consume iterator before wrapper w is closed in finally block
List<QuerySolution> results = new ArrayList<QuerySolution>();
while (rs.hasNext()) {
results.add(rs.next());
}
return results.iterator();
} finally {
qexec.close();
}
} finally { } finally {
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();

View file

@ -15,7 +15,9 @@ 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.Individual; import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ModelFactory;
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;
@ -129,26 +131,49 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
groupInd.setURI(group.getURI()); groupInd.setURI(group.getURI());
String groupURI = null; String groupURI = null;
try {
groupURI = (new WebappDaoFactoryJena(getOntModelSelector().getApplicationMetadataModel())).getIndividualDao().insertNewIndividual(groupInd); OntModel unionForURIGeneration = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM, ModelFactory.createUnion(
getOntModelSelector().getApplicationMetadataModel(),
getOntModelSelector().getFullModel()));
WebappDaoFactory wadfForURIGeneration = null;
try {
wadfForURIGeneration = new WebappDaoFactoryJena(
unionForURIGeneration);
groupURI = wadfForURIGeneration
.getIndividualDao().insertNewIndividual(groupInd);
} catch (InsertException ie) { } catch (InsertException ie) {
throw new RuntimeException(InsertException.class.getName() + "Unable to insert property group "+groupURI, ie); throw new RuntimeException(InsertException.class.getName() +
"Unable to insert property group " + groupURI, ie);
} finally {
wadfForURIGeneration.close();
} }
if (groupURI != null) { if (groupURI != null) {
getOntModel().enterCriticalSection(Lock.WRITE); getOntModel().enterCriticalSection(Lock.WRITE);
try { try {
com.hp.hpl.jena.ontology.Individual groupJenaInd = getOntModel().getIndividual(groupURI); com.hp.hpl.jena.ontology.Individual groupJenaInd =
getOntModel().getIndividual(groupURI);
try { try {
groupJenaInd.addProperty(DISPLAY_RANK, Integer.toString(group.getDisplayRank()), XSDDatatype.XSDint); groupJenaInd.addProperty(DISPLAY_RANK, Integer.toString(
group.getDisplayRank()), XSDDatatype.XSDint);
} catch (Exception e) { } catch (Exception e) {
log.error("error setting displayRank for "+groupInd.getURI()); log.error(
"error setting displayRank for "
+ groupInd.getURI());
} }
if (group.getPublicDescription() != null && group.getPublicDescription().length()>0) { if (group.getPublicDescription() != null
&& group.getPublicDescription().length()>0) {
try { try {
groupJenaInd.addProperty(PUBLIC_DESCRIPTION_ANNOT, group.getPublicDescription(), XSDDatatype.XSDstring); groupJenaInd.addProperty(
PUBLIC_DESCRIPTION_ANNOT,
group.getPublicDescription(),
XSDDatatype.XSDstring);
} catch (Exception ex) { } catch (Exception ex) {
log.error("error setting public description for "+groupInd.getURI()); log.error(
"error setting public description for "
+ groupInd.getURI());
} }
} }
} finally { } finally {

View file

@ -14,17 +14,22 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
import com.hp.hpl.jena.ontology.ObjectProperty; import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntProperty; import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.Restriction; import com.hp.hpl.jena.ontology.Restriction;
import com.hp.hpl.jena.ontology.SomeValuesFromRestriction;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
@ -95,23 +100,40 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
public Collection<PropertyInstance> getAllPossiblePropInstForIndividual(String individualURI) { public Collection<PropertyInstance> getAllPossiblePropInstForIndividual(String individualURI) {
Individual ind = getWebappDaoFactory().getIndividualDao().getIndividualByURI(individualURI); Individual ind = getWebappDaoFactory().getIndividualDao().getIndividualByURI(individualURI);
Map<String, PropertyInstance> propURI2propInst = new HashMap<String, PropertyInstance>(); VClassDao vcDao = getWebappDaoFactory().getVClassDao();
List<VClass> allTypes = ind.getVClasses(false); // include indirect types List<VClass> allTypes = ind.getVClasses(false); // include indirect types
Collections.sort(allTypes, new VClassHierarchyRanker(this.getWebappDaoFactory().getVClassDao()));
for (VClass currClass : allTypes) { Set<String> allSuperclassURIs = new HashSet<String>();
Collection<PropertyInstance> propInstsForClass = getAllPropInstByVClass(currClass.getURI());
for (PropertyInstance propInst : propInstsForClass) { for (VClass type : allTypes) {
if (propURI2propInst.get(propInst.getPropertyURI()) == null) { String classURI = type.getURI();
propURI2propInst.put(propInst.getPropertyURI(), propInst); if (classURI != null) {
} allSuperclassURIs.add(type.getURI());
} }
for (String equivURI : vcDao.getEquivalentClassURIs(classURI)) {
allSuperclassURIs.add(equivURI);
allSuperclassURIs.addAll(vcDao.getAllSuperClassURIs(equivURI));
}
allSuperclassURIs.addAll(vcDao.getAllSuperClassURIs(classURI));
}
List<VClass> vclasses = new ArrayList<VClass>();
for(String vclassURI : allSuperclassURIs) {
VClass vclass = vcDao.getVClassByURI(vclassURI);
if (vclass != null) {
vclasses.add(vclass);
}
}
Collection<PropertyInstance> piList = getAllPropInstByVClasses(vclasses);
for (PropertyInstance pi : piList) {
pi.setDomainClassURI(ind.getVClassURI());
// TODO: improve. This is so the DWR property editing passes the
// individual's VClass to get the right restrictions
} }
for (PropertyInstance pi : propURI2propInst.values()) {
pi.setDomainClassURI(ind.getVClassURI()); // TODO: improve. This is so the DWR property editing passes the individual's VClass to get the right restrictions
}
List<PropertyInstance> piList = new ArrayList<PropertyInstance>();
piList.addAll(propURI2propInst.values());
Collections.sort(piList, new PropInstSorter());
return piList; return piList;
} }
@ -126,15 +148,19 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
public int compare(VClass vc1, VClass vc2) { public int compare(VClass vc1, VClass vc2) {
if (vcDao.isSubClassOf(vc1, vc2)) { if (vcDao.isSubClassOf(vc1, vc2)) {
return -1; return -1;
} else return 0; } else if (vcDao.isSubClassOf(vc2, vc1)) {
return 1;
} else {
return 0;
}
} }
} }
public Collection<PropertyInstance> getAllPropInstByVClass(String classURI) { public Collection<PropertyInstance> getAllPropInstByVClass(String classURI) {
if (classURI==null || classURI.length()<1) { if (classURI==null || classURI.length()<1) {
return null; return null;
} }
List<PropertyInstance> propInsts = new ArrayList();
VClassDao vcDao = getWebappDaoFactory().getVClassDao(); VClassDao vcDao = getWebappDaoFactory().getVClassDao();
@ -142,56 +168,135 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
allSuperclassURIs.add(classURI); allSuperclassURIs.add(classURI);
for (String equivURI : vcDao.getEquivalentClassURIs(classURI)) { for (String equivURI : vcDao.getEquivalentClassURIs(classURI)) {
allSuperclassURIs.add(equivURI); allSuperclassURIs.add(equivURI);
allSuperclassURIs.addAll(vcDao.getAllSuperClassURIs(equivURI)); allSuperclassURIs.addAll(vcDao.getAllSuperClassURIs(equivURI));
} }
allSuperclassURIs.addAll(vcDao.getAllSuperClassURIs(classURI)); allSuperclassURIs.addAll(vcDao.getAllSuperClassURIs(classURI));
List<VClass> vclasses = new ArrayList<VClass>();
for(String vclassURI : allSuperclassURIs) {
VClass vclass = vcDao.getVClassByURI(vclassURI);
if (vclass != null) {
vclasses.add(vclass);
}
}
return getAllPropInstByVClasses(vclasses);
}
private void updatePropertyRangeMap(Map<String, Resource[]> map,
String propURI,
Resource[] ranges) {
Resource[] existingRanges = map.get(propURI);
if (existingRanges == null) {
map.put(propURI, ranges);
} else if (existingRanges[0] == null && existingRanges[1] != null) {
existingRanges[0] = ranges[0];
map.put(propURI, existingRanges);
} else if (existingRanges[0] != null && existingRanges[1] == null) {
existingRanges[1] = ranges[1];
map.put(propURI, existingRanges);
}
}
public Collection<PropertyInstance> getAllPropInstByVClasses(List<VClass> vclasses) {
List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>();
if(vclasses == null || vclasses.isEmpty()) {
return propInsts;
}
Collections.sort(vclasses, new VClassHierarchyRanker(this.getWebappDaoFactory().getVClassDao()));
OntModel ontModel = getOntModelSelector().getTBoxModel(); OntModel ontModel = getOntModelSelector().getTBoxModel();
try { try {
ontModel.enterCriticalSection(Lock.READ); ontModel.enterCriticalSection(Lock.READ);
Set<ObjectProperty> applicableProperties = new HashSet<ObjectProperty>(); // map object property URI to an array of two resources:
// the first is the "allValuesFrom" resource and the second is
// "someValuesFrom"
Map<String, Resource[]> applicableProperties =
new HashMap<String, Resource[]>();
try { try {
for (String VClassURI : allSuperclassURIs) { for (VClass vclass : vclasses) {
if (vclass.isAnonymous()) {
continue;
}
String VClassURI = vclass.getURI();
OntClass ontClass = getOntClass(ontModel,VClassURI); OntClass ontClass = getOntClass(ontModel,VClassURI);
if (ontClass != null) { if (ontClass != null) {
if (ontClass.isRestriction()) { List<OntClass> relatedClasses = new ArrayList<OntClass>();
// TODO: check if restriction is something like relatedClasses.addAll(ontClass.listEquivalentClasses().toList());
// maxCardinality 0 or allValuesFrom owl:Nothing, relatedClasses.addAll(ontClass.listSuperClasses().toList());
// in which case the property is NOT applicable! for (OntClass relatedClass : relatedClasses) {
Restriction rest = (Restriction) ontClass.as(Restriction.class); // find properties in restrictions
OntProperty onProperty = rest.getOnProperty(); if (relatedClass.isRestriction()) {
if (onProperty != null && onProperty.canAs(ObjectProperty.class)) { // TODO: check if restriction is something like
applicableProperties.add((ObjectProperty)onProperty.as(ObjectProperty.class)); // maxCardinality 0 or allValuesFrom owl:Nothing,
} // in which case the property is NOT applicable!
Restriction rest = (Restriction) relatedClass.as(Restriction.class);
OntProperty onProperty = rest.getOnProperty();
if (onProperty != null && onProperty.canAs(ObjectProperty.class)) {
Resource[] ranges = new Resource[2];
if (rest.isAllValuesFromRestriction()) {
ranges[0] = (rest.asAllValuesFromRestriction()).getAllValuesFrom();
} else if (rest.isSomeValuesFromRestriction()) {
ranges[1] = (rest.asSomeValuesFromRestriction()).getSomeValuesFrom();
}
updatePropertyRangeMap(applicableProperties, onProperty.getURI(), ranges);
}
}
}
// find properties with class in domain
ResIterator pit = ontModel.listSubjectsWithProperty(
RDFS.domain, ontClass);
while (pit.hasNext()) {
Resource prop = pit.nextResource();
if (prop.getNameSpace() != null
&& !NONUSER_NAMESPACES.contains(
prop.getNameSpace()) ) {
StmtIterator rangeSit = prop.listProperties(
RDFS.range);
Resource rangeRes = null;
while (rangeSit.hasNext()) {
Statement s = rangeSit.nextStatement();
if (s.getObject().isURIResource()) {
rangeRes = (Resource) s.getObject();
}
}
Resource[] ranges = new Resource[2];
ranges[0] = rangeRes;
updatePropertyRangeMap(
applicableProperties, prop.getURI(), ranges);
}
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Unable to get applicable properties for " + classURI log.error("Unable to get applicable properties " +
+ " by examining property restrictions", e); "by examining property restrictions and domains", e);
} }
HashSet allSuperclassURIset = new HashSet(allSuperclassURIs); // make the PropertyInstance objects
Iterator ops = ontModel.listObjectProperties(); for (String propertyURI : applicableProperties.keySet()) {
while (ops.hasNext()) { ObjectProperty op = ontModel.getObjectProperty(propertyURI);
ObjectProperty op = (ObjectProperty) ops.next(); if (op == null) {
if (op.getNameSpace() != null && !NONUSER_NAMESPACES.contains(op.getNameSpace()) ) { continue;
Resource domainRes = op.getDomain(); }
if (domainRes != null && allSuperclassURIset.contains(getURIStr(domainRes))) {
applicableProperties.add(op);
}
}
}
for (Iterator<ObjectProperty> appPropIt = applicableProperties.iterator(); appPropIt.hasNext();) {
ObjectProperty op = appPropIt.next();
String domainURIStr = getURIStr(op.getDomain()); String domainURIStr = getURIStr(op.getDomain());
Resource rangeRes = op.getRange(); Resource[] foundRanges = applicableProperties.get(propertyURI);
Resource rangeRes = (foundRanges[0] != null)
? foundRanges[0]
: (op.getRange() == null && foundRanges[1] != null)
? foundRanges[1]
: op.getRange();
PropertyInstance pi = new PropertyInstance(); PropertyInstance pi = new PropertyInstance();
if (rangeRes != null) { if (rangeRes != null) {
String rangeClassURI; String rangeClassURI;
@ -219,8 +324,7 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
pi.setRangePublic(getLabelOrId(op)); pi.setRangePublic(getLabelOrId(op));
pi.setDomainPublic(getLabelOrId(op)); pi.setDomainPublic(getLabelOrId(op));
propInsts.add(pi); propInsts.add(pi);
} }
} finally { } finally {
ontModel.leaveCriticalSection(); ontModel.leaveCriticalSection();
} }

View file

@ -32,7 +32,9 @@ public class QueryUtils {
Iterator<String> varNames = soln.varNames(); Iterator<String> varNames = soln.varNames();
while(varNames.hasNext()){ while(varNames.hasNext()){
String varName = varNames.next(); String varName = varNames.next();
map.put(varName, nodeToObject( soln.get(varName))); Object value = nodeToObject( soln.get(varName));
log.debug("Adding " + varName + " : " + value + " to query solution data.");
map.put(varName, value);
} }
return map; return map;
} }
@ -42,7 +44,9 @@ public class QueryUtils {
Iterator<String> varNames = soln.varNames(); Iterator<String> varNames = soln.varNames();
while(varNames.hasNext()){ while(varNames.hasNext()){
String varName = varNames.next(); String varName = varNames.next();
map.put(varName, nodeToString( soln.get(varName))); String value = nodeToString( soln.get(varName));
log.debug("Adding " + varName + " : " + value + " to query solution data.");
map.put(varName, value);
} }
return map; return map;
} }

View file

@ -51,7 +51,7 @@ public class RDBGraphGenerator implements GraphGenerator {
Graph graphRDB = new GraphRDB(idbConn, graphID, requestedProperties, GraphRDB.OPTIMIZE_ALL_REIFICATIONS_AND_HIDE_NOTHING, !modelExists); Graph graphRDB = new GraphRDB(idbConn, graphID, requestedProperties, GraphRDB.OPTIMIZE_ALL_REIFICATIONS_AND_HIDE_NOTHING, !modelExists);
return graphRDB; return graphRDB;
} catch (SQLException e) { } catch (SQLException e) {
log.error(e); log.error(e, e);
throw new RuntimeException("SQLException: unable to regenerate graph", e); throw new RuntimeException("SQLException: unable to regenerate graph", e);
} }
} }

View file

@ -2,9 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -32,18 +30,34 @@ public class SearchReindexingListener implements ModelChangedListener {
this.indexBuilder = indexBuilder; this.indexBuilder = indexBuilder;
} }
private synchronized void addChange(Statement stmt){ private synchronized void addChange(Statement stmt){
if( stmt == null ) return; if( stmt == null ) return;
if( log.isDebugEnabled() ){
String sub="unknown";
String pred = "unknown";
String obj ="unknown";
if( stmt.getSubject().isURIResource() ){
sub = stmt.getSubject().getURI();
}
if( stmt.getPredicate() != null ){
pred = stmt.getPredicate().getURI();
}
if( stmt.getObject().isURIResource() ){
obj = ((Resource) (stmt.getPredicate().as(Resource.class))).getURI();
}else{
obj = stmt.getObject().toString();
}
log.debug("changed statement: sub='" + sub + "' pred='" + pred +"' obj='" + obj + "'");
}
if( stmt.getSubject().isURIResource() ){ if( stmt.getSubject().isURIResource() ){
//changedUris.add( stmt.getSubject().getURI());
indexBuilder.addToChangedUris(stmt.getSubject().getURI()); indexBuilder.addToChangedUris(stmt.getSubject().getURI());
log.debug("subject: " + stmt.getSubject().getURI()); log.debug("subject: " + stmt.getSubject().getURI());
} }
if( stmt.getObject().isURIResource() ){ if( stmt.getObject().isURIResource() ){
//changedUris.add( ((Resource) stmt.getObject().as(Resource.class)).getURI() );
indexBuilder.addToChangedUris(((Resource) stmt.getObject()).getURI()); indexBuilder.addToChangedUris(((Resource) stmt.getObject()).getURI());
log.debug("object: " + ((Resource) stmt.getObject().as(Resource.class)).getURI());
} }
} }

View file

@ -21,8 +21,10 @@ import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.ObjectProperty; import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
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;
import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.util.iterator.ClosableIterator;
@ -331,7 +333,7 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
Individual portalInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"portal"+portalId); Individual portalInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"portal"+portalId);
if (portalInd == null) if (portalInd == null)
return -1; return -1;
Resource rootTabResource = (Resource) portalInd.getProperty(getOntModel().getObjectProperty(VitroVocabulary.PORTAL_ROOTTAB)).getObject(); Resource rootTabResource = (Resource) portalInd.getProperty(PORTAL_ROOTTAB).getObject();
if (rootTabResource == null) if (rootTabResource == null)
return -1; return -1;
String id = rootTabResource.getLocalName().substring(3); String id = rootTabResource.getLocalName().substring(3);
@ -346,7 +348,7 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
try { try {
Individual primaryTabInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+primaryTabId); Individual primaryTabInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+primaryTabId);
if (primaryTabInd != null) { if (primaryTabInd != null) {
ObjectProperty subTabOf = getOntModel().getObjectProperty(VitroVocabulary.TAB_SUBTABOF); ObjectProperty subTabOf = TAB_SUBTABOF;
if (subTabOf != null) { if (subTabOf != null) {
List secondaryTabs = new ArrayList(); List secondaryTabs = new ArrayList();
Iterator stmtIt = getOntModel().listStatements(null, subTabOf, primaryTabInd); Iterator stmtIt = getOntModel().listStatements(null, subTabOf, primaryTabInd);
@ -477,7 +479,7 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
Integer i = null; Integer i = null;
Individual narrowerTab = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+tabId); Individual narrowerTab = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+tabId);
if (narrowerTab != null) { if (narrowerTab != null) {
ObjectProperty subTabOf = getOntModel().getObjectProperty(VitroVocabulary.TAB_SUBTABOF); ObjectProperty subTabOf = TAB_SUBTABOF;
if (subTabOf != null) { if (subTabOf != null) {
Iterator stmtIt = narrowerTab.listProperties(subTabOf); Iterator stmtIt = narrowerTab.listProperties(subTabOf);
if (stmtIt.hasNext()) { if (stmtIt.hasNext()) {
@ -569,19 +571,19 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
try { try {
tabInd.setLabel(tab.getTitle(), (String) getDefaultLanguage()); tabInd.setLabel(tab.getTitle(), (String) getDefaultLanguage());
} catch (Exception e) {log.error("error setting label for "+tabInd.getURI());} } catch (Exception e) {log.error("error setting label for "+tabInd.getURI());}
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DESCRIPTION), tab.getDescription(), ontModel); addPropertyStringValue(tabInd, DESCRIPTION, tab.getDescription(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_STATUSID), tab.getStatusId(), ontModel); addPropertyNonNegativeIntValue(tabInd, TAB_STATUSID, tab.getStatusId(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_BODY), tab.getBody(), ontModel); addPropertyStringValue(tabInd, TAB_BODY, tab.getBody(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DISPLAY_RANK), tab.getDisplayRank(), ontModel); addPropertyNonNegativeIntValue(tabInd, DISPLAY_RANK, tab.getDisplayRank(), ontModel);
addPropertyIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_DAYLIMIT), tab.getDayLimit(), ontModel); addPropertyIntValue(tabInd, TAB_DAYLIMIT, tab.getDayLimit(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYROWS), tab.getGalleryRows(), ontModel); addPropertyNonNegativeIntValue(tabInd, TAB_GALLERYROWS, tab.getGalleryRows(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYCOLS), tab.getGalleryCols(), ontModel); addPropertyNonNegativeIntValue(tabInd, TAB_GALLERYCOLS, tab.getGalleryCols(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_MORETAG), tab.getMoreTag(), ontModel); addPropertyStringValue(tabInd, TAB_MORETAG, tab.getMoreTag(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_IMAGEWIDTH), tab.getImageWidth(), ontModel); addPropertyNonNegativeIntValue(tabInd, TAB_IMAGEWIDTH, tab.getImageWidth(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTFIELD), tab.getEntitySortField(), ontModel); addPropertyStringValue(tabInd, TAB_ENTITYSORTFIELD, tab.getEntitySortField(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTDIRECTION), tab.getEntitySortDirection(), ontModel); addPropertyStringValue(tabInd, TAB_ENTITYSORTDIRECTION, tab.getEntitySortDirection(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2MODE), tab.getFlag2Mode(), ontModel); addPropertyStringValue(tabInd, TAB_FLAG2MODE, tab.getFlag2Mode(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2SET), tab.getFlag2Set(), ontModel); addPropertyStringValue(tabInd, TAB_FLAG2SET, tab.getFlag2Set(), ontModel);
try { try {
Object o = entityLinkMethods.get(tab.getEntityLinkMethod()); Object o = entityLinkMethods.get(tab.getEntityLinkMethod());
if (o instanceof List) { if (o instanceof List) {
@ -622,19 +624,19 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
try { try {
tabInd.setLabel(tab.getTitle(), (String) getDefaultLanguage()); tabInd.setLabel(tab.getTitle(), (String) getDefaultLanguage());
} catch (Exception e) {log.error("Error updating title for tab "+tab.getTabId());} } catch (Exception e) {log.error("Error updating title for tab "+tab.getTabId());}
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DESCRIPTION), tab.getDescription(), ontModel); updatePropertyStringValue(tabInd, DESCRIPTION, tab.getDescription(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_STATUSID), tab.getStatusId(), ontModel); updatePropertyNonNegativeIntValue(tabInd, TAB_STATUSID, tab.getStatusId(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_BODY), tab.getBody(), ontModel); updatePropertyStringValue(tabInd, TAB_BODY, tab.getBody(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DISPLAY_RANK), tab.getDisplayRank(), ontModel); updatePropertyNonNegativeIntValue(tabInd, DISPLAY_RANK, tab.getDisplayRank(), ontModel);
updatePropertyIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_DAYLIMIT), tab.getDayLimit(), ontModel); updatePropertyIntValue(tabInd, TAB_DAYLIMIT, tab.getDayLimit(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYROWS), tab.getGalleryRows(), ontModel); updatePropertyNonNegativeIntValue(tabInd, TAB_GALLERYROWS, tab.getGalleryRows(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYCOLS), tab.getGalleryCols(), ontModel); updatePropertyNonNegativeIntValue(tabInd, TAB_GALLERYCOLS, tab.getGalleryCols(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_MORETAG), tab.getMoreTag(), ontModel); updatePropertyStringValue(tabInd, TAB_MORETAG, tab.getMoreTag(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_IMAGEWIDTH), tab.getImageWidth(), ontModel); updatePropertyNonNegativeIntValue(tabInd, TAB_IMAGEWIDTH, tab.getImageWidth(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTFIELD), tab.getEntitySortField(), ontModel); updatePropertyStringValue(tabInd, TAB_ENTITYSORTFIELD, tab.getEntitySortField(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTDIRECTION), tab.getEntitySortDirection(), ontModel); updatePropertyStringValue(tabInd, TAB_ENTITYSORTDIRECTION, tab.getEntitySortDirection(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2MODE), tab.getFlag2Mode(), ontModel); updatePropertyStringValue(tabInd, TAB_FLAG2MODE, tab.getFlag2Mode(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2SET), tab.getFlag2Set(), ontModel); updatePropertyStringValue(tabInd, TAB_FLAG2SET, tab.getFlag2Set(), ontModel);
Iterator types = tabInd.listRDFTypes(false); Iterator types = tabInd.listRDFTypes(false);
List typesToRemove = new ArrayList(); List typesToRemove = new ArrayList();
while (types.hasNext()) { while (types.hasNext()) {
@ -862,11 +864,7 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
* look first for heading tabs * look first for heading tabs
*/ */
private void getChildTabs(Tab tab, int auth_level, ApplicationBean appBean){ private void getChildTabs(Tab tab, int auth_level, ApplicationBean appBean){
ObjectProperty subTabOf = getOntModel().getObjectProperty(VitroVocabulary.TAB_SUBTABOF); Property subTabOf = ResourceFactory.createProperty(VitroVocabulary.TAB_SUBTABOF);
if (subTabOf == null) {
log.error("cannot find property "+ VitroVocabulary.TAB_SUBTABOF);
return;
}
Individual parentTabInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+tab.getTabId()); Individual parentTabInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+tab.getTabId());
if (parentTabInd == null) if (parentTabInd == null)
return; return;

View file

@ -780,6 +780,11 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
@Deprecated @Deprecated
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) { public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) {
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
if (getIndividualCount) {
group.setIndividualCount( getClassGroupInstanceCount(group));
}
try { try {
if ((group != null) && (group.getURI() != null)) { if ((group != null) && (group.getURI() != null)) {
Resource groupRes = ResourceFactory.createResource(group.getURI()); Resource groupRes = ResourceFactory.createResource(group.getURI());
@ -847,6 +852,29 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
} }
} }
int getClassGroupInstanceCount(VClassGroup vcg){
Model ontModel = getOntModel();
ontModel.enterCriticalSection(Lock.READ);
int count = 0;
try {
String queryText =
"SELECT COUNT( DISTINCT ?instance ) WHERE { \n" +
" ?class <"+VitroVocabulary.IN_CLASSGROUP+"> <"+vcg.getURI() +"> .\n" +
" ?instance a ?class . \n" +
"}" ;
Query countQuery = QueryFactory.create(queryText, Syntax.syntaxARQ);
QueryExecution qe = QueryExecutionFactory.create(countQuery, ontModel);
ResultSet rs =qe.execSelect();
count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
}catch(Exception ex){
log.error(ex,ex);
} finally {
ontModel.leaveCriticalSection();
}
return count;
}
public void addVClassesToGroups(List <VClassGroup> groups) { public void addVClassesToGroups(List <VClassGroup> groups) {
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
try { try {

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.List;
import com.hp.hpl.jena.ontology.AnnotationProperty; import com.hp.hpl.jena.ontology.AnnotationProperty;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Dataset;
@ -9,6 +11,8 @@ import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
@ -23,15 +27,19 @@ import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class VClassDaoSDB extends VClassDaoJena { public class VClassDaoSDB extends VClassDaoJena {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory, public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory,
WebappDaoFactoryJena wadf) { SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
this.datasetMode = datasetMode;
} }
protected DatasetWrapper getDatasetWrapper() { protected DatasetWrapper getDatasetWrapper() {
@ -40,9 +48,14 @@ public class VClassDaoSDB extends VClassDaoJena {
@Deprecated @Deprecated
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) { public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) {
if (getIndividualCount) {
group.setIndividualCount( getClassGroupInstanceCount(group));
}
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
try { try {
if ((group != null) && (group.getURI() != null)) { if ((group != null) && (group.getURI() != null)) {
Resource groupRes = ResourceFactory.createResource(group.getURI()); Resource groupRes = ResourceFactory.createResource(group.getURI());
AnnotationProperty inClassGroup = getOntModel().getAnnotationProperty(VitroVocabulary.IN_CLASSGROUP); AnnotationProperty inClassGroup = getOntModel().getAnnotationProperty(VitroVocabulary.IN_CLASSGROUP);
if (inClassGroup != null) { if (inClassGroup != null) {
@ -55,28 +68,25 @@ public class VClassDaoSDB extends VClassDaoJena {
VClass vcw = (VClass) getVClassByURI(cls.getURI()); VClass vcw = (VClass) getVClassByURI(cls.getURI());
if (vcw != null) { if (vcw != null) {
boolean classIsInstantiated = false; boolean classIsInstantiated = false;
if (getIndividualCount) { if (getIndividualCount) {
Model aboxModel = getOntModelSelector().getABoxModel(); int count = 0;
aboxModel.enterCriticalSection(Lock.READ); String[] graphVars = { "?g" };
int count = 0; String countQueryStr = "SELECT COUNT(DISTINCT ?s) WHERE \n" +
try { "{ GRAPH ?g { ?s a <" + cls.getURI() + "> } \n" +
String countQueryStr = "SELECT COUNT(*) WHERE \n" + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"{ GRAPH ?g { ?s a <" + cls.getURI() + "> } } \n"; "} \n";
Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ); Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ);
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
QueryExecution qe = QueryExecutionFactory.create(countQuery, dataset); QueryExecution qe = QueryExecutionFactory.create(countQuery, dataset);
ResultSet rs = qe.execSelect(); ResultSet rs = qe.execSelect();
count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm()); count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
} finally { } finally {
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();
} }
} finally {
aboxModel.leaveCriticalSection();
}
vcw.setEntityCount(count); vcw.setEntityCount(count);
classIsInstantiated = (count > 0); classIsInstantiated = (count > 0);
} else if (includeUninstantiatedClasses == false) { } else if (includeUninstantiatedClasses == false) {
@ -114,5 +124,43 @@ public class VClassDaoSDB extends VClassDaoJena {
getOntModel().leaveCriticalSection(); getOntModel().leaveCriticalSection();
} }
} }
// protected void addIndividualCountToGroups( List<VClassGroup> cgList ){
// for( VClassGroup cg : cgList){
// cg.setIndividualCount(getClassGroupInstanceCount(cg));
// }
// }
@Override
int getClassGroupInstanceCount(VClassGroup vcg){
int count = 0;
try {
String queryText =
"SELECT COUNT( DISTINCT ?instance ) WHERE { \n" +
" GRAPH <urn:x-arq:UnionGraph> { \n" +
" ?class <"+VitroVocabulary.IN_CLASSGROUP+"> <"+vcg.getURI() +"> .\n" +
" ?instance a ?class . \n" +
" } \n" +
"} \n" ;
Query countQuery = QueryFactory.create(queryText, Syntax.syntaxARQ);
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
QueryExecution qe = QueryExecutionFactory.create(countQuery, dataset);
ResultSet rs = qe.execSelect();
count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
} finally {
dataset.getLock().leaveCriticalSection();
w.close();
}
}catch(Exception ex){
log.error("error in getClassGroupInstanceCount()", ex);
}
return count;
}
} }

View file

@ -9,6 +9,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
@ -32,37 +33,51 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag; import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
public class VClassGroupCache implements ServletContextListener{ public class VClassGroupCache{
/* This is the cache of VClassGroups. It is a portal id to list of VClassGroups */
private transient ConcurrentHashMap<Integer, List<VClassGroup>> _groupListMap;
private transient ConcurrentLinkedQueue<String> _rebuildQueue;
private RebuildGroupCacheThread _cacheRebuildThread;
private ServletContext context;
private static final Log log = LogFactory.getLog(VClassGroupCache.class); private static final Log log = LogFactory.getLog(VClassGroupCache.class);
private static boolean ORDER_BY_DISPLAYRANK = true; private static final String ATTRIBUTE_NAME = "VClassGroupCache";
private static boolean INCLUDE_UNINSTANTIATED = true; private static final String REBUILD_EVERY_PORTAL = "Rebuild every portal.";
private static boolean INCLUDE_INDIVIDUAL_COUNT = true;
private static final boolean ORDER_BY_DISPLAYRANK = true;
public VClassGroupCache(){} private static final boolean INCLUDE_UNINSTANTIATED = true;
private static final boolean INCLUDE_INDIVIDUAL_COUNT = true;
/** /**
* Use getVClassGroupCache(ServletContext) to get a VClassGroupCache. * Use getVClassGroupCache(ServletContext) to get a VClassGroupCache.
*/ */
public static VClassGroupCache getVClassGroupCache(ServletContext sc){
return (VClassGroupCache) sc.getAttribute(ATTRIBUTE_NAME);
}
/** This is the cache of VClassGroups. It is a portal id to list of VClassGroups */
private final ConcurrentHashMap<Integer, List<VClassGroup>> _groupListMap;
private final ConcurrentLinkedQueue<String> _rebuildQueue;
private final RebuildGroupCacheThread _cacheRebuildThread;
private final ServletContext context;
private VClassGroupCache(ServletContext context) { private VClassGroupCache(ServletContext context) {
this.context = context; this.context = context;
this._groupListMap = new ConcurrentHashMap<Integer, List<VClassGroup>>(); this._groupListMap = new ConcurrentHashMap<Integer, List<VClassGroup>>();
this._rebuildQueue = new ConcurrentLinkedQueue<String>(); this._rebuildQueue = new ConcurrentLinkedQueue<String>();
if( AbortStartup.isStartupAborted(context)){
_cacheRebuildThread = null;
return;
}
VClassGroupCacheChangeListener bccl = new VClassGroupCacheChangeListener(this); VClassGroupCacheChangeListener bccl = new VClassGroupCacheChangeListener(this);
ModelContext.getJenaOntModel(context).register(bccl); ModelContext.registerListenerForChanges(context, bccl);
ModelContext.getBaseOntModel(context).register(bccl); //
ModelContext.getInferenceOntModel(context).register(bccl); // ModelContext.getJenaOntModel(context).register(bccl);
ModelContext.getUnionOntModelSelector(context).getABoxModel().register(bccl); // ModelContext.getBaseOntModel(context).register(bccl);
// ModelContext.getInferenceOntModel(context).register(bccl);
// ModelContext.getUnionOntModelSelector(context).getABoxModel().register(bccl);
// ModelContext.getBaseOntModelSelector(context).getABoxModel().register(bccl);
// ModelContext.getInferenceOntModelSelector(context).getABoxModel().register(bccl);
_rebuildQueue.add(REBUILD_EVERY_PORTAL); _rebuildQueue.add(REBUILD_EVERY_PORTAL);
_cacheRebuildThread = new RebuildGroupCacheThread(this); _cacheRebuildThread = new RebuildGroupCacheThread(this);
@ -71,13 +86,9 @@ public class VClassGroupCache implements ServletContextListener{
_cacheRebuildThread.informOfQueueChange(); _cacheRebuildThread.informOfQueueChange();
} }
public static VClassGroupCache getVClassGroupCache(ServletContext sc){ public void clearGroupCache(){
return (VClassGroupCache) sc.getAttribute("VClassGroupCache"); _groupListMap.clear();
} }
public List<VClassGroup> getGroups( int portalId ){
return getGroups(getVCGDao(),portalId );
}
/** /**
* May return null. * May return null.
@ -93,10 +104,13 @@ public class VClassGroupCache implements ServletContextListener{
return null; return null;
} }
public void clearGroupCache(){ public List<VClassGroup> getGroups( int portalId ){
_groupListMap = new ConcurrentHashMap<Integer, List<VClassGroup>>(); return getGroups(getVCGDao(),portalId );
} }
private List<VClassGroup> getGroups( VClassGroupDao vcgDao, int portalId) {
return getGroups( vcgDao, portalId, INCLUDE_INDIVIDUAL_COUNT);
}
private List<VClassGroup> getGroups( VClassGroupDao vcgDao , int portalId, boolean includeIndividualCount ){ private List<VClassGroup> getGroups( VClassGroupDao vcgDao , int portalId, boolean includeIndividualCount ){
List<VClassGroup> groupList = _groupListMap.get(portalId); List<VClassGroup> groupList = _groupListMap.get(portalId);
@ -118,10 +132,6 @@ public class VClassGroupCache implements ServletContextListener{
} }
} }
private List<VClassGroup> getGroups( VClassGroupDao vcgDao, int portalId) {
return getGroups( vcgDao, portalId, INCLUDE_INDIVIDUAL_COUNT);
}
private void requestCacheUpdate(String portalUri){ private void requestCacheUpdate(String portalUri){
log.debug("requesting update for portal " + portalUri); log.debug("requesting update for portal " + portalUri);
_rebuildQueue.add(portalUri); _rebuildQueue.add(portalUri);
@ -254,9 +264,26 @@ public class VClassGroupCache implements ServletContextListener{
return groups; return groups;
} }
private void requestStop() {
if( _cacheRebuildThread != null ){
_cacheRebuildThread.kill();
try {
_cacheRebuildThread.join();
} catch (InterruptedException e) {
log.warn("Waiting for the thread to die, but interrupted.", e);
}
}
}
protected VClassGroupDao getVCGDao(){
WebappDaoFactory wdf =(WebappDaoFactory)context.getAttribute("webappDaoFactory");
if( wdf == null ){
log.error("Cannot get webappDaoFactory from context");
return null;
}else
return wdf.getVClassGroupDao();
}
/* ****************** Jena Model Change Listener***************************** */ /* ****************** Jena Model Change Listener***************************** */
private class VClassGroupCacheChangeListener extends StatementListener { private class VClassGroupCacheChangeListener extends StatementListener {
private VClassGroupCache cache = null; private VClassGroupCache cache = null;
@ -289,88 +316,70 @@ public class VClassGroupCache implements ServletContextListener{
} }
/* ******************** RebuildGroupCacheThread **************** */ /* ******************** RebuildGroupCacheThread **************** */
protected class RebuildGroupCacheThread extends Thread { protected class RebuildGroupCacheThread extends Thread {
VClassGroupCache cache; private final VClassGroupCache cache;
boolean die = false; private final AtomicLong queueChangeMillis = new AtomicLong();
boolean queueChange = false; private volatile boolean die = false;
long queueChangeMills = 0;
private boolean awareOfQueueChange = false;
RebuildGroupCacheThread(VClassGroupCache cache) { RebuildGroupCacheThread(VClassGroupCache cache) {
super("VClassGroupCache.RebuildGroupCacheThread"); super("VClassGroupCache.RebuildGroupCacheThread");
this.cache = cache; this.cache = cache;
} }
public void run() { public void run() {
while(true){ while (!die) {
try{ int delay;
synchronized (this){
if( _rebuildQueue.isEmpty() ){ if (_rebuildQueue.isEmpty()) {
log.debug("rebuildGroupCacheThread.run() -- queye empty, sleep"); log.debug("rebuildGroupCacheThread.run() -- queue empty, sleep");
wait(1000 * 60 ); delay = 1000 * 60;
} } else if ((System.currentTimeMillis() - queueChangeMillis.get()) < 200) {
if( die ) { log.debug("rebuildGroupCacheThread.run() -- delay start of rebuild");
log.debug("doing rebuildGroupCacheThread.run() -- die()"); delay = 200;
return; } else {
} log.debug("rebuildGroupCacheThread.run() -- refreshGroupCache()");
if( queueChange && !awareOfQueueChange){ cache.refreshGroupCache();
log.debug("rebuildGroupCacheThread.run() -- awareOfQueueChange, delay start of rebuild"); delay = 0;
awareOfQueueChange = true; }
wait(200);
} if (delay > 0) {
} synchronized (this) {
try {
if( awareOfQueueChange && System.currentTimeMillis() - queueChangeMills > 200){ wait(delay);
log.debug("rebuildGroupCacheThread.run() -- refreshGroupCache()"); } catch (InterruptedException e) {
cache.refreshGroupCache(); log.warn("Waiting " + delay
synchronized( this){ + " milliseconds, but interrupted.", e);
queueChange = false; }
} }
awareOfQueueChange = false; }
}else {
synchronized( this ){
wait(200);
}
}
} catch(InterruptedException e){}
} }
log.debug("rebuildGroupCacheThread.run() -- die()");
} }
synchronized void informOfQueueChange(){ synchronized void informOfQueueChange(){
queueChange = true; queueChangeMillis.set(System.currentTimeMillis());
queueChangeMills = System.currentTimeMillis();
this.notifyAll(); this.notifyAll();
} }
synchronized void kill(){ synchronized void kill(){
die = true; die = true;
notifyAll(); this.notifyAll();
} }
} }
protected VClassGroupDao getVCGDao(){ /* ******************** ServletContextListener **************** */
if( context == null ){ public static class Setup implements ServletContextListener {
log.error("Context was not set for VClassGroupCache"); @Override
return null; public void contextInitialized(ServletContextEvent sce) {
ServletContext servletContext = sce.getServletContext();
servletContext.setAttribute(ATTRIBUTE_NAME, new VClassGroupCache(servletContext) );
} }
WebappDaoFactory wdf =(WebappDaoFactory)context.getAttribute("webappDaoFactory");
if( wdf == null ){
log.error("Cannot get webappDaoFactory from context");
return null;
}else
return wdf.getVClassGroupDao();
}
protected static String REBUILD_EVERY_PORTAL ="Rebuild every portal.";
@Override @Override
public void contextDestroyed(ServletContextEvent arg0) { public void contextDestroyed(ServletContextEvent sce) {
if( _cacheRebuildThread != null ) Object o = sce.getServletContext().getAttribute(ATTRIBUTE_NAME);
_cacheRebuildThread.kill(); if (o instanceof VClassGroupCache ) {
} ((VClassGroupCache) o).requestStop();
}
@Override }
public void contextInitialized(ServletContextEvent arg0) {
arg0.getServletContext().setAttribute("VClassGroupCache", new VClassGroupCache(arg0.getServletContext()) );
} }
} }

View file

@ -14,21 +14,25 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.DatatypeProperty;
import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.util.iterator.ClosableIterator;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.InsertException; import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary;
public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao { public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
@ -130,9 +134,9 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
if (vgrp!=null) { if (vgrp!=null) {
classDao.addVClassesToGroup(vgrp, includeUninstantiatedClasses, getIndividualCount); classDao.addVClassesToGroup(vgrp, includeUninstantiatedClasses, getIndividualCount);
groups.add(vgrp); groups.add(vgrp);
java.util.Collections.sort(groups);
} }
} }
java.util.Collections.sort(groups);
} finally { } finally {
groupIt.close(); groupIt.close();
} }
@ -157,14 +161,16 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
groups.add(ungrouped); groups.add(ungrouped);
} }
*/ */
if (groups.size()>0) { if (groups.size()>0) {
if( getIndividualCount )
addIndividualCountToGroups(groups);
return groups; return groups;
} else { } else {
classDao.addVClassesToGroups(groups); /* bdc34: the effect of the following code is that
if( getIndividualCount ) * classgroups will get empty vclasses added to them
addIndividualCountToGroups(groups); * when includeUninstantiatedClasses == false and all
* the vclasses are empty.
* This may not be the desired behavior.
*/
classDao.addVClassesToGroups(groups);
return groups; return groups;
} }
} finally { } finally {
@ -172,16 +178,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
} }
} }
private void addIndividualCountToGroups( List<VClassGroup> cgList ){
for( VClassGroup cg : cgList){
int count = 0;
for( VClass vc : cg){
count = count + vc.getEntityCount();
}
cg.setIndividualCount(count);
}
}
public VClassGroup groupFromGroupIndividual(Individual groupInd) { public VClassGroup groupFromGroupIndividual(Individual groupInd) {
if (groupInd==null) { if (groupInd==null) {
@ -193,9 +190,14 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
group.setNamespace(groupInd.getNameSpace()); group.setNamespace(groupInd.getNameSpace());
group.setLocalName(groupInd.getLocalName()); group.setLocalName(groupInd.getLocalName());
try { try {
group.setDisplayRank(Integer.decode(((Literal)(groupInd.getProperty(getOntModel().getDatatypeProperty(VitroVocabulary.DISPLAY_RANK)).getObject())).getString()).intValue()); DatatypeProperty drProp = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createDatatypeProperty(VitroVocabulary.DISPLAY_RANK);
if( drProp == null ){
log.debug("No display rank in model for portal " + groupInd.getURI() );
}else{
group.setDisplayRank(Integer.decode(((Literal)(groupInd.getProperty(drProp).getObject())).getString()).intValue());
}
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); log.warn("Cannot get display rank for portal " + groupInd.getURI() + " " + e.getMessage() );
} }
return group; return group;
} }
@ -219,10 +221,22 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
groupInd.setVClassURI(CLASSGROUP.getURI()); groupInd.setVClassURI(CLASSGROUP.getURI());
String groupURI = null; String groupURI = null;
OntModel unionForURIGeneration = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM, ModelFactory.createUnion(
getOntModelSelector().getApplicationMetadataModel(),
getOntModelSelector().getFullModel()));
WebappDaoFactory wadfForURIGeneration = null;
try { try {
groupURI = (new WebappDaoFactoryJena(ontModel)).getIndividualDao().insertNewIndividual(groupInd); wadfForURIGeneration = new WebappDaoFactoryJena(
unionForURIGeneration);
groupURI = wadfForURIGeneration
.getIndividualDao().insertNewIndividual(groupInd);
} catch (InsertException ie) { } catch (InsertException ie) {
throw new RuntimeException(InsertException.class.getName() + "Unable to insert class group "+groupURI, ie); throw new RuntimeException(InsertException.class.getName() + "Unable to insert class group "+groupURI, ie);
} finally {
wadfForURIGeneration.close();
} }
if (groupURI != null) { if (groupURI != null) {

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -11,8 +13,15 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.commons.dbcp.BasicDataSource;
import com.hp.hpl.jena.graph.GraphMaker; import com.hp.hpl.jena.graph.GraphMaker;
import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelMaker; import com.hp.hpl.jena.rdf.model.ModelMaker;
@ -23,67 +32,148 @@ import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.sdb.SDB;
import com.hp.hpl.jena.sdb.SDBFactory; import com.hp.hpl.jena.sdb.SDBFactory;
import com.hp.hpl.jena.sdb.Store; import com.hp.hpl.jena.sdb.Store;
import com.hp.hpl.jena.sdb.StoreDesc;
import com.hp.hpl.jena.sdb.sql.SDBConnection;
import com.hp.hpl.jena.sdb.util.StoreUtils; import com.hp.hpl.jena.sdb.util.StoreUtils;
import com.hp.hpl.jena.util.iterator.ExtendedIterator; import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.WrappedIterator; import com.hp.hpl.jena.util.iterator.WrappedIterator;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.ibm.icu.text.Collator; import com.ibm.icu.text.Collator;
public class VitroJenaSDBModelMaker implements ModelMaker { public class VitroJenaSDBModelMaker implements ModelMaker {
// TODO: need to rethink the inheritance/interfaces here // TODO: need to rethink the inheritance/interfaces here
private Store store = null; private StoreDesc storeDesc = null;
private BasicDataSource bds = null;
private SDBConnection conn = null;
public static final String METADATA_MODEL_URI = "http://vitro.mannlib.cornell.edu/ns/vitro/sdb/metadata"; public static final String METADATA_MODEL_URI = "http://vitro.mannlib.cornell.edu/ns/vitro/sdb/metadata";
public static final String HAS_NAMED_MODEL_URI = "http://vitro.mannlib.cornell.edu/ns/vitro/sdb/hasNamedModel"; public static final String HAS_NAMED_MODEL_URI = "http://vitro.mannlib.cornell.edu/ns/vitro/sdb/hasNamedModel";
private Model metadataModel;
private Resource sdbResource; // a resource representing the SDB database private Resource sdbResource; // a resource representing the SDB database
public VitroJenaSDBModelMaker(Store store) { public VitroJenaSDBModelMaker(StoreDesc storeDesc, BasicDataSource bds) throws SQLException {
this.store = store;
try {
Model meta = getModel(METADATA_MODEL_URI);
// Test query to see if the database has been initialized
meta.listStatements(null, RDF.type, OWL.Nothing);
} catch (Exception e) {
// initialize the store
store.getTableFormatter().create();
store.getTableFormatter().truncate();
}
this.metadataModel = getModel(METADATA_MODEL_URI); this.storeDesc = storeDesc;
this.bds = bds;
Store store = getStore();
try {
if (metadataModel.size()==0) { Model metadataModel = getMetadataModel();
// set up the model name metadata to avoid expensive calls to listNames()
Resource sdbRes = metadataModel.createResource(); if (metadataModel.size()==0) {
this.sdbResource = sdbRes; // set up the model name metadata to avoid expensive calls to listNames()
Iterator nameIt = SDBFactory.connectDataset(store).listNames(); Resource sdbRes = metadataModel.createResource();
while (nameIt.hasNext()) { this.sdbResource = sdbRes;
String name = (String) nameIt.next(); Iterator nameIt = SDBFactory.connectDataset(store).listNames();
metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),name); while (nameIt.hasNext()) {
} String name = (String) nameIt.next();
} else { metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),name);
StmtIterator stmtIt = metadataModel.listStatements((Resource)null, metadataModel.getProperty(HAS_NAMED_MODEL_URI),(RDFNode)null); }
if (stmtIt.hasNext()) { } else {
Statement stmt = stmtIt.nextStatement(); StmtIterator stmtIt = metadataModel.listStatements((Resource)null, metadataModel.getProperty(HAS_NAMED_MODEL_URI),(RDFNode)null);
sdbResource = stmt.getSubject(); if (stmtIt.hasNext()) {
} Statement stmt = stmtIt.nextStatement();
stmtIt.close(); sdbResource = stmt.getSubject();
} }
stmtIt.close();
}
} finally {
store.close();
}
}
private static final int MAX_TRIES = 10;
private Store getStore() {
Store store = null;
boolean goodStore = false;
boolean badConn = false;
int tries = 0;
while (!goodStore && tries < MAX_TRIES) {
tries++;
if (conn == null || badConn) {
try {
conn = new SDBConnection(bds.getConnection());
badConn = false;
} catch (SQLException sqle) {
throw new RuntimeException(
"Unable to get SQL connection", sqle);
}
}
store = SDBFactory.connectStore(conn, storeDesc);
try {
if (!StoreUtils.isFormatted(store)) {
// initialize the store
store.getTableFormatter().create();
store.getTableFormatter().truncate();
}
} catch (SQLException sqle) {
throw new RuntimeException(
"Unable to set up SDB store for model maker", sqle);
}
if (!isWorking(store)) {
if (conn != null) {
conn.close();
badConn = true;
}
} else {
goodStore = true;
}
}
if (store == null) {
throw new RuntimeException(
"Unable to connect to SDB store after " +
MAX_TRIES + " attempts");
}
return store;
}
Model getMetadataModel() {
return getModel(METADATA_MODEL_URI);
}
private boolean isWorking(Store store) {
Dataset d = SDBFactory.connectDataset(store);
try {
String validationQuery = "ASK { <" + RDFS.Resource.getURI() + "> " +
" <" + RDFS.isDefinedBy.getURI() + "> " +
" <" + RDFS.Resource.getURI() + "> }";
Query q = QueryFactory.create(validationQuery);
QueryExecution qe = QueryExecutionFactory.create(q, d);
try {
qe.execAsk();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
qe.close();
}
} finally {
d.close();
}
} }
public void close() { public void close() {
store.close(); getStore().close();
} }
public Model createModel(String arg0) { public Model createModel(String arg0) {
Model model = SDBFactory.connectNamedModel(store, arg0); Model model = SDBFactory.connectNamedModel(getStore(), arg0);
metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0); Model metadataModel = getMetadataModel();
try {
metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0);
} finally {
metadataModel.close();
}
return model; return model;
} }
@ -97,22 +187,30 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
} }
public boolean hasModel(String arg0) { public boolean hasModel(String arg0) {
StmtIterator stmtIt = metadataModel.listStatements(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0); Model metadataModel = getMetadataModel();
try { try {
return stmtIt.hasNext(); StmtIterator stmtIt = metadataModel.listStatements(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0);
} finally { try {
if (stmtIt != null) { return stmtIt.hasNext();
stmtIt.close(); } finally {
} if (stmtIt != null) {
} stmtIt.close();
}
}
} finally {
metadataModel.close();
}
} }
public ExtendedIterator listModels() { public ExtendedIterator listModels() {
ArrayList<String> metaNameList = new ArrayList<String>(); ArrayList<String> metaNameList = new ArrayList<String>();
ArrayList<String> storeNameList = new ArrayList<String>(); ArrayList<String> storeNameList = new ArrayList<String>();
ArrayList<String> unionNameList = new ArrayList<String>(); ArrayList<String> unionNameList = new ArrayList<String>();
Model metadataModel = getMetadataModel();
Iterator<RDFNode> metadataNameIt = metadataModel.listObjectsOfProperty(metadataModel.getProperty(HAS_NAMED_MODEL_URI)); Iterator<RDFNode> metadataNameIt = metadataModel.listObjectsOfProperty(metadataModel.getProperty(HAS_NAMED_MODEL_URI));
Iterator<Node> storeNameIt = StoreUtils.storeGraphNames(store); Iterator<Node> storeNameIt = StoreUtils.storeGraphNames(getStore());
Node node = null; Node node = null;
RDFNode rdfNode = null; RDFNode rdfNode = null;
@ -230,17 +328,26 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
}while(metaString!=null || storeString!=null); }while(metaString!=null || storeString!=null);
if (metadataModel != null) {
metadataModel.close();
}
return WrappedIterator.create(unionNameList.iterator()); return WrappedIterator.create(unionNameList.iterator());
} }
public Model openModel(String arg0, boolean arg1) { public Model openModel(String arg0, boolean arg1) {
return SDBFactory.connectNamedModel(store,arg0); return SDBFactory.connectNamedModel(getStore(),arg0);
} }
public void removeModel(String arg0) { public void removeModel(String arg0) {
Model m = getModel(arg0); Model m = getModel(arg0);
m.removeAll(null,null,null); m.removeAll(null,null,null);
metadataModel.remove(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),metadataModel.createLiteral(arg0)); Model metadataModel = getMetadataModel();
try {
metadataModel.remove(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),metadataModel.createLiteral(arg0));
} finally {
metadataModel.close();
}
} }
public Model addDescription(Model arg0, Resource arg1) { public Model addDescription(Model arg0, Resource arg1) {
@ -260,11 +367,11 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
} }
public Model openModel() { public Model openModel() {
return SDBFactory.connectDefaultModel(store); return SDBFactory.connectDefaultModel(getStore());
} }
public Model createDefaultModel() { public Model createDefaultModel() {
return SDBFactory.connectDefaultModel(store); return SDBFactory.connectDefaultModel(getStore());
} }
public Model createFreshModel() { public Model createFreshModel() {
@ -275,26 +382,26 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
* @deprecated * @deprecated
*/ */
public Model createModel() { public Model createModel() {
return SDBFactory.connectDefaultModel(store); return SDBFactory.connectDefaultModel(getStore());
} }
/** /**
* @deprecated * @deprecated
*/ */
public Model getModel() { public Model getModel() {
return SDBFactory.connectDefaultModel(store); return SDBFactory.connectDefaultModel(getStore());
} }
public Model openModel(String arg0) { public Model openModel(String arg0) {
return SDBFactory.connectDefaultModel(store); return SDBFactory.connectDefaultModel(getStore());
} }
public Model openModelIfPresent(String arg0) { public Model openModelIfPresent(String arg0) {
return (this.hasModel(arg0)) ? SDBFactory.connectNamedModel(store,arg0) : null; return (this.hasModel(arg0)) ? SDBFactory.connectNamedModel(getStore(),arg0) : null;
} }
public Model getModel(String arg0) { public Model getModel(String arg0) {
return SDBFactory.connectNamedModel(store, arg0); return SDBFactory.connectNamedModel(getStore(), arg0);
} }
public Model getModel(String arg0, ModelReader arg1) { public Model getModel(String arg0, ModelReader arg1) {

View file

@ -15,6 +15,7 @@ import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation; import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.query.DataSource; import com.hp.hpl.jena.query.DataSource;
import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Dataset;
@ -72,7 +73,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
protected KeywordDao keywordDao; protected KeywordDao keywordDao;
protected LinksDao linksDao; protected LinksDao linksDao;
protected LinktypeDao linktypeDao; protected LinktypeDao linktypeDao;
protected ApplicationDao applicationDao; protected ApplicationDaoJena applicationDao;
protected PortalDao portalDao; protected PortalDao portalDao;
protected TabDao tabDao; protected TabDao tabDao;
protected TabIndividualRelationDao tabs2EntsDao; protected TabIndividualRelationDao tabs2EntsDao;
@ -118,6 +119,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
this.userURI = userURI; this.userURI = userURI;
this.flag2ValueMap = base.flag2ValueMap; this.flag2ValueMap = base.flag2ValueMap;
this.flag2ClassLabelMap = base.flag2ClassLabelMap; this.flag2ClassLabelMap = base.flag2ClassLabelMap;
this.dwf = base.dwf;
} }
public WebappDaoFactoryJena(OntModelSelector ontModelSelector, public WebappDaoFactoryJena(OntModelSelector ontModelSelector,
@ -174,22 +176,37 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
if (languageUniversalsModel.size()>0) { if (languageUniversalsModel.size()>0) {
this.ontModelSelector.getTBoxModel().addSubModel(languageUniversalsModel); this.ontModelSelector.getTBoxModel().addSubModel(languageUniversalsModel);
} }
DataSource dataset = DatasetFactory.create();
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_DB_MODEL, Model assertions = (baseOntModelSelector != null)
(baseOntModelSelector != null) ? baseOntModelSelector.getFullModel()
? baseOntModelSelector.getFullModel() : ontModelSelector.getFullModel();
: ontModelSelector.getFullModel()); Model inferences = (inferenceOntModelSelector != null)
if (inferenceOntModelSelector != null) { ? inferenceOntModelSelector.getFullModel()
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_INF_MODEL, : null;
inferenceOntModelSelector.getFullModel());
} Dataset dataset = makeInMemoryDataset(assertions, inferences);
this.dwf = new StaticDatasetFactory(dataset); this.dwf = new StaticDatasetFactory(dataset);
} }
public static Dataset makeInMemoryDataset(Model assertions, Model inferences) {
DataSource dataset = DatasetFactory.create();
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
if (assertions != null) {
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_DB_MODEL, assertions);
union.addSubModel(assertions);
}
if (inferences != null) {
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_INF_MODEL,
inferences);
union.addSubModel(inferences);
}
dataset.setDefaultModel(union);
return dataset;
}
public WebappDaoFactoryJena(OntModelSelector ontModelSelector, public WebappDaoFactoryJena(OntModelSelector ontModelSelector,
String defaultNamespace, String defaultNamespace,
HashSet<String> nonuserNamespaces, HashSet<String> nonuserNamespaces,
@ -641,5 +658,12 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
public DisplayModelDao getDisplayModelDao(){ public DisplayModelDao getDisplayModelDao(){
return new DisplayModelDaoJena( this ); return new DisplayModelDaoJena( this );
} }
@Override
public void close() {
if (applicationDao != null) {
applicationDao.close();
}
}
} }

View file

@ -18,14 +18,16 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class WebappDaoFactorySDB extends WebappDaoFactoryJena { public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
private SDBDatasetMode datasetMode = SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
/** /**
* For use when any database connection associated with the Dataset * For use when any database connection associated with the Dataset
* is managed externally * is managed externally
* @param ontModelSelector
* @param dataset
*/ */
public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) { public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) {
super(ontModelSelector); super(ontModelSelector);
@ -35,8 +37,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
/** /**
* For use when any database connection associated with the Dataset * For use when any database connection associated with the Dataset
* is managed externally * is managed externally
* @param ontModelSelector
* @param dataset
*/ */
public WebappDaoFactorySDB(OntModelSelector ontModelSelector, public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
Dataset dataset, Dataset dataset,
@ -50,8 +50,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
/** /**
* For use when any Dataset access should get a temporary DB connection * For use when any Dataset access should get a temporary DB connection
* from a pool * from a pool
* @param ontModelSelector
* @param dataset
*/ */
public WebappDaoFactorySDB(OntModelSelector ontModelSelector, public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
BasicDataSource bds, BasicDataSource bds,
@ -62,13 +60,43 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages); super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages);
this.dwf = new ReconnectingDatasetFactory(bds, storeDesc); this.dwf = new ReconnectingDatasetFactory(bds, storeDesc);
} }
/**
* For use when any Dataset access should get a temporary DB connection
* from a pool, and access to the inference graph needs to be specified.
*/
public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
BasicDataSource bds,
StoreDesc storeDesc,
String defaultNamespace,
HashSet<String> nonuserNamespaces,
String[] preferredLanguages,
SDBDatasetMode datasetMode) {
super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages);
this.dwf = new ReconnectingDatasetFactory(bds, storeDesc);
this.datasetMode = datasetMode;
}
public WebappDaoFactorySDB(WebappDaoFactorySDB base, String userURI) {
super(base.ontModelSelector);
this.ontModelSelector = base.ontModelSelector;
this.defaultNamespace = base.defaultNamespace;
this.nonuserNamespaces = base.nonuserNamespaces;
this.preferredLanguages = base.preferredLanguages;
this.userURI = userURI;
this.flag2ValueMap = base.flag2ValueMap;
this.flag2ClassLabelMap = base.flag2ClassLabelMap;
this.dwf = base.dwf;
}
@Override @Override
public IndividualDao getIndividualDao() { public IndividualDao getIndividualDao() {
if (entityWebappDao != null) if (entityWebappDao != null)
return entityWebappDao; return entityWebappDao;
else else
return entityWebappDao = new IndividualDaoSDB(dwf, this); return entityWebappDao = new IndividualDaoSDB(
dwf, datasetMode, this);
} }
@Override @Override
@ -76,7 +104,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (dataPropertyStatementDao != null) if (dataPropertyStatementDao != null)
return dataPropertyStatementDao; return dataPropertyStatementDao;
else else
return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(dwf, this); return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(
dwf, datasetMode, this);
} }
@Override @Override
@ -84,7 +113,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (objectPropertyStatementDao != null) if (objectPropertyStatementDao != null)
return objectPropertyStatementDao; return objectPropertyStatementDao;
else else
return objectPropertyStatementDao = new ObjectPropertyStatementDaoSDB(dwf, this); return objectPropertyStatementDao =
new ObjectPropertyStatementDaoSDB(dwf, datasetMode, this);
} }
@Override @Override
@ -92,15 +122,58 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (vClassDao != null) if (vClassDao != null)
return vClassDao; return vClassDao;
else else
return vClassDao = new VClassDaoSDB(dwf, this); return vClassDao = new VClassDaoSDB(dwf, datasetMode, this);
}
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
// TODO: put the user-aware factories in a hashmap so we don't keep re-creating them
return new WebappDaoFactorySDB(this, userURI);
}
public enum SDBDatasetMode {
ASSERTIONS_ONLY, INFERENCES_ONLY, ASSERTIONS_AND_INFERENCES
}
public static String getFilterBlock(String[] graphVars,
SDBDatasetMode datasetMode) {
StringBuffer filterBlock = new StringBuffer();
for (int i = 0; i < graphVars.length; i++) {
switch (datasetMode) {
case ASSERTIONS_ONLY :
filterBlock.append("FILTER (")
.append("(!bound(").append(graphVars[i])
.append(")) || (")
.append(graphVars[i])
.append(" != <")
.append(JenaDataSourceSetupBase.JENA_INF_MODEL)
.append("> && ").append(graphVars[i])
.append(" != <")
.append(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL)
.append(">) ) \n");
break;
case INFERENCES_ONLY :
filterBlock.append("FILTER (")
.append("(!bound(").append(graphVars[i])
.append(")) || (")
.append(graphVars[i])
.append(" = <")
.append(JenaDataSourceSetupBase.JENA_INF_MODEL)
.append("> || ").append(graphVars[i])
.append(" = <")
.append(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL)
.append(">) )\n");
break;
default:
break;
}
}
return filterBlock.toString();
} }
private class ReconnectingDatasetFactory implements DatasetWrapperFactory { private class ReconnectingDatasetFactory implements DatasetWrapperFactory {
private BasicDataSource _bds; private BasicDataSource _bds;
private StoreDesc _storeDesc; private StoreDesc _storeDesc;
private Dataset _dataset;
private Connection _conn;
public ReconnectingDatasetFactory(BasicDataSource bds, StoreDesc storeDesc) { public ReconnectingDatasetFactory(BasicDataSource bds, StoreDesc storeDesc) {
_bds = bds; _bds = bds;
@ -109,20 +182,16 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
public DatasetWrapper getDatasetWrapper() { public DatasetWrapper getDatasetWrapper() {
try { try {
if ((_dataset != null) && (_conn != null) && (!_conn.isClosed())) { Connection sqlConn = _bds.getConnection();
return new DatasetWrapper(_dataset); SDBConnection conn = new SDBConnection(sqlConn) ;
} else { Store store = SDBFactory.connectStore(conn, _storeDesc);
_conn = _bds.getConnection(); Dataset dataset = SDBFactory.connectDataset(store);
SDBConnection conn = new SDBConnection(_conn) ; return new DatasetWrapper(dataset, conn);
Store store = SDBFactory.connectStore(conn, _storeDesc);
_dataset = SDBFactory.connectDataset(store);
return new DatasetWrapper(_dataset);
}
} catch (SQLException sqe) { } catch (SQLException sqe) {
throw new RuntimeException("Unable to connect to database", sqe); throw new RuntimeException("Unable to connect to database", sqe);
} }
} }
} }
} }

View file

@ -36,16 +36,6 @@ public class PropertyDWR {
public PropertyDWR(){ public PropertyDWR(){
} }
private WebappDaoFactory getUnfilteredWebappDaoFactory(VitroRequest vreq) {
try {
return (WebappDaoFactory) vreq.getSession().getServletContext().getAttribute("webappDaoFactory");
} catch (ClassCastException e) {
log.warn("Could not find unfiltered WebappDaoFactory in getServletContext().getAttribute(\"webappDaoFactory\"). " +
"Using vreq.getWebappDaoFactory() instead.");
return vreq.getWebappDaoFactory();
}
}
public Object test(){ public Object test(){
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest(); HttpServletRequest req = ctx.getHttpServletRequest();
@ -65,7 +55,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest(); HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory(); WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
Collection c = Collection c =
wdf.getPropertyInstanceDao().getAllPropInstByVClass(classURI); wdf.getPropertyInstanceDao().getAllPropInstByVClass(classURI);
@ -76,7 +66,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest(); HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory(); WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
Collection c = Collection c =
wdf.getPropertyInstanceDao().getAllPossiblePropInstForIndividual(individualURI); wdf.getPropertyInstanceDao().getAllPossiblePropInstForIndividual(individualURI);
@ -87,7 +77,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest(); HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory(); WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
return wdf.getPropertyInstanceDao().getProperty(subjectURI, predicateURI, objectURI); return wdf.getPropertyInstanceDao().getProperty(subjectURI, predicateURI, objectURI);
} }
@ -121,16 +111,14 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest(); HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
return vreq.getFullWebappDaoFactory().getPropertyInstanceDao().insertProp(prop);
return getUnfilteredWebappDaoFactory(vreq).getPropertyInstanceDao().insertProp(prop);
} }
public int deleteProp(String subjectUri, String predicateUri, String objectUri){ public int deleteProp(String subjectUri, String predicateUri, String objectUri){
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest(); HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
vreq.getFullWebappDaoFactory().getPropertyInstanceDao().deleteObjectPropertyStatement(subjectUri, predicateUri, objectUri);
getUnfilteredWebappDaoFactory(vreq).getPropertyInstanceDao().deleteObjectPropertyStatement(subjectUri, predicateUri, objectUri);
return 0; return 0;
} }
@ -154,7 +142,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get(); WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest(); HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory(); WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
return wdf.getPropertyInstanceDao().getExistingProperties(entityURI, null); return wdf.getPropertyInstanceDao().getExistingProperties(entityURI, null);
} }

View file

@ -95,7 +95,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
this.displayRequiredLevel = toPrecision( displayRequiredLevelUri ); this.displayRequiredLevel = toPrecision( displayRequiredLevelUri );
if( this.displayRequiredLevel == null ) if( this.displayRequiredLevel == null )
throw new IllegalArgumentException(minimumPrecisionURI throw new IllegalArgumentException(displayRequiredLevelUri
+" is not a valid precision for displayRequiredLevel, see VitroVocabulary.Precision"); +" is not a valid precision for displayRequiredLevel, see VitroVocabulary.Precision");
// if( this.displayRequiredLevel.ordinal() < this.minimumPrecision.ordinal() ){ // if( this.displayRequiredLevel.ordinal() < this.minimumPrecision.ordinal() ){
@ -127,7 +127,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
map.put("minimumPrecision", minimumPrecision.uri()); map.put("minimumPrecision", minimumPrecision.uri());
map.put("requiredLevel", displayRequiredLevel.uri()); map.put("requiredLevel", displayRequiredLevel.uri());
String precisionUri = getExistingPrecision(editConfig,editSub); String precisionUri = getPrecision(editConfig,editSub);
VitroVocabulary.Precision existingPrec = toPrecision(precisionUri); VitroVocabulary.Precision existingPrec = toPrecision(precisionUri);
if( precisionUri != null && !"".equals(precisionUri) && existingPrec == null ){ if( precisionUri != null && !"".equals(precisionUri) && existingPrec == null ){
@ -216,22 +216,35 @@ public class DateTimeWithPrecision extends BaseEditElement {
/** /**
* Gets the currently set precision. May return null. * Gets the currently set precision. May return null.
*/ */
private String getExistingPrecision(EditConfiguration editConfig, EditSubmission editSub) { private String getPrecision(EditConfiguration editConfig, EditSubmission editSub) {
String precisionURI = editConfig.getUrisInScope().get( getPrecisionVariableName() ); if( editSub != null ){
if( precisionURI == null ){ String submittedPrecisionURI = editSub.getUrisFromForm().get( getPrecisionVariableName() );
return null; if( submittedPrecisionURI != null ){
return submittedPrecisionURI;
}
}
String existingPrecisionURI = editConfig.getUrisInScope().get( getPrecisionVariableName() );
if( existingPrecisionURI != null ){
return existingPrecisionURI;
}else{ }else{
return precisionURI; return null;
} }
} }
private DateTime getTimeValue(EditConfiguration editConfig, EditSubmission editSub) { private DateTime getTimeValue(EditConfiguration editConfig, EditSubmission editSub) {
if( editSub != null ){
Literal submittedValue = editSub.getLiteralsFromForm().get( getValueVariableName() );
if( submittedValue != null )
return new DateTime( submittedValue.getLexicalForm() );
}
Literal dtValue = editConfig.getLiteralsInScope().get( getValueVariableName() ); Literal dtValue = editConfig.getLiteralsInScope().get( getValueVariableName() );
if( dtValue == null ){ if( dtValue != null ){
return null;
}else{
return new DateTime( dtValue.getLexicalForm() ); return new DateTime( dtValue.getLexicalForm() );
} }else{
return null;
}
} }
/** /**
@ -366,7 +379,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
} }
} }
if( nonNullAfterFirstNull ) if( nonNullAfterFirstNull )
throw new Exception("cannot determine precision, there were filled out values after the first un-filledout value, "); throw new Exception("Invalid date-time value. When creating a date-time value, there cannot be gaps between any of the selected fields.");
else{ else{
return precisions[ indexOfFirstNull ].uri(); return precisions[ indexOfFirstNull ].uri();
} }
@ -486,29 +499,32 @@ public class DateTimeWithPrecision extends BaseEditElement {
if( second == null ) if( second == null )
second = 0; second = 0;
DateTime dateTime = new DateTime(); //initialize to something so that we can be assured not to get
//system date dependent behavior
DateTime dateTime = new DateTime("1970-01-01T00:00:00Z");
try{ try{
dateTime.withYear(year); dateTime = dateTime.withYear(year);
}catch(IllegalArgumentException iae){ }catch(IllegalArgumentException iae){
errors.put(fieldName+".year", iae.getLocalizedMessage()); errors.put(fieldName+".year", iae.getLocalizedMessage());
} }
try{ try{
dateTime.withMonthOfYear(month); dateTime = dateTime.withMonthOfYear(month);
}catch(IllegalArgumentException iae){ }catch(IllegalArgumentException iae){
errors.put(fieldName+".month", iae.getLocalizedMessage()); errors.put(fieldName+".month", iae.getLocalizedMessage());
} }
try{ try{
dateTime.withDayOfMonth(day); dateTime = dateTime.withDayOfMonth(day);
}catch(IllegalArgumentException iae){ }catch(IllegalArgumentException iae){
errors.put(fieldName+".day", iae.getLocalizedMessage()); errors.put(fieldName+".day", iae.getLocalizedMessage());
} }
try{ try{
dateTime.withHourOfDay(hour); dateTime = dateTime.withHourOfDay(hour);
}catch(IllegalArgumentException iae){ }catch(IllegalArgumentException iae){
errors.put(fieldName+".hour", iae.getLocalizedMessage()); errors.put(fieldName+".hour", iae.getLocalizedMessage());
} }
try{ try{
dateTime.withSecondOfMinute(second); dateTime = dateTime.withSecondOfMinute(second);
}catch(IllegalArgumentException iae){ }catch(IllegalArgumentException iae){
errors.put(fieldName+".second", iae.getLocalizedMessage()); errors.put(fieldName+".second", iae.getLocalizedMessage());
} }
@ -581,7 +597,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
} }
/* returns null if it cannot convert */ /* returns null if it cannot convert */
private static VitroVocabulary.Precision toPrecision(String precisionUri){ public static VitroVocabulary.Precision toPrecision(String precisionUri){
for( VitroVocabulary.Precision precision : VitroVocabulary.Precision.values()){ for( VitroVocabulary.Precision precision : VitroVocabulary.Precision.values()){
if( precision.uri().equals(precisionUri)) if( precision.uri().equals(precisionUri))
return precision; return precision;

View file

@ -12,6 +12,10 @@ import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime; import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.Precision;
import edu.cornell.mannlib.vitro.webapp.edit.elements.DateTimeWithPrecision;
public class DateTimeIntervalValidation implements N3Validator { public class DateTimeIntervalValidation implements N3Validator {
private static Log log = LogFactory.getLog(DateTimeIntervalValidation.class); private static Log log = LogFactory.getLog(DateTimeIntervalValidation.class);
@ -20,12 +24,17 @@ public class DateTimeIntervalValidation implements N3Validator {
private String startValueName; private String startValueName;
private String endValueName; private String endValueName;
private String startPrecisionName;
private String endPrecisionName;
public DateTimeIntervalValidation(String startFieldName, String endFieldName){ public DateTimeIntervalValidation(String startFieldName, String endFieldName){
this.startFieldName = startFieldName; this.startFieldName = startFieldName;
this.endFieldName = endFieldName; this.endFieldName = endFieldName;
startValueName = startFieldName + ".value"; startValueName = startFieldName + ".value";
endValueName = endFieldName + ".value"; endValueName = endFieldName + ".value";
startPrecisionName = startFieldName + ".precision";
endPrecisionName = endFieldName + ".precision";
} }
public Map<String, String> validate(EditConfiguration editConfig, public Map<String, String> validate(EditConfiguration editConfig,
@ -38,16 +47,24 @@ public class DateTimeIntervalValidation implements N3Validator {
Literal formStartYear = literalsFromForm.get(startValueName); Literal formStartYear = literalsFromForm.get(startValueName);
Literal formEndYear = literalsFromForm.get(endValueName); Literal formEndYear = literalsFromForm.get(endValueName);
VitroVocabulary.Precision startPrecision = getPrecision(startPrecisionName, editConfig, editSub);
VitroVocabulary.Precision endPrecision = getPrecision(endPrecisionName, editConfig, editSub);
Map<String, String> errors = new HashMap<String, String>(); Map<String, String> errors = new HashMap<String, String>();
if( formStartYear == null && formEndYear != null ){
errors.put(startFieldName, "If there is an end date, there should be a start date");
return errors;
}
if (formStartYear != null && formEndYear != null) { if (formStartYear != null && formEndYear != null) {
errors.putAll(checkDateLiterals(formStartYear, formEndYear)); errors.putAll(checkDateLiterals(formStartYear, formEndYear, startPrecision, endPrecision));
} else if (formStartYear != null && existingEndYear != null) { } else if (formStartYear != null && existingEndYear != null) {
errors.putAll(checkDateLiterals(formStartYear, existingEndYear)); errors.putAll(checkDateLiterals(formStartYear, existingEndYear, startPrecision, endPrecision));
} else if (existingStartYear != null && formEndYear != null) { } else if (existingStartYear != null && formEndYear != null) {
errors.putAll(checkDateLiterals(existingStartYear, formEndYear)); errors.putAll(checkDateLiterals(existingStartYear, formEndYear, startPrecision, endPrecision));
} else if (existingStartYear != null && existingEndYear != null) { } else if (existingStartYear != null && existingEndYear != null) {
errors.putAll(checkDateLiterals(existingStartYear, existingEndYear)); errors.putAll(checkDateLiterals(existingStartYear, existingEndYear, startPrecision, endPrecision));
} }
if (errors.size() != 0) if (errors.size() != 0)
@ -56,8 +73,41 @@ public class DateTimeIntervalValidation implements N3Validator {
return null; return null;
} }
private Map<String, String> checkDateLiterals(Literal startLit, Literal endLit) { private Precision getPrecision(String precisionVarName,
EditConfiguration editConfig, EditSubmission editSub) {
if( editSub != null
&& editSub.getUrisFromForm() != null
&& editSub.getUrisFromForm().containsKey(precisionVarName)){
String precisionStr = editSub.getUrisFromForm().get(precisionVarName);
VitroVocabulary.Precision precision = DateTimeWithPrecision.toPrecision( precisionStr );
if( precision == null )
log.warn("cannot convert " + precisionStr + " to a precision");
else
return precision;
}else if( editConfig != null
&& editConfig.getUrisInScope() != null
&& editConfig.getUrisInScope().containsKey(precisionVarName)){
String precisionStr = editConfig.getUrisInScope().get(precisionVarName);
VitroVocabulary.Precision precision = DateTimeWithPrecision.toPrecision( precisionStr );
if( precision == null )
log.warn("cannot convert " + precisionStr + " to a precision");
else
return precision;
}
//this is what is returned if a precision was not found in the config or submission
return null;
}
private Map<String, String> checkDateLiterals(
Literal startLit, Literal endLit,
VitroVocabulary.Precision startPrecision, VitroVocabulary.Precision endPrecision) {
Map<String, String> errors = new HashMap<String, String>(); Map<String, String> errors = new HashMap<String, String>();
if( endPrecision == null ){
//there is no end date, nothing to check
return errors;
}
try{ try{
XSDDateTime startDate = (XSDDateTime)startLit.getValue(); XSDDateTime startDate = (XSDDateTime)startLit.getValue();
XSDDateTime endDate = (XSDDateTime)endLit.getValue(); XSDDateTime endDate = (XSDDateTime)endLit.getValue();
@ -65,9 +115,16 @@ public class DateTimeIntervalValidation implements N3Validator {
Calendar startCal = startDate.asCalendar(); Calendar startCal = startDate.asCalendar();
Calendar endCal = endDate.asCalendar(); Calendar endCal = endDate.asCalendar();
if( endCal != null && ! endCal.after( startCal ) ){ if( endCal != null ){
errors.put(startFieldName, "Start year must be before end year"); if( !startCal.before( endCal ) ){
errors.put(endFieldName, "End year must be after start year"); if( startPrecision == VitroVocabulary.Precision.YEAR
&& endPrecision == VitroVocabulary.Precision.YEAR ){
errors.putAll( checkYears(startCal,endCal));
}else{
errors.put(startFieldName, "Start must be before end");
errors.put(endFieldName, "End must be after start");
}
}
} }
} }
}catch(ClassCastException cce){ }catch(ClassCastException cce){
@ -79,4 +136,16 @@ public class DateTimeIntervalValidation implements N3Validator {
return errors; return errors;
} }
private Map<? extends String, ? extends String> checkYears(
Calendar startCal, Calendar endCal) {
Map<String, String> errors = new HashMap<String, String>();
if( ! (endCal.get(Calendar.YEAR) >= startCal.get(Calendar.YEAR) )){
errors.put(startFieldName, "Start must be before end");
errors.put(endFieldName, "End must be after start");
}
return errors;
}
} }

View file

@ -91,7 +91,7 @@ public class EditN3Utils {
// //
// } catch (Exception e) { // } catch (Exception e) {
// log.error("Error in updatePropertyDateTimeValue"); // log.error("Error in updatePropertyDateTimeValue");
// log.error(e); // log.error(e, e);
// } // }
// } // }
// //

View file

@ -215,7 +215,7 @@ public class EditSubmission {
try { try {
return literalCreationModel.createTypedLiteral( URLEncoder.encode(value, "UTF8"), datatypeUri); return literalCreationModel.createTypedLiteral( URLEncoder.encode(value, "UTF8"), datatypeUri);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error(e); log.error(e, e);
} }
} }
return literalCreationModel.createTypedLiteral(value, datatypeUri); return literalCreationModel.createTypedLiteral(value, datatypeUri);

View file

@ -11,7 +11,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -32,11 +31,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
public class SelectListGenerator { public class SelectListGenerator {
@ -188,13 +182,11 @@ public class SelectListGenerator {
if( stmts == null ) log.error("object properties for subject were null in SelectListGenerator.getOptions()"); if( stmts == null ) log.error("object properties for subject were null in SelectListGenerator.getOptions()");
individuals = removeIndividualsAlreadyInRange(individuals,stmts,predicateUri,editConfig.getObject()); individuals = removeIndividualsAlreadyInRange(individuals,stmts,predicateUri,editConfig.getObject());
//Collections.sort(individuals,new compareIndividualsByName()); //Collections.sort(individuals,new compareIndividualsByName());
ProhibitedFromSearch pfs = editConfig.getProhibitedFromSearch();
for( Individual ind : individuals ){ for( Individual ind : individuals ){
String uri = ind.getURI(); String uri = ind.getURI();
if( uri != null && (pfs == null || !ind.isMemberOfClassProhibitedFromSearch(pfs)) ){ if( uri != null ){
optionsMap.put(uri,ind.getName().trim()); optionsMap.put(uri,ind.getName().trim());
++optionsCount; ++optionsCount;
} }
@ -279,10 +271,9 @@ public class SelectListGenerator {
log.error("No individuals of type "+vclass.getName()+" to add to pick list in SelectListGenerator.getOptions(); check portal visibility"); log.error("No individuals of type "+vclass.getName()+" to add to pick list in SelectListGenerator.getOptions(); check portal visibility");
optionsMap.put("", "No " + vclass.getName() + " found"); optionsMap.put("", "No " + vclass.getName() + " found");
}else{ }else{
ProhibitedFromSearch pfs = editConfig.getProhibitedFromSearch();
for( Individual ind : individuals ) { for( Individual ind : individuals ) {
String uri = ind.getURI(); String uri = ind.getURI();
if( uri != null && (pfs == null || !ind.isMemberOfClassProhibitedFromSearch(pfs)) ) { if( uri != null ) {
optionsMap.put(uri,ind.getName().trim()); optionsMap.put(uri,ind.getName().trim());
++optionsCount; ++optionsCount;
} }

View file

@ -7,8 +7,12 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -40,30 +44,26 @@ public class FileStorageAliasAdder {
/** /**
* Query: get all bytestream resources that do not have alias URLs. * Query: get all bytestream resources that do not have alias URLs.
*/ */
private static final String QUERY_WORK_TO_DO = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" private static final String QUERY_BYTESTREAMS_WITHOUT_ALIASES = ""
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#>\n" + "PREFIX public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#>\n"
+ "SELECT ?bs\n" + "SELECT ?bs\n" + "WHERE {\n"
+ "WHERE {\n"
+ " ?bs rdf:type public:FileByteStream\n" + " ?bs rdf:type public:FileByteStream\n"
+ " OPTIONAL { ?bs public:directDownloadUrl ?alias }\n" + " OPTIONAL { ?bs public:directDownloadUrl ?alias }\n"
+ " FILTER ( !BOUND(?alias) )\n" + "}\n"; + " FILTER ( !BOUND(?alias) )\n" + "}\n";
/** /**
* Query: get all bytestream resources that do not have alias URLs. Get * Query: get the filenames for all bytestream resources that do not have
* their filenames from their surrogates also. * alias URLs.
*/ */
private static final String QUERY_MORE_INFO = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" private static final String QUERY_FILENAMES_FOR_BYTESTREAMS = ""
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#>\n" + "PREFIX public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#>\n"
+ "SELECT ?bs ?f ?fn\n" + "SELECT ?bs ?fn\n" + "WHERE {\n"
+ "WHERE {\n"
+ " ?bs rdf:type public:FileByteStream . \n" + " ?bs rdf:type public:FileByteStream . \n"
+ " ?f public:downloadLocation ?bs . \n" + " ?f public:downloadLocation ?bs . \n"
+ " OPTIONAL { \n" + " ?f public:filename ?fn . \n"
+ " ?f public:filename ?fn . \n" + " OPTIONAL { ?bs public:directDownloadUrl ?alias . }\n"
+ " }\n"
+ " OPTIONAL { \n"
+ " ?bs public:directDownloadUrl ?alias . \n"
+ " }\n"
+ " FILTER ( !BOUND(?alias) )\n" + "}\n"; + " FILTER ( !BOUND(?alias) )\n" + "}\n";
private final Model model; private final Model model;
@ -72,6 +72,9 @@ public class FileStorageAliasAdder {
private FSULog updateLog; private FSULog updateLog;
private Set<String> bytestreamUrisWithoutAliases;
private Map<String, String> bytestreamUrisAndFilenames;
public FileStorageAliasAdder(Model model, File uploadDirectory, public FileStorageAliasAdder(Model model, File uploadDirectory,
String vivoDefaultNamespace) { String vivoDefaultNamespace) {
this.model = model; this.model = model;
@ -120,7 +123,7 @@ public class FileStorageAliasAdder {
* URL, we have work to do. * URL, we have work to do.
*/ */
private boolean isThereAnythingToDo() { private boolean isThereAnythingToDo() {
String queryString = QUERY_WORK_TO_DO; String queryString = QUERY_BYTESTREAMS_WITHOUT_ALIASES;
log.debug("query: " + queryString); log.debug("query: " + queryString);
QueryExecution qexec = null; QueryExecution qexec = null;
@ -165,31 +168,104 @@ public class FileStorageAliasAdder {
* Add an alias URL to any FileByteStream object that doesn't have one. * Add an alias URL to any FileByteStream object that doesn't have one.
*/ */
private void findAndAddMissingAliasUrls() { private void findAndAddMissingAliasUrls() {
List<BytestreamInfo> list; findBytestreamsWithoutAliasUrls();
list = findBytestreamsWithMissingValues(); findFilenamesForBytestreams();
addMissingValuesToModel(list); addAliasUrlsToModel();
} }
/** /**
* Find every bytestream that doesn't have an alias URL. Find the filename * Find every bytestream that doesn't have an alias URL.
* for the bytestream also.
*/ */
private List<BytestreamInfo> findBytestreamsWithMissingValues() { private void findBytestreamsWithoutAliasUrls() {
List<BytestreamInfo> list = new ArrayList<BytestreamInfo>(); BytestreamUriUnpacker unpacker = new BytestreamUriUnpacker();
String queryString = QUERY_MORE_INFO;
runQuery(QUERY_BYTESTREAMS_WITHOUT_ALIASES, unpacker);
this.bytestreamUrisWithoutAliases = unpacker.getUris();
log.debug("Found " + unpacker.getUris().size()
+ " bytestreams without alias URLs");
}
/**
* Find the filename for every bytestream that doesn't have an alias URL.
*/
private void findFilenamesForBytestreams() {
FilenameUnpacker unpacker = new FilenameUnpacker();
runQuery(QUERY_FILENAMES_FOR_BYTESTREAMS, unpacker);
this.bytestreamUrisAndFilenames = unpacker.getFilenameMap();
log.debug("Found " + unpacker.getFilenameMap().size()
+ " bytestreams with filenames but no alias URLs");
}
/** Add an alias URL to each resource in the list. */
private void addAliasUrlsToModel() {
if (this.bytestreamUrisWithoutAliases.isEmpty()) {
updateLog.warn("Found no bytestreams without aliases. "
+ "Why am I here?");
return;
}
Property aliasProperty = model
.createProperty(VitroVocabulary.FS_ALIAS_URL);
for (String bytestreamUri : this.bytestreamUrisWithoutAliases) {
String aliasUrl = figureAliasUrl(bytestreamUri);
Resource resource = model.getResource(bytestreamUri);
ModelWrapper.add(model, resource, aliasProperty, aliasUrl);
updateLog.log(resource, "added alias URL: '" + aliasUrl + "'");
}
}
/**
* Convert the bytestream URI and the filename into an alias URL.
*
* If they aren't in our default namespace, or they don't have a filename,
* then their URI is the best we can do for an alias URL.
*/
private String figureAliasUrl(String bytestreamUri) {
if (!bytestreamUri.startsWith(vivoDefaultNamespace)) {
updateLog.warn("bytestream uri does not start "
+ "with the default namespace: '" + bytestreamUri + "'");
return bytestreamUri;
}
String filename = this.bytestreamUrisAndFilenames.get(bytestreamUri);
if (filename == null) {
updateLog.warn("bytestream has no surrogate or no filename: '"
+ bytestreamUri + "'");
return "filename_not_found";
}
try {
String remainder = bytestreamUri.substring(vivoDefaultNamespace
.length());
String encodedFilename = URLEncoder.encode(filename, "UTF-8");
String separator = remainder.endsWith("/") ? "" : "/";
return FILE_PATH + remainder + separator + encodedFilename;
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e); // No UTF-8? Can't happen.
}
}
private void runQuery(String queryString, QueryResultUnpacker unpacker) {
log.debug("query: " + queryString); log.debug("query: " + queryString);
QueryExecution qexec = null; QueryExecution qexec = null;
try { try {
qexec = createQueryExecutor(queryString); qexec = createQueryExecutor(queryString);
Iterator<?> results = qexec.execSelect(); Iterator<QuerySolution> results = qexec.execSelect();
while (results.hasNext()) { while (results.hasNext()) {
QuerySolution result = (QuerySolution) results.next(); QuerySolution result = results.next();
BytestreamInfo bs = captureQueryResult(result); if (log.isDebugEnabled()) {
if (bs != null) { log.debug("Query result variables: "
list.add(bs); + listVariables(result));
} }
unpacker.unpack(result);
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
@ -198,76 +274,6 @@ public class FileStorageAliasAdder {
qexec.close(); qexec.close();
} }
} }
return list;
}
/**
* Capture the data from each valid query result. If this data isn't
* perfectly valid, complain and return null instead.
*/
private BytestreamInfo captureQueryResult(QuerySolution result) {
if (log.isDebugEnabled()) {
log.debug("Query result variables: " + listVariables(result));
}
Resource bytestream = result.getResource("bs");
if (bytestream == null) {
updateLog.error("Query result contains no bytestream resource: "
+ result);
return null;
}
String uri = bytestream.getURI();
if (!uri.startsWith(vivoDefaultNamespace)) {
updateLog.warn("uri does not start with the default namespace: '"
+ uri + "'");
return null;
}
Literal filenameLiteral = result.getLiteral("fn");
if (filenameLiteral == null) {
updateLog.error("Query result for '" + uri
+ "' contains no filename.");
return null;
}
String filename = filenameLiteral.getString();
return new BytestreamInfo(uri, filename);
}
/** Add an alias URL to each resource in the list. */
private void addMissingValuesToModel(List<BytestreamInfo> list) {
if (list.isEmpty()) {
updateLog.warn("Query found no valid results.");
return;
}
Property aliasProperty = model
.createProperty(VitroVocabulary.FS_ALIAS_URL);
for (BytestreamInfo bytestreamInfo : list) {
String value = figureAliasUrl(bytestreamInfo);
Resource resource = model.getResource(bytestreamInfo.uri);
ModelWrapper.add(model, resource, aliasProperty, value);
updateLog.log(resource, "added alias URL: '" + value + "'");
}
}
/**
* Convert the bytestream URI and the filename into an alias URL. If
* problems, return null.
*/
String figureAliasUrl(BytestreamInfo bsi) {
try {
String remainder = bsi.uri.substring(vivoDefaultNamespace.length());
String filename = URLEncoder.encode(bsi.filename, "UTF-8");
String separator = remainder.endsWith("/") ? "" : "/";
return FILE_PATH + remainder + separator + filename;
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e); // No UTF-8? Can't happen.
}
} }
private QueryExecution createQueryExecutor(String queryString) { private QueryExecution createQueryExecutor(String queryString) {
@ -276,7 +282,6 @@ public class FileStorageAliasAdder {
} }
/** For debug logging. */ /** For debug logging. */
@SuppressWarnings("unchecked")
private List<String> listVariables(QuerySolution result) { private List<String> listVariables(QuerySolution result) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (Iterator<String> names = result.varNames(); names.hasNext();) { for (Iterator<String> names = result.varNames(); names.hasNext();) {
@ -287,13 +292,61 @@ public class FileStorageAliasAdder {
return list; return list;
} }
private static class BytestreamInfo { // ----------------------------------------------------------------------
final String uri; // Helper classes
final String filename; // ----------------------------------------------------------------------
BytestreamInfo(String uri, String filename) { private interface QueryResultUnpacker {
this.uri = uri; public abstract void unpack(QuerySolution result);
this.filename = filename; }
private class BytestreamUriUnpacker implements QueryResultUnpacker {
private final Set<String> uris = new HashSet<String>();
@Override
public void unpack(QuerySolution result) {
Resource bytestream = result.getResource("bs");
if (bytestream == null) {
updateLog.error("Query result contains no "
+ "bytestream resource: " + result);
return;
}
uris.add(bytestream.getURI());
}
public Set<String> getUris() {
return uris;
} }
} }
private class FilenameUnpacker implements QueryResultUnpacker {
private final Map<String, String> filenameMap = new HashMap<String, String>();
@Override
public void unpack(QuerySolution result) {
Resource bytestream = result.getResource("bs");
if (bytestream == null) {
updateLog.error("Query result contains no "
+ "bytestream resource: " + result);
return;
}
String bytestreamUri = bytestream.getURI();
Literal filenameLiteral = result.getLiteral("fn");
if (filenameLiteral == null) {
updateLog.error("Query result for '" + bytestreamUri
+ "' contains no filename.");
return;
}
String filename = filenameLiteral.getString();
filenameMap.put(bytestreamUri, filename);
}
public Map<String, String> getFilenameMap() {
return filenameMap;
}
}
} }

Some files were not shown because too many files have changed in this diff Show more