/** * 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; }
/** * 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; }
/** * Creates and populates a business object data storage unit create response. * * @param storageUnitEntity the storage unit entity * * @return the business object data storage unit create response */ protected BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnitCreateResponse(StorageUnitEntity storageUnitEntity) { // Get business object data key from the business object data entity. BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(storageUnitEntity.getBusinessObjectData()); // Create a business object data storage unit create response. BusinessObjectDataStorageUnitCreateResponse response = new BusinessObjectDataStorageUnitCreateResponse(); // Add business object data storage unit key. response.setBusinessObjectDataStorageUnitKey( storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, storageUnitEntity.getStorage().getName())); // Add storage directory. if (storageUnitEntity.getDirectoryPath() != null) { response.setStorageDirectory(new StorageDirectory(storageUnitEntity.getDirectoryPath())); } // Add storage files. if (CollectionUtils.isNotEmpty(storageUnitEntity.getStorageFiles())) { response.setStorageFiles(storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles())); } // Return the response. return response; }
/** * Creates and populates a business object data storage unit create response. * * @param storageUnitEntity the storage unit entity * * @return the business object data storage unit create response */ protected BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnitCreateResponse(StorageUnitEntity storageUnitEntity) { // Get business object data key from the business object data entity. BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(storageUnitEntity.getBusinessObjectData()); // Create a business object data storage unit create response. BusinessObjectDataStorageUnitCreateResponse response = new BusinessObjectDataStorageUnitCreateResponse(); // Add business object data storage unit key. response.setBusinessObjectDataStorageUnitKey( storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, storageUnitEntity.getStorage().getName())); // Add storage directory. if (storageUnitEntity.getDirectoryPath() != null) { response.setStorageDirectory(new StorageDirectory(storageUnitEntity.getDirectoryPath())); } // Add storage files. if (CollectionUtils.isNotEmpty(storageUnitEntity.getStorageFiles())) { response.setStorageFiles(storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles())); } // Return the response. return response; }
when(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntity)).thenReturn(businessObjectDataKey); when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey); when(storageFileHelper.createStorageFilesFromEntities(storageFileEntities)).thenReturn(storageFiles); verify(businessObjectDataHelper).createBusinessObjectDataKeyFromEntity(businessObjectDataEntity); verify(storageUnitHelper).createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME); verify(storageFileHelper).createStorageFilesFromEntities(storageFileEntities); verify(storageUnitDao).saveAndRefresh(storageUnitEntity); verifyNoMoreInteractionsHelper();
List<StorageFile> storageFiles = storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles());
List<StorageFile> sourceStorageFiles = storageFileHelper.createStorageFilesFromEntities(sourceStorageUnitEntity.getStorageFiles());
List<StorageFile> storageFiles = storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles());
@Test public void testPrepareToFinalizeRestoreMissingOptionalParameters() throws Exception { // Create a business object data key without sub-partition values. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey); // Get the storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Create a storage unit key. BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME); // Prepare to finalize a restore for business object data without sub-partition values. BusinessObjectDataRestoreDto result = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey); // Validate the returned object. assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, result.getS3KeyPrefix(), NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()), NO_EXCEPTION), result); }
@Test public void testPrepareToFinalizeRestore() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create a storage unit key. BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey); // Get the storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Prepare to finalize a restore for the business object data. BusinessObjectDataRestoreDto result = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey); // Validate the returned object. assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, result.getS3KeyPrefix(), NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()), NO_EXCEPTION), result); }
List<StorageFile> storageFiles = storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles());