Search in sources :

Example 6 with GlobalAttributeDefinitionEntity

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

the class GlobalAttributeDefinitionDaoHelperTest method testGetGlobalAttributeDefinitionEntity.

@Test
public void testGetGlobalAttributeDefinitionEntity() {
    // Create a global attribute definition key.
    GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Create a global attribute definition entity.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = globalAttributeDefinitionDaoTestHelper.createGlobalAttributeDefinitionEntity(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Mock calls to external methods.
    when(globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey)).thenReturn(globalAttributeDefinitionEntity);
    // Call the method under test.
    GlobalAttributeDefinitionEntity response = globalAttributeDefinitionDaoHelper.getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey);
    // Verify the external calls.
    verify(globalAttributeDefinitionDao).getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey);
    verifyNoMoreInteractions(globalAttributeDefinitionDao);
    // Validate the response.
    assertEquals(globalAttributeDefinitionEntity, response);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 7 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity 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 8 with GlobalAttributeDefinitionEntity

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

the class GlobalAttributeDefinitionDaoTest method testGetGlobalAttributeDefinitionByKey.

@Test
public void testGetGlobalAttributeDefinitionByKey() {
    // Create and persist a global attribute definition entity.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = globalAttributeDefinitionDaoTestHelper.createGlobalAttributeDefinitionEntity(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Retrieve a global attribute definition entity.
    assertEquals(globalAttributeDefinitionEntity, globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME)));
    // Test case insensitivity.
    assertEquals(globalAttributeDefinitionEntity, globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL.toUpperCase(), GLOBAL_ATTRIBUTE_DEFINITON_NAME.toUpperCase())));
    assertEquals(globalAttributeDefinitionEntity, globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL.toLowerCase(), GLOBAL_ATTRIBUTE_DEFINITON_NAME.toLowerCase())));
    // Confirm negative results when using invalid values.
    assertNull(globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(new GlobalAttributeDefinitionKey(I_DO_NOT_EXIST, GLOBAL_ATTRIBUTE_DEFINITON_NAME)));
    assertNull(globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, I_DO_NOT_EXIST)));
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) Test(org.junit.Test)

Example 9 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity 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)

Example 10 with GlobalAttributeDefinitionEntity

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

the class GlobalAttributeDefinitionDaoImpl method getGlobalAttributeDefinitionByKey.

@Override
public GlobalAttributeDefinitionEntity getGlobalAttributeDefinitionByKey(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<GlobalAttributeDefinitionEntity> criteria = builder.createQuery(GlobalAttributeDefinitionEntity.class);
    // The criteria root is the global attribute definition entity.
    Root<GlobalAttributeDefinitionEntity> globalAttributeDefinitionEntityRoot = criteria.from(GlobalAttributeDefinitionEntity.class);
    // Join on the other tables that we filter on
    Join<GlobalAttributeDefinitionEntity, GlobalAttributeDefinitionLevelEntity> globalAttributeDefinitionLevelEntityJoin = globalAttributeDefinitionEntityRoot.join(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionLevel);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(globalAttributeDefinitionLevelEntityJoin.get(GlobalAttributeDefinitionLevelEntity_.globalAttributeDefinitionLevel)), globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel().toUpperCase()));
    predicates.add(builder.equal(builder.upper(globalAttributeDefinitionEntityRoot.get(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionName)), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName().toUpperCase()));
    // Add all clauses to the query.
    criteria.select(globalAttributeDefinitionEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    return executeSingleResultQuery(criteria, String.format("Found more than one global attribute definition with parameters {globalAttributeDefinitionLevel=\"%s\", globalAttributeDefinitionLevel=\"%s\"}.", globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel(), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Aggregations

GlobalAttributeDefinitionEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)19 Test (org.junit.Test)10 GlobalAttributeDefinitionKey (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)7 GlobalAttributeDefinitionLevelEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)5 Attribute (org.finra.herd.model.api.xml.Attribute)4 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)4 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)4 GlobalAttributeDefinition (org.finra.herd.model.api.xml.GlobalAttributeDefinition)3 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)3 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 AllowedAttributeValueEntity (org.finra.herd.model.jpa.AllowedAttributeValueEntity)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 Tuple (javax.persistence.Tuple)1 Predicate (javax.persistence.criteria.Predicate)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)1 GlobalAttributeDefinitionCreateRequest (org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest)1