diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/TestJava.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/TestJava.java index 803af7300..f16abce1e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/TestJava.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/TestJava.java @@ -46,10 +46,10 @@ public class TestJava { } Map yearToPublicationCount = new TreeMap(); - yearToPublicationCount.put("2003", 5); - yearToPublicationCount.put("2001", 5); - yearToPublicationCount.put("2002", 5); - yearToPublicationCount.put("2090", 7); +// yearToPublicationCount.put("2003", 5); +// yearToPublicationCount.put("2001", 5); +// yearToPublicationCount.put("2002", 5); +// yearToPublicationCount.put("2090", 7); yearToPublicationCount.put("Unknown", 6); Node egoNode; @@ -78,17 +78,31 @@ public class TestJava { } } - System.out.println(biboDocumentURLToCoAuthors); + System.out.println(yearToPublicationCount); - System.out.println( new HashMap(){{ + Map saHashMap = new HashMap(){{ put("sdsd", 4); - }}); + + }}; + System.out.println(saHashMap.keySet()); + + + Set keySet = new HashSet(yearToPublicationCount.keySet()); + keySet.remove("Unknown"); + + try { + System.out.println(Collections.min(keySet)); + } catch (Exception e) { + } + + + - System.out.println(yearToPublicationCount.get("44454454")); - System.out.println(Collections.min(yearToPublicationCount.keySet())); String emptyString = ""; System.out.println(emptyString.isEmpty()); + + System.out.println(yearToPublicationCount); // System.out.println(Collections.max(yearToPublicationCount.keySet())); // System.out.println(Collections.min(yearToPublicationCount.keySet())); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipGraphMLWriter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipGraphMLWriter.java new file mode 100644 index 000000000..787c1538f --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipGraphMLWriter.java @@ -0,0 +1,327 @@ +package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; +import java.util.Set; + +import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationController; +import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; +import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Edge; +import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Node; + +public class CoAuthorshipGraphMLWriter { + + private StringBuilder coAuthorshipGraphMLContent; + + public final String GRAPHML_HEADER = "" + + " \n" + + " \n\n"; + + private final String GRAPHML_FOOTER = ""; + + public CoAuthorshipGraphMLWriter(VisVOContainer visVOContainer) { + + coAuthorshipGraphMLContent = createCoAuthorshipGraphMLContent(visVOContainer); + + } + + private StringBuilder createCoAuthorshipGraphMLContent( + VisVOContainer visVOContainer) { + + StringBuilder graphMLContent = new StringBuilder(); + + graphMLContent.append(GRAPHML_HEADER); + + /* + * We are side-effecting "graphMLContent" object in this method since creating + * another String object to hold key definition data will be redundant & will + * not serve the purpose. + * */ + generateKeyDefinitionContent(visVOContainer, graphMLContent); + + /* + * Used to generate graph content. It will contain both the nodes & edge information. + * We are side-effecting "graphMLContent". + * */ + generateGraphContent(visVOContainer, graphMLContent); + + graphMLContent.append(GRAPHML_FOOTER); + + return graphMLContent; + } + + private void generateGraphContent(VisVOContainer visVOContainer, + StringBuilder graphMLContent) { + + graphMLContent.append("\n\n"); + + generateNodeSectionContent(visVOContainer, graphMLContent); + + generateEdgeSectionContent(visVOContainer, graphMLContent); + + graphMLContent.append("\n"); + + + + + } + + private void generateEdgeSectionContent(VisVOContainer visVOContainer, + StringBuilder graphMLContent) { + + graphMLContent.append("\n"); + + Set edges = visVOContainer.getEdges(); + + + for (Edge currentEdge : edges) { + + /* + * This method actually creates the XML code for a single edge. "graphMLContent" + * is being side-effected. + * */ + getEdgeContent(graphMLContent, currentEdge); + + } + + } + + private void getEdgeContent(StringBuilder graphMLContent, Edge currentEdge) { + + graphMLContent.append("\n"); + + graphMLContent.append("\t" + currentEdge.getSourceNode().getNodeName() + "\n"); + graphMLContent.append("\t" + currentEdge.getTargetNode().getNodeName() + "\n"); + + graphMLContent.append("\t" + + currentEdge.getNumOfCoAuthoredWorks() + + "\n"); + + if (currentEdge.getEarliestCollaborationYearCount() != null) { + + /* + * There is no clean way of getting the map contents in java even though + * we are sure to have only one entry on the map. So using the for loop. + * I am feeling dirty just about now. + * */ + for (Map.Entry publicationInfo : + currentEdge.getEarliestCollaborationYearCount().entrySet()) { + + graphMLContent.append("\t" + + publicationInfo.getKey() + + "\n"); + + graphMLContent.append("\t" + + publicationInfo.getValue() + + "\n"); + + + } + + } + + if (currentEdge.getLatestCollaborationYearCount() != null) { + + for (Map.Entry publicationInfo : + currentEdge.getLatestCollaborationYearCount().entrySet()) { + + graphMLContent.append("\t" + + publicationInfo.getKey() + + "\n"); + + graphMLContent.append("\t" + + publicationInfo.getValue() + + "\n"); + } + + } + + if (currentEdge.getUnknownCollaborationYearCount() != null) { + + graphMLContent.append("\t" + + currentEdge.getUnknownCollaborationYearCount() + + "\n"); + + } + + graphMLContent.append("\n"); + + + } + + private void generateNodeSectionContent(VisVOContainer visVOContainer, + StringBuilder graphMLContent) { + + graphMLContent.append("\n"); + + Node egoNode = visVOContainer.getEgoNode(); + Set authorNodes = visVOContainer.getNodes(); + + /* + * This method actually creates the XML code for a single node. "graphMLContent" + * is being side-effected. The egoNode is added first because this is the "requirement" + * of the co-author vis. Ego should always come first. + * + * */ + getNodeContent(graphMLContent, egoNode); + + + for (Node currNode : authorNodes) { + + /* + * We have already printed the Ego Node info. + * */ + if (currNode != egoNode) { + + getNodeContent(graphMLContent, currNode); + + } + + } + + } + + private void getNodeContent(StringBuilder graphMLContent, Node node) { + + String profileURL = null; + try { + profileURL = "/individual?" + + VisualizationFrameworkConstants.INDIVIDUAL_URI_URL_HANDLE + + "=" + URLEncoder.encode(node.getNodeURL(), + VisualizationController + .URL_ENCODING_SCHEME).toString(); + } catch (UnsupportedEncodingException e) { + System.err.println("URL Encoding ERRor. Move this to use log.error ASAP"); + } + + + + graphMLContent.append("\n"); + graphMLContent.append("\t" + node.getNodeURL() + "\n"); + graphMLContent.append("\t" + node.getNodeName() + "\n"); + + if (profileURL != null) { + graphMLContent.append("\t" + profileURL + "\n"); + } + + + graphMLContent.append("\t" + + node.getNumOfAuthoredWorks() + + "\n"); + + if (node.getEarliestPublicationYearCount() != null) { + + /* + * There is no clean way of getting the map contents in java even though + * we are sure to have only one entry on the map. So using the for loop. + * I am feeling dirty just about now. + * */ + for (Map.Entry publicationInfo : + node.getEarliestPublicationYearCount().entrySet()) { + + graphMLContent.append("\t" + + publicationInfo.getKey() + + "\n"); + + graphMLContent.append("\t" + + publicationInfo.getValue() + + "\n"); + + + } + + } + + if (node.getLatestPublicationYearCount() != null) { + + for (Map.Entry publicationInfo : + node.getLatestPublicationYearCount().entrySet()) { + + graphMLContent.append("\t" + + publicationInfo.getKey() + + "\n"); + + graphMLContent.append("\t" + + publicationInfo.getValue() + + "\n"); + + + } + + } + + if (node.getUnknownPublicationYearCount() != null) { + + graphMLContent.append("\t" + + node.getUnknownPublicationYearCount() + + "\n"); + + } + + graphMLContent.append("\n"); + } + + private void generateKeyDefinitionContent(VisVOContainer visVOContainer, + StringBuilder graphMLContent) { + + /* + * Generate the key definition content for node. + * */ + getKeyDefinitionFromSchema(visVOContainer.getNodeSchema(), graphMLContent); + + /* + * Generate the key definition content for edge. + * */ + getKeyDefinitionFromSchema(visVOContainer.getEdgeSchema(), graphMLContent); + + + } + + private void getKeyDefinitionFromSchema(Set> schema, + StringBuilder graphMLContent) { + + for (Map currentNodeSchemaAttribute : schema) { + + graphMLContent.append("\n currentAttributeKey : currentNodeSchemaAttribute.entrySet()) { + + graphMLContent.append(currentAttributeKey.getKey() + + "=\"" + currentAttributeKey.getValue() + + "\" "); + + } + + if (currentNodeSchemaAttribute.containsKey("default")) { + + graphMLContent.append(">\n"); + graphMLContent.append(""); + graphMLContent.append(currentNodeSchemaAttribute.get("default")); + graphMLContent.append("\n"); + graphMLContent.append("\n"); + + } else { + graphMLContent.append("/>\n"); + } + + } + } + + + + + + + + + + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/QueryHandler.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/QueryHandler.java index 80ad31027..380a8d470 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/QueryHandler.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/QueryHandler.java @@ -331,7 +331,7 @@ public class QueryHandler { + " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") " + " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") " + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") " - + " (str(?coAuthorLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") " + + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") " + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") " + " (str(?documentLabel) as ?" + QueryFieldLabels.DOCUMENT_LABEL + ") " + " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") " diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisVOContainer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisVOContainer.java index b86060bb9..7cfb31030 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisVOContainer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisVOContainer.java @@ -1,5 +1,8 @@ package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Set; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Edge; @@ -10,7 +13,9 @@ public class VisVOContainer { private Set nodes; private Set edges; private Node egoNode; - + private Set> NODE_SCHEMA; + private Set> EDGE_SCHEMA; + public VisVOContainer(Node egoNode, Set nodes, Set edges) { this.egoNode = egoNode; this.nodes = nodes; @@ -29,4 +34,199 @@ public class VisVOContainer { return egoNode; } + /* + * Node Schema for graphML + * */ + public Set> getNodeSchema() { + + if (NODE_SCHEMA == null) { + NODE_SCHEMA = initializeNodeSchema(); + } + + return NODE_SCHEMA; + } + + /* + * Edge Schema for graphML + * */ + public Set> getEdgeSchema() { + + if (EDGE_SCHEMA == null) { + EDGE_SCHEMA = initializeEdgeSchema(); + } + + return EDGE_SCHEMA; + } + + private Set> initializeEdgeSchema() { + + Set> edgeSchema = new HashSet>(); + + Map schemaAttributes = new LinkedHashMap(); + + schemaAttributes.put("id", "collaborator1"); + schemaAttributes.put("for", "edge"); + schemaAttributes.put("attr.name", "collaborator1"); + schemaAttributes.put("attr.type", "string"); + + edgeSchema.add(schemaAttributes); + + schemaAttributes = new LinkedHashMap(); + + schemaAttributes.put("id", "collaborator2"); + schemaAttributes.put("for", "edge"); + schemaAttributes.put("attr.name", "collaborator2"); + schemaAttributes.put("attr.type", "string"); + + edgeSchema.add(schemaAttributes); + + schemaAttributes = new LinkedHashMap(); + + 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(); + + 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(); + + 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(); + + 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(); + + 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(); + + 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> initializeNodeSchema() { + + Set> nodeSchema = new HashSet>(); + + Map schemaAttributes = new LinkedHashMap(); + + schemaAttributes.put("id", "url"); + schemaAttributes.put("for", "node"); + schemaAttributes.put("attr.name", "url"); + schemaAttributes.put("attr.type", "string"); + + nodeSchema.add(schemaAttributes); + + schemaAttributes = new LinkedHashMap(); + + schemaAttributes.put("id", "name"); + schemaAttributes.put("for", "node"); + schemaAttributes.put("attr.name", "name"); + schemaAttributes.put("attr.type", "string"); + + nodeSchema.add(schemaAttributes); + + schemaAttributes = new LinkedHashMap(); + + 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(); + + 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(); + + 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(); + + 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(); + + 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(); + + 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(); + + 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; + } + + + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisualizationRequestHandler.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisualizationRequestHandler.java index f63c08e37..d50cdb631 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisualizationRequestHandler.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/VisualizationRequestHandler.java @@ -352,7 +352,7 @@ public class VisualizationRequestHandler { + "\n\tLatest Publication - " + egoNode.getLatestPublicationYearCount() + "\n\tUnknown Publication - " + egoNode.getUnknownPublicationYearCount()); - authorNodes.remove(egoNode); +// authorNodes.remove(egoNode); for (Node currNode : authorNodes) { @@ -360,7 +360,9 @@ public class VisualizationRequestHandler { printWriter.append(currNode.getNodeID() + " - " + currNode.getNodeName() + " -> " + currNode.getNodeURL() + "\n"); printWriter.append("\tEarliest Publication - " + currNode.getEarliestPublicationYearCount() + "\n\tLatest Publication - " + currNode.getLatestPublicationYearCount() - + "\n\tUnknown Publication - " + currNode.getUnknownPublicationYearCount()); + + "\n\tUnknown Publication - " + currNode.getUnknownPublicationYearCount() + + "\n\tTotal Publications - " + currNode.getNumOfAuthoredWorks()); + } @@ -371,7 +373,8 @@ public class VisualizationRequestHandler { + currentEdge.getTargetNode().getNodeName() + "\n"); printWriter.append("\tEarliest Collaboration - " + currentEdge.getEarliestCollaborationYearCount() + "\n\tLatest Collaboration - " + currentEdge.getLatestCollaborationYearCount() - + "\n\tUnknown Collaboration - " + currentEdge.getUnknownCollaborationYearCount()); + + "\n\tUnknown Collaboration - " + currentEdge.getUnknownCollaborationYearCount() + + "\n\tTotal Collaboration - " + currentEdge.getNumOfCoAuthoredWorks()); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java index 80107578e..8d06f0689 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/constants/QueryFieldLabels.java @@ -23,7 +23,7 @@ public class QueryFieldLabels { * Co-Author related field labels * */ public static final String CO_AUTHOR_URL = "coAuthPersonLit"; - public static final String CO_AUTHOR_LABEL = "coAuthorLabelLit"; + public static final String CO_AUTHOR_LABEL = "coAuthPersonLabelLit"; /* * College related field labels diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Edge.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Edge.java index 00f895a39..76c1c1451 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Edge.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Edge.java @@ -67,16 +67,27 @@ public class Edge { yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments); } - final String earliestYear = Collections.min(yearToPublicationCount.keySet()); - final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear); + /* + * We do not want to consider the default publication year when we are checking + * for the min or max publication year. + * */ + Set yearsToBeConsidered = new HashSet(yearToPublicationCount.keySet()); + yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR); /* - * If there is no minimum year available then we should imply so by returning a "null". + * 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 (!earliestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { + if (yearsToBeConsidered.size() > 0) { + final String earliestYear = Collections.min(yearsToBeConsidered); + final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear); + return new HashMap(){{ - put(earliestYear, earliestYearPubCount); - }}; + put(earliestYear, earliestYearPubCount); + }}; } else { return null; } @@ -88,36 +99,45 @@ public class Edge { yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments); } - final String latestYear = Collections.max(yearToPublicationCount.keySet()); - final Integer latestYearPubCount = yearToPublicationCount.get(latestYear); + /* + * We do not want to consider the default publication year when we are checking + * for the min or max publication year. + * */ + Set yearsToBeConsidered = new HashSet(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 (!latestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { + if (yearsToBeConsidered.size() > 0) { + final String latestYear = Collections.max(yearsToBeConsidered); + final Integer latestYearPubCount = yearToPublicationCount.get(latestYear); + return new HashMap(){{ - put(latestYear, latestYearPubCount); - }}; + put(latestYear, latestYearPubCount); + }}; } else { return null; } } @SuppressWarnings("serial") - public Map getUnknownCollaborationYearCount() { + public Integer getUnknownCollaborationYearCount() { if (yearToPublicationCount == null) { yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments); } - final Integer unknownYearPubCount = yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR); + 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 new HashMap(){{ - put(VOConstants.DEFAULT_PUBLICATION_YEAR, unknownYearPubCount); - }}; + return unknownYearPubCount; } else { return null; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Node.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Node.java index 5330325c6..24efd0a4e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Node.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/valueobjects/Node.java @@ -66,18 +66,30 @@ public class Node extends Individual { public Map getEarliestPublicationYearCount() { if (yearToPublicationCount == null) { yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments); + System.out.println("early - " + yearToPublicationCount); } - final String earliestYear = Collections.min(yearToPublicationCount.keySet()); - final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear); + /* + * We do not want to consider the default publication year when we are checking + * for the min or max publication year. + * */ + Set yearsToBeConsidered = new HashSet(yearToPublicationCount.keySet()); + yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR); /* - * If there is no minimum year available then we should imply so by returning a "null". + * 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 (!earliestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { + if (yearsToBeConsidered.size() > 0) { + final String earliestYear = Collections.min(yearsToBeConsidered); + final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear); + return new HashMap(){{ - put(earliestYear, earliestYearPubCount); - }}; + put(earliestYear, earliestYearPubCount); + }}; } else { return null; } @@ -89,36 +101,45 @@ public class Node extends Individual { yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments); } - final String latestYear = Collections.max(yearToPublicationCount.keySet()); - final Integer latestYearPubCount = yearToPublicationCount.get(latestYear); + /* + * We do not want to consider the default publication year when we are checking + * for the min or max publication year. + * */ + Set yearsToBeConsidered = new HashSet(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 (!latestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { + if (yearsToBeConsidered.size() > 0) { + final String latestYear = Collections.max(yearsToBeConsidered); + final Integer latestYearPubCount = yearToPublicationCount.get(latestYear); + return new HashMap(){{ - put(latestYear, latestYearPubCount); - }}; + put(latestYear, latestYearPubCount); + }}; } else { return null; } + } - @SuppressWarnings("serial") - public Map getUnknownPublicationYearCount() { + public Integer getUnknownPublicationYearCount() { if (yearToPublicationCount == null) { yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments); } - final Integer unknownYearPubCount = yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR); + 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 new HashMap(){{ - put(VOConstants.DEFAULT_PUBLICATION_YEAR, unknownYearPubCount); - }}; + return unknownYearPubCount; } else { return null; }