use of com.synopsys.integration.blackduck.api.manual.view.ProjectMappingView in project blackduck-common by blackducksoftware.
the class ProjectMappingService method populateApplicationId.
public void populateApplicationId(ProjectView projectView, String applicationId) throws IntegrationException {
List<ProjectMappingView> projectMappings = blackDuckApiClient.getAllResponses(projectView.metaProjectMappingsLink());
boolean canCreate = projectMappings.isEmpty();
if (canCreate) {
if (!projectView.hasLink(ProjectView.PROJECT_MAPPINGS_LINK)) {
throw new BlackDuckIntegrationException(String.format("The supplied projectView does not have the link (%s) to create a project mapping.", ProjectView.PROJECT_MAPPINGS_LINK));
}
HttpUrl projectMappingsLink = projectView.getFirstLink(ProjectView.PROJECT_MAPPINGS_LINK);
ProjectMappingView projectMappingView = new ProjectMappingView();
projectMappingView.setApplicationId(applicationId);
blackDuckApiClient.post(projectMappingsLink, projectMappingView);
} else {
// Currently there exists only one project-mapping which is the project's Application ID.
// Eventually, this method would need to take in a namespace on which we will need to filter.
ProjectMappingView projectMappingView = projectMappings.get(0);
projectMappingView.setApplicationId(applicationId);
blackDuckApiClient.put(projectMappingView);
}
}
use of com.synopsys.integration.blackduck.api.manual.view.ProjectMappingView in project blackduck-common by blackducksoftware.
the class ProjectMappingServiceTest method populateApplicationId.
@Test
void populateApplicationId() throws IntegrationException {
List<ProjectMappingView> projectMappings = projectMappingService.getProjectMappings(projectView);
assertEquals(0, projectMappings.size());
// Testing Creation
projectMappingService.populateApplicationId(projectView, "testApplicationId1");
projectMappings = projectMappingService.getProjectMappings(projectView);
assertEquals(1, projectMappings.size());
ProjectMappingView projectMappingView = projectMappings.get(0);
String applicationId = projectMappingView.getApplicationId();
assertEquals("testApplicationId1", applicationId);
// Testing Updating
projectMappingService.populateApplicationId(projectView, "testApplicationId2");
projectMappings = projectMappingService.getProjectMappings(projectView);
assertEquals(1, projectMappings.size());
projectMappingView = projectMappings.get(0);
applicationId = projectMappingView.getApplicationId();
assertEquals("testApplicationId2", applicationId);
}
Aggregations