Search in sources :

Example 1 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class SolrIndexServiceTest method testPublication.

@Test(enabled = false)
public void testPublication() throws Exception {
    Archive archive = Archive.readZipFileIntoMemory(new File(TEST_DATA_DIR + "pone.0056489.zip"));
    //    Article article = articleCrudService.writeArchive(archive,
    //        Optional.empty(), DoiBasedCrudService.WriteMode.CREATE_ONLY, OptionalInt.empty());
    Article article = new Article();
    ArticleIdentifier articleId = ArticleIdentifier.create(article.getDoi());
    SolrIndexServiceImpl impl = (SolrIndexServiceImpl) solrIndexService;
    DummyMessageSender dummySender = (DummyMessageSender) impl.messageSender;
    assertEquals(dummySender.messagesSent.size(), 5);
    List<String> solrMessages = dummySender.messagesSent.get("activemq:fake.indexing.queue");
    assertEquals(solrMessages.size(), 1);
    XMLUnit.compareXML(IOUtils.toString(new FileInputStream(TEST_DATA_DIR + "pone.0056489_solr_decorated.xml")), solrMessages.get(0));
    String expectedSyndication = "<ambraMessage><doi>info:doi/10.1371/journal.pone.0056489</doi><archive>pone.0056489.zip</archive></ambraMessage>";
    List<String> crossRefMessages = dummySender.messagesSent.get("activemq:fake.crossref.queue");
    assertEquals(crossRefMessages.size(), 1);
    XMLUnit.compareXML(expectedSyndication, crossRefMessages.get(0));
    List<String> pmcMessages = dummySender.messagesSent.get("activemq:fake.pmc.queue");
    assertEquals(pmcMessages.size(), 1);
    XMLUnit.compareXML(expectedSyndication, pmcMessages.get(0));
    List<String> pubmedMessages = dummySender.messagesSent.get("activemq:fake.pubmed.queue");
    assertEquals(pubmedMessages.size(), 1);
    XMLUnit.compareXML(expectedSyndication, pubmedMessages.get(0));
    solrIndexService.removeSolrIndex(articleId);
    assertEquals(dummySender.messagesSent.size(), 6);
    List<String> deletionMessages = dummySender.messagesSent.get("activemq:fake.delete.queue");
    assertEquals(deletionMessages.size(), 1);
    assertEquals(deletionMessages.get(0), article.getDoi());
}
Also used : Archive(org.ambraproject.rhino.util.Archive) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) SolrIndexServiceImpl(org.ambraproject.rhino.service.impl.SolrIndexServiceImpl) Article(org.ambraproject.rhino.model.Article) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) BaseRhinoTest(org.ambraproject.rhino.BaseRhinoTest)

Example 2 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class IngestionTest method compareRelationshipLists.

private void compareRelationshipLists(AssertionCollector results, List<RelatedArticleLink> actual, List<RelatedArticleLink> expected) {
    Map<ArticleIdentifier, RelatedArticleLink> actualMap = Maps.uniqueIndex(actual, RelatedArticleLink::getArticleId);
    Set<ArticleIdentifier> actualDois = actualMap.keySet();
    Map<ArticleIdentifier, RelatedArticleLink> expectedMap = Maps.uniqueIndex(expected, RelatedArticleLink::getArticleId);
    Set<ArticleIdentifier> expectedDois = expectedMap.keySet();
    for (ArticleIdentifier missingDoi : Sets.difference(expectedDois, actualDois)) {
        compare(results, ArticleRelationship.class, "otherArticleDoi", null, missingDoi);
    }
    for (ArticleIdentifier extraDoi : Sets.difference(actualDois, expectedDois)) {
        compare(results, ArticleRelationship.class, "otherArticleDoi", extraDoi, null);
    }
    for (ArticleIdentifier doi : Sets.intersection(actualDois, expectedDois)) {
        compare(results, ArticleRelationship.class, "otherArticleDoi", doi, doi);
        compare(results, ArticleRelationship.class, "type", actualMap.get(doi).getType(), expectedMap.get(doi).getType());
    }
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink)

Example 3 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class IssueCrudServiceImpl method applyInput.

private Issue applyInput(Issue issue, IssueInputView input) {
    String issueDoi = input.getDoi();
    if (issueDoi != null) {
        IssueIdentifier issueId = IssueIdentifier.create(issueDoi);
        issue.setDoi(issueId.getDoi().getName());
    }
    String displayName = input.getDisplayName();
    if (displayName != null) {
        issue.setDisplayName(displayName);
    } else if (issue.getDisplayName() == null) {
        issue.setDisplayName("");
    }
    String imageDoi = input.getImageArticleDoi();
    if (imageDoi != null) {
        ArticleIdentifier imageArticleId = ArticleIdentifier.create(imageDoi);
        Article imageArticle = articleCrudService.readArticle(imageArticleId);
        issue.setImageArticle(imageArticle);
    } else {
        issue.setImageArticle(null);
    }
    List<String> inputArticleDois = input.getArticleOrder();
    if (inputArticleDois != null) {
        List<Article> inputArticles = inputArticleDois.stream().map(doi -> articleCrudService.readArticle(ArticleIdentifier.create(doi))).collect(Collectors.toList());
        issue.setArticles(inputArticles);
    }
    return issue;
}
Also used : Article(org.ambraproject.rhino.model.Article) IssueInputView(org.ambraproject.rhino.view.journal.IssueInputView) Journal(org.ambraproject.rhino.model.Journal) CacheableResponse(org.ambraproject.rhino.rest.response.CacheableResponse) RestClientException(org.ambraproject.rhino.rest.RestClientException) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) IssueOutputView(org.ambraproject.rhino.view.journal.IssueOutputView) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) HttpStatus(org.springframework.http.HttpStatus) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) List(java.util.List) Issue(org.ambraproject.rhino.model.Issue) VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier) Volume(org.ambraproject.rhino.model.Volume) VolumeCrudService(org.ambraproject.rhino.service.VolumeCrudService) Query(org.hibernate.Query) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) IssueCrudService(org.ambraproject.rhino.service.IssueCrudService) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) Article(org.ambraproject.rhino.model.Article)

Example 4 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class ArticleOverview method build.

public static ArticleOverview build(ArticleIdentifier articleId, Collection<ArticleIngestion> ingestions, Collection<ArticleRevision> revisions) {
    // Initialize every ingestion number with an empty list of revisions, then fill in revisions.
    Map<Integer, Collection<Integer>> ingestionTable = ingestions.stream().collect(Collectors.toMap(ArticleIngestion::getIngestionNumber, ingestion -> new ArrayList<>(1)));
    for (ArticleRevision revision : revisions) {
        int ingestionKey = revision.getIngestion().getIngestionNumber();
        ingestionTable.get(ingestionKey).add(revision.getRevisionNumber());
    }
    Map<Integer, Integer> revisionTable = revisions.stream().collect(Collectors.toMap(ArticleRevision::getRevisionNumber, revision -> revision.getIngestion().getIngestionNumber()));
    return new ArticleOverview(articleId, Maps.transformValues(ingestionTable, ImmutableSortedSet::copyOf), revisionTable);
}
Also used : ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Collection(java.util.Collection) Map(java.util.Map) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) ArrayList(java.util.ArrayList) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 5 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class CommentCrudServiceImpl method createComment.

@Override
public ServiceResponse<CommentOutputView> createComment(Optional<ArticleIdentifier> articleId, CommentInputView input) {
    final Optional<String> parentCommentUri = Optional.ofNullable(input.getParentCommentId());
    final Article article;
    final Comment parentComment;
    if (parentCommentUri.isPresent()) {
        parentComment = readComment(CommentIdentifier.create(parentCommentUri.get()));
        if (parentComment == null) {
            throw new RestClientException("Parent comment not found: " + parentCommentUri, HttpStatus.BAD_REQUEST);
        }
        article = parentComment.getArticle();
        ArticleIdentifier articleDoiFromDb = ArticleIdentifier.create(parentComment.getArticle().getDoi());
        if (!articleId.isPresent()) {
            articleId = Optional.of(articleDoiFromDb);
        } else if (!articleId.get().equals(articleDoiFromDb)) {
            String message = String.format("Parent comment (%s) not from declared article (%s).", parentCommentUri.get(), articleId.get());
            throw new RestClientException(message, HttpStatus.BAD_REQUEST);
        }
    } else {
        // The comment is a root-level reply to an article (no parent comment).
        if (!articleId.isPresent()) {
            throw new RestClientException("Must provide articleId or parentCommentUri", HttpStatus.BAD_REQUEST);
        }
        article = articleCrudService.readArticle(articleId.get());
        parentComment = null;
    }
    // comment receives same DOI prefix as article
    String doiPrefix = extractDoiPrefix(articleId.get());
    // generate a new DOI out of a random UUID
    UUID uuid = UUID.randomUUID();
    Doi createdCommentUri = Doi.create(doiPrefix + "annotation/" + uuid);
    Comment created = new Comment();
    created.setArticle(article);
    created.setParent(parentComment);
    created.setCommentUri(createdCommentUri.getName());
    created.setUserProfileID(Long.valueOf(Strings.nullToEmpty(input.getCreatorUserId())));
    created.setTitle(Strings.nullToEmpty(input.getTitle()));
    created.setBody(Strings.nullToEmpty(input.getBody()));
    created.setHighlightedText(Strings.nullToEmpty(input.getHighlightedText()));
    created.setCompetingInterestBody(Strings.nullToEmpty(input.getCompetingInterestStatement()));
    created.setIsRemoved(Boolean.valueOf(Strings.nullToEmpty(input.getIsRemoved())));
    hibernateTemplate.save(created);
    // the new comment can't have any children yet
    List<Comment> childComments = ImmutableList.of();
    CompetingInterestPolicy competingInterestPolicy = new CompetingInterestPolicy(runtimeConfiguration);
    CommentOutputView.Factory viewFactory = new CommentOutputView.Factory(competingInterestPolicy, childComments, article);
    CommentOutputView view = viewFactory.buildView(created);
    return ServiceResponse.reportCreated(view);
}
Also used : Comment(org.ambraproject.rhino.model.Comment) Article(org.ambraproject.rhino.model.Article) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) RestClientException(org.ambraproject.rhino.rest.RestClientException) CommentOutputView(org.ambraproject.rhino.view.comment.CommentOutputView) UUID(java.util.UUID) Doi(org.ambraproject.rhino.identity.Doi) CompetingInterestPolicy(org.ambraproject.rhino.view.comment.CompetingInterestPolicy)

Aggregations

ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 CommentIdentifier (org.ambraproject.rhino.identity.CommentIdentifier)9 Article (org.ambraproject.rhino.model.Article)7 RestClientException (org.ambraproject.rhino.rest.RestClientException)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)4 Query (org.hibernate.Query)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Preconditions (com.google.common.base.Preconditions)2 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2