Search in sources :

Example 1 with GlobalAttributeDefinitionLevelEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionLevelDaoTest method testGetGlobalAttributeDefinitionLevel.

@Test
public void testGetGlobalAttributeDefinitionLevel() {
    // Create and persist a global attribute definition level entity.
    GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDaoTestHelper.createGlobalAttributeDefinitionLevelEntity(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL);
    // Retrieve the global attribute definition level entity by its code.
    assertEquals(globalAttributeDefinitionLevelEntity, globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL));
    // Test case insensitivity.
    assertEquals(globalAttributeDefinitionLevelEntity, globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL.toUpperCase()));
    assertEquals(globalAttributeDefinitionLevelEntity, globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL.toLowerCase()));
    // Confirm negative results when using invalid values.
    assertNull(globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(I_DO_NOT_EXIST));
}
Also used : GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) Test(org.junit.Test)

Example 2 with GlobalAttributeDefinitionLevelEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionServiceTest method testCreateGlobalAttributeDefinition.

@Test
public void testCreateGlobalAttributeDefinition() {
    // Create a global attribute definition key.
    GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Create a global attribute definition create request.
    GlobalAttributeDefinitionCreateRequest request = new GlobalAttributeDefinitionCreateRequest(globalAttributeDefinitionKey, attributeValueListKeyNull);
    // Create a global attribute definition level entity.
    GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = new GlobalAttributeDefinitionLevelEntity();
    globalAttributeDefinitionLevelEntity.setGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL);
    // Create a global attribute definition entity.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = new GlobalAttributeDefinitionEntity();
    globalAttributeDefinitionEntity.setId(GLOBAL_ATTRIBUTE_DEFINITON_ID);
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevelEntity);
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionName(GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Mock calls to external methods.
    when(globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL)).thenReturn(globalAttributeDefinitionLevelEntity);
    when(globalAttributeDefinitionDao.saveAndRefresh(any(GlobalAttributeDefinitionEntity.class))).thenReturn(globalAttributeDefinitionEntity);
    // Call the method under test.
    GlobalAttributeDefinition response = globalAttributeDefinitionService.createGlobalAttributeDefinition(request);
    // Verify the external calls.
    verify(globalAttributeDefinitionHelper).validateGlobalAttributeDefinitionKey(globalAttributeDefinitionKey);
    verify(globalAttributeDefinitionDaoHelper).validateGlobalAttributeDefinitionNoExists(globalAttributeDefinitionKey);
    verify(globalAttributeDefinitionLevelDao).getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL);
    verify(globalAttributeDefinitionDao).saveAndRefresh(any(GlobalAttributeDefinitionEntity.class));
    verifyNoMoreInteractionsHelper();
    // Validate the response.
    assertEquals(new GlobalAttributeDefinition(GLOBAL_ATTRIBUTE_DEFINITON_ID, globalAttributeDefinitionKey, attributeValueListNull), response);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) GlobalAttributeDefinitionCreateRequest(org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest) GlobalAttributeDefinition(org.finra.herd.model.api.xml.GlobalAttributeDefinition) Test(org.junit.Test)

Example 3 with GlobalAttributeDefinitionLevelEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionDaoTestHelper method createGlobalAttributeDefinitionEntity.

/**
 * Creates and persists a new Global Attribute Definition entity.
 *
 * @param globalAttributeDefinitionLevel the level
 * @param globalAttributeDefinitionName the name
 *
 * @return the newly created Global Attribute Definition entity.
 */
public GlobalAttributeDefinitionEntity createGlobalAttributeDefinitionEntity(String globalAttributeDefinitionLevel, String globalAttributeDefinitionName) {
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = new GlobalAttributeDefinitionEntity();
    GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevel);
    if (globalAttributeDefinitionLevelEntity == null) {
        globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDaoTestHelper.createGlobalAttributeDefinitionLevelEntity(globalAttributeDefinitionLevel);
    }
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevelEntity);
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionName(globalAttributeDefinitionName);
    return globalAttributeDefinitionDao.saveAndRefresh(globalAttributeDefinitionEntity);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)

Example 4 with GlobalAttributeDefinitionLevelEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionLevelDaoTestHelper method createGlobalAttributeDefinitionLevelEntity.

/**
 * Creates and persists a new global attribute definition level entity.
 *
 * @param globalAttributeDefinitionLevel the global attribute definition level code
 *
 * @return the newly created global attribute definition entity
 */
public GlobalAttributeDefinitionLevelEntity createGlobalAttributeDefinitionLevelEntity(String globalAttributeDefinitionLevel) {
    GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = new GlobalAttributeDefinitionLevelEntity();
    globalAttributeDefinitionLevelEntity.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevel);
    return globalAttributeDefinitionLevelDao.saveAndRefresh(globalAttributeDefinitionLevelEntity);
}
Also used : GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)

Example 5 with GlobalAttributeDefinitionLevelEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionDaoImpl method getAllGlobalAttributeDefinitionKeys.

@Override
public List<GlobalAttributeDefinitionKey> getAllGlobalAttributeDefinitionKeys() {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the global attribute definition.
    Root<GlobalAttributeDefinitionEntity> globalAttributeDefinitionEntityRoot = criteria.from(GlobalAttributeDefinitionEntity.class);
    // Join on the other tables that we filter on
    Join<GlobalAttributeDefinitionEntity, GlobalAttributeDefinitionLevelEntity> globalAttributeDefinitionLevelEntityJoin = globalAttributeDefinitionEntityRoot.join(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionLevel);
    // Get the columns
    Path<String> globalAttributeDefinitionLevel = globalAttributeDefinitionLevelEntityJoin.get(GlobalAttributeDefinitionLevelEntity_.globalAttributeDefinitionLevel);
    Path<String> globalAttributeDefinitionName = globalAttributeDefinitionEntityRoot.get(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionName);
    // Add all clauses to the query
    criteria.multiselect(globalAttributeDefinitionLevel, globalAttributeDefinitionName).orderBy(builder.asc(globalAttributeDefinitionLevel), builder.asc(globalAttributeDefinitionName));
    // Populate the "keys" objects from the returned tuples
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    List<GlobalAttributeDefinitionKey> globalAttributeDefinitionKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        globalAttributeDefinitionKeys.add(new GlobalAttributeDefinitionKey(tuple.get(globalAttributeDefinitionLevel), tuple.get(globalAttributeDefinitionName)));
    }
    return globalAttributeDefinitionKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) ArrayList(java.util.ArrayList) GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) Tuple(javax.persistence.Tuple)

Aggregations

GlobalAttributeDefinitionLevelEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)8 GlobalAttributeDefinitionEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ArrayList (java.util.ArrayList)2 Predicate (javax.persistence.criteria.Predicate)2 GlobalAttributeDefinitionKey (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)2 Test (org.junit.Test)2 Tuple (javax.persistence.Tuple)1 GlobalAttributeDefinition (org.finra.herd.model.api.xml.GlobalAttributeDefinition)1 GlobalAttributeDefinitionCreateRequest (org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest)1 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)1