use of org.ambraproject.rhino.rest.RestClientException in project rhino by PLOS.
the class IssueCrudServiceImpl method create.
@Override
public Issue create(VolumeIdentifier volumeId, IssueInputView input) {
Preconditions.checkNotNull(volumeId);
IssueIdentifier issueId = IssueIdentifier.create(input.getDoi());
if (getIssue(issueId).isPresent()) {
throw new RestClientException("Issue already exists with DOI: " + issueId, HttpStatus.BAD_REQUEST);
}
Issue issue = applyInput(new Issue(), input);
Volume volume = volumeCrudService.readVolume(volumeId);
volume.getIssues().add(issue);
hibernateTemplate.save(volume);
return issue;
}
use of org.ambraproject.rhino.rest.RestClientException in project rhino by PLOS.
the class IngestionService method getManuscriptEntry.
private String getManuscriptEntry(ImmutableSet<String> entryNames, ManifestXml manifestXml) {
ManifestXml.Representation manuscriptRepr = manifestXml.getArticleAsset().getRepresentation("manuscript").orElseThrow(() -> new RestClientException("Manuscript entry not found in manifest", HttpStatus.BAD_REQUEST));
String manuscriptEntry = manuscriptRepr.getFile().getEntry();
if (!entryNames.contains(manuscriptEntry)) {
throw new RestClientException("Manuscript file not found in archive: " + manuscriptEntry, HttpStatus.BAD_REQUEST);
}
return manuscriptEntry;
}
use of org.ambraproject.rhino.rest.RestClientException in project rhino by PLOS.
the class IssueCrudServiceImpl method delete.
@Override
public void delete(IssueIdentifier issueId) {
Issue issue = readIssue(issueId);
List<String> currentIssueJournalKeys = hibernateTemplate.execute((Session session) -> {
Query query = session.createQuery("select journalKey from Journal where currentIssue = :issue");
query.setParameter("issue", issue);
return query.list();
});
if (!currentIssueJournalKeys.isEmpty()) {
String message = String.format("Cannot delete issue: %s. It is the current issue for: %s", issueId, currentIssueJournalKeys);
throw new RestClientException(message, HttpStatus.BAD_REQUEST);
}
hibernateTemplate.delete(issue);
}
use of org.ambraproject.rhino.rest.RestClientException in project rhino by PLOS.
the class JournalCrudServiceImpl method validateIssueInJournal.
private Issue validateIssueInJournal(Issue issue, Journal journal) {
Object results = hibernateTemplate.execute((Session session) -> {
String hql = "from Journal j, Issue i, Volume v " + "where j.journalId = :journalId " + "and i.issueId = :issueId " + "and v in elements(j.volumes) " + "and i in elements(v.issues)";
Query query = session.createQuery(hql);
query.setParameter("journalId", journal.getJournalId());
query.setParameter("issueId", issue.getIssueId());
return query.uniqueResult();
});
if (results != null) {
return issue;
} else {
throw new RestClientException("Issue with DOI " + issue.getDoi() + " not found in journal with key " + journal.getJournalKey(), HttpStatus.BAD_REQUEST);
}
}
use of org.ambraproject.rhino.rest.RestClientException 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);
}
Aggregations