Search in sources :

Example 6 with GlobalAttributeDefinitionLevelEntity

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

the class GlobalAttributeDefinitionDaoImpl method getGlobalAttributeDefinitionByKey.

@Override
public GlobalAttributeDefinitionEntity getGlobalAttributeDefinitionByKey(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<GlobalAttributeDefinitionEntity> criteria = builder.createQuery(GlobalAttributeDefinitionEntity.class);
    // The criteria root is the global attribute definition entity.
    Root<GlobalAttributeDefinitionEntity> globalAttributeDefinitionEntityRoot = criteria.from(GlobalAttributeDefinitionEntity.class);
    // Join on the other tables that we filter on
    Join<GlobalAttributeDefinitionEntity, GlobalAttributeDefinitionLevelEntity> globalAttributeDefinitionLevelEntityJoin = globalAttributeDefinitionEntityRoot.join(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionLevel);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(globalAttributeDefinitionLevelEntityJoin.get(GlobalAttributeDefinitionLevelEntity_.globalAttributeDefinitionLevel)), globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel().toUpperCase()));
    predicates.add(builder.equal(builder.upper(globalAttributeDefinitionEntityRoot.get(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionName)), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName().toUpperCase()));
    // Add all clauses to the query.
    criteria.select(globalAttributeDefinitionEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    return executeSingleResultQuery(criteria, String.format("Found more than one global attribute definition with parameters {globalAttributeDefinitionLevel=\"%s\", globalAttributeDefinitionLevel=\"%s\"}.", globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel(), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 7 with GlobalAttributeDefinitionLevelEntity

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

the class GlobalAttributeDefinitionLevelDaoImpl method getGlobalAttributeDefinitionLevel.

@Override
public GlobalAttributeDefinitionLevelEntity getGlobalAttributeDefinitionLevel(String code) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<GlobalAttributeDefinitionLevelEntity> criteria = builder.createQuery(GlobalAttributeDefinitionLevelEntity.class);
    // The criteria root is the global attribute definition level
    Root<GlobalAttributeDefinitionLevelEntity> globalAttributeDefinitionLevelEntityRoot = criteria.from(GlobalAttributeDefinitionLevelEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate predicate = builder.equal(builder.upper(globalAttributeDefinitionLevelEntityRoot.get(GlobalAttributeDefinitionLevelEntity_.globalAttributeDefinitionLevel)), code.toUpperCase());
    // Add all clauses to the query.
    criteria.select(globalAttributeDefinitionLevelEntityRoot).where(predicate);
    // Execute the query and return the result.
    return executeSingleResultQuery(criteria, String.format("Found more than one global attribute definition level with code \"%s\".", code));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) Predicate(javax.persistence.criteria.Predicate)

Example 8 with GlobalAttributeDefinitionLevelEntity

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

the class GlobalAttributeDefinitionServiceImpl method createGlobalAttributeDefinition.

@Override
public GlobalAttributeDefinition createGlobalAttributeDefinition(GlobalAttributeDefinitionCreateRequest request) {
    // Validate and trim the request parameters.
    validateGlobalAttributeDefinitionCreateRequest(request);
    // Validate the global Attribute Definition entity does not already exist in the database.
    globalAttributeDefinitionDaoHelper.validateGlobalAttributeDefinitionNoExists(request.getGlobalAttributeDefinitionKey());
    // Get the existing global Attribute Definition level entity
    GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(request.getGlobalAttributeDefinitionKey().getGlobalAttributeDefinitionLevel());
    AttributeValueListEntity attributeValueListEntity = null;
    // Get the attribute value list if the attribute value key exists
    if (request.getAttributeValueListKey() != null) {
        // Get the existing attribute list and ensure it exists
        attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
    }
    // Create and persist a new global Attribute Definition entity from the request information.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = createGlobalAttributeDefinitionEntity(request.getGlobalAttributeDefinitionKey(), globalAttributeDefinitionLevelEntity, attributeValueListEntity);
    // Create and return the global Attribute Definition object from the persisted entity.
    return createGlobalAttributeDefinitionFromEntity(globalAttributeDefinitionEntity);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity)

Aggregations

GlobalAttributeDefinitionLevelEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)8 GlobalAttributeDefinitionEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ArrayList (java.util.ArrayList)2 Predicate (javax.persistence.criteria.Predicate)2 GlobalAttributeDefinitionKey (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)2 Test (org.junit.Test)2 Tuple (javax.persistence.Tuple)1 GlobalAttributeDefinition (org.finra.herd.model.api.xml.GlobalAttributeDefinition)1 GlobalAttributeDefinitionCreateRequest (org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest)1 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)1