use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.
the class RestChannelUtility method createPostMessageRequest.
public Request createPostMessageRequest(String url, Map<String, String> headers, @Nullable Map<String, Set<String>> queryParameters, String jsonString) {
HttpUrl httpUrl;
try {
httpUrl = new HttpUrl(url);
} catch (IntegrationException e) {
throw new AlertRuntimeException(e);
}
Request.Builder requestBuilder = new Request.Builder().method(HttpMethod.POST).url(httpUrl);
requestBuilder.getHeaders().putAll(headers);
requestBuilder.bodyContent(new StringBodyContent(jsonString, BodyContentConverter.DEFAULT));
if (queryParameters != null && !queryParameters.isEmpty()) {
requestBuilder.queryParameters(queryParameters);
}
return requestBuilder.build();
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.
the class DefaultRoleAccessor method updateRoleOperations.
private List<PermissionMatrixRelation> updateRoleOperations(RoleEntity roleEntity, PermissionMatrixModel permissionMatrix) {
List<PermissionMatrixRelation> oldPermissionsForRole = permissionMatrixRepository.findAllByRoleId(roleEntity.getId());
if (!oldPermissionsForRole.isEmpty()) {
permissionMatrixRepository.deleteAll(oldPermissionsForRole);
}
List<PermissionMatrixRelation> matrixEntries = new ArrayList<>();
Map<PermissionKey, Integer> permissions = permissionMatrix.getPermissions();
for (Map.Entry<PermissionKey, Integer> permission : permissions.entrySet()) {
PermissionKey permissionKey = permission.getKey();
ConfigContextEntity dbContext = configContextRepository.findFirstByContext(permissionKey.getContext()).orElseThrow(() -> new AlertRuntimeException("Invalid context specified for permission"));
RegisteredDescriptorEntity registeredDescriptor = registeredDescriptorRepository.findFirstByName(permissionKey.getDescriptorName()).orElseThrow(() -> new AlertRuntimeException("Invalid descriptor name specified for permission"));
int accessOperations = permission.getValue();
PermissionMatrixRelation permissionMatrixRelation = new PermissionMatrixRelation(roleEntity.getId(), dbContext.getId(), registeredDescriptor.getId(), accessOperations);
matrixEntries.add(permissionMatrixRelation);
}
if (!matrixEntries.isEmpty()) {
return permissionMatrixRepository.saveAll(matrixEntries);
}
return List.of();
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.
the class DescriptorAccessorTestIT method getFieldsForDescriptorByIdTest.
@Test
public void getFieldsForDescriptorByIdTest() {
final String field1Key = "field1";
final String field2Key = "field2";
DefinedFieldModel field1 = new DefinedFieldModel(field1Key, ConfigContextEnum.DISTRIBUTION, Boolean.FALSE);
DefinedFieldModel field2 = new DefinedFieldModel(field2Key, ConfigContextEnum.DISTRIBUTION, Boolean.TRUE);
descriptorMocker.registerDescriptor(DESCRIPTOR_NAME, DescriptorType.CHANNEL, Arrays.asList(field1, field2));
RegisteredDescriptorModel registeredDescriptorModel = descriptorAccessor.getRegisteredDescriptorByKey(createDescriptorKey()).orElseThrow(() -> new AlertRuntimeException("This descriptor should exist"));
List<DefinedFieldModel> descriptorFields = descriptorAccessor.getFieldsForDescriptorById(registeredDescriptorModel.getId(), ConfigContextEnum.DISTRIBUTION);
assertEquals(2, descriptorFields.size());
assertTrue(descriptorFields.contains(field1));
assertTrue(descriptorFields.contains(field2));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException in project hub-alert by blackducksoftware.
the class DescriptorAccessorTestIT method registerAndGetDescriptorTest.
@Test
public void registerAndGetDescriptorTest() {
descriptorMocker.registerDescriptor(DESCRIPTOR_NAME, DescriptorType.CHANNEL);
RegisteredDescriptorModel registeredDescriptorModel = descriptorAccessor.getRegisteredDescriptorByKey(createDescriptorKey()).orElseThrow(() -> new AlertRuntimeException("This descriptor should exist"));
assertNotNull(registeredDescriptorModel.getId());
assertEquals(DESCRIPTOR_NAME, registeredDescriptorModel.getName());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException 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;
}
Aggregations