Search in sources :

Example 36 with FileTypeEntity

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

the class BusinessObjectFormatDaoImpl method getBusinessObjectFormatMaxVersion.

@Override
public Integer getBusinessObjectFormatMaxVersion(BusinessObjectFormatKey businessObjectFormatKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Integer> criteria = builder.createQuery(Integer.class);
    // The criteria root is the business object format.
    Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    // Create the standard restrictions (i.e. the standard where clauses).
    // Business object format version should be ignored when building the query restriction.
    Predicate queryRestriction = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity, businessObjectFormatKey, true);
    // Create the path.
    Expression<Integer> maxBusinessObjectFormatVersion = builder.max(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion));
    criteria.select(maxBusinessObjectFormatVersion).where(queryRestriction);
    return entityManager.createQuery(criteria).getSingleResult();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate)

Example 37 with FileTypeEntity

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

the class BusinessObjectFormatDaoImpl method getBusinessObjectFormatsWithFilters.

@Override
public List<BusinessObjectFormatKey> getBusinessObjectFormatsWithFilters(BusinessObjectDefinitionKey businessObjectDefinitionKey, String businessObjectFormatUsage, boolean latestBusinessObjectFormatVersion) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the business object format.
    Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name);
    Path<String> businessObjectFormatUsageColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage);
    Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code);
    Path<Integer> businessObjectFormatVersionColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion);
    Expression<Integer> maxBusinessObjectFormatVersionExpression = builder.max(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion));
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectDefinitionKey.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase()));
    // Add the business object format usage where parameter is not empty
    if (StringUtils.isNotEmpty(businessObjectFormatUsage)) {
        queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatUsage.toUpperCase()));
    }
    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, businessObjectFormatUsageColumn, fileTypeCodeColumn, latestBusinessObjectFormatVersion ? maxBusinessObjectFormatVersionExpression : businessObjectFormatVersionColumn);
    // Add the where clause.
    criteria.where(queryRestriction);
    // If only the latest (maximum) business object format versions to be returned, create and apply the group by clause.
    if (latestBusinessObjectFormatVersion) {
        List<Expression<?>> grouping = new ArrayList<>();
        grouping.add(namespaceCodeColumn);
        grouping.add(businessObjectDefinitionNameColumn);
        grouping.add(businessObjectFormatUsageColumn);
        grouping.add(fileTypeCodeColumn);
        criteria.groupBy(grouping);
    }
    // Add the order by clause.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(businessObjectFormatUsageColumn));
    orderBy.add(builder.asc(fileTypeCodeColumn));
    if (!latestBusinessObjectFormatVersion) {
        orderBy.add(builder.asc(businessObjectFormatVersionColumn));
    }
    criteria.orderBy(orderBy);
    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectFormatKey> businessObjectFormatKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey();
        businessObjectFormatKeys.add(businessObjectFormatKey);
        businessObjectFormatKey.setNamespace(tuple.get(namespaceCodeColumn));
        businessObjectFormatKey.setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn));
        businessObjectFormatKey.setBusinessObjectFormatUsage(tuple.get(businessObjectFormatUsageColumn));
        businessObjectFormatKey.setBusinessObjectFormatFileType(tuple.get(fileTypeCodeColumn));
        businessObjectFormatKey.setBusinessObjectFormatVersion(tuple.get(latestBusinessObjectFormatVersion ? maxBusinessObjectFormatVersionExpression : businessObjectFormatVersionColumn));
    }
    return businessObjectFormatKeys;
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) Expression(javax.persistence.criteria.Expression) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) Tuple(javax.persistence.Tuple)

Example 38 with FileTypeEntity

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

the class CustomDdlDaoImpl method getCustomDdlByKey.

@Override
public CustomDdlEntity getCustomDdlByKey(CustomDdlKey customDdlKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CustomDdlEntity> criteria = builder.createQuery(CustomDdlEntity.class);
    // The criteria root is the custom DDL.
    Root<CustomDdlEntity> customDdlEntity = criteria.from(CustomDdlEntity.class);
    // Join to the other tables we can filter on.
    Join<CustomDdlEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = customDdlEntity.join(CustomDdlEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), customDdlKey.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), customDdlKey.getBusinessObjectDefinitionName().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), customDdlKey.getBusinessObjectFormatUsage().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), customDdlKey.getBusinessObjectFormatFileType().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), customDdlKey.getBusinessObjectFormatVersion()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(customDdlEntity.get(CustomDdlEntity_.customDdlName)), customDdlKey.getCustomDdlName().toUpperCase()));
    // Add select and where clauses.
    criteria.select(customDdlEntity).where(queryRestriction);
    return executeSingleResultQuery(criteria, String.format("Found more than one custom DDL instance with parameters {businessObjectDefinitionName=\"%s\"," + " businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", businessObjectFormatVersion=\"%d\", customDdlName=\"%s\"}.", customDdlKey.getBusinessObjectDefinitionName(), customDdlKey.getBusinessObjectFormatUsage(), customDdlKey.getBusinessObjectFormatFileType(), customDdlKey.getBusinessObjectFormatVersion(), customDdlKey.getCustomDdlName()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)

Example 39 with FileTypeEntity

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

the class CustomDdlDaoImpl method getCustomDdls.

@Override
public List<CustomDdlKey> getCustomDdls(BusinessObjectFormatKey businessObjectFormatKey) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the business object format.
    Root<CustomDdlEntity> customDdlEntity = criteria.from(CustomDdlEntity.class);
    // Join to the other tables we can filter on.
    Join<CustomDdlEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = customDdlEntity.join(CustomDdlEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name);
    Path<String> businessObjectFormatUsageColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage);
    Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code);
    Path<Integer> businessObjectFormatVersionColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion);
    Path<String> customDdlNameColumn = customDdlEntity.get(CustomDdlEntity_.customDdlName);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectFormatKey.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectFormatKey.getBusinessObjectDefinitionName().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatKey.getBusinessObjectFormatUsage().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectFormatKey.getBusinessObjectFormatFileType().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatKey.getBusinessObjectFormatVersion()));
    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, businessObjectFormatUsageColumn, fileTypeCodeColumn, businessObjectFormatVersionColumn, customDdlNameColumn);
    // Add the where clause.
    criteria.where(queryRestriction);
    // Add the order by clause.
    criteria.orderBy(builder.asc(customDdlNameColumn));
    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<CustomDdlKey> customDdlKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        CustomDdlKey customDdlKey = new CustomDdlKey();
        customDdlKeys.add(customDdlKey);
        customDdlKey.setNamespace(tuple.get(namespaceCodeColumn));
        customDdlKey.setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn));
        customDdlKey.setBusinessObjectFormatUsage(tuple.get(businessObjectFormatUsageColumn));
        customDdlKey.setBusinessObjectFormatFileType(tuple.get(fileTypeCodeColumn));
        customDdlKey.setBusinessObjectFormatVersion(tuple.get(businessObjectFormatVersionColumn));
        customDdlKey.setCustomDdlName(tuple.get(customDdlNameColumn));
    }
    return customDdlKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey) Predicate(javax.persistence.criteria.Predicate) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) Tuple(javax.persistence.Tuple)

Example 40 with FileTypeEntity

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

the class BusinessObjectDataNotificationRegistrationDaoImpl method getBusinessObjectDataNotificationRegistrationKeysByNotificationFilter.

@Override
public List<NotificationRegistrationKey> getBusinessObjectDataNotificationRegistrationKeysByNotificationFilter(BusinessObjectDataNotificationFilter businessObjectDataNotificationFilter) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the business object data notification registration.
    Root<BusinessObjectDataNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria.from(BusinessObjectDataNotificationRegistrationEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin = notificationRegistrationEntityRoot.join(BusinessObjectDataNotificationRegistrationEntity_.namespace);
    Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = notificationRegistrationEntityRoot.join(BusinessObjectDataNotificationRegistrationEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    Join<BusinessObjectDataNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity = notificationRegistrationEntityRoot.join(BusinessObjectDataNotificationRegistrationEntity_.fileType, JoinType.LEFT);
    // Get the columns.
    Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.name);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionNamespaceEntity.get(NamespaceEntity_.code)), businessObjectDataNotificationFilter.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataNotificationFilter.getBusinessObjectDefinitionName().toUpperCase()));
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage())) {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.usage)), builder.equal(builder.upper(notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.usage)), businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase())));
    }
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType())) {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectDataNotificationFilter.getBusinessObjectFormatFileType().toUpperCase())));
    }
    // Add the select and where clauses to the query.
    criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    // Add the order by clause to the query.
    criteria.orderBy(builder.asc(notificationRegistrationNamespaceColumn), builder.asc(notificationRegistrationNameColumn));
    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    // Populate the list of keys from the returned tuples.
    return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) Tuple(javax.persistence.Tuple)

Aggregations

FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)45 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)38 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)25 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)24 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)23 Predicate (javax.persistence.criteria.Predicate)23 ArrayList (java.util.ArrayList)20 StorageEntity (org.finra.herd.model.jpa.StorageEntity)17 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)14 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)13 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)10 Order (javax.persistence.criteria.Order)8 NotificationEventTypeEntity (org.finra.herd.model.jpa.NotificationEventTypeEntity)8 NotificationRegistrationStatusEntity (org.finra.herd.model.jpa.NotificationRegistrationStatusEntity)8 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)8 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)8 Tuple (javax.persistence.Tuple)6 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)6 JobAction (org.finra.herd.model.api.xml.JobAction)6 BusinessObjectDataNotificationRegistrationEntity (org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity)5