PartEffectivityResource { @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) public 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) throws UserNotActiveException, EntityNotFoundException, AccessRightException, WorkspaceNotEnabledException, EntityAlreadyExistsException, CreationException { TypeEffectivity typeEffectivity = effectivity.getTypeEffectivity(); Effectivity createdEffectivity = null; EffectivityDTO returnedEffectivityDTO; ConfigurationItemKey configurationItemKey = effectivity.getConfigurationItemKey(); String productId = configurationItemKey != null ? configurationItemKey.getId() : null; if (TypeEffectivity.DATEBASEDEFFECTIVITY.equals(typeEffectivity)) { createdEffectivity = effectivityManager.createDateBasedEffectivity( workspaceId, partNumber, partVersion, effectivity.getName(), effectivity.getDescription(), productId, effectivity.getStartDate(), effectivity.getEndDate()); } else if (TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY.equals(typeEffectivity)) { createdEffectivity = effectivityManager.createSerialNumberBasedEffectivity( workspaceId, partNumber, partVersion, effectivity.getName(), effectivity.getDescription(), productId, effectivity.getStartNumber(), effectivity.getEndNumber()); } else if (TypeEffectivity.LOTBASEDEFFECTIVITY.equals(typeEffectivity)) { createdEffectivity = effectivityManager.createLotBasedEffectivity( workspaceId, partNumber, partVersion, effectivity.getName(), effectivity.getDescription(), productId, effectivity.getStartLotId(), effectivity.getEndLotId()); } returnedEffectivityDTO = mapper.map(createdEffectivity, EffectivityDTO.class); returnedEffectivityDTO.setConfigurationItemKey(configurationItemKey); returnedEffectivityDTO.setTypeEffectivity(effectivity.getTypeEffectivity()); return returnedEffectivityDTO; } 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 createEffectivityTest() throws ApplicationException { EffectivityDTO effectivity = new EffectivityDTO(); effectivity.setTypeEffectivity(TypeEffectivity.DATEBASEDEFFECTIVITY); Mockito.when(effectivityManager.createDateBasedEffectivity(workspaceId, partNumber, partVersion, effectivity.getName(), effectivity.getDescription(), null, effectivity.getStartDate(), effectivity.getEndDate())) .thenReturn(new DateBasedEffectivity()); EffectivityDTO result = partEffectivityResource.createEffectivity(effectivity, workspaceId, partNumber, partVersion); Assert.assertEquals(TypeEffectivity.DATEBASEDEFFECTIVITY, result.getTypeEffectivity()); effectivity.setTypeEffectivity(TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY); Mockito.when(effectivityManager.createSerialNumberBasedEffectivity( workspaceId, partNumber, partVersion, effectivity.getName(), effectivity.getDescription(), null, effectivity.getStartNumber(), effectivity.getEndNumber())) .thenReturn(new SerialNumberBasedEffectivity()); result = partEffectivityResource.createEffectivity(effectivity, workspaceId, partNumber, partVersion); Assert.assertEquals(TypeEffectivity.SERIALNUMBERBASEDEFFECTIVITY, result.getTypeEffectivity()); effectivity.setTypeEffectivity(TypeEffectivity.LOTBASEDEFFECTIVITY); Mockito.when(effectivityManager.createLotBasedEffectivity( workspaceId, partNumber, partVersion, effectivity.getName(), effectivity.getDescription(), null, effectivity.getStartLotId(), effectivity.getEndLotId())) .thenReturn(new LotBasedEffectivity()); result = partEffectivityResource.createEffectivity(effectivity, workspaceId, partNumber, partVersion); Assert.assertEquals(TypeEffectivity.LOTBASEDEFFECTIVITY, result.getTypeEffectivity()); }