Search in sources :

Example 16 with DescriptorConfigEntity

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

the class DefaultConfigurationModelConfigurationAccessor method updateConfiguration.

/**
 * @return the config after update
 */
@Override
public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertConfigurationException {
    DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository.findById(descriptorConfigId).orElseThrow(() -> new AlertConfigurationException(String.format("Config with id '%d' did not exist", descriptorConfigId)));
    List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId);
    fieldValueRepository.deleteAll(oldValues);
    fieldValueRepository.flush();
    ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId());
    if (configuredFields != null && !configuredFields.isEmpty()) {
        List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size());
        for (ConfigurationFieldModel configFieldModel : configuredFields) {
            String fieldKey = configFieldModel.getFieldKey();
            Long fieldId = getFieldIdOrThrowException(fieldKey);
            boolean isSensitive = isFieldSensitive(fieldKey);
            for (String value : configFieldModel.getFieldValues()) {
                FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive));
                fieldValuesToSave.add(newFieldValue);
            }
            updatedConfig.put(configFieldModel);
        }
        fieldValueRepository.saveAll(fieldValuesToSave);
        fieldValueRepository.flush();
    }
    descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp());
    descriptorConfigsRepository.save(descriptorConfigEntity);
    return updatedConfig;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) ArrayList(java.util.ArrayList) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity)

Example 17 with DescriptorConfigEntity

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

the class DefaultConfigurationModelConfigurationAccessor method getConfigurationsByDescriptorNameAndContext.

@Override
public List<ConfigurationModel> getConfigurationsByDescriptorNameAndContext(String descriptorName, ConfigContextEnum context) {
    Long contextId = getConfigContextIdOrThrowException(context);
    Long descriptorId = getDescriptorIdOrThrowException(descriptorName);
    List<DescriptorConfigEntity> descriptorConfigEntities = descriptorConfigsRepository.findByDescriptorIdAndContextId(descriptorId, contextId);
    List<ConfigurationModel> configurationModels = new ArrayList<>();
    for (DescriptorConfigEntity descriptorConfigEntity : descriptorConfigEntities) {
        configurationModels.add(createConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), contextId));
    }
    return configurationModels;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) ArrayList(java.util.ArrayList)

Example 18 with DescriptorConfigEntity

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

the class FieldValueRepositoryTestIT method findByConfigIdTest.

@Test
public void findByConfigIdTest() {
    RegisteredDescriptorEntity descriptorEntity = new RegisteredDescriptorEntity(DESCRIPTOR_NAME, 1L);
    RegisteredDescriptorEntity savedDescriptorEntity = registeredDescriptorRepository.save(descriptorEntity);
    DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity("fieldKey1", Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity("fieldKey2", Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity3 = new DefinedFieldEntity("fieldKey3", Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity4 = new DefinedFieldEntity("fieldKey4", Boolean.FALSE);
    DefinedFieldEntity savedEntity1 = definedFieldRepository.save(definedFieldEntity1);
    DefinedFieldEntity savedEntity2 = definedFieldRepository.save(definedFieldEntity2);
    DefinedFieldEntity savedEntity3 = definedFieldRepository.save(definedFieldEntity3);
    DefinedFieldEntity savedEntity4 = definedFieldRepository.save(definedFieldEntity4);
    assertEquals(4, definedFieldRepository.findAll().size());
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity1.getId()));
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity2.getId()));
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity3.getId()));
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity4.getId()));
    ConfigContextEntity configContextEntity = new ConfigContextEntity(CONTEXT_NAME);
    ConfigContextEntity savedContextEntity = configContextRepository.save(configContextEntity);
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DescriptorConfigEntity descriptorConfigEntity1 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
    DescriptorConfigEntity descriptorConfigEntity2 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
    descriptorConfigRepository.save(descriptorConfigEntity1);
    descriptorConfigRepository.save(descriptorConfigEntity2);
    assertEquals(2, descriptorConfigRepository.findAll().size());
    FieldValueEntity fieldValueEntity1 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity1.getId(), "value1");
    FieldValueEntity fieldValueEntity2 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity2.getId(), "value2");
    FieldValueEntity fieldValueEntity3 = new FieldValueEntity(descriptorConfigEntity2.getId(), savedEntity3.getId(), "value3");
    FieldValueEntity fieldValueEntity4 = new FieldValueEntity(descriptorConfigEntity2.getId(), savedEntity4.getId(), "value4");
    fieldValueRepository.save(fieldValueEntity1);
    fieldValueRepository.save(fieldValueEntity2);
    fieldValueRepository.save(fieldValueEntity3);
    fieldValueRepository.save(fieldValueEntity4);
    assertEquals(4, fieldValueRepository.findAll().size());
    List<FieldValueEntity> fieldValueEntityList1 = fieldValueRepository.findByConfigId(descriptorConfigEntity1.getId());
    assertEquals(2, fieldValueEntityList1.size());
    List<FieldValueEntity> fieldValueEntityList2 = fieldValueRepository.findByConfigId(descriptorConfigEntity2.getId());
    assertEquals(2, fieldValueEntityList2.size());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DescriptorFieldRelation(com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 19 with DescriptorConfigEntity

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

the class FieldValueRepositoryTestIT method onDeleteCascadeTest.

@Test
public void onDeleteCascadeTest() {
    RegisteredDescriptorEntity descriptorEntity = new RegisteredDescriptorEntity(DESCRIPTOR_NAME, 1L);
    RegisteredDescriptorEntity savedDescriptorEntity = registeredDescriptorRepository.save(descriptorEntity);
    DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity("fieldKey1", Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity("fieldKey2", Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity3 = new DefinedFieldEntity("fieldKey3", Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity4 = new DefinedFieldEntity("fieldKey4", Boolean.FALSE);
    DefinedFieldEntity savedEntity1 = definedFieldRepository.save(definedFieldEntity1);
    DefinedFieldEntity savedEntity2 = definedFieldRepository.save(definedFieldEntity2);
    DefinedFieldEntity savedEntity3 = definedFieldRepository.save(definedFieldEntity3);
    DefinedFieldEntity savedEntity4 = definedFieldRepository.save(definedFieldEntity4);
    assertEquals(4, definedFieldRepository.findAll().size());
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity1.getId()));
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity2.getId()));
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity3.getId()));
    descriptorFieldRepository.save(new DescriptorFieldRelation(descriptorEntity.getId(), savedEntity4.getId()));
    ConfigContextEntity configContextEntity = new ConfigContextEntity(CONTEXT_NAME);
    ConfigContextEntity savedContextEntity = configContextRepository.save(configContextEntity);
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DescriptorConfigEntity descriptorConfigEntity1 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
    DescriptorConfigEntity descriptorConfigEntity2 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
    DescriptorConfigEntity descriptorConfigEntity3 = new DescriptorConfigEntity(savedDescriptorEntity.getId(), savedContextEntity.getId(), currentTime, currentTime);
    descriptorConfigRepository.save(descriptorConfigEntity1);
    descriptorConfigRepository.save(descriptorConfigEntity2);
    descriptorConfigRepository.save(descriptorConfigEntity3);
    assertEquals(3, descriptorConfigRepository.findAll().size());
    FieldValueEntity fieldValueEntity1 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity1.getId(), "value1");
    FieldValueEntity fieldValueEntity2 = new FieldValueEntity(descriptorConfigEntity1.getId(), savedEntity2.getId(), "value2");
    FieldValueEntity fieldValueEntity3 = new FieldValueEntity(descriptorConfigEntity2.getId(), savedEntity3.getId(), "value3");
    FieldValueEntity fieldValueEntity4 = new FieldValueEntity(descriptorConfigEntity3.getId(), savedEntity4.getId(), "value4");
    fieldValueRepository.save(fieldValueEntity1);
    fieldValueRepository.save(fieldValueEntity2);
    fieldValueRepository.save(fieldValueEntity3);
    fieldValueRepository.save(fieldValueEntity4);
    assertEquals(4, fieldValueRepository.findAll().size());
    // Delete a configuration (deletes 1 & 2)
    descriptorConfigRepository.deleteById(descriptorConfigEntity1.getId());
    descriptorConfigRepository.flush();
    assertEquals(2, fieldValueRepository.findAll().size());
    // Delete a descriptor field (deletes 3)
    definedFieldRepository.deleteById(savedEntity3.getId());
    definedFieldRepository.flush();
    assertEquals(1, fieldValueRepository.findAll().size());
    // Delete a descriptor (deletes 4)
    registeredDescriptorRepository.deleteById(savedDescriptorEntity.getId());
    registeredDescriptorRepository.flush();
    assertEquals(0, fieldValueRepository.findAll().size());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DescriptorFieldRelation(com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)19 Test (org.junit.jupiter.api.Test)14 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)13 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)10 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)10 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)7 OffsetDateTime (java.time.OffsetDateTime)7 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)5 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 ArrayList (java.util.ArrayList)4 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)2 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)2 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)1 DescriptorTypeEntity (com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)1 PageRequest (org.springframework.data.domain.PageRequest)1