Search in sources :

Example 1 with Doi

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

the class VolumeCrudServiceTest method testCreate.

@Test(enabled = false)
public void testCreate() {
    Doi volumeId = Doi.create("10.1371/volume.pmed.v05");
    String displayName = "volumeDisplay";
    String json = String.format("{\"volumeUri\": \"%s\", \"displayName\": \"%s\"}", volumeId.getName(), displayName);
    VolumeInputView input = entityGson.fromJson(json, VolumeInputView.class);
    Journal testJournal = createTestJournal();
    volumeCrudService.create(testJournal.getJournalKey(), input);
    testJournal = getTestJournal();
    List<Volume> testJournalVolumes = testJournal.getVolumes();
    assertFalse(testJournalVolumes.isEmpty());
}
Also used : Volume(org.ambraproject.rhino.model.Volume) VolumeInputView(org.ambraproject.rhino.view.journal.VolumeInputView) Journal(org.ambraproject.rhino.model.Journal) Doi(org.ambraproject.rhino.identity.Doi) Test(org.testng.annotations.Test) BaseRhinoTest(org.ambraproject.rhino.BaseRhinoTest)

Example 2 with Doi

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

the class IngestionService method processIngestPackage.

private ArticleIngestion processIngestPackage(IngestPackage ingestPackage) {
    Doi doi = ArticleIdentifier.create(ingestPackage.getArticleMetadata().getDoi()).getDoi();
    ArticlePackage articlePackage = ingestPackage.getArticlePackage();
    for (ManifestXml.Asset asset : articlePackage.getManifest().getAssets()) {
        Doi assetDoi = Doi.create(asset.getUri());
        validateAssetUniqueness(doi, articleCrudService.getAllArticleItems(assetDoi));
    }
    validateManuscript(doi, articlePackage.getManifest().getArticleAsset().getUri());
    return persistArticle(ingestPackage, doi, articlePackage);
}
Also used : ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) Doi(org.ambraproject.rhino.identity.Doi) ArticlePackage(org.ambraproject.rhino.model.ingest.ArticlePackage)

Example 3 with Doi

use of org.ambraproject.rhino.identity.Doi 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)

Example 4 with Doi

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

the class ArticleXml method setFromXml.

private void setFromXml(final ArticleMetadata.Builder article) throws XmlContentException {
    Doi doi = readDoi();
    article.setDoi(doi.getName());
    article.setTitle(getXmlFromNode(readNode("/article/front/article-meta/title-group/article-title")));
    String eissn = readString("/article/front/journal-meta/issn[@pub-type=\"epub\"]");
    if (Strings.isNullOrEmpty(eissn)) {
        eissn = readString("/article/front/journal-meta/issn");
    }
    article.seteIssn(checkEissn(eissn));
    article.setDescription(getXmlFromNode(findAbstractNode()));
    String rights = readString("/article/front/article-meta/permissions/copyright-statement");
    if (rights == null) {
        rights = buildRights(readString("/article/front/article-meta/permissions/copyright-holder"), readString("/article/front/article-meta/permissions/license/license-p"));
    }
    article.setRights(rights);
    article.setPageCount(parsePageCount(readString("/article/front/article-meta/counts/page-count/@count")));
    article.seteLocationId(readString("/article/front/article-meta/elocation-id"));
    article.setVolume(readString("/article/front/article-meta/volume"));
    article.setIssue(readString("/article/front/article-meta/issue"));
    article.setPublisherName(readString("/article/front/journal-meta/publisher/publisher-name"));
    article.setPublisherLocation(readString("/article/front/journal-meta/publisher/publisher-loc"));
    article.setLanguage(parseLanguage(readString("/article/@xml:lang")));
    Node dateNode = readNode("/article/front/article-meta/pub-date[@pub-type=\"epub\"]");
    if (dateNode == null) {
        dateNode = readNode("/article/front/article-meta/pub-date[@publication-format=\"electronic\"]");
    }
    article.setPublicationDate(parseDate(dateNode));
    article.setNlmArticleType(readString("/article/@article-type"));
    article.setArticleType(parseArticleHeading());
    article.setEditors(readPersons(readNodeList("/article/front/article-meta/contrib-group/contrib[@contrib-type=\"editor\"]/name")));
    article.setUrl(buildUrl(doi));
    article.setRelatedArticles(parseRelatedArticles());
    article.setAssets(parseAssets());
}
Also used : Node(org.w3c.dom.Node) Doi(org.ambraproject.rhino.identity.Doi)

Example 5 with Doi

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

the class ArticleCrudServiceImpl method getManuscriptMetadata.

@Override
public RepoObjectMetadata getManuscriptMetadata(ArticleIngestion ingestion) {
    Doi articleDoi = Doi.create(ingestion.getArticle().getDoi());
    ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(articleDoi, ingestion.getIngestionNumber());
    ArticleItemIdentifier articleItemId = ingestionId.getItemFor();
    ArticleFileIdentifier manuscriptId = ArticleFileIdentifier.create(articleItemId, "manuscript");
    RepoObjectMetadata objectMetadata = assetCrudService.getArticleItemFile(manuscriptId);
    return objectMetadata;
}
Also used : ArticleIngestionIdentifier(org.ambraproject.rhino.identity.ArticleIngestionIdentifier) RepoObjectMetadata(org.plos.crepo.model.metadata.RepoObjectMetadata) ArticleItemIdentifier(org.ambraproject.rhino.identity.ArticleItemIdentifier) ArticleFileIdentifier(org.ambraproject.rhino.identity.ArticleFileIdentifier) Doi(org.ambraproject.rhino.identity.Doi)

Aggregations

Doi (org.ambraproject.rhino.identity.Doi)12 RestClientException (org.ambraproject.rhino.rest.RestClientException)4 Node (org.w3c.dom.Node)4 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)3 Article (org.ambraproject.rhino.model.Article)3 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 LocalDate (java.time.LocalDate)2 Optional (java.util.Optional)2 ArticleFile (org.ambraproject.rhino.model.ArticleFile)2 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)2 ArticleItem (org.ambraproject.rhino.model.ArticleItem)2 ArticleMetadata (org.ambraproject.rhino.model.article.ArticleMetadata)2 RelatedArticleLink (org.ambraproject.rhino.model.article.RelatedArticleLink)2 Query (org.hibernate.Query)2 Logger (org.slf4j.Logger)2