Search in sources :

Example 11 with SchemaColumnEntity

use of org.finra.herd.model.jpa.SchemaColumnEntity in project herd by FINRAOS.

the class Hive13DdlGeneratorTest method testGenerateReplaceColumnsStatementAssertionErrorIfColumnsEmpty.

/**
 * Asserts that generateReplaceColumnsStatement() throws an IllegalArgumentException when the format entity only specified partitions, but no columns.
 */
@Test
public void testGenerateReplaceColumnsStatementAssertionErrorIfColumnsEmpty() {
    BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = new BusinessObjectFormatDdlRequest();
    businessObjectFormatDdlRequest.setTableName(TABLE_NAME);
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
    {
        SchemaColumnEntity schemaColumnEntity = new SchemaColumnEntity();
        schemaColumnEntity.setPartitionLevel(0);
        schemaColumnEntity.setName("col1");
        schemaColumnEntity.setType("date");
        businessObjectFormatEntity.getSchemaColumns().add(schemaColumnEntity);
    }
    try {
        hive13DdlGenerator.generateReplaceColumnsStatement(businessObjectFormatDdlRequest, businessObjectFormatEntity);
        Assert.fail("expected IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "No schema columns specified for business object format {namespace: \"" + NAMESPACE + "\", businessObjectDefinitionName: \"" + BDEF_NAME + "\", businessObjectFormatUsage: \"" + FORMAT_USAGE_CODE + "\", businessObjectFormatFileType: \"" + FORMAT_FILE_TYPE_CODE + "\", businessObjectFormatVersion: " + FORMAT_VERSION + "}.", e.getMessage());
    }
}
Also used : SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 12 with SchemaColumnEntity

use of org.finra.herd.model.jpa.SchemaColumnEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionColumnServiceImpl method deleteBusinessObjectDefinitionColumn.

@NamespacePermission(fields = "#businessObjectDefinitionColumnKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionColumn deleteBusinessObjectDefinitionColumn(BusinessObjectDefinitionColumnKey businessObjectDefinitionColumnKey) {
    // Validate and trim the business object definition column key.
    validateBusinessObjectDefinitionColumnKey(businessObjectDefinitionColumnKey);
    // Retrieve and ensure that a business object definition column exists with the business object definition.
    BusinessObjectDefinitionColumnEntity businessObjectDefinitionColumnEntity = businessObjectDefinitionColumnDaoHelper.getBusinessObjectDefinitionColumnEntity(businessObjectDefinitionColumnKey);
    // Unlink schema columns from the business object definition column.
    for (SchemaColumnEntity schemaColumnEntity : businessObjectDefinitionColumnEntity.getSchemaColumns()) {
        schemaColumnEntity.setBusinessObjectDefinitionColumn(null);
    }
    // Delete the business object definition column.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionColumnEntity.getBusinessObjectDefinition();
    businessObjectDefinitionEntity.getColumns().remove(businessObjectDefinitionColumnEntity);
    businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
    // 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 column object from the deleted entity.
    return createBusinessObjectDefinitionColumnFromEntity(businessObjectDefinitionColumnEntity, true, getValidSearchResponseFields(), false);
}
Also used : SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 13 with SchemaColumnEntity

use of org.finra.herd.model.jpa.SchemaColumnEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionColumnServiceImpl method createBusinessObjectDefinitionColumn.

@NamespacePermission(fields = "#request.businessObjectDefinitionColumnKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionColumn createBusinessObjectDefinitionColumn(BusinessObjectDefinitionColumnCreateRequest request) {
    // Validate and trim the business object definition column create request.
    validateBusinessObjectDefinitionColumnCreateRequest(request);
    // Get the business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = businessObjectDefinitionHelper.getBusinessObjectDefinitionKey(request.getBusinessObjectDefinitionColumnKey());
    // Get the business object definition and ensure it exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    // Ensure a business object definition column with the specified name doesn't already exist for the business object definition.
    if (businessObjectDefinitionColumnDao.getBusinessObjectDefinitionColumnByBusinessObjectDefinitionColumnName(businessObjectDefinitionEntity, request.getBusinessObjectDefinitionColumnKey().getBusinessObjectDefinitionColumnName()) != null) {
        throw new AlreadyExistsException(String.format("Unable to create business object definition column with name \"%s\" because it already exists for the business object definition {%s}.", request.getBusinessObjectDefinitionColumnKey().getBusinessObjectDefinitionColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
    }
    // Retrieve schema column entities from all format instances for the business object definition that match the specified schema column name.
    Collection<SchemaColumnEntity> schemaColumnEntities = schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, request.getSchemaColumnName());
    // Ensure that exists at least one schema column that matches the specified schema column name.
    if (CollectionUtils.isEmpty(schemaColumnEntities)) {
        if (businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat() == null) {
            throw new ObjectNotFoundException(String.format("Unable to create business object definition column because there are no format schema " + "columns with name \"%s\" for the business object definition {%s}.", request.getSchemaColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
        } else {
            throw new ObjectNotFoundException(String.format("Unable to create business object definition column because there are no format schema " + "columns with name \"%s\" in the descriptive business object format for the business object definition {%s}.", request.getSchemaColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
        }
    }
    // Ensure a business object definition column with the specified schema column name doesn't already exist for this business object definition.
    for (SchemaColumnEntity schemaColumnEntity : schemaColumnEntities) {
        if (schemaColumnEntity.getBusinessObjectDefinitionColumn() != null) {
            throw new AlreadyExistsException(String.format("Unable to create business object definition column because a business object definition column " + "with schema column name \"%s\" already exists for the business object definition {%s}.", request.getSchemaColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
        }
    }
    // Create a business object definition column entity from the request information.
    BusinessObjectDefinitionColumnEntity businessObjectDefinitionColumnEntity = createBusinessObjectDefinitionColumnEntity(businessObjectDefinitionEntity, request);
    // Link schema columns with the business object definition column.
    for (SchemaColumnEntity schemaColumnEntity : schemaColumnEntities) {
        schemaColumnEntity.setBusinessObjectDefinitionColumn(businessObjectDefinitionColumnEntity);
    }
    // Persist the change event entity
    businessObjectDefinitionColumnDaoHelper.saveBusinessObjectDefinitionColumnChangeEvents(businessObjectDefinitionColumnEntity);
    // Persist the new entity.
    businessObjectDefinitionColumnEntity = businessObjectDefinitionColumnDao.saveAndRefresh(businessObjectDefinitionColumnEntity);
    // 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 column object from the persisted entity.
    return createBusinessObjectDefinitionColumnFromEntity(businessObjectDefinitionColumnEntity, true, getValidSearchResponseFields(), false);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 14 with SchemaColumnEntity

use of org.finra.herd.model.jpa.SchemaColumnEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionColumnServiceTest method testCreateBusinessObjectDefinitionColumn.

@Test
public void testCreateBusinessObjectDefinitionColumn() {
    // Create and persist a business object format entity.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY);
    // Create and persist a schema column for this business object format.
    SchemaColumnEntity schemaColumnEntity = schemaColumnDaoTestHelper.createSchemaColumnEntity(businessObjectFormatEntity, COLUMN_NAME);
    // Create a business object definition column key.
    BusinessObjectDefinitionColumnKey businessObjectDefinitionColumnKey = new BusinessObjectDefinitionColumnKey(BDEF_NAMESPACE, BDEF_NAME, BDEF_COLUMN_NAME);
    // Create a business object definition column.
    businessObjectDefinitionColumnService.createBusinessObjectDefinitionColumn(new BusinessObjectDefinitionColumnCreateRequest(businessObjectDefinitionColumnKey, COLUMN_NAME, BDEF_COLUMN_DESCRIPTION));
    // Get the business object definition column entity.
    BusinessObjectDefinitionColumnEntity resultBusinessObjectDefinitionColumnEntity = businessObjectDefinitionColumnDaoHelper.getBusinessObjectDefinitionColumnEntity(businessObjectDefinitionColumnKey);
    // Get the business object definition column.
    BusinessObjectDefinitionColumn resultBusinessObjectDefinitionColumn = businessObjectDefinitionColumnService.getBusinessObjectDefinitionColumn(businessObjectDefinitionColumnKey, true);
    // Validate the returned object.
    assertEquals(new BusinessObjectDefinitionColumn(resultBusinessObjectDefinitionColumn.getId(), businessObjectDefinitionColumnKey, COLUMN_NAME, BDEF_COLUMN_DESCRIPTION, Lists.newArrayList(new BusinessObjectDefinitionColumnChangeEvent(BDEF_COLUMN_DESCRIPTION, resultBusinessObjectDefinitionColumn.getBusinessObjectDefinitionColumnChangeEvents().get(0).getEventTime(), resultBusinessObjectDefinitionColumnEntity.getCreatedBy()))), resultBusinessObjectDefinitionColumn);
    // Validate that the schema column is now linked with the business object definition column.
    assertEquals(Long.valueOf(resultBusinessObjectDefinitionColumn.getId()), Long.valueOf(schemaColumnEntity.getBusinessObjectDefinitionColumn().getId()));
}
Also used : SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) BusinessObjectDefinitionColumnCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnCreateRequest) BusinessObjectDefinitionColumnKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey) BusinessObjectDefinitionColumnChangeEvent(org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnChangeEvent) BusinessObjectDefinitionColumn(org.finra.herd.model.api.xml.BusinessObjectDefinitionColumn) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Test(org.junit.Test)

Aggregations

SchemaColumnEntity (org.finra.herd.model.jpa.SchemaColumnEntity)14 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)8 ArrayList (java.util.ArrayList)4 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)3 BusinessObjectDefinitionColumnEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity)3 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)3 Test (org.junit.Test)3 Predicate (javax.persistence.criteria.Predicate)2 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)2 Attribute (org.finra.herd.model.api.xml.Attribute)2 BusinessObjectFormatDdlRequest (org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest)2 BusinessObjectFormatAttributeEntity (org.finra.herd.model.jpa.BusinessObjectFormatAttributeEntity)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 AttributeDefinition (org.finra.herd.model.api.xml.AttributeDefinition)1 BusinessObjectDefinitionColumn (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumn)1