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