use of org.finra.herd.model.jpa.AllowedAttributeValueEntity in project herd by FINRAOS.
the class AllowedAttributeValueDaoTestHelper method createAllowedAttributeValueEntities.
/**
* Returns a list of test allowed attribute value entities.
*
* @return the list of allowed attribute value entities
*/
public List<AllowedAttributeValueEntity> createAllowedAttributeValueEntities(AttributeValueListKey attributeValueListKey, List<String> allowedAttributeValues) {
AttributeValueListEntity attributeValueListEntity = attributeValueListDao.getAttributeValueListByKey(attributeValueListKey);
if (attributeValueListEntity == null) {
attributeValueListEntity = attributeValueListDaoTestHelper.createAttributeValueListEntity(attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName());
}
List<AllowedAttributeValueEntity> allowedAttributeValueEntities = new ArrayList<>();
for (String allowedAttributeValue : allowedAttributeValues) {
AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue);
allowedAttributeValueEntities.add(allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity));
}
return allowedAttributeValueEntities;
}
use of org.finra.herd.model.jpa.AllowedAttributeValueEntity in project herd by FINRAOS.
the class AllowedAttributeValueDaoTest method testGetAllowedAttributeValues.
@Test
public void testGetAllowedAttributeValues() {
// Create attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(NAMESPACE_CODE, ATTRIBUTE_VALUE_LIST_NAME);
List<String> allowedAttributeValueList = allowedAttributeValueDaoTestHelper.getTestUnsortedAllowedAttributeValues();
// Create and persist a attribute value list key entity.
attributeValueListDaoTestHelper.createAttributeValueListEntity(NAMESPACE_CODE, ATTRIBUTE_VALUE_LIST_NAME);
// Create and persist a list of allowed attribute values.
allowedAttributeValueDaoTestHelper.createAllowedAttributeValueEntities(attributeValueListKey, allowedAttributeValueList);
// Get the allowed attribute values for the specified key.
List<AllowedAttributeValueEntity> responseEntities = allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey);
// Create a list of allowed attribute values.
List<String> allowedAttributesResponse = new ArrayList<>();
responseEntities.forEach((responseEntity) -> {
allowedAttributesResponse.add(responseEntity.getAllowedAttributeValue());
});
// Validate the response is sorted by allowed attribute values.
Collections.sort(allowedAttributeValueList);
assertEquals(allowedAttributeValueList, allowedAttributesResponse);
}
use of org.finra.herd.model.jpa.AllowedAttributeValueEntity in project herd by FINRAOS.
the class AllowedAttributeValueDaoImpl method getAllowedAttributeValuesByAttributeValueListKey.
@Override
public List<AllowedAttributeValueEntity> getAllowedAttributeValuesByAttributeValueListKey(AttributeValueListKey attributeValueListKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<AllowedAttributeValueEntity> criteria = builder.createQuery(AllowedAttributeValueEntity.class);
// The criteria root is the allowed attribute value.
Root<AllowedAttributeValueEntity> allowedAttributeValueEntityRoot = criteria.from(AllowedAttributeValueEntity.class);
// Join to the other tables we can filter on.
Join<AllowedAttributeValueEntity, AttributeValueListEntity> attributeValueListEntityJoin = allowedAttributeValueEntityRoot.join(AllowedAttributeValueEntity_.attributeValueList);
Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityJoin.join(AttributeValueListEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(builder.upper(attributeValueListEntityJoin.get(AttributeValueListEntity_.name)), attributeValueListKey.getAttributeValueListName().toUpperCase()));
predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase()));
// Order the results by allowed attribute value.
Order orderByAllowedAttributeValue = builder.asc(allowedAttributeValueEntityRoot.get(AllowedAttributeValueEntity_.allowedAttributeValue));
// Add the clauses for the query.
criteria.select(allowedAttributeValueEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderByAllowedAttributeValue);
// Execute the query and return the results.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.AllowedAttributeValueEntity in project herd by FINRAOS.
the class AllowedAttributeValueServiceImpl method deleteAllowedAttributeValues.
/**
* Deletes specified allowed attribute values from an existing attribute value list which is identified by name.
*
* @param request the information needed to delete the allowed attribute values
*
* @return the allowed attribute values that got deleted
*/
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public AllowedAttributeValuesInformation deleteAllowedAttributeValues(AllowedAttributeValuesDeleteRequest request) {
// Perform request validation and trim request parameters.
validateAllowedAttributeValuesDeleteRequest(request);
// Retrieve and ensure that a attribute value list exists with the specified name.
AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
// Load all existing allowed attribute value entities into a map for quick access.
Map<String, AllowedAttributeValueEntity> allowedAttributeValueEntityMap = getAllowedAttributeValueEntityMap(attributeValueListEntity.getAllowedAttributeValues());
// Build a list of all allowed attribute value entities to be deleted.
Collection<AllowedAttributeValueEntity> deletedAllowedAttributeValueEntities = new ArrayList<>();
for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
// Find the relative allowed attribute entity.
AllowedAttributeValueEntity allowedAttributeValueEntity = allowedAttributeValueEntityMap.get(allowedAttributeValue);
if (allowedAttributeValueEntity != null) {
deletedAllowedAttributeValueEntities.add(allowedAttributeValueEntity);
} else {
throw new ObjectNotFoundException(String.format("Allowed attribute value \"%s\" doesn't exist in \"%s\" attribute value list.", allowedAttributeValue, attributeValueListEntity.getName()));
}
}
// Perform the actual deletion.
for (AllowedAttributeValueEntity allowedAttributeValueEntity : deletedAllowedAttributeValueEntities) {
attributeValueListEntity.getAllowedAttributeValues().remove(allowedAttributeValueEntity);
}
allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, deletedAllowedAttributeValueEntities);
}
use of org.finra.herd.model.jpa.AllowedAttributeValueEntity in project herd by FINRAOS.
the class AllowedAttributeValueServiceImpl method createAllowedAttributeValues.
/**
* Creates a list of allowed attribute values for an existing attribute value list key.
*
* @param request the information needed to create the allowed attribute values
*
* @return the newly created allowed attribute values
*/
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public AllowedAttributeValuesInformation createAllowedAttributeValues(AllowedAttributeValuesCreateRequest request) {
// Perform request validation and trim request parameters.
validateAllowedAttributeValuesCreateRequest(request);
// Retrieve and ensure that a attribute value list exists with the specified name.
AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
// Load all existing allowed attribute value entities into a map for quick access.
Map<String, AllowedAttributeValueEntity> allowedAttributeValueEntityMap = getAllowedAttributeValueEntityMap(attributeValueListEntity.getAllowedAttributeValues());
// Fail if any of the allowed attribute values to be created already exist.
for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
if (allowedAttributeValueEntityMap.containsKey(allowedAttributeValue)) {
throw new AlreadyExistsException(String.format("Allowed attribute value \"%s\" already exists in \"%s\" attribute value list.", allowedAttributeValue, attributeValueListEntity.getName()));
}
}
// Create and persist the allowed attribute value entities.
Collection<AllowedAttributeValueEntity> createdAllowedAttributeValueEntities = new ArrayList<>();
for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
createdAllowedAttributeValueEntities.add(allowedAttributeValueEntity);
allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue);
allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity);
}
allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, createdAllowedAttributeValueEntities);
}
Aggregations