Search in sources :

Example 11 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity 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)

Example 12 with GlobalAttributeDefinitionEntity

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

the class GlobalAttributeDefinitionServiceImpl method createGlobalAttributeDefinition.

@Override
public GlobalAttributeDefinition createGlobalAttributeDefinition(GlobalAttributeDefinitionCreateRequest request) {
    // Validate and trim the request parameters.
    validateGlobalAttributeDefinitionCreateRequest(request);
    // Validate the global Attribute Definition entity does not already exist in the database.
    globalAttributeDefinitionDaoHelper.validateGlobalAttributeDefinitionNoExists(request.getGlobalAttributeDefinitionKey());
    // Get the existing global Attribute Definition level entity
    GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(request.getGlobalAttributeDefinitionKey().getGlobalAttributeDefinitionLevel());
    AttributeValueListEntity attributeValueListEntity = null;
    // Get the attribute value list if the attribute value key exists
    if (request.getAttributeValueListKey() != null) {
        // Get the existing attribute list and ensure it exists
        attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
    }
    // Create and persist a new global Attribute Definition entity from the request information.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = createGlobalAttributeDefinitionEntity(request.getGlobalAttributeDefinitionKey(), globalAttributeDefinitionLevelEntity, attributeValueListEntity);
    // Create and return the global Attribute Definition object from the persisted entity.
    return createGlobalAttributeDefinitionFromEntity(globalAttributeDefinitionEntity);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity)

Example 13 with GlobalAttributeDefinitionEntity

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

the class GlobalAttributeDefinitionServiceImpl method getGlobalAttributeDefinition.

@Override
public GlobalAttributeDefinition getGlobalAttributeDefinition(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) {
    // Perform validation and trim.
    globalAttributeDefinitionHelper.validateGlobalAttributeDefinitionKey(globalAttributeDefinitionKey);
    // Retrieve and ensure that a global Attribute Definition already exists with the specified key.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = globalAttributeDefinitionDaoHelper.getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey);
    // Create and return the global Attribute Definition object from the deleted entity.
    return createGlobalAttributeDefinitionFromEntity(globalAttributeDefinitionEntity);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)

Example 14 with GlobalAttributeDefinitionEntity

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

the class GlobalAttributeDefinitionServiceImpl method deleteGlobalAttributeDefinition.

@Override
public GlobalAttributeDefinition deleteGlobalAttributeDefinition(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) {
    // Perform validation and trim.
    globalAttributeDefinitionHelper.validateGlobalAttributeDefinitionKey(globalAttributeDefinitionKey);
    // Retrieve and ensure that a global Attribute Definition already exists with the specified key.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = globalAttributeDefinitionDaoHelper.getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey);
    // Delete the global Attribute Definition.
    globalAttributeDefinitionDao.delete(globalAttributeDefinitionEntity);
    // Create and return the global Attribute Definition object from the deleted entity.
    return createGlobalAttributeDefinitionFromEntity(globalAttributeDefinitionEntity);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)

Example 15 with GlobalAttributeDefinitionEntity

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

the class GlobalAttributeDefinitionDaoHelper method getAllowedAttributeValues.

/**
 * Gets allowed attribute values for the global attribute definition
 *
 * @param globalAttributeDefinitionKey the global attribute definition key
 *
 * @return list of allowed attribute values, if the global attribute definition does not have attribute list returns null
 */
public List<String> getAllowedAttributeValues(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) {
    List<String> allowedAttributeValues = null;
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey);
    if (globalAttributeDefinitionEntity.getAttributeValueList() != null) {
        allowedAttributeValues = new ArrayList<>();
        Collection<AllowedAttributeValueEntity> list = globalAttributeDefinitionEntity.getAttributeValueList().getAllowedAttributeValues();
        for (AllowedAttributeValueEntity allowedAttributeValueEntity : list) {
            allowedAttributeValues.add(allowedAttributeValueEntity.getAllowedAttributeValue());
        }
    }
    return allowedAttributeValues;
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity)

Aggregations

GlobalAttributeDefinitionEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)19 Test (org.junit.Test)10 GlobalAttributeDefinitionKey (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)7 GlobalAttributeDefinitionLevelEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)5 Attribute (org.finra.herd.model.api.xml.Attribute)4 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)4 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)4 GlobalAttributeDefinition (org.finra.herd.model.api.xml.GlobalAttributeDefinition)3 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)3 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 AllowedAttributeValueEntity (org.finra.herd.model.jpa.AllowedAttributeValueEntity)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 Tuple (javax.persistence.Tuple)1 Predicate (javax.persistence.criteria.Predicate)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)1 GlobalAttributeDefinitionCreateRequest (org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest)1