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
- 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
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
@ -22,9 +26,15 @@ OPTIONAL ELEMENTS
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
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
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
@ -54,20 +61,16 @@ Query for collated property
- Include a ?subclass variable, named as such, in the SELECT clause. If the ?subclass variable
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
?infoResource and core:InformationResource:
OPTIONAL { GRAPH ?g4 { ?subclass rdfs:subClassOf core:InformationResource }
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
subclass bibo:Book but not bibo:Document, assuming the latter is inferred. If both have been
asserted, we will get both.
- Postprocessing removes all but the most specific subclass value from the query result set.
----------------------
Datetimes in the query

View file

@ -72,7 +72,7 @@ public class InfoResponseParser {
throws Exception {
Matcher matcher = pattern.matcher(infoResponse);
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);

View file

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

View file

@ -159,5 +159,8 @@ webapp/web/js/selectivizr.js
# PROBLEM: Can't find any info on licensing.
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
webapp/web/js/sparql/prototype.js

View file

@ -171,7 +171,7 @@
</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>
<!--
@ -315,6 +315,24 @@
<url-pattern>/SearchIndex</url-pattern>
</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-name>MenuN3EditController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.MenuN3EditController</servlet-class>
@ -1505,3 +1523,8 @@
</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.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
public class BaseEditController extends VitroHttpServlet {
@ -159,14 +160,13 @@ public class BaseEditController extends VitroHttpServlet {
try {
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 ) {
try {
ontModel = (OntModel) ctx.getAttribute(MODEL_ATTR_NAME);
} catch (Exception e) {
throw new RuntimeException("Could not find OntModel in context attribute '"+MODEL_ATTR_NAME+"'");
}
ontModel = (OntModel) ModelContext.getBaseOntModelSelector(ctx).getTBoxModel();
}
return ontModel;

View file

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

View file

@ -67,7 +67,7 @@ public class OperationUtils{
* @return
*/
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
* @return
*/
public static Object cloneBean (Object bean, Class beanClass){
public static Object cloneBean (Object bean, Class beanClass, Class iface){
Object newBean = null;
try {
newBean = beanClass.newInstance();
Method[] beanMeths = beanClass.getMethods();
for (int i=0; i<beanMeths.length ; ++i){
String methName = beanMeths[i].getName();
if (methName.indexOf("get")==0){
Method[] beanMeths = iface.getMethods();
for (int i=0; i<beanMeths.length ; ++i) {
Method beanMeth = beanMeths[i];
String methName = beanMeth.getName();
if (methName.startsWith("get")
&& beanMeth.getParameterTypes().length == 0 ) {
String fieldName = methName.substring(3,methName.length());
Class returnType = beanMeths[i].getReturnType();
Class returnType = beanMeth.getReturnType();
try {
Class[] args = new Class[1];
args[0] = returnType;
Method setterMethod = beanClass.getMethod("set"+fieldName,args);
Method setterMethod = iface.getMethod("set"+fieldName,args);
try {
Object fieldVal = beanMeths[i].invoke(bean,(Object[])null);
Object fieldVal = beanMeth.invoke(bean,(Object[])null);
try {
Object[] setArgs = new Object[1];
setArgs[0] = fieldVal;
setterMethod.invoke(newBean,setArgs);
} 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) {
log.error("edu.cornell.mannlib.vitro.edit.utils.OperationUtils encountered InvocationTargetException invoking "+setterMethod.getName());
log.error(ite.getTargetException().getClass().toString());
log.error(OperationUtils.class.getName() +
".cloneBean() " +
" encountered InvocationTargetException"
+ " invoking "
+ setterMethod.getName(), ite);
throw new RuntimeException(ite);
}
} 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) {
log.error(OperationUtils.class.getName()+" encountered InvocationTargetException invoking "+beanMeths[i].getName());
log.error(ite.getTargetException().getClass().toString());
} catch (IllegalArgumentException iae) {
// log.error(OperationUtils.class.getName()+" found that "+beanMeths[i].getName()+" requires one or more arguments. Skipping.");
log.error(OperationUtils.class.getName() +
".cloneBean() encountered " +
" InvocationTargetException invoking " +
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){
// 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
* 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
*/
public class ConfigurationProperties {
@ -144,7 +147,10 @@ public class ConfigurationProperties {
Map<String, String> newMap = new HashMap<String, String>();
for (Enumeration<?> keys = props.keys(); keys.hasMoreElements();) {
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);

View file

@ -130,6 +130,7 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory {
if (uri == null) {
log.debug("Could not find an Individual with a netId of "
+ username);
return null;
}
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.LogFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
/**
* Setups context so that Identifiers for Individuals associated with Users are
* added to requests.
@ -22,6 +24,11 @@ public class UserToIndIdentifierFactorySetup implements ServletContextListener{
private static final Log log = LogFactory.getLog(UserToIndIdentifierFactorySetup.class.getName());
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
ServletContext sc = sce.getServletContext();
ServletIdentifierBundleFactory
.addIdentifierBundleFactory(sc, new UserToIndIdentifierFactory());

View file

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

View file

@ -501,4 +501,8 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
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.
* @author bdc34
*/
public static class DisplayComparatorIgnoringPropertyGroup implements Comparator {
public static class DisplayComparatorIgnoringPropertyGroup implements Comparator {
public int compare(Object o1, Object o2) {
//log.warn("starting property display comparator; ignoring group ");
Property p1 = o1 == null ? null : (Property) o1;
Property p2 = o2 == null ? null : (Property) o2;
if (p1==null || p2==null) {
log.error("Null property passed to DisplayComparatorIgnoringPropertyGroup");
if (p1==null || p2==null) {
return 0;
}
//log.warn("comparing property "+p1.getLocalName()+" (rank "+determineDisplayRank(p1)+") to property "+p2.getLocalName()+" (rank "+determineDisplayRank(p2)+") ...");
int diff = determineDisplayRank(p1) - determineDisplayRank(p2);
if (diff==0) {
String p1Str = p1.getLabel() == null ? p1.getURI() : p1.getLabel();
if (p1.getLabel()==null) {
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());
}
String p1Str = p1.getLabel() == null ? p1.getURI() : p1.getLabel();
String p2Str = p2.getLabel() == null ? p2.getURI() : p2.getLabel();
return p1Str.compareTo(p2Str);
}
return diff;

View file

@ -110,7 +110,7 @@ public class EntityController extends VitroHttpServlet {
return;
} catch (Throwable e) {
log.error(e);
log.error(e, e);
req.setAttribute("javax.servlet.jsp.jspException",e);
RequestDispatcher rd = req.getRequestDispatcher("/error.jsp");
rd.forward(req, res);
@ -505,7 +505,14 @@ public class EntityController extends VitroHttpServlet {
String url = fileInfo.getBytestreamAliasUrl();
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 ) {

View file

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

View file

@ -19,6 +19,15 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
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.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.OntologyDao;
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;
public class EntityURLController extends VitroHttpServlet {
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{
@ -84,21 +96,45 @@ public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOExc
return;
}
List<Individual> inds = (List<Individual>)getServletContext().getAttribute("inds");
Model model = ModelFactory.createDefaultModel();
if(inds != null){
System.out.println("Into the loop");
Iterator<Individual> itr = (Iterator<Individual>)inds.iterator();
Individual ind = null;
Resource resource = null;
while(itr.hasNext()){
ind = itr.next();
resource = ResourceFactory.createResource(ind.getURI());
RDFNode node = (RDFNode) ResourceFactory.createResource((String) getServletContext().getAttribute("classuri"));
model.add(resource, RDF.type, node);
}
}
String classUri = (String) getServletContext().getAttribute("classuri");
BooleanQuery query = new BooleanQuery();
query.add(
new TermQuery( new Term(Entity2LuceneDoc.term.RDFTYPE, classUri)),
BooleanClause.Occur.MUST );
IndexSearcher index = LuceneIndexFactory.getIndexSearcher(getServletContext());
TopDocs docs = index.search(query, null,
ENTITY_LIST_CONTROLLER_MAX_RESULTS,
new Sort(Entity2LuceneDoc.term.NAMELOWERCASE));
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 = "";
if(contentType != null){
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.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@ -573,53 +574,52 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
String path = context.getRealPath(FEDORA_PROPERTIES);
try{
InputStream in = new FileInputStream(new File( path ));
if( in == null ){
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;
} else {
props.load( in );
fedoraUrl = props.getProperty("fedoraUrl");
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;
props.load( in );
fedoraUrl = props.getProperty("fedoraUrl");
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;
}
}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){
status.append("<p>Fedora configuration failed.</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.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
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.Individual;
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.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.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.SelectListGenerator;
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;
/**
@ -60,22 +65,64 @@ public class JSONServlet extends VitroHttpServlet {
super.doGet(req, resp);
VitroRequest vreq = new VitroRequest(req);
if(vreq.getParameter("getEntitiesByVClass") != null ){
if( vreq.getParameter("resultKey") == null) {
getEntitiesByVClass(req, resp);
try{
if(vreq.getParameter("getEntitiesByVClass") != null ){
if( vreq.getParameter("resultKey") == null) {
getEntitiesByVClass(req, resp);
return;
} else {
getEntitiesByVClassContinuation( req, resp);
return;
}
}else if( vreq.getParameter("getN3EditOptionList") != null ){
doN3EditOptionList(req,resp);
return;
} else {
getEntitiesByVClassContinuation( req, resp);
}else if( vreq.getParameter("getLuceneIndividualsByVClass") != null ){
getLuceneIndividualsByVClass(req,resp);
return;
}else if( vreq.getParameter("getVClassesForVClassGroup") != null ){
getVClassesForVClassGroup(req,resp);
return;
}
}else if( vreq.getParameter("getN3EditOptionList") != null ){
doN3EditOptionList(req,resp);
return;
}else if( vreq.getParameter("getLuceneIndividualsByVClass") != null ){
getLuceneIndividualsByVClass(req,resp);
}catch(Exception ex){
log.warn(ex,ex);
}
}
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;
}
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 ){

View file

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

View file

@ -55,13 +55,13 @@ public class TabController extends VitroHttpServlet {
if (leadingTab.getTabId()==portal.getRootTabId()) {
request.setAttribute("homePageRequested", "true");
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");
rd.forward(request, response);
return;
}
else
request.setAttribute("title",leadingTab.getTitle());
else {
request.setAttribute("title",leadingTab.getTitle());
}
String body = leadingTab.getBody();
if( body != null && body.startsWith("JSPBody:") )

View file

@ -247,10 +247,10 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
}else if( sortField.equalsIgnoreCase("sunset") ){
sort = new Sort(Entity2LuceneDoc.term.SUNSET);
}else{
sort = new Sort(Entity2LuceneDoc.term.NAMEUNANALYZED);
sort = new Sort(Entity2LuceneDoc.term.NAMELOWERCASE);
}
} else {
sort = new Sort(Entity2LuceneDoc.term.NAMEUNANALYZED);
sort = new Sort(Entity2LuceneDoc.term.NAMELOWERCASE);
}
if( depth > 1 && "rand()".equalsIgnoreCase(sortField) ){
@ -426,24 +426,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
}
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
@ -482,7 +465,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
Query alphaQuery = null;
if( alpha != null && !"".equals(alpha) && alpha.length() == 1){
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);
}
@ -539,7 +522,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
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="+ 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){
//the selected pages is in the middle of the list of page
int startPage = selectedPage - MAX_PAGES / 2;

View file

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

View file

@ -164,7 +164,7 @@ public class BasicAuthenticator extends Authenticator {
LoginStatusBean lsb = new LoginStatusBean(userUri, username,
securityLevel, authSource);
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.VitroRequest;
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.login.LoginProcessBean;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.Message;
@ -89,6 +90,9 @@ public class Authenticate extends VitroHttpServlet {
VitroRequest vreq = new VitroRequest(request);
try {
if (loginProcessIsRestarting(vreq)) {
LoginProcessBean.removeBean(vreq);
}
if (loginProcessPagesAreEmpty(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.
*/
@ -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) {
return (null != request.getParameter(PARAMETER_RETURN));
}
@ -451,6 +476,8 @@ public class Authenticate extends VitroHttpServlet {
throws IOException {
log.debug("logging in.");
LoginInProcessFlag.set(vreq);
String loginProcessPage = LoginProcessBean.getBean(vreq)
.getLoginPageUrl();
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;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections.map.ListOrderedMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.beans.DynamicField;
import edu.cornell.mannlib.vedit.beans.DynamicFieldRow;
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
import edu.cornell.mannlib.vedit.beans.FormObject;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vedit.beans.Option;
import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vedit.forwarder.PageForwarder;
import edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder;
import edu.cornell.mannlib.vedit.util.FormUtils;
import edu.cornell.mannlib.vedit.validator.impl.RequiredFieldValidator;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
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.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
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.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.listener.impl.IndividualDataPropertyStatementProcessor;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections.map.ListOrderedMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.beans.DynamicField;
import edu.cornell.mannlib.vedit.beans.DynamicFieldRow;
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
import edu.cornell.mannlib.vedit.beans.FormObject;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vedit.beans.Option;
import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vedit.forwarder.PageForwarder;
import edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder;
import edu.cornell.mannlib.vedit.util.FormUtils;
import edu.cornell.mannlib.vedit.validator.impl.RequiredFieldValidator;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
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.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
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.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.listener.impl.IndividualDataPropertyStatementProcessor;
public class EntityRetryController extends BaseEditController {
@ -86,7 +86,7 @@ public class EntityRetryController extends BaseEditController {
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());
IndividualDao ewDao = myWebappDaoFactory.getIndividualDao();
@ -326,7 +326,8 @@ public class EntityRetryController extends BaseEditController {
request.setAttribute("title","Individual Editing Form");
request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+portal.getThemeDir()+"css/edit.css\"/>");
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("unqualifiedClassName","Individual");
setRequestAttributes(request,epo);
@ -339,24 +340,24 @@ public class EntityRetryController extends BaseEditController {
log.error(e.getStackTrace());
}
}
private List<Option> getMonikerOptionsList(Individual entity,
IndividualDao indDao) {
ArrayList<Option> monikerOpts = new ArrayList<Option>();
monikerOpts.add(new Option("", "none", (entity.getMoniker() == null)));
if (entity.getVClassURI() != null) {
List<String> monikers = indDao.monikers(entity.getVClassURI());
if (monikers != null) {
for (String moniker : monikers) {
monikerOpts.add(new Option(
moniker, moniker,
moniker.equals(entity.getMoniker())));
}
}
}
monikerOpts.add(new Option("", "[new moniker]"));
return monikerOpts;
}
private List<Option> getMonikerOptionsList(Individual entity,
IndividualDao indDao) {
ArrayList<Option> monikerOpts = new ArrayList<Option>();
monikerOpts.add(new Option("", "none", (entity.getMoniker() == null)));
if (entity.getVClassURI() != null) {
List<String> monikers = indDao.monikers(entity.getVClassURI());
if (monikers != null) {
for (String moniker : monikers) {
monikerOpts.add(new Option(
moniker, moniker,
moniker.equals(entity.getMoniker())));
}
}
}
monikerOpts.add(new Option("", "[new moniker]"));
return monikerOpts;
}
public void doGet (HttpServletRequest request, HttpServletResponse response) {

View file

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

View file

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

View file

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

View file

@ -249,6 +249,9 @@ public class RefactorOperationController extends BaseEditController {
ontModel.leaveCriticalSection();
}
// there are no statements to delete, but we want indexes updated appropriately
request.getFullWebappDaoFactory().getIndividualDao().deleteIndividual(oldURIStr);
String redirectStr = null;
/* 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("formOnCancel", "forceCancel(this.form);");
}
else {
else {
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("scripts","/templates/edit/specific/user_retry_head.jsp");
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 {
static final long serialVersionUID=2006030721126L;
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
protected String getTitle(String siteName, VitroRequest vreq) {
return "Index to " + siteName + " Contents";
return "Index of Contents";
}
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
Map<String, Object> body = new HashMap<String, Object>();
String message = null;
String templateName = TEMPLATE_DEFAULT;
if( vreq.getParameter("clearcache") != null ) //mainly for debugging
clearGroupCache();
int portalId = vreq.getPortalId();
List<VClassGroup> groups = null;
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(getServletContext());
if( vcgc == null ){
log.error("Could not get VClassGroupCache");
message = "The system is not configured correctly. Please check your logs for error messages.";
}else{
groups =vcgc.getGroups( vreq.getPortalId());
if (groups == null || groups.isEmpty()) {
message = "There are not yet any items in the system.";
if ( vreq.getParameter("clearcache") != null ) //mainly for debugging
clearGroupCache();
int portalId = vreq.getPortalId();
List<VClassGroup> groups = null;
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(getServletContext());
if ( vcgc == null ) {
log.error("Could not get VClassGroupCache");
message = "The system is not configured correctly. Please check your logs for error messages.";
} else {
groups =vcgc.getGroups( vreq.getPortalId());
List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size());
for (VClassGroup group : groups) {
vcgroups.add(new VClassGroupTemplateModel(group));
}
else {
List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size());
for (VClassGroup group : groups) {
vcgroups.add(new VClassGroupTemplateModel(group));
}
body.put("classGroups", vcgroups);
}
}
if (message != null) {
body.put("message", message);
templateName = Template.TITLED_MESSAGE.toString();
}
body.put("classGroups", vcgroups);
}
if (message != null) {
body.put("message", message);
templateName = Template.TITLED_MESSAGE.toString();
}
return new TemplateResponseValues(templateName, body);
}
protected void 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.web.BreadCrumbsUtil;
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.files.Scripts;
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 Log log = LogFactory.getLog(FreemarkerHttpServlet.class);
public static final String PAGE_TEMPLATE_TYPE = "page";
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,
// 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) {
// 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.
private final Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder, VitroRequest vreq) {
Map<String, String> urls = new HashMap<String, String>();
urls.put("home", urlBuilder.getHomeUrl());
// Templates use this to construct urls.
urls.put("base", urlBuilder.contextPath);
urls.put("base", UrlBuilder.contextPath);
urls.put("about", urlBuilder.getPortalUrl(Route.ABOUT));
if (ContactMailServlet.getSmtpHostFromProperties() != null) {
@ -264,13 +261,24 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN));
urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons")); // deprecated
urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images"));
urls.put("images", urlBuilder.getUrl("/images"));
urls.put("theme", urlBuilder.getUrl(themeDir));
urls.put("index", urlBuilder.getUrl("/browse"));
urls.put("images", UrlBuilder.getUrl("/images"));
urls.put("theme", UrlBuilder.getUrl(themeDir));
urls.put("index", UrlBuilder.getUrl("/browse"));
urls.put("currentPage", getCurrentPageUrl(vreq));
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) {
BeansWrapper wrapper = new DefaultObjectWrapper();
// 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.
* This is public and static so that these may be used by other classes during
* the transition from JSP to Freemarker.
* @return
*/
public static Map<String, Object> getDirectives() {
Map<String, Object> map = new HashMap<String, Object>();
@ -325,9 +332,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
return map;
}
protected Map<String, Object> getMethods() {
public static Map<String, Object> getMethods() {
Map<String, Object> map = new HashMap<String, Object>();
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;
}
@ -353,14 +361,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
String themeDir = getThemeDir(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("currentTheme", themeDir.substring(themeDir.lastIndexOf('/')+1));
map.put("stylesheets", getStylesheetList(themeDir));
map.put("scripts", getScriptList(themeDir));
map.put("headScripts", getScriptList(themeDir));
map.put("currentPage", vreq.getServletPath().replaceFirst("/", ""));
map.putAll(getDirectives());
map.putAll(getMethods());
@ -393,14 +400,21 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
map.put("flash", flashMessage);
}
// Let the page template know which page it's processing.
map.put("currentPage", vreq.getServletPath().replaceFirst("/", ""));
// Let the page template know which page it's processing.
map.put("currentServlet", normalizeServletName(vreq.getServletPath().replaceFirst("/", "")));
// Allow template to send domain name to JavaScript (needed for AJAX calls)
map.put("requestedPage", vreq.getRequestURL().toString());
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) {
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.LogFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
import freemarker.template.Configuration;
@ -20,6 +21,10 @@ public class FreemarkerSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
if (AbortStartup.isStartupAborted(event.getServletContext())) {
return;
}
ServletContext sc = event.getServletContext();
sc.setAttribute("themeToConfigMap", new HashMap<String, Configuration>());
BaseTemplateModel.setServletContext(sc);

View file

@ -9,6 +9,8 @@ import java.util.Map;
import org.apache.commons.logging.Log;
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.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
@ -44,11 +46,20 @@ public class HomePageController extends FreemarkerHttpServlet {
if(pageData != null)
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);
}
// 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
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
.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. */
public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024;
@ -389,7 +390,14 @@ public class ImageUploadController extends FreemarkerHttpServlet {
entity.getURI());
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_CANCEL_URL, cancelUrl);
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.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.DataPropertyStatement;
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.dao.IndividualDao;
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.edit.n3editing.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
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.ListedIndividualTemplateModel;
import freemarker.ext.beans.BeansWrapper;
@ -124,6 +123,7 @@ public class IndividualController extends FreemarkerHttpServlet {
body.put("title", individual.getName());
body.put("relatedSubject", getRelatedSubject(vreq));
body.put("namespaces", namespaces);
body.put("temporalVisualizationEnabled", getTemporalVisualizationFlag());
IndividualTemplateModel itm = getIndividualTemplateModel(vreq, individual);
/* 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.
*/
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(itm));
body.put("headContent", getRdfLinkTag(itm));
body.put("localName", new IndividualLocalNameMethod());
body.put("headContent", getRdfLinkTag(itm));
String template = getIndividualTemplate(individual);
String template = getIndividualTemplate(individual, vreq);
return new TemplateResponseValues(template, body);
} catch (Throwable e) {
log.error(e);
log.error(e, 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.
// If not, return the default individual template.
private String getIndividualTemplate(Individual individual) {
private String getIndividualTemplate(Individual individual, VitroRequest vreq) {
@SuppressWarnings("unused")
String vclassName = "unknown";
String customTemplate = null;
if( individual.getVClass() != null ){
// First check vclass
if( individual.getVClass() != null ){
vclassName = individual.getVClass().getName();
List<VClass> clasList = individual.getVClasses(true);
for (VClass clas : clasList) {
customTemplate = clas.getCustomDisplayView();
List<VClass> directClasses = individual.getVClasses(true);
for (VClass vclass : directClasses) {
customTemplate = vclass.getCustomDisplayView();
if (customTemplate != null) {
if (customTemplate.length()>0) {
vclassName = clas.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");
vclassName = vclass.getName(); // reset entity vclassname to name of class where a custom view; this call has side-effects
log.debug("Found direct class [" + vclass.getName() + "] with custom view " + customTemplate + "; resetting entity vclassName to this class");
break;
} else {
customTemplate = null;
}
}
}
if (customTemplate == null) { //still
clasList = individual.getVClasses(false);
for (VClass clas : clasList) {
customTemplate = clas.getCustomDisplayView();
// If no custom template defined, check other vclasses
if (customTemplate == null) {
List<VClass> inferredClasses = individual.getVClasses(false);
for (VClass vclass : inferredClasses) {
customTemplate = vclass.getCustomDisplayView();
if (customTemplate != null) {
if (customTemplate.length()>0) {
// 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;
} else {
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) {
log.debug("Individual " + individual.getURI() + " with class URI " +
individual.getVClassURI() + ": no class found with that URI");
@ -515,9 +538,21 @@ public class IndividualController extends FreemarkerHttpServlet {
String url = fileInfo.getBytestreamAliasUrl();
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 ) {
Resource subj = newModel.getResource(entity.getURI());

View file

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

View file

@ -35,6 +35,7 @@ public class MenuN3EditController extends FreemarkerHttpServlet {
menuN3 = vreq.getWebappDaoFactory().getDisplayModelDao()
.getDisplayModel(getServletContext());
data.put("menuN3", menuN3);
data.put("cancelUrl", "/siteAdmin");
} catch (Exception e) {
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.freemarker.responsevalues.ResponseValues;
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;
public class NavigationController extends FreemarkerHttpServlet {

View file

@ -70,7 +70,7 @@ public class PageController extends FreemarkerHttpServlet{
ResponseValues rv = new TemplateResponseValues(getTemplate( mapForTemplate ), mapForTemplate);
return rv;
} catch (Throwable e) {
log.error(e);
log.error(e, 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(
SimpleReasonerRecomputeController.class);
private static final String RECOMPUTE_INFERENCES_FTL = "recomputeInferences.ftl";
protected ResponseValues processRequest(VitroRequest vreq) {
// Due to requiresLoginLevel(), we don't get here unless logged in as DBA
if (!LoginStatusBean.getBean(vreq)
@ -40,13 +42,23 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
if (simpleReasoner == null) {
messageStr = "No SimpleReasoner has been set up.";
} else {
String signal = (String) vreq.getParameter("signal");
if (simpleReasoner.isRecomputing()) {
messageStr =
"The SimpleReasoner is currently in the process of " +
"recomputing inferences.";
} else {
new Thread(new Recomputer(simpleReasoner)).start();
messageStr = "Recomputation of inferences started";
} else{
String restart = (String)getServletContext().getAttribute("restart");
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",
"There was an error while recomputing inferences: " +
e.getMessage());
return new ExceptionResponseValues(
Template.ERROR_MESSAGE.toString(), body, e);
return new ExceptionResponseValues(
RECOMPUTE_INFERENCES_FTL, body, e);
}
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 {

View file

@ -92,7 +92,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
// 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
boolean classGroupDisplayAssumptionsMeet = checkClassGroupDisplayAssumptions(classGroups);
//boolean classGroupDisplayAssumptionsMet = checkClassGroupDisplayAssumptions(classGroups);
Set<String> seenGroupNames = new HashSet<String>();
@ -102,10 +102,10 @@ public class SiteAdminController extends FreemarkerHttpServlet {
VClassGroup group = (VClassGroup)classGroupIt.next();
List opts = FormUtils.makeOptionListFromBeans(group.getVitroClassList(),"URI","PickListName",null,null,false);
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);
}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);
}else{
orderedClassGroups.put(group.getPublicName(),opts);
@ -199,11 +199,11 @@ public class SiteAdminController extends FreemarkerHttpServlet {
Map<String, Object> map = new HashMap<String, Object>();
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("rdfExport", urlBuilder.getPortalUrl("/export"));
urls.put("sparqlQuery", urlBuilder.getUrl("/admin/sparqlquery"));
urls.put("sparqlQueryBuilder", urlBuilder.getUrl("/admin/sparqlquerybuilder"));
urls.put("sparqlQuery", UrlBuilder.getUrl("/admin/sparqlquery"));
urls.put("sparqlQueryBuilder", UrlBuilder.getUrl("/admin/sparqlquerybuilder"));
map.put("urls", urls);
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
* meet. see issue NIHVIVO-1635.
*/
private boolean checkClassGroupDisplayAssumptions( List<VClassGroup> groups){
//Assumption A: all of the classgroups have a non-null 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
boolean rvalue = true;
Set<String> seenPublicNames = new HashSet<String>();
for( VClassGroup group :groups ){
//check Assumption A
if( group.getPublicName() == null){
rvalue = false;
break;
}
//check Assumption B
if( seenPublicNames.contains(group.getPublicName()) ){
rvalue = false;
break;
}
seenPublicNames.add(group.getPublicName());
}
if( !rvalue )
log.error("The rdfs:labels on the classgroups in the system do " +
"not meet the display assumptions. Falling back to alternative.");
return rvalue;
}
// private boolean checkClassGroupDisplayAssumptions( List<VClassGroup> groups){
// //Assumption A: all of the classgroups have a non-null 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
// boolean rvalue = true;
// Set<String> seenPublicNames = new HashSet<String>();
//
// for( VClassGroup group :groups ){
// //check Assumption A
// if( group.getPublicName() == null){
// rvalue = false;
// break;
// }
//
// //check Assumption B
// if( seenPublicNames.contains(group.getPublicName()) ){
// rvalue = false;
// break;
// }
// seenPublicNames.add(group.getPublicName());
// }
//
//
// if( !rvalue )
// log.error("The rdfs:labels on the classgroups in the system do " +
// "not meet the display assumptions. Falling back to alternative.");
// return rvalue;
// }
}

View file

@ -26,16 +26,14 @@ public class TemplateProcessingHelper {
private Configuration config = null;
private HttpServletRequest request = 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.request = request;
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);
StringWriter sw = new StringWriter();
processTemplate(template, map, sw);
@ -57,6 +55,13 @@ public class TemplateProcessingHelper {
// can be used in directives.
env.setCustomAttribute("request", request);
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();
} catch (TemplateException 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.
protected String processTemplateToString(String templateName, Map<String, Object> map) {
// For cases where we need a String instead of a StringWriter. StringWriter objects can be put in the template data model,
// 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();
}

View file

@ -2,21 +2,15 @@
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.List;
import java.util.Map;
import org.apache.commons.logging.Log;
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.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import freemarker.template.Configuration;
/**
* Freemarker controller and template sandbox.

View file

@ -15,9 +15,8 @@ import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl;
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.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.filters.PortalPickerFilter;
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) {
putAll(map);
}
@ -239,7 +242,15 @@ public class UrlBuilder {
private static String addParams(String url, ParamMap params, String glue) {
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 = "&";
}
return url;
@ -259,7 +270,7 @@ public class UrlBuilder {
}
public static String getIndividualProfileUrl(String individualUri, WebappDaoFactory wadf) {
Individual individual = wadf.getIndividualDao().getIndividualByURI(individualUri);
Individual individual = new IndividualImpl(individualUri);
return getIndividualProfileUrl(individual, individualUri, wadf);
}
@ -291,24 +302,24 @@ public class UrlBuilder {
return profileUrl;
}
public static String urlEncode(String url) {
public static String urlEncode(String str) {
String encoding = "ISO-8859-1";
String encodedUrl = null;
try {
encodedUrl = URLEncoder.encode(url, encoding);
encodedUrl = URLEncoder.encode(str, encoding);
} 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;
}
public static String urlDecode(String url) {
public static String urlDecode(String str) {
String encoding = "ISO-8859-1";
String decodedUrl = null;
try {
decodedUrl = URLDecoder.decode(url, encoding);
decodedUrl = URLDecoder.decode(str, encoding);
} 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;
}

View file

@ -380,7 +380,7 @@ public class JenaAdminActions extends BaseEditController {
try {
taxonomyModel.write(response.getOutputStream());
} 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.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
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.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.dao.VitroVocabulary;
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 {
@ -91,8 +86,6 @@ public class JenaExportController extends BaseEditController {
Model model = null;
OntModel ontModel = ModelFactory.createOntologyModel();
boolean limitToInferred = false;
Model inferenceModel = null;
if(!subgraphParam.equalsIgnoreCase("tbox") && !subgraphParam.equalsIgnoreCase("abox") && !subgraphParam.equalsIgnoreCase("full")){
ontologyURI = subgraphParam;
@ -104,43 +97,110 @@ public class JenaExportController extends BaseEditController {
}
String mode = (JenaDataSourceSetupBase.isSDBActive()) ? "SDB" : "RDB";
if( "abox".equals(subgraphParam)){
model = ModelFactory.createDefaultModel();
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)){
model = xutil.extractABox(dataset, FULL_GRAPH);
if(mode.equals("RDB")){
model = xutil.extractABox((OntModel)getServletContext().getAttribute("jenaOntModel"));
}
else{
model = ModelContext.getUnionOntModelSelector(getServletContext()).getABoxModel();
}
}
else{
model = xutil.extractABox(dataset, ASSERTIONS_GRAPH);
else if("asserted".equals(assertedOrInferredParam)){
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)){
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);
}
if ("inferred".equals(assertedOrInferredParam)) {
// the extraction won't work on just the inferred graph,
// so we'll extract the whole ontology and then include
// only those statements that are in the inferred graph
Model tempModel = xutil.extractTBox(
ModelContext.getUnionOntModelSelector(
getServletContext()).getTBoxModel(), ontologyURI);
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)){
if("inferred".equals(assertedOrInferredParam)){
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)){
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{
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.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
@ -27,6 +28,7 @@ import javax.servlet.ServletContextEvent;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
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.event.EditEvent;
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.utils.jena.JenaIngestUtils;
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
@ -130,7 +133,18 @@ public class JenaIngestController extends BaseEditController {
if ("listModels".equals(actionStr)) {
String modelT = (String)getServletContext().getAttribute("modelT");
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("infoLine", "RDB models");
}
@ -340,7 +354,11 @@ public class JenaIngestController extends BaseEditController {
String jdbcUrl = vreq.getParameter("jdbcUrl");
String tripleStore = vreq.getParameter("tripleStore");
if (jdbcUrl != null) {
doConnectDB(vreq);
try {
doConnectDB(vreq);
} catch (SQLException sqle) {
throw new RuntimeException("Unable to connect to DB", sqle);
}
if ("SDB".equals(tripleStore)) {
getServletContext().setAttribute("modelT", "sdb");
getServletContext().setAttribute("info", "SDB models");
@ -744,14 +762,13 @@ public class JenaIngestController extends BaseEditController {
else{
destination.add(utils.renameBNodesByPattern(source, namespaceEtc, vreq.getJenaOntModel(), pattern, property));
}
if(csv2rdf){
if(csv2rdf && property!=null){
ClosableIterator closeIt = destination.listSubjects();
Property prop = ResourceFactory.createProperty(property);
try {
for (Iterator it = closeIt; it.hasNext();) {
Resource res = (Resource) it.next();
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);
Statement stmt = null;
try {
@ -773,6 +790,21 @@ public class JenaIngestController extends BaseEditController {
csv2rdf = false;
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 {
destination.leaveCriticalSection();
@ -858,7 +890,7 @@ public class JenaIngestController extends BaseEditController {
return tempModel.size();
}
public void doConnectDB(VitroRequest vreq) {
public void doConnectDB(VitroRequest vreq) throws SQLException {
String jdbcUrl = vreq.getParameter("jdbcUrl");
String username = vreq.getParameter("username");
String password = vreq.getParameter("password");
@ -870,40 +902,48 @@ public class JenaIngestController extends BaseEditController {
jdbcUrl += "useUnicode=yes&characterEncoding=utf8";
}
dbTypeObj = DatabaseType.fetch(dbType);
loadDriver(dbTypeObj);
String driver = loadDriver(dbTypeObj);
System.out.println("Connecting to DB at "+jdbcUrl);
StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ;
SDBConnection conn = new SDBConnection(jdbcUrl, username, password) ;
Store store = SDBFactory.connectStore(conn, storeDesc);
VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(store);
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, dbType);
getServletContext().setAttribute("vitroJenaSDBModelMaker", vsmm);
getServletContext().setAttribute("vitroJenaModelMaker", vjmm);
if("SDB".equals(tripleStore))
vreq.getSession().setAttribute("vitroJenaModelMaker",vsmm);
else
vreq.getSession().setAttribute("vitroJenaModelMaker",vjmm);
StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ;
BasicDataSource bds = JenaDataSourceSetup.makeBasicDataSource(
driver, jdbcUrl, username, password);
try {
VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(storeDesc, bds);
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, dbType);
getServletContext().setAttribute("vitroJenaSDBModelMaker", vsmm);
getServletContext().setAttribute("vitroJenaModelMaker", vjmm);
if("SDB".equals(tripleStore))
vreq.getSession().setAttribute("vitroJenaModelMaker",vsmm);
else
vreq.getSession().setAttribute("vitroJenaModelMaker",vjmm);
} catch (SQLException sqle) {
throw new RuntimeException("Unable to create SDB ModelMaker", sqle);
}
}
private void loadDriver(DatabaseType dbType) {
if (DatabaseType.MySQL.equals(dbType)) {
JDBC.loadDriverMySQL();
} else if (DatabaseType.DB2.equals(dbType)) {
JDBC.loadDriverDB2();
} else if (DatabaseType.Derby.equals(dbType)) {
JDBC.loadDriverDerby();
} else if (DatabaseType.H2.equals(dbType)) {
JDBC.loadDriverH2();
} else if (DatabaseType.HSQLDB.equals(dbType)) {
JDBC.loadDriverHSQL();
} else if (DatabaseType.Oracle.equals(dbType)) {
JDBC.loadDriverOracle();
} else if (DatabaseType.PostgreSQL.equals(dbType)) {
JDBC.loadDriverPGSQL();
} else if (DatabaseType.SQLServer.equals(dbType)) {
JDBC.loadDriverSQLServer();
}
private String loadDriver(DatabaseType dbType) {
String driverName = JDBC.getDriver(dbType);
JDBC.loadDriver(driverName);
return driverName;
// if (DatabaseType.MySQL.equals(dbType)) {
// JDBC.loadDriverMySQL();
// } else if (DatabaseType.DB2.equals(dbType)) {
// JDBC.loadDriverDB2();
// } else if (DatabaseType.Derby.equals(dbType)) {
// JDBC.loadDriverDerby();
// } else if (DatabaseType.H2.equals(dbType)) {
// JDBC.loadDriverH2();
// } else if (DatabaseType.HSQLDB.equals(dbType)) {
// JDBC.loadDriverHSQL();
// } else if (DatabaseType.Oracle.equals(dbType)) {
// JDBC.loadDriverOracle();
// } else if (DatabaseType.PostgreSQL.equals(dbType)) {
// JDBC.loadDriverPGSQL();
// } else if (DatabaseType.SQLServer.equals(dbType)) {
// JDBC.loadDriverSQLServer();
// }
}
/*public void doExecuteCsv2Rdf(VitroRequest vreq) {

View file

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

View file

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

View file

@ -2,17 +2,28 @@
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.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
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 */
public static final String DISPLAY_NS = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#";
private static final String NS = DISPLAY_NS;
/* Individuals */
public static final String PRIMARY_LUCENE_INDEX_URI = NS + "PrimaryLuceneIndex";
/* Page types */
public static final String PAGE_TYPE = NS + "Page";
public static final String HOME_PAGE_TYPE = NS + "HomePage";
@ -22,11 +33,73 @@ public class DisplayVocabulary {
public static final String FOR_CLASSGROUP = NS + "forClassGroup";
/* 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 REQUIRES_BODY_TEMPLATE = NS + "requiresBodyTemplate";
public static final DatatypeProperty REQUIRES_BODY_TEMPLATE = m_model.createDatatypeProperty(NS + "requiresBodyTemplate");
/* URIs for storing menu.n3 */
public static final String MENU_TEXT_RES = NS + "MenuText";
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.Map;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
@ -31,4 +32,6 @@ public interface ObjectPropertyStatementDao {
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, 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_ONTOLOGY = OWL+"Ontology";
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";

View file

@ -138,4 +138,6 @@ public interface WebappDaoFactory {
public PageDao getPageDao();
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.
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.List;
import java.util.Map;
import java.util.Set;
import net.sf.jga.algorithms.Filter;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
@ -88,6 +89,14 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
String subjectUri, String propertyUri, String 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

View file

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

View file

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

View file

@ -163,13 +163,18 @@ public class ProhibitedFromUpdateBelowRoleLevelFilter extends VitroFiltersImpl {
try {
ObjectProperty prop = stmt.getProperty();
if( prop == null )
prop = wdf.getObjectPropertyDao().getObjectPropertyByURI( stmt.getPropertyURI() );
if( prop == null )
if( ! canViewOddItems() ){ return false; }
else
if( sameLevelOrHigher( prop.getProhibitedFromUpdateBelowRoleLevel()) == false)
return false;
if (prop == null) {
prop = wdf.getObjectPropertyDao().getObjectPropertyByURI(stmt.getPropertyURI());
}
if (prop == null) {
if (!canViewOddItems()) {
return false;
}
} else {
if (sameLevelOrHigher(prop.getProhibitedFromUpdateBelowRoleLevel()) == false) {
return false;
}
}
Individual subject =
(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
* that has a annotation of hiddenFromDisplayBelowRoleLevel higher than current user's role level
*/
public static VitroFilters getDisplayFilterByRoleLevel(RoleLevel role, WebappDaoFactory wdf){
log.info("initializing HiddenFromDisplayBelowRoleLevelFilter");
public static VitroFilters getDisplayFilterByRoleLevel(RoleLevel role, WebappDaoFactory wdf){
return new HiddenFromDisplayBelowRoleLevelFilter(role, wdf);
}
/* bdc34: Currently, this is not called from anywhere in the code. */
public static VitroFilters getUpdateFilterByRoleLevel(RoleLevel role, WebappDaoFactory wdf){
log.info("initializing ProhibitedFromUpdateBelowRoleLevelFilter");
public static VitroFilters getUpdateFilterByRoleLevel(RoleLevel role, WebappDaoFactory 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.rdf.listeners.StatementListener;
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.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
@ -26,14 +27,20 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
Integer portalCount = null;
List<String> externallyLinkedNamespaces = null;
ModelChangedListener modelChangedListener = null;
public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
super(wadf);
getOntModelSelector().getDisplayModel().register(
new ExternalNamespacesChangeListener());
modelChangedListener = new ExternalNamespacesChangeListener();
getOntModelSelector().getDisplayModel().register(modelChangedListener);
}
public void close() {
if (modelChangedListener != null) {
getOntModelSelector().getDisplayModel().unregister(modelChangedListener);
}
}
public boolean isFlag1Active() {
boolean somePortalIsFiltering=false;
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.SomeValuesFromRestriction;
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.QuerySolution;
import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Property;
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.DataPropertyStatement;
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.VClass;
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.
*/
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/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#"
"http://vitro.mannlib.cornell.edu/ns/vitro/public#"
);
/*
@ -86,21 +83,21 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
}
propertyFilters = "FILTER (" + StringUtils.join(namespaceFilters, " && ") + ")\n";
}
protected static final String dataPropertyQueryString =
PREFIXES + "\n" +
protected static final String DATA_PROPERTY_QUERY_STRING =
prefixes + "\n" +
"SELECT DISTINCT ?property WHERE { \n" +
" GRAPH ?g1 { ?subject ?property ?object } \n" +
" GRAPH ?g2 { ?property rdf:type owl:DatatypeProperty } \n" +
propertyFilters +
"}";
static protected Query dataPropertyQuery;
protected static Query dataPropertyQuery;
static {
try {
dataPropertyQuery = QueryFactory.create(dataPropertyQueryString);
dataPropertyQuery = QueryFactory.create(DATA_PROPERTY_QUERY_STRING);
} catch(Throwable th){
log.error("could not create SPARQL query for dataPropertyQueryString " + th.getMessage());
log.error(dataPropertyQueryString);
log.error("could not create SPARQL query for DATA_PROPERTY_QUERY_STRING " + th.getMessage());
log.error(DATA_PROPERTY_QUERY_STRING);
}
}
@ -421,9 +418,10 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
public Collection<DataProperty> getAllPossibleDatapropsForIndividual(String individualURI) {
Individual ind = getWebappDaoFactory().getIndividualDao().getIndividualByURI(individualURI);
Collection<DataProperty> dpColl = new ArrayList<DataProperty>();
List<String> vclassURIs = getVClassURIs(ind);
try {
for (VClass currClass : ind.getVClasses(true)) {
for (VClass currClass : ind.getVClasses( DIRECT )) {
List<DataProperty> currList = getDatapropsForClass(currClass.getURI());
for (Iterator<DataProperty> dpIter = currList.iterator(); dpIter.hasNext();) {
DataProperty dp = (DataProperty) dpIter.next();
@ -447,7 +445,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
// now change range datatype based on individual
// TODO: rethink all these methods to reduce inefficiency
for (DataProperty dp : dpColl) {
dp.setRangeDatatypeURI(getRequiredDatatypeURI(ind, dp));
dp.setRangeDatatypeURI(getRequiredDatatypeURI(ind, dp, vclassURIs));
}
}
} catch (ProfileException pe) {
@ -469,59 +467,68 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
);
}
public String getRequiredDatatypeURI(Individual individual, DataProperty dataprop) {
OntModel ontModel = getOntModelSelector().getFullModel();
String datatypeURI = dataprop.getRangeDatatypeURI();
List<String> vclassURIs = null;
if (reasoningAvailable()) {
vclassURIs = new ArrayList<String>();
for (VClass vc : individual.getVClasses(INDIRECT)) {
if (vc.getURI() != null) {
vclassURIs.add(vc.getURI());
}
}
} else {
vclassURIs = getSupertypeURIs(individual);
}
ontModel.enterCriticalSection(Lock.READ);
try {
// get universal restrictions applicable to data property
Iterator<Resource> restIt = ontModel.listSubjectsWithProperty(OWL.onProperty, ontModel.getResource(dataprop.getURI()));
while (restIt.hasNext()) {
Resource restRes = restIt.next();
if (restRes.canAs(Restriction.class)) {
Restriction rest = (Restriction) restRes.as(Restriction.class);
if (rest.isAllValuesFromRestriction()) {
AllValuesFromRestriction avfrest = rest.asAllValuesFromRestriction();
if (avfrest.getAllValuesFrom() != null) {
// check if the individual has the restriction as one of its types
if (!individual.isAnonymous() &&
ontModel.contains(ontModel.getResource(individual.getURI()),
RDF.type,
rest)
) {
datatypeURI = avfrest.getAllValuesFrom().getURI();
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())) {
datatypeURI = avfrest.getAllValuesFrom().getURI();
break;
}
}
}
}
}
}
}
} finally {
ontModel.leaveCriticalSection();
}
return datatypeURI;
private String getRequiredDatatypeURI(Individual individual, DataProperty dataprop, List<String> vclassURIs) {
OntModel ontModel = getOntModelSelector().getTBoxModel();
String datatypeURI = dataprop.getRangeDatatypeURI();
ontModel.enterCriticalSection(Lock.READ);
try {
// get universal restrictions applicable to data property
Iterator<Resource> restIt = ontModel.listSubjectsWithProperty(OWL.onProperty, ontModel.getResource(dataprop.getURI()));
while (restIt.hasNext()) {
Resource restRes = restIt.next();
if (restRes.canAs(Restriction.class)) {
Restriction rest = (Restriction) restRes.as(Restriction.class);
if (rest.isAllValuesFromRestriction()) {
AllValuesFromRestriction avfrest = rest.asAllValuesFromRestriction();
if (avfrest.getAllValuesFrom() != null) {
// check if the individual has the restriction as one of its types
if (!individual.isAnonymous() &&
ontModel.contains(ontModel.getResource(individual.getURI()),
RDF.type,
rest)
) {
datatypeURI = avfrest.getAllValuesFrom().getURI();
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())) {
datatypeURI = avfrest.getAllValuesFrom().getURI();
break;
}
}
}
}
}
}
}
} finally {
ontModel.leaveCriticalSection();
}
return datatypeURI;
}
public String getRequiredDatatypeURI(Individual individual, DataProperty dataprop) {
return getRequiredDatatypeURI(individual,dataprop,getVClassURIs(individual));
}
private List<String> getVClassURIs(Individual individual){
List<String> vclassURIs = null;
if (reasoningAvailable()) {
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;
@ -746,9 +753,9 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
* into the new one in a future release.
*/
public List<DataProperty> getDataPropertyList(String subjectUri) {
log.debug("dataPropertyQueryString:\n" + dataPropertyQueryString);
log.debug("dataPropertyQuery:\n" + dataPropertyQuery);
ResultSet results = getPropertyQueryResults(subjectUri, dataPropertyQuery);
log.debug("Data property query string:\n" + DATA_PROPERTY_QUERY_STRING);
log.debug("Data property query:\n" + dataPropertyQuery);
Iterator<QuerySolution> results = getPropertyQueryResults(subjectUri, dataPropertyQuery);
List<DataProperty> properties = new ArrayList<DataProperty>();
while (results.hasNext()) {
QuerySolution sol = results.next();

View file

@ -42,7 +42,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
private DatasetWrapperFactory dwf;
protected static final String dataPropertyValueQueryString =
protected static final String DATA_PROPERTY_VALUE_QUERY_STRING =
"SELECT ?value WHERE { \n" +
" GRAPH ?g {\n" +
" ?subject ?property ?value . \n" +
@ -52,10 +52,10 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
static protected Query dataPropertyValueQuery;
static {
try {
dataPropertyValueQuery = QueryFactory.create(dataPropertyValueQueryString);
dataPropertyValueQuery = QueryFactory.create(DATA_PROPERTY_VALUE_QUERY_STRING);
} catch(Throwable th){
log.error("could not create SPARQL query for dataPropertyQueryString " + th.getMessage());
log.error(dataPropertyValueQueryString);
log.error("could not create SPARQL query for DATA_PROPERTY_VALUE_QUERY_STRING " + th.getMessage());
log.error(DATA_PROPERTY_VALUE_QUERY_STRING);
}
}
@ -65,26 +65,40 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
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.enterCriticalSection(Lock.WRITE);
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,dataPropertyStatement.getIndividualURI()));
com.hp.hpl.jena.ontology.Individual ind = ontModel.getIndividual(dataPropertyStatement.getIndividualURI());
Property prop = ontModel.getProperty(dataPropertyStatement.getDatapropURI());
Literal l = jenaLiteralFromDataPropertyStatement(dataPropertyStatement, ontModel);
if (ind != null && prop != null && l != null) {
ontModel.getBaseModel().remove(ind, prop, l);
}
} finally {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),false,dataPropertyStatement.getIndividualURI()));
ontModel.leaveCriticalSection();
}
OntModel ontModel = getOntModelSelector().getABoxModel();
try {
ontModel.enterCriticalSection(Lock.WRITE);
getOntModel().getBaseModel().notifyEvent(
new IndividualUpdateEvent(
getWebappDaoFactory().getUserURI(),
true,
dataPropertyStatement.getIndividualURI()));
com.hp.hpl.jena.ontology.Individual ind = ontModel.getIndividual(
dataPropertyStatement.getIndividualURI());
OntModel tboxModel = getOntModelSelector().getTBoxModel();
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*/)
@ -143,19 +157,29 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
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);
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,individualURI));
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(
getWebappDaoFactory().getUserURI(),
true,
individualURI));
try {
Resource indRes = ontModel.getResource(individualURI);
DatatypeProperty datatypeProperty = ontModel.getDatatypeProperty(dataPropertyURI);
if (indRes != null && datatypeProperty != null) {
ontModel.removeAll(indRes, datatypeProperty, (Literal)null);
}
Resource indRes = ResourceFactory.createResource(individualURI);
Property datatypeProperty = ResourceFactory.createProperty(
dataPropertyURI);
ontModel.removeAll(indRes, datatypeProperty, (Literal)null);
} finally {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),false,individualURI));
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(
getWebappDaoFactory().getUserURI(),
false,
individualURI));
ontModel.leaveCriticalSection();
}
}
public void deleteDataPropertyStatementsForIndividualByDataProperty(Individual individual, DataProperty dataProperty) {
@ -296,12 +320,12 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
@Override
public List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri) {
log.debug("dataPropertyValueQueryString:\n" + dataPropertyValueQueryString);
log.debug("dataPropertyValueQuery:\n" + dataPropertyValueQuery);
log.debug("Data property value query string:\n" + DATA_PROPERTY_VALUE_QUERY_STRING);
log.debug("Data property value:\n" + dataPropertyValueQuery);
QuerySolutionMap bindings = new QuerySolutionMap();
bindings.add("subject", ResourceFactory.createResource(subjectUri));
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
List<Literal> values = new ArrayList<Literal>();
@ -310,7 +334,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
dataset.getLock().enterCriticalSection(Lock.READ);
try {
QueryExecution qexec = QueryExecutionFactory.create(
dataPropertyValueQuery, dataset, bindings);
dataPropertyValueQuery, dataset, initialBindings);
ResultSet results = qexec.execSelect();
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.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
implements DataPropertyStatementDao {
private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public DataPropertyStatementDaoSDB(DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf) {
public DataPropertyStatementDaoSDB(
DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super (datasetWrapperFactory, wadf);
this.dwf = datasetWrapperFactory;
this.datasetMode = datasetMode;
}
@Override
@ -51,12 +57,14 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
}
else
{
String[] graphVars = { "?g" };
String query =
"CONSTRUCT { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" +
"} WHERE { GRAPH ?g { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" +
" FILTER(isLiteral(?o)) \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"} }" ;
Model results = null;
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.VClass;
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 {
private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
private WebappDaoFactoryJena wadf;
public IndividualDaoSDB(DatasetWrapperFactory dwf, WebappDaoFactoryJena wadf) {
public IndividualDaoSDB(DatasetWrapperFactory dwf,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super(wadf);
this.dwf = dwf;
this.datasetMode = datasetMode;
}
protected DatasetWrapper getDatasetWrapper() {
@ -61,7 +68,12 @@ public class IndividualDaoSDB extends IndividualDaoJena {
}
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());
@ -97,38 +109,57 @@ public class IndividualDaoSDB extends IndividualDaoJena {
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
String[] graphVars = {"?g", "?h", "?i"};
String query =
"SELECT DISTINCT ?ind ?label ?moniker " +
"WHERE " +
"{ GRAPH ?g { \n" +
" ?ind a <" + theClass.getURI() + "> \n" +
"} \n" +
"OPTIONAL { GRAPH ?h { ?ind <" + RDFS.label.getURI() + "> ?label } }\n" +
"OPTIONAL { GRAPH ?i { ?ind <" + VitroVocabulary.MONIKER + "> ?moniker } } \n" +
"} ORDER BY ?label";
"{ \n" +
"{ \n" +
" ?ind a <" + theClass.getURI() + "> . \n" +
" ?ind <" + RDFS.label.getURI() + "> ?label \n" +
"} \n" +
"UNION { \n" +
" ?ind a <" + theClass.getURI() + "> . \n" +
" ?ind <" + VitroVocabulary.MONIKER + "> ?moniker \n" +
"} \n" +
"} ORDER BY ?ind ?label";
ResultSet rs =QueryExecutionFactory.create(
QueryFactory.create(query), dataset)
.execSelect();
Resource res = null;
String uri = null;
String label = null;
String moniker = null;
while (rs.hasNext()) {
QuerySolution sol = rs.nextSolution();
Resource currRes = sol.getResource("ind");
if ((res == null || !res.equals(currRes))
&& !currRes.isAnon()) {
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 (currRes.isAnon()) {
continue;
}
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 {
dataset.getLock().leaveCriticalSection();
@ -149,13 +180,22 @@ public class IndividualDaoSDB extends IndividualDaoJena {
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
public Individual getIndividualByURI(String entityURI) {
if( entityURI == null || entityURI.length() == 0 ) {
return null;
} else {
return makeIndividual(entityURI);
return makeIndividual(entityURI);
}
}
@ -300,11 +340,13 @@ public class IndividualDaoSDB extends IndividualDaoJena {
final List<String> list =
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" +
" FILTER (?g != <" + JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL + "> " +
" && !regex(str(?g),\"tbox\")) \n " +
"}";
Query q = QueryFactory.create(query);
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
@ -324,70 +366,21 @@ public class IndividualDaoSDB extends IndividualDaoJena {
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){
log.info("Number of individuals from source: " + list.size());
return new Iterator(){
Iterator<String> innerIt = list.iterator();
public boolean hasNext() {
return innerIt.hasNext();
}
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() {
//not used
@ -407,7 +400,10 @@ public class IndividualDaoSDB extends IndividualDaoJena {
Iterator indIt = cls.listInstances();
while (indIt.hasNext()) {
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();
} finally {
@ -456,7 +452,10 @@ public class IndividualDaoSDB extends IndividualDaoJena {
typeIt.close();
}
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 {
moniker = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().MONIKER);
if (moniker == null) {
try {
// trying to deal with the fact that an entity may have more than 1 VClass
List<VClass> clasList = this.getVClasses(true);
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 {
moniker = preferredClass.getName();
}
}
} catch (Exception e) {}
//Changing behavior to moniker because it is taking extra time to get the vclass
//alternative if the moniker isn't filled out. That time is wasted if the vclass alternative isn't desired.
//see NIHVIVO-2001
moniker = "";
}
return moniker;
} finally {
@ -1043,7 +1025,7 @@ public class IndividualJena extends IndividualImpl implements Individual {
} catch (Exception e) {
log.error(e);
log.error(e, e);
}
}

View file

@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.text.Collator;
import java.util.ArrayList;
@ -20,30 +18,29 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource;
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.query.QuerySolution;
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.Model;
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.ResIterator;
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.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
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.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.dao.VClassDao;
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.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
@ -72,12 +70,17 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private Float _searchBoostJena = null;
private boolean retreivedNullRdfsLabel = false;
private DatasetWrapperFactory dwf = null;
private SDBDatasetMode datasetMode =
SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
private String individualURI = null;
private Model model = null;
private Boolean _hasThumb = null;
public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory,
WebappDaoFactoryJena wadf, Model initModel) {
DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf,
Model initModel) {
this.individualURI = individualURI;
this.dwf = datasetWrapperFactory;
@ -114,9 +117,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf,
boolean skipInitialization) {
this.individualURI = individualURI;
this.datasetMode = datasetMode;
this.dwf = datasetWrapperFactory;
if (skipInitialization) {
@ -132,19 +137,18 @@ public class IndividualSDB extends IndividualImpl implements Individual {
"CONSTRUCT " +
"{ <"+individualURI+"> <" + RDFS.label.getURI() +
"> ?ooo. \n" +
"<"+individualURI+"> a ?type . \n" +
// "<"+individualURI+"> a ?type . \n" +
"<"+individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker \n" +
"} WHERE {" +
"{ GRAPH ?g { \n" +
"{ <"+individualURI+"> <" + RDFS.label.getURI() +
"> ?ooo } \n" +
"UNION { GRAPH ?h { <" +
"UNION { <" +
individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker } } \n" +
"} } \n" +
"UNION { GRAPH ?i { <"
+ individualURI + "> a ?type } } \n" +
"> ?moniker \n" +
"} \n" +
// "UNION { <"
// + individualURI + "> a ?type } \n" +
"}";
model = QueryExecutionFactory.create(
QueryFactory.create(getStatements), dataset)
@ -157,20 +161,50 @@ public class IndividualSDB extends IndividualImpl implements Individual {
OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM, model);
if (model.isEmpty() && noTriplesFor(individualURI)) {
throw new IndividualNotFoundException();
}
this.ind = ontModel.createOntResource(individualURI);
}
setUpURIParts(ind);
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,
DatasetWrapperFactory datasetWrapperFactory,
DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
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) {
if (ind != null) {
if (ind.isAnon()) {
@ -293,8 +327,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
int portalid = FlagMathUtils.numeric2Portalid(numericPortal);
String portalTypeUri = VitroVocabulary.vitroURI +
"Flag1Value" + portalid + "Thing";
String Ask = "ASK { GRAPH ?g { <" + this.individualURI +
"> <" +RDF.type+ "> <" + portalTypeUri +">} }";
String Ask = "ASK { <" + this.individualURI +
"> <" +RDF.type+ "> <" + portalTypeUri +">} ";
if(!QueryExecutionFactory.create(
QueryFactory.create(Ask), dataset).execAsk()) {
return false;
@ -308,162 +342,208 @@ public class IndividualSDB extends IndividualImpl implements Individual {
}
private void doFlag1() {
String getObjects = null;
Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
ClosableIterator typeIt = null;
int portalNumeric = 0;
String portalSet = "";
try{
getObjects =
"CONSTRUCT{<" + this.individualURI + "> <" +
RDF.type + "> ?object}" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
RDF.type + "> ?object} }";
tempModel = QueryExecutionFactory.create(
QueryFactory.create(
getObjects), dataset).execConstruct();
ontModel.add(tempModel.listStatements());
OntResource ontRes = ontModel.createOntResource(
this.individualURI);
typeIt = ontRes.getOntModel().listStatements(
ontRes, RDF.type ,(String) null);
while (typeIt.hasNext()) {
Statement stmt = (Statement) typeIt.next();
Resource type = (Resource)stmt.getObject();
String typeName = type.getLocalName();
if(type.getNameSpace() != null
&& type.getNameSpace().equals(
VitroVocabulary.vitroURI)
&& typeName.indexOf("Flag1Value")==0) {
try {
int portalNumber = Integer.decode(
typeName.substring(10,typeName.length()-5));
portalNumeric = portalNumeric | (1 << portalNumber);
if (portalSet.length() > 0) {
portalSet+=",";
if( webappDaoFactory.getPortalDao().isSinglePortal() ){
flag1Set = "0";
flag1Numeric = 1;
}else{
String getObjects = null;
Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
ClosableIterator typeIt = null;
int portalNumeric = 0;
String portalSet = "";
try{
getObjects =
"CONSTRUCT{<" + this.individualURI + "> <" +
RDF.type + "> ?object}" +
"WHERE{ <" + this.individualURI + "> <" +
RDF.type + "> ?object }";
tempModel = QueryExecutionFactory.create(
QueryFactory.create(
getObjects), dataset).execConstruct();
ontModel.add(tempModel.listStatements());
OntResource ontRes = ontModel.createOntResource(
this.individualURI);
typeIt = ontRes.getOntModel().listStatements(
ontRes, RDF.type ,(String) null);
while (typeIt.hasNext()) {
Statement stmt = (Statement) typeIt.next();
Resource type = (Resource)stmt.getObject();
String typeName = type.getLocalName();
if(type.getNameSpace() != null
&& type.getNameSpace().equals(
VitroVocabulary.vitroURI)
&& typeName.indexOf("Flag1Value")==0) {
try {
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{
if( typeIt != null ) typeIt.close() ;
}
flag1Set = portalSet;
flag1Numeric = portalNumeric;
} finally {
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
flag1Set = portalSet;
flag1Numeric = portalNumeric;
} finally {
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
}
}
}
private void doFlag2() {
String getObjects = null;
Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
ClosableIterator typeIt=null;
String flagSet = "";
try{
getObjects =
"CONSTRUCT{<" + this.individualURI + "> <" +
RDF.type + "> ?object}" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
RDF.type + "> ?object} }";
tempModel = QueryExecutionFactory.create(
QueryFactory.create(
getObjects), dataset).execConstruct();
ontModel.add(tempModel.listStatements());
OntResource ontRes = ontModel.createOntResource(
this.individualURI);
typeIt = ontRes.getOntModel().listStatements(
ontRes, RDF.type ,(String) null);
while (typeIt.hasNext()) {
Statement stmt = (Statement) typeIt.next();
Resource type = (Resource)stmt.getObject();
String typeName = type.getLocalName();
if(type.getNameSpace() != null
&& type.getNameSpace().equals(
VitroVocabulary.vitroURI)
&& typeName.indexOf("Flag2Value")==0) {
try {
String flagValue =
((WebappDaoFactoryJena) webappDaoFactory)
.getFlag2ClassLabelMap().get(type);
if (flagSet.length() > 0) {
flagSet+=",";
if( webappDaoFactory.getPortalDao().isSinglePortal() ){
flag2Set = "";
flag2Numeric = 0 ;
}else{
String getObjects = null;
Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
ClosableIterator typeIt=null;
String flagSet = "";
try{
getObjects =
"CONSTRUCT{<" + this.individualURI + "> <" +
RDF.type + "> ?object}" +
"WHERE{ <" + this.individualURI + "> <" +
RDF.type + "> ?object }";
tempModel = QueryExecutionFactory.create(
QueryFactory.create(
getObjects), dataset).execConstruct();
ontModel.add(tempModel.listStatements());
OntResource ontRes = ontModel.createOntResource(
this.individualURI);
typeIt = ontRes.getOntModel().listStatements(
ontRes, RDF.type ,(String) null);
while (typeIt.hasNext()) {
Statement stmt = (Statement) typeIt.next();
Resource type = (Resource)stmt.getObject();
String typeName = type.getLocalName();
if(type.getNameSpace() != null
&& type.getNameSpace().equals(
VitroVocabulary.vitroURI)
&& typeName.indexOf("Flag2Value")==0) {
try {
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{
if( typeIt != null ) typeIt.close() ;
dataset.getLock().leaveCriticalSection();
w.close();
}
flag2Set = flagSet;
} finally {
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();
}
}
}
return sunset;
}
public Date getTimekey() {
if (timekey != null) {
return timekey;
} else {
constructProperty(ind, VitroVocabulary.TIMEKEY);
ind.getOntModel().enterCriticalSection(Lock.READ);
try {
timekey = webappDaoFactory.getJenaBaseDao()
@ -508,41 +588,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
.getPropertyStringValue(
ind,webappDaoFactory.getJenaBaseDao().MONIKER);
if (moniker == null) {
try {
// trying to deal with the fact that an entity
// may have more than 1 VClass
List<VClass> clasList = this.getVClasses(true);
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) {}
}
//Changing behavior to moniker because it is taking extra time to get the vclass
//alternative if the moniker isn't filled out. That time is wasted if the vclass alternative isn't desired.
//see NIHVIVO-2001
moniker = "";
}
return moniker;
} finally {
ind.getOntModel().leaveCriticalSection();
@ -554,7 +604,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (this.blurb != null) {
return blurb;
} else {
constructProperty(ind, VitroVocabulary.BLURB);
ind.getOntModel().enterCriticalSection(Lock.READ);
try {
blurb = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().BLURB);
@ -570,7 +620,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (this.description != null) {
return description;
} else {
constructProperty(ind, VitroVocabulary.DESCRIPTION);
ind.getOntModel().enterCriticalSection(Lock.READ);
try {
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(){
if( this._searchBoostJena != null ){
return this._searchBoostJena;
}else{
String[] graphVars = { "?g" };
String getPropertyValue =
"SELECT ?value" +
"WHERE { GRAPH ?g { <" + individualURI + ">" +
webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT +
"?value} }";
"SELECT ?value \n" +
"WHERE { GRAPH ?g { \n" +
"<" +individualURI+ "> <" +webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT+ "> ?value }\n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + "\n" +
"}";
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try{
try {
searchBoost =
((Literal)QueryExecutionFactory.create(
QueryFactory.create(getPropertyValue), dataset)
.execSelect()).getFloat();
} catch (Exception e) {
searchBoost = null;
}
return searchBoost;
ResultSet rs = QueryExecutionFactory.create(
QueryFactory.create(getPropertyValue),
dataset).execSelect();
if(rs.hasNext()){
QuerySolution qs = rs.nextSolution();
if(qs.get("value") !=null){
Literal value = qs.get("value").asLiteral();
searchBoost = Float.parseFloat(value.getLexicalForm());
return searchBoost;
}
}
else{
return null;
}
} catch (Exception e){
log.error(e,e);
return null;
}finally{
dataset.getLock().leaveCriticalSection();
w.close();
}
}
return null;
}
@Override
@ -660,6 +744,35 @@ public class IndividualSDB extends IndividualImpl implements Individual {
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() {
if (this.anchor != null) {
return anchor;
@ -686,6 +799,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
String graphVars[] = { "?g" };
StringBuffer selectPrimaryLinkQueryBuff = new StringBuffer().append(
"SELECT ?url ?anchor \n" ).append(
"WHERE{ GRAPH ?g { \n " ).append(
@ -696,7 +810,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
).append(
" ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n"
).append(
"} }");
"} \n")
.append(WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode))
.append("}");
QueryExecution qexec = QueryExecutionFactory.create(
QueryFactory.create(selectPrimaryLinkQueryBuff.toString())
, dataset);
@ -809,9 +925,12 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
String[] graphVars = { "?g" };
String valuesOfProperty =
"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();
ontModel.add(tempModel.listStatements());
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)) {
continue;
}
Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), this.dwf, webappDaoFactory);
Individual obj = new IndividualSDB(((OntResource) s.getObject().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, datasetMode, webappDaoFactory);
ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI());
if (subj != null && obj != null && op != null) {
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
@ -855,10 +974,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
String[] graphVars = { "?g" };
String valuesOfProperty =
"SELECT ?object" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
propertyURI + "> ?object} }";
propertyURI + "> ?object} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
ResultSet values = QueryExecutionFactory.create(
QueryFactory.create(valuesOfProperty), dataset)
.execSelect();
@ -871,7 +993,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
new IndividualSDB(
((OntResource) value.as(OntResource.class))
.getURI(),
this.dwf, webappDaoFactory) );
this.dwf,
datasetMode,
webappDaoFactory) );
}
}
} finally {
@ -890,21 +1014,30 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
String[] graphVars = { "?g" };
String valueOfProperty =
"SELECT ?object" +
"SELECT ?object " +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
propertyURI + "> ?object} }";
ResultSet results = QueryExecutionFactory.create(
QueryFactory.create(valueOfProperty), dataset).execSelect();
QuerySolution result = results.next();
RDFNode value = result.get("object");
if (value != null && value.canAs(OntResource.class)) {
return new IndividualSDB(
((OntResource) value.as(OntResource.class)).getURI(),
dwf, webappDaoFactory);
} else {
return null;
}
propertyURI + "> ?object} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
QueryExecution qe = QueryExecutionFactory.create(
QueryFactory.create(valueOfProperty), dataset);
try {
ResultSet results = qe.execSelect();
if (results.hasNext()) {
QuerySolution result = results.next();
RDFNode value = result.get("object");
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 {
dataset.getLock().leaveCriticalSection();
w.close();
@ -1070,8 +1203,14 @@ public class IndividualSDB extends IndividualImpl implements Individual {
((direct)
? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>"
: "?g")
+ " { <" + this.individualURI +"> <" +RDF.type+ "> ?types \n" +
"} } \n";
+ " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n" ;
if (!direct) {
String[] graphVars = { "?g" };
getTypes += WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode);
}
getTypes += "} \n";
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
@ -1306,7 +1445,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} 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) {
if (res != null && dataprop != null && value != null && value.length()>0) {
model.add(res, dataprop, value, XSDDatatype.XSDstring);
System.out.println("JenaBaseDao" + value);
}
}
@ -476,7 +475,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
}
} catch (Exception e) {
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 );
// 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 );
}
} */
} finally {
r.getOntModel().leaveCriticalSection();
}

View file

@ -148,8 +148,12 @@ public class JenaModelUtils {
private final OntModelSpec DEFAULT_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
public OntModel extractTBox( Model inputModel) {
Dataset dataset = DatasetFactory.create(inputModel);
return extractTBox( dataset,null,null );
return extractTBox(inputModel, 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 ) {
@ -242,11 +246,11 @@ private final OntModelSpec DEFAULT_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
public Model extractABox(Model 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();
// 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)inputModel
//: ModelFactory.createOntologyModel( DEFAULT_ONT_MODEL_SPEC, inputModel );
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
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());
OntModel ontModel = extractTBox(unionDataset, null, graphURI);
try {
ontModel.enterCriticalSection(Lock.READ);
Iterator classIt = ontModel.listNamedClasses();
QueryExecution qe = null;
while ( classIt.hasNext() ) {
OntClass ontClass = (OntClass) classIt.next();
if ( !(ontClass.getNameSpace().startsWith(OWL.getURI()) )
&& !(ontClass.getNameSpace().startsWith(VitroVocabulary.vitroURI)) ) {
//if ( !(ontClass.getNameSpace().startsWith(OWL.getURI()) )
// && !(ontClass.getNameSpace().startsWith(VitroVocabulary.vitroURI)) ) {
if(!(ontClass.getNameSpace().startsWith(OWL.getURI()))){
String queryStr = makeDescribeQueryStr( ontClass.getURI(), null, graphURI );
Query aboxSparqlQuery = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(aboxSparqlQuery,dataset);
try {
dataset.getLock().enterCriticalSection(Lock.READ);
qe.execDescribe(aboxModel); // puts the statements about each resource into aboxModel.
} finally {
dataset.getLock().leaveCriticalSection();
if(baseOrInfDataset != null){
qe = QueryExecutionFactory.create(aboxSparqlQuery,baseOrInfDataset);
}
else{
qe = QueryExecutionFactory.create(aboxSparqlQuery,unionDataset);
}
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 {
keywordURI = webappDaoFactory.getIndividualDao().insertNewIndividual(keywordIndividual);
} catch (InsertException e) {
log.error(e);
log.error(e, e);
}
log.debug("KeywordDaoJena.insertNewKeyword() : "+keywordURI);

View file

@ -189,7 +189,7 @@ public class ModelAuditor implements ModelChangedListener {
}
} 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 com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
public class ModelContext {
@ -75,4 +76,26 @@ public class ModelContext {
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 {
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(
//"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#",
//"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#",
// Don't need to exclude these, because they are not owl:ObjectProperty
//"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#"
);
/*
@ -75,43 +71,43 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
namespaceFilters.add("(afn:namespace(?property) != \"" + s + "\")");
}
// 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> ||" +
"?property = <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#additionalLink> ||" +
namespaceFilters.add("( ?property = vitro:primaryLink ||" +
"?property = vitro:additionalLink ||" +
"afn:namespace(?property) != \"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#\" )");
propertyFilters = "FILTER (" + StringUtils.join(namespaceFilters, " && ") + ")\n";
}
protected static final String objectPropertyQueryString =
PREFIXES + "\n" +
protected static final String OBJECT_PROPERTY_QUERY_STRING =
prefixes + "\n" +
"SELECT DISTINCT ?property WHERE { \n" +
" GRAPH ?g1 { ?subject ?property ?object } \n" +
" GRAPH ?g2 { ?property rdf:type owl:ObjectProperty } \n" +
propertyFilters +
"}";
static protected Query objectPropertyQuery;
protected static Query objectPropertyQuery;
static {
try {
objectPropertyQuery = QueryFactory.create(objectPropertyQueryString);
objectPropertyQuery = QueryFactory.create(OBJECT_PROPERTY_QUERY_STRING);
} catch(Throwable th){
log.error("could not create SPARQL query for objectPropertyQueryString " + th.getMessage());
log.error(objectPropertyQueryString);
log.error("could not create SPARQL query for OBJECT_PROPERTY_QUERY_STRING " + th.getMessage());
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#>" +
"SELECT ?property ?filename WHERE { \n" +
" ?property display:listViewConfigFile ?filename . \n" +
"}";
static protected Query listViewConfigFileQuery;
protected static Query listViewConfigFileQuery;
static {
try {
listViewConfigFileQuery = QueryFactory.create(listViewConfigFileQueryString);
listViewConfigFileQuery = QueryFactory.create(LIST_VIEW_CONFIG_FILE_QUERY_STRING);
} catch(Throwable th){
log.error("could not create SPARQL query for listViewConfigFileQueryString " + th.getMessage());
log.error(listViewConfigFileQueryString);
log.error("could not create SPARQL query for LIST_VIEW_CONFIG_FILE_QUERY_STRING " + th.getMessage());
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.
*/
public List<ObjectProperty> getObjectPropertyList(String subjectUri) {
log.debug("objectPropertyQueryString:\n" + objectPropertyQueryString);
log.debug("objectPropertyQuery:\n" + objectPropertyQuery);
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
log.debug("Object property query string:\n" + OBJECT_PROPERTY_QUERY_STRING);
log.debug("Object property query:\n" + objectPropertyQuery);
Iterator<QuerySolution> results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
while (results.hasNext()) {
QuerySolution soln = results.next();

View file

@ -3,9 +3,11 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
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.ResultSet;
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.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
@ -246,6 +250,17 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
return 0;
}
@Override
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri,
String propertyUri,
String queryString) {
return getObjectPropertyStatementsForIndividualByProperty(
subjectUri, propertyUri, null);
}
@Override
/*
* 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.
* 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);
@ -264,11 +286,14 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
} catch(Throwable th){
log.error("Could not create SPARQL query for query string. " + th.getMessage());
log.error(queryString);
return Collections.emptyList();
}
QuerySolutionMap bindings = new QuerySolutionMap();
bindings.add("subject", ResourceFactory.createResource(subjectUri));
bindings.add("property", ResourceFactory.createResource(propertyUri));
// RY One oddity here is that SDB adds the bound variables to the query select terms,
// even if they're not included in the query.
QuerySolutionMap initialBindings = new QuerySolutionMap();
initialBindings.add("subject", ResourceFactory.createResource(subjectUri));
initialBindings.add("property", ResourceFactory.createResource(propertyUri));
// Run the SPARQL query to get the properties
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);
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();
while (results.hasNext()) {
@ -293,4 +323,59 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
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.dao.ObjectPropertyStatementDao;
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
ObjectPropertyStatementDaoJena implements ObjectPropertyStatementDao {
private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public ObjectPropertyStatementDaoSDB(
DatasetWrapperFactory dwf,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super (dwf, wadf);
this.dwf = dwf;
this.datasetMode = datasetMode;
}
@Override
@ -48,15 +53,17 @@ public class ObjectPropertyStatementDaoSDB extends
Map<String, ObjectProperty> uriToObjectProperty = new HashMap<String,ObjectProperty>();
String query = "CONSTRUCT { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" +
" ?o a ?oType . \n" +
" ?o <" + RDFS.label.getURI() + "> ?oLabel . \n" +
" ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker \n" +
"} WHERE { GRAPH ?g { \n" +
" <" + entity.getURI() + "> ?p ?o \n" +
" OPTIONAL { GRAPH ?h { ?o a ?oType } } \n" +
" OPTIONAL { GRAPH ?i { ?o <" + RDFS.label.getURI() + "> ?oLabel } } \n" +
" OPTIONAL { GRAPH ?j { ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } } \n" +
"} }";
// " ?o a ?oType . \n" +
// " ?o <" + RDFS.label.getURI() + "> ?oLabel . \n" +
// " ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker \n" +
"} WHERE { \n" +
" { <" + entity.getURI() + "> ?p ?o } \n" +
// " UNION { <" + entity.getURI() + "> ?p ?o . ?o a ?oType } \n" +
// " UNION { <" + entity.getURI() + "> ?p ?o . \n" +
// " ?o <" + RDFS.label.getURI() + "> ?oLabel } \n" +
// " UNION { <" + entity.getURI() + "> ?p ?o . \n " +
// " ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } \n" +
"}";
long startTime = System.currentTimeMillis();
Model m = null;
DatasetWrapper w = dwf.getDatasetWrapper();
@ -90,48 +97,46 @@ public class ObjectPropertyStatementDaoSDB extends
ObjectPropertyStatement objPropertyStmt = new ObjectPropertyStatementImpl();
objPropertyStmt.setSubjectURI(entity.getURI());
objPropertyStmt.setSubject(entity);
try {
objPropertyStmt.setObjectURI(((Resource)st.getObject()).getURI());
} catch (Throwable t) {
t.printStackTrace();
}
objPropertyStmt.setObjectURI(((Resource)st.getObject()).getURI());
objPropertyStmt.setPropertyURI(st.getPredicate().getURI());
try {
Property prop = st.getPredicate();
if( uriToObjectProperty.containsKey(prop.getURI())){
objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI()));
}else{
ObjectProperty p = getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURI(prop.getURI());
if( p != null ){
uriToObjectProperty.put(prop.getURI(), p);
objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI()));
}else{
//if ObjectProperty not found in ontology, skip it
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;
}
Property prop = st.getPredicate();
if( uriToObjectProperty.containsKey(prop.getURI())){
objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI()));
}else{
ObjectProperty p = getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURI(prop.getURI());
if( p != null ){
uriToObjectProperty.put(prop.getURI(), p);
objPropertyStmt.setProperty(uriToObjectProperty.get(prop.getURI()));
}else{
//if ObjectProperty not found in ontology, skip it
continue;
}
}
if (objPropertyStmt.getObjectURI() != null) {
Individual objInd = new IndividualSDB(
objPropertyStmt.getObjectURI(),
this.dwf,
getWebappDaoFactory(),
m);
objPropertyStmt.setObject(objInd);
//this might throw IndividualNotFoundException
Individual objInd = new IndividualSDB(
objPropertyStmt.getObjectURI(),
this.dwf,
datasetMode,
getWebappDaoFactory());
objPropertyStmt.setObject(objInd);
}
//add object property statement to list for Individual
if ((objPropertyStmt.getSubjectURI() != null)
&& (objPropertyStmt.getPropertyURI() != null)
&& (objPropertyStmt.getObject() != null)){
//only add statement to list if it has its values filled out
if ( (objPropertyStmt.getSubjectURI() != null)
&& (objPropertyStmt.getPropertyURI() != null)
&& (objPropertyStmt.getObject() != null) ) {
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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
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.dao.PropertyDao;
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;
public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
protected static final Log log = LogFactory.getLog(PropertyDaoJena.class.getName());
protected static final String PREFIXES =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
//"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" +
"PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>";
private static final Map<String, String> NAMESPACES = new HashMap<String, String>() {{
put("afn", VitroVocabulary.AFN);
put("owl", VitroVocabulary.OWL);
put("rdf", VitroVocabulary.RDF);
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,
WebappDaoFactoryJena wadf) {
@ -117,7 +130,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} catch (Exception cce) {}
}
} catch (Exception e) {
log.error(e);
log.error(e, e);
} finally {
getOntModel().leaveCriticalSection();
}
@ -158,7 +171,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} catch (Exception cce) {}
}
} catch (Exception e) {
log.error(e);
log.error(e, e);
} finally {
getOntModel().leaveCriticalSection();
}
@ -238,7 +251,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
}
}
} catch (Exception e) {
log.error(e);
log.error(e, e);
} finally {
getOntModel().leaveCriticalSection();
}
@ -389,21 +402,32 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return classSet;
}
protected ResultSet getPropertyQueryResults(String subjectUri, Query query) {
protected Iterator<QuerySolution> getPropertyQueryResults(String subjectUri, Query query) {
log.debug("SPARQL query:\n" + query.toString());
// Bind the subject's uri to the ?subject query term
QuerySolutionMap subjectBinding = new QuerySolutionMap();
subjectBinding.add("subject",
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();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
try {
QueryExecution qexec = QueryExecutionFactory.create(
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 {
dataset.getLock().leaveCriticalSection();
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.ontology.Individual;
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.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.shared.Lock;
@ -129,26 +131,49 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
groupInd.setURI(group.getURI());
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) {
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) {
getOntModel().enterCriticalSection(Lock.WRITE);
try {
com.hp.hpl.jena.ontology.Individual groupJenaInd = getOntModel().getIndividual(groupURI);
com.hp.hpl.jena.ontology.Individual groupJenaInd =
getOntModel().getIndividual(groupURI);
try {
groupJenaInd.addProperty(DISPLAY_RANK, Integer.toString(group.getDisplayRank()), XSDDatatype.XSDint);
groupJenaInd.addProperty(DISPLAY_RANK, Integer.toString(
group.getDisplayRank()), XSDDatatype.XSDint);
} 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 {
groupJenaInd.addProperty(PUBLIC_DESCRIPTION_ANNOT, group.getPublicDescription(), XSDDatatype.XSDstring);
groupJenaInd.addProperty(
PUBLIC_DESCRIPTION_ANNOT,
group.getPublicDescription(),
XSDDatatype.XSDstring);
} catch (Exception ex) {
log.error("error setting public description for "+groupInd.getURI());
log.error(
"error setting public description for "
+ groupInd.getURI());
}
}
} finally {

View file

@ -14,17 +14,22 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
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.OntProperty;
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.ResIterator;
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.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
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.ObjectPropertyStatement;
@ -95,23 +100,40 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
public Collection<PropertyInstance> getAllPossiblePropInstForIndividual(String 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
Collections.sort(allTypes, new VClassHierarchyRanker(this.getWebappDaoFactory().getVClassDao()));
for (VClass currClass : allTypes) {
Collection<PropertyInstance> propInstsForClass = getAllPropInstByVClass(currClass.getURI());
for (PropertyInstance propInst : propInstsForClass) {
if (propURI2propInst.get(propInst.getPropertyURI()) == null) {
propURI2propInst.put(propInst.getPropertyURI(), propInst);
}
}
Set<String> allSuperclassURIs = new HashSet<String>();
for (VClass type : allTypes) {
String classURI = type.getURI();
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;
}
@ -126,15 +148,19 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
public int compare(VClass vc1, VClass vc2) {
if (vcDao.isSubClassOf(vc1, vc2)) {
return -1;
} else return 0;
} else if (vcDao.isSubClassOf(vc2, vc1)) {
return 1;
} else {
return 0;
}
}
}
public Collection<PropertyInstance> getAllPropInstByVClass(String classURI) {
if (classURI==null || classURI.length()<1) {
return null;
}
List<PropertyInstance> propInsts = new ArrayList();
VClassDao vcDao = getWebappDaoFactory().getVClassDao();
@ -142,56 +168,135 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
allSuperclassURIs.add(classURI);
for (String equivURI : vcDao.getEquivalentClassURIs(classURI)) {
allSuperclassURIs.add(equivURI);
allSuperclassURIs.addAll(vcDao.getAllSuperClassURIs(equivURI));
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);
}
}
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();
try {
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 {
for (String VClassURI : allSuperclassURIs) {
for (VClass vclass : vclasses) {
if (vclass.isAnonymous()) {
continue;
}
String VClassURI = vclass.getURI();
OntClass ontClass = getOntClass(ontModel,VClassURI);
if (ontClass != null) {
if (ontClass.isRestriction()) {
// TODO: check if restriction is something like
// maxCardinality 0 or allValuesFrom owl:Nothing,
// in which case the property is NOT applicable!
Restriction rest = (Restriction) ontClass.as(Restriction.class);
OntProperty onProperty = rest.getOnProperty();
if (onProperty != null && onProperty.canAs(ObjectProperty.class)) {
applicableProperties.add((ObjectProperty)onProperty.as(ObjectProperty.class));
}
List<OntClass> relatedClasses = new ArrayList<OntClass>();
relatedClasses.addAll(ontClass.listEquivalentClasses().toList());
relatedClasses.addAll(ontClass.listSuperClasses().toList());
for (OntClass relatedClass : relatedClasses) {
// find properties in restrictions
if (relatedClass.isRestriction()) {
// TODO: check if restriction is something like
// 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) {
log.error("Unable to get applicable properties for " + classURI
+ " by examining property restrictions", e);
log.error("Unable to get applicable properties " +
"by examining property restrictions and domains", e);
}
HashSet allSuperclassURIset = new HashSet(allSuperclassURIs);
Iterator ops = ontModel.listObjectProperties();
while (ops.hasNext()) {
ObjectProperty op = (ObjectProperty) ops.next();
if (op.getNameSpace() != null && !NONUSER_NAMESPACES.contains(op.getNameSpace()) ) {
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();
// make the PropertyInstance objects
for (String propertyURI : applicableProperties.keySet()) {
ObjectProperty op = ontModel.getObjectProperty(propertyURI);
if (op == null) {
continue;
}
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();
if (rangeRes != null) {
String rangeClassURI;
@ -219,8 +324,7 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements
pi.setRangePublic(getLabelOrId(op));
pi.setDomainPublic(getLabelOrId(op));
propInsts.add(pi);
}
}
} finally {
ontModel.leaveCriticalSection();
}

View file

@ -32,7 +32,9 @@ public class QueryUtils {
Iterator<String> varNames = soln.varNames();
while(varNames.hasNext()){
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;
}
@ -42,7 +44,9 @@ public class QueryUtils {
Iterator<String> varNames = soln.varNames();
while(varNames.hasNext()){
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;
}

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);
return graphRDB;
} catch (SQLException e) {
log.error(e);
log.error(e, e);
throw new RuntimeException("SQLException: unable to regenerate graph", e);
}
}

View file

@ -2,9 +2,7 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -32,18 +30,34 @@ public class SearchReindexingListener implements ModelChangedListener {
this.indexBuilder = indexBuilder;
}
private synchronized void addChange(Statement stmt){
private synchronized void addChange(Statement stmt){
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() ){
//changedUris.add( stmt.getSubject().getURI());
indexBuilder.addToChangedUris(stmt.getSubject().getURI());
log.debug("subject: " + stmt.getSubject().getURI());
}
if( stmt.getObject().isURIResource() ){
//changedUris.add( ((Resource) stmt.getObject().as(Resource.class)).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.OntClass;
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.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.shared.Lock;
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);
if (portalInd == null)
return -1;
Resource rootTabResource = (Resource) portalInd.getProperty(getOntModel().getObjectProperty(VitroVocabulary.PORTAL_ROOTTAB)).getObject();
Resource rootTabResource = (Resource) portalInd.getProperty(PORTAL_ROOTTAB).getObject();
if (rootTabResource == null)
return -1;
String id = rootTabResource.getLocalName().substring(3);
@ -346,7 +348,7 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
try {
Individual primaryTabInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+primaryTabId);
if (primaryTabInd != null) {
ObjectProperty subTabOf = getOntModel().getObjectProperty(VitroVocabulary.TAB_SUBTABOF);
ObjectProperty subTabOf = TAB_SUBTABOF;
if (subTabOf != null) {
List secondaryTabs = new ArrayList();
Iterator stmtIt = getOntModel().listStatements(null, subTabOf, primaryTabInd);
@ -477,7 +479,7 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
Integer i = null;
Individual narrowerTab = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+tabId);
if (narrowerTab != null) {
ObjectProperty subTabOf = getOntModel().getObjectProperty(VitroVocabulary.TAB_SUBTABOF);
ObjectProperty subTabOf = TAB_SUBTABOF;
if (subTabOf != null) {
Iterator stmtIt = narrowerTab.listProperties(subTabOf);
if (stmtIt.hasNext()) {
@ -569,19 +571,19 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
try {
tabInd.setLabel(tab.getTitle(), (String) getDefaultLanguage());
} catch (Exception e) {log.error("error setting label for "+tabInd.getURI());}
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DESCRIPTION), tab.getDescription(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_STATUSID), tab.getStatusId(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_BODY), tab.getBody(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DISPLAY_RANK), tab.getDisplayRank(), ontModel);
addPropertyIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_DAYLIMIT), tab.getDayLimit(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYROWS), tab.getGalleryRows(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYCOLS), tab.getGalleryCols(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_MORETAG), tab.getMoreTag(), ontModel);
addPropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_IMAGEWIDTH), tab.getImageWidth(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTFIELD), tab.getEntitySortField(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTDIRECTION), tab.getEntitySortDirection(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2MODE), tab.getFlag2Mode(), ontModel);
addPropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2SET), tab.getFlag2Set(), ontModel);
addPropertyStringValue(tabInd, DESCRIPTION, tab.getDescription(), ontModel);
addPropertyNonNegativeIntValue(tabInd, TAB_STATUSID, tab.getStatusId(), ontModel);
addPropertyStringValue(tabInd, TAB_BODY, tab.getBody(), ontModel);
addPropertyNonNegativeIntValue(tabInd, DISPLAY_RANK, tab.getDisplayRank(), ontModel);
addPropertyIntValue(tabInd, TAB_DAYLIMIT, tab.getDayLimit(), ontModel);
addPropertyNonNegativeIntValue(tabInd, TAB_GALLERYROWS, tab.getGalleryRows(), ontModel);
addPropertyNonNegativeIntValue(tabInd, TAB_GALLERYCOLS, tab.getGalleryCols(), ontModel);
addPropertyStringValue(tabInd, TAB_MORETAG, tab.getMoreTag(), ontModel);
addPropertyNonNegativeIntValue(tabInd, TAB_IMAGEWIDTH, tab.getImageWidth(), ontModel);
addPropertyStringValue(tabInd, TAB_ENTITYSORTFIELD, tab.getEntitySortField(), ontModel);
addPropertyStringValue(tabInd, TAB_ENTITYSORTDIRECTION, tab.getEntitySortDirection(), ontModel);
addPropertyStringValue(tabInd, TAB_FLAG2MODE, tab.getFlag2Mode(), ontModel);
addPropertyStringValue(tabInd, TAB_FLAG2SET, tab.getFlag2Set(), ontModel);
try {
Object o = entityLinkMethods.get(tab.getEntityLinkMethod());
if (o instanceof List) {
@ -622,19 +624,19 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
try {
tabInd.setLabel(tab.getTitle(), (String) getDefaultLanguage());
} catch (Exception e) {log.error("Error updating title for tab "+tab.getTabId());}
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DESCRIPTION), tab.getDescription(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_STATUSID), tab.getStatusId(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_BODY), tab.getBody(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.DISPLAY_RANK), tab.getDisplayRank(), ontModel);
updatePropertyIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_DAYLIMIT), tab.getDayLimit(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYROWS), tab.getGalleryRows(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_GALLERYCOLS), tab.getGalleryCols(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_MORETAG), tab.getMoreTag(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_IMAGEWIDTH), tab.getImageWidth(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTFIELD), tab.getEntitySortField(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_ENTITYSORTDIRECTION), tab.getEntitySortDirection(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2MODE), tab.getFlag2Mode(), ontModel);
updatePropertyStringValue(tabInd, ontModel.getDatatypeProperty(VitroVocabulary.TAB_FLAG2SET), tab.getFlag2Set(), ontModel);
updatePropertyStringValue(tabInd, DESCRIPTION, tab.getDescription(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, TAB_STATUSID, tab.getStatusId(), ontModel);
updatePropertyStringValue(tabInd, TAB_BODY, tab.getBody(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, DISPLAY_RANK, tab.getDisplayRank(), ontModel);
updatePropertyIntValue(tabInd, TAB_DAYLIMIT, tab.getDayLimit(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, TAB_GALLERYROWS, tab.getGalleryRows(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, TAB_GALLERYCOLS, tab.getGalleryCols(), ontModel);
updatePropertyStringValue(tabInd, TAB_MORETAG, tab.getMoreTag(), ontModel);
updatePropertyNonNegativeIntValue(tabInd, TAB_IMAGEWIDTH, tab.getImageWidth(), ontModel);
updatePropertyStringValue(tabInd, TAB_ENTITYSORTFIELD, tab.getEntitySortField(), ontModel);
updatePropertyStringValue(tabInd, TAB_ENTITYSORTDIRECTION, tab.getEntitySortDirection(), ontModel);
updatePropertyStringValue(tabInd, TAB_FLAG2MODE, tab.getFlag2Mode(), ontModel);
updatePropertyStringValue(tabInd, TAB_FLAG2SET, tab.getFlag2Set(), ontModel);
Iterator types = tabInd.listRDFTypes(false);
List typesToRemove = new ArrayList();
while (types.hasNext()) {
@ -862,11 +864,7 @@ public class TabDaoJena extends JenaBaseDao implements TabDao {
* look first for heading tabs
*/
private void getChildTabs(Tab tab, int auth_level, ApplicationBean appBean){
ObjectProperty subTabOf = getOntModel().getObjectProperty(VitroVocabulary.TAB_SUBTABOF);
if (subTabOf == null) {
log.error("cannot find property "+ VitroVocabulary.TAB_SUBTABOF);
return;
}
Property subTabOf = ResourceFactory.createProperty(VitroVocabulary.TAB_SUBTABOF);
Individual parentTabInd = getOntModel().getIndividual(DEFAULT_NAMESPACE+"tab"+tab.getTabId());
if (parentTabInd == null)
return;

View file

@ -780,6 +780,11 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
@Deprecated
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) {
getOntModel().enterCriticalSection(Lock.READ);
if (getIndividualCount) {
group.setIndividualCount( getClassGroupInstanceCount(group));
}
try {
if ((group != null) && (group.getURI() != null)) {
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) {
getOntModel().enterCriticalSection(Lock.READ);
try {

View file

@ -2,6 +2,8 @@
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.OntClass;
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.QueryExecutionFactory;
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.Syntax;
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.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class VClassDaoSDB extends VClassDaoJena {
private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory,
WebappDaoFactoryJena wadf) {
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super(wadf);
this.dwf = datasetWrapperFactory;
this.datasetMode = datasetMode;
}
protected DatasetWrapper getDatasetWrapper() {
@ -40,9 +48,14 @@ public class VClassDaoSDB extends VClassDaoJena {
@Deprecated
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) {
if (getIndividualCount) {
group.setIndividualCount( getClassGroupInstanceCount(group));
}
getOntModel().enterCriticalSection(Lock.READ);
try {
if ((group != null) && (group.getURI() != null)) {
if ((group != null) && (group.getURI() != null)) {
Resource groupRes = ResourceFactory.createResource(group.getURI());
AnnotationProperty inClassGroup = getOntModel().getAnnotationProperty(VitroVocabulary.IN_CLASSGROUP);
if (inClassGroup != null) {
@ -55,28 +68,25 @@ public class VClassDaoSDB extends VClassDaoJena {
VClass vcw = (VClass) getVClassByURI(cls.getURI());
if (vcw != null) {
boolean classIsInstantiated = false;
if (getIndividualCount) {
Model aboxModel = getOntModelSelector().getABoxModel();
aboxModel.enterCriticalSection(Lock.READ);
int count = 0;
try {
String countQueryStr = "SELECT COUNT(*) WHERE \n" +
"{ GRAPH ?g { ?s a <" + cls.getURI() + "> } } \n";
Query countQuery = QueryFactory.create(countQueryStr, 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();
}
} finally {
aboxModel.leaveCriticalSection();
}
if (getIndividualCount) {
int count = 0;
String[] graphVars = { "?g" };
String countQueryStr = "SELECT COUNT(DISTINCT ?s) WHERE \n" +
"{ GRAPH ?g { ?s a <" + cls.getURI() + "> } \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"} \n";
Query countQuery = QueryFactory.create(countQueryStr, 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();
}
vcw.setEntityCount(count);
classIsInstantiated = (count > 0);
} else if (includeUninstantiatedClasses == false) {
@ -114,5 +124,43 @@ public class VClassDaoSDB extends VClassDaoJena {
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.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletContext;
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.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
public class VClassGroupCache implements ServletContextListener{
/* 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;
public class VClassGroupCache{
private static final Log log = LogFactory.getLog(VClassGroupCache.class);
private static boolean ORDER_BY_DISPLAYRANK = true;
private static boolean INCLUDE_UNINSTANTIATED = true;
private static boolean INCLUDE_INDIVIDUAL_COUNT = true;
public VClassGroupCache(){}
private static final String ATTRIBUTE_NAME = "VClassGroupCache";
private static final String REBUILD_EVERY_PORTAL = "Rebuild every portal.";
private static final boolean ORDER_BY_DISPLAYRANK = true;
private static final boolean INCLUDE_UNINSTANTIATED = true;
private static final boolean INCLUDE_INDIVIDUAL_COUNT = true;
/**
* 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) {
this.context = context;
this._groupListMap = new ConcurrentHashMap<Integer, List<VClassGroup>>();
this._rebuildQueue = new ConcurrentLinkedQueue<String>();
if( AbortStartup.isStartupAborted(context)){
_cacheRebuildThread = null;
return;
}
VClassGroupCacheChangeListener bccl = new VClassGroupCacheChangeListener(this);
ModelContext.getJenaOntModel(context).register(bccl);
ModelContext.getBaseOntModel(context).register(bccl);
ModelContext.getInferenceOntModel(context).register(bccl);
ModelContext.getUnionOntModelSelector(context).getABoxModel().register(bccl);
ModelContext.registerListenerForChanges(context, bccl);
//
// ModelContext.getJenaOntModel(context).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);
_cacheRebuildThread = new RebuildGroupCacheThread(this);
@ -71,13 +86,9 @@ public class VClassGroupCache implements ServletContextListener{
_cacheRebuildThread.informOfQueueChange();
}
public static VClassGroupCache getVClassGroupCache(ServletContext sc){
return (VClassGroupCache) sc.getAttribute("VClassGroupCache");
}
public List<VClassGroup> getGroups( int portalId ){
return getGroups(getVCGDao(),portalId );
}
public void clearGroupCache(){
_groupListMap.clear();
}
/**
* May return null.
@ -93,10 +104,13 @@ public class VClassGroupCache implements ServletContextListener{
return null;
}
public void clearGroupCache(){
_groupListMap = new ConcurrentHashMap<Integer, List<VClassGroup>>();
}
public List<VClassGroup> getGroups( int portalId ){
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 ){
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){
log.debug("requesting update for portal " + portalUri);
_rebuildQueue.add(portalUri);
@ -254,9 +264,26 @@ public class VClassGroupCache implements ServletContextListener{
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***************************** */
private class VClassGroupCacheChangeListener extends StatementListener {
private VClassGroupCache cache = null;
@ -289,88 +316,70 @@ public class VClassGroupCache implements ServletContextListener{
}
/* ******************** RebuildGroupCacheThread **************** */
protected class RebuildGroupCacheThread extends Thread {
VClassGroupCache cache;
boolean die = false;
boolean queueChange = false;
long queueChangeMills = 0;
private boolean awareOfQueueChange = false;
private final VClassGroupCache cache;
private final AtomicLong queueChangeMillis = new AtomicLong();
private volatile boolean die = false;
RebuildGroupCacheThread(VClassGroupCache cache) {
super("VClassGroupCache.RebuildGroupCacheThread");
this.cache = cache;
}
public void run() {
while(true){
try{
synchronized (this){
if( _rebuildQueue.isEmpty() ){
log.debug("rebuildGroupCacheThread.run() -- queye empty, sleep");
wait(1000 * 60 );
}
if( die ) {
log.debug("doing rebuildGroupCacheThread.run() -- die()");
return;
}
if( queueChange && !awareOfQueueChange){
log.debug("rebuildGroupCacheThread.run() -- awareOfQueueChange, delay start of rebuild");
awareOfQueueChange = true;
wait(200);
}
}
if( awareOfQueueChange && System.currentTimeMillis() - queueChangeMills > 200){
log.debug("rebuildGroupCacheThread.run() -- refreshGroupCache()");
cache.refreshGroupCache();
synchronized( this){
queueChange = false;
}
awareOfQueueChange = false;
}else {
synchronized( this ){
wait(200);
}
}
} catch(InterruptedException e){}
while (!die) {
int delay;
if (_rebuildQueue.isEmpty()) {
log.debug("rebuildGroupCacheThread.run() -- queue empty, sleep");
delay = 1000 * 60;
} else if ((System.currentTimeMillis() - queueChangeMillis.get()) < 200) {
log.debug("rebuildGroupCacheThread.run() -- delay start of rebuild");
delay = 200;
} else {
log.debug("rebuildGroupCacheThread.run() -- refreshGroupCache()");
cache.refreshGroupCache();
delay = 0;
}
if (delay > 0) {
synchronized (this) {
try {
wait(delay);
} catch (InterruptedException e) {
log.warn("Waiting " + delay
+ " milliseconds, but interrupted.", e);
}
}
}
}
log.debug("rebuildGroupCacheThread.run() -- die()");
}
synchronized void informOfQueueChange(){
queueChange = true;
queueChangeMills = System.currentTimeMillis();
queueChangeMillis.set(System.currentTimeMillis());
this.notifyAll();
}
synchronized void kill(){
die = true;
notifyAll();
this.notifyAll();
}
}
protected VClassGroupDao getVCGDao(){
if( context == null ){
log.error("Context was not set for VClassGroupCache");
return null;
/* ******************** ServletContextListener **************** */
public static class Setup implements ServletContextListener {
@Override
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
public void contextDestroyed(ServletContextEvent arg0) {
if( _cacheRebuildThread != null )
_cacheRebuildThread.kill();
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
arg0.getServletContext().setAttribute("VClassGroupCache", new VClassGroupCache(arg0.getServletContext()) );
@Override
public void contextDestroyed(ServletContextEvent sce) {
Object o = sce.getServletContext().getAttribute(ATTRIBUTE_NAME);
if (o instanceof VClassGroupCache ) {
((VClassGroupCache) o).requestStop();
}
}
}
}

View file

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

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -11,8 +13,15 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.commons.dbcp.BasicDataSource;
import com.hp.hpl.jena.graph.GraphMaker;
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.Model;
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.Statement;
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.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.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.WrappedIterator;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.ibm.icu.text.Collator;
public class VitroJenaSDBModelMaker implements ModelMaker {
// 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 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
public VitroJenaSDBModelMaker(Store store) {
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();
}
public VitroJenaSDBModelMaker(StoreDesc storeDesc, BasicDataSource bds) throws SQLException {
this.metadataModel = getModel(METADATA_MODEL_URI);
this.storeDesc = storeDesc;
this.bds = bds;
Store store = getStore();
try {
if (metadataModel.size()==0) {
// set up the model name metadata to avoid expensive calls to listNames()
Resource sdbRes = metadataModel.createResource();
this.sdbResource = sdbRes;
Iterator nameIt = SDBFactory.connectDataset(store).listNames();
while (nameIt.hasNext()) {
String name = (String) nameIt.next();
metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),name);
}
} else {
StmtIterator stmtIt = metadataModel.listStatements((Resource)null, metadataModel.getProperty(HAS_NAMED_MODEL_URI),(RDFNode)null);
if (stmtIt.hasNext()) {
Statement stmt = stmtIt.nextStatement();
sdbResource = stmt.getSubject();
}
stmtIt.close();
}
Model metadataModel = getMetadataModel();
if (metadataModel.size()==0) {
// set up the model name metadata to avoid expensive calls to listNames()
Resource sdbRes = metadataModel.createResource();
this.sdbResource = sdbRes;
Iterator nameIt = SDBFactory.connectDataset(store).listNames();
while (nameIt.hasNext()) {
String name = (String) nameIt.next();
metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),name);
}
} else {
StmtIterator stmtIt = metadataModel.listStatements((Resource)null, metadataModel.getProperty(HAS_NAMED_MODEL_URI),(RDFNode)null);
if (stmtIt.hasNext()) {
Statement stmt = stmtIt.nextStatement();
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() {
store.close();
getStore().close();
}
public Model createModel(String arg0) {
Model model = SDBFactory.connectNamedModel(store, arg0);
metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0);
Model model = SDBFactory.connectNamedModel(getStore(), arg0);
Model metadataModel = getMetadataModel();
try {
metadataModel.add(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0);
} finally {
metadataModel.close();
}
return model;
}
@ -97,22 +187,30 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
}
public boolean hasModel(String arg0) {
StmtIterator stmtIt = metadataModel.listStatements(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0);
try {
return stmtIt.hasNext();
} finally {
if (stmtIt != null) {
stmtIt.close();
}
}
Model metadataModel = getMetadataModel();
try {
StmtIterator stmtIt = metadataModel.listStatements(sdbResource,metadataModel.getProperty(HAS_NAMED_MODEL_URI),arg0);
try {
return stmtIt.hasNext();
} finally {
if (stmtIt != null) {
stmtIt.close();
}
}
} finally {
metadataModel.close();
}
}
public ExtendedIterator listModels() {
ArrayList<String> metaNameList = new ArrayList<String>();
ArrayList<String> storeNameList = new ArrayList<String>();
ArrayList<String> unionNameList = new ArrayList<String>();
Model metadataModel = getMetadataModel();
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;
RDFNode rdfNode = null;
@ -230,17 +328,26 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
}while(metaString!=null || storeString!=null);
if (metadataModel != null) {
metadataModel.close();
}
return WrappedIterator.create(unionNameList.iterator());
}
public Model openModel(String arg0, boolean arg1) {
return SDBFactory.connectNamedModel(store,arg0);
return SDBFactory.connectNamedModel(getStore(),arg0);
}
public void removeModel(String arg0) {
Model m = getModel(arg0);
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) {
@ -260,11 +367,11 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
}
public Model openModel() {
return SDBFactory.connectDefaultModel(store);
return SDBFactory.connectDefaultModel(getStore());
}
public Model createDefaultModel() {
return SDBFactory.connectDefaultModel(store);
return SDBFactory.connectDefaultModel(getStore());
}
public Model createFreshModel() {
@ -275,26 +382,26 @@ public class VitroJenaSDBModelMaker implements ModelMaker {
* @deprecated
*/
public Model createModel() {
return SDBFactory.connectDefaultModel(store);
return SDBFactory.connectDefaultModel(getStore());
}
/**
* @deprecated
*/
public Model getModel() {
return SDBFactory.connectDefaultModel(store);
return SDBFactory.connectDefaultModel(getStore());
}
public Model openModel(String arg0) {
return SDBFactory.connectDefaultModel(store);
return SDBFactory.connectDefaultModel(getStore());
}
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) {
return SDBFactory.connectNamedModel(store, arg0);
return SDBFactory.connectNamedModel(getStore(), arg0);
}
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.ontology.OntClass;
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.query.DataSource;
import com.hp.hpl.jena.query.Dataset;
@ -72,7 +73,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
protected KeywordDao keywordDao;
protected LinksDao linksDao;
protected LinktypeDao linktypeDao;
protected ApplicationDao applicationDao;
protected ApplicationDaoJena applicationDao;
protected PortalDao portalDao;
protected TabDao tabDao;
protected TabIndividualRelationDao tabs2EntsDao;
@ -118,6 +119,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
this.userURI = userURI;
this.flag2ValueMap = base.flag2ValueMap;
this.flag2ClassLabelMap = base.flag2ClassLabelMap;
this.dwf = base.dwf;
}
public WebappDaoFactoryJena(OntModelSelector ontModelSelector,
@ -174,22 +176,37 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
if (languageUniversalsModel.size()>0) {
this.ontModelSelector.getTBoxModel().addSubModel(languageUniversalsModel);
}
DataSource dataset = DatasetFactory.create();
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_DB_MODEL,
(baseOntModelSelector != null)
? baseOntModelSelector.getFullModel()
: ontModelSelector.getFullModel());
if (inferenceOntModelSelector != null) {
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_INF_MODEL,
inferenceOntModelSelector.getFullModel());
}
Model assertions = (baseOntModelSelector != null)
? baseOntModelSelector.getFullModel()
: ontModelSelector.getFullModel();
Model inferences = (inferenceOntModelSelector != null)
? inferenceOntModelSelector.getFullModel()
: null;
Dataset dataset = makeInMemoryDataset(assertions, inferences);
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,
String defaultNamespace,
HashSet<String> nonuserNamespaces,
@ -641,5 +658,12 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
public DisplayModelDao getDisplayModelDao(){
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.ObjectPropertyStatementDao;
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 {
private SDBDatasetMode datasetMode = SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
/**
* For use when any database connection associated with the Dataset
* is managed externally
* @param ontModelSelector
* @param dataset
*/
public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) {
super(ontModelSelector);
@ -35,8 +37,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
/**
* For use when any database connection associated with the Dataset
* is managed externally
* @param ontModelSelector
* @param dataset
*/
public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
Dataset dataset,
@ -50,8 +50,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
/**
* For use when any Dataset access should get a temporary DB connection
* from a pool
* @param ontModelSelector
* @param dataset
*/
public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
BasicDataSource bds,
@ -62,13 +60,43 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages);
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
public IndividualDao getIndividualDao() {
if (entityWebappDao != null)
return entityWebappDao;
else
return entityWebappDao = new IndividualDaoSDB(dwf, this);
return entityWebappDao = new IndividualDaoSDB(
dwf, datasetMode, this);
}
@Override
@ -76,7 +104,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (dataPropertyStatementDao != null)
return dataPropertyStatementDao;
else
return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(dwf, this);
return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(
dwf, datasetMode, this);
}
@Override
@ -84,7 +113,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (objectPropertyStatementDao != null)
return objectPropertyStatementDao;
else
return objectPropertyStatementDao = new ObjectPropertyStatementDaoSDB(dwf, this);
return objectPropertyStatementDao =
new ObjectPropertyStatementDaoSDB(dwf, datasetMode, this);
}
@Override
@ -92,15 +122,58 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (vClassDao != null)
return vClassDao;
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 BasicDataSource _bds;
private StoreDesc _storeDesc;
private Dataset _dataset;
private Connection _conn;
public ReconnectingDatasetFactory(BasicDataSource bds, StoreDesc storeDesc) {
_bds = bds;
@ -109,20 +182,16 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
public DatasetWrapper getDatasetWrapper() {
try {
if ((_dataset != null) && (_conn != null) && (!_conn.isClosed())) {
return new DatasetWrapper(_dataset);
} else {
_conn = _bds.getConnection();
SDBConnection conn = new SDBConnection(_conn) ;
Store store = SDBFactory.connectStore(conn, _storeDesc);
_dataset = SDBFactory.connectDataset(store);
return new DatasetWrapper(_dataset);
}
Connection sqlConn = _bds.getConnection();
SDBConnection conn = new SDBConnection(sqlConn) ;
Store store = SDBFactory.connectStore(conn, _storeDesc);
Dataset dataset = SDBFactory.connectDataset(store);
return new DatasetWrapper(dataset, conn);
} catch (SQLException sqe) {
throw new RuntimeException("Unable to connect to database", sqe);
}
}
}
}
}

View file

@ -36,16 +36,6 @@ public class 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(){
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
@ -65,7 +55,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
Collection c =
wdf.getPropertyInstanceDao().getAllPropInstByVClass(classURI);
@ -76,7 +66,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
Collection c =
wdf.getPropertyInstanceDao().getAllPossiblePropInstForIndividual(individualURI);
@ -87,7 +77,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
return wdf.getPropertyInstanceDao().getProperty(subjectURI, predicateURI, objectURI);
}
@ -121,16 +111,14 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req);
return getUnfilteredWebappDaoFactory(vreq).getPropertyInstanceDao().insertProp(prop);
return vreq.getFullWebappDaoFactory().getPropertyInstanceDao().insertProp(prop);
}
public int deleteProp(String subjectUri, String predicateUri, String objectUri){
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req);
getUnfilteredWebappDaoFactory(vreq).getPropertyInstanceDao().deleteObjectPropertyStatement(subjectUri, predicateUri, objectUri);
vreq.getFullWebappDaoFactory().getPropertyInstanceDao().deleteObjectPropertyStatement(subjectUri, predicateUri, objectUri);
return 0;
}
@ -154,7 +142,7 @@ public class PropertyDWR {
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
VitroRequest vreq = new VitroRequest(req);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
WebappDaoFactory wdf = vreq.getFullWebappDaoFactory();
return wdf.getPropertyInstanceDao().getExistingProperties(entityURI, null);
}

View file

@ -95,7 +95,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
this.displayRequiredLevel = toPrecision( displayRequiredLevelUri );
if( this.displayRequiredLevel == null )
throw new IllegalArgumentException(minimumPrecisionURI
throw new IllegalArgumentException(displayRequiredLevelUri
+" is not a valid precision for displayRequiredLevel, see VitroVocabulary.Precision");
// if( this.displayRequiredLevel.ordinal() < this.minimumPrecision.ordinal() ){
@ -127,7 +127,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
map.put("minimumPrecision", minimumPrecision.uri());
map.put("requiredLevel", displayRequiredLevel.uri());
String precisionUri = getExistingPrecision(editConfig,editSub);
String precisionUri = getPrecision(editConfig,editSub);
VitroVocabulary.Precision existingPrec = toPrecision(precisionUri);
if( precisionUri != null && !"".equals(precisionUri) && existingPrec == null ){
@ -216,22 +216,35 @@ public class DateTimeWithPrecision extends BaseEditElement {
/**
* Gets the currently set precision. May return null.
*/
private String getExistingPrecision(EditConfiguration editConfig, EditSubmission editSub) {
String precisionURI = editConfig.getUrisInScope().get( getPrecisionVariableName() );
if( precisionURI == null ){
return null;
private String getPrecision(EditConfiguration editConfig, EditSubmission editSub) {
if( editSub != null ){
String submittedPrecisionURI = editSub.getUrisFromForm().get( getPrecisionVariableName() );
if( submittedPrecisionURI != null ){
return submittedPrecisionURI;
}
}
String existingPrecisionURI = editConfig.getUrisInScope().get( getPrecisionVariableName() );
if( existingPrecisionURI != null ){
return existingPrecisionURI;
}else{
return precisionURI;
}
return null;
}
}
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() );
if( dtValue == null ){
return null;
}else{
if( dtValue != null ){
return new DateTime( dtValue.getLexicalForm() );
}
}else{
return null;
}
}
/**
@ -366,7 +379,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
}
}
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{
return precisions[ indexOfFirstNull ].uri();
}
@ -486,29 +499,32 @@ public class DateTimeWithPrecision extends BaseEditElement {
if( second == null )
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{
dateTime.withYear(year);
dateTime = dateTime.withYear(year);
}catch(IllegalArgumentException iae){
errors.put(fieldName+".year", iae.getLocalizedMessage());
}
try{
dateTime.withMonthOfYear(month);
dateTime = dateTime.withMonthOfYear(month);
}catch(IllegalArgumentException iae){
errors.put(fieldName+".month", iae.getLocalizedMessage());
}
try{
dateTime.withDayOfMonth(day);
dateTime = dateTime.withDayOfMonth(day);
}catch(IllegalArgumentException iae){
errors.put(fieldName+".day", iae.getLocalizedMessage());
}
try{
dateTime.withHourOfDay(hour);
dateTime = dateTime.withHourOfDay(hour);
}catch(IllegalArgumentException iae){
errors.put(fieldName+".hour", iae.getLocalizedMessage());
}
try{
dateTime.withSecondOfMinute(second);
dateTime = dateTime.withSecondOfMinute(second);
}catch(IllegalArgumentException iae){
errors.put(fieldName+".second", iae.getLocalizedMessage());
}
@ -581,7 +597,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
}
/* 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()){
if( precision.uri().equals(precisionUri))
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.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 {
private static Log log = LogFactory.getLog(DateTimeIntervalValidation.class);
@ -20,12 +24,17 @@ public class DateTimeIntervalValidation implements N3Validator {
private String startValueName;
private String endValueName;
private String startPrecisionName;
private String endPrecisionName;
public DateTimeIntervalValidation(String startFieldName, String endFieldName){
this.startFieldName = startFieldName;
this.endFieldName = endFieldName;
startValueName = startFieldName + ".value";
endValueName = endFieldName + ".value";
startPrecisionName = startFieldName + ".precision";
endPrecisionName = endFieldName + ".precision";
}
public Map<String, String> validate(EditConfiguration editConfig,
@ -38,16 +47,24 @@ public class DateTimeIntervalValidation implements N3Validator {
Literal formStartYear = literalsFromForm.get(startValueName);
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>();
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) {
errors.putAll(checkDateLiterals(formStartYear, formEndYear));
errors.putAll(checkDateLiterals(formStartYear, formEndYear, startPrecision, endPrecision));
} else if (formStartYear != null && existingEndYear != null) {
errors.putAll(checkDateLiterals(formStartYear, existingEndYear));
errors.putAll(checkDateLiterals(formStartYear, existingEndYear, startPrecision, endPrecision));
} else if (existingStartYear != null && formEndYear != null) {
errors.putAll(checkDateLiterals(existingStartYear, formEndYear));
errors.putAll(checkDateLiterals(existingStartYear, formEndYear, startPrecision, endPrecision));
} else if (existingStartYear != null && existingEndYear != null) {
errors.putAll(checkDateLiterals(existingStartYear, existingEndYear));
errors.putAll(checkDateLiterals(existingStartYear, existingEndYear, startPrecision, endPrecision));
}
if (errors.size() != 0)
@ -56,8 +73,41 @@ public class DateTimeIntervalValidation implements N3Validator {
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>();
if( endPrecision == null ){
//there is no end date, nothing to check
return errors;
}
try{
XSDDateTime startDate = (XSDDateTime)startLit.getValue();
XSDDateTime endDate = (XSDDateTime)endLit.getValue();
@ -65,9 +115,16 @@ public class DateTimeIntervalValidation implements N3Validator {
Calendar startCal = startDate.asCalendar();
Calendar endCal = endDate.asCalendar();
if( endCal != null && ! endCal.after( startCal ) ){
errors.put(startFieldName, "Start year must be before end year");
errors.put(endFieldName, "End year must be after start year");
if( endCal != null ){
if( !startCal.before( endCal ) ){
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){
@ -79,4 +136,16 @@ public class DateTimeIntervalValidation implements N3Validator {
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) {
// log.error("Error in updatePropertyDateTimeValue");
// log.error(e);
// log.error(e, e);
// }
// }
//

View file

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

View file

@ -11,7 +11,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
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.jena.WebappDaoFactoryJena;
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 {
@ -188,13 +182,11 @@ public class SelectListGenerator {
if( stmts == null ) log.error("object properties for subject were null in SelectListGenerator.getOptions()");
individuals = removeIndividualsAlreadyInRange(individuals,stmts,predicateUri,editConfig.getObject());
//Collections.sort(individuals,new compareIndividualsByName());
ProhibitedFromSearch pfs = editConfig.getProhibitedFromSearch();
//Collections.sort(individuals,new compareIndividualsByName());
for( Individual ind : individuals ){
String uri = ind.getURI();
if( uri != null && (pfs == null || !ind.isMemberOfClassProhibitedFromSearch(pfs)) ){
if( uri != null ){
optionsMap.put(uri,ind.getName().trim());
++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");
optionsMap.put("", "No " + vclass.getName() + " found");
}else{
ProhibitedFromSearch pfs = editConfig.getProhibitedFromSearch();
for( Individual ind : individuals ) {
String uri = ind.getURI();
if( uri != null && (pfs == null || !ind.isMemberOfClassProhibitedFromSearch(pfs)) ) {
if( uri != null ) {
optionsMap.put(uri,ind.getName().trim());
++optionsCount;
}

View file

@ -7,8 +7,12 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -40,30 +44,26 @@ public class FileStorageAliasAdder {
/**
* 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"
+ "SELECT ?bs\n"
+ "WHERE {\n"
+ "SELECT ?bs\n" + "WHERE {\n"
+ " ?bs rdf:type public:FileByteStream\n"
+ " OPTIONAL { ?bs public:directDownloadUrl ?alias }\n"
+ " FILTER ( !BOUND(?alias) )\n" + "}\n";
/**
* Query: get all bytestream resources that do not have alias URLs. Get
* their filenames from their surrogates also.
* Query: get the filenames for all bytestream resources that do not have
* 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"
+ "SELECT ?bs ?f ?fn\n"
+ "WHERE {\n"
+ "SELECT ?bs ?fn\n" + "WHERE {\n"
+ " ?bs rdf:type public:FileByteStream . \n"
+ " ?f public:downloadLocation ?bs . \n"
+ " OPTIONAL { \n"
+ " ?f public:filename ?fn . \n"
+ " }\n"
+ " OPTIONAL { \n"
+ " ?bs public:directDownloadUrl ?alias . \n"
+ " }\n"
+ " ?f public:filename ?fn . \n"
+ " OPTIONAL { ?bs public:directDownloadUrl ?alias . }\n"
+ " FILTER ( !BOUND(?alias) )\n" + "}\n";
private final Model model;
@ -72,6 +72,9 @@ public class FileStorageAliasAdder {
private FSULog updateLog;
private Set<String> bytestreamUrisWithoutAliases;
private Map<String, String> bytestreamUrisAndFilenames;
public FileStorageAliasAdder(Model model, File uploadDirectory,
String vivoDefaultNamespace) {
this.model = model;
@ -120,7 +123,7 @@ public class FileStorageAliasAdder {
* URL, we have work to do.
*/
private boolean isThereAnythingToDo() {
String queryString = QUERY_WORK_TO_DO;
String queryString = QUERY_BYTESTREAMS_WITHOUT_ALIASES;
log.debug("query: " + queryString);
QueryExecution qexec = null;
@ -165,31 +168,104 @@ public class FileStorageAliasAdder {
* Add an alias URL to any FileByteStream object that doesn't have one.
*/
private void findAndAddMissingAliasUrls() {
List<BytestreamInfo> list;
list = findBytestreamsWithMissingValues();
addMissingValuesToModel(list);
findBytestreamsWithoutAliasUrls();
findFilenamesForBytestreams();
addAliasUrlsToModel();
}
/**
* Find every bytestream that doesn't have an alias URL. Find the filename
* for the bytestream also.
* Find every bytestream that doesn't have an alias URL.
*/
private List<BytestreamInfo> findBytestreamsWithMissingValues() {
List<BytestreamInfo> list = new ArrayList<BytestreamInfo>();
String queryString = QUERY_MORE_INFO;
private void findBytestreamsWithoutAliasUrls() {
BytestreamUriUnpacker unpacker = new BytestreamUriUnpacker();
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);
QueryExecution qexec = null;
try {
qexec = createQueryExecutor(queryString);
Iterator<?> results = qexec.execSelect();
Iterator<QuerySolution> results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution result = (QuerySolution) results.next();
BytestreamInfo bs = captureQueryResult(result);
if (bs != null) {
list.add(bs);
QuerySolution result = results.next();
if (log.isDebugEnabled()) {
log.debug("Query result variables: "
+ listVariables(result));
}
unpacker.unpack(result);
}
} catch (Exception e) {
log.error(e, e);
@ -198,76 +274,6 @@ public class FileStorageAliasAdder {
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) {
@ -276,7 +282,6 @@ public class FileStorageAliasAdder {
}
/** For debug logging. */
@SuppressWarnings("unchecked")
private List<String> listVariables(QuerySolution result) {
List<String> list = new ArrayList<String>();
for (Iterator<String> names = result.varNames(); names.hasNext();) {
@ -287,13 +292,61 @@ public class FileStorageAliasAdder {
return list;
}
private static class BytestreamInfo {
final String uri;
final String filename;
// ----------------------------------------------------------------------
// Helper classes
// ----------------------------------------------------------------------
BytestreamInfo(String uri, String filename) {
this.uri = uri;
this.filename = filename;
private interface QueryResultUnpacker {
public abstract void unpack(QuerySolution result);
}
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