Search in sources :

Example 21 with StorageUnitStatusEntity

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

the class StorageUnitDaoImpl method getMaximumBusinessObjectFormatVersionSubQuery.

/**
 * Builds a sub-query to select the maximum business object data version.
 *
 * @param builder the criteria builder
 * @param criteria the criteria query
 * @param businessObjectDefinitionEntity the business object definition entity that appears in the from clause of the main query
 * @param businessObjectFormatEntity the business object format entity that appears in the from clause of the main query
 * @param fileTypeEntity the file type entity that appears in the from clause of the main query
 * @param businessObjectDataEntity the business object data entity that appears in the from clause of the main query
 * @param businessObjectDataVersion the business object data version. If a business object data version isn't specified, the latest data version based on
 * the specified business object data status is returned
 * @param businessObjectDataStatus the business object data status. This parameter is ignored when the business object data version is specified. When
 * business object data version and business object data status both are not specified, the latest data version for each set of partition values will be
 * used regardless of the status
 * @param storageNames the list of storage names where the business object data storage units should be looked for (case-insensitive)
 * @param storagePlatformType the optional storage platform type, e.g. S3 for Hive DDL. It is ignored when the list of storages is not empty
 * @param excludedStoragePlatformType the optional storage platform type to be excluded from search. It is ignored when the list of storages is not empty or
 * the storage platform type is specified
 * @param selectOnlyAvailableStorageUnits specifies if only available storage units will be selected or any storage units regardless of their status
 *
 * @return the sub-query to select the maximum business object data version
 */
private Subquery<Integer> getMaximumBusinessObjectFormatVersionSubQuery(CriteriaBuilder builder, CriteriaQuery<?> criteria, From<?, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, From<?, FileTypeEntity> fileTypeEntity, From<?, BusinessObjectDataEntity> businessObjectDataEntity, Integer businessObjectDataVersion, String businessObjectDataStatus, List<String> storageNames, String storagePlatformType, String excludedStoragePlatformType, boolean selectOnlyAvailableStorageUnits) {
    // Business object format version is not specified, so just use the latest available for this set of partition values.
    Subquery<Integer> subQuery = criteria.subquery(Integer.class);
    // The criteria root is the business object data.
    Root<BusinessObjectDataEntity> subBusinessObjectDataEntity = subQuery.from(BusinessObjectDataEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDataEntity, StorageUnitEntity> subStorageUnitEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.storageUnits);
    Join<StorageUnitEntity, StorageEntity> subStorageEntity = subStorageUnitEntity.join(StorageUnitEntity_.storage);
    Join<StorageEntity, StoragePlatformEntity> subStoragePlatformEntity = subStorageEntity.join(StorageEntity_.storagePlatform);
    Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> subBusinessObjectDefinitionEntity = subBusinessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> subBusinessObjectFormatFileTypeEntity = subBusinessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.status);
    Join<StorageUnitEntity, StorageUnitStatusEntity> subStorageUnitStatusEntity = subStorageUnitEntity.join(StorageUnitEntity_.status);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate subQueryRestriction = builder.equal(subBusinessObjectDefinitionEntity, businessObjectDefinitionEntity);
    subQueryRestriction = builder.and(subQueryRestriction, builder.equal(subBusinessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage), businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)));
    subQueryRestriction = builder.and(subQueryRestriction, builder.equal(subBusinessObjectFormatFileTypeEntity, fileTypeEntity));
    // Create and add standard restrictions on primary and sub-partition values.
    subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity));
    // Add restrictions on business object data version and business object data status.
    Predicate subQueryRestrictionOnBusinessObjectDataVersionAndStatus = getQueryRestrictionOnBusinessObjectDataVersionAndStatus(builder, subBusinessObjectDataEntity, subBusinessObjectDataStatusEntity, businessObjectDataVersion, businessObjectDataStatus);
    if (subQueryRestrictionOnBusinessObjectDataVersionAndStatus != null) {
        subQueryRestriction = builder.and(subQueryRestriction, subQueryRestrictionOnBusinessObjectDataVersionAndStatus);
    }
    // Create and add a standard restriction on storage.
    subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnStorage(builder, subStorageEntity, subStoragePlatformEntity, storageNames, storagePlatformType, excludedStoragePlatformType));
    // If specified, add a restriction on storage unit status availability flag.
    if (selectOnlyAvailableStorageUnits) {
        subQueryRestriction = builder.and(subQueryRestriction, builder.isTrue(subStorageUnitStatusEntity.get(StorageUnitStatusEntity_.available)));
    }
    // Add all of the clauses to the subquery.
    subQuery.select(builder.max(subBusinessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion))).where(subQueryRestriction);
    return subQuery;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 22 with StorageUnitStatusEntity

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

the class StorageUnitDaoImpl method getS3StorageUnitsToRestore.

@Override
public List<StorageUnitEntity> getS3StorageUnitsToRestore(int maxResult) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);
    // The criteria root is the storage unit.
    Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class);
    // Join to the other tables we can filter on.
    Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.storage);
    Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin.join(StorageEntity_.storagePlatform);
    Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.status);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));
    predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORING));
    // Order the results by storage unit updated on timestamp.
    Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.updatedOn));
    // Add the clauses for the query.
    criteria.select(storageUnitEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
    // Execute the query and return the results.
    return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Predicate(javax.persistence.criteria.Predicate) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity)

Example 23 with StorageUnitStatusEntity

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

the class StorageUnitNotificationRegistrationDaoImpl method getStorageUnitNotificationRegistrations.

@Override
public List<StorageUnitNotificationRegistrationEntity> getStorageUnitNotificationRegistrations(String notificationEventTypeCode, BusinessObjectDataKey businessObjectDataKey, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus, String notificationRegistrationStatus) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitNotificationRegistrationEntity> criteria = builder.createQuery(StorageUnitNotificationRegistrationEntity.class);
    // The criteria root is the storage unit notification registration entity.
    Root<StorageUnitNotificationRegistrationEntity> storageUnitNotificationRegistrationEntityRoot = criteria.from(StorageUnitNotificationRegistrationEntity.class);
    // Join to the other tables we can filter on.
    Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> namespaceEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, NotificationEventTypeEntity> notificationEventTypeEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.notificationEventType);
    Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntityJoin = businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, StorageEntity> storageEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.storage);
    Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT);
    Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> newStorageUnitStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus, JoinType.LEFT);
    Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> oldStorageUnitStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus, JoinType.LEFT);
    Join<StorageUnitNotificationRegistrationEntity, NotificationRegistrationStatusEntity> notificationRegistrationStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.notificationRegistrationStatus);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(notificationEventTypeEntityJoin.get(NotificationEventTypeEntity_.code)), notificationEventTypeCode.toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionNamespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDataKey.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataKey.getBusinessObjectDefinitionName().toUpperCase()));
    predicates.add(builder.equal(builder.upper(storageEntityJoin.get(StorageEntity_.name)), storageName.toUpperCase()));
    predicates.add(builder.or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)), builder.equal(builder.upper(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)), businessObjectDataKey.getBusinessObjectFormatUsage().toUpperCase())));
    predicates.add(builder.or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataKey.getBusinessObjectFormatFileType().toUpperCase())));
    predicates.add(builder.or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion)), builder.equal(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion), businessObjectDataKey.getBusinessObjectFormatVersion())));
    predicates.add(builder.or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus)), builder.equal(builder.upper(newStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)), newStorageUnitStatus.toUpperCase())));
    // Please note that old business object data status parameter value is null for a business object data registration event.
    predicates.add(builder.or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus)), builder.equal(builder.upper(oldStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)), oldStorageUnitStatus == null ? null : oldStorageUnitStatus.toUpperCase())));
    predicates.add(builder.equal(builder.upper(notificationRegistrationStatusEntityJoin.get(NotificationRegistrationStatusEntity_.code)), notificationRegistrationStatus.toUpperCase()));
    // Order the results by namespace and notification name.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code)));
    orderBy.add(builder.asc(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.name)));
    // Add the clauses for the query.
    criteria.select(storageUnitNotificationRegistrationEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
    // Execute the query and return the results.
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Predicate(javax.persistence.criteria.Predicate) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity)

Example 24 with StorageUnitStatusEntity

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

the class StorageUnitStatusDaoImpl method getStorageUnitStatusByCode.

@Override
public StorageUnitStatusEntity getStorageUnitStatusByCode(String code) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitStatusEntity> criteria = builder.createQuery(StorageUnitStatusEntity.class);
    // The criteria root is the storage unit status.
    Root<StorageUnitStatusEntity> storageUnitStatusEntity = criteria.from(StorageUnitStatusEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate storageUnitStatusCodeRestriction = builder.equal(builder.upper(storageUnitStatusEntity.get(StorageUnitStatusEntity_.code)), code.toUpperCase());
    criteria.select(storageUnitStatusEntity).where(storageUnitStatusCodeRestriction);
    return executeSingleResultQuery(criteria, String.format("Found more than one storage unit status with code \"%s\".", code));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) Predicate(javax.persistence.criteria.Predicate)

Example 25 with StorageUnitStatusEntity

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

the class StorageUnitStatusDaoTestHelper method createStorageUnitStatusEntity.

/**
 * Creates and persists a new storage unit status entity.
 *
 * @param statusCode the code of the storage unit status
 * @param description the description of the status code
 * @param available specifies if the business object data stored in the relative storage unit is available or not for consumption
 *
 * @return the newly created storage unit status entity
 */
public StorageUnitStatusEntity createStorageUnitStatusEntity(String statusCode, String description, Boolean available) {
    StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
    storageUnitStatusEntity.setCode(statusCode);
    storageUnitStatusEntity.setDescription(description);
    storageUnitStatusEntity.setAvailable(available);
    return storageUnitStatusDao.saveAndRefresh(storageUnitStatusEntity);
}
Also used : StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity)

Aggregations

StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)47 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)35 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)30 StorageEntity (org.finra.herd.model.jpa.StorageEntity)24 Test (org.junit.Test)23 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)18 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)15 ArrayList (java.util.ArrayList)11 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)11 Predicate (javax.persistence.criteria.Predicate)10 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)10 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)10 StoragePlatformEntity (org.finra.herd.model.jpa.StoragePlatformEntity)9 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 StorageFile (org.finra.herd.model.api.xml.StorageFile)8 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)8 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 Order (javax.persistence.criteria.Order)6 Timestamp (java.sql.Timestamp)5