Search in sources :

Example 21 with ConfigContextEntity

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

the class NotificationContentRepositoryTestIT method createProviderConfig.

private DescriptorConfigEntity createProviderConfig() {
    RegisteredDescriptorEntity providerDescriptor = registeredDescriptorRepository.findFirstByName(BLACK_DUCK_PROVIDER_KEY.getUniversalKey()).orElseThrow();
    ConfigContextEntity context = configContextRepository.findFirstByContext(ConfigContextEnum.GLOBAL.name()).orElseThrow();
    DescriptorConfigEntity providerConfigToSave = new DescriptorConfigEntity(providerDescriptor.getId(), context.getId(), OffsetDateTime.now(), OffsetDateTime.now());
    return descriptorConfigRepository.save(providerConfigToSave);
}
Also used : DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity)

Example 22 with ConfigContextEntity

use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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
        }
    }
}
Also used : FieldContextRelation(com.synopsys.integration.alert.database.configuration.FieldContextRelation) DescriptorFieldRelation(com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity)

Example 23 with ConfigContextEntity

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

the class DefaultDescriptorAccessor method saveContextAndReturnId.

private Long saveContextAndReturnId(ConfigContextEnum context) {
    String contextString = context.name();
    Optional<Long> optionalConfigContextId = configContextRepository.findFirstByContext(contextString).map(ConfigContextEntity::getId);
    if (optionalConfigContextId.isPresent()) {
        return optionalConfigContextId.get();
    }
    ConfigContextEntity configContextEntity = new ConfigContextEntity(contextString);
    ConfigContextEntity savedContextEntity = configContextRepository.save(configContextEntity);
    return savedContextEntity.getId();
}
Also used : ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity)

Example 24 with ConfigContextEntity

use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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 25 with ConfigContextEntity

use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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

ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)25 Test (org.junit.jupiter.api.Test)20 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)17 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)14 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)13 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)8 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)8 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)7 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)5 PermissionMatrixRelation (com.synopsys.integration.alert.database.authorization.PermissionMatrixRelation)5 OffsetDateTime (java.time.OffsetDateTime)5 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)4 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)3 FieldContextRelation (com.synopsys.integration.alert.database.configuration.FieldContextRelation)3 ConfigContextRepository (com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository)3 RegisteredDescriptorRepository (com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository)3 RoleEntity (com.synopsys.integration.alert.database.user.RoleEntity)3 ArrayList (java.util.ArrayList)3