use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class BlackDuckDistributionFieldModelTestActionTest method createFieldUtilityData.
private FieldUtility createFieldUtilityData(String projectNamePattern, String projectVersionNamePattern) {
ConfigurationFieldModel providerConfigId = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
providerConfigId.setFieldValue("1");
ConfigurationFieldModel filterByProject = ConfigurationFieldModel.create(ProviderDescriptor.KEY_FILTER_BY_PROJECT);
filterByProject.setFieldValue("true");
ConfigurationFieldModel configuredProject = ConfigurationFieldModel.create(ProviderDescriptor.KEY_CONFIGURED_PROJECT);
ConfigurationFieldModel projectNamePatternField = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROJECT_NAME_PATTERN);
projectNamePatternField.setFieldValue(projectNamePattern);
ConfigurationFieldModel projectVersionNamePatternField = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN);
projectVersionNamePatternField.setFieldValue(projectVersionNamePattern);
Map<String, ConfigurationFieldModel> fieldModelMap = DataStructureUtils.mapToValues(List.of(providerConfigId, filterByProject, configuredProject, projectNamePatternField, projectVersionNamePatternField), ConfigurationFieldModel::getFieldKey);
return new FieldUtility(fieldModelMap);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class NotificationExtractorBlackDuckServicesFactoryCacheTest method createConfigurationModel.
private ConfigurationModel createConfigurationModel() {
Map<String, ConfigurationFieldModel> configuredFields = new HashMap<>();
ConfigurationFieldModel apiKey = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
apiKey.setFieldValue("blackDuckApiKey");
configuredFields.put(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, apiKey);
ConfigurationFieldModel url = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
url.setFieldValue("http://blackDuckUrl");
configuredFields.put(BlackDuckDescriptor.KEY_BLACKDUCK_URL, url);
return new ConfigurationModel(1L, 2L, "createdAt", "lastUpdated", ConfigContextEnum.GLOBAL, configuredFields);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method createFieldsMap.
private Map<String, ConfigurationFieldModel> createFieldsMap(FieldModel channelFieldModel, Collection<FieldModel> otherJobModels) throws AlertException {
Map<String, ConfigurationFieldModel> fields = new HashMap<>();
fields.putAll(modelConverter.convertToConfigurationFieldModelMap(channelFieldModel));
Optional<ConfigurationModel> configurationFieldModel = configurationModelConfigurationAccessor.getConfigurationsByDescriptorNameAndContext(channelFieldModel.getDescriptorName(), ConfigContextEnum.GLOBAL).stream().findFirst();
configurationFieldModel.ifPresent(model -> fields.putAll(model.getCopyOfKeyToFieldMap()));
for (FieldModel fieldModel : otherJobModels) {
fields.putAll(modelConverter.convertToConfigurationFieldModelMap(fieldModel));
}
return fields;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method createWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> createWithoutChecks(JobFieldModel resource) {
try {
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeSaveEventFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
Collection<ConfigurationFieldModel> savedFieldsModels = modelConverter.convertToConfigurationFieldModelMap(beforeSaveEventFieldModel).values();
configurationFieldModels.addAll(savedFieldsModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, DateUtils.createCurrentDateTimestamp(), null);
DistributionJobModel savedJob = jobAccessor.createJob(jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel updatedModel = fieldModelProcessor.performAfterSaveAction(fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} catch (AlertException ex) {
logger.error("Error creating job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method testWithoutChecks.
@Override
protected ValidationActionResponse testWithoutChecks(JobFieldModel resource) {
ValidationResponseModel responseModel;
String jobIdString = resource.getJobId();
UUID jobId = Optional.ofNullable(jobIdString).filter(StringUtils::isNotBlank).map(UUID::fromString).orElse(null);
try {
Collection<FieldModel> otherJobModels = new LinkedList<>();
FieldModel channelFieldModel = getChannelFieldModelAndPopulateOtherJobModels(resource, otherJobModels);
if (null != channelFieldModel) {
String channelDescriptorName = channelFieldModel.getDescriptorName();
Map<String, ConfigurationFieldModel> fields = createFieldsMap(channelFieldModel, otherJobModels);
// The custom message fields are not written to the database or defined fields in the database. Need to manually add them.
// TODO Create a mechanism to create the field accessor with a combination of fields in the database and fields that are not.
Optional<ConfigurationFieldModel> topicField = convertFieldToConfigurationField(channelFieldModel, FieldModelTestAction.KEY_CUSTOM_TOPIC);
Optional<ConfigurationFieldModel> messageField = convertFieldToConfigurationField(channelFieldModel, FieldModelTestAction.KEY_CUSTOM_MESSAGE);
topicField.ifPresent(model -> fields.put(FieldModelTestAction.KEY_CUSTOM_TOPIC, model));
messageField.ifPresent(model -> fields.put(FieldModelTestAction.KEY_CUSTOM_MESSAGE, model));
MessageResult providerTestResult = testProviderConfig(new FieldUtility(fields), jobIdString, channelFieldModel);
if (providerTestResult.hasErrors()) {
responseModel = ValidationResponseModel.fromStatusCollection(providerTestResult.getStatusMessage(), providerTestResult.getFieldStatuses());
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
List<BlackDuckProjectDetailsModel> projectFilterDetails = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of()).stream().map(jobProject -> new BlackDuckProjectDetailsModel(jobProject.getName(), jobProject.getHref())).collect(Collectors.toList());
DistributionJobModel testJobModel = distributionJobModelExtractor.convertToJobModel(jobId, fields, DateUtils.createCurrentDateTimestamp(), null, projectFilterDetails);
DistributionChannelTestAction distributionChannelTestAction = channelTestActionMap.findRequiredAction(channelDescriptorName);
MessageResult testActionResult = distributionChannelTestAction.testConfig(testJobModel, testJobModel.getName(), topicField.flatMap(ConfigurationFieldModel::getFieldValue).orElse(null), messageField.flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
List<AlertFieldStatus> resultFieldStatuses = testActionResult.getFieldStatuses();
List<AlertFieldStatus> allStatuses = Stream.concat(resultFieldStatuses.stream(), providerTestResult.fieldWarnings().stream()).collect(Collectors.toList());
responseModel = ValidationResponseModel.fromStatusCollection(testActionResult.getStatusMessage(), allStatuses);
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
responseModel = ValidationResponseModel.generalError("No field model of type channel was was sent to test.");
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
} catch (IntegrationRestException e) {
logger.error(e.getMessage(), e);
return ValidationActionResponse.createResponseFromIntegrationRestException(e);
} catch (AlertFieldException e) {
logger.error("Test Error with field Errors", e);
responseModel = ValidationResponseModel.fromStatusCollection(e.getMessage(), e.getFieldErrors());
return new ValidationActionResponse(HttpStatus.OK, responseModel);
} catch (IntegrationException e) {
// TODO this is not necessarily a PKIX
responseModel = pkixErrorResponseFactory.createSSLExceptionResponse(e).orElse(ValidationResponseModel.generalError(e.getMessage()));
return new ValidationActionResponse(HttpStatus.OK, responseModel);
} catch (Exception e) {
logger.error(e.getMessage(), e);
responseModel = pkixErrorResponseFactory.createSSLExceptionResponse(e).orElse(ValidationResponseModel.generalError(e.getMessage()));
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
}
Aggregations