use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListDaoTestHelper method createAttributeValueListEntity.
/**
* Creates attribute value list entity and save it in the database.
*
* @param namespace the namespace of the attribute value list
* @param attributeValueListName the name of the attribute value list
*
* @return the attribute value list entity
*/
public AttributeValueListEntity createAttributeValueListEntity(String namespace, String attributeValueListName) {
// Create a namespace entity if not exists.
NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace);
if (namespaceEntity == null) {
namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(namespace);
}
// Create an attribute value list entity.
AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
attributeValueListEntity.setNamespace(namespaceEntity);
attributeValueListEntity.setName(attributeValueListName);
return attributeValueListDao.saveAndRefresh(attributeValueListEntity);
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AllowedAttributeValueDaoTestHelper method createAllowedAttributeValueEntities.
/**
* Returns a list of test allowed attribute value entities.
*
* @return the list of allowed attribute value entities
*/
public List<AllowedAttributeValueEntity> createAllowedAttributeValueEntities(AttributeValueListKey attributeValueListKey, List<String> allowedAttributeValues) {
AttributeValueListEntity attributeValueListEntity = attributeValueListDao.getAttributeValueListByKey(attributeValueListKey);
if (attributeValueListEntity == null) {
attributeValueListEntity = attributeValueListDaoTestHelper.createAttributeValueListEntity(attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName());
}
List<AllowedAttributeValueEntity> allowedAttributeValueEntities = new ArrayList<>();
for (String allowedAttributeValue : allowedAttributeValues) {
AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue);
allowedAttributeValueEntities.add(allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity));
}
return allowedAttributeValueEntities;
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListDaoTest method testGetAttributeValueListByKey.
@Test
public void testGetAttributeValueListByKey() {
// Create and persist a attribute value list entity.
AttributeValueListEntity attributeValueListEntity = attributeValueListDaoTestHelper.createAttributeValueListEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Retrieve a attribute value list entity.
assertEquals(attributeValueListEntity, attributeValueListDao.getAttributeValueListByKey(new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME)));
// Test case insensitivity.
assertEquals(attributeValueListEntity, attributeValueListDao.getAttributeValueListByKey(new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE.toUpperCase(), ATTRIBUTE_VALUE_LIST_NAME.toUpperCase())));
assertEquals(attributeValueListEntity, attributeValueListDao.getAttributeValueListByKey(new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE.toLowerCase(), ATTRIBUTE_VALUE_LIST_NAME.toLowerCase())));
// Confirm negative results when using invalid values.
assertNull(attributeValueListDao.getAttributeValueListByKey(new AttributeValueListKey(I_DO_NOT_EXIST, ATTRIBUTE_VALUE_LIST_NAME)));
assertNull(attributeValueListDao.getAttributeValueListByKey(new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, I_DO_NOT_EXIST)));
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AllowedAttributeValueDaoImpl method getAllowedAttributeValuesByAttributeValueListKey.
@Override
public List<AllowedAttributeValueEntity> getAllowedAttributeValuesByAttributeValueListKey(AttributeValueListKey attributeValueListKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<AllowedAttributeValueEntity> criteria = builder.createQuery(AllowedAttributeValueEntity.class);
// The criteria root is the allowed attribute value.
Root<AllowedAttributeValueEntity> allowedAttributeValueEntityRoot = criteria.from(AllowedAttributeValueEntity.class);
// Join to the other tables we can filter on.
Join<AllowedAttributeValueEntity, AttributeValueListEntity> attributeValueListEntityJoin = allowedAttributeValueEntityRoot.join(AllowedAttributeValueEntity_.attributeValueList);
Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityJoin.join(AttributeValueListEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(builder.upper(attributeValueListEntityJoin.get(AttributeValueListEntity_.name)), attributeValueListKey.getAttributeValueListName().toUpperCase()));
predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase()));
// Order the results by allowed attribute value.
Order orderByAllowedAttributeValue = builder.asc(allowedAttributeValueEntityRoot.get(AllowedAttributeValueEntity_.allowedAttributeValue));
// Add the clauses for the query.
criteria.select(allowedAttributeValueEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderByAllowedAttributeValue);
// Execute the query and return the results.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class GlobalAttributeDefinitionServiceTest method testGetGlobalAttributeDefinition.
@Test
public void testGetGlobalAttributeDefinition() {
// 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);
AttributeValueListEntity attributeValueListEntity = attributeValueListDaoTestHelper.createAttributeValueListEntity("namespace_1", "list_1");
globalAttributeDefinitionEntity.setAttributeValueList(attributeValueListEntity);
// Mock calls to external methods.
when(globalAttributeDefinitionDaoHelper.getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey)).thenReturn(globalAttributeDefinitionEntity);
// Call the method under test.
GlobalAttributeDefinition response = globalAttributeDefinitionService.getGlobalAttributeDefinition(globalAttributeDefinitionKey);
// Verify the external calls.
verify(globalAttributeDefinitionHelper).validateGlobalAttributeDefinitionKey(globalAttributeDefinitionKey);
verify(globalAttributeDefinitionDaoHelper).getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey);
verifyNoMoreInteractionsHelper();
// Validate.
assertEquals(new GlobalAttributeDefinition(response.getId(), globalAttributeDefinitionKey, attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)), response);
}
Aggregations