Search in sources :

Example 11 with AlertRuntimeException

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();
}
Also used : StringBodyContent(com.synopsys.integration.rest.body.StringBodyContent) IntegrationException(com.synopsys.integration.exception.IntegrationException) Request(com.synopsys.integration.rest.request.Request) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 12 with AlertRuntimeException

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();
}
Also used : PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ArrayList(java.util.ArrayList) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) PermissionMatrixRelation(com.synopsys.integration.alert.database.authorization.PermissionMatrixRelation) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) HashMap(java.util.HashMap) Map(java.util.Map) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity)

Example 13 with AlertRuntimeException

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));
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with AlertRuntimeException

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());
}
Also used : RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 15 with AlertRuntimeException

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;
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DataStructureUtils(com.synopsys.integration.alert.common.util.DataStructureUtils) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) List(java.util.List) Component(org.springframework.stereotype.Component) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) EnumUtils(org.apache.commons.lang3.EnumUtils) Map(java.util.Map) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) Optional(java.util.Optional) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) HashMap(java.util.HashMap) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)

Aggregations

AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)22 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)3 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 ArrayList (java.util.ArrayList)3 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)2 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)2 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)2 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)2 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)2 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)2 HashMap (java.util.HashMap)2 List (java.util.List)2