/** * Asserts that the given storage unit entity contains exactly one storage file. * * @param storageUnitEntity - storage unit to check * * @throws IllegalArgumentException when the number of storage files is not 1 */ private void assertHasOneStorageFile(StorageUnitEntity storageUnitEntity) { Assert.isTrue(storageUnitEntity.getStorageFiles().size() == 1, String .format("Found %d registered storage files when expecting one in \"%s\" storage for the business object data {%s}.", storageUnitEntity.getStorageFiles().size(), storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData()))); }
/** * Gets a unique storage from the given business object data. The given business object data must have one and only one storage unit with a storage, * otherwise this method throws an exception. * * @param businessObjectDataEntity the business object data entity * * @return the unique storage entity */ private StorageEntity getUniqueStorage(BusinessObjectDataEntity businessObjectDataEntity) { Collection<StorageUnitEntity> targetStorageUnits = businessObjectDataEntity.getStorageUnits(); Assert.notEmpty(targetStorageUnits, "No storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); Assert.isTrue(targetStorageUnits.size() == 1, "More than 1 storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); return IterableUtils.get(targetStorageUnits, 0).getStorage(); }
/** * Gets a unique storage from the given business object data. The given business object data must have one and only one storage unit with a storage, * otherwise this method throws an exception. * * @param businessObjectDataEntity the business object data entity * * @return the unique storage entity */ private StorageEntity getUniqueStorage(BusinessObjectDataEntity businessObjectDataEntity) { Collection<StorageUnitEntity> targetStorageUnits = businessObjectDataEntity.getStorageUnits(); Assert.notEmpty(targetStorageUnits, "No storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); Assert.isTrue(targetStorageUnits.size() == 1, "More than 1 storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); return IterableUtils.get(targetStorageUnits, 0).getStorage(); }
/** * Asserts that the given storage unit entity contains exactly one storage file. * * @param storageUnitEntity - storage unit to check * * @throws IllegalArgumentException when the number of storage files is not 1 */ private void assertHasOneStorageFile(StorageUnitEntity storageUnitEntity) { Assert.isTrue(storageUnitEntity.getStorageFiles().size() == 1, String .format("Found %d registered storage files when expecting one in \"%s\" storage for the business object data {%s}.", storageUnitEntity.getStorageFiles().size(), storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData()))); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
@Override public void execute() { // Delete the storage which is invalid because there still exists a storage unit entity that references it. StorageKey alternateKey = new StorageKey(storageUnitEntity.getStorage().getName()); storageService.deleteStorage(alternateKey); } });
/** * Sets storage unit status value for a storage unit. This method also generates a storage unit status change notification event as per system * configuration. * * @param storageUnitEntity the storage unit entity * @param storageUnitStatusEntity the storage unit status entity */ public void setStorageUnitStatus(StorageUnitEntity storageUnitEntity, StorageUnitStatusEntity storageUnitStatusEntity) { // Set the storage unit status value. storageUnitEntity.setStatus(storageUnitStatusEntity); // Send a storage unit status change notification as per system configuration. messageNotificationEventService .processStorageUnitStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData()), storageUnitEntity.getStorage().getName(), storageUnitStatusEntity.getCode(), null); }
/** * Sets storage unit status value for a storage unit. This method also generates a storage unit status change notification event as per system * configuration. * * @param storageUnitEntity the storage unit entity * @param storageUnitStatusEntity the storage unit status entity */ public void setStorageUnitStatus(StorageUnitEntity storageUnitEntity, StorageUnitStatusEntity storageUnitStatusEntity) { // Set the storage unit status value. storageUnitEntity.setStatus(storageUnitStatusEntity); // Send a storage unit status change notification as per system configuration. messageNotificationEventService .processStorageUnitStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData()), storageUnitEntity.getStorage().getName(), storageUnitStatusEntity.getCode(), null); }
@Test public void testGetStorageUnitsByStorageAndBusinessObjectData() { // Create database entities required for testing. StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper .createStorageUnitEntity(STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, TEST_S3_KEY_PREFIX); // Retrieve storage unit entities by storage and business object data. List<StorageUnitEntity> resultStorageUnitEntities = storageUnitDao.getStorageUnitsByStorageAndBusinessObjectData(storageUnitEntity.getStorage(), Collections.singletonList(storageUnitEntity.getBusinessObjectData())); // Validate the results. assertNotNull(resultStorageUnitEntities); assertEquals(1, resultStorageUnitEntities.size()); assertEquals(TEST_S3_KEY_PREFIX, resultStorageUnitEntities.get(0).getDirectoryPath()); }
RelationalStorageAttributesDto relationalStorageAttributesDto = getRelationalStorageAttributes(storageUnitEntity.getStorage());
RelationalStorageAttributesDto relationalStorageAttributesDto = getRelationalStorageAttributes(storageUnitEntity.getStorage());
storageUnitEntity.getStorage().getName(), storageUnitStatusEntity.getCode(), oldStatus);
storageUnitEntity.getStorage().getName(), storageUnitStatusEntity.getCode(), oldStatus);
@Test public void testInitiateDownloadSingleMultipleStorageFilesExist() { // Create the upload data. UploadSingleInitiationResponse uploadSingleInitiationResponse = uploadDownloadServiceTestHelper.createUploadedFileData(BusinessObjectDataStatusEntity.VALID); // Get the target business object data entity. BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDao .getBusinessObjectDataByAltKey(businessObjectDataHelper.getBusinessObjectDataKey(uploadSingleInitiationResponse.getTargetBusinessObjectData())); // Get the target bushiness object data storage unit. StorageUnitEntity targetStorageUnitEntity = IterableUtils.get(targetBusinessObjectDataEntity.getStorageUnits(), 0); // Add a second storage file to the target business object data storage unit. storageFileDaoTestHelper.createStorageFileEntity(targetStorageUnitEntity, FILE_NAME_2, FILE_SIZE_1_KB, ROW_COUNT_1000); // Try to initiate a single file download when business object data has more than one storage file. try { // Initiate the download against the uploaded data (i.e. the target business object data). initiateDownload(uploadSingleInitiationResponse.getTargetBusinessObjectData()); fail("Suppose to throw an IllegalArgumentException when business object has more than one storage file."); } catch (IllegalArgumentException e) { BusinessObjectData businessObjectData = uploadSingleInitiationResponse.getTargetBusinessObjectData(); assertEquals(String.format("Found 2 registered storage files when expecting one in \"%s\" storage for the business object data {%s}.", targetStorageUnitEntity.getStorage().getName(), businessObjectDataServiceTestHelper .getExpectedBusinessObjectDataKeyAsString(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData))), e.getMessage()); } }
@Test public void testGetStorageUnitByBusinessObjectDataAndStorage() { StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper .createStorageUnitEntity(STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, STORAGE_DIRECTORY_PATH); BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData(); StorageEntity storageEntity = storageUnitEntity.getStorage(); // Test retrieval by entities. assertEquals(storageUnitEntity, storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)); // Test retrieval failures. assertNull( storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(), storageEntity)); assertNull(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageDaoTestHelper.createStorageEntity())); }
/** * Creates a storage unit key from a storage unit entity. * * @param storageUnitEntity the storage unit entity * * @return the storage unit key */ public BusinessObjectDataStorageUnitKey createStorageUnitKeyFromEntity(StorageUnitEntity storageUnitEntity) { // Get the business object data entity. BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData(); // Create and initialize the storage unit key. BusinessObjectDataStorageUnitKey storageUnitKey = new BusinessObjectDataStorageUnitKey(); storageUnitKey.setNamespace(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getNamespace().getCode()); storageUnitKey.setBusinessObjectDefinitionName(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getName()); storageUnitKey.setBusinessObjectFormatUsage(businessObjectDataEntity.getBusinessObjectFormat().getUsage()); storageUnitKey.setBusinessObjectFormatFileType(businessObjectDataEntity.getBusinessObjectFormat().getFileType().getCode()); storageUnitKey.setBusinessObjectFormatVersion(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion()); storageUnitKey.setPartitionValue(businessObjectDataEntity.getPartitionValue()); storageUnitKey.setSubPartitionValues(businessObjectDataHelper.getSubPartitionValues(businessObjectDataEntity)); storageUnitKey.setBusinessObjectDataVersion(businessObjectDataEntity.getVersion()); storageUnitKey.setStorageName(storageUnitEntity.getStorage().getName()); return storageUnitKey; }
/** * Creates a storage unit key from a storage unit entity. * * @param storageUnitEntity the storage unit entity * * @return the storage unit key */ public BusinessObjectDataStorageUnitKey createStorageUnitKeyFromEntity(StorageUnitEntity storageUnitEntity) { // Get the business object data entity. BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData(); // Create and initialize the storage unit key. BusinessObjectDataStorageUnitKey storageUnitKey = new BusinessObjectDataStorageUnitKey(); storageUnitKey.setNamespace(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getNamespace().getCode()); storageUnitKey.setBusinessObjectDefinitionName(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getName()); storageUnitKey.setBusinessObjectFormatUsage(businessObjectDataEntity.getBusinessObjectFormat().getUsage()); storageUnitKey.setBusinessObjectFormatFileType(businessObjectDataEntity.getBusinessObjectFormat().getFileType().getCode()); storageUnitKey.setBusinessObjectFormatVersion(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion()); storageUnitKey.setPartitionValue(businessObjectDataEntity.getPartitionValue()); storageUnitKey.setSubPartitionValues(businessObjectDataHelper.getSubPartitionValues(businessObjectDataEntity)); storageUnitKey.setBusinessObjectDataVersion(businessObjectDataEntity.getVersion()); storageUnitKey.setStorageName(storageUnitEntity.getStorage().getName()); return storageUnitKey; }