use of won.owner.model.Draft 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.model.Draft 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.model.Draft 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;
}
use of won.owner.model.Draft in project webofneeds by researchstudio-sat.
the class RestNeedController method createDraft.
/**
* saves draft of a draft
* @param createDraftObject an object containing information of the need draft
* @return a JSON object of the draft with its temprory id.
*/
@ResponseBody
@RequestMapping(value = "/drafts", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
// TODO: move transactionality annotation into the service layer
@Transactional(propagation = Propagation.SUPPORTS)
public CreateDraftPojo createDraft(@RequestBody CreateDraftPojo createDraftObject) throws ParseException {
User user = getCurrentUser();
URI draftURI = URI.create(createDraftObject.getDraftURI());
user.getDraftURIs().add(draftURI);
wonUserDetailService.save(user);
Draft draft = null;
draft = draftRepository.findOneByDraftURI(draftURI);
if (draft == null) {
draft = new Draft(draftURI, createDraftObject.getDraft());
}
draft.setContent(createDraftObject.getDraft());
draftRepository.save(draft);
return createDraftObject;
}
Aggregations