Search in sources :

Example 1 with Draft

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");
    }
}
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 Draft

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;
}
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 Draft

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;
}
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)

Example 4 with Draft

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

Aggregations

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