Search in sources :

Example 1 with ProjectMappingView

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);
    }
}
Also used : ProjectMappingView(com.synopsys.integration.blackduck.api.manual.view.ProjectMappingView) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 2 with 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);
}
Also used : ProjectMappingView(com.synopsys.integration.blackduck.api.manual.view.ProjectMappingView) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectMappingView (com.synopsys.integration.blackduck.api.manual.view.ProjectMappingView)2 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)1 HttpUrl (com.synopsys.integration.rest.HttpUrl)1 Test (org.junit.jupiter.api.Test)1