Search in sources :

Example 1 with CreateDraftPojo

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");
    }
}
Also used : Draft(won.owner.model.Draft) User(won.owner.model.User) CreateDraftPojo(won.owner.pojo.CreateDraftPojo) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CreateDraftPojo

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;
}
Also used : Draft(won.owner.model.Draft) CreateDraftPojo(won.owner.pojo.CreateDraftPojo) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CreateDraftPojo

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;
}
Also used : Draft(won.owner.model.Draft) User(won.owner.model.User) ArrayList(java.util.ArrayList) CreateDraftPojo(won.owner.pojo.CreateDraftPojo) URI(java.net.URI) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

URI (java.net.URI)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Draft (won.owner.model.Draft)3 CreateDraftPojo (won.owner.pojo.CreateDraftPojo)3 URISyntaxException (java.net.URISyntaxException)2 User (won.owner.model.User)2 ArrayList (java.util.ArrayList)1