PartEffectivityResource { @GET @ApiOperation(value = "Get effectivities of a given PartRevision", response = EffectivityDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of effectivities. 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) public Response getEffectivities( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Part revision number") @PathParam("partNumber") String partNumber, @ApiParam(required = true, value = "Part revision version") @PathParam("partVersion") String partVersion) throws UserNotActiveException, EntityNotFoundException, AccessRightException, WorkspaceNotEnabledException { PartRevision partRevision = productManager.getPartRevision(new PartRevisionKey(workspaceId, partNumber, partVersion)); Set<Effectivity> effectivitySet = partRevision.getEffectivities(); List<EffectivityDTO> effectivityDTOs = new ArrayList<>(); for (Effectivity effectivity : effectivitySet) { EffectivityDTO effectivityDTO = mapper.map(effectivity, EffectivityDTO.class); ConfigurationItem configurationItem = effectivity.getConfigurationItem(); effectivityDTO.setConfigurationItemKey(configurationItem != null ? configurationItem.getKey() : null); if (effectivity.getClass().equals(SerialNumberBasedEffectivity.class)) { effectivityDTO.setTypeEffectivity(TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY); } else if (effectivity.getClass().equals(DateBasedEffectivity.class)) { effectivityDTO.setTypeEffectivity(TypeEffectivity.DATEBASEDEFFECTIVITY); } else if (effectivity.getClass().equals(LotBasedEffectivity.class)) { effectivityDTO.setTypeEffectivity(TypeEffectivity.LOTBASEDEFFECTIVITY); } effectivityDTOs.add(effectivityDTO); } return Response.ok(new GenericEntity<List<EffectivityDTO>>(effectivityDTOs) { }).build(); } PartEffectivityResource(); @PostConstruct void init(); @POST @ApiOperation(value = "Create an Effectivity for a given PartRevision", response = EffectivityDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created effectivity"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) EffectivityDTO createEffectivity(
            @ApiParam(required = true, value = "Effectivity to create") EffectivityDTO effectivity,
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Part revision number") @PathParam("partNumber") String partNumber,
            @ApiParam(required = true, value = "Part revision version") @PathParam("partVersion") String partVersion); @GET @ApiOperation(value = "Get effectivities of a given PartRevision", response = EffectivityDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of effectivities. 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 getEffectivities(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Part revision number") @PathParam("partNumber") String partNumber,
            @ApiParam(required = true, value = "Part revision version") @PathParam("partVersion") String partVersion); @DELETE @ApiOperation(value = "Delete effectivity from given part revision", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of effectivity"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{effectivityId}") @Produces(MediaType.APPLICATION_JSON) Response deleteEffectivity(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Part revision number") @PathParam("partNumber") String partNumber,
            @ApiParam(required = true, value = "Part revision version") @PathParam("partVersion") String partVersion,
            @ApiParam(required = true, value = "Effectivity id") @PathParam("effectivityId") int effectivityId);  }
@Test public void getEffectivitiesTest() throws ApplicationException { PartRevision part = new PartRevision(); Set<Effectivity> list = new HashSet<>(); SerialNumberBasedEffectivity serialEffectivity = new SerialNumberBasedEffectivity(); DateBasedEffectivity dateEffectivity = new DateBasedEffectivity(); LotBasedEffectivity lotEffectivity = new LotBasedEffectivity(); list.add(serialEffectivity); list.add(dateEffectivity); list.add(lotEffectivity); part.setEffectivities(list); Mockito.when(productManager.getPartRevision(new PartRevisionKey(workspaceId, partNumber, partVersion))) .thenReturn(part); Response res = partEffectivityResource.getEffectivities(workspaceId, partNumber, partVersion); Object entity = res.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(ArrayList.class)); ArrayList resultList = (ArrayList) entity; Object e1 = resultList.get(0); Object e2 = resultList.get(1); Object e3 = resultList.get(2); Assert.assertTrue(e1.getClass().isAssignableFrom(EffectivityDTO.class)); Assert.assertTrue(e2.getClass().isAssignableFrom(EffectivityDTO.class)); Assert.assertTrue(e3.getClass().isAssignableFrom(EffectivityDTO.class)); List<TypeEffectivity> typeEffectivities = Arrays.asList( ((EffectivityDTO) e1).getTypeEffectivity(), ((EffectivityDTO) e2).getTypeEffectivity(), ((EffectivityDTO) e3).getTypeEffectivity() ); Assert.assertEquals(list.size(), typeEffectivities.size()); Assert.assertTrue(typeEffectivities.contains(TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY)); Assert.assertTrue(typeEffectivities.contains(TypeEffectivity.DATEBASEDEFFECTIVITY)); Assert.assertTrue(typeEffectivities.contains(TypeEffectivity.LOTBASEDEFFECTIVITY)); }