From 1b75b2a93fbe3f8b9efe21738207270cf1aad37a Mon Sep 17 00:00:00 2001 From: tworrall Date: Wed, 1 Aug 2012 14:07:08 +0000 Subject: [PATCH] merging r9990 into the trunk --- webapp/config/default.log4j.properties | 1 + .../individual/IndividualResponseBuilder.java | 33 +++++++++++++++++-- .../individual/individual-properties.ftl | 22 +++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/webapp/config/default.log4j.properties b/webapp/config/default.log4j.properties index d3ad4f5e7..5dd5339b1 100644 --- a/webapp/config/default.log4j.properties +++ b/webapp/config/default.log4j.properties @@ -38,6 +38,7 @@ log4j.logger.edu.cornell.mannlib.vitro.webapp.startup.StartupStatus=WARN log4j.logger.edu.cornell.mannlib.vitro.webapp.controller.freemarker.BrowseController=WARN log4j.logger.edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener=WARN log4j.logger.edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator=WARN +log4j.logger.edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase=DEBUG # Spring as a whole is too chatty to display INFO messages. log4j.logger.org.springframework=WARN diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java index d7d4699b7..8a8dc0569 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java @@ -87,9 +87,14 @@ class IndividualResponseBuilder { * into the data model: no real data can be modified. */ // body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE)); + if ( itm.person() ) { + body.put("publicationCount", getPublicationCount(itm.getUri(), vreq)); + body.put("grantCount", getGrantCount(itm.getUri(), vreq)); + } + if ( itm.organization() ) { + body.put("peopleCount", getPeopleCount(itm.getUri(), vreq)); + } body.put("labelCount", getLabelCount(itm.getUri(), vreq)); - body.put("publicationCount", getPublicationCount(itm.getUri(), vreq)); - body.put("grantCount", getGrantCount(itm.getUri(), vreq)); body.put("individual", wrap(itm, new ReadOnlyBeansWrapper())); body.put("headContent", getRdfLinkTag(itm)); @@ -264,6 +269,12 @@ class IndividualResponseBuilder { + " { ?subject core:hasResearcherRole ?role } \n" + "}" ; + private static String PEOPLE_COUNT_QUERY = "" + + "PREFIX core: \n" + + "SELECT ( str(COUNT(?position)) AS ?positionCount ) WHERE { \n" + + " ?subject core:organizationForPosition ?position \n" + + "}" ; + private static Integer getLabelCount(String subjectUri, VitroRequest vreq) { String queryStr = QueryUtils.subUriForQueryVar(LABEL_COUNT_QUERY, "subject", subjectUri); @@ -315,4 +326,22 @@ class IndividualResponseBuilder { } return theCount; } + + private static Integer getPeopleCount(String subjectUri, VitroRequest vreq) { + + String queryStr = QueryUtils.subUriForQueryVar(PEOPLE_COUNT_QUERY, "subject", subjectUri); + log.debug("queryStr = " + queryStr); + int theCount = 0; + try { + ResultSet results = QueryUtils.getQueryResults(queryStr, vreq); + if (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + String countStr = soln.get("positionCount").toString(); + theCount = Integer.parseInt(countStr); + } + } catch (Exception e) { + log.error(e, e); + } + return theCount; + } } diff --git a/webapp/web/templates/freemarker/body/partials/individual/individual-properties.ftl b/webapp/web/templates/freemarker/body/partials/individual/individual-properties.ftl index 7722ee206..e31d92f22 100644 --- a/webapp/web/templates/freemarker/body/partials/individual/individual-properties.ftl +++ b/webapp/web/templates/freemarker/body/partials/individual/individual-properties.ftl @@ -25,21 +25,39 @@ <#-- List the properties in the group --> + <#assign pubCount = 0 > + <#assign researchCount = 0 > + <#assign peepsCount = 0 > + <#if publicationCount?? > + <#assign pubCount = publicationCount > + + <#if grantCount?? > + <#assign researchCount = grantCount > + + <#if peopleCount?? > + <#assign peepsCount = peopleCount > + <#list group.properties as property>
<#-- Property display name --> - <#if property.localName == "authorInAuthorship" && editable && (publicationCount > 0) > + <#if property.localName == "authorInAuthorship" && editable && (pubCount > 0) >

${property.name} <@p.addLink property editable /> <@p.verboseDisplay property /> style="padding-top:10px" > manage publications

- <#elseif property.localName == "hasResearcherRole" && editable && (grantCount > 0) > + <#elseif property.localName == "hasResearcherRole" && editable && (researchCount! > 0) >

${property.name} <@p.addLink property editable /> <@p.verboseDisplay property /> style="padding-top:10px" > manage grants & projects

+ <#elseif property.localName == "organizationForPosition" && editable && (peepsCount! > 0) > +

${property.name} <@p.addLink property editable /> <@p.verboseDisplay property /> + style="padding-top:10px" > + manage affiliated people + +

<#else>

${property.name} <@p.addLink property editable /> <@p.verboseDisplay property />