From f70aad23f60a079c343617f43b4de5c2851da2b8 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Sat, 15 Jan 2011 05:28:58 +0000 Subject: [PATCH 001/374] Record only merge of r7041 from nihvivo-rel-1.2-maint From c2e69fe9e19196c0cdded835e331d8ec09467f37 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Sat, 15 Jan 2011 22:26:37 +0000 Subject: [PATCH 002/374] Record-only merge of r7044 from nihvivo-rel-1.2-maint From c6afc196c896e8910aa5ed09266a37ae7292f402 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Sun, 16 Jan 2011 14:30:25 +0000 Subject: [PATCH 003/374] Merge r7047-7048 from nihvivo-rel-1.2-maint --- .../freemarker/IndividualController.java | 107 ++++++++++-------- .../controller/freemarker/UrlBuilder.java | 23 +++- .../vitro/webapp/dao/ApplicationDao.java | 2 + .../webapp/dao/jena/ApplicationDaoJena.java | 5 + .../individual/IndividualTemplateModel.java | 50 +++++--- .../ObjectPropertyTemplateModel.java | 2 +- 6 files changed, 119 insertions(+), 70 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java index 77ffc1a20..e3b8d6f85 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java @@ -92,7 +92,7 @@ public class IndividualController extends FreemarkerHttpServlet { String url = vreq.getRequestURI().substring(vreq.getContextPath().length()); // Check to see if the request is for a non-information resource, redirect if it is. - String redirectURL = checkForRedirect ( url, vreq.getHeader("accept") ); + String redirectURL = checkForRedirect ( url, vreq ); if( redirectURL != null ){ return new RedirectResponseValues(redirectURL); } @@ -108,7 +108,7 @@ public class IndividualController extends FreemarkerHttpServlet { return doNotFound(vreq); } - ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept")); + ContentType rdfFormat = checkForLinkedDataRequest(url, vreq); if( rdfFormat != null ){ return doRdf(vreq, individual, rdfFormat); } @@ -184,7 +184,7 @@ public class IndividualController extends FreemarkerHttpServlet { private String getRdfLinkTag(IndividualTemplateModel itm) { String linkTag = null; - String linkedDataUrl = itm.getLinkedDataUrl(); + String linkedDataUrl = itm.getRdfUrl(false); if (linkedDataUrl != null) { linkTag = " "; @@ -200,10 +200,7 @@ public class IndividualController extends FreemarkerHttpServlet { individual.setKeywords(iwDao.getKeywordsForIndividualByMode(individual.getURI(),"visible")); individual.sortForDisplay(); - //setup highlighter for search terms - //checkForSearch(vreq, individual); - - return new IndividualTemplateModel(individual, vreq, LoginStatusBean.getBean(vreq)); + return new IndividualTemplateModel(individual, vreq); } // Determine whether the individual has a custom display template based on its class membership. @@ -387,10 +384,10 @@ public class IndividualController extends FreemarkerHttpServlet { //Redirect if the request is for http://hostname/individual/localname // if accept is nothing or text/html redirect to ??? // if accept is some RDF thing redirect to the URL for RDF - private String checkForRedirect(String url, String acceptHeader) { + private String checkForRedirect(String url, VitroRequest vreq) { Matcher m = URI_PATTERN.matcher(url); if( m.matches() && m.groupCount() == 1 ){ - ContentType c = checkForLinkedDataRequest(url, acceptHeader); + ContentType c = checkForLinkedDataRequest(url, vreq); if( c != null ){ String redirectUrl = "/individual/" + m.group(1) + "/" + m.group(1) ; if( RDFXML_MIMETYPE.equals( c.getMediaType()) ){ @@ -413,13 +410,37 @@ public class IndividualController extends FreemarkerHttpServlet { private static Pattern TTL_REQUEST = Pattern.compile("^/individual/([^/]*)/\\1.ttl$"); private static Pattern HTML_REQUEST = Pattern.compile("^/display/([^/]*)$"); + public static final Pattern RDFXML_FORMAT = Pattern.compile("rdfxml"); + public static final Pattern N3_FORMAT = Pattern.compile("n3"); + public static final Pattern TTL_FORMAT = Pattern.compile("ttl"); + /** * @return null if this is not a linked data request, returns content type if it is a * linked data request. */ - protected ContentType checkForLinkedDataRequest(String url, String acceptHeader) { + protected ContentType checkForLinkedDataRequest(String url, VitroRequest vreq ) { try { - //check the accept header + ContentType contentType = null; + Matcher m; + // Check for url param specifying format + String formatParam = (String) vreq.getParameter("format"); + if (formatParam != null) { + m = RDFXML_FORMAT.matcher(formatParam); + if ( m.matches() ) { + return new ContentType(RDFXML_MIMETYPE); + } + m = N3_FORMAT.matcher(formatParam); + if( m.matches() ) { + return new ContentType(N3_MIMETYPE); + } + m = TTL_FORMAT.matcher(formatParam); + if( m.matches() ) { + return new ContentType(TTL_MIMETYPE); + } + } + + //check the accept header + String acceptHeader = vreq.getHeader("accept"); if (acceptHeader != null) { List actualContentTypes = new ArrayList(); actualContentTypes.add(new ContentType( XHTML_MIMETYPE )); @@ -428,14 +449,13 @@ public class IndividualController extends FreemarkerHttpServlet { actualContentTypes.add(new ContentType( RDFXML_MIMETYPE )); actualContentTypes.add(new ContentType( N3_MIMETYPE )); actualContentTypes.add(new ContentType( TTL_MIMETYPE )); - - - ContentType best = ContentType.getBestContentType(acceptHeader,actualContentTypes); - if (best!=null && ( - RDFXML_MIMETYPE.equals(best.getMediaType()) || - N3_MIMETYPE.equals(best.getMediaType()) || - TTL_MIMETYPE.equals(best.getMediaType()) )) - return best; + + contentType = ContentType.getBestContentType(acceptHeader,actualContentTypes); + if (contentType!=null && ( + RDFXML_MIMETYPE.equals(contentType.getMediaType()) || + N3_MIMETYPE.equals(contentType.getMediaType()) || + TTL_MIMETYPE.equals(contentType.getMediaType()) )) + return contentType; } /* @@ -444,22 +464,30 @@ public class IndividualController extends FreemarkerHttpServlet { http://vivo.cornell.edu/individual/n23/n23.n3 http://vivo.cornell.edu/individual/n23/n23.ttl */ - - Matcher m = RDF_REQUEST.matcher(url); - if( m.matches() ) - return new ContentType(RDFXML_MIMETYPE); - m = N3_REQUEST.matcher(url); - if( m.matches() ) - return new ContentType(N3_MIMETYPE); - m = TTL_REQUEST.matcher(url); - if( m.matches() ) - return new ContentType(TTL_MIMETYPE); + m = RDF_REQUEST.matcher(url); + if( m.matches() ) { + return new ContentType(RDFXML_MIMETYPE); + } + m = N3_REQUEST.matcher(url); + if( m.matches() ) { + return new ContentType(N3_MIMETYPE); + } + m = TTL_REQUEST.matcher(url); + if( m.matches() ) { + return new ContentType(TTL_MIMETYPE); + } + } catch (Throwable th) { log.error("problem while checking accept header " , th); } return null; } + + private ContentType getContentTypeFromString(String string) { + + return null; + } @SuppressWarnings("unused") private boolean checkForSunset(VitroRequest vreq, Individual entity) { @@ -540,27 +568,6 @@ public class IndividualController extends FreemarkerHttpServlet { return newModel; } - - - private void checkForSearch(HttpServletRequest req, Individual ent) { - if (req.getSession().getAttribute("LastQuery") != null) { - VitroQueryWrapper qWrap = (VitroQueryWrapper) req.getSession() - .getAttribute("LastQuery"); - if (qWrap.getRequestCount() > 0 && qWrap.getQuery() != null) { - VitroQuery query = qWrap.getQuery(); - - //set query text so we can get it in JSP - req.setAttribute("querytext", query.getTerms()); - - //setup highlighting for output - StringProcessorTag.putStringProcessorInRequest(req, qWrap.getHighlighter()); - - qWrap.setRequestCount(qWrap.getRequestCount() - 1); - } else { - req.getSession().removeAttribute("LastQuery"); - } - } - } private Pattern badrequest= Pattern.compile(".*([&\\?=]|\\.\\.).*"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/UrlBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/UrlBuilder.java index ff1657046..30ceef439 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/UrlBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/UrlBuilder.java @@ -234,12 +234,24 @@ public class UrlBuilder { } public static String getPath(String path, ParamMap params) { - String glue = "?"; - for (String key : params.keySet()) { - path += glue + key + "=" + urlEncode(params.get(key)); + return addParams(path, params, "?"); + } + + private static String addParams(String url, ParamMap params, String glue) { + for (String key: params.keySet()) { + url += glue + key + "=" + urlEncode(params.get(key)); glue = "&"; } - return path; + return url; + } + + public static String addParams(String url, ParamMap params) { + String glue = url.contains("?") ? "&" : "?"; + return addParams(url, params, glue); + } + + public static String addParams(String url, String...params) { + return addParams(url, new ParamMap(params)); } public static String getPath(Route route, ParamMap params) { @@ -267,8 +279,7 @@ public class UrlBuilder { if (defaultNamespace.equals(namespace)) { profileUrl = getUrl(Route.INDIVIDUAL.path() + "/" + localName); } else { - List externallyLinkedNamespaces = wadf.getApplicationDao().getExternallyLinkedNamespaces(); - if (externallyLinkedNamespaces.contains(namespace)) { + if (wadf.getApplicationDao().isExternallyLinkedNamespace(namespace)) { log.debug("Found externally linked namespace " + namespace); profileUrl = namespace + "/" + localName; } else { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java index 6ccd29b4f..729865d2e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java @@ -12,4 +12,6 @@ public interface ApplicationDao { public List getExternallyLinkedNamespaces(); + public boolean isExternallyLinkedNamespace(String namespace); + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java index 1b89dbc96..418240732 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java @@ -80,6 +80,11 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao { return externallyLinkedNamespaces; } + public boolean isExternallyLinkedNamespace(String namespace) { + List namespaces = getExternallyLinkedNamespaces(); + return namespaces.contains(namespace); + } + private class ExternalNamespacesChangeListener extends StatementListener { @Override diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java index df3be635d..a9ae7cdb1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java @@ -2,15 +2,16 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.openrdf.model.URI; +import org.openrdf.model.impl.URIImpl; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.Link; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route; @@ -31,10 +32,10 @@ public class IndividualTemplateModel extends BaseTemplateModel { protected LoginStatusBean loginStatusBean = null; private EditingPolicyHelper policyHelper = null; - public IndividualTemplateModel(Individual individual, VitroRequest vreq, LoginStatusBean loginStatusBean) { + public IndividualTemplateModel(Individual individual, VitroRequest vreq) { this.individual = individual; this.vreq = vreq; - this.loginStatusBean = loginStatusBean; + this.loginStatusBean = LoginStatusBean.getBean(vreq); // Needed for getting portal-sensitive urls. Remove if multi-portal support is removed. this.urlBuilder = new UrlBuilder(vreq.getPortal()); @@ -80,16 +81,39 @@ public class IndividualTemplateModel extends BaseTemplateModel { return thumbUrl == null ? null : getUrl(thumbUrl); } - public String getLinkedDataUrl() { - String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace(); - String uri = getUri(); - return uri.startsWith(defaultNamespace) ? uri + "/" + getLocalName() + ".rdf" : null; + public String getRdfUrl() { + return getRdfUrl(true); } - // RY Used for the rdf link on the individual page. Is it correct that this is not the same - // as getLinkedDataUrl()? - public String getRdfUrl() { - return getProfileUrl() + "/" + getLocalName() + ".rdf"; + // Used to create a link to generate the individual's rdf. + public String getRdfUrl(boolean checkExternalNamespaces) { + + String individualUri = getUri(); + String profileUrl = getProfileUrl(); + + URI uri = new URIImpl(individualUri); + String namespace = uri.getNamespace(); + + // Individuals in the default namespace + // e.g., http://vivo.cornell.edu/individual/n2345/n2345.rdf + // where default namespace = http://vivo.cornell.edu/individual/ + String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace(); + if (defaultNamespace.equals(namespace)) { + return profileUrl + "/" + getLocalName() + ".rdf"; + } + + // An RDF url is not defined for an externally linked namespace. The data does not reside + // in the current system, and the external system may not accept a request for rdf. + if (checkExternalNamespaces && vreq.getWebappDaoFactory() + .getApplicationDao() + .isExternallyLinkedNamespace(namespace)) { + return null; + } + + // http://some.other.namespace/n2345?format=rdfxml + // ** RY Not sure it is correct to return this for the element + return UrlBuilder.addParams(profileUrl, "format", "rdfxml"); + } public String getEditUrl() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java index 750e93d11..8147cc6c0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java @@ -141,7 +141,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel try { return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper); } catch (InvalidConfigurationException e) { - log.warn(e); + log.warn(e.getMessage()); return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper); } } else { From 3a5a01ee5799be1f8826c5fe801c9498ab9d4eb5 Mon Sep 17 00:00:00 2001 From: nac26 Date: Sun, 16 Jan 2011 19:26:15 +0000 Subject: [PATCH 004/374] NIHVIVO-1458 Login form is hidden once again if JavaScript is disabled. Autofocus on login form also makes a triumphant return. --- webapp/web/js/login/loginUtils.js | 2 +- .../freemarker/widgets/widget-login.ftl | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/webapp/web/js/login/loginUtils.js b/webapp/web/js/login/loginUtils.js index 1c46d8d7b..9fa54dee2 100644 --- a/webapp/web/js/login/loginUtils.js +++ b/webapp/web/js/login/loginUtils.js @@ -3,7 +3,7 @@ $(document).ready(function(){ // login form is hidden by default; use JavaScript to reveal - $("#loginFormAndLinks").show(); + $("#login").removeClass('hidden'); // focus on email or newpassword field $('.focus').focus(); diff --git a/webapp/web/templates/freemarker/widgets/widget-login.ftl b/webapp/web/templates/freemarker/widgets/widget-login.ftl index 3941f3a39..5e6ee2c13 100644 --- a/webapp/web/templates/freemarker/widgets/widget-login.ftl +++ b/webapp/web/templates/freemarker/widgets/widget-login.ftl @@ -13,16 +13,15 @@ <#macro loginForm> + -
+ <#else> ${noDataNotification} From df9b1cb99d4cf87b87b8d74e7670d88fb135495e Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Feb 2011 16:21:09 +0000 Subject: [PATCH 274/374] Don't show moniker span if there's no moniker --- .../web/templates/freemarker/body/individualList.ftl | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/webapp/web/templates/freemarker/body/individualList.ftl b/webapp/web/templates/freemarker/body/individualList.ftl index 9bebae9f4..1603c7656 100644 --- a/webapp/web/templates/freemarker/body/individualList.ftl +++ b/webapp/web/templates/freemarker/body/individualList.ftl @@ -35,18 +35,14 @@ ${stylesheets.add("/css/browseIndex.css")}
    <#list individuals as individual>
  • - <#-- The old JSP version uses a custom search view if one is defined, but it doesn't make sense - to do that in the current system, because we don't use the default search view. We could define - a custom list or use the custom short view, but for now just hard-code the view here; it will not be - customizable. - <#include "${individual.searchView}"> --> - ${individual.name}<#if individual.moniker??> ${individual.moniker} + <#assign moniker = individual.moniker!""> + ${individual.name}<#if moniker?has_content> ${moniker} <#if individual.links?has_content>
      <@l.firstLastList> <#list individual.links as link> <#if link?? && link.url?? && link.anchor?? > -
    • ${link.anchor}
    • +
    • ${link.anchor}
    • From dad29a5516109b0b2b1f9204a4cf0674d3e5c9b4 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Feb 2011 17:53:37 +0000 Subject: [PATCH 275/374] NIHVIVO-1557 Fix firstLastList macro so it works with li elements that have class or other attributes --- .../web/templates/freemarker/lib/lib-list.ftl | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/webapp/web/templates/freemarker/lib/lib-list.ftl b/webapp/web/templates/freemarker/lib/lib-list.ftl index 6570164a1..55c89aa27 100644 --- a/webapp/web/templates/freemarker/lib/lib-list.ftl +++ b/webapp/web/templates/freemarker/lib/lib-list.ftl @@ -32,11 +32,11 @@ --> <#macro firstLastList> - <#assign text> + <#local text> <#nested> - + - <@processListItems text?matches("
    • .*?
    • ", "s") /> + <@processListItems text?matches("", "s") /> <#----------------------------------------------------------------------------> @@ -94,13 +94,13 @@ RY Consider rewriting in Java. Probably designers won't want to modify this. --> <#macro firstLastListNested delim=","> - <#assign text> + <#local text> <#nested> - + <#-- Strip out a list-final delimiter, else (unlike most languages) it results in an empty final array item. --> - <#assign text = text?replace("${delim}\\s*$", "", "r")> + <#local text = text?replace("${delim}\\s*$", "", "r")> <@processListItems text?split(delim) /> @@ -121,29 +121,29 @@ <#list items as item> <#-- A FreeMarker loop variable cannot have its value modified, so we use a new variable. --> - <#assign newItem = item?trim> + <#local newItem = item?trim> - <#assign classVal = ""> + <#local classVal = ""> <#-- Keep any class value already assigned --> - <#assign currentClass = newItem?matches("^
    • ]*(class=[\'\"](.*?)[\'\"])")> + <#local currentClass = newItem?matches("^
    • ]*(class=[\'\"](.*?)[\'\"])")> <#list currentClass as m> - ${m?groups[2]}
      - <#assign classVal = m?groups[2]> - <#assign newItem = newItem?replace(m?groups[1], "")> + <#local classVal = m?groups[2]> <#-- get the assigned class value --> + <#local newItem = newItem?replace(m?groups[1], "")> <#-- remove 'class="xyz"' --> <#if item_index == 0> - <#assign classVal = "${classVal} first"> + <#local classVal = "${classVal} first"> - <#if !item_has_next> - <#assign classVal = "${classVal} last"> + <#if ! item_has_next> + <#local classVal = "${classVal} last"> - <#if classVal != ""> - <#assign classVal = classVal?replace("^ ", "", "r")> + <#local classVal = classVal?trim> + + <#if classVal?has_content> <#-- Replace first instance only, in case the item contains nested li tags. --> - <#assign newItem = newItem?replace(" + <#local newItem = newItem?replace(" ${newItem} From 0c6aa67e06f022bf06a637cc64fcd0c7085ee92e Mon Sep 17 00:00:00 2001 From: bdc34 Date: Fri, 4 Feb 2011 18:05:31 +0000 Subject: [PATCH 276/374] Changing getAllPossibleDataPropsForIndividual to only call getVClasses once. NIHVIVO-2002 --- .../webapp/dao/jena/DataPropertyDaoJena.java | 122 ++++++++++-------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java index 201261a5b..73b29b53c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java @@ -418,9 +418,10 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements public Collection getAllPossibleDatapropsForIndividual(String individualURI) { Individual ind = getWebappDaoFactory().getIndividualDao().getIndividualByURI(individualURI); Collection dpColl = new ArrayList(); + List vclassURIs = getVClassURIs(ind); + try { - for (VClass currClass : ind.getVClasses(true)) { - + for (VClass currClass : ind.getVClasses( DIRECT )) { List currList = getDatapropsForClass(currClass.getURI()); for (Iterator dpIter = currList.iterator(); dpIter.hasNext();) { DataProperty dp = (DataProperty) dpIter.next(); @@ -444,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) { @@ -466,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 vclassURIs = null; - if (reasoningAvailable()) { - vclassURIs = new ArrayList(); - 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 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 equivOrSubResources = new ArrayList(); - 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 vclassURIs) { + OntModel ontModel = getOntModelSelector().getFullModel(); + String datatypeURI = dataprop.getRangeDatatypeURI(); + + ontModel.enterCriticalSection(Lock.READ); + try { + // get universal restrictions applicable to data property + Iterator 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 equivOrSubResources = new ArrayList(); + 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 getVClassURIs(Individual individual){ + List vclassURIs = null; + if (reasoningAvailable()) { + vclassURIs = new ArrayList(); + for (VClass vc : individual.getVClasses(INDIRECT)) { + if (vc.getURI() != null) { + vclassURIs.add(vc.getURI()); + } + } + } else { + vclassURIs = getSupertypeURIs(individual); + } + return vclassURIs; } private boolean DIRECT = true; From 1851872eb041d500ce72fc2de565bfe1d6147003 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Feb 2011 18:38:29 +0000 Subject: [PATCH 277/374] NIHVIVO-1557 improvement to regex in firstLastList macro --- webapp/web/templates/freemarker/lib/lib-list.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/web/templates/freemarker/lib/lib-list.ftl b/webapp/web/templates/freemarker/lib/lib-list.ftl index 55c89aa27..205a4982d 100644 --- a/webapp/web/templates/freemarker/lib/lib-list.ftl +++ b/webapp/web/templates/freemarker/lib/lib-list.ftl @@ -126,9 +126,9 @@ <#local classVal = ""> <#-- Keep any class value already assigned --> - <#local currentClass = newItem?matches("^
    • ]*(class=[\'\"](.*?)[\'\"])")> + <#local currentClass = newItem?matches("^
    • ]*(class=([\'\"])(.*?)\\2)")> <#list currentClass as m> - <#local classVal = m?groups[2]> <#-- get the assigned class value --> + <#local classVal = m?groups[3]> <#-- get the assigned class value --> <#local newItem = newItem?replace(m?groups[1], "")> <#-- remove 'class="xyz"' --> From cbfa225c31b1f16597d6aa18ec40b72efc8ecc06 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Feb 2011 18:49:25 +0000 Subject: [PATCH 278/374] NIHVIVO-1557 improvement to regex in firstLastList macro --- webapp/web/templates/freemarker/lib/lib-list.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/web/templates/freemarker/lib/lib-list.ftl b/webapp/web/templates/freemarker/lib/lib-list.ftl index 205a4982d..4f6fe30ac 100644 --- a/webapp/web/templates/freemarker/lib/lib-list.ftl +++ b/webapp/web/templates/freemarker/lib/lib-list.ftl @@ -126,8 +126,8 @@ <#local classVal = ""> <#-- Keep any class value already assigned --> - <#local currentClass = newItem?matches("^
    • ]*(class=([\'\"])(.*?)\\2)")> - <#list currentClass as m> + <#local classMatch = newItem?matches("^
    • ]*(class=([\'\"])(.*?)\\2)")> + <#list classMatch as m> <#local classVal = m?groups[3]> <#-- get the assigned class value --> <#local newItem = newItem?replace(m?groups[1], "")> <#-- remove 'class="xyz"' --> From b8fec2e96c157acbf26b7828c336dfb47dd5d7fb Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Feb 2011 19:17:44 +0000 Subject: [PATCH 279/374] NIHVIVO-2038 Improve performance of creating grouped property list by keeping a list of object property uris to check against, so a property doesn't have to be instantiated from the propertyUri in order to check whether it's on the list. --- .../individual/GroupedPropertyList.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java index ebf339280..57a74d549 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -141,14 +141,23 @@ public class GroupedPropertyList extends BaseTemplateModel { } private void mergeAllPossibleObjectProperties(List objectPropertyList, List propertyList) { + + // Performance improvement: keep a list of uris on the propertyList to check against, rather than + // having to instantiate a property from propertyUri to check against the propertyList. + List propertyListUris = new ArrayList(propertyList.size()); + for (Property p : propertyList) { + propertyListUris.add(p.getURI()); + } + PropertyInstanceDao piDao = wdf.getPropertyInstanceDao(); Collection allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI()); + if (allPropInstColl != null) { ObjectPropertyDao opDao = wdf.getObjectPropertyDao(); for (PropertyInstance pi : allPropInstColl) { if (pi != null) { if (! alreadyOnObjectPropertyList(objectPropertyList, pi)) { - addIfNotAlreadyOnList(propertyList, pi.getPropertyURI(), opDao); + addIfNotAlreadyOnList(propertyList, propertyListUris, pi.getPropertyURI(), opDao); } } else { log.error("a property instance in the Collection created by PropertyInstanceDao.getAllPossiblePropInstForIndividual() is unexpectedly null"); @@ -158,23 +167,26 @@ public class GroupedPropertyList extends BaseTemplateModel { // In future, vitro ns props will be phased out. Vitro public properties should be changed so they do no // constitute a special case. for (String propertyUri : VITRO_PROPS_TO_ADD_TO_LIST) { - addIfNotAlreadyOnList(propertyList, propertyUri, opDao); + addIfNotAlreadyOnList(propertyList, propertyListUris, propertyUri, opDao); } } else { log.error("a null Collection is returned from PropertyInstanceDao.getAllPossiblePropInstForIndividual()"); } } - private void addIfNotAlreadyOnList(List propertyList, String propertyUri, ObjectPropertyDao opDao) { + private void addIfNotAlreadyOnList(List propertyList, List propertyListUris, String propertyUri, ObjectPropertyDao opDao) { - ObjectProperty op = opDao.getObjectPropertyByURI(propertyUri); - if (op == null) { - log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI()"); - } else if (op.getURI() == null) { - log.error("ObjectProperty op returned with null propertyURI from opDao.getObjectPropertyByURI()"); - } else if (! alreadyOnPropertyList(propertyList, op)) { - propertyList.add(op); - } + if ( ! propertyListUris.contains(propertyUri)) { + ObjectProperty op = opDao.getObjectPropertyByURI(propertyUri); + if (op == null) { + log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI()"); + } else if (op.getURI() == null) { + log.error("ObjectProperty op returned with null propertyURI from opDao.getObjectPropertyByURI()"); + } else { + propertyList.add(op); + propertyListUris.add(propertyUri); + } + } } protected void mergeAllPossibleDataProperties(List propertyList) { @@ -186,7 +198,6 @@ public class GroupedPropertyList extends BaseTemplateModel { if (dp.getURI() == null) { log.error("DataProperty dp returned with null propertyURI from dpDao.getAllPossibleDatapropsForIndividual()"); } else if (! alreadyOnPropertyList(propertyList, dp)) { - //dp.setLabel(dp.getPublicName()); propertyList.add(dp); } } else { From 40264e0c0b020624e2e2309b91fd317e39e4aeef Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Feb 2011 19:21:29 +0000 Subject: [PATCH 280/374] NIHVIVO-2042 Show heading "Primary Web Page" on vitro:primaryLink only if editing --- .../freemarker/body/partials/individual/lib-properties.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl b/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl index 6911f0c10..ced1886b2 100644 --- a/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl +++ b/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl @@ -148,7 +148,7 @@ name will be used as the label. -->