use of org.finra.herd.model.jpa.AttributeValueListEntity 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.AttributeValueListEntity 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);
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AllowedAttributeValueServiceImpl method getAllowedAttributeValues.
/**
* Retrieves existing allowed attribute values based on the specified key
*
* @param attributeValueListKey the attribute value list key
*
* @return the allowed attribute values information
*/
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public AllowedAttributeValuesInformation getAllowedAttributeValues(AttributeValueListKey attributeValueListKey) {
// Perform validation and trim of the input parameters.
attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey);
// Retrieve and ensure that a attribute value list exists with the specified name.
AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey);
// Retrieve a list of allowed attribute values.
List<AllowedAttributeValueEntity> allowedAttributeValueEntities = allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey);
return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, allowedAttributeValueEntities);
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListServiceImpl method createAttributeValueListEntity.
/**
* Creates and persists a new attribute value list entity from the request information.
*
* @param request the request
* @param namespaceEntity the namespace
*
* @return the newly created attribute value list entity
*/
private AttributeValueListEntity createAttributeValueListEntity(AttributeValueListCreateRequest request, NamespaceEntity namespaceEntity) {
// Create a new entity.
AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
attributeValueListEntity.setNamespace(namespaceEntity);
attributeValueListEntity.setName(request.getAttributeValueListKey().getAttributeValueListName());
// Persist and return the newly created entity.
return attributeValueListDao.saveAndRefresh(attributeValueListEntity);
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListDaoHelperTest method testGetAttributeValueListEntity.
@Test
public void testGetAttributeValueListEntity() {
// Create an attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create an attribute value list entity.
AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
// Mock calls to external methods.
when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(attributeValueListEntity);
// Call the method under test.
AttributeValueListEntity result = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey);
// Verify the external calls.
verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
verifyNoMoreInteractions(attributeValueListDao);
// Validate the result.
assertEquals(attributeValueListEntity, result);
}
Aggregations