Search in sources :

Example 1 with FieldContextRelation

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

the class FieldContextRepositoryTestIT method findByContextId.

@Test
public void findByContextId() {
    DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity(FIELD_KEY_1, Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity(FIELD_KEY_2, Boolean.FALSE);
    DefinedFieldEntity savedFieldEntity1 = definedFieldRepository.save(definedFieldEntity1);
    DefinedFieldEntity savedFieldEntity2 = definedFieldRepository.save(definedFieldEntity2);
    assertEquals(2, definedFieldRepository.findAll().size());
    ConfigContextEntity configContextEntity1 = new ConfigContextEntity(CONTEXT_NAME);
    ConfigContextEntity configContextEntity2 = new ConfigContextEntity(CONTEXT_NAME + "2");
    ConfigContextEntity savedContextEntity1 = configContextRepository.save(configContextEntity1);
    ConfigContextEntity savedContextEntity2 = configContextRepository.save(configContextEntity2);
    assertEquals(2, configContextRepository.findAll().size());
    FieldContextRelation fieldContextRelation1 = new FieldContextRelation(savedFieldEntity1.getId(), savedContextEntity1.getId());
    FieldContextRelation fieldContextRelation2 = new FieldContextRelation(savedFieldEntity1.getId(), savedContextEntity2.getId());
    FieldContextRelation fieldContextRelation3 = new FieldContextRelation(savedFieldEntity2.getId(), savedContextEntity1.getId());
    fieldContextRepository.save(fieldContextRelation1);
    fieldContextRepository.save(fieldContextRelation2);
    fieldContextRepository.save(fieldContextRelation3);
    assertEquals(3, fieldContextRepository.findAll().size());
    List<FieldContextRelation> foundList1 = fieldContextRepository.findByContextId(savedContextEntity1.getId());
    assertEquals(2, foundList1.size());
    List<FieldContextRelation> foundList2 = fieldContextRepository.findByContextId(savedContextEntity2.getId());
    assertEquals(1, foundList2.size());
}
Also used : FieldContextRelation(com.synopsys.integration.alert.database.configuration.FieldContextRelation) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with FieldContextRelation

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

the class FieldContextRepositoryTestIT method findByFieldId.

@Test
public void findByFieldId() {
    DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity(FIELD_KEY_1, Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity(FIELD_KEY_2, Boolean.FALSE);
    DefinedFieldEntity savedFieldEntity1 = definedFieldRepository.save(definedFieldEntity1);
    DefinedFieldEntity savedFieldEntity2 = definedFieldRepository.save(definedFieldEntity2);
    assertEquals(2, definedFieldRepository.findAll().size());
    ConfigContextEntity configContextEntity1 = new ConfigContextEntity(CONTEXT_NAME);
    ConfigContextEntity configContextEntity2 = new ConfigContextEntity(CONTEXT_NAME + "2");
    ConfigContextEntity savedContextEntity1 = configContextRepository.save(configContextEntity1);
    ConfigContextEntity savedContextEntity2 = configContextRepository.save(configContextEntity2);
    assertEquals(2, configContextRepository.findAll().size());
    FieldContextRelation fieldContextRelation1 = new FieldContextRelation(savedFieldEntity1.getId(), savedContextEntity1.getId());
    FieldContextRelation fieldContextRelation2 = new FieldContextRelation(savedFieldEntity1.getId(), savedContextEntity2.getId());
    FieldContextRelation fieldContextRelation3 = new FieldContextRelation(savedFieldEntity2.getId(), savedContextEntity1.getId());
    fieldContextRepository.save(fieldContextRelation1);
    fieldContextRepository.save(fieldContextRelation2);
    fieldContextRepository.save(fieldContextRelation3);
    assertEquals(3, fieldContextRepository.findAll().size());
    List<FieldContextRelation> foundList1 = fieldContextRepository.findByFieldId(savedFieldEntity1.getId());
    assertEquals(2, foundList1.size());
    List<FieldContextRelation> foundList2 = fieldContextRepository.findByFieldId(savedFieldEntity2.getId());
    assertEquals(1, foundList2.size());
}
Also used : FieldContextRelation(com.synopsys.integration.alert.database.configuration.FieldContextRelation) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with FieldContextRelation

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

Aggregations

ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)3 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)3 FieldContextRelation (com.synopsys.integration.alert.database.configuration.FieldContextRelation)3 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)2 Test (org.junit.jupiter.api.Test)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)1 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)1