Search in sources :

Example 6 with RestClientException

use of org.ambraproject.rhino.rest.RestClientException in project rhino by PLOS.

the class CommentCrudServiceImpl method patchComment.

@Override
public ServiceResponse<CommentOutputView> patchComment(CommentIdentifier commentId, CommentInputView input) {
    Comment comment = readComment(commentId);
    String declaredUri = input.getAnnotationUri();
    if (declaredUri != null && !CommentIdentifier.create(declaredUri).equals(commentId)) {
        throw new RestClientException("Mismatched commentUri in body", HttpStatus.BAD_REQUEST);
    }
    String creatorUserId = input.getCreatorUserId();
    if (creatorUserId != null) {
        comment.setUserProfileID(Long.valueOf(creatorUserId));
    }
    String title = input.getTitle();
    if (title != null) {
        comment.setTitle(title);
    }
    String body = input.getBody();
    if (body != null) {
        comment.setBody(body);
    }
    String highlightedText = input.getHighlightedText();
    if (highlightedText != null) {
        comment.setHighlightedText(highlightedText);
    }
    String competingInterestStatement = input.getCompetingInterestStatement();
    if (competingInterestStatement != null) {
        comment.setCompetingInterestBody(competingInterestStatement);
    }
    String isRemoved = input.getIsRemoved();
    if (isRemoved != null) {
        comment.setIsRemoved(Boolean.valueOf(isRemoved));
    }
    hibernateTemplate.update(comment);
    return ServiceResponse.serveView(createView(comment));
}
Also used : Comment(org.ambraproject.rhino.model.Comment) RestClientException(org.ambraproject.rhino.rest.RestClientException)

Example 7 with RestClientException

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;
}
Also used : Issue(org.ambraproject.rhino.model.Issue) Volume(org.ambraproject.rhino.model.Volume) IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) RestClientException(org.ambraproject.rhino.rest.RestClientException)

Example 8 with RestClientException

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;
}
Also used : RestClientException(org.ambraproject.rhino.rest.RestClientException) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml)

Example 9 with RestClientException

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);
}
Also used : Issue(org.ambraproject.rhino.model.Issue) Query(org.hibernate.Query) RestClientException(org.ambraproject.rhino.rest.RestClientException) Session(org.hibernate.Session)

Example 10 with RestClientException

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);
    }
}
Also used : Query(org.hibernate.Query) RestClientException(org.ambraproject.rhino.rest.RestClientException) Session(org.hibernate.Session)

Aggregations

RestClientException (org.ambraproject.rhino.rest.RestClientException)21 Transactional (org.springframework.transaction.annotation.Transactional)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Volume (org.ambraproject.rhino.model.Volume)5 Issue (org.ambraproject.rhino.model.Issue)4 Journal (org.ambraproject.rhino.model.Journal)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 ManifestXml (org.ambraproject.rhino.content.xml.ManifestXml)3 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)3 Article (org.ambraproject.rhino.model.Article)3 Comment (org.ambraproject.rhino.model.Comment)3 Query (org.hibernate.Query)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Doi (org.ambraproject.rhino.identity.Doi)2 VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)2 ArticleList (org.ambraproject.rhino.model.ArticleList)2 Session (org.hibernate.Session)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1