ProductBaselinesResource { @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) public 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) throws EntityNotFoundException, UserNotActiveException, AccessRightException, WorkspaceNotEnabledException { List<PathToPathLink> pathToPathLinks = productBaselineService.getPathToPathLinkFromSourceAndTarget(workspaceId, configurationItemId, baselineId, sourcePathAsString, targetPathAsString); List<PathToPathLinkDTO> pathToPathLinkDTOs = new ArrayList<>(); ConfigurationItemKey ciKey = new ConfigurationItemKey(workspaceId, configurationItemId); for (PathToPathLink pathToPathLink : pathToPathLinks) { PathToPathLinkDTO pathToPathLinkDTO = mapper.map(pathToPathLink, PathToPathLinkDTO.class); List<LightPartLinkDTO> sourceLightPartLinkDTOs = new ArrayList<>(); List<PartLink> sourcePath = productService.decodePath(ciKey, pathToPathLink.getSourcePath()); List<PartLink> targetPath = productService.decodePath(ciKey, pathToPathLink.getTargetPath()); for (PartLink partLink : sourcePath) { LightPartLinkDTO lightPartLinkDTO = new LightPartLinkDTO(partLink.getComponent().getNumber(), partLink.getComponent().getName(),partLink.getReferenceDescription(),partLink.getFullId()); sourceLightPartLinkDTOs.add(lightPartLinkDTO); } List<LightPartLinkDTO> targetLightPartLinkDTOs = new ArrayList<>(); for (PartLink partLink : targetPath) { LightPartLinkDTO lightPartLinkDTO = new LightPartLinkDTO(partLink.getComponent().getNumber(), partLink.getComponent().getName(),partLink.getReferenceDescription(),partLink.getFullId()); targetLightPartLinkDTOs.add(lightPartLinkDTO); } pathToPathLinkDTO.setSourceComponents(sourceLightPartLinkDTOs); pathToPathLinkDTO.setTargetComponents(targetLightPartLinkDTOs); pathToPathLinkDTOs.add(pathToPathLinkDTO); } return Response.ok(new GenericEntity<List<PathToPathLinkDTO>>((List<PathToPathLinkDTO>) pathToPathLinkDTOs) { }).build(); } 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 getPathToPathLinkInProductBaselineTest () throws ApplicationException { String sourcePathAsString = "source"; String targetPathAsString = "dest"; Mockito.when(productBaselineService.getPathToPathLinkFromSourceAndTarget(workspaceId, ciId, baseline.getId(), sourcePathAsString, targetPathAsString)) .thenReturn(pathToPathLinks); PartUsageLink link = new PartUsageLink(); link.setComponent(partMaster); List<PartLink> sourcePath = Collections.singletonList(link); Mockito.when(productService.decodePath(configurationItemKey, p2pLink.getSourcePath())) .thenReturn(sourcePath); List<PartLink> targetPath = Collections.singletonList(link); Mockito.when(productService.decodePath(configurationItemKey, p2pLink.getTargetPath())) .thenReturn(targetPath); Response response = productBaselineResource.getPathToPathLinkInProductBaseline(workspaceId, ciId, baseline.getId(), sourcePathAsString, targetPathAsString); Assert.assertNotNull(response); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }