1. Attempting to delete old visualization back-end & front-end

This commit is contained in:
cdtank 2011-01-12 19:28:21 +00:00
parent dcad4e0d3f
commit 08e643982a
33 changed files with 3 additions and 3555 deletions

View file

@ -95,6 +95,7 @@ $(document).ready(function(){
<#-- Moniker-->
<em id="ego_moniker" class="moniker"></em>
<br />
<span class="pictos-arrow-14">4</span><a href="${egoVivoProfileURL}">Back to Profile</a>
</div>

View file

@ -92,7 +92,7 @@ $(document).ready(function(){
<#-- Moniker-->
<em id="ego_moniker" class="moniker"></em>
<br />
<span class="pictos-arrow-14">4</span><a href="${egoVivoProfileURL}">Back to Profile</a>
</div>

View file

@ -1,104 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.visualization;
/*
Copyright (c) 2010, Cornell University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Cornell University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
/**
* Services a sparql query. This will return a simple error message and a 501 if
* there is no jena Model.
*
* @author bdc34
*
*/
public class DummyVisClientController extends BaseEditController {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(DummyVisClientController.class.getName());
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doGet(request,response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if (!checkLoginStatus(request, response))
return;
super.doGet(request, response);
VitroRequest vreq = new VitroRequest(request);
prepareVisualizationQueryResponse(request, response, vreq);
return;
}
private void prepareVisualizationQueryResponse(HttpServletRequest request,
HttpServletResponse response, VitroRequest vreq) {
Portal portal = vreq.getPortal();
RequestDispatcher requestDispatcher = request.getRequestDispatcher(Controllers.BASIC_JSP);
request.setAttribute("bodyJsp", "/templates/visualization/dummy_vis_client.jsp");
request.setAttribute("portalBean", portal);
request.setAttribute("title", "Dummy Visualization Client");
request.setAttribute("scripts", "/templates/visualization/visualization_scripts.jsp");
try {
requestDispatcher.forward(request, response);
} catch (Exception e) {
log.error("EntityEditController could not forward to view.");
log.error(e.getMessage());
log.error(e.getStackTrace());
}
}
}

View file

@ -1,224 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.visualization;
import java.io.IOException;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.hp.hpl.jena.query.DataSource;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler;
/**
* Services a visualization request. This will return a simple error message and a 501 if
* there is no jena Model.
*
* @author cdtank
*/
@SuppressWarnings("serial")
public class VisualizationController extends BaseEditController {
private Map<String, VisualizationRequestHandler> visualizationIDsToClass;
public static final String URL_ENCODING_SCHEME = "UTF-8";
private static final Log log = LogFactory.getLog(VisualizationController.class.getName());
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
/* This method is overridden to inject vis dependencies i.e. the vis algorithms that are
* being implemented into the vis controller. Modified Dependency Injection pattern is
* used here. XML file containing the location of all the vis is saved in accessible folder.
* @see javax.servlet.GenericServlet#init()
*/
@Override
public void init() throws ServletException {
super.init();
try {
String resourcePath =
getServletContext()
.getRealPath(VisualizationFrameworkConstants
.RELATIVE_LOCATION_OF_VISUALIZATIONS_BEAN);
ApplicationContext context = new ClassPathXmlApplicationContext(
"file:" + resourcePath);
BeanFactory factory = context;
VisualizationInjector visualizationInjector =
(VisualizationInjector) factory.getBean("visualizationInjector");
visualizationIDsToClass = visualizationInjector.getVisualizationIDToClass();
} catch (Exception e) {
log.error(e);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
super.doGet(request, response);
VitroRequest vitroRequest = new VitroRequest(request);
/*
* Based on the query parameters passed via URI get the appropriate visualization
* request handler.
* */
VisualizationRequestHandler visRequestHandler =
getVisualizationRequestHandler(request, response, vitroRequest);
/*
* Pass the query to the selected visualization request handler & render the visualization.
* Since the visualization content is directly added to the response object we are side-
* effecting this method.
* */
renderVisualization(request, response, vitroRequest, visRequestHandler);
return;
}
private void renderVisualization(HttpServletRequest request,
HttpServletResponse response,
VitroRequest vitroRequest,
VisualizationRequestHandler visRequestHandler)
throws ServletException, IOException {
DataSource dataSource = setupJENADataSource(request,
response,
vitroRequest);
if (dataSource != null && visRequestHandler != null) {
visRequestHandler.generateVisualization(vitroRequest,
request,
response,
log,
dataSource);
} else {
String errorMessage = "Data Model Empty &/or Inappropriate "
+ "query parameters were submitted. ";
handleMalformedParameters(errorMessage,
request,
response);
log.error(errorMessage);
}
}
private VisualizationRequestHandler getVisualizationRequestHandler(
HttpServletRequest request,
HttpServletResponse response,
VitroRequest vitroRequest)
throws ServletException, IOException {
String visType = vitroRequest.getParameter(VisualizationFrameworkConstants
.VIS_TYPE_KEY);
VisualizationRequestHandler visRequestHandler = null;
try {
visRequestHandler = visualizationIDsToClass.get(visType);
} catch (NullPointerException nullKeyException) {
/*
* This is side-effecting because the error content is directly
* added to the request object. From where it is redirected to
* the error page.
* */
handleMalformedParameters("Inappropriate query parameters were submitted. ",
request,
response);
}
return visRequestHandler;
}
private DataSource setupJENADataSource(HttpServletRequest request,
HttpServletResponse response, VitroRequest vreq) {
Model model = vreq.getJenaOntModel(); // getModel()
if (model == null) {
doNoModelInContext(request, response);
return null;
}
log.debug("rdfResultFormat was: " + VisConstants.RDF_RESULT_FORMAT_PARAM);
DataSource dataSource = DatasetFactory.create();
ModelMaker maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker");
dataSource.setDefaultModel(model);
return dataSource;
}
private void doNoModelInContext(HttpServletRequest request, HttpServletResponse res) {
try {
res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
ServletOutputStream sos = res.getOutputStream();
sos.println("<html><body>this service is not supporeted by the current "
+ "webapp configuration. A jena model is required in the "
+ "servlet context.</body></html>");
} catch (IOException e) {
log.error("Could not write to ServletOutputStream");
}
}
private void handleMalformedParameters(String errorMessage, HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
VitroRequest vreq = new VitroRequest(request);
Portal portal = vreq.getPortal();
request.setAttribute("error", errorMessage);
RequestDispatcher requestDispatcher = request.getRequestDispatcher(Controllers.BASIC_JSP);
request.setAttribute("bodyJsp", "/templates/visualization/visualization_error.jsp");
request.setAttribute("portalBean", portal);
request.setAttribute("title", "Visualization Query Error");
try {
requestDispatcher.forward(request, response);
} catch (Exception e) {
log.error("EntityEditController could not forward to view.");
log.error(e.getMessage());
log.error(e.getStackTrace());
}
}
}

View file

@ -1,91 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.visualization;
public class VisualizationFrameworkConstants {
/*
* Contains the location of bean containing info on all the visualizations
* available in that instance. Currently it is stored under
* "productMods/WEB-INF..."
*/
public static final String RELATIVE_LOCATION_OF_VISUALIZATIONS_BEAN =
"/WEB-INF/visualization/visualizations-beans-injection.xml";
/*
* Freemarker Version
* */
public static final String RELATIVE_LOCATION_OF_FM_VISUALIZATIONS_BEAN =
"/WEB-INF/visualization/visualizations-beans-injection-fm.xml";
public static final String ERROR_TEMPLATE = "/visualization/visualizationError.ftl";
/*
* Vis URL prefix that is seen by all the users
*/
public static final String VISUALIZATION_URL_PREFIX = "/visualization";
public static final String FREEMARKERIZED_VISUALIZATION_URL_PREFIX = "/visualizationfm";
public static final String AJAX_VISUALIZATION_SERVICE_URL_PREFIX = "/visualizationAjax";
public static final String DATA_VISUALIZATION_SERVICE_URL_PREFIX = "/visualizationData";
public static final String INDIVIDUAL_URL_PREFIX = "/individual";
/*
* These represent possible query keys in a URI for visualization purposes.
* Examples,
* 1. http://vivo.indiana.edu/visualization?uri=http://vivoweb.org/ontology/core/Person10979&vis=person_level&render_mode=standalone
* 2. http://vivo.indiana.edu/visualization?uri=http://vivoweb.org/ontology/core/Person72&vis=person_pub_count&render_mode=dynamic&container=vis_container
* */
public static final String VIS_TYPE_KEY = "vis";
public static final String VIS_CONTAINER_KEY = "container";
public static final String INDIVIDUAL_URI_KEY = "uri";
public static final String VIS_MODE_KEY = "vis_mode";
public static final String RENDER_MODE_KEY = "render_mode";
/*
* These values represent possible render modes.
* */
public static final String STANDALONE_RENDER_MODE = "standalone";
public static final String DYNAMIC_RENDER_MODE = "dynamic";
public static final String DATA_RENDER_MODE = "data";
public static final String PDF_RENDER_MODE = "pdf";
/*
* These values represent possible sub-vis modes.
* */
public static final String IMAGE_VIS_MODE = "image";
public static final String SPARKLINE_VIS_MODE = "sparkline";
public static final String COAUTHORSLIST_VIS_MODE = "coauthors";
public static final String SHORT_SPARKLINE_VIS_MODE = "short";
public static final String FULL_SPARKLINE_VIS_MODE = "full";
public static final String COPI_VIS_MODE = "copi";
/*
* These values represent possible utilities vis modes.
* */
public static final String PROFILE_INFO_UTILS_VIS_MODE = "PROFILE_INFO";
public static final String PROFILE_UTILS_VIS_MODE = "PROFILE_URL";
public static final String COAUTHOR_UTILS_VIS_MODE = "COAUTHORSHIP_URL";
public static final String PERSON_LEVEL_UTILS_VIS_MODE = "PERSON_LEVEL_URL";
public static final String COPI_UTILS_VIS_MODE = "COPI_URL";
public static final String IMAGE_UTILS_VIS_MODE = "IMAGE_URL";
public static final String UNIVERSITY_COMPARISON_VIS_MODE = "UNIVERSITY";
public static final String SCHOOL_COMPARISON_VIS_MODE = "SCHOOL";
public static final String DEPARTMENT_COMPARISON_VIS_MODE = "DEPARTMENT";
/*
* These values represent possible visualizations provided as values to the "vis" url key.
* */
public static final String PERSON_PUBLICATION_COUNT_VIS = "person_pub_count";
public static final String PERSON_GRANT_COUNT_VIS = "person_grant_count";
public static final String PDF_REPORT_VIS = "pdf_report";
public static final String COLLEGE_PUBLICATION_COUNT_VIS = "college_pub_count";
public static final String COAUTHORSHIP_VIS = "coauthorship";
public static final String PERSON_LEVEL_VIS = "person_level";
public static final String UTILITIES_VIS = "utilities";
public static final String ENTITY_COMPARISON_VIS = "entity_comparison";
public static final String CO_PI_VIS = "coprincipalinvestigator";
}

View file

@ -1,19 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.visualization;
import java.util.Map;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler;
public class VisualizationInjector {
private Map<String, VisualizationRequestHandler> visualizationIDToClass;
public Map<String, VisualizationRequestHandler> getVisualizationIDToClass() {
return visualizationIDToClass;
}
public void setVisualizations(Map<String, VisualizationRequestHandler> visualizationIDToClass) {
this.visualizationIDToClass = visualizationIDToClass;
}
}

View file

@ -1,7 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.entitygrantcount;
public class EntityGrantCountQueryRunner {
}

View file

@ -33,7 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.In
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SparklineData;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.VisualizationRequestHandler;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.PDFDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
/**

View file

@ -1,305 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.utilities;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import com.google.gson.Gson;
import com.hp.hpl.jena.query.DataSource;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationController;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
import edu.cornell.mannlib.vitro.webapp.filestorage.FileServingHelper;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.AllPropertiesQueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.GenericQueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.VisualizationRequestHandler;
/**
* This request handler is used when you need helpful information to add more context
* to the visualization. It does not have any code for generating the visualization,
* just fires sparql queries to get info for specific cases like,
* 1. thumbnail/image location for a particular individual
* 2. profile information for a particular individual like label, moniker etc
* 3. person level vis url for a particular individual
* etc.
* @author cdtank
*/
public class UtilitiesRequestHandler implements VisualizationRequestHandler {
public void generateVisualization(VitroRequest vitroRequest,
HttpServletRequest request,
HttpServletResponse response,
Log log,
DataSource dataSource) {
String individualURI = vitroRequest.getParameter(
VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
String visMode = vitroRequest.getParameter(
VisualizationFrameworkConstants.VIS_MODE_KEY);
String preparedURL = "";
try {
/*
* If the info being requested is about a profile which includes the name, moniker
* & image url.
* */
if (VisualizationFrameworkConstants.PROFILE_INFO_UTILS_VIS_MODE
.equalsIgnoreCase(visMode)) {
String filterRule = "?predicate = j.2:mainImage "
+ "|| ?predicate = vitro:moniker "
+ "|| ?predicate = rdfs:label";
QueryRunner<GenericQueryMap> profileQueryHandler =
new AllPropertiesQueryRunner(individualURI,
filterRule,
dataSource,
log);
try {
GenericQueryMap profilePropertiesToValues =
profileQueryHandler.getQueryResult();
profilePropertiesToValues.addEntry("imageContextPath",
request.getContextPath());
Gson profileInformation = new Gson();
prepareUtilitiesResponse(
profileInformation.toJson(profilePropertiesToValues),
response);
return;
} catch (MalformedQueryParametersException e) {
try {
UtilityFunctions.handleMalformedParameters(
e.getMessage(),
"Visualization Query Error - Utilities Profile Info",
vitroRequest,
request,
response,
log);
} catch (ServletException e1) {
log.error(e1.getStackTrace());
} catch (IOException e1) {
log.error(e1.getStackTrace());
}
return;
}
} else if (VisualizationFrameworkConstants.IMAGE_UTILS_VIS_MODE
.equalsIgnoreCase(visMode)) {
/*
* If the url being requested is about a standalone image, which is used when we
* want to render an image & other info for a co-author OR ego for that matter.
* */
Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>();
fieldLabelToOutputFieldLabel.put("downloadLocation",
QueryFieldLabels.THUMBNAIL_LOCATION_URL);
fieldLabelToOutputFieldLabel.put("fileName", QueryFieldLabels.THUMBNAIL_FILENAME);
String whereClause = "<" + individualURI
+ "> j.2:thumbnailImage ?thumbnailImage . "
+ "?thumbnailImage j.2:downloadLocation "
+ "?downloadLocation ; j.2:filename ?fileName .";
QueryRunner<ResultSet> imageQueryHandler =
new GenericQueryRunner(individualURI,
fieldLabelToOutputFieldLabel,
whereClause,
dataSource,
log);
try {
String thumbnailAccessURL =
getThumbnailInformation(
imageQueryHandler.getQueryResult(),
fieldLabelToOutputFieldLabel);
prepareUtilitiesResponse(thumbnailAccessURL, response);
return;
} catch (MalformedQueryParametersException e) {
try {
UtilityFunctions.handleMalformedParameters(
e.getMessage(),
"Visualization Query Error - Utilities Image Info",
vitroRequest,
request,
response,
log);
} catch (ServletException e1) {
log.error(e1.getStackTrace());
} catch (IOException e1) {
log.error(e1.getStackTrace());
}
return;
}
} else if (VisualizationFrameworkConstants.COAUTHOR_UTILS_VIS_MODE
.equalsIgnoreCase(visMode)) {
/*
* By default we will be generating profile url else some specific url like
* coAuthorShip vis url for that individual.
* */
preparedURL += request.getContextPath()
+ VisualizationFrameworkConstants.VISUALIZATION_URL_PREFIX
+ "?"
+ VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY
+ "=" + URLEncoder.encode(individualURI,
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.VIS_TYPE_KEY
+ "=" + URLEncoder.encode("coauthorship",
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.RENDER_MODE_KEY
+ "=" + URLEncoder.encode(VisualizationFrameworkConstants
.STANDALONE_RENDER_MODE,
VisualizationController.URL_ENCODING_SCHEME)
.toString();
prepareUtilitiesResponse(preparedURL, response);
return;
} else if (VisualizationFrameworkConstants.PERSON_LEVEL_UTILS_VIS_MODE
.equalsIgnoreCase(visMode)) {
/*
* By default we will be generating profile url else some specific url like
* coAuthorShip vis url for that individual.
* */
preparedURL += request.getContextPath()
+ VisualizationFrameworkConstants.VISUALIZATION_URL_PREFIX
+ "?"
+ VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY
+ "=" + URLEncoder.encode(individualURI,
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.VIS_TYPE_KEY
+ "=" + URLEncoder.encode("person_level",
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.RENDER_MODE_KEY
+ "=" + URLEncoder.encode(VisualizationFrameworkConstants
.STANDALONE_RENDER_MODE,
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.VIS_MODE_KEY
+ "=" + URLEncoder.encode("coauthorship",
VisualizationController.URL_ENCODING_SCHEME).toString();
prepareUtilitiesResponse(preparedURL, response);
return;
} else if (VisualizationFrameworkConstants.COPI_UTILS_VIS_MODE
.equalsIgnoreCase(visMode)) {
preparedURL += request.getContextPath()
+ VisualizationFrameworkConstants.VISUALIZATION_URL_PREFIX
+ "?"
+ VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY
+ "=" + URLEncoder.encode(individualURI,
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.VIS_TYPE_KEY
+ "=" + URLEncoder.encode("person_level",
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.RENDER_MODE_KEY
+ "=" + URLEncoder.encode(VisualizationFrameworkConstants
.STANDALONE_RENDER_MODE,
VisualizationController.URL_ENCODING_SCHEME).toString()
+ "&"
+ VisualizationFrameworkConstants.VIS_MODE_KEY
+ "=" + URLEncoder.encode("copi",
VisualizationController.URL_ENCODING_SCHEME).toString();
prepareUtilitiesResponse(preparedURL, response);
return;
} else {
preparedURL += request.getContextPath()
+ VisualizationFrameworkConstants.INDIVIDUAL_URL_PREFIX
+ "?"
+ VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY
+ "=" + URLEncoder.encode(individualURI,
VisualizationController.URL_ENCODING_SCHEME).toString();
prepareUtilitiesResponse(preparedURL, response);
return;
}
} catch (UnsupportedEncodingException e) {
log.error(e.getLocalizedMessage());
}
}
private String getThumbnailInformation(ResultSet resultSet,
Map<String, String> fieldLabelToOutputFieldLabel) {
String finalThumbNailLocation = "";
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
RDFNode downloadLocationNode = solution.get(
fieldLabelToOutputFieldLabel
.get("downloadLocation"));
RDFNode fileNameNode = solution.get(fieldLabelToOutputFieldLabel.get("fileName"));
if (downloadLocationNode != null && fileNameNode != null) {
finalThumbNailLocation =
FileServingHelper
.getBytestreamAliasUrl(downloadLocationNode.toString(),
fileNameNode.toString());
}
}
return finalThumbNailLocation;
}
private void prepareUtilitiesResponse(String preparedURL,
HttpServletResponse response) {
response.setContentType("text/plain");
try {
PrintWriter responseWriter = response.getWriter();
responseWriter.append(preparedURL);
responseWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -1,183 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
/**
* @author cdtank
*
*/
public class BiboDocument extends Individual {
private String documentMoniker;
private String documentBlurb;
private String documentDescription;
private String publicationYear;
private String publicationYearMonth;
private String publicationDate;
private String parsedPublicationYear = VOConstants.DEFAULT_PUBLICATION_YEAR;
public BiboDocument(String documentURL) {
super(documentURL);
}
public String getDocumentURL() {
return this.getIndividualURI();
}
public String getDocumentMoniker() {
return documentMoniker;
}
public void setDocumentMoniker(String documentMoniker) {
this.documentMoniker = documentMoniker;
}
public String getDocumentLabel() {
return this.getIndividualLabel();
}
public void setDocumentLabel(String documentLabel) {
this.setIndividualLabel(documentLabel);
}
public String getDocumentBlurb() {
return documentBlurb;
}
public void setDocumentBlurb(String documentBlurb) {
this.documentBlurb = documentBlurb;
// if (documentBlurb != null) {
// this.setParsedPublicationYear(parsePublicationYear(documentBlurb));
// }
}
private String parsePublicationYear(String documentBlurb) {
/*
* This pattern will match all group of numbers which have only 4 digits
* delimited by the word boundary.
* */
String pattern = "(?<!-)\\b\\d{4}\\b(?=[^-])";
Pattern yearPattern = Pattern.compile(pattern);
String publishedYear = VOConstants.DEFAULT_PUBLICATION_YEAR;
Matcher yearMatcher = yearPattern.matcher(documentBlurb);
while (yearMatcher.find()) {
String yearCandidate = yearMatcher.group();
Integer candidateYearInteger = Integer.valueOf(yearCandidate);
/*
* Published year has to be equal or less than the current year
* and more than a minimum default year.
* */
if (candidateYearInteger <= VOConstants.CURRENT_YEAR
&& candidateYearInteger >= VOConstants.MINIMUM_PUBLICATION_YEAR) {
publishedYear = candidateYearInteger.toString();
}
}
return publishedYear;
}
public String getDocumentDescription() {
return documentDescription;
}
public void setDocumentDescription(String documentDescription) {
this.documentDescription = documentDescription;
}
/**
* This method will be called when there is no usable core:year value found
* for the bibo:Document. It will first check & parse core:yearMonth failing
* which it will try core:date
* @return
*/
public String getParsedPublicationYear() {
/*
* We are assuming that core:yearMonth has "YYYY-MM" format. This is based
* off of http://www.w3.org/TR/xmlschema-2/#gYearMonth , which is what
* core:yearMonth points to internally.
* */
if (publicationYearMonth != null
&& publicationYearMonth.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT
&& isValidPublicationYear(publicationYearMonth.substring(
0,
VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) {
return publicationYearMonth.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT);
}
if (publicationDate != null
&& publicationDate.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT
&& isValidPublicationYear(publicationDate
.substring(0,
VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) {
return publicationDate.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT);
}
/*
* If all else fails return default unknown year identifier
* */
return VOConstants.DEFAULT_PUBLICATION_YEAR;
}
/*
* This publicationYear value is directly from the data supported by the ontology.
* If this is empty only then use the parsedPublicationYear.
* */
public String getPublicationYear() {
if (publicationYear != null && isValidPublicationYear(publicationYear)) {
return publicationYear;
} else {
return null;
}
}
public void setPublicationYear(String publicationYear) {
this.publicationYear = publicationYear;
}
public String getPublicationYearMonth() {
return publicationYearMonth;
}
public void setPublicationYearMonth(String publicationYearMonth) {
this.publicationYearMonth = publicationYearMonth;
}
public String getPublicationDate() {
return publicationDate;
}
public void setPublicationDate(String publicationDate) {
this.publicationDate = publicationDate;
}
private boolean isValidPublicationYear(String testPublicationYear) {
if (testPublicationYear.length() != 0
&& testPublicationYear.trim().length() == VOConstants.NUM_CHARS_IN_YEAR_FORMAT
&& testPublicationYear.matches("\\d+")
&& Integer.parseInt(testPublicationYear) >= VOConstants.MINIMUM_PUBLICATION_YEAR) {
return true;
}
return false;
}
}

View file

@ -1,42 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.Set;
import java.util.HashSet;
/**
* @author bkoniden
* Deepak Konidena
*
*/
public class Child extends Individual {
Set<BiboDocument> documents = new HashSet<BiboDocument>();
public Child(String individualURI) {
super(individualURI);
}
public Set<BiboDocument> getDocuments() {
return documents;
}
public Child(String individualURI, String individualLabel) {
super(individualURI, individualLabel);
}
@Override
public boolean equals(Object other){
boolean result = false;
if (other instanceof Child){
Child person = (Child) other;
result = (this.getIndividualLabel().equals(person.getIndividualLabel())
&& this.getIndividualURI().equals(person.getIndividualURI()));
}
return result;
}
@Override
public int hashCode(){
return(41*(getIndividualLabel().hashCode() + 41*(getIndividualURI().hashCode())));
}
}

View file

@ -1,229 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class CoAuthorshipData {
private Set<Node> nodes;
private Set<Edge> edges;
private Node egoNode;
private Set<Map<String, String>> NODE_SCHEMA;
private Set<Map<String, String>> EDGE_SCHEMA;
public CoAuthorshipData(Node egoNode, Set<Node> nodes, Set<Edge> edges) {
this.egoNode = egoNode;
this.nodes = nodes;
this.edges = edges;
}
public Set<Node> getNodes() {
return nodes;
}
public Set<Edge> getEdges() {
return edges;
}
public Node getEgoNode() {
return egoNode;
}
/*
* Node Schema for graphML
* */
public Set<Map<String, String>> getNodeSchema() {
if (NODE_SCHEMA == null) {
NODE_SCHEMA = initializeNodeSchema();
}
return NODE_SCHEMA;
}
/*
* Edge Schema for graphML
* */
public Set<Map<String, String>> getEdgeSchema() {
if (EDGE_SCHEMA == null) {
EDGE_SCHEMA = initializeEdgeSchema();
}
return EDGE_SCHEMA;
}
private Set<Map<String, String>> initializeEdgeSchema() {
Set<Map<String, String>> edgeSchema = new HashSet<Map<String, String>>();
Map<String, String> schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "collaborator1");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "collaborator1");
schemaAttributes.put("attr.type", "string");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "collaborator2");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "collaborator2");
schemaAttributes.put("attr.type", "string");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "number_of_coauthored_works");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "number_of_coauthored_works");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "earliest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "earliest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_earliest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_earliest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "latest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "latest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_latest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_latest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_unknown_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_unknown_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
return edgeSchema;
}
private Set<Map<String, String>> initializeNodeSchema() {
Set<Map<String, String>> nodeSchema = new HashSet<Map<String, String>>();
Map<String, String> schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "url");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "url");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "label");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "label");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "profile_url");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "profile_url");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "number_of_authored_works");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "number_of_authored_works");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "earliest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "earliest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_earliest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_earliest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "latest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "latest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_latest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_latest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_unknown_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_unknown_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
return nodeSchema;
}
}

View file

@ -1,251 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class CoPIData {
private Set<CoPINode> nodes;
private Set<CoPIEdge> edges;
private CoPINode egoNode;
private Set<Map<String, String>> NODE_SCHEMA;
private Set<Map<String, String>> EDGE_SCHEMA;
public CoPIData(CoPINode egoNode, Set<CoPINode> nodes, Set<CoPIEdge> edges) {
this.egoNode = egoNode;
this.nodes = nodes;
this.edges = edges;
}
public Set<CoPINode> getNodes() {
return nodes;
}
public Set<CoPIEdge> getEdges() {
return edges;
}
public CoPINode getEgoNode() {
return egoNode;
}
/*
* Node Schema for graphML
* */
public Set<Map<String, String>> getNodeSchema() {
if (NODE_SCHEMA == null) {
NODE_SCHEMA = initializeNodeSchema();
}
return NODE_SCHEMA;
}
/*
* Edge Schema for graphML
* */
public Set<Map<String, String>> getEdgeSchema() {
if (EDGE_SCHEMA == null) {
EDGE_SCHEMA = initializeEdgeSchema();
}
return EDGE_SCHEMA;
}
public void print(){
System.out.println("\n-----------------------------");
System.out.println("Ego node is "+ this.getEgoNode().getNodeName());
System.out.println("\nNodes are: ");
for(CoPINode node : this.getNodes()){
System.out.println(node.getNodeName());
}
System.out.println("\nEdges are: ");
for(CoPIEdge edge : this.getEdges()){
System.out.println(edge.getSourceNode() + "-->" + edge.getTargetNode());
}
System.out.println("\n-----------------------------");
}
private Set<Map<String, String>> initializeEdgeSchema() {
Set<Map<String, String>> edgeSchema = new HashSet<Map<String, String>>();
Map<String, String> schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "collaborator1");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "collaborator1");
schemaAttributes.put("attr.type", "string");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "collaborator2");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "collaborator2");
schemaAttributes.put("attr.type", "string");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "number_of_coinvestigated_grants");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "number_of_coinvestigated_grants");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "earliest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "earliest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_earliest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_earliest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "latest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "latest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_latest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_latest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_unknown_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_unknown_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
return edgeSchema;
}
private Set<Map<String, String>> initializeNodeSchema() {
Set<Map<String, String>> nodeSchema = new HashSet<Map<String, String>>();
Map<String, String> schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "url");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "url");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "label");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "label");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "profile_url");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "profile_url");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "number_of_investigated_grants");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "number_of_investigated_grants");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "earliest_grant");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "earliest_grant");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_earliest_grant");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_earliest_grant");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "latest_grant");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "latest_grant");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_latest_grant");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_latest_grant");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_unknown_grant");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_unknown_grant");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
return nodeSchema;
}
}

View file

@ -1,144 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
/**
* This stores edge information for Co-PI vis.
* @author bkoniden
* Deepak Konidena
*/
public class CoPIEdge {
private int edgeID;
private Map<String, Integer> yearToGrantCount;
private Set<Grant> collaboratorGrants = new HashSet<Grant>();
private CoPINode sourceNode;
private CoPINode targetNode;
public CoPIEdge(CoPINode sourceNode, CoPINode targetNode, Grant seedCoPIedGrant, UniqueIDGenerator uniqueIDGenerator){
edgeID = uniqueIDGenerator.getNextNumericID();
this.sourceNode = sourceNode;
this.targetNode = targetNode;
this.collaboratorGrants.add(seedCoPIedGrant);
}
public int getEdgeID() {
return edgeID;
}
public Set<Grant> getCollaboratorGrants() {
return collaboratorGrants;
}
public CoPINode getSourceNode() {
return sourceNode;
}
public CoPINode getTargetNode() {
return targetNode;
}
public int getNumberOfCoInvestigatedGrants(){
return collaboratorGrants.size();
}
public void addCollaboratorGrant(Grant grant){
this.collaboratorGrants.add(grant);
}
/*
* getEarliest, Latest & Unknown Grant YearCount should only be used after
* the parsing of the entire sparql is done. Else it will give results based on
* incomplete dataset.
* */
@SuppressWarnings("serial")
public Map<String, Integer> getEarliestCollaborationYearCount() {
if (yearToGrantCount == null) {
yearToGrantCount = UtilityFunctions.getYearToGrantCount(collaboratorGrants);
}
/*
* We do not want to consider the default grant year when we are checking
* for the min or max grant year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToGrantCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String earliestYear = Collections.min(yearsToBeConsidered);
final Integer earliestYearGrantCount = yearToGrantCount.get(earliestYear);
return new HashMap<String, Integer>() { {
put(earliestYear, earliestYearGrantCount);
} };
} else {
return null;
}
}
@SuppressWarnings("serial")
public Map<String, Integer> getLatestCollaborationYearCount() {
if (yearToGrantCount == null) {
yearToGrantCount = UtilityFunctions.getYearToGrantCount(collaboratorGrants);
}
/*
* We do not want to consider the default grant year when we are checking
* for the min or max grant year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToGrantCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only grant the PI has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String latestYear = Collections.max(yearsToBeConsidered);
final Integer latestYearGrantCount = yearToGrantCount.get(latestYear);
return new HashMap<String, Integer>() { {
put(latestYear, latestYearGrantCount);
} };
} else {
return null;
}
}
public Integer getUnknownCollaborationYearCount() {
if (yearToGrantCount == null) {
yearToGrantCount = UtilityFunctions.getYearToGrantCount(collaboratorGrants);
}
Integer unknownYearGrantCount = yearToGrantCount
.get(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* If there is no unknown year available then we should imply so by returning a "null".
* */
if (unknownYearGrantCount != null) {
return unknownYearGrantCount;
} else {
return null;
}
}
}

View file

@ -1,154 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
/**
* CoPINode is the node in a CoPI vis.
* @author bkoniden
* Deepak Konidena
*/
public class CoPINode extends Individual {
private int nodeID;
private Map<String, Integer> yearToGrantCount;
private Set<Grant> pIGrants = new HashSet<Grant>();
public CoPINode(String nodeURI, UniqueIDGenerator uniqueIDGenerator){
super(nodeURI);
nodeID = uniqueIDGenerator.getNextNumericID();
}
public int getNodeID(){
return nodeID;
}
public String getNodeURI(){
return this.getIndividualURI();
}
public String getNodeName(){
return this.getIndividualLabel();
}
public void setNodeName(String nodeName) {
this.setIndividualLabel(nodeName);
}
public Set<Grant> getInvestigatedGrants(){
return pIGrants;
}
public int getNumberOfInvestigatedGrants(){
return pIGrants.size();
}
public void addGrant(Grant grant){
this.pIGrants.add(grant);
}
public Map<String, Integer> getYearToGrantCount(){
if(yearToGrantCount == null){
yearToGrantCount = UtilityFunctions.getYearToGrantCount(pIGrants);
}
return yearToGrantCount;
}
/*
* getEarliest, Latest & Unknown Grant YearCount should only be used after
* the parsing of the entire sparql is done. Else it will give results based on
* incomplete dataset.
* */
@SuppressWarnings("serial")
public Map<String, Integer> getEarliestGrantYearCount() {
if (yearToGrantCount == null) {
yearToGrantCount = UtilityFunctions.getYearToGrantCount(pIGrants);
}
/*
* We do not want to consider the default grant year when we are checking
* for the min or max grant year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToGrantCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String earliestYear = Collections.min(yearsToBeConsidered);
final Integer earliestYearGrantCount = yearToGrantCount.get(earliestYear);
return new HashMap<String, Integer>() { {
put(earliestYear, earliestYearGrantCount);
} };
} else {
return null;
}
}
@SuppressWarnings("serial")
public Map<String, Integer> getLatestGrantYearCount() {
if (yearToGrantCount == null) {
yearToGrantCount = UtilityFunctions.getYearToGrantCount(pIGrants);
}
/*
* We do not want to consider the default grant year when we are checking
* for the min or max grant year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToGrantCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only grant the PI has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String latestYear = Collections.max(yearsToBeConsidered);
final Integer latestYearGrantCount = yearToGrantCount.get(latestYear);
return new HashMap<String, Integer>() { {
put(latestYear, latestYearGrantCount);
} };
} else {
return null;
}
}
public Integer getUnknownGrantYearCount() {
if (yearToGrantCount == null) {
yearToGrantCount = UtilityFunctions.getYearToGrantCount(pIGrants);
}
Integer unknownYearGrantCount = yearToGrantCount
.get(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* If there is no unknown year available then we should imply so by returning a "null".
* */
if (unknownYearGrantCount != null) {
return unknownYearGrantCount;
} else {
return null;
}
}
}

View file

@ -1,54 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.Set;
/**
* @author bkoniden
* Deepak Konidena
*
*/
public class Department extends Individual{
Set<BiboDocument> publication;
Set<Person> person;
public Department(String departmentURI, String departmentLabel){
super(departmentURI, departmentLabel);
}
public void setDepartmentLabel(String departmentURI){
this.setIndividualLabel(departmentURI);
}
public String getDepartmentURI(){
return this.getIndividualURI();
}
public Set<BiboDocument> getPublication() {
return publication;
}
public String getDepartmentLabel(){
return this.getIndividualLabel();
}
public Set<Person> getPerson() {
return person;
}
public void addPublication(BiboDocument biboDocument) {
this.publication.add(biboDocument);
}
public void addPersons(Person person) {
this.person.add(person);
}
public void addPerson(Person person) {
this.person.add(person);
}
}

View file

@ -1,153 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
/**
*
* This is stores edge information mainly for co-author vis.
*
* @author cdtank
*
*/
public class Edge {
private int edgeID;
private Map<String, Integer> yearToPublicationCount;
private Set<BiboDocument> collaboratorDocuments = new HashSet<BiboDocument>();
private Node sourceNode;
private Node targetNode;
public Edge(Node sourceNode, Node targetNode, BiboDocument seedCoAuthoredDocument,
UniqueIDGenerator uniqueIDGenerator) {
edgeID = uniqueIDGenerator.getNextNumericID();
this.sourceNode = sourceNode;
this.targetNode = targetNode;
this.collaboratorDocuments.add(seedCoAuthoredDocument);
}
public int getEdgeID() {
return edgeID;
}
public Node getSourceNode() {
return sourceNode;
}
public Node getTargetNode() {
return targetNode;
}
public Set<BiboDocument> getCollaboratorDocuments() {
return collaboratorDocuments;
}
public int getNumOfCoAuthoredWorks() {
return collaboratorDocuments.size();
}
public void addCollaboratorDocument(BiboDocument authorDocument) {
this.collaboratorDocuments.add(authorDocument);
}
/*
* getEarliest, Latest & Unknown Publication YearCount should only be used after
* the parsing of the entire sparql is done. Else it will give results based on
* incomplete dataset.
* */
@SuppressWarnings("serial")
public Map<String, Integer> getEarliestCollaborationYearCount() {
if (yearToPublicationCount == null) {
yearToPublicationCount = UtilityFunctions
.getYearToPublicationCount(collaboratorDocuments);
}
/*
* We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String earliestYear = Collections.min(yearsToBeConsidered);
final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear);
return new HashMap<String, Integer>() { {
put(earliestYear, earliestYearPubCount);
} };
} else {
return null;
}
}
@SuppressWarnings("serial")
public Map<String, Integer> getLatestCollaborationYearCount() {
if (yearToPublicationCount == null) {
yearToPublicationCount = UtilityFunctions
.getYearToPublicationCount(collaboratorDocuments);
}
/*
* We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String latestYear = Collections.max(yearsToBeConsidered);
final Integer latestYearPubCount = yearToPublicationCount.get(latestYear);
return new HashMap<String, Integer>() { {
put(latestYear, latestYearPubCount);
} };
} else {
return null;
}
}
public Integer getUnknownCollaborationYearCount() {
if (yearToPublicationCount == null) {
yearToPublicationCount = UtilityFunctions
.getYearToPublicationCount(collaboratorDocuments);
}
Integer unknownYearPubCount = yearToPublicationCount
.get(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* If there is no unknown year available then we should imply so by returning a "null".
* */
if (unknownYearPubCount != null) {
return unknownYearPubCount;
} else {
return null;
}
}
}

View file

@ -1,51 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.HashSet;
import java.util.Set;
import java.util.LinkedHashSet;
/**
* @author bkoniden
* Deepak Konidena
*
*/
public class Entity extends Individual{
Set<BiboDocument> publications = new HashSet<BiboDocument>();
Set<SubEntity> children = new LinkedHashSet<SubEntity>();
public Entity(String departmentURI, String departmentLabel){
super(departmentURI, departmentLabel);
}
public void setDepartmentLabel(String departmentURI){
this.setIndividualLabel(departmentURI);
}
public String getEntityURI(){
return this.getIndividualURI();
}
public Set<BiboDocument> getPublications() {
return publications;
}
public String getEntityLabel(){
return this.getIndividualLabel();
}
public Set<SubEntity> getSubEntities() {
return children;
}
public void addPublications(BiboDocument biboDocument) {
this.publications.add(biboDocument);
}
public void addSubEntity(SubEntity subEntity) {
this.children.add(subEntity);
}
}

View file

@ -1,41 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/**
* Right now this is just acting as a hashmap but in future we would want to provide
* more detailed info other than just what properties had what values. E.g. we
* could parse properties (& its values) to look for what namespaces are used.
*
* @author cdtank
*/
@SuppressWarnings("serial")
public class GenericQueryMap extends HashMap<String, Set<String>> {
public GenericQueryMap() {
super();
}
public void addEntry(String property, String value) {
Set<String> values;
if (this.containsKey(property)) {
values = this.get(property);
values.add(value);
} else {
values = new HashSet<String>();
values.add(value);
this.put(property, values);
}
}
}

View file

@ -1,134 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
/**
* @author bkoniden
* Deepak Konidena
*
*/
public class Grant extends Individual {
private String grantStartYear;
private String grantStartYearMonth;
private String grantStartDate;
private String grantEndYear;
private String grantEndYearMonth;
private String grantEndDate;
public Grant(String grantURL, String grantLabel){
super(grantURL, grantLabel);
}
public Grant(String grantURL){
super(grantURL);
}
public String getGrantURL() {
return this.getIndividualURI();
}
public String getGrantLabel(){
return this.getIndividualLabel();
}
/**
* This method will be called when there is no usable core:year value found
* for the bibo:Document. It will first check & parse core:yearMonth failing
* which it will try core:date
* @return
*/
public String getParsedGrantStartYear() {
/*
* We are assuming that core:yearMonth has "YYYY-MM-DD" format. This is based
* off of http://www.w3.org/TR/xmlschema-2/#gYearMonth , which is what
* core:yearMonth points to internally.
* */
if (grantStartYearMonth != null
&& grantStartYearMonth.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT
&& isValidPublicationYear(grantStartYearMonth.substring(
0,
VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) {
return grantStartYearMonth.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT);
}
if (grantStartDate != null
&& grantStartDate.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT
&& isValidPublicationYear(grantStartDate
.substring(0,
VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) {
return grantStartDate.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT);
}
/*
* If all else fails return default unknown year identifier
* */
return VOConstants.DEFAULT_GRANT_YEAR;
}
public String getGrantStartYear() {
return grantStartYear;
}
public void setGrantStartYear(String grantStartYear) {
this.grantStartYear = grantStartYear;
}
public String getGrantStartYearMonth() {
return grantStartYearMonth;
}
public void setGrantStartYearMonth(String grantStartYearMonth) {
this.grantStartYearMonth = grantStartYearMonth;
}
public String getGrantStartDate() {
return grantStartDate;
}
public void setGrantStartDate(String grantStartDate) {
this.grantStartDate = grantStartDate;
}
public String getGrantEndYear() {
return grantEndYear;
}
public void setGrantEndYear(String grantEndYear) {
this.grantEndYear = grantEndYear;
}
public String getGrantEndYearMonth() {
return grantEndYearMonth;
}
public void setGrantEndYearMonth(String grantEndYearMonth) {
this.grantEndYearMonth = grantEndYearMonth;
}
public String getGrantEndDate() {
return grantEndDate;
}
public void setGrantEndDate(String grantEndDate) {
this.grantEndDate = grantEndDate;
}
private boolean isValidPublicationYear(String testGrantYear) {
if (testGrantYear.length() != 0
&& testGrantYear.trim().length() == VOConstants.NUM_CHARS_IN_YEAR_FORMAT
&& testGrantYear.matches("\\d+")
&& Integer.parseInt(testGrantYear) >= VOConstants.MINIMUM_PUBLICATION_YEAR) {
return true;
}
return false;
}
}

View file

@ -1,32 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
public class Individual {
private String individualLabel;
private String individualURI;
public Individual(String individualURI, String individualLabel) {
this.individualURI = individualURI;
this.individualLabel = individualLabel;
}
public Individual(String individualURI) {
this(individualURI, "");
}
public String getIndividualLabel() {
return individualLabel;
}
public void setIndividualLabel(String individualLabel) {
this.individualLabel = individualLabel;
}
public String getIndividualURI() {
return individualURI;
}
}

View file

@ -1,76 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.ArrayList;
import java.util.List;
/**
* JsonObject is used for creating data in JSON format,
* by just using the fields that are required to be included.
* @author bkoniden
* Deepak Konidena
*/
public class JsonObject {
private String label;
private List<List<Integer>> data = new ArrayList<List<Integer>>();
private String entityURI;
private String visMode;
private List<String> organizationType = new ArrayList<String>();
private List<String> stopWords = new ArrayList<String>();
public List<String> getStopWords() {
return stopWords;
}
public void setStopWords(List<String> stopWords) {
this.stopWords = stopWords;
}
public List<String> getOrganizationType() {
return organizationType;
}
public void setOrganizationType(List<String> organizationType) {
this.organizationType = organizationType;
}
public String getEntityURI() {
return entityURI;
}
public void setEntityURI(String entityURI) {
this.entityURI = entityURI;
}
public String getVisMode() {
return visMode;
}
public void setVisMode(String visMode) {
this.visMode = visMode;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<List<Integer>> getYearToPublicationCount() {
return data;
}
public JsonObject(String label){
this.label = label;
}
public void setYearToPublicationCount(List<List<Integer>> yearToPublicationCount){
this.data = yearToPublicationCount;
}
}

View file

@ -1,156 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions;
/**
*
* This stores node information mainly for co-author vis.
*
* @author cdtank
*/
public class Node extends Individual {
private int nodeID;
private Map<String, Integer> yearToPublicationCount;
private Set<BiboDocument> authorDocuments = new HashSet<BiboDocument>();
public Node(String nodeURI,
UniqueIDGenerator uniqueIDGenerator) {
super(nodeURI);
nodeID = uniqueIDGenerator.getNextNumericID();
}
public int getNodeID() {
return nodeID;
}
public String getNodeURI() {
return this.getIndividualURI();
}
public String getNodeName() {
return this.getIndividualLabel();
}
public void setNodeName(String nodeName) {
this.setIndividualLabel(nodeName);
}
public Set<BiboDocument> getAuthorDocuments() {
return authorDocuments;
}
public int getNumOfAuthoredWorks() {
return authorDocuments.size();
}
public void addAuthorDocument(BiboDocument authorDocument) {
this.authorDocuments.add(authorDocument);
}
public Map<String, Integer> getYearToPublicationCount() {
if (yearToPublicationCount == null) {
yearToPublicationCount = UtilityFunctions.getYearToPublicationCount(authorDocuments);
}
return yearToPublicationCount;
}
/*
* getEarliest, Latest & Unknown Publication YearCount should only be used after
* the parsing of the entire sparql is done. Else it will give results based on
* incomplete dataset.
* */
@SuppressWarnings("serial")
public Map<String, Integer> getEarliestPublicationYearCount() {
if (yearToPublicationCount == null) {
yearToPublicationCount = UtilityFunctions.getYearToPublicationCount(authorDocuments);
}
/*
* We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String earliestYear = Collections.min(yearsToBeConsidered);
final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear);
return new HashMap<String, Integer>() { {
put(earliestYear, earliestYearPubCount);
} };
} else {
return null;
}
}
@SuppressWarnings("serial")
public Map<String, Integer> getLatestPublicationYearCount() {
if (yearToPublicationCount == null) {
yearToPublicationCount = UtilityFunctions.getYearToPublicationCount(authorDocuments);
}
/*
* We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */
if (yearsToBeConsidered.size() > 0) {
final String latestYear = Collections.max(yearsToBeConsidered);
final Integer latestYearPubCount = yearToPublicationCount.get(latestYear);
return new HashMap<String, Integer>() { {
put(latestYear, latestYearPubCount);
} };
} else {
return null;
}
}
public Integer getUnknownPublicationYearCount() {
if (yearToPublicationCount == null) {
yearToPublicationCount = UtilityFunctions.getYearToPublicationCount(authorDocuments);
}
Integer unknownYearPubCount = yearToPublicationCount
.get(VOConstants.DEFAULT_PUBLICATION_YEAR);
/*
* If there is no unknown year available then we should imply so by returning a "null".
* */
if (unknownYearPubCount != null) {
return unknownYearPubCount;
} else {
return null;
}
}
}

View file

@ -1,27 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.Set;
import java.util.HashSet;
/**
* @author bkoniden
* Deepak Konidena
*/
public class Person extends Individual {
Set<BiboDocument> documents = new HashSet<BiboDocument>();
public Person(String individualURI) {
super(individualURI);
}
public Set<BiboDocument> getDocuments() {
return documents;
}
public Person(String individualURI, String individualLabel) {
super(individualURI, individualLabel);
}
}

View file

@ -1,140 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
public class SparklineData {
/*
* For now sparklineNumPublicationsText & sparklinePublicationRangeText is left
* as empty but later on we would want to leverage the granularity that this
* provides.
* */
private String sparklineNumPublicationsText = "";
private String sparklinePublicationRangeText = "";
private Integer earliestRenderedPublicationYear;
private Integer latestRenderedPublicationYear;
private Integer earliestRenderedGrantYear;
private Integer latestRenderedGrantYear;
private String table = "";
private String downloadDataLink = "";
private String fullTimelineNetworkLink = "";
private String downloadCoPIDataLink = "";
private String fullTimelineCoPINetworkLink = "";
private String sparklineContent;
private String sparklineContext;
public String getSparklineNumPublicationsText() {
return sparklineNumPublicationsText;
}
public void setSparklineNumPublicationsText(String sparklineNumPublicationsText) {
this.sparklineNumPublicationsText = sparklineNumPublicationsText;
}
public String getSparklinePublicationRangeText() {
return sparklinePublicationRangeText;
}
public void setSparklinePublicationRangeText(
String sparklinePublicationRangeText) {
this.sparklinePublicationRangeText = sparklinePublicationRangeText;
}
public Integer getEarliestRenderedPublicationYear() {
return earliestRenderedPublicationYear;
}
public void setEarliestRenderedPublicationYear(
Integer earliestRenderedPublicationYear) {
this.earliestRenderedPublicationYear = earliestRenderedPublicationYear;
}
public Integer getLatestRenderedPublicationYear() {
return latestRenderedPublicationYear;
}
public void setLatestRenderedPublicationYear(
Integer latestRenderedPublicationYear) {
this.latestRenderedPublicationYear = latestRenderedPublicationYear;
}
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
}
public String getDownloadDataLink() {
return downloadDataLink;
}
public void setDownloadDataLink(String downloadDataLink) {
this.downloadDataLink = downloadDataLink;
}
public String getFullTimelineNetworkLink() {
return fullTimelineNetworkLink;
}
public void setFullTimelineNetworkLink(String fullTimelineNetworkLink) {
this.fullTimelineNetworkLink = fullTimelineNetworkLink;
}
public String getSparklineContent() {
return sparklineContent;
}
public void setSparklineContent(String shortSparklineContent) {
this.sparklineContent = shortSparklineContent;
}
public String getSparklineContext() {
return sparklineContext;
}
public void setSparklineContext(String shortSparklineContext) {
this.sparklineContext = shortSparklineContext;
}
public String getDownloadCoPIDataLink() {
return downloadCoPIDataLink;
}
public void setDownloadCoPIDataLink(String downloadCoPIDataLink) {
this.downloadCoPIDataLink = downloadCoPIDataLink;
}
public String getFullTimelineCoPINetworkLink() {
return fullTimelineCoPINetworkLink;
}
public void setFullTimelineCoPINetworkLink(String fullTimelineCoPINetworkLink) {
this.fullTimelineCoPINetworkLink = fullTimelineCoPINetworkLink;
}
public Integer getEarliestRenderedGrantYear() {
return earliestRenderedGrantYear;
}
public void setEarliestRenderedGrantYear(Integer earliestRenderedGrantYear) {
this.earliestRenderedGrantYear = earliestRenderedGrantYear;
}
public Integer getLatestRenderedGrantYear() {
return latestRenderedGrantYear;
}
public void setLatestRenderedGrantYear(Integer latestRenderedGrantYear) {
this.latestRenderedGrantYear = latestRenderedGrantYear;
}
}

View file

@ -1,59 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
/**
* @author bkoniden
* Deepak Konidena
*/
public class SubEntity extends Individual {
Set<BiboDocument> publications = new HashSet<BiboDocument>();
Map<String, Map<String, String>> personToPositionAndStartYear = new HashMap<String, Map<String, String>>();
public SubEntity(String individualURI) {
super(individualURI);
}
public Map<String, Map<String, String>> getPersonToPositionAndStartYear() {
return personToPositionAndStartYear;
}
public void setPersonToPositionAndStartYear(
Map<String, Map<String, String>> personToPositionAndStartYear) {
this.personToPositionAndStartYear = personToPositionAndStartYear;
}
public Set<BiboDocument> getDocuments() {
return publications;
}
public SubEntity(String individualURI, String individualLabel) {
super(individualURI, individualLabel);
}
@Override
public boolean equals(Object other){
boolean result = false;
if (other instanceof SubEntity){
SubEntity person = (SubEntity) other;
result = (this.getIndividualLabel().equals(person.getIndividualLabel())
&& this.getIndividualURI().equals(person.getIndividualURI()));
}
return result;
}
@Override
public int hashCode(){
return(41*(getIndividualLabel().hashCode() + 41*(getIndividualURI().hashCode())));
}
public void addPublications(BiboDocument biboDocument) {
this.publications.add(biboDocument);
}
}

View file

@ -1,148 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.DataSource;
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.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
/**
* This query runner is used to execute a sparql query that will fetch all the
* properties available for the provided individual URI.
*
* @author cdtank
*/
public class AllPropertiesQueryRunner implements QueryRunner<GenericQueryMap> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String filterRule, individualURI;
private DataSource dataSource;
private Log log;
public AllPropertiesQueryRunner(String individualURI,
String filterRule,
DataSource dataSource,
Log log) {
this.individualURI = individualURI;
this.filterRule = filterRule;
this.dataSource = dataSource;
this.log = log;
}
private GenericQueryMap createJavaValueObjects(ResultSet resultSet) {
GenericQueryMap queryResult = new GenericQueryMap();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
RDFNode predicateNode = solution.get(QueryFieldLabels.PREDICATE);
RDFNode objectNode = solution.get(QueryFieldLabels.OBJECT);
if (predicateNode != null && objectNode != null) {
queryResult.addEntry(predicateNode.toString(),
objectNode.toString());
}
}
return queryResult;
}
private ResultSet executeQuery(String queryText,
DataSource dataSource) {
QueryExecution queryExecution = null;
// try {
Query query = QueryFactory.create(queryText, SYNTAX);
// QuerySolutionMap qs = new QuerySolutionMap();
// qs.add("authPerson", queryParam); // bind resource to s
queryExecution = QueryExecutionFactory.create(query, dataSource);
// if (query.isSelectType()) {
return queryExecution.execSelect();
// }
// } finally {
// if (queryExecution != null) {
// queryExecution.close();
// }
//
// }
// return null;
}
private String generateGenericSparqlQuery(String queryURI, String filterRule) {
// Resource uri1 = ResourceFactory.createResource(queryURI);
String filterClause;
if (StringUtils.isNotBlank(filterRule)) {
filterClause = "FILTER ( " + filterRule + " ) . ";
} else {
filterClause = "";
}
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ "SELECT "
+ " (str(?predicate) as ?" + QueryFieldLabels.PREDICATE + ") "
+ " (str(?object) as ?" + QueryFieldLabels.OBJECT + ") "
+ "WHERE { "
+ "<" + queryURI + "> ?predicate ?object. "
+ filterClause
+ "}";
return sparqlQuery;
}
public GenericQueryMap getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.individualURI)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.individualURI);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Generic Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(
this.individualURI,
this.filterRule),
this.dataSource);
return createJavaValueObjects(resultSet);
}
}

View file

@ -1,131 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.DataSource;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
/**
* This query runner is used to run a generic sparql query based on the "select",
* "where" & "filter" rules provided to it.
*
* @author cdtank
*/
public class GenericQueryRunner implements QueryRunner<ResultSet> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String whereClause, individualURLParam;
private DataSource dataSource;
private Log log;
private Map<String, String> fieldLabelToOutputFieldLabel;
public GenericQueryRunner(String individualURLParam,
Map<String, String> fieldLabelToOutputFieldLabel,
String whereClause,
DataSource dataSource,
Log log) {
this.individualURLParam = individualURLParam;
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
this.whereClause = whereClause;
this.dataSource = dataSource;
this.log = log;
}
private ResultSet executeQuery(String queryText,
DataSource dataSource) {
QueryExecution queryExecution = null;
// try {
Query query = QueryFactory.create(queryText, SYNTAX);
// QuerySolutionMap qs = new QuerySolutionMap();
// qs.add("authPerson", queryParam); // bind resource to s
queryExecution = QueryExecutionFactory.create(query, dataSource);
//remocve this if loop after knowing what is describe & construct sparql stuff.
// if (query.isSelectType()) {
return queryExecution.execSelect();
// }
// } finally {
// if (queryExecution != null) {
// queryExecution.close();
// }
//
// }
// return null;
}
private String generateGenericSparqlQuery() {
// Resource uri1 = ResourceFactory.createResource(queryURI);
StringBuilder sparqlQuery = new StringBuilder();
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
sparqlQuery.append("SELECT\n");
for (Map.Entry<String, String> currentfieldLabelToOutputFieldLabel
: this.fieldLabelToOutputFieldLabel.entrySet()) {
sparqlQuery.append("\t(str(?" + currentfieldLabelToOutputFieldLabel.getKey() + ") as ?"
+ currentfieldLabelToOutputFieldLabel.getValue() + ")\n");
}
sparqlQuery.append("WHERE {\n");
sparqlQuery.append(this.whereClause);
sparqlQuery.append("}\n");
return sparqlQuery.toString();
}
public ResultSet getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.individualURLParam)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.individualURLParam);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Generic Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
this.dataSource);
return resultSet;
}
}

View file

@ -1,297 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Stroke;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Map.Entry;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfGState;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
public class PDFDocument {
static Stroke stroke = new BasicStroke(5.f, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND);
final static Color bg = Color.green;
final static Color fg = Color.black;
public PDFDocument(String authorName,
Map<String, Integer> yearToPublicationCount,
Document document,
PdfWriter pdfWriter) {
// setPreferredSize(new Dimension(600,400));
try {
document.addTitle("PDF Pipeline iText Prototype");
document.addAuthor(authorName);
document.addSubject("This example tests text, color, image, transparency & table functionality.");
document.addKeywords("text, color, image, transparency, table");
document.addCreator("Standalone PDF Renderer using iText");
Paragraph header = new Paragraph();
Font pageHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLDITALIC | Font.UNDERLINE);
Font featureHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, new BaseColor(Color.red));
header.add(new Chunk("PDF Pipeline Prototype v2 using iText\n",
pageHeaderStyle));
header.setSpacingAfter(15f);
document.add(header);
Paragraph content = new Paragraph();
content.add(new Chunk("Publication Count - Author Name - " + authorName,
featureHeaderStyle));
content.setSpacingAfter(15f);
document.add(content);
// step4
PdfPTable publicationCount = createTable(yearToPublicationCount);
document.add(publicationCount);
content = new Paragraph();
content.add(new Chunk("Transparency of Shapes",
featureHeaderStyle));
content.setSpacingAfter(15f);
document.add(content);
createTransparencyShapes(document, pdfWriter);
createImage(document, pdfWriter, featureHeaderStyle);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void createImage(Document document, PdfWriter writer,
Font featureHeaderStyle) throws BadElementException,
MalformedURLException, IOException, DocumentException {
Image imageSprite = Image.getInstance(new URL("http://lh3.ggpht.com/_4msVPAgKJv8/SCRYD-pPVKI/AAAAAAAAAYU/zUN963EPoZc/s1024/102_0609.JPG"));
imageSprite.setAbsolutePosition(400, 500);
imageSprite.scaleAbsolute(171.0f, 250.0f);
float imageSpriteY = document.getPageSize().getHeight() * 0.60f;
float imageSpriteX = document.getPageSize().getWidth() * 0.65f;
imageSprite.setAlignment(Image.UNDERLYING);
document.add(imageSprite);
PdfContentByte cb = writer.getDirectContent();
ColumnText ct = new ColumnText(cb);
Chunk imageHeader = new Chunk("Images",
featureHeaderStyle);
ct.addText(imageHeader);
ct.setAlignment(Element.ALIGN_LEFT);
ct.setSimpleColumn(imageSpriteX, imageSpriteY - imageSprite.getScaledHeight(),
imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY + imageSprite.getScaledHeight() + 20);
ct.go();
ct = new ColumnText(cb);
Chunk imageFooter = new Chunk("Footer to be set for a figure. Similar to 'image cpation'.",
FontFactory.getFont(FontFactory.TIMES_ROMAN, 8));
ct.addText(imageFooter);
ct.setAlignment(Element.ALIGN_CENTER);
ct.setSimpleColumn(imageSpriteX, imageSpriteY - 150, imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY);
ct.go();
}
private void createTransparencyShapes(Document document,
PdfWriter writer) throws Exception {
PdfContentByte cb = writer.getDirectContent();
pictureBackdrop(document.leftMargin(), 350, cb);
cb.saveState();
PdfGState gs1 = new PdfGState();
gs1.setFillOpacity(0.5f);
cb.setGState(gs1);
pictureCircles(document.leftMargin(), 350, cb);
cb.restoreState();
cb.resetRGBColorFill();
}
/**
* Prints a square and fills half of it with a gray rectangle.
* @param x
* @param y
* @param cb
* @throws Exception
*/
public void pictureBackdrop(float x, float y, PdfContentByte cb) throws Exception {
cb.setColorStroke(new BaseColor(Color.black));
cb.setColorFill(new BaseColor(Color.gray));
cb.rectangle(x, y, 100, 200);
cb.fill();
cb.setLineWidth(2);
cb.rectangle(x, y, 200, 200);
cb.stroke();
}
/**
* Prints 3 circles in different colors that intersect with eachother.
* @param x
* @param y
* @param cb
* @throws Exception
*/
public void pictureCircles(float x, float y, PdfContentByte cb) throws Exception {
cb.saveState();
PdfGState gs1 = new PdfGState();
gs1.setFillOpacity(1.0f);
cb.setGState(gs1);
cb.setColorFill(new BaseColor(Color.red));
cb.circle(x + 70, y + 70, 50);
cb.fill();
cb.restoreState();
cb.setColorFill(new BaseColor(Color.yellow));
cb.circle(x + 100, y + 130, 50);
cb.fill();
cb.setColorFill(new BaseColor(Color.blue));
cb.circle(x + 130, y + 70, 50);
cb.fill();
}
private PdfPTable createTable(Map<String, Integer> yearToPublicationCount) {
Font normalContentStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11);
Font summaryContentStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLDITALIC);
BaseColor summaryBackgroundColor = new BaseColor(0xEE, 0xEE, 0xEE);
BaseColor headerBackgroundColor = new BaseColor(0xC3, 0xD9, 0xFF);
BaseColor bodyBackgroundColor = new BaseColor(Color.white);
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(36.0f);
table.setHorizontalAlignment(Element.ALIGN_LEFT);
table.getDefaultCell().setBorderWidth(0.0f);
table.setHeaderRows(2);
PdfPCell cell;
cell = new PdfPCell(new Phrase("Publications per year", normalContentStyle));
setTableCaptionStyle(summaryBackgroundColor, cell);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Year", normalContentStyle));
setTableHeaderStyle(headerBackgroundColor, cell);
table.addCell(cell);
cell.setPhrase(new Phrase("Publications", normalContentStyle));
table.addCell(cell);
setTableBodyStyle(bodyBackgroundColor, cell);
int totalPublications = 0;
for (Entry<String, Integer> currentEntry : yearToPublicationCount.entrySet()) {
cell.setPhrase(new Phrase(currentEntry.getKey(), normalContentStyle));
table.addCell(cell);
cell.setPhrase(new Phrase(currentEntry.getValue().toString(), normalContentStyle));
table.addCell(cell);
totalPublications += currentEntry.getValue();
}
setTableFooterStyle(summaryBackgroundColor, cell);
cell.setPhrase(new Phrase("Total", summaryContentStyle));
table.addCell(cell);
cell.setPhrase(new Phrase(String.valueOf(totalPublications), summaryContentStyle));
table.addCell(cell);
return table;
}
private void setTableFooterStyle(BaseColor footerBackgroundColor,
PdfPCell cell) {
cell.setBorderWidth(0.0f);
cell.setBackgroundColor(footerBackgroundColor);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setPaddingTop(5f);
cell.setPaddingRight(10f);
cell.setPaddingBottom(5f);
cell.setPaddingLeft(10f);
}
private void setTableBodyStyle(BaseColor bodyBackgroundColor,
PdfPCell cell) {
cell.setBorderWidth(0.0f);
cell.setBackgroundColor(bodyBackgroundColor);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setPaddingTop(5f);
cell.setPaddingRight(10f);
cell.setPaddingBottom(5f);
cell.setPaddingLeft(10f);
}
private void setTableHeaderStyle(BaseColor headerBackgroundColor,
PdfPCell cell) {
cell.setBorderWidth(0.0f);
cell.setBackgroundColor(headerBackgroundColor);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setPaddingTop(5f);
cell.setPaddingRight(10f);
cell.setPaddingBottom(5f);
cell.setPaddingLeft(10f);
}
private void setTableCaptionStyle(BaseColor summaryBackgroundColor,
PdfPCell cell) {
cell.setBorderWidth(0.0f);
cell.setBackgroundColor(summaryBackgroundColor);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setPaddingTop(5.0f);
cell.setPaddingRight(10.0f);
cell.setPaddingBottom(5.0f);
cell.setPaddingLeft(10.0f);
cell.setColspan(2);
}
}

View file

@ -1,11 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
public interface QueryRunner<QueryResult> {
QueryResult getQueryResult() throws MalformedQueryParametersException;
}

View file

@ -1,16 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
public class UniqueIDGenerator {
private int nextNumericID = 1;
public int getNextNumericID() {
int nextNumericID = this.nextNumericID;
this.nextNumericID++;
return nextNumericID;
}
}

View file

@ -1,243 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.BiboDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.CoAuthorshipData;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.CoPIData;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Grant;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.CoPINode;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Node;
public class UtilityFunctions {
public static Map<String, Integer> getYearToPublicationCount(
Set<BiboDocument> authorDocuments) {
/*
* Create a map from the year to number of publications. Use the BiboDocument's
* parsedPublicationYear to populate the data.
* */
Map<String, Integer> yearToPublicationCount = new TreeMap<String, Integer>();
for (BiboDocument curr : authorDocuments) {
/*
* Increment the count because there is an entry already available for
* that particular year.
*
* I am pushing the logic to check for validity of year in "getPublicationYear" itself
* because,
* 1. We will be using getPub... multiple times & this will save us duplication of code
* 2. If we change the logic of validity of a pub year we would not have to make
* changes all throughout the codebase.
* 3. We are asking for a publication year & we should get a proper one or NOT at all.
* */
String publicationYear;
if (curr.getPublicationYear() != null) {
publicationYear = curr.getPublicationYear();
} else {
publicationYear = curr.getParsedPublicationYear();
}
if (yearToPublicationCount.containsKey(publicationYear)) {
yearToPublicationCount.put(publicationYear,
yearToPublicationCount
.get(publicationYear) + 1);
} else {
yearToPublicationCount.put(publicationYear, 1);
}
}
return yearToPublicationCount;
}
/**
* This method is used to return a mapping between publication year & all the co-authors
* that published with ego in that year.
* @param authorNodesAndEdges
* @return
*/
public static Map<String, Set<Node>> getPublicationYearToCoAuthors(
CoAuthorshipData authorNodesAndEdges) {
Map<String, Set<Node>> yearToCoAuthors = new TreeMap<String, Set<Node>>();
Node egoNode = authorNodesAndEdges.getEgoNode();
for (Node currNode : authorNodesAndEdges.getNodes()) {
/*
* We have already printed the Ego Node info.
* */
if (currNode != egoNode) {
for (String year : currNode.getYearToPublicationCount().keySet()) {
Set<Node> coAuthorNodes;
if (yearToCoAuthors.containsKey(year)) {
coAuthorNodes = yearToCoAuthors.get(year);
coAuthorNodes.add(currNode);
} else {
coAuthorNodes = new HashSet<Node>();
coAuthorNodes.add(currNode);
yearToCoAuthors.put(year, coAuthorNodes);
}
}
}
}
return yearToCoAuthors;
}
/**
* Currently the approach for slugifying filenames is naive. In future if there is need,
* we can write more sophisticated method.
* @param textToBeSlugified
* @return
*/
public static String slugify(String textToBeSlugified) {
String textBlockSeparator = "-";
return StringUtils.removeEnd(StringUtils.substring(textToBeSlugified.toLowerCase().trim()
.replaceAll("[^a-zA-Z0-9-]+", textBlockSeparator),
0,
VisConstants.MAX_NAME_TEXT_LENGTH),
textBlockSeparator);
}
public static void handleMalformedParameters(String errorMessage,
String errorPageTitle,
VitroRequest vitroRequest,
HttpServletRequest request,
HttpServletResponse response,
Log log)
throws ServletException, IOException {
Portal portal = vitroRequest.getPortal();
request.setAttribute("error", errorMessage);
RequestDispatcher requestDispatcher = request.getRequestDispatcher(Controllers.BASIC_JSP);
request.setAttribute("bodyJsp", "/templates/visualization/visualization_error.jsp");
request.setAttribute("portalBean", portal);
request.setAttribute("title", errorPageTitle);
try {
requestDispatcher.forward(request, response);
} catch (Exception e) {
log.error("EntityEditController could not forward to view.");
log.error(e.getMessage());
log.error(e.getStackTrace());
}
}
public static Map<String, Set<CoPINode>> getGrantYearToCoPI(
CoPIData pINodesAndEdges) {
Map<String, Set<CoPINode>> yearToCoPIs = new TreeMap<String, Set<CoPINode>>();
CoPINode egoNode = pINodesAndEdges.getEgoNode();
for (CoPINode currNode : pINodesAndEdges.getNodes()) {
/*
* We have already printed the Ego Node info.
* */
if (currNode != egoNode) {
for (String year : currNode.getYearToGrantCount().keySet()) {
Set<CoPINode> coPINodes;
if (yearToCoPIs.containsKey(year)) {
coPINodes = yearToCoPIs.get(year);
coPINodes.add(currNode);
} else {
coPINodes = new HashSet<CoPINode>();
coPINodes.add(currNode);
yearToCoPIs.put(year, coPINodes);
}
}
}
}
return yearToCoPIs;
}
public static Map<String, Integer> getYearToGrantCount(Set<Grant> pIGrants) {
/*
* Create a map from the year to number of grants. Use the Grant's
* parsedGrantStartYear to populate the data.
* */
Map<String, Integer> yearToGrantCount = new TreeMap<String, Integer>();
for (Grant curr : pIGrants) {
/*
* Increment the count because there is an entry already available for
* that particular year.
*
* I am pushing the logic to check for validity of year in "getGrantYear" itself
* because,
* 1. We will be using getGra... multiple times & this will save us duplication of code
* 2. If we change the logic of validity of a grant year we would not have to make
* changes all throughout the codebase.
* 3. We are asking for a grant year & we should get a proper one or NOT at all.
* */
String grantYear;
if (curr.getGrantStartYear() != null) {
grantYear = curr.getGrantStartYear();
} else {
grantYear = curr.getParsedGrantStartYear();
}
if (yearToGrantCount.containsKey(grantYear)) {
yearToGrantCount.put(grantYear,
yearToGrantCount
.get(grantYear) + 1);
} else {
yearToGrantCount.put(grantYear, 1);
}
}
return yearToGrantCount;
}
}

View file

@ -1,31 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.query.DataSource;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
/**
* This interface is being implemented by all the visualization request handlers like
* PersonLevelRequestHandler, PersonPublicationCountRequestHandler, UtilitiesRequestHandler
* etc. All the future visualizations <b>must</b> implement this because the ability of
* a visualization to be served to the users is dependent on it. We have implemented
* dependency injection mechanism & one of the conditions that is used to enable a visualization
* handler is its implementation of VisualizationRequestHandler.
*
* @author cdtank
*/
public interface VisualizationRequestHandler {
void generateVisualization(VitroRequest vitroRequest,
HttpServletRequest request,
HttpServletResponse response,
Log log,
DataSource dataSource);
}