/**
   * @param doc the article xml document in question
   * @param authors list of article authors
   * @return an xml-sorted map of article affiliates and their respective authors
   */
  public Map<String, List<AuthorView>> getAuthorsByAffiliation(
      Document doc, List<AuthorView> authors) throws RuntimeException {

    Map<String, List<AuthorView>> authorsByAffiliation =
        new LinkedHashMap<String, List<AuthorView>>();

    try {
      /*
      <String, String> in the following case is, in xpath parlance, <//aff@id>,<//aff/addr-line/text() but
      AuthorView cues on the //aff/addr-line/text() part, so we need to add a level of indirection
      */
      Map<String, String> originalAffiliateMap =
          AuthorsXmlExtractor.getAffiliateMap(doc, xPathUtil);
      for (Map.Entry<String, String> entry : originalAffiliateMap.entrySet()) {
        authorsByAffiliation.put(entry.getValue(), new ArrayList<AuthorView>());
      }

      for (AuthorView currentAuthorView : authors) {
        for (String affiliate : currentAuthorView.getAffiliations()) {

          List<AuthorView> authorList = authorsByAffiliation.get(affiliate);
          if (authorList != null) {
            authorsByAffiliation.get(affiliate).add(currentAuthorView);
          } else {
            log.error(
                new StringBuilder("Could not associate ")
                    .append(currentAuthorView.getFullName())
                    .append(" with institution ")
                    .append(affiliate)
                    .toString());
          }
        }
      }
    } catch (XPathException e) {
      throw new RuntimeException();
    }

    // make sure to return only non-empty lists
    Map<String, List<AuthorView>> tempAuthorAffiliations =
        new LinkedHashMap<String, List<AuthorView>>();
    for (Map.Entry<String, List<AuthorView>> affiliationMapping : authorsByAffiliation.entrySet()) {

      if (affiliationMapping.getValue().size() > 0) {
        tempAuthorAffiliations.put(affiliationMapping.getKey(), affiliationMapping.getValue());
      }
    }
    authorsByAffiliation = tempAuthorAffiliations;

    return authorsByAffiliation;
  }
Exemplo n.º 2
0
  protected void checkAnnotationProperties(AnnotationView result, Annotation expected) {
    if (expected.getType() == AnnotationType.MINOR_CORRECTION) {
      assertEquals(
          result.getTitle(),
          "Minor Correction: " + expected.getTitle(),
          "Annotation view had incorrect title");
    } else if (expected.getType() == AnnotationType.FORMAL_CORRECTION) {
      assertEquals(
          result.getTitle(),
          "Formal Correction: " + expected.getTitle(),
          "Annotation view had incorrect title");
    } else if (expected.getType() == AnnotationType.RETRACTION) {
      assertEquals(
          result.getTitle(),
          "Retraction: " + expected.getTitle(),
          "Annotation view had incorrect title");
    }
    assertEquals(
        result.getBody(),
        "<p>" + expected.getBody() + "</p>",
        "Annotation view had incorrect body");
    assertEquals(
        result.getCompetingInterestStatement(),
        expected.getCompetingInterestBody() == null ? "" : expected.getCompetingInterestBody(),
        "Annotation view had incorrect ci statement");
    assertEquals(
        result.getAnnotationUri(),
        expected.getAnnotationUri(),
        "Annotation view had incorrect annotation uri");
    assertEquals(
        result.getCreatorID(),
        expected.getCreator().getID(),
        "Annotation view had incorrect creator id");
    assertEquals(
        result.getCreatorDisplayName(),
        expected.getCreator().getDisplayName(),
        "Annotation view had incorrect creator name");

    if (Arrays.asList(
            AnnotationType.FORMAL_CORRECTION,
            AnnotationType.MINOR_CORRECTION,
            AnnotationType.RETRACTION)
        .contains(expected.getType())) {
      assertTrue(result.isCorrection(), "Result should have been created as a correction");
    } else {
      assertFalse(result.isCorrection(), "Result should not have been created as a correction");
    }

    if (expected.getAnnotationCitation() == null) {
      assertNull(result.getCitation(), "returned non-null citation when null was expected");
    } else {
      assertNotNull(result.getCitation(), "returned null citation when non-null was expected");
      assertEquals(
          result.getCitation().getTitle(),
          expected.getAnnotationCitation().getTitle(),
          "Returned citation with incorrect title");
      assertEquals(
          result.getCitation().geteLocationId(),
          expected.getAnnotationCitation().getELocationId(),
          "Returned citation with incorrect eLocationId");
      assertEquals(
          result.getCitation().getJournal(),
          expected.getAnnotationCitation().getJournal(),
          "Returned citation with incorrect journal");
      assertEquals(
          result.getCitation().getYear(),
          expected.getAnnotationCitation().getYear(),
          "Returned citation with incorrect year");

      assertEquals(
          result.getCitation().getVolume(),
          expected.getAnnotationCitation().getVolume(),
          "Returned citation with incorrect volume");
      assertEquals(
          result.getCitation().getIssue(),
          expected.getAnnotationCitation().getIssue(),
          "Returned citation with incorrect issue");
      assertEquals(
          result.getCitation().getSummary(),
          expected.getAnnotationCitation().getSummary(),
          "Returned citation with incorrect summary");
      assertEquals(
          result.getCitation().getNote(),
          expected.getAnnotationCitation().getNote(),
          "Returned citation with incorrect note");

      if (expected.getAnnotationCitation().getCollaborativeAuthors() != null) {
        assertEqualsNoOrder(
            result.getCitation().getCollabAuthors(),
            expected.getAnnotationCitation().getCollaborativeAuthors().toArray(),
            "Returned citation with incorrect collab authors");
      } else {
        assertTrue(
            ArrayUtils.isEmpty(result.getCitation().getCollabAuthors()),
            "Returned non-empty collab authors when empty was expected");
      }
      if (expected.getAnnotationCitation().getAuthors() != null) {
        assertNotNull(
            result.getCitation().getAuthors(), "Returned null authors when authors were expected");
        assertEquals(
            result.getCitation().getAuthors().length,
            expected.getAnnotationCitation().getAuthors().size(),
            "Returned incorrect number of authors");
        for (int i = 0; i < result.getCitation().getAuthors().length; i++) {
          AuthorView actualAuthor = result.getCitation().getAuthors()[i];
          CorrectedAuthor expectedAuthor = expected.getAnnotationCitation().getAuthors().get(i);
          assertEquals(
              actualAuthor.getGivenNames(),
              expectedAuthor.getGivenNames(),
              "Author " + (i + 1) + " had incorrect given names");
          assertEquals(
              actualAuthor.getSurnames(),
              expectedAuthor.getSurName(),
              "Author " + (i + 1) + " had incorrect surnames");
          assertEquals(
              actualAuthor.getSuffix(),
              expectedAuthor.getSuffix(),
              "Author " + (i + 1) + " had incorrect suffix");
        }
      }
    }
  }