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);
}
}
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;
}
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"));
}
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());
}
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());
}
Aggregations