Search in sources :

Example 16 with GlobalAttributeDefinitionKey

use of org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey in project herd by FINRAOS.

the class GlobalAttributeDefinitionDaoImpl method getAllGlobalAttributeDefinitionKeys.

@Override
public List<GlobalAttributeDefinitionKey> getAllGlobalAttributeDefinitionKeys() {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the global attribute definition.
    Root<GlobalAttributeDefinitionEntity> globalAttributeDefinitionEntityRoot = criteria.from(GlobalAttributeDefinitionEntity.class);
    // Join on the other tables that we filter on
    Join<GlobalAttributeDefinitionEntity, GlobalAttributeDefinitionLevelEntity> globalAttributeDefinitionLevelEntityJoin = globalAttributeDefinitionEntityRoot.join(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionLevel);
    // Get the columns
    Path<String> globalAttributeDefinitionLevel = globalAttributeDefinitionLevelEntityJoin.get(GlobalAttributeDefinitionLevelEntity_.globalAttributeDefinitionLevel);
    Path<String> globalAttributeDefinitionName = globalAttributeDefinitionEntityRoot.get(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionName);
    // Add all clauses to the query
    criteria.multiselect(globalAttributeDefinitionLevel, globalAttributeDefinitionName).orderBy(builder.asc(globalAttributeDefinitionLevel), builder.asc(globalAttributeDefinitionName));
    // Populate the "keys" objects from the returned tuples
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    List<GlobalAttributeDefinitionKey> globalAttributeDefinitionKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        globalAttributeDefinitionKeys.add(new GlobalAttributeDefinitionKey(tuple.get(globalAttributeDefinitionLevel), tuple.get(globalAttributeDefinitionName)));
    }
    return globalAttributeDefinitionKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) ArrayList(java.util.ArrayList) GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) Tuple(javax.persistence.Tuple)

Example 17 with GlobalAttributeDefinitionKey

use of org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey in project herd by FINRAOS.

the class GlobalAttributeDefinitionRestControllerTest method testGetGlobalAttributeDefinitions.

@Test
public void testGetGlobalAttributeDefinitions() {
    // Create a list of global attribute definition keys.
    GlobalAttributeDefinitionKeys globalAttributeDefinitionKeys = new GlobalAttributeDefinitionKeys(Arrays.asList(new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME), new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME_2)));
    // Mock calls to external methods.
    when(globalAttributeDefinitionService.getGlobalAttributeDefinitionKeys()).thenReturn(globalAttributeDefinitionKeys);
    // Call the method under test.
    GlobalAttributeDefinitionKeys response = globalAttributeDefinitionRestController.getGlobalAttributeDefinitions();
    // Verify the external calls.
    verify(globalAttributeDefinitionService).getGlobalAttributeDefinitionKeys();
    verifyNoMoreInteractions(globalAttributeDefinitionService);
    // Validate the response.
    assertEquals(new GlobalAttributeDefinitionKeys(Arrays.asList(new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME), new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME_2))), response);
}
Also used : GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) GlobalAttributeDefinitionKeys(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKeys) Test(org.junit.Test)

Example 18 with GlobalAttributeDefinitionKey

use of org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey 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 19 with GlobalAttributeDefinitionKey

use of org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey in project herd by FINRAOS.

the class AttributeHelper method getGlobalAttributesDefinitionForFormat.

/**
 * Return all the format level global attribute definitions
 *
 * @return global attribute definition keys
 */
public List<GlobalAttributeDefinitionKey> getGlobalAttributesDefinitionForFormat() {
    List<GlobalAttributeDefinitionKey> globalAttributeDefinitionKeys = new ArrayList<>();
    GlobalAttributeDefinitionKeys globalAttributesDefinitions = globalAttributeDefinitionService.getGlobalAttributeDefinitionKeys();
    for (GlobalAttributeDefinitionKey globalAttributeDefinitionKey : globalAttributesDefinitions.getGlobalAttributeDefinitionKeys()) {
        if (GlobalAttributeDefinitionLevelEntity.GlobalAttributeDefinitionLevels.BUS_OBJCT_FRMT.name().equalsIgnoreCase(globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel())) {
            globalAttributeDefinitionKeys.add(globalAttributeDefinitionKey);
        }
    }
    return globalAttributeDefinitionKeys;
}
Also used : ArrayList(java.util.ArrayList) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) GlobalAttributeDefinitionKeys(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKeys)

Example 20 with GlobalAttributeDefinitionKey

use of org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey in project herd by FINRAOS.

the class AttributeHelper method validateFormatAttributes.

/**
 * Validate format attributes
 *
 * @param attributes the attributes
 *
 * @throws IllegalArgumentException  if any invalid attributes were found.
 */
public void validateFormatAttributes(List<Attribute> attributes) throws IllegalArgumentException {
    Map<String, String> attributeNameValidationMap = validateAttributes(attributes);
    // Validate each format level global attribute exists and attribute value is from allowed list, if the allowed list exists
    for (GlobalAttributeDefinitionKey globalAttributeFormat : getGlobalAttributesDefinitionForFormat()) {
        String globalAttributeDefinitionNameOriginal = globalAttributeFormat.getGlobalAttributeDefinitionName();
        String globalAttributeDefinitionName = globalAttributeDefinitionNameOriginal.toLowerCase();
        if (!attributeNameValidationMap.containsKey(globalAttributeDefinitionName) || StringUtils.isBlank(attributeNameValidationMap.get(globalAttributeDefinitionName))) {
            throw new IllegalArgumentException(String.format("The business object format has a required attribute \"%s\" which was not specified or has a value which is blank.", globalAttributeDefinitionNameOriginal));
        } else {
            List<String> allowedAttributeValues = globalAttributeDefinitionDaoHelper.getAllowedAttributeValues(globalAttributeFormat);
            if (allowedAttributeValues != null) {
                String attributeValue = attributeNameValidationMap.get(globalAttributeDefinitionName);
                if (!allowedAttributeValues.contains(attributeValue)) {
                    throw new IllegalArgumentException(String.format("The business object format attribute \"%s\" value \"%s\" is not from allowed attribute values.", globalAttributeDefinitionNameOriginal, attributeValue));
                }
            }
        }
    }
}
Also used : GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)

Aggregations

GlobalAttributeDefinitionKey (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)20 Test (org.junit.Test)16 GlobalAttributeDefinition (org.finra.herd.model.api.xml.GlobalAttributeDefinition)7 GlobalAttributeDefinitionEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)7 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)5 GlobalAttributeDefinitionCreateRequest (org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest)3 GlobalAttributeDefinitionKeys (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKeys)3 ArrayList (java.util.ArrayList)2 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)2 GlobalAttributeDefinitionLevelEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)2 Tuple (javax.persistence.Tuple)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1