Search in sources :

Example 16 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class UnmapCodeLocationsOperation method unmapCodeLocations.

public void unmapCodeLocations(ProjectVersionView projectVersionView) throws DetectUserFriendlyException {
    try {
        List<CodeLocationView> codeLocationViews = blackDuckService.getAllResponses(projectVersionView.metaCodelocationsLink());
        for (CodeLocationView codeLocationView : codeLocationViews) {
            codeLocationService.unmapCodeLocation(codeLocationView);
        }
        logger.info("Successfully unmapped (" + codeLocationViews.size() + ") code locations.");
    } catch (IntegrationException e) {
        String errorMessage = String.format("There was a problem unmapping Code Locations: %s", e.getMessage());
        throw new DetectUserFriendlyException(errorMessage, e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException)

Example 17 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class CreateAggregateBdio2FileOperation method writeDocument.

private void writeDocument(File aggregateFile, Bdio2Document bdio2Document) throws DetectUserFriendlyException {
    Bdio2Writer bdio2Writer = new Bdio2Writer();
    try {
        OutputStream outputStream = new FileOutputStream(aggregateFile);
        bdio2Writer.writeBdioDocument(outputStream, bdio2Document);
        logger.debug(String.format("BDIO Generated: %s", aggregateFile.getAbsolutePath()));
    } catch (IOException e) {
        throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
    }
}
Also used : Bdio2Writer(com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 18 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException 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;
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) CustomFieldElement(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldElement) ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) IntegrationException(com.synopsys.integration.exception.IntegrationException) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) CustomFieldOperation(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ArrayList(java.util.ArrayList) LinkMultipleResponses(com.synopsys.integration.blackduck.api.core.response.LinkMultipleResponses) CustomFieldDocument(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldDocument) CustomFieldOptionView(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOptionView) List(java.util.List) CustomFieldView(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldView) BlackDuckView(com.synopsys.integration.blackduck.api.core.BlackDuckView) Optional(java.util.Optional) NoSuchElementException(java.util.NoSuchElementException) Collections(java.util.Collections) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) CustomFieldView(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldView) ArrayList(java.util.ArrayList) CustomFieldOperation(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation) CustomFieldOptionView(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOptionView) CustomFieldElement(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldElement) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException)

Example 19 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException 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);
        }
    }
}
Also used : CustomFieldView(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldView) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException) CustomFieldOperation(com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation)

Example 20 with DetectUserFriendlyException

use of com.synopsys.integration.detect.configuration.DetectUserFriendlyException in project synopsys-detect by blackducksoftware.

the class BlackDuckConfigFactory method createServerConfig.

public BlackDuckServerConfig createServerConfig(IntLogger intLogger) throws DetectUserFriendlyException {
    IntLogger logger;
    if (intLogger == null) {
        logger = new SilentIntLogger();
    } else {
        logger = intLogger;
    }
    ConnectionDetails connectionDetails = blackDuckConnectionDetails.getConnectionDetails();
    BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = BlackDuckServerConfig.newApiTokenBuilder().setExecutorService(Executors.newFixedThreadPool(blackDuckConnectionDetails.getParallelProcessors())).setLogger(logger);
    blackDuckServerConfigBuilder.setProperties(blackDuckConnectionDetails.getBlackduckProperties().entrySet());
    blackDuckServerConfigBuilder.setProperty(BLACK_DUCK_SERVER_CONFIG_BUILDER_TIMEOUT_KEY, blackDuckConnectionDetails.getConnectionDetails().getTimeout().toString());
    blackDuckServerConfigBuilder.setSolutionDetails(new NameVersion("synopsys_detect", detectInfo.getDetectVersion()));
    Optional<Boolean> shouldIgnore = blackDuckConnectionDetails.getBlackDuckUrl().map(blackduckUrl -> ProxyUtil.shouldIgnoreUrl(blackduckUrl, connectionDetails.getIgnoredProxyHostPatterns(), logger));
    if (shouldIgnore.isPresent() && Boolean.TRUE.equals(shouldIgnore.get())) {
        blackDuckServerConfigBuilder.setProxyInfo(ProxyInfo.NO_PROXY_INFO);
    } else {
        blackDuckServerConfigBuilder.setProxyInfo(connectionDetails.getProxyInformation());
    }
    try {
        return blackDuckServerConfigBuilder.build();
    } catch (IllegalArgumentException e) {
        throw new DetectUserFriendlyException("Failed to configure Black Duck server connection: " + e.getMessage(), e, ExitCodeType.FAILURE_CONFIGURATION);
    }
}
Also used : SilentIntLogger(com.synopsys.integration.log.SilentIntLogger) BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) NameVersion(com.synopsys.integration.util.NameVersion) SilentIntLogger(com.synopsys.integration.log.SilentIntLogger) IntLogger(com.synopsys.integration.log.IntLogger)

Aggregations

DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)33 File (java.io.File)14 IntegrationException (com.synopsys.integration.exception.IntegrationException)12 IOException (java.io.IOException)12 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 ExitCodeType (com.synopsys.integration.detect.configuration.enumeration.ExitCodeType)3 ArrayList (java.util.ArrayList)3 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 SpdxCreator (com.synopsys.integration.bdio.model.SpdxCreator)2 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 ProductRunData (com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)2 CustomFieldOperation (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldOperation)2 CustomFieldView (com.synopsys.integration.detect.workflow.blackduck.project.customfields.CustomFieldView)2 SilentIntLogger (com.synopsys.integration.log.SilentIntLogger)2 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)2 FileOutputStream (java.io.FileOutputStream)2