Search in sources :

Example 1 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class ArticleIngestionView method serialize.

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    serialized.addProperty("doi", ingestion.getArticle().getDoi());
    serialized.addProperty("ingestionNumber", ingestion.getIngestionNumber());
    serialized.add("journal", context.serialize(journal));
    serialized.addProperty("bucketName", bucketName);
    ArticleItem strikingImage = ingestion.getStrikingImage();
    if (strikingImage != null) {
        serialized.add("strikingImage", context.serialize(ItemSetView.getItemView(strikingImage)));
    }
    JsonAdapterUtil.copyWithoutOverwriting(context.serialize(metadata).getAsJsonObject(), serialized);
    JsonAdapterUtil.copyWithoutOverwriting(context.serialize(customMetadata).getAsJsonObject(), serialized);
    serialized.remove("assets");
    List<AssetMetadataView> assetViews = metadata.getAssets().stream().map(AssetMetadataView::new).collect(Collectors.toList());
    serialized.add("assetsLinkedFromManuscript", context.serialize(assetViews));
    return serialized;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) JsonObject(com.google.gson.JsonObject)

Example 2 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class ContentRepoPersistenceServiceImpl method createItem.

@Override
public ArticleItem createItem(ArticleItemInput itemInput, ArticleIngestion ingestion) {
    ArticleItem item = new ArticleItem();
    item.setIngestion(ingestion);
    item.setDoi(itemInput.getDoi().getName());
    item.setItemType(itemInput.getType());
    Collection<ArticleFile> files = new ArrayList<>(itemInput.getFiles().entrySet().size());
    for (Map.Entry<String, ArticleFileInput> entry : itemInput.getFiles().entrySet()) {
        ArticleFileInput fileInput = entry.getValue();
        RepoVersion repoVersion = contentRepoService.autoCreateRepoObject(fileInput.getObject()).getVersion();
        ArticleFile file = new ArticleFile();
        file.setIngestion(ingestion);
        file.setItem(item);
        file.setFileType(entry.getKey());
        RepoId repoId = repoVersion.getId();
        file.setBucketName(repoId.getBucketName());
        file.setCrepoKey(repoId.getKey());
        file.setCrepoUuid(repoVersion.getUuid().toString());
        file.setFileSize(contentRepoService.getRepoObjectMetadata(repoVersion).getSize());
        file.setIngestedFileName(fileInput.getFilename());
        files.add(file);
    }
    item.setFiles(files);
    return item;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleFileInput(org.ambraproject.rhino.model.ingest.ArticleFileInput) ArrayList(java.util.ArrayList) ArticleFile(org.ambraproject.rhino.model.ArticleFile) RepoId(org.plos.crepo.model.identity.RepoId) Map(java.util.Map) RepoVersion(org.plos.crepo.model.identity.RepoVersion)

Example 3 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class AssetCrudServiceImpl method getArticleItemFile.

@Override
public RepoObjectMetadata getArticleItemFile(ArticleFileIdentifier fileId) {
    ArticleItem work = articleCrudService.getArticleItem(fileId.getItemIdentifier());
    String fileType = fileId.getFileType();
    ArticleFile articleFile = work.getFile(fileType).orElseThrow(() -> new RestClientException("Unrecognized type: " + fileType, HttpStatus.NOT_FOUND));
    try {
        return contentRepoService.getRepoObjectMetadata(articleFile.getCrepoVersion());
    } catch (NotFoundException e) {
        throw new RestClientException("Object not found: " + fileId + ". File info: " + articleFile, HttpStatus.NOT_FOUND);
    }
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) RestClientException(org.ambraproject.rhino.rest.RestClientException) NotFoundException(org.plos.crepo.exceptions.NotFoundException) ArticleFile(org.ambraproject.rhino.model.ArticleFile)

Example 4 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class ArticleCrudServiceImpl method getItemOverview.

@Override
public Optional<ResolvedDoiView> getItemOverview(Doi doi) {
    return hibernateTemplate.execute(session -> {
        Query ingestionQuery = session.createQuery("FROM ArticleItem WHERE doi = :doi");
        ingestionQuery.setParameter("doi", doi.getName());
        List<ArticleItem> items = ingestionQuery.list();
        if (items.isEmpty())
            return Optional.empty();
        ResolvedDoiView.DoiWorkType type = items.stream().allMatch(ArticleCrudServiceImpl::isMainArticleItem) ? ResolvedDoiView.DoiWorkType.ARTICLE : ResolvedDoiView.DoiWorkType.ASSET;
        ArticleIdentifier articleId = Iterables.getOnlyElement(items.stream().map(item -> ArticleIdentifier.create(item.getIngestion().getArticle().getDoi())).collect(Collectors.toSet()));
        Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + "  (SELECT ingestion FROM ArticleItem WHERE doi = :doi)");
        revisionQuery.setParameter("doi", doi.getName());
        List<ArticleRevision> revisions = revisionQuery.list();
        Collection<ArticleIngestion> ingestions = Collections2.transform(items, ArticleItem::getIngestion);
        ArticleOverview articleOverview = ArticleOverview.build(articleId, ingestions, revisions);
        return Optional.of(ResolvedDoiView.createForArticle(doi, type, articleOverview));
    });
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Query(org.hibernate.Query) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview)

Example 5 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class ArticleCrudServiceImpl method getLatestRevision.

@Override
public Optional<ArticleRevision> getLatestRevision(Article article) {
    Integer maxRevisionNumber = hibernateTemplate.execute(session -> {
        Query query = session.createQuery("" + "SELECT MAX(rev.revisionNumber) " + "FROM ArticleRevision rev, ArticleItem item " + "WHERE item.doi = :doi " + "  AND rev.ingestion = item.ingestion");
        query.setParameter("doi", Doi.create(article.getDoi()).getName());
        return (Integer) query.uniqueResult();
    });
    if (maxRevisionNumber == null)
        return Optional.empty();
    return Optional.ofNullable(hibernateTemplate.execute(session -> {
        Query query = session.createQuery("" + "FROM ArticleRevision as av " + "WHERE av.ingestion.article = :article " + "AND av.revisionNumber = :latestRevision");
        query.setParameter("article", article);
        query.setParameter("latestRevision", maxRevisionNumber);
        return (ArticleRevision) query.uniqueResult();
    }));
}
Also used : ArticleIngestionIdentifier(org.ambraproject.rhino.identity.ArticleIngestionIdentifier) ServiceResponse(org.ambraproject.rhino.rest.response.ServiceResponse) ArticleFileIdentifier(org.ambraproject.rhino.identity.ArticleFileIdentifier) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Collections2(com.google.common.collect.Collections2) Archive(org.ambraproject.rhino.util.Archive) ArticleXml(org.ambraproject.rhino.content.xml.ArticleXml) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Matcher(java.util.regex.Matcher) Document(org.w3c.dom.Document) Map(java.util.Map) Query(org.hibernate.Query) StringEscapeUtils(org.apache.commons.lang3.StringEscapeUtils) ArticleAllAuthorsView(org.ambraproject.rhino.view.article.author.ArticleAllAuthorsView) ArticleItem(org.ambraproject.rhino.model.ArticleItem) RepoObjectMetadata(org.plos.crepo.model.metadata.RepoObjectMetadata) Collection(java.util.Collection) Set(java.util.Set) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) AssetCrudService(org.ambraproject.rhino.service.AssetCrudService) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Objects(java.util.Objects) List(java.util.List) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) LocalDate(java.time.LocalDate) Optional(java.util.Optional) ArticleFile(org.ambraproject.rhino.model.ArticleFile) Pattern(java.util.regex.Pattern) ArticleRevisionView(org.ambraproject.rhino.view.article.ArticleRevisionView) ArticleRelationship(org.ambraproject.rhino.model.ArticleRelationship) Iterables(com.google.common.collect.Iterables) Article(org.ambraproject.rhino.model.Article) CacheableResponse(org.ambraproject.rhino.rest.response.CacheableResponse) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview) ArticleItemIdentifier(org.ambraproject.rhino.identity.ArticleItemIdentifier) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TaxonomyService(org.ambraproject.rhino.service.taxonomy.TaxonomyService) XpathReader(org.ambraproject.rhino.content.xml.XpathReader) Doi(org.ambraproject.rhino.identity.Doi) ByteSource(com.google.common.io.ByteSource) XPathException(javax.xml.xpath.XPathException) ArticleIngestionView(org.ambraproject.rhino.view.article.ArticleIngestionView) Logger(org.slf4j.Logger) XmlContentException(org.ambraproject.rhino.content.xml.XmlContentException) IOException(java.io.IOException) ArticleCategoryAssignment(org.ambraproject.rhino.model.ArticleCategoryAssignment) HttpStatus(org.springframework.http.HttpStatus) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) AuthorView(org.ambraproject.rhino.view.article.author.AuthorView) CategoryAssignmentView(org.ambraproject.rhino.view.article.CategoryAssignmentView) ItemSetView(org.ambraproject.rhino.view.article.ItemSetView) InputStream(java.io.InputStream) Query(org.hibernate.Query)

Aggregations

ArticleItem (org.ambraproject.rhino.model.ArticleItem)11 ArticleFile (org.ambraproject.rhino.model.ArticleFile)5 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)5 Article (org.ambraproject.rhino.model.Article)4 Query (org.hibernate.Query)4 Collection (java.util.Collection)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)3 RestClientException (org.ambraproject.rhino.rest.RestClientException)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Doi (org.ambraproject.rhino.identity.Doi)2 Journal (org.ambraproject.rhino.model.Journal)2 ArticleItemInput (org.ambraproject.rhino.model.ingest.ArticleItemInput)2 ArticleCrudService (org.ambraproject.rhino.service.ArticleCrudService)2