use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation in project synopsys-detect by blackducksoftware.
the class UpdateCustomFieldsOperation method pairOperationFromViews.
private List<CustomFieldOperation> pairOperationFromViews(List<CustomFieldElement> elements, List<CustomFieldView> views, String targetName, BlackDuckApiClient blackDuckService) throws DetectUserFriendlyException {
List<CustomFieldOperation> operations = new ArrayList<>();
for (CustomFieldElement element : elements) {
Optional<CustomFieldView> fieldView = views.stream().filter(view -> view.getLabel().equals(element.getLabel())).findFirst();
if (!fieldView.isPresent()) {
throw new DetectUserFriendlyException(String.format("Unable to find custom field view with label '%s' on the %s. Ensure it exists.", element.getLabel(), targetName), ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
}
List<String> values = new ArrayList<>();
List<CustomFieldOptionView> options = retrieveCustomFieldOptions(fieldView.get(), blackDuckService);
if (options.isEmpty()) {
logger.debug("Did not find any associated options for this field, will use raw values.");
values = element.getValue();
} else {
logger.debug("Found one or more options for this field. Will attempt to map given values to fields..");
for (String value : element.getValue()) {
Optional<CustomFieldOptionView> option = options.stream().filter(it -> it.getLabel().equals(value)).findFirst();
if (option.isPresent()) {
values.add(option.get().getHref().string());
} else {
throw new DetectUserFriendlyException(String.format("Unable to update custom field '%s', unable to find option for value '%s'", element.getLabel(), value), ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
}
}
}
operations.add(new CustomFieldOperation(fieldView.get(), values));
}
return operations;
}
use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation in project synopsys-detect by blackducksoftware.
the class UpdateCustomFieldsOperation method executeCustomFieldOperations.
// radio, multiselect, and dropdown
private void executeCustomFieldOperations(List<CustomFieldOperation> operations, BlackDuckApiClient blackDuckService) throws DetectUserFriendlyException {
for (CustomFieldOperation operation : operations) {
CustomFieldView fieldView = operation.customField;
fieldView.setValues(operation.values);
try {
blackDuckService.put(fieldView);
} catch (IntegrationException e) {
throw new DetectUserFriendlyException(String.format("Unable to update custom field label with name '%s'", operation.customField.getLabel()), e, ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
}
}
}
use of com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation 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.");
}
Aggregations