Search in sources :

Example 16 with AttributeValueListEntity

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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity)

Example 17 with 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;
}
Also used : ArrayList(java.util.ArrayList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity)

Example 18 with AttributeValueListEntity

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)));
}
Also used : AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 19 with AttributeValueListEntity

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) Predicate(javax.persistence.criteria.Predicate)

Example 20 with AttributeValueListEntity

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);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) GlobalAttributeDefinition(org.finra.herd.model.api.xml.GlobalAttributeDefinition) Test(org.junit.Test)

Aggregations

AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)27 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)14 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)14 Test (org.junit.Test)12 AllowedAttributeValueEntity (org.finra.herd.model.jpa.AllowedAttributeValueEntity)11 ArrayList (java.util.ArrayList)9 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)6 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)3 AllowedAttributeValuesInformation (org.finra.herd.model.api.xml.AllowedAttributeValuesInformation)3 AttributeValueList (org.finra.herd.model.api.xml.AttributeValueList)3 GlobalAttributeDefinitionEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)3 Order (javax.persistence.criteria.Order)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 AllowedAttributeValuesCreateRequest (org.finra.herd.model.api.xml.AllowedAttributeValuesCreateRequest)2 AllowedAttributeValuesDeleteRequest (org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest)2 AttributeValueListCreateRequest (org.finra.herd.model.api.xml.AttributeValueListCreateRequest)2 GlobalAttributeDefinition (org.finra.herd.model.api.xml.GlobalAttributeDefinition)2 GlobalAttributeDefinitionKey (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)2