1. Made changes to the value objects structure/inheritance.

2. Removed unnecessary fields from BiboDocument.
3. Changes to the Query & Vis request handlers to incorporate changes to the VOs.
This commit is contained in:
cdtank 2010-06-23 01:25:03 +00:00
parent 7bb0b8a17d
commit 4a74799a18
10 changed files with 114 additions and 108 deletions

View file

@ -46,6 +46,9 @@ public class TestJava {
yearToPublicationCount.put("2090", 7);
yearToPublicationCount.put("2087", 6);
String emptyString = "";
System.out.println(emptyString.isEmpty());
// System.out.println(Collections.max(yearToPublicationCount.keySet()));
// System.out.println(Collections.min(yearToPublicationCount.keySet()));

View file

@ -120,8 +120,11 @@ public class QueryHandler {
currentEmployee.addParentDepartment(currentDepartment);
} else {
currentEmployee = new VivoEmployee(employeeNode.toString(), currentEmployeeType, currentDepartment);
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
currentEmployee.setIndividualLabel(authorLabelNode.toString());
}
employeeURLToVO.put(employeeNode.toString(), currentEmployee);
}
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
@ -203,11 +206,6 @@ public class QueryHandler {
biboDocument.setPublicationYear(publicationYearNode.toString());
}
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
biboDocument.setAuthorLabel(authorLabelNode.toString());
}
return biboDocument;
}
@ -278,7 +276,7 @@ public class QueryHandler {
String ontologyHandle) {
String sparqlQuery = " {?department " + ontologyHandle + " ?" + employeeHandle + " . "
+ "?" + employeeHandle + " rdf:type foaf:Person; rdfs:label ?authorLabel. "
+ "?" + employeeHandle + " rdf:type foaf:Individual; rdfs:label ?authorLabel. "
+ "OPTIONAL { ?" + employeeHandle + " vivo:authorOf ?document ." +
" ?document rdf:type bibo:Document ." +
" ?document rdfs:label ?documentLabel ." +

View file

@ -33,6 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.visualization.PDFDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.BiboDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Individual;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.VivoCollegeOrSchool;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.VivoDepartmentOrDivision;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.VivoEmployee;
@ -132,13 +133,16 @@ public class VisualizationRequestHandler {
* It is ugly!
* */
if (DATA_RENDER_MODE_URL_VALUE.equalsIgnoreCase(renderMode)) {
prepareVisualizationQueryDataResponse(departmentToPublicationsOverTime,
prepareVisualizationQueryDataResponse(
departmentToPublicationsOverTime,
queryManager.getCollegeURLToVO());
System.out.println(publishedYearsForCollege);
log.debug(publishedYearsForCollege);
return;
}
/*
if (PDF_RENDER_MODE_URL_VALUE.equalsIgnoreCase(renderMode)) {
prepareVisualizationQueryPDFResponse(authorDocuments,
@ -263,8 +267,9 @@ public class VisualizationRequestHandler {
return departmentYearToPublicationCount;
}
private void prepareVisualizationQueryPDFResponse(List<BiboDocument> authorDocuments,
Map<String, Integer> yearToPublicationCount) {
private void prepareVisualizationQueryPDFResponse(Individual college,
List<BiboDocument> authorDocuments,
Map<String, Integer> yearToPublicationCount) {
String authorName = null;
@ -273,7 +278,7 @@ public class VisualizationRequestHandler {
* individual.
* */
if (authorDocuments.size() > 0) {
authorName = ((BiboDocument) authorDocuments.get(0)).getAuthorLabel();
authorName = college.getIndividualLabel();
}
/*
@ -298,29 +303,22 @@ public class VisualizationRequestHandler {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
document.open();
// document.add(new Paragraph("JSS Chintan Deepak Tank "));
// document.add(Chunk.NEWLINE);
// document.add(new Paragraph("The method used to generate this PDF was: TEST OPST"));
PDFDocument pdfDocument = new PDFDocument(authorName, yearToPublicationCount, document, pdfWriter);
PDFDocument pdfDocument = new PDFDocument(authorName,
yearToPublicationCount,
document,
pdfWriter);
document.close();
// setting some response headers
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
// setting the content type
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
baos.writeTo(responseOutputStream);
responseOutputStream.flush();
responseOutputStream.close();
// System.out.println("done with response o/p stream");
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
@ -340,7 +338,7 @@ public class VisualizationRequestHandler {
* */
// System.out.println(collegeURLToVO);
if (collegeURLToVO.size() > 0) {
// collegeName = ((VivoCollegeOrSchool) collegeURLToVO.entrySet().iterator().next()).getCollegeLabel();
collegeName = ((VivoCollegeOrSchool) collegeURLToVO.values().iterator().next()).getCollegeLabel();
}
/*
@ -350,8 +348,7 @@ public class VisualizationRequestHandler {
collegeName = "";
}
String outputFileName = slugify(collegeName + "depts-pub-count")
+ ".csv";
String outputFileName = slugify(collegeName + "depts-pub-count") + ".csv";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=" + outputFileName);
@ -439,7 +436,7 @@ public class VisualizationRequestHandler {
request.setAttribute("bodyJsp", "/templates/visualization/publication_count.jsp");
request.setAttribute("portalBean", portal);
request.setAttribute("title", "Person Publication Count Visualization");
request.setAttribute("title", "Individual Publication Count Visualization");
request.setAttribute("scripts", "/templates/visualization/visualization_scripts.jsp");
}
@ -468,7 +465,7 @@ public class VisualizationRequestHandler {
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 - Person Publication Count");
request.setAttribute("title", "Visualization Query Error - Individual Publication Count");
try {
requestDispatcher.forward(request, response);

View file

@ -24,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP
import edu.cornell.mannlib.vitro.webapp.visualization.sparqlutils.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.sparqlutils.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.BiboDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Individual;
@ -39,6 +40,12 @@ public class QueryHandler {
private String queryParam, resultFormatParam, rdfResultFormatParam;
private DataSource dataSource;
private Individual author;
public Individual getAuthor() {
return author;
}
private Log log;
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "" +
@ -106,14 +113,19 @@ public class QueryHandler {
biboDocument.setPublicationYear(publicationYearNode.toString());
}
/*
* Since we are getting publication count for just one author at a time we need
* to create only one "Individual" instance. We test against the null for "author" to
* make sure that it has not already been instantiated.
* */
RDFNode authorURLNode = solution.get(QueryFieldLabels.AUTHOR_URL);
if (authorURLNode != null) {
biboDocument.setAuthorURL(authorURLNode.toString());
}
if (authorURLNode != null && author == null) {
author = new Individual(authorURLNode.toString());
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
author.setIndividualLabel(authorLabelNode.toString());
}
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
biboDocument.setAuthorLabel(authorLabelNode.toString());
}
authorDocuments.add(biboDocument);
@ -154,7 +166,7 @@ public class QueryHandler {
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE
+ "(str(<" + queryURI + ">) as ?authPersonLit) "
+ "WHERE { "
+ "<" + queryURI + "> rdf:type foaf:Person ; vivo:authorOf ?document ; rdfs:label ?authorLabel. "
+ "<" + queryURI + "> rdf:type foaf:Individual ; vivo:authorOf ?document ; rdfs:label ?authorLabel. "
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE
+ "}";

View file

@ -31,6 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.PDFDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.VisualizationCodeGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.BiboDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Individual;
public class VisualizationRequestHandler {
@ -104,15 +105,17 @@ public class VisualizationRequestHandler {
* It is ugly!
* */
if (DATA_RENDER_MODE_URL_VALUE.equalsIgnoreCase(renderMode)) {
prepareVisualizationQueryDataResponse(authorDocuments,
prepareVisualizationQueryDataResponse(queryManager.getAuthor(),
authorDocuments,
yearToPublicationCount);
return;
}
if (PDF_RENDER_MODE_URL_VALUE.equalsIgnoreCase(renderMode)) {
prepareVisualizationQueryPDFResponse(authorDocuments,
yearToPublicationCount);
prepareVisualizationQueryPDFResponse(queryManager.getAuthor(),
authorDocuments,
yearToPublicationCount);
return;
}
@ -182,7 +185,7 @@ public class VisualizationRequestHandler {
}
private void prepareVisualizationQueryPDFResponse(List<BiboDocument> authorDocuments,
private void prepareVisualizationQueryPDFResponse(Individual author, List<BiboDocument> authorDocuments,
Map<String, Integer> yearToPublicationCount) {
String authorName = null;
@ -192,7 +195,7 @@ public class VisualizationRequestHandler {
* individual.
* */
if (authorDocuments.size() > 0) {
authorName = ((BiboDocument) authorDocuments.get(0)).getAuthorLabel();
authorName = author.getIndividualLabel();
}
/*
@ -239,7 +242,7 @@ public class VisualizationRequestHandler {
}
}
private void prepareVisualizationQueryDataResponse(List<BiboDocument> authorDocuments,
private void prepareVisualizationQueryDataResponse(Individual author, List<BiboDocument> authorDocuments,
Map<String, Integer> yearToPublicationCount) {
String authorName = null;
@ -249,7 +252,7 @@ public class VisualizationRequestHandler {
* individual.
* */
if (authorDocuments.size() > 0) {
authorName = ((BiboDocument) authorDocuments.get(0)).getAuthorLabel();
authorName = author.getIndividualLabel();
}
/*
@ -323,7 +326,7 @@ public class VisualizationRequestHandler {
request.setAttribute("bodyJsp", "/templates/visualization/publication_count.jsp");
request.setAttribute("portalBean", portal);
request.setAttribute("title", "Person Publication Count visualization");
request.setAttribute("title", "Individual Publication Count visualization");
request.setAttribute("scripts", "/templates/visualization/visualization_scripts.jsp");
}
@ -352,7 +355,7 @@ public class VisualizationRequestHandler {
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 - Person Publication Count");
request.setAttribute("title", "Visualization Query Error - Individual Publication Count");
try {
requestDispatcher.forward(request, response);

View file

@ -4,50 +4,24 @@ import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BiboDocument {
public class BiboDocument extends Individual{
public static final String DEFAULT_PUBLICATION_YEAR = "Unknown";
public static final int MINIMUM_PUBLICATION_YEAR = 1800;
private static final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);
private String authorURL;
private String authorLabel;
private String documentURL;
private String documentMoniker;
private String documentLabel;
private String documentBlurb;
private String documentDescription;
private String publicationYear;
private String parsedPublicationYear = DEFAULT_PUBLICATION_YEAR;
public BiboDocument(String documentURL) {
this.documentURL = documentURL;
}
public String getAuthorURL() {
return authorURL;
}
public void setAuthorURL(String authorURL) {
this.authorURL = authorURL;
}
public String getAuthorLabel() {
return authorLabel;
}
public void setAuthorLabel(String authorLabel) {
this.authorLabel = authorLabel;
super(documentURL);
}
public String getDocumentURL() {
return documentURL;
}
public void setDocumentURL(String documentURL) {
this.documentURL = documentURL;
return this.getIndividualURL();
}
public String getDocumentMoniker() {
@ -59,11 +33,11 @@ public class BiboDocument {
}
public String getDocumentLabel() {
return documentLabel;
return this.getIndividualLabel();
}
public void setDocumentLabel(String documentLabel) {
this.documentLabel = documentLabel;
this.setIndividualLabel(documentLabel);
}
public String getDocumentBlurb() {

View file

@ -0,0 +1,30 @@
package edu.cornell.mannlib.vitro.webapp.visualization.valueobjects;
public class Individual {
private String individualLabel;
private String individualURL;
public Individual(String individualURL, String individualLabel) {
this.individualLabel = individualLabel;
this.individualURL = individualURL;
}
public Individual(String individualURL) {
this(individualURL, "");
}
public String getIndividualLabel() {
return individualLabel;
}
public void setIndividualLabel(String individualLabel) {
this.individualLabel = individualLabel;
}
public String getIndividualURL() {
return individualURL;
}
}

View file

@ -9,14 +9,12 @@ import java.util.Set;
* @author cdtank
*
*/
public class VivoCollegeOrSchool {
public class VivoCollegeOrSchool extends Individual {
private String collegeURL;
private String collegeLabel;
private Set<VivoDepartmentOrDivision> departments = new HashSet<VivoDepartmentOrDivision>();
public VivoCollegeOrSchool(String collegeURL) {
this.collegeURL = collegeURL;
super(collegeURL);
}
public Set<VivoDepartmentOrDivision> getDepartments() {
@ -28,19 +26,15 @@ public class VivoCollegeOrSchool {
}
public String getCollegeURL() {
return collegeURL;
return this.getIndividualURL();
}
public String getCollegeLabel() {
if (collegeLabel != null) {
return collegeLabel;
} else {
return "";
}
return this.getIndividualLabel();
}
public void setCollegeLabel(String collegeLabel) {
this.collegeLabel = collegeLabel;
this.setIndividualLabel(collegeLabel);
}
}

View file

@ -9,14 +9,12 @@ import java.util.Set;
* @author cdtank
*
*/
public class VivoDepartmentOrDivision {
public class VivoDepartmentOrDivision extends Individual {
private String departmentURL;
private String departmentLabel;
private Set<VivoCollegeOrSchool> parentColleges = new HashSet<VivoCollegeOrSchool>();
public VivoDepartmentOrDivision(String departmentURL, VivoCollegeOrSchool parentCollege) {
this.departmentURL = departmentURL;
super(departmentURL);
addParentCollege(parentCollege);
}
@ -29,19 +27,15 @@ public class VivoDepartmentOrDivision {
}
public String getDepartmentURL() {
return departmentURL;
return this.getIndividualURL();
}
public String getDepartmentLabel() {
if (departmentLabel != null) {
return departmentLabel;
} else {
return "";
}
return this.getIndividualLabel();
}
public void setDepartmentLabel(String departmentLabel) {
this.departmentLabel = departmentLabel;
this.setIndividualLabel(departmentLabel);
}
}

View file

@ -11,24 +11,25 @@ import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.VOConstants.E
* @author cdtank
*
*/
public class VivoEmployee {
public class VivoEmployee extends Individual{
private String employeeURL;
private EmployeeType employeeType;
private Set<VivoDepartmentOrDivision> parentDepartments = new HashSet<VivoDepartmentOrDivision>();
private Set<BiboDocument> authorDocuments = new HashSet<BiboDocument>();
public VivoEmployee(String employeeURL, EmployeeType employeeType, VivoDepartmentOrDivision parentDepartment) {
this.employeeURL = employeeURL;
public VivoEmployee(String employeeURL,
EmployeeType employeeType,
VivoDepartmentOrDivision parentDepartment) {
super(employeeURL);
addParentDepartment(parentDepartment);
}
public String getEmployeeURL() {
return employeeURL;
return this.getIndividualURL();
}
public void setEmployeeURL(String employeeURL) {
this.employeeURL = employeeURL;
public String getEmployeeName() {
return this.getIndividualLabel();
}
public EmployeeType getEmployeeType() {