use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelConverter method convertToConfigurationFieldModelMap.
public final Map<String, ConfigurationFieldModel> convertToConfigurationFieldModelMap(FieldModel fieldModel) {
ConfigContextEnum context = EnumUtils.getEnum(ConfigContextEnum.class, fieldModel.getContext());
String descriptorName = fieldModel.getDescriptorName();
DescriptorKey descriptorKey = getDescriptorKey(descriptorName).orElseThrow(() -> new AlertRuntimeException("Could not find a Descriptor with the name: " + descriptorName));
List<DefinedFieldModel> fieldsForContext = descriptorAccessor.getFieldsForDescriptor(descriptorKey, context);
Map<String, ConfigurationFieldModel> configurationModels = new HashMap<>();
for (DefinedFieldModel definedField : fieldsForContext) {
fieldModel.getFieldValueModel(definedField.getKey()).flatMap(fieldValueModel -> convertFromDefinedFieldModel(definedField, fieldValueModel.getValues(), fieldValueModel.getIsSet())).ifPresent(configurationFieldModel -> configurationModels.put(configurationFieldModel.getFieldKey(), configurationFieldModel));
}
return configurationModels;
}
use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.
the class AzureBoardsGlobalApiAction method beforeSaveAction.
@Override
public FieldModel beforeSaveAction(FieldModel fieldModel) throws AlertException {
FieldModel updatedFieldModel = super.beforeSaveAction(fieldModel);
Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(fieldModel.getDescriptorName());
if (!descriptorKey.isPresent()) {
return updatedFieldModel;
}
ConfigContextEnum context = ConfigContextEnum.valueOf(fieldModel.getContext());
List<ConfigurationModel> existingConfig = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey.get(), context);
Optional<ConfigurationModel> configurationModel = existingConfig.stream().findFirst();
return configurationModel.map(config -> updateTokenFields(updatedFieldModel, config)).orElse(updatedFieldModel);
}
use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.
the class DescriptorMetadataActions method getDescriptorsByPermissions.
public ActionResponse<DescriptorsResponseModel> getDescriptorsByPermissions(@Nullable String name, @Nullable String type, @Nullable String context) {
Predicate<Descriptor> descriptorFilter = ignored -> true;
Set<ConfigContextEnum> requestedContexts = Set.of(ConfigContextEnum.GLOBAL, ConfigContextEnum.DISTRIBUTION);
if (StringUtils.isNotBlank(name)) {
descriptorFilter = descriptorFilter.and(descriptor -> name.equals(descriptor.getDescriptorKey().getUniversalKey()));
}
if (StringUtils.isNotBlank(type)) {
descriptorFilter = descriptorFilter.and(descriptor -> type.equals(descriptor.getType().name()));
}
if (StringUtils.isNotBlank(context)) {
ConfigContextEnum requestedContext = EnumUtils.getEnum(ConfigContextEnum.class, context);
if (null != requestedContext) {
requestedContexts = Set.of(requestedContext);
} else {
requestedContexts = Set.of();
}
}
return createDescriptorResponse(descriptorFilter, requestedContexts);
}
use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.
the class DescriptorMocker method addFieldToDescriptor.
public void addFieldToDescriptor(String descriptorName, String fieldKey, Collection<ConfigContextEnum> contexts, Boolean sensitive) {
Long descriptorId = registeredDescriptorRepository.findFirstByName(descriptorName).map(RegisteredDescriptorEntity::getId).orElseThrow();
Long fieldId = definedFieldRepository.findFirstByKey(fieldKey).map(DefinedFieldEntity::getId).orElseGet(() -> definedFieldRepository.save(new DefinedFieldEntity(fieldKey, sensitive)).getId());
try {
descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorId, fieldId));
} catch (Exception e) {
// Ignore exception, relation already registered
}
for (ConfigContextEnum context : contexts) {
String contextName = context.name();
Long contextId = configContextRepository.findFirstByContext(contextName).map(ConfigContextEntity::getId).orElseGet(() -> configContextRepository.save(new ConfigContextEntity(contextName)).getId());
try {
fieldContextRepository.save(new FieldContextRelation(fieldId, contextId));
} catch (Exception e) {
// Ignore exception, relation already registered
}
}
}
use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.
the class DescriptorMetadataActionsTest method getDescriptorsWithNameAndContextTest.
@Test
public void getDescriptorsWithNameAndContextTest() {
String componentName1 = getNamePrefix(DescriptorType.CHANNEL) + "_4";
ConfigContextEnum context1 = ConfigContextEnum.GLOBAL;
ActionResponse<DescriptorsResponseModel> response1 = actions.getDescriptorsByPermissions(componentName1, null, context1.name());
assertTrue(response1.isSuccessful());
assertTrue(response1.hasContent());
Set<DescriptorMetadata> descriptorMetadata1 = response1.getContent().get().getDescriptors();
assertEquals(1, descriptorMetadata1.size());
String componentName2 = getNamePrefix(DescriptorType.COMPONENT) + "_4";
ConfigContextEnum context2 = ConfigContextEnum.GLOBAL;
ActionResponse<DescriptorsResponseModel> response2 = actions.getDescriptorsByPermissions(componentName2, null, context2.name());
assertTrue(response2.isSuccessful());
assertTrue(response2.hasContent());
Set<DescriptorMetadata> descriptorMetadata2 = response2.getContent().get().getDescriptors();
assertEquals(1, descriptorMetadata2.size());
String componentName3 = getNamePrefix(DescriptorType.PROVIDER) + "_4";
ConfigContextEnum context3 = ConfigContextEnum.GLOBAL;
ActionResponse<DescriptorsResponseModel> response3 = actions.getDescriptorsByPermissions(componentName3, null, context3.name());
assertTrue(response3.isSuccessful());
assertTrue(response3.hasContent());
Set<DescriptorMetadata> descriptorMetadata3 = response3.getContent().get().getDescriptors();
assertEquals(1, descriptorMetadata3.size());
ConfigContextEnum context4 = ConfigContextEnum.DISTRIBUTION;
ActionResponse<DescriptorsResponseModel> response4 = actions.getDescriptorsByPermissions(componentName1, null, context4.name());
assertTrue(response4.isSuccessful());
assertTrue(response4.hasContent());
Set<DescriptorMetadata> descriptorMetadata4 = response4.getContent().get().getDescriptors();
assertEquals(1, descriptorMetadata4.size());
ConfigContextEnum context5 = ConfigContextEnum.DISTRIBUTION;
ActionResponse<DescriptorsResponseModel> response5 = actions.getDescriptorsByPermissions(componentName2, null, context5.name());
assertTrue(response5.isSuccessful());
assertTrue(response5.hasContent());
Set<DescriptorMetadata> descriptorMetadata5 = response5.getContent().get().getDescriptors();
assertEquals(1, descriptorMetadata5.size());
ConfigContextEnum context6 = ConfigContextEnum.DISTRIBUTION;
ActionResponse<DescriptorsResponseModel> response6 = actions.getDescriptorsByPermissions(componentName3, null, context6.name());
assertTrue(response6.isSuccessful());
assertTrue(response6.hasContent());
Set<DescriptorMetadata> descriptorMetadata6 = response6.getContent().get().getDescriptors();
assertEquals(1, descriptorMetadata6.size());
}
Aggregations