Search in sources :

Example 11 with AttributeValueListEntity

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

the class AttributeValueListServiceTest method testDeleteAttributeValueList.

@Test
public void testDeleteAttributeValueList() {
    // Create an attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create a namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create an attribute value list entity.
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    // Mock calls to external methods.
    when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
    when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod();
    // Call the method under test.
    AttributeValueList result = attributeValueListService.deleteAttributeValueList(attributeValueListKey);
    // Verify the external calls.
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
    verify(attributeValueListDao).delete(attributeValueListEntity);
    verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AttributeValueList(org.finra.herd.model.api.xml.AttributeValueList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 12 with AttributeValueListEntity

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

the class AttributeValueListServiceTest method testGetAttributeValueList.

@Test
public void testGetAttributeValueList() {
    // Create an attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create a namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create an attribute value list entity.
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    // Mock calls to external methods.
    when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
    when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod();
    // Call the method under test.
    AttributeValueList result = attributeValueListService.getAttributeValueList(attributeValueListKey);
    // Verify the external calls.
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
    verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AttributeValueList(org.finra.herd.model.api.xml.AttributeValueList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 13 with AttributeValueListEntity

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

the class AttributeValueListServiceTest method createAttributeValueList.

@Test
public void createAttributeValueList() {
    // Create an attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create an attribute value list create request.
    AttributeValueListCreateRequest request = new AttributeValueListCreateRequest(attributeValueListKey);
    // Create a namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create an attribute value list entity.
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    // Mock calls to external methods.
    when(namespaceDaoHelper.getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(namespaceEntity);
    when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(null);
    when(attributeValueListDao.saveAndRefresh(any(AttributeValueListEntity.class))).thenReturn(attributeValueListEntity);
    when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod();
    // Call the method under test.
    AttributeValueList result = attributeValueListService.createAttributeValueList(request);
    // Verify the external calls.
    verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request);
    verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
    verify(attributeValueListDao).saveAndRefresh(any(AttributeValueListEntity.class));
    verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AttributeValueList(org.finra.herd.model.api.xml.AttributeValueList) AttributeValueListCreateRequest(org.finra.herd.model.api.xml.AttributeValueListCreateRequest) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 14 with AttributeValueListEntity

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

the class AttributeValueListDaoImpl method getAttributeValueListByKey.

@Override
public AttributeValueListEntity getAttributeValueListByKey(AttributeValueListKey attributeValueListKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<AttributeValueListEntity> criteria = builder.createQuery(AttributeValueListEntity.class);
    // The criteria root is the attribute value list.
    Root<AttributeValueListEntity> attributeValueListEntityRoot = criteria.from(AttributeValueListEntity.class);
    // Join to the other tables we can filter on.
    Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityRoot.join(AttributeValueListEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(attributeValueListEntityRoot.get(AttributeValueListEntity_.name)), attributeValueListKey.getAttributeValueListName().toUpperCase()));
    // Add all clauses to the query.
    criteria.select(attributeValueListEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    // Execute the query and return the results.
    return executeSingleResultQuery(criteria, String.format("Found more than one attribute value list with parameters {namespace=\"%s\", attribute_value_name=\"%s\"}.", attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) Predicate(javax.persistence.criteria.Predicate)

Example 15 with AttributeValueListEntity

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

the class AttributeValueListDaoImpl method getAttributeValueLists.

@Override
public List<AttributeValueListKey> getAttributeValueLists(Collection<String> namespaces) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<AttributeValueListEntity> criteria = builder.createQuery(AttributeValueListEntity.class);
    // The criteria root is the attribute value list entity.
    Root<AttributeValueListEntity> attributeValueListEntityRoot = criteria.from(AttributeValueListEntity.class);
    // Join to the other tables we can filter on.
    Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityRoot.join(AttributeValueListEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(namespaces)) {
        predicates.add(namespaceEntityJoin.get(NamespaceEntity_.code).in(namespaces));
    }
    // Order the results by namespace and job name.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code)));
    orderBy.add(builder.asc(attributeValueListEntityRoot.get(AttributeValueListEntity_.name)));
    // Add all clauses to the query.
    criteria.select(attributeValueListEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
    // Execute the query and build a list of keys.
    List<AttributeValueListKey> attributeValueListKeys = new ArrayList<>();
    for (AttributeValueListEntity attributeValueListEntity : entityManager.createQuery(criteria).getResultList()) {
        attributeValueListKeys.add(new AttributeValueListKey(attributeValueListEntity.getNamespace().getCode(), attributeValueListEntity.getName()));
    }
    return attributeValueListKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey)

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