use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel 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.ConfigurationModel in project hub-alert by blackducksoftware.
the class ConfigActions method convertConfigurationModelList.
private List<FieldModel> convertConfigurationModelList(String descriptorName, String context, List<ConfigurationModel> configurationModels) {
List<FieldModel> responseFieldModels = new LinkedList<>();
List<FieldModel> fieldModelList = new LinkedList<>();
if (null != configurationModels) {
for (ConfigurationModel configurationModel : configurationModels) {
FieldModel fieldModel = modelConverter.convertToFieldModel(configurationModel);
fieldModelList.add(fieldModel);
}
}
if (fieldModelList.isEmpty()) {
fieldModelList.add(new FieldModel(descriptorName, context, new HashMap<>()));
}
for (FieldModel fieldModel : fieldModelList) {
try {
responseFieldModels.add(fieldModelProcessor.performAfterReadAction(fieldModel));
} catch (AlertException ex) {
logger.error("Error performing after read action", ex);
}
}
return responseFieldModels;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ConfigActions method readAllByContextAndDescriptorWithoutChecks.
@Override
protected ActionResponse<MultiFieldModel> readAllByContextAndDescriptorWithoutChecks(String context, String descriptorName) {
ConfigContextEnum configContext = ConfigContextEnum.valueOf(context);
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(descriptorName);
if (!descriptorKey.isPresent()) {
return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Unknown descriptor: %s", descriptorName));
}
List<ConfigurationModel> configurationModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), configContext);
List<FieldModel> fieldModels = convertConfigurationModelList(descriptorName, context, configurationModels);
return new ActionResponse<>(HttpStatus.OK, new MultiFieldModel(fieldModels));
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class GlobalConfigurationModelToConcreteConversionServiceTest method deleteDescriptorFoundTest.
@Test
void deleteDescriptorFoundTest() {
TestSaveActions saveActions = new TestSaveActions(testDescriptorKey);
DescriptorMap descriptorMap = new DescriptorMap(List.of(testDescriptorKey), List.of());
List<GlobalConfigurationModelToConcreteSaveActions> fieldModelSaveActions = List.of(saveActions);
String timestamp = DateUtils.createCurrentDateString(DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
ConfigurationModel configurationModel = new ConfigurationModel(1L, 1L, timestamp, timestamp, ConfigContextEnum.GLOBAL, Map.of());
GlobalConfigurationModelToConcreteConversionService conversionService = new GlobalConfigurationModelToConcreteConversionService(fieldModelSaveActions, descriptorMap);
conversionService.deleteDefaultConcreteModel(TEST_DESCRIPTOR_KEY, configurationModel);
assertTrue(saveActions.wasDeleteCalled());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class GlobalConfigurationModelToConcreteConversionServiceTest method createdDescriptorFoundTest.
@Test
void createdDescriptorFoundTest() {
TestSaveActions saveActions = new TestSaveActions(testDescriptorKey);
DescriptorMap descriptorMap = new DescriptorMap(List.of(testDescriptorKey), List.of());
List<GlobalConfigurationModelToConcreteSaveActions> fieldModelSaveActions = List.of(saveActions);
String timestamp = DateUtils.createCurrentDateString(DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
ConfigurationModel configurationModel = new ConfigurationModel(1L, 1L, timestamp, timestamp, ConfigContextEnum.GLOBAL, Map.of());
GlobalConfigurationModelToConcreteConversionService conversionService = new GlobalConfigurationModelToConcreteConversionService(fieldModelSaveActions, descriptorMap);
conversionService.createDefaultConcreteModel(TEST_DESCRIPTOR_KEY, configurationModel);
assertTrue(saveActions.wasCreatedCalled());
}
Aggregations