+
+
+

+
+
diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl
index dd88f20d..4a50cc05 100644
--- a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl
+++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnGrantsStandalone.ftl
@@ -23,7 +23,7 @@ var currentParameter = "${currentParameter}";
/*
This is used in util.js to print grant temporal graph links for all sub-organizations.
*/
-var subOrganizationTemporalGraphURL = "${subOrganizationGrantTemporalGraphCommonURL}";
+var temporalGraphCommonURL = subOrganizationGrantTemporalGraphCommonURL;
var temporalGraphDataURL = '${temporalGraphDataURL}';
@@ -50,7 +50,7 @@ $(document).ready(function () {
<#include "entityComparisonBody.ftl">
<#--
-Right now we include the error message by default becuae currently I could not devise any more smarted solution. By default
+Right now we include the error message by default because currently I could not devise any more smarted solution. By default
the CSS of the #error-container is display:none; so it will be hidden unless explicitly commanded to be shown which we do in
via JavaScript.
-->
diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl
index abd59d55..da47d15b 100644
--- a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl
+++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonOnPublicationsStandalone.ftl
@@ -23,7 +23,7 @@ var currentParameter = "${currentParameter}";
/*
This is used in util.js to print grant temporal graph links for all sub-organizations.
*/
-var subOrganizationTemporalGraphURL = "${subOrganizationPublicationTemporalGraphCommonURL}";
+var temporalGraphCommonURL = subOrganizationPublicationTemporalGraphCommonURL;
var temporalGraphDataURL = '${temporalGraphDataURL}';
@@ -50,7 +50,7 @@ $(document).ready(function () {
<#include "entityComparisonBody.ftl">
<#--
-Right now we include the error message by default becuae currently I could not devise any more smarted solution. By default
+Right now we include the error message by default because currently I could not devise any more smarted solution. By default
the CSS of the #error-container is display:none; so it will be hidden unless explicitly commanded to be shown which we do in
via JavaScript.
-->
diff --git a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl
index c8a46376..cb858d88 100644
--- a/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl
+++ b/productMods/templates/freemarker/visualization/entitycomparison/entityComparisonSetup.ftl
@@ -26,14 +26,18 @@
"pluralName": "publications",
"dropDownText": "by Publications",
"viewLink": "${organizationPublicationTemporalGraphURL}",
- "dataLink": "${organizationPublicationTemporalGraphDataURL}",
+ "viewBaseLink": "${subOrganizationPublicationTemporalGraphCommonURL}",
+ "dataLink": "${organizationPublicationTemporalGraphDataURL}",
+ "csvLink": "${temporalGraphDownloadCSVCommonURL}&vis=entity_comparison",
"value": "Publications" }>
<#assign grantParameter = { "name": "grant",
"pluralName": "grants",
"dropDownText": "by Grants",
- "viewLink": "${organizationGrantTemporalGraphURL}",
+ "viewLink": "${organizationGrantTemporalGraphURL}",
+ "viewBaseLink": "${subOrganizationGrantTemporalGraphCommonURL}",
"dataLink": "${organizationGrantTemporalGraphDataURL}",
+ "csvLink": "${temporalGraphDownloadCSVCommonURL}&vis=entity_grant_count",
"value": "Grants" }>
<#assign parameterOptions = [publicationParameter, grantParameter]>
@@ -86,6 +90,9 @@ var contextPath = "${urls.base}";
var temporalGraphSmallIcon = "${temporalGraphSmallIcon}";
var subOrganizationVivoProfileURL = "${subOrganizationVivoProfileURL}";
+var subOrganizationGrantTemporalGraphCommonURL = "${subOrganizationGrantTemporalGraphCommonURL}";
+var subOrganizationPublicationTemporalGraphCommonURL = "${subOrganizationPublicationTemporalGraphCommonURL}";
+
var jsonString = '${jsonContent!}';
var organizationLabel = '${organizationLabel}';
var organizationVIVOProfileURL = "${organizationVivoProfileURL}";
@@ -97,7 +104,7 @@ var entityCheckboxSelectorDOMClass = "${entityCheckboxSelectorDOMClass}";
var isDataRequestSentViaAJAX = false;
-var temporalGraphProcessor;
+var csvDownloadURL, temporalGraphProcessor;
/*
This has to be declared before making a call to GUI event manager JS.
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java
index ef1e37fb..9b98a9f0 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java
@@ -93,6 +93,12 @@ public class QueryFieldLabels {
public static final String SUBORGANIZATION_URL = "subOrganizationLit";
public static final String SUBORGANIZATION_LABEL = "subOrganizationLabelLit";
+ /*
+ * Parent Organization related field labels
+ */
+ public static final String PARENT_ORGANIZATION_URL = "parentOrganizationLit";
+ public static final String PARENT_ORGANIZATION_LABEL = "parentOrganizationLabelLit";
+
/*
* Sub Organization related field labels
*/
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java
index 44edd3cf..129d6a90 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityComparisonUtilityFunctions.java
@@ -172,11 +172,23 @@ public class EntityComparisonUtilityFunctions {
if (StringUtils.equalsIgnoreCase(entityA.getEntityURI(), entityB.getEntityURI())) {
- Entity mergedEntity = new Entity(entityA.getEntityURI(), entityA.getEntityLabel());
+ Entity mergedEntity = new Entity(entityA.getEntityURI());
+
+ if (StringUtils.isNotBlank(entityA.getEntityLabel())) {
+
+ mergedEntity.setEntityLabel(entityA.getEntityLabel());
+
+ } else if (StringUtils.isNotBlank(entityB.getEntityLabel())) {
+
+ mergedEntity.setEntityLabel(entityB.getEntityLabel());
+ }
mergedEntity.addSubEntitities(entityA.getSubEntities());
mergedEntity.addSubEntitities(entityB.getSubEntities());
+ mergedEntity.addParents(entityA.getParents());
+ mergedEntity.addParents(entityB.getParents());
+
return mergedEntity;
} else {
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java
index 5835a854..baf2fce5 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalGrantVisualizationRequestHandler.java
@@ -31,6 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Co
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubjectEntityJSON;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.SelectOnModelUtilities;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
@@ -221,7 +222,7 @@ public class TemporalGrantVisualizationRequestHandler implements
"application/octet-stream");
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
writeGrantsOverTimeJSON(vitroRequest,
- entity.getSubEntities()));
+ entity));
return fileData;
}
@@ -285,12 +286,12 @@ public class TemporalGrantVisualizationRequestHandler implements
* @param subOrganizationTypesResult
*/
private String writeGrantsOverTimeJSON(VitroRequest vreq,
- Set
subentities) {
+ Entity subjectEntity) {
Gson json = new Gson();
- Set subEntitiesJson = new HashSet();
+ Set jsonifiedResponse = new HashSet();
- for (SubEntity subentity : subentities) {
+ for (SubEntity subentity : subjectEntity.getSubEntities()) {
JsonObject entityJson = new JsonObject(
subentity.getIndividualLabel());
@@ -326,10 +327,17 @@ public class TemporalGrantVisualizationRequestHandler implements
entityJson.setVisMode("ORGANIZATION");
}
- subEntitiesJson.add(entityJson);
+ jsonifiedResponse.add(entityJson);
}
- return json.toJson(subEntitiesJson);
+
+ SubjectEntityJSON subjectEntityJSON = new SubjectEntityJSON(subjectEntity.getEntityLabel(),
+ subjectEntity.getEntityURI(),
+ subjectEntity.getParents());
+
+ jsonifiedResponse.add(subjectEntityJSON);
+
+ return json.toJson(jsonifiedResponse);
}
private String getEntityGrantsPerYearCSVContent(Entity entity) {
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalPublicationVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalPublicationVisualizationRequestHandler.java
index 8179fd46..9fd0f5e5 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalPublicationVisualizationRequestHandler.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/cached/TemporalPublicationVisualizationRequestHandler.java
@@ -29,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Ac
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.JsonObject;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubjectEntityJSON;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.SelectOnModelUtilities;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
@@ -88,7 +89,6 @@ public class TemporalPublicationVisualizationRequestHandler implements
Entity organizationWithAssociatedPeople = SelectOnModelUtilities
.getSubjectOrganizationAssociatedPeople(dataset, subjectEntityURI);
-
if (organizationWithAssociatedPeople.getSubEntities() != null) {
@@ -247,7 +247,7 @@ public class TemporalPublicationVisualizationRequestHandler implements
"application/octet-stream");
fileData.put(DataVisualizationController.FILE_CONTENT_KEY,
writePublicationsOverTimeJSON(vitroRequest,
- entity.getSubEntities()));
+ entity));
return fileData;
}
@@ -277,12 +277,12 @@ public class TemporalPublicationVisualizationRequestHandler implements
* @param subOrganizationTypesResult
*/
private String writePublicationsOverTimeJSON(VitroRequest vreq,
- Set subentities) {
+ Entity subjectEntity) {
Gson json = new Gson();
- Set subEntitiesJson = new HashSet();
+ Set subEntitiesJson = new HashSet();
- for (SubEntity subentity : subentities) {
+ for (SubEntity subentity : subjectEntity.getSubEntities()) {
JsonObject entityJson = new JsonObject(
subentity.getIndividualLabel());
@@ -320,6 +320,13 @@ public class TemporalPublicationVisualizationRequestHandler implements
subEntitiesJson.add(entityJson);
}
+
+ SubjectEntityJSON subjectEntityJSON = new SubjectEntityJSON(subjectEntity.getEntityLabel(),
+ subjectEntity.getEntityURI(),
+ subjectEntity.getParents());
+
+ subEntitiesJson.add(subjectEntityJSON);
+
return json.toJson(subEntitiesJson);
}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/ModelConstructorUtilities.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/ModelConstructorUtilities.java
index c169ad3a..39669842 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/ModelConstructorUtilities.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/ModelConstructorUtilities.java
@@ -17,6 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructo
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PeopleToPublicationsFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PersonToGrantsFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.PersonToPublicationsFactory;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory.SubOrganizationWithinModelFactory;
public class ModelConstructorUtilities {
@@ -30,6 +31,7 @@ public class ModelConstructorUtilities {
put(OrganizationToGrantsForSubOrganizationsModelConstructor.MODEL_TYPE, new OrganizationToGrantsForSubOrganizationsFactory());
put(OrganizationAssociatedPeopleModelWithTypesConstructor.MODEL_TYPE, new OrganizationAssociatedPeopleModelWithTypesFactory());
put(OrganizationModelWithTypesConstructor.MODEL_TYPE, new OrganizationModelWithTypesFactory());
+ put(SubOrganizationWithinModelConstructor.MODEL_TYPE, new SubOrganizationWithinModelFactory());
}};
public static Model getOrConstructModel(String uri, String modelType, Dataset dataset)
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/OrganizationModelWithTypesConstructor.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/OrganizationModelWithTypesConstructor.java
index d310bb7e..df624e90 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/OrganizationModelWithTypesConstructor.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/OrganizationModelWithTypesConstructor.java
@@ -70,8 +70,6 @@ public class OrganizationModelWithTypesConstructor implements ModelConstructor {
private Model executeQuery(String constructQuery) {
- System.out.println("in constructed model fior organization");
-
Model constructedModel = ModelFactory.createDefaultModel();
before = System.currentTimeMillis();
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/SubOrganizationWithinModelConstructor.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/SubOrganizationWithinModelConstructor.java
new file mode 100644
index 00000000..e4905874
--- /dev/null
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/SubOrganizationWithinModelConstructor.java
@@ -0,0 +1,111 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+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.Syntax;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+
+import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
+import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
+
+public class SubOrganizationWithinModelConstructor implements ModelConstructor {
+
+ protected static final Syntax SYNTAX = Syntax.syntaxARQ;
+
+ public static final String MODEL_TYPE = "SUBORGANIZATION_WITHIN_HIERARCHY_MODEL";
+
+ private Dataset dataset;
+
+ private Model constructedModel;
+
+ private Log log = LogFactory.getLog(SubOrganizationWithinModelConstructor.class.getName());
+
+ private long before, after;
+
+ public SubOrganizationWithinModelConstructor(Dataset dataset) {
+ this.dataset = dataset;
+ }
+
+ /**
+ * This constructor is present so that we can abstract out the model construction process.
+ * @param uri
+ * @param dataset
+ */
+ public SubOrganizationWithinModelConstructor(String uri, Dataset dataset) {
+ this.dataset = dataset;
+ }
+
+ private String constructAllSubOrganizationsWithinQuery() {
+ return ""
+ + " CONSTRUCT { "
+ + " ?organization rdf:type foaf:Organization . "
+ + " ?organization rdfs:label ?organizationLabel . "
+ + " ?organization core:subOrganizationWithin ?parentOrganization . "
+ + " ?parentOrganization rdfs:label ?parentOrganizationLabel . "
+ + " } "
+ + " WHERE { "
+ + " ?organization rdf:type foaf:Organization . "
+ + " ?organization rdfs:label ?organizationLabel . "
+ + " "
+ + " OPTIONAL { "
+ + " ?organization core:subOrganizationWithin ?parentOrganization . "
+ + " ?parentOrganization rdfs:label ?parentOrganizationLabel . "
+ + " } "
+ + " } ";
+
+ }
+
+ private Model executeQuery(String constructQuery) {
+
+ Model constructedModel = ModelFactory.createDefaultModel();
+
+ before = System.currentTimeMillis();
+ log.debug("CONSTRUCT query string : " + constructQuery);
+
+ Query query = null;
+
+ try {
+ query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery()
+ + constructQuery, SYNTAX);
+ } catch (Throwable th) {
+ log.error("Could not create CONSTRUCT SPARQL query for query "
+ + "string. " + th.getMessage());
+ log.error(constructQuery);
+ }
+
+ QueryExecution qe = QueryExecutionFactory.create(query, dataset);
+
+ try {
+ qe.execConstruct(constructedModel);
+ } finally {
+ qe.close();
+ }
+
+ after = System.currentTimeMillis();
+ log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
+ + (after - before));
+
+ return constructedModel;
+ }
+
+ public Model getConstructedModel() throws MalformedQueryParametersException {
+
+ if (constructedModel != null && !constructedModel.isEmpty()) {
+ return constructedModel;
+ } else {
+ constructedModel = executeQuery(constructAllSubOrganizationsWithinQuery());
+ return constructedModel;
+ }
+
+ }
+
+}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/factory/SubOrganizationWithinModelFactory.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/factory/SubOrganizationWithinModelFactory.java
new file mode 100644
index 00000000..e1e07979
--- /dev/null
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/modelconstructor/factory/SubOrganizationWithinModelFactory.java
@@ -0,0 +1,42 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.factory;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.rdf.model.Model;
+
+import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.SubOrganizationWithinModelConstructor;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.ConstructedModelTracker;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.ModelConstructor;
+
+public class SubOrganizationWithinModelFactory implements ModelFactoryInterface {
+
+ @Override
+ public Model getOrCreateModel(String uri, Dataset dataset) throws MalformedQueryParametersException {
+
+ Model candidateModel = ConstructedModelTracker.getModel(
+ ConstructedModelTracker
+ .generateModelIdentifier(
+ null,
+ SubOrganizationWithinModelConstructor.MODEL_TYPE));
+
+ if (candidateModel != null) {
+
+ return candidateModel;
+
+ } else {
+
+ ModelConstructor model = new SubOrganizationWithinModelConstructor(dataset);
+ Model constructedModel = model.getConstructedModel();
+
+ ConstructedModelTracker.trackModel(
+ ConstructedModelTracker
+ .generateModelIdentifier(
+ null,
+ SubOrganizationWithinModelConstructor.MODEL_TYPE),
+ constructedModel);
+
+ return constructedModel;
+ }
+ }
+}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java
index 812574b2..08ce73d9 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Entity.java
@@ -11,6 +11,7 @@ import java.util.Set;
*/
public class Entity extends Individual {
+ private Set parents = new LinkedHashSet();
private Set children = new LinkedHashSet();
public Entity(String entityURI, String entityLabel) {
@@ -28,10 +29,18 @@ public class Entity extends Individual {
public String getEntityLabel() {
return this.getIndividualLabel();
}
+
+ public void setEntityLabel(String label) {
+ this.setIndividualLabel(label);
+ }
public Set getSubEntities() {
return children;
}
+
+ public Set getParents() {
+ return parents;
+ }
public void addSubEntity(SubEntity subEntity) {
this.children.add(subEntity);
@@ -40,5 +49,9 @@ public class Entity extends Individual {
public void addSubEntitities(Collection subEntities) {
this.children.addAll(subEntities);
}
-
+
+ public void addParents(Collection parents) {
+ this.parents.addAll(parents);
+ }
+
}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java
index c6e0f922..44c58118 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/JsonObject.java
@@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Set;
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/SubjectEntityJSON.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/SubjectEntityJSON.java
new file mode 100644
index 00000000..58f94a52
--- /dev/null
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/SubjectEntityJSON.java
@@ -0,0 +1,47 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class SubjectEntityJSON {
+
+ private String subjectEntityLabel;
+ private String subjectEntityURI;
+ private Map parentURIToLabel = new HashMap();
+
+ public SubjectEntityJSON(String subjectEntityURI, String label,
+ Set parentOrganizations) {
+ this.subjectEntityURI = subjectEntityURI;
+ this.subjectEntityLabel = label;
+
+ this.setParentURIToLabel(parentOrganizations);
+ }
+
+ public String getSubjectEntityURI() {
+ return subjectEntityURI;
+ }
+
+ public void setSubjectEntityURI(String subjectEntityURI) {
+ this.subjectEntityURI = subjectEntityURI;
+ }
+
+ public String getSubjectEntityLabel() {
+ return subjectEntityLabel;
+ }
+
+ public void setSubjectEntityLabel(String label) {
+ this.subjectEntityLabel = label;
+ }
+
+ public Map getParentURIToLabel() {
+ return parentURIToLabel;
+ }
+
+ public void setParentURIToLabel(Set parentOrganizations) {
+ for (Individual parentOrganization : parentOrganizations) {
+ this.parentURIToLabel.put(parentOrganization.getIndividualURI(), parentOrganization.getIndividualLabel());
+ }
+ }
+}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java
index 63e46cf7..c86954c6 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/SelectOnModelUtilities.java
@@ -25,8 +25,10 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructo
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.OrganizationToPublicationsForSubOrganizationsModelConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PeopleToGrantsModelConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.PeopleToPublicationsModelConstructor;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.modelconstructor.SubOrganizationWithinModelConstructor;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Activity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
+import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Individual;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
public class SelectOnModelUtilities {
@@ -59,8 +61,82 @@ public class SelectOnModelUtilities {
"",
organizationModel);
- return getEntityWithSubOrganizations(subjectEntityURI,
+ Entity entityWithSubOrganizations = getEntityWithSubOrganizations(subjectEntityURI,
subOrganizationsWithTypesQuery.getQueryResult());
+
+ Entity entityWithParentOrganizations = getAllParentOrganizations(dataset, subjectEntityURI);
+
+ entityWithSubOrganizations.addParents(entityWithParentOrganizations.getParents());
+
+ return entityWithSubOrganizations;
+ }
+
+ public static Entity getAllParentOrganizations(Dataset dataset,
+ String subjectEntityURI) throws MalformedQueryParametersException {
+ Model organizationModel = ModelConstructorUtilities
+ .getOrConstructModel(
+ null,
+ SubOrganizationWithinModelConstructor.MODEL_TYPE,
+ dataset);
+
+ Map fieldLabelToOutputFieldLabel = new HashMap();
+ fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL);
+ fieldLabelToOutputFieldLabel.put("parentOrganization", QueryFieldLabels.PARENT_ORGANIZATION_URL);
+ fieldLabelToOutputFieldLabel.put("parentOrganizationLabel", QueryFieldLabels.PARENT_ORGANIZATION_LABEL);
+
+ String whereClause = ""
+ + " <" + subjectEntityURI + "> rdfs:label ?organizationLabel . "
+ + " <" + subjectEntityURI + "> core:subOrganizationWithin ?parentOrganization . "
+ + " ?parentOrganization rdfs:label ?parentOrganizationLabel . ";
+
+ QueryRunner parentOrganizationsQuery =
+ new GenericQueryRunnerOnModel(fieldLabelToOutputFieldLabel,
+ "",
+ whereClause,
+ "",
+ organizationModel);
+
+ return getEntityWithParentOrganizations(subjectEntityURI,
+ parentOrganizationsQuery.getQueryResult());
+ }
+
+ private static Entity getEntityWithParentOrganizations(String subjectEntityURI, ResultSet queryResult) {
+
+ Entity entity = new Entity(subjectEntityURI);
+ Map parentOrganizationURIToVO = new HashMap();
+
+ while (queryResult.hasNext()) {
+
+ QuerySolution solution = queryResult.nextSolution();
+
+ if (StringUtils.isEmpty(entity.getEntityLabel())) {
+
+ RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
+ if (organizationLabelNode != null) {
+ entity.setIndividualLabel(organizationLabelNode.toString());
+ }
+ }
+
+ RDFNode parentOrganizationNode = solution.get(QueryFieldLabels.PARENT_ORGANIZATION_URL);
+
+ Individual parent;
+
+ if (!parentOrganizationURIToVO.containsKey(parentOrganizationNode.toString())) {
+
+ parent = new Individual(parentOrganizationNode.toString());
+
+ parentOrganizationURIToVO.put(parentOrganizationNode.toString(), parent);
+
+ RDFNode parentOrganizationLabelNode = solution.get(QueryFieldLabels.PARENT_ORGANIZATION_LABEL);
+ if (parentOrganizationLabelNode != null) {
+ parent.setIndividualLabel(parentOrganizationLabelNode.toString());
+ }
+ }
+ }
+
+ entity.addParents(parentOrganizationURIToVO.values());
+
+ return entity;
}
private static Entity getEntityWithSubOrganizations(String subjectEntityURI, ResultSet queryResult) {
@@ -76,7 +152,8 @@ public class SelectOnModelUtilities {
RDFNode organizationLabelNode = solution.get(QueryFieldLabels.ORGANIZATION_LABEL);
if (organizationLabelNode != null) {
- entity.setIndividualLabel(organizationLabelNode.toString());
+
+ entity.setEntityLabel(organizationLabelNode.toString());
}
}