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;
}
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);
}
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);
}
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;
}
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));
}
}
}
}
}
Aggregations