use of org.finra.herd.model.jpa.DataProviderEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoHelper method createBusinessObjectDefinitionEntity.
/**
* Create Business Object Definition Entity
* @param request business object definition create request
* @return Business Object Definition Entity
*/
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(BusinessObjectDefinitionCreateRequest request) {
// Perform the validation.
validateBusinessObjectDefinitionCreateRequest(request);
// Get the namespace and ensure it exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
// Get the data provider and ensure it exists.
DataProviderEntity dataProviderEntity = dataProviderDaoHelper.getDataProviderEntity(request.getDataProviderName());
// Get business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(request.getNamespace(), request.getBusinessObjectDefinitionName());
// Ensure a business object definition with the specified key doesn't already exist.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
if (businessObjectDefinitionEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace()));
}
// Create a new entity.
businessObjectDefinitionEntity = new BusinessObjectDefinitionEntity();
businessObjectDefinitionEntity.setNamespace(namespaceEntity);
businessObjectDefinitionEntity.setName(request.getBusinessObjectDefinitionName());
businessObjectDefinitionEntity.setDescription(request.getDescription());
businessObjectDefinitionEntity.setDataProvider(dataProviderEntity);
businessObjectDefinitionEntity.setDisplayName(request.getDisplayName());
// Create the attributes if they are specified.
if (!CollectionUtils.isEmpty(request.getAttributes())) {
List<BusinessObjectDefinitionAttributeEntity> attributeEntities = new ArrayList<>();
businessObjectDefinitionEntity.setAttributes(attributeEntities);
for (Attribute attribute : request.getAttributes()) {
BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
attributeEntities.add(attributeEntity);
attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
attributeEntity.setName(attribute.getName());
attributeEntity.setValue(attribute.getValue());
}
}
// Persist the change event entity
saveBusinessObjectDefinitionChangeEvents(businessObjectDefinitionEntity);
// Persist and return the new entity.
return businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
use of org.finra.herd.model.jpa.DataProviderEntity in project herd by FINRAOS.
the class DataProviderServiceImpl method deleteDataProvider.
@Override
public DataProvider deleteDataProvider(DataProviderKey dataProviderKey) {
// Perform validation and trim.
validateDataProviderKey(dataProviderKey);
// Retrieve and ensure that a data provider already exists with the specified key.
DataProviderEntity dataProviderEntity = dataProviderDaoHelper.getDataProviderEntity(dataProviderKey.getDataProviderName());
// Delete the data provider.
dataProviderDao.delete(dataProviderEntity);
// Create and return the data provider object from the deleted entity.
return createDataProviderFromEntity(dataProviderEntity);
}
use of org.finra.herd.model.jpa.DataProviderEntity 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.jpa.DataProviderEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceTestHelper method createBusinessObjectFormat.
/**
* Creates and persists {@link org.finra.herd.model.jpa.BusinessObjectFormatEntity} from the given request. Also creates and persists namespace, data
* provider, bdef, and file type required for the format. If the request has sub-partitions, schema columns will be persisted. Otherwise, no schema will be
* set for this format.
*
* @param request {@link org.finra.herd.model.api.xml.BusinessObjectDataInvalidateUnregisteredRequest} format alt key
*
* @return created {@link org.finra.herd.model.jpa.BusinessObjectFormatEntity}
*/
public BusinessObjectFormatEntity createBusinessObjectFormat(BusinessObjectDataInvalidateUnregisteredRequest request) {
// Create namespace
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(request.getNamespace());
// Create data provider with a name which is irrelevant for the test cases
DataProviderEntity dataProviderEntity = dataProviderDaoTestHelper.createDataProviderEntity(AbstractServiceTest.DATA_PROVIDER_NAME);
// Create business object definition
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(namespaceEntity, request.getBusinessObjectDefinitionName(), dataProviderEntity, AbstractServiceTest.NO_BDEF_DESCRIPTION, AbstractServiceTest.NO_BDEF_DISPLAY_NAME, AbstractServiceTest.NO_ATTRIBUTES, AbstractServiceTest.NO_SAMPLE_DATA_FILES);
// Create file type
FileTypeEntity fileTypeEntity = fileTypeDaoTestHelper.createFileTypeEntity(request.getBusinessObjectFormatFileType());
// Manually creating format since it is easier than providing large amounts of params to existing method
// Create format
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectFormatEntity.setUsage(request.getBusinessObjectFormatUsage());
businessObjectFormatEntity.setFileType(fileTypeEntity);
businessObjectFormatEntity.setBusinessObjectFormatVersion(request.getBusinessObjectFormatVersion());
// If sub-partition values exist in the request
if (!CollectionUtils.isEmpty(request.getSubPartitionValues())) {
// Create schema columns
List<SchemaColumnEntity> schemaColumnEntities = new ArrayList<>();
for (int partitionLevel = 0; partitionLevel < request.getSubPartitionValues().size() + 1; partitionLevel++) {
SchemaColumnEntity schemaColumnEntity = new SchemaColumnEntity();
schemaColumnEntity.setBusinessObjectFormat(businessObjectFormatEntity);
schemaColumnEntity.setName(AbstractServiceTest.PARTITION_KEY + partitionLevel);
schemaColumnEntity.setType("STRING");
schemaColumnEntity.setPartitionLevel(partitionLevel);
schemaColumnEntity.setPosition(partitionLevel);
schemaColumnEntities.add(schemaColumnEntity);
}
businessObjectFormatEntity.setSchemaColumns(schemaColumnEntities);
businessObjectFormatEntity.setPartitionKey(AbstractServiceTest.PARTITION_KEY + "0");
} else // If sub-partition values do not exist in the request
{
businessObjectFormatEntity.setPartitionKey(AbstractServiceTest.PARTITION_KEY);
}
businessObjectFormatEntity.setLatestVersion(true);
businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
return businessObjectFormatEntity;
}
use of org.finra.herd.model.jpa.DataProviderEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoTestHelper method createBusinessObjectDefinitionEntity.
/**
* Creates and persists a new business object definition entity.
*
* @return the newly created business object definition entity
*/
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(String namespaceCode, String businessObjectDefinitionName, String dataProviderName, String businessObjectDefinitionDescription, String displayName, List<Attribute> attributes, List<SampleDataFile> sampleDataFiles) {
// Create a namespace entity if needed.
NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespaceCode);
if (namespaceEntity == null) {
namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(namespaceCode);
}
// Create a data provider entity if needed.
DataProviderEntity dataProviderEntity = dataProviderDao.getDataProviderByName(dataProviderName);
if (dataProviderEntity == null) {
dataProviderEntity = dataProviderDaoTestHelper.createDataProviderEntity(dataProviderName);
}
return createBusinessObjectDefinitionEntity(namespaceEntity, businessObjectDefinitionName, dataProviderEntity, businessObjectDefinitionDescription, displayName, attributes, sampleDataFiles);
}
Aggregations