Search in sources :

Example 1 with NotFoundException

use of org.ambraproject.wombat.controller.NotFoundException in project wombat by PLOS.

the class ArticleResolutionService method resolve.

private static ArticlePointer resolve(RequestedDoiVersion id, Map<String, ?> articleOverview) {
    final String canonicalDoi = (String) Objects.requireNonNull(articleOverview.get("doi"));
    final Map<String, Number> revisionTable = (Map<String, Number>) Objects.requireNonNull(articleOverview.get("revisions"));
    OptionalInt ingestionNumber = id.getIngestionNumber();
    if (ingestionNumber.isPresent()) {
        return new ArticlePointer(id, canonicalDoi, ingestionNumber.getAsInt(), OptionalInt.empty());
    }
    OptionalInt revisionNumber = id.getRevisionNumber();
    if (revisionNumber.isPresent()) {
        int revisionValue = revisionNumber.getAsInt();
        Number ingestionForRevision = revisionTable.get(Integer.toString(revisionValue));
        if (ingestionForRevision == null) {
            String message = String.format("Article %s has no revision %d", id.getDoi(), revisionValue);
            throw new NotFoundException(message);
        }
        return new ArticlePointer(id, canonicalDoi, ingestionForRevision.intValue(), OptionalInt.of(revisionValue));
    } else {
        RevisionPointer latestRevision = findLatestRevision(revisionTable).orElseThrow(() -> {
            String message = String.format("Article %s has no published revisions", id.getDoi());
            return new NotFoundException(message);
        });
        return new ArticlePointer(id, canonicalDoi, latestRevision.getIngestionNumber(), OptionalInt.of(latestRevision.getRevisionNumber()));
    }
}
Also used : NotFoundException(org.ambraproject.wombat.controller.NotFoundException) OptionalInt(java.util.OptionalInt) Map(java.util.Map) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer)

Example 2 with NotFoundException

use of org.ambraproject.wombat.controller.NotFoundException in project wombat by PLOS.

the class ArticleResolutionService method toParentIngestion.

public AssetPointer toParentIngestion(RequestedDoiVersion assetId) throws IOException {
    Map<String, ?> doiOverview;
    try {
        doiOverview = articleApi.requestObject(ApiAddress.builder("dois").embedDoi(assetId.getDoi()).build(), Map.class);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    }
    String type = (String) doiOverview.get("type");
    if (!ARTICLE_ASSET_TYPES.contains(type)) {
        throw new NotFoundException("Not an article asset: " + assetId);
    }
    Map<String, ?> parentArticle = (Map<String, ?>) doiOverview.get("article");
    ArticlePointer parentArticlePtr = resolve(assetId, parentArticle);
    String canonicalAssetDoi = (String) doiOverview.get("doi");
    return new AssetPointer(canonicalAssetDoi, parentArticlePtr);
}
Also used : AssetPointer(org.ambraproject.wombat.identity.AssetPointer) NotFoundException(org.ambraproject.wombat.controller.NotFoundException) Map(java.util.Map) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer)

Aggregations

Map (java.util.Map)2 NotFoundException (org.ambraproject.wombat.controller.NotFoundException)2 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)2 OptionalInt (java.util.OptionalInt)1 AssetPointer (org.ambraproject.wombat.identity.AssetPointer)1