Search in sources :

Example 11 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class BusinessObjectDefinitionSubjectMatterExpertServiceImpl method createBusinessObjectDefinitionSubjectMatterExpert.

@NamespacePermission(fields = "#request.businessObjectDefinitionSubjectMatterExpertKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionSubjectMatterExpert createBusinessObjectDefinitionSubjectMatterExpert(BusinessObjectDefinitionSubjectMatterExpertCreateRequest request) {
    // Validate and trim the business object definition subject matter expert create request.
    validateBusinessObjectDefinitionSubjectMatterExpertCreateRequest(request);
    // Get the business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(request.getBusinessObjectDefinitionSubjectMatterExpertKey().getNamespace(), request.getBusinessObjectDefinitionSubjectMatterExpertKey().getBusinessObjectDefinitionName());
    // Get the business object definition and ensure it exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    // Ensure a business object definition subject matter expert with the specified name doesn't already exist for the business object definition.
    if (businessObjectDefinitionSubjectMatterExpertDao.getBusinessObjectDefinitionSubjectMatterExpert(businessObjectDefinitionEntity, request.getBusinessObjectDefinitionSubjectMatterExpertKey().getUserId()) != null) {
        throw new AlreadyExistsException(String.format("Unable to create business object definition subject matter expert with user id \"%s\" " + "because it already exists for the business object definition {%s}.", request.getBusinessObjectDefinitionSubjectMatterExpertKey().getUserId(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
    }
    // Create a business object definition subject matter expert entity from the request information.
    BusinessObjectDefinitionSubjectMatterExpertEntity businessObjectDefinitionSubjectMatterExpertEntity = createBusinessObjectDefinitionSubjectMatterExpertEntity(businessObjectDefinitionEntity, request);
    // Persist the new entity.
    businessObjectDefinitionSubjectMatterExpertEntity = businessObjectDefinitionSubjectMatterExpertDao.saveAndRefresh(businessObjectDefinitionSubjectMatterExpertEntity);
    // Notify the search index that a business object definition must be updated.
    searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
    // Create and return the business object definition subject matter expert object from the persisted entity.
    return createBusinessObjectDefinitionSubjectMatterExpertFromEntity(businessObjectDefinitionSubjectMatterExpertEntity);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionSubjectMatterExpertEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionSubjectMatterExpertEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 12 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException 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 13 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class DataProviderServiceImpl method createDataProvider.

@Override
public DataProvider createDataProvider(DataProviderCreateRequest request) {
    // Perform the validation.
    validateDataProviderCreateRequest(request);
    // Get the data provider key.
    DataProviderKey dataProviderKey = new DataProviderKey(request.getDataProviderName());
    // Ensure a data provider with the specified data provider key doesn't already exist.
    DataProviderEntity dataProviderEntity = dataProviderDao.getDataProviderByKey(dataProviderKey);
    if (dataProviderEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create data provider \"%s\" because it already exists.", dataProviderKey.getDataProviderName()));
    }
    // Create a data provider entity from the request information.
    dataProviderEntity = createDataProviderEntity(request);
    // Persist the new entity.
    dataProviderEntity = dataProviderDao.saveAndRefresh(dataProviderEntity);
    // Create and return the data provider object from the persisted entity.
    return createDataProviderFromEntity(dataProviderEntity);
}
Also used : DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey)

Example 14 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class BusinessObjectDataAttributeServiceImpl method createBusinessObjectDataAttributeImpl.

/**
 * Creates a new business object data attribute.
 *
 * @param request the information needed to create a business object data attribute
 *
 * @return the newly created business object data attribute
 */
protected BusinessObjectDataAttribute createBusinessObjectDataAttributeImpl(BusinessObjectDataAttributeCreateRequest request) {
    // Validate and trim the key.
    businessObjectDataAttributeHelper.validateBusinessObjectDataAttributeKey(request.getBusinessObjectDataAttributeKey());
    // Get the business object format and ensure it exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion()));
    // Validate the attribute value.
    if (businessObjectDataAttributeHelper.isBusinessObjectDataAttributeRequired(request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectFormatEntity)) {
        Assert.hasText(request.getBusinessObjectDataAttributeValue(), String.format("A business object data attribute value must be specified since \"%s\" is a required attribute for business object format {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
    }
    // Get the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(new BusinessObjectDataKey(request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion(), request.getBusinessObjectDataAttributeKey().getPartitionValue(), request.getBusinessObjectDataAttributeKey().getSubPartitionValues(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDataVersion()));
    // Load all existing business object data attribute entities into a map for quick access using lowercase attribute names.
    Map<String, BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntityMap = businessObjectDataAttributeDaoHelper.getBusinessObjectDataAttributeEntityMap(businessObjectDataEntity.getAttributes());
    // Ensure a business object data attribute with the specified name doesn't already exist for the specified business object data.
    if (businessObjectDataAttributeEntityMap.containsKey(request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName().toLowerCase())) {
        throw new AlreadyExistsException(String.format("Unable to create business object data attribute with name \"%s\" because it already exists for the business object data {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
    }
    // Create a business object data attribute entity from the request information.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = createBusinessObjectDataAttributeEntity(businessObjectDataEntity, request);
    // Persist the new entity.
    businessObjectDataAttributeEntity = businessObjectDataAttributeDao.saveAndRefresh(businessObjectDataAttributeEntity);
    // Create and return the business object data attribute object from the persisted entity.
    return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity);
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 15 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceTest method testCreateBusinessObjectDefinitionAlreadyExists.

@Test
public void testCreateBusinessObjectDefinitionAlreadyExists() throws Exception {
    // Create and persist a business object definition.
    businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, null);
    // Try to create a business object definition when it already exists.
    try {
        businessObjectDefinitionService.createBusinessObjectDefinition(new BusinessObjectDefinitionCreateRequest(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, NO_ATTRIBUTES));
        fail("Should throw an AlreadyExistsException when business object definition already exists.");
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", BDEF_NAME, NAMESPACE), e.getMessage());
    }
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest) Test(org.junit.Test)

Aggregations

AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)62 Test (org.junit.Test)35 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)12 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)11 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)9 ArrayList (java.util.ArrayList)7 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)7 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)6 StorageEntity (org.finra.herd.model.jpa.StorageEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)5 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)5 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)4 StorageFile (org.finra.herd.model.api.xml.StorageFile)4 TagKey (org.finra.herd.model.api.xml.TagKey)4 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)3 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)3 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)3 RelationalTableRegistrationCreateRequest (org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest)3 TagTypeKey (org.finra.herd.model.api.xml.TagTypeKey)3