Search in sources :

Example 6 with CustomFieldElement

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

the class DetectCustomFieldParserTest method parsedEmptyQuotesAsEmptyArray.

@Test
public void parsedEmptyQuotesAsEmptyArray() throws DetectUserFriendlyException {
    Map<String, String> props = new HashMap<>();
    props.put("detect.custom.fields.project[0].name", "example");
    props.put("detect.custom.fields.project[0].value", "\"\"");
    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)

Example 7 with CustomFieldElement

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

the class DetectCustomFieldParserTest method parsedVersion.

@Test
public void parsedVersion() throws DetectUserFriendlyException {
    Map<String, String> props = new HashMap<>();
    props.put("detect.custom.fields.version[0].label", "label");
    props.put("detect.custom.fields.version[0].value", "value1, value2");
    DetectCustomFieldParser parser = new DetectCustomFieldParser();
    CustomFieldDocument document = parser.parseCustomFieldDocument(props);
    Assertions.assertEquals(1, document.getVersion().size());
    CustomFieldElement element = document.getVersion().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 8 with CustomFieldElement

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

the class DetectCustomFieldParserTest method parsedMissingLabelStillList.

@Test
public void parsedMissingLabelStillList() throws DetectUserFriendlyException {
    Map<String, String> props = new HashMap<>();
    props.put("detect.custom.fields.project[0].value", "value1");
    DetectCustomFieldParser parser = new DetectCustomFieldParser();
    CustomFieldDocument document = parser.parseCustomFieldDocument(props);
    CustomFieldElement element = document.getProject().get(0);
    Assertions.assertEquals("", element.getLabel());
}
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 9 with CustomFieldElement

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

the class UpdateCustomFieldsOperation method updateCustomFields.

public void updateCustomFields(ProjectVersionWrapper projectVersionWrapper, CustomFieldDocument customFieldDocument) throws DetectUserFriendlyException {
    logger.debug("Will update the following custom fields and values.");
    for (CustomFieldElement element : customFieldDocument.getProject()) {
        logger.debug(String.format("Project field '%s' will be set to '%s'.", element.getLabel(), String.join(",", element.getValue())));
    }
    for (CustomFieldElement element : customFieldDocument.getVersion()) {
        logger.debug(String.format("Version field '%s' will be set to '%s'.", element.getLabel(), String.join(",", element.getValue())));
    }
    List<CustomFieldOperation> customFieldOperations = determineOperations(customFieldDocument, projectVersionWrapper, blackDuckService);
    executeCustomFieldOperations(customFieldOperations, blackDuckService);
    logger.info("Successfully updated (" + (customFieldDocument.getVersion().size() + customFieldDocument.getProject().size()) + ") custom fields.");
}
Also used : CustomFieldElement(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldElement) CustomFieldOperation(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation)

Aggregations

CustomFieldElement (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldElement)9 CustomFieldDocument (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 CustomFieldOperation (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation)2 BlackDuckView (com.synopsys.integration.blackduck.api.core.BlackDuckView)1 LinkMultipleResponses (com.synopsys.integration.blackduck.api.core.response.LinkMultipleResponses)1 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)1 ExitCodeType (com.synopsys.integration.detect.configuration.enumeration.ExitCodeType)1 CustomFieldOptionView (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOptionView)1 CustomFieldView (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldView)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 Logger (org.slf4j.Logger)1