use of org.ambraproject.rhino.model.Issue in project rhino by PLOS.
the class IssueCrudServiceImpl method applyInput.
private Issue applyInput(Issue issue, IssueInputView input) {
String issueDoi = input.getDoi();
if (issueDoi != null) {
IssueIdentifier issueId = IssueIdentifier.create(issueDoi);
issue.setDoi(issueId.getDoi().getName());
}
String displayName = input.getDisplayName();
if (displayName != null) {
issue.setDisplayName(displayName);
} else if (issue.getDisplayName() == null) {
issue.setDisplayName("");
}
String imageDoi = input.getImageArticleDoi();
if (imageDoi != null) {
ArticleIdentifier imageArticleId = ArticleIdentifier.create(imageDoi);
Article imageArticle = articleCrudService.readArticle(imageArticleId);
issue.setImageArticle(imageArticle);
} else {
issue.setImageArticle(null);
}
List<String> inputArticleDois = input.getArticleOrder();
if (inputArticleDois != null) {
List<Article> inputArticles = inputArticleDois.stream().map(doi -> articleCrudService.readArticle(ArticleIdentifier.create(doi))).collect(Collectors.toList());
issue.setArticles(inputArticles);
}
return issue;
}
use of org.ambraproject.rhino.model.Issue 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.model.Issue 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.model.Issue in project rhino by PLOS.
the class IssueCrudController method create.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "IssueInputView", value = "example: {\"doi\": \"10.1371/issue.pbio.v02.i07\", " + "\"displayName\": \"July\", " + "\"imageArticleDoi\": \"10.1371/image.pbio.v02.i07\", " + "\"articleOrder\": [\"10.1371/journal.pbio.0020213\", \"10.1371/journal.pbio.0020214\", " + "\"10.1371/journal.pbio.0020228\"]}")
public ResponseEntity<?> create(HttpServletRequest request, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi) throws IOException {
// TODO: Validate journalKey
VolumeIdentifier volumeId = VolumeIdentifier.create(DoiEscaping.unescape(volumeDoi));
IssueInputView input = readJsonFromRequest(request, IssueInputView.class);
if (StringUtils.isBlank(input.getDoi())) {
throw new RestClientException("issueUri required", HttpStatus.BAD_REQUEST);
}
Issue issue = issueCrudService.create(volumeId, input);
return ServiceResponse.reportCreated(issueOutputViewFactory.getView(issue)).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.model.Issue in project rhino by PLOS.
the class IssueCrudController method readArticlesInIssue.
@Transactional(readOnly = true)
@RequestMapping(value = "/issues/{issueDoi:.+}/contents", method = RequestMethod.GET)
public ResponseEntity<?> readArticlesInIssue(@PathVariable("issueDoi") String issueDoi) throws IOException {
IssueIdentifier issueId = getIssueId(issueDoi);
Issue issue = issueCrudService.readIssue(issueId);
List<ArticleRevisionView> views = issueOutputViewFactory.getIssueArticlesView(issue);
return ServiceResponse.serveView(views).asJsonResponse(entityGson);
}
Aggregations