use of org.finra.herd.model.api.xml.AttributeValueListKey in project herd by FINRAOS.
the class AllowedAttributeValueServiceTest method testCreateAllowedAttributeValuesMissingAllowedAttributeValue.
@Test
public void testCreateAllowedAttributeValuesMissingAllowedAttributeValue() {
// Create attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create the request without allowed attribute values.
AllowedAttributeValuesCreateRequest request = new AllowedAttributeValuesCreateRequest(attributeValueListKey, NO_ALLOWED_ATTRIBUTE_VALUES);
// Try to call method under test.
try {
allowedAttributeValueService.createAllowedAttributeValues(request);
fail();
} catch (IllegalArgumentException e) {
assertEquals("At least one allowed attribute value must be specified.", e.getMessage());
}
// Verify the external calls.
verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.api.xml.AttributeValueListKey in project herd by FINRAOS.
the class AllowedAttributeValueServiceTest method testCreateAllowedAttributeValuesAlreadyExists.
@Test
public void testCreateAllowedAttributeValuesAlreadyExists() {
// Create attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create namespace entity.
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
// Create attribute value list entity.
Collection<AllowedAttributeValueEntity> allowedAttributeValueEntities = new ArrayList<>();
AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
attributeValueListEntity.setNamespace(namespaceEntity);
attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
attributeValueListEntity.setAllowedAttributeValues(allowedAttributeValueEntities);
// Create allowed attribute value entity.
AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
allowedAttributeValueEntity.setAllowedAttributeValue(ALLOWED_ATTRIBUTE_VALUE);
allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
allowedAttributeValueEntities.add(allowedAttributeValueEntity);
// Mock calls to external method.
when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE);
// Try to call method under test.
try {
allowedAttributeValueService.createAllowedAttributeValues(new AllowedAttributeValuesCreateRequest(attributeValueListKey, Arrays.asList(ALLOWED_ATTRIBUTE_VALUE)));
fail();
} catch (AlreadyExistsException e) {
assertEquals(String.format("Allowed attribute value \"%s\" already exists in \"%s\" attribute value list.", ALLOWED_ATTRIBUTE_VALUE, attributeValueListEntity.getName()), e.getMessage());
}
// Verify the external calls.
verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
verify(alternateKeyHelper).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE);
verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.api.xml.AttributeValueListKey in project herd by FINRAOS.
the class AttributeValueListServiceImpl method createAttributeValueList.
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public AttributeValueList createAttributeValueList(AttributeValueListCreateRequest request) {
// Validate and trim the request parameters.
attributeValueListHelper.validateAttributeValueListCreateRequest(request);
// Get the attribute value list key.
AttributeValueListKey attributeValueListKey = request.getAttributeValueListKey();
// Retrieve the namespace entity and validate it exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getAttributeValueListKey().getNamespace());
// Validate the attribute value list does not already exist.
if (attributeValueListDao.getAttributeValueListByKey(request.getAttributeValueListKey()) != null) {
throw new AlreadyExistsException(String.format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace()));
}
// Create and persist a new attribute value list entity from the request information.
AttributeValueListEntity attributeValueListEntity = createAttributeValueListEntity(request, namespaceEntity);
// Create and return the attribute value list object from the persisted entity.
return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity);
}
use of org.finra.herd.model.api.xml.AttributeValueListKey in project herd by FINRAOS.
the class AllowedAttributeValueServiceImpl method createAllowedAttributeValuesInformationFromEntities.
/**
* Creates the allowed attribute values information from the persisted entities.
*
* @param attributeValueListEntity the attribute value list entity
* @param allowedAttributeValueEntities the list of allowed attribute value entities
*
* @return the allowed attribute values information
*/
private AllowedAttributeValuesInformation createAllowedAttributeValuesInformationFromEntities(AttributeValueListEntity attributeValueListEntity, Collection<AllowedAttributeValueEntity> allowedAttributeValueEntities) {
// Create an allowed attribute values information instance.
AllowedAttributeValuesInformation allowedAttributeValuesInformation = new AllowedAttributeValuesInformation();
// Add the attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey();
allowedAttributeValuesInformation.setAttributeValueListKey(attributeValueListKey);
attributeValueListKey.setNamespace(attributeValueListEntity.getNamespace().getCode());
attributeValueListKey.setAttributeValueListName(attributeValueListEntity.getName());
// Add the allowed attribute values.
List<String> allowedAttributeValues = new ArrayList<>();
allowedAttributeValuesInformation.setAllowedAttributeValues(allowedAttributeValues);
allowedAttributeValueEntities.forEach(allowedAttributeValueEntity -> {
allowedAttributeValues.add(allowedAttributeValueEntity.getAllowedAttributeValue());
});
return allowedAttributeValuesInformation;
}
use of org.finra.herd.model.api.xml.AttributeValueListKey in project herd by FINRAOS.
the class AttributeValueListServiceTest method createAttributeValueListAlreadyExists.
@Test
public void createAttributeValueListAlreadyExists() {
// Create an attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create an attribute value list create request.
AttributeValueListCreateRequest request = new AttributeValueListCreateRequest(attributeValueListKey);
// Mock calls to external methods.
when(namespaceDaoHelper.getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(new NamespaceEntity());
when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(new AttributeValueListEntity());
// Try to call the method under test.
try {
attributeValueListService.createAttributeValueList(request);
fail();
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", ATTRIBUTE_VALUE_LIST_NAME, ATTRIBUTE_VALUE_LIST_NAMESPACE), e.getMessage());
}
// Verify the external calls.
verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request);
verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE);
verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
verifyNoMoreInteractionsHelper();
}
Aggregations