@Test public void saveAnswerTest() { String invitationToken = "UO6QUYLIK1"; Integer questionnaireId = 58; String questionCode = "Q1"; TextAnswer answer = TextAnswer.fromValue("Antonio Maria"); Entity<TextAnswer> wrapper = Entity.json(answer); Response response = client() .target(String.format("%sruntime/questionnaires/%d/answer?questionCode=%s", getBaseUri(), questionnaireId, questionCode)).request().accept(MediaType.APPLICATION_JSON).post(wrapper); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode()); }
@POST @Path("/{questionnaireId}/answer") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Allow the respondent save answers") @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "Answer saved correctly") }) public Response saveAnswer(@ApiParam(value = "Answer", required = true) Answer answer, @Context final SecurityContext context, @PathParam("questionnaireId") @ApiParam(value = "Questionnair id", required = true) Integer questionnaireId, @QueryParam("questionCode") @ApiParam(value = "Question Code", required = true) String questionCode) { logger.debug("New attempt for saving answer from {}", context.getUserPrincipal().getName()); try { questionnairFacade.saveAnswer(questionnaireId, questionCode, answer); } catch (Exception e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return Response.ok().build(); }
QuestionnairResource { @POST @Path("/{questionnaireId}/answer") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Allow the respondent save answers") @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "Answer saved correctly") }) public Response saveAnswer(@ApiParam(value = "Answer", required = true) Answer answer, @Context final SecurityContext context, @PathParam("questionnaireId") @ApiParam(value = "Questionnair id", required = true) Integer questionnaireId, @QueryParam("questionCode") @ApiParam(value = "Question Code", required = true) String questionCode) { logger.debug("New attempt for saving answer from {}", context.getUserPrincipal().getName()); try { questionnairFacade.saveAnswer(questionnaireId, questionCode, answer); } catch (Exception e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return Response.ok().build(); } }
QuestionnairResource { @POST @Path("/{questionnaireId}/answer") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Allow the respondent save answers") @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "Answer saved correctly") }) public Response saveAnswer(@ApiParam(value = "Answer", required = true) Answer answer, @Context final SecurityContext context, @PathParam("questionnaireId") @ApiParam(value = "Questionnair id", required = true) Integer questionnaireId, @QueryParam("questionCode") @ApiParam(value = "Question Code", required = true) String questionCode) { logger.debug("New attempt for saving answer from {}", context.getUserPrincipal().getName()); try { questionnairFacade.saveAnswer(questionnaireId, questionCode, answer); } catch (Exception e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return Response.ok().build(); } QuestionnairResource(); }
QuestionnairResource { @POST @Path("/{questionnaireId}/answer") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Allow the respondent save answers") @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "Answer saved correctly") }) public Response saveAnswer(@ApiParam(value = "Answer", required = true) Answer answer, @Context final SecurityContext context, @PathParam("questionnaireId") @ApiParam(value = "Questionnair id", required = true) Integer questionnaireId, @QueryParam("questionCode") @ApiParam(value = "Question Code", required = true) String questionCode) { logger.debug("New attempt for saving answer from {}", context.getUserPrincipal().getName()); try { questionnairFacade.saveAnswer(questionnaireId, questionCode, answer); } catch (Exception e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return Response.ok().build(); } QuestionnairResource(); @GET @RolesAllowed("respondent") @ApiOperation(value = "Get questionnair definition", notes = "More notes about this method", response = QuestionnairDTO.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "questionnaires available") }) Response getDefinition(@Context
    final SecurityContext context, @PathParam("questionnaireId")
    @ApiParam(value = "Questionnair id")
    Integer questionnaireId); @GET @Path("/{questionnaireId}/page") @RolesAllowed("respondent") @ApiOperation(value = "Fetch the next, current or previous page for the given questionnair", notes = "More notes about this method", response = PageDTO.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "questionnaires available") }) Response getPage(
            @Context
            final SecurityContext context,
            @PathParam("questionnaireId")
            @ApiParam(value = "Questionnair id")
            Integer questionnaireId,
            @ApiParam(name = "mode", value = "Refers how many questions are returned by page.", required = true, defaultValue = "GROUP_BY_GROUP", allowableValues = "QUESTION_BY_QUESTION,GROUP_BY_GROUP", allowMultiple = true)
            @QueryParam("mode")
            String modeStr,
            @ApiParam(name = "action", value = "Action fired for the respondent", required = true, defaultValue = "ENTERING", allowableValues = "FORWARD,BACKWARD,ENTERING", allowMultiple = true)
            @QueryParam("action")
            String actionStr); @POST @Path("/{questionnaireId}/answer") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Allow the respondent save answers") @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "Answer saved correctly") }) Response saveAnswer(@ApiParam(value = "Answer", required = true)
    Answer answer, @Context
    final SecurityContext context, @PathParam("questionnaireId")
    @ApiParam(value = "Questionnair id", required = true)
    Integer questionnaireId, @QueryParam("questionCode")
    @ApiParam(value = "Question Code", required = true)
    String questionCode); }
QuestionnairResource { @POST @Path("/{questionnaireId}/answer") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Allow the respondent save answers") @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "Answer saved correctly") }) public Response saveAnswer(@ApiParam(value = "Answer", required = true) Answer answer, @Context final SecurityContext context, @PathParam("questionnaireId") @ApiParam(value = "Questionnair id", required = true) Integer questionnaireId, @QueryParam("questionCode") @ApiParam(value = "Question Code", required = true) String questionCode) { logger.debug("New attempt for saving answer from {}", context.getUserPrincipal().getName()); try { questionnairFacade.saveAnswer(questionnaireId, questionCode, answer); } catch (Exception e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } return Response.ok().build(); } QuestionnairResource(); @GET @RolesAllowed("respondent") @ApiOperation(value = "Get questionnair definition", notes = "More notes about this method", response = QuestionnairDTO.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "questionnaires available") }) Response getDefinition(@Context
    final SecurityContext context, @PathParam("questionnaireId")
    @ApiParam(value = "Questionnair id")
    Integer questionnaireId); @GET @Path("/{questionnaireId}/page") @RolesAllowed("respondent") @ApiOperation(value = "Fetch the next, current or previous page for the given questionnair", notes = "More notes about this method", response = PageDTO.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "questionnaires available") }) Response getPage(
            @Context
            final SecurityContext context,
            @PathParam("questionnaireId")
            @ApiParam(value = "Questionnair id")
            Integer questionnaireId,
            @ApiParam(name = "mode", value = "Refers how many questions are returned by page.", required = true, defaultValue = "GROUP_BY_GROUP", allowableValues = "QUESTION_BY_QUESTION,GROUP_BY_GROUP", allowMultiple = true)
            @QueryParam("mode")
            String modeStr,
            @ApiParam(name = "action", value = "Action fired for the respondent", required = true, defaultValue = "ENTERING", allowableValues = "FORWARD,BACKWARD,ENTERING", allowMultiple = true)
            @QueryParam("action")
            String actionStr); @POST @Path("/{questionnaireId}/answer") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Allow the respondent save answers") @ApiResponses(value = { @ApiResponse(code = 404, message = "Invalid invitation token supplied"), @ApiResponse(code = 200, message = "Answer saved correctly") }) Response saveAnswer(@ApiParam(value = "Answer", required = true)
    Answer answer, @Context
    final SecurityContext context, @PathParam("questionnaireId")
    @ApiParam(value = "Questionnair id", required = true)
    Integer questionnaireId, @QueryParam("questionCode")
    @ApiParam(value = "Question Code", required = true)
    String questionCode);  }