BusinessObjectDataStorageUnitServiceImpl implements BusinessObjectDataStorageUnitService { protected void validateBusinessObjectDataStorageUnitCreateRequest(BusinessObjectDataStorageUnitCreateRequest request) { Assert.notNull(request, "A business object data storage unit create request must be specified."); storageUnitHelper.validateBusinessObjectDataStorageUnitKey(request.getBusinessObjectDataStorageUnitKey()); if (BooleanUtils.isTrue(request.isDiscoverStorageFiles())) { Assert.isTrue(request.getStorageDirectory() != null, "A storage directory must be specified when discovery of storage files is enabled."); Assert.isTrue(CollectionUtils.isEmpty(request.getStorageFiles()), "Storage files cannot be specified when discovery of storage files is enabled."); } else { Assert.isTrue(request.getStorageDirectory() != null || CollectionUtils.isNotEmpty(request.getStorageFiles()), "A storage directory or at least one storage file must be specified when discovery of storage files is not enabled."); } if (request.getStorageDirectory() != null) { Assert.hasText(request.getStorageDirectory().getDirectoryPath(), "A storage directory path must be specified."); request.getStorageDirectory().setDirectoryPath(request.getStorageDirectory().getDirectoryPath().trim()); } if (CollectionUtils.isNotEmpty(request.getStorageFiles())) { storageFileHelper.validateCreateRequestStorageFiles(request.getStorageFiles()); } }  @PublishNotificationMessages @NamespacePermission(fields = "#request.businessObjectDataStorageUnitKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnit(BusinessObjectDataStorageUnitCreateRequest request);  }
@Test public void testValidateBusinessObjectDataStorageUnitCreateRequestDirectoryOnlyRegistration() { BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME); businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest( new BusinessObjectDataStorageUnitCreateRequest(businessObjectDataStorageUnitKey, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, DISCOVER_STORAGE_FILES)); verify(storageUnitHelper).validateBusinessObjectDataStorageUnitKey(businessObjectDataStorageUnitKey); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateBusinessObjectDataStorageUnitCreateRequestInvalidParameters() { try { businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(null); fail(); } catch (IllegalArgumentException e) { assertEquals("A business object data storage unit create request must be specified.", e.getMessage()); } try { businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest( new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, DISCOVER_STORAGE_FILES)); fail(); } catch (IllegalArgumentException e) { assertEquals("A storage directory must be specified when discovery of storage files is enabled.", e.getMessage()); } try { businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest( new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), new StorageDirectory(STORAGE_DIRECTORY_PATH), Collections.singletonList(new StorageFile(FILE_NAME, FILE_SIZE, ROW_COUNT)), DISCOVER_STORAGE_FILES)); fail(); } catch (IllegalArgumentException e) { assertEquals("Storage files cannot be specified when discovery of storage files is enabled.", e.getMessage()); } try { businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest( new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)); fail(); } catch (IllegalArgumentException e) { assertEquals("A storage directory or at least one storage file must be specified when discovery of storage files is not enabled.", e.getMessage()); } try { businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest( new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), new StorageDirectory(BLANK_TEXT), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)); fail(); } catch (IllegalArgumentException e) { assertEquals("A storage directory path must be specified.", e.getMessage()); } }