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()));
}
}
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);
}
Aggregations