Search in sources :

Example 51 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckProviderService method findBlackDuckProvider.

public String findBlackDuckProvider() throws IntegrationException {
    String blackDuckProviderSearch = String.format("/api/configuration?context=%s&descriptorName=%s", ConfigContextEnum.GLOBAL, blackDuckProviderKey);
    String response = alertRequestUtility.executeGetRequest(blackDuckProviderSearch, "Could not find the Black Duck provider.");
    MultiFieldModel blackDuckConfigurations = gson.fromJson(response, MultiFieldModel.class);
    FieldModel blackDuckProviderConfiguration = blackDuckConfigurations.getFieldModels().stream().filter(blackDuckConfiguration -> blackDuckConfiguration.getFieldValue("blackduck.url").filter(blackDuckProviderUrl::equals).isPresent()).findFirst().orElseThrow(() -> new IntegrationException("Could not find the BlackDuck provider configuration."));
    String blackDuckProviderID = blackDuckProviderConfiguration.getId();
    String blackDuckConfigBody = gson.toJson(blackDuckProviderConfiguration);
    alertRequestUtility.executePutRequest("/api/configuration/" + blackDuckProviderID, blackDuckConfigBody, "Could not save the Black Duck provider.");
    intLogger.info(String.format("Retrieved the Black Duck provider, ID %s.", blackDuckProviderID));
    return blackDuckProviderID;
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel)

Example 52 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckProviderService method triggerBlackDuckNotification.

public void triggerBlackDuckNotification(Supplier<ExternalId> externalIdSupplier, Predicate<ProjectVersionComponentVersionView> componentFilter) throws IntegrationException {
    setupBlackDuckServicesFactory();
    BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    ProjectVersionWrapper projectVersion = projectService.getProjectVersion(blackDuckProjectName, blackDuckProjectVersion).orElseThrow(() -> new IntegrationException(String.format("Could not find the Black Duck project '%s' version '%s'", blackDuckProjectName, blackDuckProjectVersion)));
    ProjectVersionView projectVersionView = projectVersion.getProjectVersionView();
    List<ProjectVersionComponentVersionView> bomComponents = blackDuckService.getAllResponses(projectVersionView.metaComponentsLink());
    Optional<ProjectVersionComponentVersionView> apacheCommonsFileUpload = bomComponents.stream().filter(componentFilter).findFirst();
    if (apacheCommonsFileUpload.isPresent()) {
        blackDuckService.delete(apacheCommonsFileUpload.get());
    // Thread.currentThread().wait(1000);
    }
    ExternalId externalId = externalIdSupplier.get();
    ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
    projectBomService.addComponentToProjectVersion(externalId, projectVersionView);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 53 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class ConfigurationManager method createGlobalConfiguration.

public void createGlobalConfiguration(FieldModel globalConfig) {
    String configurationRequestBody = gson.toJson(globalConfig);
    String descriptorName = globalConfig.getDescriptorName();
    try {
        String globalConfigSearchResponse = alertRequestUtility.executeGetRequest(String.format("/api/configuration?context=%s&descriptorName=%s", ConfigContextEnum.GLOBAL.name(), descriptorName), String.format("Could not find the existing global configuration for %s.", descriptorName));
        JsonObject globalConfigSearchJsonObject = gson.fromJson(globalConfigSearchResponse, JsonObject.class);
        JsonArray fieldModels = globalConfigSearchJsonObject.get("fieldModels").getAsJsonArray();
        JsonElement firstFieldModel = fieldModels.get(0);
        FieldModel originalGlobalConfig = gson.fromJson(firstFieldModel, FieldModel.class);
        globalConfig.setId(originalGlobalConfig.getId());
        alertRequestUtility.executePostRequest("/api/configuration/validate", configurationRequestBody, String.format("Validating the global configuration %s failed.", descriptorName));
        alertRequestUtility.executePostRequest("/api/configuration/test", configurationRequestBody, String.format("Testing the global configuration %s failed.", descriptorName));
        alertRequestUtility.executePutRequest(String.format("/api/configuration/%s", globalConfig.getId()), configurationRequestBody, String.format("Could not create the global configuration %s.", descriptorName));
    } catch (IntegrationException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) IntegrationException(com.synopsys.integration.exception.IntegrationException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel)

Aggregations

IntegrationException (com.synopsys.integration.exception.IntegrationException)53 HttpUrl (com.synopsys.integration.rest.HttpUrl)19 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)9 ArrayList (java.util.ArrayList)9 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)8 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 Set (java.util.Set)8 Test (org.junit.jupiter.api.Test)8 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)7 List (java.util.List)7 Optional (java.util.Optional)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)6