use of won.owner.pojo.CreateDraftPojo in project webofneeds by researchstudio-sat.
the class RestNeedController method deleteDraft.
@ResponseBody
@RequestMapping(value = "/drafts/draft", method = RequestMethod.DELETE)
public ResponseEntity<String> deleteDraft(@RequestParam("uri") String uri) {
logger.debug("deleting draft: " + uri);
URI draftURI = null;
CreateDraftPojo draftPojo = null;
User user = getCurrentUser();
try {
draftURI = new URI(uri);
user.getDraftURIs().remove(draftURI);
wonUserDetailService.save(user);
Draft draft = draftRepository.findOneByDraftURI(draftURI);
if (draft == null) {
logger.warn("draft requested for delete was not found: " + uri);
} else {
draftRepository.delete(draft);
}
return ResponseEntity.ok().body("\"deleted draft: " + uri + "\"");
} catch (URISyntaxException e) {
logger.warn("draft uri problem.", e);
return ResponseEntity.badRequest().body("draft uri problem");
}
}
use of won.owner.pojo.CreateDraftPojo in project webofneeds by researchstudio-sat.
the class RestNeedController method getDraft.
@ResponseBody
@RequestMapping(value = "/drafts/draft", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public CreateDraftPojo getDraft(@RequestParam("uri") String uri) {
logger.debug("getting draft: " + uri);
URI draftURI = null;
CreateDraftPojo draftPojo = null;
try {
draftURI = new URI(uri);
Draft draft = draftRepository.findOneByDraftURI(draftURI);
if (draft == null) {
logger.warn("draft requested for delete was not found: " + uri);
} else {
draftPojo = new CreateDraftPojo(draft.getDraftURI().toString(), draft.getContent());
}
} catch (URISyntaxException e) {
logger.warn("draft uri problem.", e);
}
return draftPojo;
}
use of won.owner.pojo.CreateDraftPojo in project webofneeds by researchstudio-sat.
the class RestNeedController method getAllDrafts.
@ResponseBody
@RequestMapping(value = "/drafts", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public // TODO: move transactionality annotation into the service layer
List<CreateDraftPojo> getAllDrafts() {
User user = getCurrentUser();
List<CreateDraftPojo> createDraftPojos = new ArrayList<>();
Set<URI> draftURIs = user.getDraftURIs();
Iterator<URI> draftURIIterator = draftURIs.iterator();
while (draftURIIterator.hasNext()) {
URI draftURI = draftURIIterator.next();
Draft draft = draftRepository.findByDraftURI(draftURI).get(0);
CreateDraftPojo createDraftPojo = new CreateDraftPojo(draftURI.toString(), draft.getContent());
createDraftPojos.add(createDraftPojo);
}
return createDraftPojos;
}
Aggregations