Search in sources :

Example 6 with AttributeValueListKey

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();
}
Also used : AllowedAttributeValuesCreateRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesCreateRequest) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 7 with AttributeValueListKey

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();
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AllowedAttributeValuesCreateRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesCreateRequest) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) ArrayList(java.util.ArrayList) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 8 with AttributeValueListKey

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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with AttributeValueListKey

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;
}
Also used : ArrayList(java.util.ArrayList) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) AllowedAttributeValuesInformation(org.finra.herd.model.api.xml.AllowedAttributeValuesInformation)

Example 10 with AttributeValueListKey

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();
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) AttributeValueListCreateRequest(org.finra.herd.model.api.xml.AttributeValueListCreateRequest) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Aggregations

AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)32 Test (org.junit.Test)27 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)14 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)11 AllowedAttributeValuesInformation (org.finra.herd.model.api.xml.AllowedAttributeValuesInformation)7 AttributeValueList (org.finra.herd.model.api.xml.AttributeValueList)7 AllowedAttributeValueEntity (org.finra.herd.model.jpa.AllowedAttributeValueEntity)7 ArrayList (java.util.ArrayList)6 AllowedAttributeValuesDeleteRequest (org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest)5 AllowedAttributeValuesCreateRequest (org.finra.herd.model.api.xml.AllowedAttributeValuesCreateRequest)4 AttributeValueListCreateRequest (org.finra.herd.model.api.xml.AttributeValueListCreateRequest)4 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)4 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 AttributeValueListKeys (org.finra.herd.model.api.xml.AttributeValueListKeys)2 HashSet (java.util.HashSet)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Order (javax.persistence.criteria.Order)1 Predicate (javax.persistence.criteria.Predicate)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1