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);
}
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);
}
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);
}
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);
}
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());
}
}
Aggregations