コード例 #1
0
  @ApiMethod(
      summary = APIDoc.SUM_DELETE_KNOWLEDGE,
      responsestatuscode = APIDoc.STATUS_DELETE_KNOWLEDGE)
  @RequestMapping(value = "/user/{idUser}/knowledge/{idArea}", method = RequestMethod.DELETE)
  public HttpEntity deleteKnowledge(
      @PathVariable("idUser") Long idUser, @PathVariable("idArea") Long idArea) {
    if (!Utils.verifyParamEmptyOrNull(idUser) || !Utils.verifyParamEmptyOrNull(idArea))
      return new ResponseEntity(HttpStatus.BAD_REQUEST);

    if (service.delete(idArea, idUser)) return new ResponseEntity(HttpStatus.OK);
    else return new ResponseEntity(HttpStatus.NOT_MODIFIED);
  }
コード例 #2
0
  private ResponseEntity getErrorResponse(Object object) {

    if (object instanceof KnowledgeMod) {
      KnowledgeMod param = (KnowledgeMod) object;
      if (!Utils.verifyParamEmptyOrNull(param.area) && !Utils.verifyParamEmptyOrNull(param.name)) {
        return new ResponseEntity(
            "Dados referênte a área estão inválidos: {" + param.area + " : " + param.name + "}",
            HttpStatus.UNPROCESSABLE_ENTITY);
      }
    }
    return null;
  }
コード例 #3
0
  /*
   * TODO: Refatorar esse código, está um lixo. Validar Subject enviado, senão vai dar exception.
   */
  @ApiMethod(
      produces = APIDoc.PROD_CONSU_JSON,
      consumes = APIDoc.PROD_CONSU_JSON,
      summary = APIDoc.SUM_SAVE_KNOWLEDGE)
  @ApiBodyObject(clazz = KnowledgeMod.class)
  @RequestMapping(value = "/knowledge", method = RequestMethod.POST)
  public ResponseEntity saveKnowledge(@RequestBody KnowledgeMod param) {

    ResponseEntity responseEntity = getErrorResponse(param);
    if (responseEntity != null) return responseEntity;

    User user = null;
    if (Utils.verifyParamEmptyOrNull(param.idUser)) user = userService.findById(param.idUser);
    else if (user == null)
      return new ResponseEntity("Usuário inválido.", HttpStatus.UNPROCESSABLE_ENTITY);

    Area area = null;
    if (Utils.verifyParamEmptyOrNull(param.area)) {
      area = service.findAreaById(param.area);
      if (area == null)
        return new ResponseEntity(
            "Impossível localizar área com id: " + param.area, HttpStatus.UNPROCESSABLE_ENTITY);
      else param.name = area.getName();
    } else {
      area = service.saveArea(new Area(param.name));
      param.area = area.getId();
    }

    Knowledge knowledge = new Knowledge(user, area);
    if (param.subject != null && param.subject > 0) {
      Subject subject = service.findSubjectById(param.subject);
      knowledge.setSubject(subject);
    }
    service.save(knowledge);

    return new ResponseEntity(
        param, knowledge != null ? HttpStatus.CREATED : HttpStatus.INTERNAL_SERVER_ERROR);
  }