ProductBaselinesResource { @POST @ApiOperation(value = "Create a new product-baseline", response = ProductBaselineDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ProductBaselineDTO"), @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) public ProductBaselineDTO createProductBaseline( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Product baseline to create") ProductBaselineCreationDTO productBaselineDTO, @ApiParam(required = false, value = "Dry run flag") @QueryParam("dryRun") boolean dryRun) throws UserNotActiveException, EntityNotFoundException, NotAllowedException, AccessRightException, PartRevisionNotReleasedException, EntityConstraintException, CreationException, EntityAlreadyExistsException, WorkspaceNotEnabledException { String ciId = productBaselineDTO.getConfigurationItemId(); ConfigurationItemKey ciKey = new ConfigurationItemKey(workspaceId, ciId); String description = productBaselineDTO.getDescription(); String name = productBaselineDTO.getName(); ProductBaselineType type = productBaselineDTO.getType(); List<BaselinedPartDTO> baselinedPartsDTO = productBaselineDTO.getBaselinedParts(); List<PartIterationKey> partIterationKeys = baselinedPartsDTO.stream() .map(part -> new PartIterationKey(workspaceId, part.getNumber(), part.getVersion(), part.getIteration())).collect(Collectors.toList()); ProductBaseline baseline = productBaselineService.createBaseline(ciKey, name, type, description, partIterationKeys, productBaselineDTO.getSubstituteLinks(), productBaselineDTO.getOptionalUsageLinks(), productBaselineDTO.getEffectiveDate(), productBaselineDTO.getEffectiveSerialNumber(), productBaselineDTO.getEffectiveLotId(), dryRun); ProductBaselineDTO dto = mapper.map(baseline, ProductBaselineDTO.class); dto.setConfigurationItemLatestRevision(baseline.getConfigurationItem().getDesignItem().getLastRevision().getVersion()); if(!dryRun) { dto.setHasObsoletePartRevisions(!productBaselineService.getObsoletePartRevisionsInBaseline(workspaceId, baseline.getId()).isEmpty()); } return dto; } ProductBaselinesResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get product-baselines in given workspace", response = ProductBaselineDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ProductBaselineDTOs. 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 getAllProductBaselines(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @GET @Path("{ciId}/baselines") @ApiOperation(value = "Get product-baseline with given configuration item", response = ProductBaselineDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ProductBaselineDTOs. 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 getProductBaselinesForProduct(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Configuration item id") @PathParam("ciId") String ciId); @POST @ApiOperation(value = "Create a new product-baseline", response = ProductBaselineDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ProductBaselineDTO"), @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) ProductBaselineDTO createProductBaseline(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Product baseline to create") ProductBaselineCreationDTO productBaselineDTO,
            @ApiParam(required = false, value = "Dry run flag") @QueryParam("dryRun") boolean dryRun); @DELETE @ApiOperation(value = "Delete product-baseline", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of ProductBaselineDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{ciId}/baselines/{baselineId}") @Consumes(MediaType.APPLICATION_JSON) Response deleteProductBaseline(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Configuration item id") @PathParam("ciId") String ciId,
            @ApiParam(required = true, value = "Baseline id") @PathParam("baselineId") int baselineId); @GET @ApiOperation(value = "Get product-baseline by id", response = ProductBaselineDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ProductBaselineDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{ciId}/baselines/{baselineId}") @Produces(MediaType.APPLICATION_JSON) ProductBaselineDTO getProductBaseline(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Configuration item id") @PathParam("ciId") String ciId,
            @ApiParam(required = true, value = "Baseline id") @PathParam("baselineId") int baselineId); @GET @ApiOperation(value = "Get product-baseline's baselined parts", response = BaselinedPartDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of BaselinedPartDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{ciId}/baselines/{baselineId}/parts") @Produces(MediaType.APPLICATION_JSON) Response getProductBaselineParts(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Configuration item id") @PathParam("ciId") String ciId,
            @ApiParam(required = true, value = "Baseline id") @PathParam("baselineId") int baselineId,
            @ApiParam(required = true, value = "Query") @QueryParam("q") String q); @GET @ApiOperation(value = "Get product-baseline's path-to-path links", response = LightPathToPathLinkDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of LightPathToPathLinkDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{ciId}/baselines/{baselineId}/path-to-path-links-types") @Produces(MediaType.APPLICATION_JSON) Response getPathToPathLinkTypesInBaseline(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Configuration item id") @PathParam("ciId") String ciId,
            @ApiParam(required = true, value = "Baseline id") @PathParam("baselineId") int baselineId); @GET @ApiOperation(value = "Get product-baseline's path-to-path links for given source and target", response = LightPathToPathLinkDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of LightPathToPathLinkDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{ciId}/baselines/{baselineId}/path-to-path-links/source/{sourcePath}/target/{targetPath}") @Produces(MediaType.APPLICATION_JSON) Response getPathToPathLinkInProductBaseline(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Configuration item id") @PathParam("ciId") String configurationItemId,
            @ApiParam(required = true, value = "Baseline id") @PathParam("baselineId") int baselineId,
            @ApiParam(required = true, value = "Source path") @PathParam("sourcePath") String sourcePathAsString,
            @ApiParam(required = true, value = "Target path") @PathParam("targetPath") String targetPathAsString);  }
@Test public void createProductBaselineTest() throws ApplicationException { ProductBaselineCreationDTO dto = new ProductBaselineCreationDTO(); dto.setConfigurationItemId(ciId); dto.setBaselinedParts(new ArrayList<>()); dto.setType(ProductBaselineType.LATEST); dto.setName(name); dto.setDescription(description); List<PartIterationKey> partIterationKeys = dto.getBaselinedParts().stream() .map(part -> new PartIterationKey(workspaceId, part.getNumber(), part.getVersion(), part.getIteration())).collect(Collectors.toList()); Mockito.when(productBaselineService.createBaseline(configurationItemKey, name, ProductBaselineType.LATEST, description, partIterationKeys, dto.getSubstituteLinks(), dto.getOptionalUsageLinks(), null, null, null, true)) .thenReturn(baseline); ProductBaselineDTO productBaseline = productBaselineResource.createProductBaseline(workspaceId, dto, true); Mockito.verify(productBaselineService, times(0)).getObsoletePartRevisionsInBaseline(workspaceId, baseline.getId()); Assert.assertNotNull(productBaseline); Mockito.when(productBaselineService.createBaseline(configurationItemKey, name, ProductBaselineType.LATEST, description, partIterationKeys, dto.getSubstituteLinks(), dto.getOptionalUsageLinks(), null, null, null, false)) .thenReturn(baseline); productBaselineResource.createProductBaseline(workspaceId, dto, false); Mockito.verify(productBaselineService, times(1)).getObsoletePartRevisionsInBaseline(workspaceId, baseline.getId()); }