/** * Gets a storage unit by storage name (case insensitive). * * @param businessObjectData the business object data * @param storageName the storage name * * @return the storage unit * @throws IllegalStateException if business object data has no storage unit with the specified storage name */ public StorageUnit getStorageUnitByStorageName(BusinessObjectData businessObjectData, String storageName) throws IllegalStateException { StorageUnit resultStorageUnit = null; // Find a storage unit that belongs to the specified storage. for (StorageUnit storageUnit : businessObjectData.getStorageUnits()) { if (storageUnit.getStorage().getName().equalsIgnoreCase(storageName)) { resultStorageUnit = storageUnit; break; } } // Validate that we found a storage unit that belongs to the specified storage. if (resultStorageUnit == null) { throw new IllegalStateException(String.format("Business object data has no storage unit with storage name \"%s\".", storageName)); } return resultStorageUnit; }
/** * Gets a storage unit by storage name (case insensitive). * * @param businessObjectData the business object data * @param storageName the storage name * * @return the storage unit * @throws IllegalStateException if business object data has no storage unit with the specified storage name */ public StorageUnit getStorageUnitByStorageName(BusinessObjectData businessObjectData, String storageName) throws IllegalStateException { StorageUnit resultStorageUnit = null; // Find a storage unit that belongs to the specified storage. for (StorageUnit storageUnit : businessObjectData.getStorageUnits()) { if (storageUnit.getStorage().getName().equalsIgnoreCase(storageName)) { resultStorageUnit = storageUnit; break; } } // Validate that we found a storage unit that belongs to the specified storage. if (resultStorageUnit == null) { throw new IllegalStateException(String.format("Business object data has no storage unit with storage name \"%s\".", storageName)); } return resultStorageUnit; }
/** * Trigger business object data and storage unit notification for business object data creation event. * * @param businessObjectData the business object data */ public void triggerNotificationsForCreateBusinessObjectData(BusinessObjectData businessObjectData) { BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData); // Create business object data notifications. for (NotificationEventTypeEntity.EventTypesBdata eventType : Arrays .asList(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG)) { notificationEventService.processBusinessObjectDataNotificationEventAsync(eventType, businessObjectDataKey, businessObjectData.getStatus(), null); } // Create storage unit notifications. for (StorageUnit storageUnit : businessObjectData.getStorageUnits()) { notificationEventService .processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, storageUnit.getStorage().getName(), storageUnit.getStorageUnitStatus(), null); } }
/** * Trigger business object data and storage unit notification for business object data creation event. * * @param businessObjectData the business object data */ public void triggerNotificationsForCreateBusinessObjectData(BusinessObjectData businessObjectData) { BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData); // Create business object data notifications. for (NotificationEventTypeEntity.EventTypesBdata eventType : Arrays .asList(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG)) { notificationEventService.processBusinessObjectDataNotificationEventAsync(eventType, businessObjectDataKey, businessObjectData.getStatus(), null); } // Create storage unit notifications. for (StorageUnit storageUnit : businessObjectData.getStorageUnits()) { notificationEventService .processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, storageUnit.getStorage().getName(), storageUnit.getStorageUnitStatus(), null); } }
for (StorageUnit storageUnit : businessObjectData.getStorageUnits())
for (StorageUnit storageUnit : businessObjectData.getStorageUnits())
/** * Validates a download single initiation response as compared to the upload initiation response. * * @param uploadSingleInitiationResponse the upload single initiation response. * @param downloadSingleInitiationResponse the download single initiation response. */ public void validateDownloadSingleInitiationResponse(UploadSingleInitiationResponse uploadSingleInitiationResponse, DownloadSingleInitiationResponse downloadSingleInitiationResponse) { BusinessObjectData targetBusinessObjectData = uploadSingleInitiationResponse.getTargetBusinessObjectData(); validateDownloadSingleInitiationResponse(targetBusinessObjectData.getNamespace(), targetBusinessObjectData.getBusinessObjectDefinitionName(), targetBusinessObjectData.getBusinessObjectFormatUsage(), targetBusinessObjectData.getBusinessObjectFormatFileType(), targetBusinessObjectData.getBusinessObjectFormatVersion(), targetBusinessObjectData.getAttributes(), targetBusinessObjectData.getStorageUnits().get(0).getStorageFiles().get(0).getFileSizeBytes(), downloadSingleInitiationResponse); }
/** * Validates actualBusinessObjectData contents against specified arguments and expected (hard coded) test values. * * @param expectedDataVersion the expected business object data version * @param expectedAttributes the expected attributes * @param expectedParents the expected business object data parents * @param actualBusinessObjectData the BusinessObjectData object instance to be validated */ protected void assertBusinessObjectData(Integer expectedDataVersion, List<Attribute> expectedAttributes, List<BusinessObjectDataKey> expectedParents, BusinessObjectData actualBusinessObjectData) { assertNotNull(actualBusinessObjectData); assertEquals(TEST_BUSINESS_OBJECT_DEFINITION, actualBusinessObjectData.getBusinessObjectDefinitionName()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_USAGE, actualBusinessObjectData.getBusinessObjectFormatUsage()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_FILE_TYPE, actualBusinessObjectData.getBusinessObjectFormatFileType()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_VERSION.intValue(), actualBusinessObjectData.getBusinessObjectFormatVersion()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_PARTITION_KEY, actualBusinessObjectData.getPartitionKey()); assertEquals(TEST_PARTITION_VALUE, actualBusinessObjectData.getPartitionValue()); assertEquals(expectedDataVersion.intValue(), actualBusinessObjectData.getVersion()); assertEquals(1, actualBusinessObjectData.getStorageUnits().size()); assertEquals(StorageEntity.MANAGED_STORAGE, actualBusinessObjectData.getStorageUnits().get(0).getStorage().getName()); assertEquals(testManifestFiles.size(), actualBusinessObjectData.getStorageUnits().get(0).getStorageFiles().size()); assertEquals(expectedAttributes, actualBusinessObjectData.getAttributes()); assertEquals(expectedParents, actualBusinessObjectData.getBusinessObjectDataParents()); }
@Test public void testCreateBusinessObjectDataPreRegistrationAssertDirectoryPathNotRequiredWhenStatusIsPreRegistrationAndDirectoryIsSetInResponse() { StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME); storageEntity.getAttributes().add(storageDaoTestHelper .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "foo")); // Create an initial version of the business object data. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(); businessObjectDataCreateRequest.setSubPartitionValues(null); businessObjectDataCreateRequest.setStatus("UPLOADING"); businessObjectDataCreateRequest.setStorageUnits(Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, null, null, null))); BusinessObjectData businessObjectData = businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); assertEquals("foo", businessObjectData.getStorageUnits().get(0).getStorageDirectory().getDirectoryPath()); }
@Test public void testS3Message() throws Exception { setLogLevel(UploadDownloadHelperServiceImpl.class, LogLevel.OFF); uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting(); UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest()); String filePath = resultUploadSingleInitiationResponse.getSourceBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath(); S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity(filePath, 0L, null, null), null); List<S3EventNotificationRecord> records = new ArrayList<>(); records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null)); S3EventNotification s3EventNotification = new S3EventNotification(records); setLogLevel(UploadDownloadServiceImpl.class, LogLevel.OFF); setLogLevel(HerdJmsMessageListener.class, LogLevel.DEBUG); herdJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null); }
@Test public void testS3MessageS3FileNoExists() throws Exception { setLogLevel(UploadDownloadHelperServiceImpl.class, LogLevel.OFF); uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting(); UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper .createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, TARGET_S3_KEY)); String filePath = resultUploadSingleInitiationResponse.getSourceBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath(); S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity(filePath, 0L, null, null), null); List<S3EventNotificationRecord> records = new ArrayList<>(); records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null)); S3EventNotification s3EventNotification = new S3EventNotification(records); setLogLevel(UploadDownloadServiceImpl.class, LogLevel.OFF); setLogLevel(HerdJmsMessageListener.class, LogLevel.OFF); // Try to process an S3 JMS message, when source S3 file does not exist. herdJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null); }
/** * Retrieves S3 key prefix from the herd registration server. * * @param businessObjectData the business object data * * @return the S3 key prefix * @throws JAXBException if a JAXB error was encountered * @throws IOException if an I/O error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ public S3KeyPrefixInformation getS3KeyPrefix(BusinessObjectData businessObjectData) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { DataBridgeBaseManifestDto dataBridgeBaseManifestDto = new DataBridgeBaseManifestDto(); dataBridgeBaseManifestDto.setNamespace(businessObjectData.getNamespace()); dataBridgeBaseManifestDto.setBusinessObjectDefinitionName(businessObjectData.getBusinessObjectDefinitionName()); dataBridgeBaseManifestDto.setBusinessObjectFormatUsage(businessObjectData.getBusinessObjectFormatUsage()); dataBridgeBaseManifestDto.setBusinessObjectFormatFileType(businessObjectData.getBusinessObjectFormatFileType()); dataBridgeBaseManifestDto.setBusinessObjectFormatVersion(String.valueOf(businessObjectData.getBusinessObjectFormatVersion())); dataBridgeBaseManifestDto.setPartitionKey(businessObjectData.getPartitionKey()); dataBridgeBaseManifestDto.setPartitionValue(businessObjectData.getPartitionValue()); dataBridgeBaseManifestDto.setSubPartitionValues(businessObjectData.getSubPartitionValues()); dataBridgeBaseManifestDto.setStorageName(businessObjectData.getStorageUnits().get(0).getStorage().getName()); return super.getS3KeyPrefix(dataBridgeBaseManifestDto, businessObjectData.getVersion(), Boolean.FALSE); }
assertEquals(1, actualBusinessObjectData.getStorageUnits().size()); StorageUnit actualStorageUnit = actualBusinessObjectData.getStorageUnits().get(0);
assertEquals(1, businessObjectData.getStorageUnits().size()); StorageUnit storageUnit = businessObjectData.getStorageUnits().get(0); assertEquals(expectedStorageName, storageUnit.getStorage().getName()); String expectedStorageDirectoryPath = String.format("%s/%s/%s", AbstractServiceTest.ENVIRONMENT_NAME.trim().toLowerCase().replace('_', '-'),
@Test public void testPerformCompleteUploadSingleMessageS3FileNoExists() { uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting(); UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper .createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, FILE_NAME)); String filePath = resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath(); // Try to complete the upload, when source S3 file does not exist. UploadDownloadServiceImpl.CompleteUploadSingleMessageResult result = uploadDownloadService.performCompleteUploadSingleMessage(filePath); assertEquals(BusinessObjectDataStatusEntity.UPLOADING, result.getSourceOldBusinessObjectDataStatus()); assertEquals(BusinessObjectDataStatusEntity.DELETED, result.getSourceNewBusinessObjectDataStatus()); assertEquals(BusinessObjectDataStatusEntity.UPLOADING, result.getTargetOldBusinessObjectDataStatus()); assertEquals(BusinessObjectDataStatusEntity.INVALID, result.getTargetNewBusinessObjectDataStatus()); }
assertEquals(businessObjectDataVersion.intValue(), businessObjectData.getVersion()); assertEquals(true, businessObjectData.isLatestVersion()); assertEquals(1, businessObjectData.getStorageUnits().size()); assertEquals(0, businessObjectData.getAttributes().size()); assertEquals(0, businessObjectData.getBusinessObjectDataParents().size());
/** * Creates the appropriate business object data entries for an upload. * * @param businessObjectDataStatusCode the target business object data status. * * @return the upload single initiation response created during the upload flow. */ public UploadSingleInitiationResponse createUploadedFileData(String businessObjectDataStatusCode) { loggingHelper.setLogLevel(UploadDownloadHelperServiceImpl.class, LogLevel.OFF); // Create source and target business object formats database entities which are required to initiate an upload. createDatabaseEntitiesForUploadDownloadTesting(); // Initiate a file upload. UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(createUploadSingleInitiationRequest()); // Complete the upload. uploadDownloadService.performCompleteUploadSingleMessage( resultUploadSingleInitiationResponse.getSourceBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath()); // Update the target business object data status to valid. Normally this would happen as part of the completion request, but since the status update // happens asynchronously, this will not happen within a unit test context which is why we are setting it explicitly. businessObjectDataDao.getBusinessObjectDataByAltKey( businessObjectDataHelper.getBusinessObjectDataKey(resultUploadSingleInitiationResponse.getTargetBusinessObjectData())) .setStatus(businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(businessObjectDataStatusCode)); resultUploadSingleInitiationResponse.getTargetBusinessObjectData().setStatus(businessObjectDataStatusCode); // Return the initiate upload single response. return resultUploadSingleInitiationResponse; }
@Test public void testPerformCompleteUploadSingleMessageTargetBusinessObjectDataStatusNotUploading() { uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting(); UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper .createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, FILE_NAME)); String filePath = resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath(); // Create a business object data status. businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS); // Update the status of the target business object data so it would not be "UPLOADING". businessObjectDataStatusService.updateBusinessObjectDataStatus( businessObjectDataHelper.getBusinessObjectDataKey(resultUploadSingleInitiationResponse.getTargetBusinessObjectData()), new BusinessObjectDataStatusUpdateRequest(BDATA_STATUS)); // Try to complete the upload, when target business object data status is not "UPLOADING". UploadDownloadServiceImpl.CompleteUploadSingleMessageResult result = uploadDownloadService.performCompleteUploadSingleMessage(filePath); assertEquals(BusinessObjectDataStatusEntity.UPLOADING, result.getSourceOldBusinessObjectDataStatus()); assertNull(result.getSourceNewBusinessObjectDataStatus()); assertEquals(BDATA_STATUS, result.getTargetOldBusinessObjectDataStatus()); assertNull(result.getTargetNewBusinessObjectDataStatus()); }
@Test public void testPerformCompleteUploadSingleMessageSourceBusinessObjectDataStatusNotUploading() { uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting(); UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper .createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, FILE_NAME)); String filePath = resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath(); // Create a business object data status. businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS); // Update the status of the source business object data so it would not be "UPLOADING". businessObjectDataStatusService.updateBusinessObjectDataStatus( businessObjectDataHelper.getBusinessObjectDataKey(resultUploadSingleInitiationResponse.getSourceBusinessObjectData()), new BusinessObjectDataStatusUpdateRequest(BDATA_STATUS)); // Try to complete the upload, when source business object data status is not "UPLOADING". UploadDownloadServiceImpl.CompleteUploadSingleMessageResult result = uploadDownloadService.performCompleteUploadSingleMessage(filePath); assertEquals(BDATA_STATUS, result.getSourceOldBusinessObjectDataStatus()); assertNull(result.getSourceNewBusinessObjectDataStatus()); assertEquals(BusinessObjectDataStatusEntity.UPLOADING, result.getTargetOldBusinessObjectDataStatus()); assertNull(result.getTargetNewBusinessObjectDataStatus()); }
String filePath = resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath();