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);
}
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);
}
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)));
}
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;
}
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()));
}
Aggregations