Search in sources :

Example 1 with CustomFieldDocument

use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument in project synopsys-detect by blackducksoftware.

the class DetectCustomFieldParser method parseCustomFieldDocument.

public CustomFieldDocument parseCustomFieldDocument(Map<String, String> currentProperties) throws DetectUserFriendlyException {
    try {
        ConfigurationPropertySource source = new MapConfigurationPropertySource(currentProperties);
        Binder objectBinder = new Binder(source);
        BindResult<CustomFieldDocument> fieldDocumentBinding = objectBinder.bind("detect.custom.fields", CustomFieldDocument.class);
        CustomFieldDocument fieldDocument = fieldDocumentBinding.orElse(new CustomFieldDocument());
        fieldDocument.getProject().forEach(this::filterEmptyQuotes);
        fieldDocument.getVersion().forEach(this::filterEmptyQuotes);
        return fieldDocument;
    } catch (Exception e) {
        throw new DetectUserFriendlyException("Unable to parse custom fields.", e, ExitCodeType.FAILURE_CONFIGURATION);
    }
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) CustomFieldDocument(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource)

Example 2 with CustomFieldDocument

use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument in project synopsys-detect by blackducksoftware.

the class BlackDuckProjectVersionStepRunner method runAll.

ProjectVersionWrapper runAll(NameVersion projectNameVersion, BlackDuckRunData blackDuckRunData) throws DetectUserFriendlyException, OperationException {
    CloneFindResult cloneFindResult = findClone(projectNameVersion.getName(), blackDuckRunData);
    ProjectGroupFindResult projectGroupFindResult = findProjectGroup(blackDuckRunData);
    ProjectVersionLicenseFindResult projectVersionLicensesFindResult = findLicense(blackDuckRunData);
    ProjectVersionWrapper projectVersion = operationFactory.syncProjectVersion(projectNameVersion, projectGroupFindResult, cloneFindResult, projectVersionLicensesFindResult, blackDuckRunData);
    ParentProjectMapOptions mapOptions = operationFactory.calculateParentProjectMapOptions();
    if (StringUtils.isNotBlank(mapOptions.getParentProjectName()) || StringUtils.isNotBlank(mapOptions.getParentProjectVersionName())) {
        operationFactory.mapToParentProject(mapOptions.getParentProjectName(), mapOptions.getParentProjectVersionName(), projectVersion, blackDuckRunData);
    }
    String applicationId = operationFactory.calculateApplicationId();
    if (StringUtils.isBlank(applicationId)) {
        logger.debug("No 'Application ID' to set.");
    } else {
        operationFactory.setApplicationId(applicationId, projectVersion, blackDuckRunData);
    }
    CustomFieldDocument customFieldDocument = operationFactory.calculateCustomFields();
    if (customFieldDocument == null || (customFieldDocument.getProject().size() == 0 && customFieldDocument.getVersion().size() == 0)) {
        logger.debug("No custom fields to set.");
    } else {
        operationFactory.updateCustomFields(customFieldDocument, projectVersion, blackDuckRunData);
    }
    List<String> userGroups = operationFactory.calculateUserGroups();
    if (userGroups == null) {
        logger.debug("No user groups to set.");
    } else {
        operationFactory.addUserGroups(userGroups, projectVersion, blackDuckRunData);
    }
    List<String> tags = operationFactory.calculateTags();
    if (tags == null) {
        logger.debug("No tags to set.");
    } else {
        operationFactory.addTags(tags, projectVersion, blackDuckRunData);
    }
    if (operationFactory.calculateShouldUnmap()) {
        logger.debug("Unmapping code locations.");
        operationFactory.unmapCodeLocations(projectVersion, blackDuckRunData);
    } else {
        logger.debug("Will not unmap code locations: Project view was not present, or should not unmap code locations.");
    }
    return projectVersion;
}
Also used : ProjectGroupFindResult(com.synopsys.integration.detect.workflow.blackduck.project.options.ProjectGroupFindResult) ParentProjectMapOptions(com.synopsys.integration.detect.workflow.blackduck.project.options.ParentProjectMapOptions) CustomFieldDocument(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument) CloneFindResult(com.synopsys.integration.detect.workflow.blackduck.project.options.CloneFindResult) ProjectVersionLicenseFindResult(com.synopsys.integration.detect.workflow.blackduck.project.options.ProjectVersionLicenseFindResult) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)

Example 3 with CustomFieldDocument

use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument in project synopsys-detect by blackducksoftware.

the class DetectCustomFieldParserTest method parsedProject.

@Test
public void parsedProject() throws DetectUserFriendlyException {
    Map<String, String> props = new HashMap<>();
    props.put("detect.custom.fields.project[0].label", "label");
    props.put("detect.custom.fields.project[0].value", "value1, value2");
    DetectCustomFieldParser parser = new DetectCustomFieldParser();
    CustomFieldDocument document = parser.parseCustomFieldDocument(props);
    Assertions.assertEquals(1, document.getProject().size());
    CustomFieldElement element = document.getProject().get(0);
    Assertions.assertEquals("label", element.getLabel());
    Assertions.assertEquals(2, element.getValue().size());
    Assertions.assertTrue(element.getValue().contains("value1"));
    Assertions.assertTrue(element.getValue().contains("value2"));
}
Also used : CustomFieldDocument(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument) CustomFieldElement(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldElement) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 4 with CustomFieldDocument

use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument in project synopsys-detect by blackducksoftware.

the class DetectCustomFieldParserTest method parsedProjectMultiple.

@Test
public void parsedProjectMultiple() throws DetectUserFriendlyException {
    Map<String, String> props = new HashMap<>();
    props.put("detect.custom.fields.project[0].label", "label");
    props.put("detect.custom.fields.project[0].value", "value1");
    props.put("detect.custom.fields.project[1].label", "label");
    props.put("detect.custom.fields.project[1].value", "value1");
    props.put("detect.custom.fields.project[2].label", "label");
    props.put("detect.custom.fields.project[2].value", "value1");
    DetectCustomFieldParser parser = new DetectCustomFieldParser();
    CustomFieldDocument document = parser.parseCustomFieldDocument(props);
    Assertions.assertEquals(3, document.getProject().size());
}
Also used : CustomFieldDocument(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 5 with CustomFieldDocument

use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument in project synopsys-detect by blackducksoftware.

the class DetectCustomFieldParserTest method parsedMissingValueStillList.

@Test
public void parsedMissingValueStillList() throws DetectUserFriendlyException {
    Map<String, String> props = new HashMap<>();
    props.put("detect.custom.fields.project[0].label", "label");
    DetectCustomFieldParser parser = new DetectCustomFieldParser();
    CustomFieldDocument document = parser.parseCustomFieldDocument(props);
    CustomFieldElement element = document.getProject().get(0);
    Assertions.assertEquals(0, element.getValue().size());
}
Also used : CustomFieldDocument(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument) CustomFieldElement(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldElement) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

CustomFieldDocument (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument)11 HashMap (java.util.HashMap)9 Test (org.junit.jupiter.api.Test)9 CustomFieldElement (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldElement)7 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 CloneFindResult (com.synopsys.integration.detect.workflow.blackduck.project.options.CloneFindResult)1 ParentProjectMapOptions (com.synopsys.integration.detect.workflow.blackduck.project.options.ParentProjectMapOptions)1 ProjectGroupFindResult (com.synopsys.integration.detect.workflow.blackduck.project.options.ProjectGroupFindResult)1 ProjectVersionLicenseFindResult (com.synopsys.integration.detect.workflow.blackduck.project.options.ProjectVersionLicenseFindResult)1 Binder (org.springframework.boot.context.properties.bind.Binder)1 ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)1 MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)1