/** * Validate that business object data status is supported by the storage policy feature. * * @param businessObjectDataEntity the business object data entity * @param businessObjectDataKey the business object data key */ private void validateBusinessObjectData(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey) { Assert.isTrue(StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES.contains(businessObjectDataEntity.getStatus().getCode()), String .format("Business object data status \"%s\" is not supported by the storage policy feature. Business object data: {%s}", businessObjectDataEntity.getStatus().getCode(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); }
/** * Validate that business object data status is supported by the storage policy feature. * * @param businessObjectDataEntity the business object data entity * @param businessObjectDataKey the business object data key */ private void validateBusinessObjectData(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey) { Assert.isTrue(StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES.contains(businessObjectDataEntity.getStatus().getCode()), String .format("Business object data status \"%s\" is not supported by the storage policy feature. Business object data: {%s}", businessObjectDataEntity.getStatus().getCode(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); }
/** * Validates that storage does not have any other registered storage files that start with the specified S3 key prefix, but belong to some other business * object data instances. * * @param storageName the storage name * @param businessObjectDataKey the business object data key * @param s3KeyPrefix the S3 key prefix * @param expectedStorageFilesCount the expected number of storage files that match the specified S3 key prefix in the storage */ public void validateStorageFilesCount(String storageName, BusinessObjectDataKey businessObjectDataKey, String s3KeyPrefix, int expectedStorageFilesCount) { // Get count of all storage files from the storage that start with the specified S3 key prefix. // Since the S3 key prefix represents a directory, we add a trailing '/' character to it. String s3KeyPrefixWithTrailingSlash = StringUtils.appendIfMissing(s3KeyPrefix, "/"); Long registeredStorageFilesCount = storageFileDao.getStorageFileCount(storageName, s3KeyPrefixWithTrailingSlash); // Check if the number of registered storage files that match the S3 key prefix is equal to the expected value. if (registeredStorageFilesCount != expectedStorageFilesCount) { throw new IllegalStateException(String.format( "Found %d registered storage file(s) matching business object data S3 key prefix in the storage that is not equal to the number " + "of storage files (%d) registered with the business object data in that storage. " + "Storage: {%s}, s3KeyPrefix {%s}, business object data: {%s}", registeredStorageFilesCount, expectedStorageFilesCount, storageName, s3KeyPrefixWithTrailingSlash, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } } }
/** * Validates that storage does not have any other registered storage files that start with the specified S3 key prefix, but belong to some other business * object data instances. * * @param storageName the storage name * @param businessObjectDataKey the business object data key * @param s3KeyPrefix the S3 key prefix * @param expectedStorageFilesCount the expected number of storage files that match the specified S3 key prefix in the storage */ public void validateStorageFilesCount(String storageName, BusinessObjectDataKey businessObjectDataKey, String s3KeyPrefix, int expectedStorageFilesCount) { // Get count of all storage files from the storage that start with the specified S3 key prefix. // Since the S3 key prefix represents a directory, we add a trailing '/' character to it. String s3KeyPrefixWithTrailingSlash = StringUtils.appendIfMissing(s3KeyPrefix, "/"); Long registeredStorageFilesCount = storageFileDao.getStorageFileCount(storageName, s3KeyPrefixWithTrailingSlash); // Check if the number of registered storage files that match the S3 key prefix is equal to the expected value. if (registeredStorageFilesCount != expectedStorageFilesCount) { throw new IllegalStateException(String.format( "Found %d registered storage file(s) matching business object data S3 key prefix in the storage that is not equal to the number " + "of storage files (%d) registered with the business object data in that storage. " + "Storage: {%s}, s3KeyPrefix {%s}, business object data: {%s}", registeredStorageFilesCount, expectedStorageFilesCount, storageName, s3KeyPrefixWithTrailingSlash, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } } }
/** * Validates the storage unit. * * @param storageUnitEntity the storage unit entity, not null * @param storageName the storage name * @param businessObjectDataKey the business object data key */ private void validateStorageUnit(StorageUnitEntity storageUnitEntity, String storageName, BusinessObjectDataKey businessObjectDataKey) { Assert.isTrue(StorageUnitStatusEntity.ENABLED.equals(storageUnitEntity.getStatus().getCode()) || StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String.format( "Storage unit status is \"%s\", but must be \"%s\" or \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ENABLED, StorageUnitStatusEntity.ARCHIVING, storageName, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); }
/** * Validates the storage unit. * * @param storageUnitEntity the storage unit entity, not null * @param storageName the storage name * @param businessObjectDataKey the business object data key */ private void validateStorageUnit(StorageUnitEntity storageUnitEntity, String storageName, BusinessObjectDataKey businessObjectDataKey) { Assert.isTrue(StorageUnitStatusEntity.ENABLED.equals(storageUnitEntity.getStatus().getCode()) || StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String.format( "Storage unit status is \"%s\", but must be \"%s\" or \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ENABLED, StorageUnitStatusEntity.ARCHIVING, storageName, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); }
/** * Retrieves storage file by storage unit entity and file path. * * @param storageUnitEntity the storage unit entity * @param filePath the file path * @param businessObjectDataKey the business object data key * * @return the storage file entity * @throws org.finra.herd.model.ObjectNotFoundException if the storage file doesn't exist * @throws IllegalArgumentException if more than one storage file matching the file path exist in the storage */ public StorageFileEntity getStorageFileEntity(StorageUnitEntity storageUnitEntity, String filePath, BusinessObjectDataKey businessObjectDataKey) throws ObjectNotFoundException, IllegalArgumentException { StorageFileEntity storageFileEntity = storageFileDao.getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath); if (storageFileEntity == null) { throw new ObjectNotFoundException(String .format("Storage file \"%s\" doesn't exist in \"%s\" storage. Business object data: {%s}", filePath, storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } return storageFileEntity; }
/** * Retrieves storage file by storage unit entity and file path. * * @param storageUnitEntity the storage unit entity * @param filePath the file path * @param businessObjectDataKey the business object data key * * @return the storage file entity * @throws org.finra.herd.model.ObjectNotFoundException if the storage file doesn't exist * @throws IllegalArgumentException if more than one storage file matching the file path exist in the storage */ public StorageFileEntity getStorageFileEntity(StorageUnitEntity storageUnitEntity, String filePath, BusinessObjectDataKey businessObjectDataKey) throws ObjectNotFoundException, IllegalArgumentException { StorageFileEntity storageFileEntity = storageFileDao.getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath); if (storageFileEntity == null) { throw new ObjectNotFoundException(String .format("Storage file \"%s\" doesn't exist in \"%s\" storage. Business object data: {%s}", filePath, storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } return storageFileEntity; }
/** * Retrieves and validates a list of storage files registered with the specified storage unit. This method makes sure that the list of storage files is not * empty and that all storage files match the expected s3 key prefix value. * * @param storageUnitEntity the storage unit entity the storage file paths to be validated * @param s3KeyPrefix the S3 key prefix that storage file paths are expected to start with * @param storageName the storage name * @param businessObjectDataKey the business object data key * * @return the list of storage files */ public List<StorageFile> getAndValidateStorageFiles(StorageUnitEntity storageUnitEntity, String s3KeyPrefix, String storageName, BusinessObjectDataKey businessObjectDataKey) { // Check if the list of storage files is not empty. if (CollectionUtils.isEmpty(storageUnitEntity.getStorageFiles())) { throw new IllegalArgumentException(String .format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", storageName, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } // Retrieve storage files. List<StorageFile> storageFiles = createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()); // Validate storage file paths registered with this business object data in the specified storage. validateStorageFilePaths(getFilePathsFromStorageFiles(storageFiles), s3KeyPrefix, storageUnitEntity.getBusinessObjectData(), storageName); // Return the list of storage files. return storageFiles; }
@Test public void testBusinessObjectDataKeyToStringWithNull() { assertNull(businessObjectDataHelper.businessObjectDataKeyToString(null)); }
@Override public String getIdentifyingInformation(NotificationEventParamsDto notificationEventParams, BusinessObjectDataHelper businessObjectDataHelper) { if (notificationEventParams instanceof StorageUnitNotificationEventParamsDto) { StorageUnitNotificationEventParamsDto storageUnitNotificationEventParams = (StorageUnitNotificationEventParamsDto) notificationEventParams; return String.format("namespace: \"%s\", actionId: \"%s\" with " + businessObjectDataHelper.businessObjectDataKeyToString( businessObjectDataHelper.getBusinessObjectDataKey(storageUnitNotificationEventParams.getBusinessObjectData())) + ", storageName: \"%s\"", storageUnitNotificationEventParams.getStorageUnitNotificationRegistration().getNamespace().getCode(), storageUnitNotificationEventParams.getNotificationJobAction().getId(), storageUnitNotificationEventParams.getStorageName()); } else { throw new IllegalStateException( "Notification event parameters DTO passed to the method must be an instance of StorageUnitNotificationEventParamsDto."); } }
@Override public String getIdentifyingInformation(NotificationEventParamsDto notificationEventParams, BusinessObjectDataHelper businessObjectDataHelper) { if (notificationEventParams instanceof BusinessObjectDataNotificationEventParamsDto) { BusinessObjectDataNotificationEventParamsDto businessObjectDataNotificationEventParams = (BusinessObjectDataNotificationEventParamsDto) notificationEventParams; return String.format("namespace: \"%s\", actionId: \"%s\" with " + businessObjectDataHelper.businessObjectDataKeyToString( businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataNotificationEventParams.getBusinessObjectData())) + ", storageName: \"%s\"", businessObjectDataNotificationEventParams.getBusinessObjectDataNotificationRegistration().getNamespace().getCode(), businessObjectDataNotificationEventParams.getNotificationJobAction().getId(), businessObjectDataNotificationEventParams.getStorageName()); } else { throw new IllegalStateException( "Notification event parameters DTO passed to the method must be an instance of BusinessObjectDataNotificationEventParamsDto."); } }
@Override public String getIdentifyingInformation(NotificationEventParamsDto notificationEventParams, BusinessObjectDataHelper businessObjectDataHelper) { if (notificationEventParams instanceof StorageUnitNotificationEventParamsDto) { StorageUnitNotificationEventParamsDto storageUnitNotificationEventParams = (StorageUnitNotificationEventParamsDto) notificationEventParams; return String.format("namespace: \"%s\", actionId: \"%s\" with " + businessObjectDataHelper.businessObjectDataKeyToString( businessObjectDataHelper.getBusinessObjectDataKey(storageUnitNotificationEventParams.getBusinessObjectData())) + ", storageName: \"%s\"", storageUnitNotificationEventParams.getStorageUnitNotificationRegistration().getNamespace().getCode(), storageUnitNotificationEventParams.getNotificationJobAction().getId(), storageUnitNotificationEventParams.getStorageName()); } else { throw new IllegalStateException( "Notification event parameters DTO passed to the method must be an instance of StorageUnitNotificationEventParamsDto."); } }
@Override public String getIdentifyingInformation(NotificationEventParamsDto notificationEventParams, BusinessObjectDataHelper businessObjectDataHelper) { if (notificationEventParams instanceof BusinessObjectDataNotificationEventParamsDto) { BusinessObjectDataNotificationEventParamsDto businessObjectDataNotificationEventParams = (BusinessObjectDataNotificationEventParamsDto) notificationEventParams; return String.format("namespace: \"%s\", actionId: \"%s\" with " + businessObjectDataHelper.businessObjectDataKeyToString( businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataNotificationEventParams.getBusinessObjectData())) + ", storageName: \"%s\"", businessObjectDataNotificationEventParams.getBusinessObjectDataNotificationRegistration().getNamespace().getCode(), businessObjectDataNotificationEventParams.getNotificationJobAction().getId(), businessObjectDataNotificationEventParams.getStorageName()); } else { throw new IllegalStateException( "Notification event parameters DTO passed to the method must be an instance of BusinessObjectDataNotificationEventParamsDto."); } }
/** * Completes a storage policy transition as per specified storage policy selection. * * @param storagePolicyTransitionParamsDto the storage policy transition DTO that contains parameters needed to complete a storage policy transition */ protected void completeStoragePolicyTransitionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto) { // Get the business object data key. BusinessObjectDataKey businessObjectDataKey = storagePolicyTransitionParamsDto.getBusinessObjectDataKey(); // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey); // Validate that business object data status is supported by the storage policy feature. String businessObjectDataStatus = businessObjectDataEntity.getStatus().getCode(); Assert.isTrue(StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES.contains(businessObjectDataStatus), String .format("Business object data status \"%s\" is not supported by the storage policy feature. Business object data: {%s}", businessObjectDataStatus, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); // Retrieve storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataEntity); // Validate that storage unit status is ARCHIVING. Assert.isTrue(StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String .format("Storage unit status is \"%s\", but must be \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ARCHIVING, storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); // Change the storage unit status to ARCHIVED. String reason = StorageUnitStatusEntity.ARCHIVED; storagePolicyTransitionParamsDto.setOldStorageUnitStatus(storageUnitEntity.getStatus().getCode()); storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason); storagePolicyTransitionParamsDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode()); }
/** * Returns a string representation of the business object data key. * * @param businessObjectDataKey the business object data key * * @return the string representation of the business object data key */ public String businessObjectDataKeyToString(BusinessObjectDataKey businessObjectDataKey) { if (businessObjectDataKey == null) { return null; } return businessObjectDataKeyToString(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), businessObjectDataKey.getBusinessObjectDataVersion()); }
/** * Returns a string representation of the business object data key. * * @param businessObjectDataKey the business object data key * * @return the string representation of the business object data key */ public String businessObjectDataKeyToString(BusinessObjectDataKey businessObjectDataKey) { if (businessObjectDataKey == null) { return null; } return businessObjectDataKeyToString(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), businessObjectDataKey.getBusinessObjectDataVersion()); }
@Test public void testBusinessObjectDataKeyToString() { // Create test business object data key. BusinessObjectDataKey testBusinessObjectDataKey = new BusinessObjectDataKey(); testBusinessObjectDataKey.setNamespace(NAMESPACE); testBusinessObjectDataKey.setBusinessObjectDefinitionName(BDEF_NAME); testBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE); testBusinessObjectDataKey.setBusinessObjectFormatFileType(FORMAT_FILE_TYPE_CODE); testBusinessObjectDataKey.setBusinessObjectFormatVersion(FORMAT_VERSION); testBusinessObjectDataKey.setPartitionValue(PARTITION_VALUE); testBusinessObjectDataKey.setSubPartitionValues(SUBPARTITION_VALUES); testBusinessObjectDataKey.setBusinessObjectDataVersion(DATA_VERSION); // Create the expected test output. String expectedOutput = String.format("namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d, businessObjectDataPartitionValue: \"%s\", " + "businessObjectDataSubPartitionValues: \"%s\", businessObjectDataVersion: %d", NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, StringUtils.join(SUBPARTITION_VALUES, ","), DATA_VERSION); assertEquals(expectedOutput, businessObjectDataHelper.businessObjectDataKeyToString(testBusinessObjectDataKey)); assertEquals(expectedOutput, businessObjectDataHelper .businessObjectDataKeyToString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION)); }
/** * Returns a string representation of the alternate key values for the business object data entity. * * @param businessObjectDataEntity the business object data entity * * @return the string representation of the alternate key values for the business object data entity */ public String businessObjectDataEntityAltKeyToString(BusinessObjectDataEntity businessObjectDataEntity) { BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectDataEntity.getBusinessObjectFormat(); return businessObjectDataKeyToString(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode(), businessObjectFormatEntity.getBusinessObjectDefinition().getName(), businessObjectFormatEntity.getUsage(), businessObjectFormatEntity.getFileType().getCode(), businessObjectFormatEntity.getBusinessObjectFormatVersion(), businessObjectDataEntity.getPartitionValue(), getSubPartitionValues(businessObjectDataEntity), businessObjectDataEntity.getVersion()); }
/** * Returns a string representation of the alternate key values for the business object data entity. * * @param businessObjectDataEntity the business object data entity * * @return the string representation of the alternate key values for the business object data entity */ public String businessObjectDataEntityAltKeyToString(BusinessObjectDataEntity businessObjectDataEntity) { BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectDataEntity.getBusinessObjectFormat(); return businessObjectDataKeyToString(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode(), businessObjectFormatEntity.getBusinessObjectDefinition().getName(), businessObjectFormatEntity.getUsage(), businessObjectFormatEntity.getFileType().getCode(), businessObjectFormatEntity.getBusinessObjectFormatVersion(), businessObjectDataEntity.getPartitionValue(), getSubPartitionValues(businessObjectDataEntity), businessObjectDataEntity.getVersion()); }