@Test public void getOrdersByMilestoneTest() throws ApplicationException { int milestoneId = 22; List<ChangeOrder> orders = new ArrayList<>(); ChangeOrder order = new ChangeOrder(); Workspace workspace = new Workspace(workspaceId); order.setWorkspace(workspace); Account account = new Account("foo"); User author = new User(workspace, account); order.setAuthor(author); order.setName("name"); orders.add(order); Mockito.when(changeManager.getChangeOrdersByMilestone(workspaceId, milestoneId)) .thenReturn(orders); Response response = milestonesResource.getOrdersByMilestone(workspaceId, milestoneId); Object entity = response.getEntity(); Assert.assertNotNull(entity); Assert.assertTrue(entity.getClass().isAssignableFrom(ArrayList.class)); List orderList = (ArrayList) entity; Assert.assertFalse(orderList.isEmpty()); Object o = orderList.get(0); Assert.assertTrue(o.getClass().isAssignableFrom(ChangeOrderDTO.class)); ChangeOrderDTO dto = (ChangeOrderDTO) o; Assert.assertEquals(order.getName(), dto.getName()); }
@GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") public Response getOrdersByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException, WorkspaceNotEnabledException { List<ChangeOrder> changeOrders = changeManager.getChangeOrdersByMilestone(workspaceId, milestoneId); List<ChangeOrderDTO> changeOrderDTOs = new ArrayList<>(); for (ChangeOrder changeOrder : changeOrders) { changeOrderDTOs.add(mapper.map(changeOrder, ChangeOrderDTO.class)); } return Response.ok(new GenericEntity<List<ChangeOrderDTO>>((List<ChangeOrderDTO>) changeOrderDTOs) { }).build(); }
MilestonesResource { @GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") public Response getOrdersByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException, WorkspaceNotEnabledException { List<ChangeOrder> changeOrders = changeManager.getChangeOrdersByMilestone(workspaceId, milestoneId); List<ChangeOrderDTO> changeOrderDTOs = new ArrayList<>(); for (ChangeOrder changeOrder : changeOrders) { changeOrderDTOs.add(mapper.map(changeOrder, ChangeOrderDTO.class)); } return Response.ok(new GenericEntity<List<ChangeOrderDTO>>((List<ChangeOrderDTO>) changeOrderDTOs) { }).build(); } }
MilestonesResource { @GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") public Response getOrdersByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException, WorkspaceNotEnabledException { List<ChangeOrder> changeOrders = changeManager.getChangeOrdersByMilestone(workspaceId, milestoneId); List<ChangeOrderDTO> changeOrderDTOs = new ArrayList<>(); for (ChangeOrder changeOrder : changeOrders) { changeOrderDTOs.add(mapper.map(changeOrder, ChangeOrderDTO.class)); } return Response.ok(new GenericEntity<List<ChangeOrderDTO>>((List<ChangeOrderDTO>) changeOrderDTOs) { }).build(); } MilestonesResource(); }
MilestonesResource { @GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") public Response getOrdersByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException, WorkspaceNotEnabledException { List<ChangeOrder> changeOrders = changeManager.getChangeOrdersByMilestone(workspaceId, milestoneId); List<ChangeOrderDTO> changeOrderDTOs = new ArrayList<>(); for (ChangeOrder changeOrder : changeOrders) { changeOrderDTOs.add(mapper.map(changeOrder, ChangeOrderDTO.class)); } return Response.ok(new GenericEntity<List<ChangeOrderDTO>>((List<ChangeOrderDTO>) changeOrderDTOs) { }).build(); } MilestonesResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get milestones for given parameters", response = MilestoneDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getMilestones(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @POST @ApiOperation(value = "Create a new milestone", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) MilestoneDTO createMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone to create") MilestoneDTO milestoneDTO); @GET @ApiOperation(value = "Get a milestone by id", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}") MilestoneDTO getMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @PUT @ApiOperation(value = "Update milestone", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}") MilestoneDTO updateMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId,
            @ApiParam(required = true, value = "Milestone to update") MilestoneDTO pMilestoneDTO); @DELETE @ApiOperation(value = "Delete milestone", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Path("{milestoneId}") Response removeMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @GET @ApiOperation(value = "Get change requests for a given milestone", response = ChangeRequestDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeRequestDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/requests") Response getRequestsByMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") Response getOrdersByMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @PUT @ApiOperation(value = "Update ACL of a milestone", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful ACL update of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{milestoneId}/acl") @Consumes(MediaType.APPLICATION_JSON) Response updateMilestoneACL(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId,
            @ApiParam(required = true, value = "ACL rules to set") ACLDTO acl); }
MilestonesResource { @GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") public Response getOrdersByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException, WorkspaceNotEnabledException { List<ChangeOrder> changeOrders = changeManager.getChangeOrdersByMilestone(workspaceId, milestoneId); List<ChangeOrderDTO> changeOrderDTOs = new ArrayList<>(); for (ChangeOrder changeOrder : changeOrders) { changeOrderDTOs.add(mapper.map(changeOrder, ChangeOrderDTO.class)); } return Response.ok(new GenericEntity<List<ChangeOrderDTO>>((List<ChangeOrderDTO>) changeOrderDTOs) { }).build(); } MilestonesResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get milestones for given parameters", response = MilestoneDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getMilestones(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @POST @ApiOperation(value = "Create a new milestone", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) MilestoneDTO createMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone to create") MilestoneDTO milestoneDTO); @GET @ApiOperation(value = "Get a milestone by id", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}") MilestoneDTO getMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @PUT @ApiOperation(value = "Update milestone", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}") MilestoneDTO updateMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId,
            @ApiParam(required = true, value = "Milestone to update") MilestoneDTO pMilestoneDTO); @DELETE @ApiOperation(value = "Delete milestone", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Path("{milestoneId}") Response removeMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @GET @ApiOperation(value = "Get change requests for a given milestone", response = ChangeRequestDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeRequestDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/requests") Response getRequestsByMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") Response getOrdersByMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @PUT @ApiOperation(value = "Update ACL of a milestone", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful ACL update of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{milestoneId}/acl") @Consumes(MediaType.APPLICATION_JSON) Response updateMilestoneACL(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId,
            @ApiParam(required = true, value = "ACL rules to set") ACLDTO acl);  }