Search in sources :

Example 6 with DefinedFieldEntity

use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessor method createConfigModel.

private ConfigurationModelMutable createConfigModel(Long descriptorId, Long configId, OffsetDateTime createdAt, OffsetDateTime lastUpdated, Long contextId) {
    String configContext = getContextById(contextId);
    String createdAtFormatted = DateUtils.formatDate(createdAt, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
    String lastUpdatedFormatted = DateUtils.formatDate(lastUpdated, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
    ConfigurationModelMutable newModel = new ConfigurationModelMutable(descriptorId, configId, createdAtFormatted, lastUpdatedFormatted, configContext);
    List<FieldValueEntity> fieldValueEntities = fieldValueRepository.findByConfigId(configId);
    for (FieldValueEntity fieldValueEntity : fieldValueEntities) {
        DefinedFieldEntity definedFieldEntity = definedFieldRepository.findById(fieldValueEntity.getFieldId()).orElseThrow(() -> new AlertRuntimeException("Field Id missing from the database"));
        String fieldKey = definedFieldEntity.getKey();
        ConfigurationFieldModel fieldModel = BooleanUtils.isTrue(definedFieldEntity.getSensitive()) ? ConfigurationFieldModel.createSensitive(fieldKey) : ConfigurationFieldModel.create(fieldKey);
        String decryptedValue = decrypt(fieldValueEntity.getValue(), fieldModel.isSensitive());
        fieldModel.setFieldValue(decryptedValue);
        newModel.put(fieldModel);
    }
    return newModel;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity)

Example 7 with DefinedFieldEntity

use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorKeyTest.

@Test
public void getConfigurationsByDescriptorKeyTest() {
    final Long descriptorId = 3L;
    final Long configurationId = 5L;
    DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
    DescriptorKey badDescriptorKey = createDescriptorKey("bad-descriptorKey");
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name-test", 1L);
    registeredDescriptorEntity.setId(2L);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(8L);
    Mockito.when(descriptorConfigRepository.findByDescriptorName(descriptorKey.getUniversalKey())).thenReturn(List.of(descriptorConfigEntity));
    Mockito.when(registeredDescriptorRepository.findFirstByName(badDescriptorKey.getUniversalKey())).thenReturn(Optional.empty());
    setupCreatConfigMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
    List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(descriptorKey);
    List<ConfigurationModel> configurationModelListEmpty = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(badDescriptorKey);
    assertEquals(1, configurationModelList.size());
    assertTrue(configurationModelListEmpty.isEmpty());
    ConfigurationModel configurationModel = configurationModelList.get(0);
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) Test(org.junit.jupiter.api.Test)

Example 8 with DefinedFieldEntity

use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method updateConfigurationTest.

@Test
public void updateConfigurationTest() throws Exception {
    Long configurationId = 2L;
    Long descriptorId = 3L;
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create("channel.common.name");
    configurationFieldModel.setFieldValue(fieldValue);
    List<ConfigurationFieldModel> configuredFields = List.of(configurationFieldModel);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    FieldValueEntity fieldValueEntity = new FieldValueEntity(5L, 6L, fieldValue);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(7L);
    Mockito.when(descriptorConfigRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorConfigEntity));
    Mockito.when(fieldValueRepository.findByConfigId(Mockito.any())).thenReturn(List.of(fieldValueEntity));
    Mockito.when(configContextRepository.findById(Mockito.any())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(null, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, null);
    ConfigurationModel configurationModel = configurationModelConfigurationAccessor.updateConfiguration(1L, configuredFields);
    Mockito.verify(fieldValueRepository).deleteAll(Mockito.any());
    Mockito.verify(descriptorConfigRepository).save(Mockito.any());
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) Test(org.junit.jupiter.api.Test)

Example 9 with DefinedFieldEntity

use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorKeyAndContextTest.

@Test
public void getConfigurationsByDescriptorKeyAndContextTest() {
    final Long descriptorId = 3L;
    final Long configurationId = 5L;
    DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    configContextEntity.setId(3L);
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name", 1L);
    registeredDescriptorEntity.setId(2L);
    FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(8L);
    Mockito.when(descriptorConfigRepository.findByDescriptorIdAndContextId(Mockito.any(), Mockito.any())).thenReturn(List.of(descriptorConfigEntity));
    Mockito.when(configContextRepository.findFirstByContext(Mockito.any())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(configContextRepository.findById(Mockito.any())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(registeredDescriptorRepository.findFirstByName(Mockito.any())).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(fieldValueRepository.findByConfigId(Mockito.any())).thenReturn(List.of(fieldValueEntity));
    Mockito.when(definedFieldRepository.findById(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
    EncryptionUtility encryptionUtility = createEncryptionUtility();
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
    List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, configContextEnum);
    assertEquals(1, configurationModelList.size());
    ConfigurationModel configurationModel = configurationModelList.get(0);
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 10 with DefinedFieldEntity

use of com.synopsys.integration.alert.database.configuration.DefinedFieldEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorTypeTest.

@Test
public void getConfigurationsByDescriptorTypeTest() {
    final Long descriptorId = 3L;
    final Long configurationId = 5L;
    DescriptorType descriptorType = DescriptorType.CHANNEL;
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity("CHANNEL");
    descriptorTypeEntity.setId(1L);
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name-test", 1L);
    registeredDescriptorEntity.setId(2L);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(8L);
    Mockito.when(descriptorConfigRepository.findByDescriptorType(Mockito.eq(descriptorType.name()))).thenReturn(List.of(descriptorConfigEntity));
    setupCreatConfigMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
    List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(descriptorType);
    assertEquals(1, configurationModelList.size());
    ConfigurationModel configurationModel = configurationModelList.get(0);
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorTypeEntity(com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) Test(org.junit.jupiter.api.Test)

Aggregations

DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)20 Test (org.junit.jupiter.api.Test)17 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)14 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)11 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)10 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)8 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)7 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)6 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)4 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 FieldContextRelation (com.synopsys.integration.alert.database.configuration.FieldContextRelation)3 OffsetDateTime (java.time.OffsetDateTime)3 ArrayList (java.util.ArrayList)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)2 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)2 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)2 ConfigContextRepository (com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository)2