Search in sources :

Example 11 with BusinessObjectDefinitionColumnEntity

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

the class BusinessObjectDefinitionColumnDaoImpl method getBusinessObjectDefinitionColumnByKey.

@Override
public BusinessObjectDefinitionColumnEntity getBusinessObjectDefinitionColumnByKey(BusinessObjectDefinitionColumnKey businessObjectDefinitionColumnKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionColumnEntity> criteria = builder.createQuery(BusinessObjectDefinitionColumnEntity.class);
    // The criteria root is the business object definition column.
    Root<BusinessObjectDefinitionColumnEntity> businessObjectDefinitionColumnEntityRoot = criteria.from(BusinessObjectDefinitionColumnEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionColumnEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectDefinitionColumnEntityRoot.join(BusinessObjectDefinitionColumnEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDefinitionColumnKey.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionColumnKey.getBusinessObjectDefinitionName().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionColumnEntityRoot.get(BusinessObjectDefinitionColumnEntity_.name)), businessObjectDefinitionColumnKey.getBusinessObjectDefinitionColumnName().toUpperCase()));
    // Add the clauses for the query.
    criteria.select(businessObjectDefinitionColumnEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    return executeSingleResultQuery(criteria, String.format("Found more than one business object definition column instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " businessObjectDefinitionColumnName=\"%s\"}.", businessObjectDefinitionColumnKey.getNamespace(), businessObjectDefinitionColumnKey.getBusinessObjectDefinitionName(), businessObjectDefinitionColumnKey.getBusinessObjectDefinitionColumnName()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 12 with BusinessObjectDefinitionColumnEntity

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

the class BusinessObjectDefinitionColumnDaoImpl method getBusinessObjectDefinitionColumnByBusinessObjectDefinitionColumnName.

@Override
public BusinessObjectDefinitionColumnEntity getBusinessObjectDefinitionColumnByBusinessObjectDefinitionColumnName(BusinessObjectDefinitionEntity businessObjectDefinitionEntity, String businessObjectDefinitionColumnName) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionColumnEntity> criteria = builder.createQuery(BusinessObjectDefinitionColumnEntity.class);
    // The criteria root is the business object definition column.
    Root<BusinessObjectDefinitionColumnEntity> businessObjectDefinitionColumnEntityRoot = criteria.from(BusinessObjectDefinitionColumnEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(businessObjectDefinitionColumnEntityRoot.get(BusinessObjectDefinitionColumnEntity_.businessObjectDefinition), businessObjectDefinitionEntity));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionColumnEntityRoot.get(BusinessObjectDefinitionColumnEntity_.name)), businessObjectDefinitionColumnName.toUpperCase()));
    // Add the clauses for the query.
    criteria.select(businessObjectDefinitionColumnEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    return executeSingleResultQuery(criteria, String.format("Found more than one business object definition column instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " businessObjectDefinitionColumnName=\"%s\"}.", businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName(), businessObjectDefinitionColumnName));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 13 with BusinessObjectDefinitionColumnEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity 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 14 with BusinessObjectDefinitionColumnEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity 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 15 with BusinessObjectDefinitionColumnEntity

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

the class BusinessObjectDefinitionColumnServiceImpl method updateBusinessObjectDefinitionColumn.

@NamespacePermission(fields = "#businessObjectDefinitionColumnKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionColumn updateBusinessObjectDefinitionColumn(BusinessObjectDefinitionColumnKey businessObjectDefinitionColumnKey, BusinessObjectDefinitionColumnUpdateRequest request) {
    // Validate and trim the business object definition column key.
    validateBusinessObjectDefinitionColumnKey(businessObjectDefinitionColumnKey);
    // Validate and trim the business object definition column update request.
    validateBusinessObjectDefinitionColumnUpdateRequest(request);
    // Retrieve and ensure that a business object definition column exists with the business object definition.
    BusinessObjectDefinitionColumnEntity businessObjectDefinitionColumnEntity = businessObjectDefinitionColumnDaoHelper.getBusinessObjectDefinitionColumnEntity(businessObjectDefinitionColumnKey);
    // Update the entity with the new values.
    businessObjectDefinitionColumnEntity.setDescription(request.getDescription());
    // Persist the change event entity
    businessObjectDefinitionColumnDaoHelper.saveBusinessObjectDefinitionColumnChangeEvents(businessObjectDefinitionColumnEntity);
    // Persist the entity.
    businessObjectDefinitionColumnEntity = businessObjectDefinitionColumnDao.saveAndRefresh(businessObjectDefinitionColumnEntity);
    // Notify the search index that a business object definition must be updated.
    searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionColumnEntity.getBusinessObjectDefinition(), 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 : BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Aggregations

BusinessObjectDefinitionColumnEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity)29 BusinessObjectDefinitionColumnKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey)20 Test (org.junit.Test)19 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)18 BusinessObjectDefinitionColumn (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumn)16 BusinessObjectDefinitionColumnUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnUpdateRequest)6 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)5 BusinessObjectDefinitionColumnCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnCreateRequest)4 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)3 BusinessObjectDefinitionColumnChangeEvent (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnChangeEvent)3 SchemaColumnEntity (org.finra.herd.model.jpa.SchemaColumnEntity)3 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 BusinessObjectDefinitionColumnKeys (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKeys)1 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1