Search in sources :

Example 1 with DataProviderEntity

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);
}
Also used : BusinessObjectDefinitionAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ArrayList(java.util.ArrayList)

Example 2 with DataProviderEntity

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);
}
Also used : DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity)

Example 3 with 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);
}
Also used : DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey)

Example 4 with 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;
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Example 5 with DataProviderEntity

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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity)

Aggregations

DataProviderEntity (org.finra.herd.model.jpa.DataProviderEntity)15 ArrayList (java.util.ArrayList)6 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)6 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)5 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)4 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)4 DataProviderKey (org.finra.herd.model.api.xml.DataProviderKey)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)2 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)2 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)2 StorageEntity (org.finra.herd.model.jpa.StorageEntity)2 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)2 Test (org.junit.Test)2 Predicate (javax.persistence.criteria.Predicate)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)1 BusinessObjectDefinitionAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity)1 SchemaColumnEntity (org.finra.herd.model.jpa.SchemaColumnEntity)1