Search in sources :

Example 6 with AttributeValueListEntity

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

the class GlobalAttributeDefinitionServiceImpl method createGlobalAttributeDefinitionFromEntity.

private GlobalAttributeDefinition createGlobalAttributeDefinitionFromEntity(GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity) {
    GlobalAttributeDefinition globalAttributeDefinition = new GlobalAttributeDefinition();
    globalAttributeDefinition.setId(globalAttributeDefinitionEntity.getId());
    GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey();
    globalAttributeDefinitionKey.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionEntity.getGlobalAttributeDefinitionLevel().getGlobalAttributeDefinitionLevel());
    globalAttributeDefinitionKey.setGlobalAttributeDefinitionName(globalAttributeDefinitionEntity.getGlobalAttributeDefinitionName());
    globalAttributeDefinition.setGlobalAttributeDefinitionKey(globalAttributeDefinitionKey);
    AttributeValueListEntity attributeValueListEntity = globalAttributeDefinitionEntity.getAttributeValueList();
    if (attributeValueListEntity != null) {
        globalAttributeDefinition.setAttributeValueList(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity));
    }
    return globalAttributeDefinition;
}
Also used : GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) GlobalAttributeDefinition(org.finra.herd.model.api.xml.GlobalAttributeDefinition)

Example 7 with AttributeValueListEntity

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

the class AttributeValueListServiceImpl method deleteAttributeValueList.

@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public AttributeValueList deleteAttributeValueList(AttributeValueListKey attributeValueListKey) {
    // Perform validation and trim.
    attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey);
    // Retrieve and ensure that an attribute value list already exists with the specified key.
    AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey);
    // Delete the attribute value list.
    attributeValueListDao.delete(attributeValueListEntity);
    // Create and return the attribute value list object from the deleted entity.
    return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity);
}
Also used : AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 8 with AttributeValueListEntity

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

the class AttributeValueListServiceImpl method getAttributeValueList.

@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public AttributeValueList getAttributeValueList(AttributeValueListKey attributeValueListKey) {
    // Perform validation and trim.
    attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey);
    // Retrieve and ensure that an attribute value list already exists with the specified key.
    AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey);
    // Create and return the attribute value list object from the deleted entity.
    return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity);
}
Also used : AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 9 with AttributeValueListEntity

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

the class AttributeValueListServiceImpl method createAttributeValueList.

@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public AttributeValueList createAttributeValueList(AttributeValueListCreateRequest request) {
    // Validate and trim the request parameters.
    attributeValueListHelper.validateAttributeValueListCreateRequest(request);
    // Get the attribute value list key.
    AttributeValueListKey attributeValueListKey = request.getAttributeValueListKey();
    // Retrieve the namespace entity and validate it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getAttributeValueListKey().getNamespace());
    // Validate the attribute value list does not already exist.
    if (attributeValueListDao.getAttributeValueListByKey(request.getAttributeValueListKey()) != null) {
        throw new AlreadyExistsException(String.format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace()));
    }
    // Create and persist a new attribute value list entity from the request information.
    AttributeValueListEntity attributeValueListEntity = createAttributeValueListEntity(request, namespaceEntity);
    // Create and return the attribute value list object from the persisted entity.
    return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with AttributeValueListEntity

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

the class AttributeValueListServiceTest method createAttributeValueListAlreadyExists.

@Test
public void createAttributeValueListAlreadyExists() {
    // 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);
    // Mock calls to external methods.
    when(namespaceDaoHelper.getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(new NamespaceEntity());
    when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(new AttributeValueListEntity());
    // Try to call the method under test.
    try {
        attributeValueListService.createAttributeValueList(request);
        fail();
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", ATTRIBUTE_VALUE_LIST_NAME, ATTRIBUTE_VALUE_LIST_NAMESPACE), e.getMessage());
    }
    // Verify the external calls.
    verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request);
    verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) 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)

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