List of usage examples for org.apache.commons.lang3.time DateFormatUtils format
public static String format(final Calendar calendar, final String pattern)
Formats a calendar into a specific pattern.
From source file:architecture.common.spring.jdbc.core.ExtendedJdbcTemplate.java
public int[] batchUpdate(String sql, final List<ParameterMapping> parameterMappings, final List<Map<String, Object>> parameters) { return batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { Map<String, Object> row = parameters.get(i); for (ParameterMapping mapping : parameterMappings) { JdbcType jdbcType = mapping.getJdbcType(); Object value = row.get(mapping.getProperty()); Object valueToUse = value; if (valueToUse == null && mapping.getJavaType() == Date.class) { valueToUse = new Date(); }/*from w w w . j a va 2 s . co m*/ if (valueToUse instanceof Date && jdbcType == JdbcType.VARCHAR) { valueToUse = DateFormatUtils.format((Date) valueToUse, mapping.getPattern()); } if (valueToUse instanceof String && jdbcType == JdbcType.VARCHAR) { String stringValue = (String) valueToUse; if (!StringUtils.isEmpty(mapping.getEncoding())) { if (!StringUtils.isEmpty(stringValue)) { String[] encoding = StringUtils.split(mapping.getEncoding(), ">"); try { if (encoding.length == 2) valueToUse = new String(stringValue.getBytes(encoding[0]), encoding[1]); else if (encoding.length == 1) valueToUse = new String(stringValue.getBytes(), encoding[0]); } catch (UnsupportedEncodingException e) { logger.error(e); } } } } if (valueToUse == null) ps.setNull(mapping.getIndex(), jdbcType.TYPE_CODE); else ps.setObject(mapping.getIndex(), valueToUse, jdbcType.TYPE_CODE); } } public int getBatchSize() { return parameters.size(); } }); }
From source file:com.norconex.commons.lang.file.FileUtil.java
/** * Creates (if not already existing) a series of directories reflecting * a date and time, up to the seconds, under a given parent directory. * For example,//from ww w . j ava 2s. co m * a date of 2000-12-31T13:34:12 will create the following directory * structure: * <code> * /<parentDir>/2000/12/31/13/34/12/ * </code> * @param parentDir the parent directory where to create date directories * @param dateTime the date to create directories from * @return the directory representing the full path created * @throws IOException if the parent directory is not valid */ public static File createDateTimeDirs(File parentDir, Date dateTime) throws IOException { if (parentDir == null) { throw new IOException("Parent directory cannot be null."); } if (dateTime == null) { throw new IOException("Date cannot be null."); } if (parentDir.exists() && !parentDir.isDirectory()) { throw new IOException("Parent directory \"" + parentDir + "\" already exists and is not a directory."); } File dateDir = new File( parentDir.getAbsolutePath() + "/" + DateFormatUtils.format(dateTime, "yyyy/MM/dd/HH/mm/ss")); FileUtils.forceMkdir(dateDir); return dateDir; }
From source file:com.daphne.es.showcase.excel.service.ExcelDataService.java
private String generateFilename(final User user, final String contextRootPath, Integer index, final String extension) { String path = FilenameUtils.concat(contextRootPath, storePath); path = FilenameUtils.concat(path, user.getUsername()); path = FilenameUtils.concat(path,// w w w. jav a 2 s. co m EXPORT_FILENAME_PREFIX + "_" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS") + (index != null ? ("_" + index) : "") + "." + extension); File file = new File(path); if (!file.exists()) { File parentFile = file.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } return path; } return generateFilename(user, contextRootPath, extension); }
From source file:com.feilong.core.date.DateUtil.java
/** * <code>date</code>???./*from w ww .ja v a 2s . co m*/ * * <pre class="code"> * DateUtil.toString(Tue Oct 16 23:49:21 CST 2012,DatePattern.COMMON_DATE_AND_TIME_WITH_MILLISECOND) =2012-10-16 23:49:21.525 * </pre> * * @param date * ? * @param datePattern * ? {@link DatePattern} * @return <code>date</code> null, {@link NullPointerException}<br> * <code>pattern</code> null, {@link NullPointerException}<br> * <code>pattern</code> blank, {@link IllegalArgumentException}<br> * ? {@link java.util.Locale#getDefault()},{@link java.text.DateFormat#format(Date)} * @see org.apache.commons.lang3.time.DateFormatUtils#format(Date, String) * @see "org.joda.time.base.AbstractDateTime#toString(String)" * @see <a href="http://stackoverflow.com/questions/5683728/convert-java-util-date-to-string">convert-java-util-date-to-string</a> * @see <a href="http://stackoverflow.com/questions/4772425/change-date-format-in-a-java-string">change-date-format-in-a-java-string</a> * @since 1.6.0 */ public static String toString(Date date, String datePattern) { return DateFormatUtils.format(date, datePattern); }
From source file:org.apache.marmotta.maven.plugins.buildinfo.ProjectInfoProvider.java
public Map<String, String> getInfo(MavenProject project) { Date date = new Date(); Map<String, String> info = new LinkedHashMap<String, String>(); info.put("project.name", project.getName()); info.put("build.module", project.getArtifactId()); info.put("build.version", project.getVersion()); info.put("build.timestamp", DateFormatUtils.format(date, "EEE, dd MMM yyyy HH:mm:ss z")); return info;/*from ww w . j av a2 s . com*/ }
From source file:org.bahmni.feed.openelis.feed.service.impl.AccessionService.java
private String toISODateFormat(Timestamp timestamp) { return DateFormatUtils.format(timestamp.getTime(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); }
From source file:org.finra.herd.dao.BusinessObjectDataDaoTest.java
@Test public void testBusinessObjectDataSearchWithRetentionExpirationFilterPartitionValueRetentionType() { // Create a partition value offset by test retention period in days from today. java.util.Date retentionThresholdDate = DateUtils.addDays(new java.util.Date(), -1 * RETENTION_PERIOD_DAYS); String partitionValue = DateFormatUtils.format(retentionThresholdDate, AbstractHerdDao.DEFAULT_SINGLE_DAY_DATE_MASK); // Create business object data entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValue, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, NO_LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.INVALID); businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValue, SUBPARTITION_VALUES, SECOND_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID); // Execute the search query by passing business object data search key parameters, except for filters. assertEquals(2,/*from www . ja va 2 s . c o m*/ businessObjectDataDao.searchBusinessObjectData( new BusinessObjectDataSearchKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, NO_FILTER_ON_RETENTION_EXPIRATION), DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE).size()); // Get retention type entity for PARTITION_VALUE. RetentionTypeEntity retentionTypeEntity = retentionTypeDao .getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE); assertNotNull(retentionTypeEntity); // Configure retention information for the business object format, so the test business object date is not expired per retention configuration. businessObjectDataEntity.getBusinessObjectFormat().setRetentionType(retentionTypeEntity); businessObjectDataEntity.getBusinessObjectFormat().setRetentionPeriodInDays(RETENTION_PERIOD_DAYS + 1); // Validate the results by executing search request with retention expiration filter enabled. // Business object data is expected not to be selected, since it is not expired yet per retention configuration. assertEquals(0, businessObjectDataDao.searchBusinessObjectData( new BusinessObjectDataSearchKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, FILTER_ON_RETENTION_EXPIRATION), DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE).size()); // Configure retention information for the business object format, so the test // business object data partition value is the same as retention expiration date. businessObjectDataEntity.getBusinessObjectFormat().setRetentionPeriodInDays(RETENTION_PERIOD_DAYS); // Validate the results by executing search request with retention expiration filter enabled. // Business object data is expected not to be selected, since it is not expired yet per retention configuration. assertEquals(0, businessObjectDataDao.searchBusinessObjectData( new BusinessObjectDataSearchKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, FILTER_ON_RETENTION_EXPIRATION), DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE).size()); // Configure retention information for the business object format, so the test business object date is expired per retention configuration. businessObjectDataEntity.getBusinessObjectFormat().setRetentionPeriodInDays(RETENTION_PERIOD_DAYS - 1); // Validate the results by executing search request with retention expiration filter enabled. // Business object data is still expected to get selected as it is expired per retention configuration. assertEquals(2, businessObjectDataDao.searchBusinessObjectData( new BusinessObjectDataSearchKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, FILTER_ON_RETENTION_EXPIRATION), DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE).size()); }
From source file:org.finra.herd.dao.BusinessObjectDataDaoTest.java
@Test public void testBusinessObjectDataSearchWithRetentionExpirationFilterMultipleFormats() { int retentionPeriod = 180; java.util.Date date = DateUtils.addDays(new java.util.Date(), -1 * retentionPeriod); String partitionValueDate = DateFormatUtils.format(date, AbstractHerdDao.DEFAULT_SINGLE_DAY_DATE_MASK); BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "VALID"); BusinessObjectDataEntity businessObjectDataEntity2 = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID"); BusinessObjectDataEntity businessObjectDataEntity3 = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID"); BusinessObjectDataEntity businessObjectDataEntity4 = businessObjectDataDaoTestHelper .createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID"); businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID"); RetentionTypeEntity existingRetentionType = retentionTypeDao .getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE); if (existingRetentionType == null) { retentionTypeDaoTestHelper.createRetentionTypeEntity(RetentionTypeEntity.PARTITION_VALUE); }//from ww w.j av a2s . c om businessObjectDataEntity.getBusinessObjectFormat().setRetentionType(existingRetentionType); businessObjectDataEntity.getBusinessObjectFormat().setRetentionPeriodInDays(retentionPeriod - 1); businessObjectDataEntity2.getBusinessObjectFormat().setRetentionType(existingRetentionType); businessObjectDataEntity2.getBusinessObjectFormat().setRetentionPeriodInDays(retentionPeriod - 1); businessObjectDataEntity3.getBusinessObjectFormat().setRetentionType(existingRetentionType); businessObjectDataEntity3.getBusinessObjectFormat().setRetentionPeriodInDays(null); RetentionTypeEntity notFoundRetentionTypeEntity = retentionTypeDaoTestHelper .createRetentionTypeEntity(RetentionTypeEntity.PARTITION_VALUE + "NOTFOUND"); businessObjectDataEntity4.getBusinessObjectFormat().setRetentionType(notFoundRetentionTypeEntity); businessObjectDataEntity4.getBusinessObjectFormat().setRetentionPeriodInDays(retentionPeriod); BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey(); businessObjectDataSearchKey.setNamespace(NAMESPACE); businessObjectDataSearchKey.setBusinessObjectDefinitionName(BDEF_NAME); businessObjectDataSearchKey.setFilterOnRetentionExpiration(true); List<BusinessObjectData> result = businessObjectDataDao .searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE); assertEquals(2, result.size()); }
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
/** * Apply retention expiration filter to the main query predicate. * * @param businessObjectDataSearchKey the business object data search key * @param businessObjectDataEntityRoot the criteria root which is a business object data entity * @param businessObjectFormatEntityJoin the join with the business object format table * @param builder the criteria builder//from www. j a v a2s . com * @param mainQueryPredicate the main query predicate to be updated * * @return the updated main query predicate */ private Predicate applyRetentionExpirationFilter(BusinessObjectDataSearchKey businessObjectDataSearchKey, Root<BusinessObjectDataEntity> businessObjectDataEntityRoot, Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin, CriteriaBuilder builder, Predicate mainQueryPredicate) { // Create a business object definition key per specified search key. BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey( businessObjectDataSearchKey.getNamespace(), businessObjectDataSearchKey.getBusinessObjectDefinitionName()); // Get latest versions of all business object formats that registered with the business object definition. List<BusinessObjectFormatEntity> businessObjectFormatEntities = businessObjectFormatDao .getLatestVersionBusinessObjectFormatsByBusinessObjectDefinition(businessObjectDefinitionKey); // Create a result predicate to join all retention expiration predicates created per selected business object formats. Predicate businessObjectDefinitionRetentionExpirationPredicate = null; // Get the current database timestamp to be used to select expired business object data per BDATA_RETENTION_DATE retention type. Timestamp currentTimestamp = getCurrentTimestamp(); // Create a predicate for each business object format with the retention information. for (BusinessObjectFormatEntity businessObjectFormatEntity : businessObjectFormatEntities) { if (businessObjectFormatEntity.getRetentionType() != null) { // Create a retention expiration predicate for this business object format. Predicate businessObjectFormatRetentionExpirationPredicate = null; if (StringUtils.equals(businessObjectFormatEntity.getRetentionType().getCode(), RetentionTypeEntity.BDATA_RETENTION_DATE)) { // Select business object data that has expired per its explicitly configured retention expiration date. businessObjectFormatRetentionExpirationPredicate = builder.lessThan( businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.retentionExpiration), currentTimestamp); } else if (StringUtils.equals(businessObjectFormatEntity.getRetentionType().getCode(), RetentionTypeEntity.PARTITION_VALUE) && businessObjectFormatEntity.getRetentionPeriodInDays() != null) { // Compute the retention expiration date and convert it to the date format to match against partition values. String retentionExpirationDate = DateFormatUtils.format( DateUtils.addDays(new Date(), -1 * businessObjectFormatEntity.getRetentionPeriodInDays()), DEFAULT_SINGLE_DAY_DATE_MASK); // Create a predicate to compare business object data primary partition value against the retention expiration date. businessObjectFormatRetentionExpirationPredicate = builder.lessThan( businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue), retentionExpirationDate); } // If it was initialize, complete processing of retention expiration predicate for this business object format. if (businessObjectFormatRetentionExpirationPredicate != null) { // Update the predicate to match this business object format w/o version. businessObjectFormatRetentionExpirationPredicate = builder.and( businessObjectFormatRetentionExpirationPredicate, builder.equal( builder.upper( businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatEntity.getUsage().toUpperCase())); businessObjectFormatRetentionExpirationPredicate = builder.and( businessObjectFormatRetentionExpirationPredicate, builder.equal(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.fileType), businessObjectFormatEntity.getFileType())); // Add this business object format specific retention expiration predicate to other // retention expiration predicates created for the specified business object definition. if (businessObjectDefinitionRetentionExpirationPredicate == null) { businessObjectDefinitionRetentionExpirationPredicate = businessObjectFormatRetentionExpirationPredicate; } else { businessObjectDefinitionRetentionExpirationPredicate = builder.or( businessObjectDefinitionRetentionExpirationPredicate, businessObjectFormatRetentionExpirationPredicate); } } } } // Fail if no retention expiration predicates got created per specified business objject definition. Assert.notNull(businessObjectDefinitionRetentionExpirationPredicate, String.format( "Business object definition with name \"%s\" and namespace \"%s\" has no business object formats with supported retention type.", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace())); // Add created business object definition retention expiration predicate to the main query predicate passed to this method and return the result. return builder.and(mainQueryPredicate, businessObjectDefinitionRetentionExpirationPredicate); }
From source file:org.finra.herd.service.BusinessObjectDataServiceDestroyBusinessObjectDataTest.java
@Test public void testDestroyBusinessObjectData() throws Exception { // Create a primary partition value that satisfies the retention threshold check. String primaryPartitionValue = DateFormatUtils.format( DateUtils.addDays(new Date(), -1 * (RETENTION_PERIOD_DAYS + 1)), AbstractHerdDao.DEFAULT_SINGLE_DAY_DATE_MASK); // Build the expected S3 key prefix for test business object data. String s3KeyPrefix = getExpectedS3KeyPrefix(BDEF_NAMESPACE, DATA_PROVIDER_NAME, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, primaryPartitionValue, null, null, DATA_VERSION);//from ww w.j ava 2 s . co m // Create S3FileTransferRequestParamsDto to access the S3 bucket location. // Since test S3 key prefix represents a directory, we add a trailing '/' character to it. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = S3FileTransferRequestParamsDto.builder() .withS3BucketName(S3_BUCKET_NAME).withS3KeyPrefix(s3KeyPrefix + "/").build(); // Create an S3 storage with the relative attributes. storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, Arrays.asList( new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), AbstractServiceTest.S3_BUCKET_NAME), new Attribute( configurationHelper .getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), AbstractServiceTest.S3_KEY_PREFIX_VELOCITY_TEMPLATE), new Attribute( configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), Boolean.TRUE.toString()), new Attribute( configurationHelper .getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), Boolean.TRUE.toString()))); // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, primaryPartitionValue, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create and persist a storage unit in the storage. StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH); // Add storage files to the storage unit. for (String filePath : LOCAL_FILES) { storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, s3KeyPrefix + "/" + filePath, FILE_SIZE_1_KB, ROW_COUNT_1000); } // Get the storage files. List<StorageFile> storageFiles = storageFileHelper .createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()); // Get the business object format entity. BusinessObjectFormatEntity businessObjectFormatEntity = storageUnitEntity.getBusinessObjectData() .getBusinessObjectFormat(); // Set the retention information for the business object format, which is the latest version business object format. businessObjectFormatEntity .setRetentionType(retentionTypeDao.getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE)); businessObjectFormatEntity.setRetentionPeriodInDays(RETENTION_PERIOD_DAYS); businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity); // Override configuration to specify some settings required for testing. Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.S3_OBJECT_DELETE_TAG_KEY.getKey(), S3_OBJECT_TAG_KEY); overrideMap.put(ConfigurationValue.S3_OBJECT_DELETE_TAG_VALUE.getKey(), S3_OBJECT_TAG_VALUE); overrideMap.put(ConfigurationValue.S3_OBJECT_DELETE_ROLE_ARN.getKey(), S3_OBJECT_TAGGER_ROLE_ARN); overrideMap.put(ConfigurationValue.S3_OBJECT_DELETE_ROLE_SESSION_NAME.getKey(), S3_OBJECT_TAGGER_ROLE_SESSION_NAME); modifyPropertySourceInEnvironment(overrideMap); try { // Put relative S3 files into the S3 bucket. for (StorageFile storageFile : storageFiles) { s3Operations.putObject(new PutObjectRequest(S3_BUCKET_NAME, storageFile.getFilePath(), new ByteArrayInputStream(new byte[storageFile.getFileSizeBytes().intValue()]), null), null); } // Add one more S3 file, which is an unregistered non-empty file. // The business object data destroy logic expected not to fail when detecting an unregistered S3 file. String unregisteredS3FilePath = s3KeyPrefix + "/unregistered.txt"; s3Operations.putObject(new PutObjectRequest(S3_BUCKET_NAME, unregisteredS3FilePath, new ByteArrayInputStream(new byte[1]), null), null); // Assert that we got all files listed under the test S3 prefix. assertEquals(storageFiles.size() + 1, s3Dao.listDirectory(s3FileTransferRequestParamsDto).size()); // Request to destroy business object data. BusinessObjectData result = businessObjectDataService.destroyBusinessObjectData(businessObjectDataKey); // Validate the result. assertNotNull(result); assertEquals(storageUnitEntity.getBusinessObjectData().getId(), Integer.valueOf(result.getId())); // Validate the status of the storage unit entity. assertEquals(StorageUnitStatusEntity.DISABLED, storageUnitEntity.getStatus().getCode()); // Validate the status of the business object data entity. assertEquals(BusinessObjectDataStatusEntity.DELETED, storageUnitEntity.getBusinessObjectData().getStatus().getCode()); // Validate that all registered S3 files are now tagged. for (StorageFile storageFile : storageFiles) { GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging( new GetObjectTaggingRequest(S3_BUCKET_NAME, storageFile.getFilePath()), null); assertEquals(Collections.singletonList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE)), getObjectTaggingResult.getTagSet()); } // Validate that unregistered S3 file is now tagged. GetObjectTaggingResult getObjectTaggingResult = s3Operations .getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, unregisteredS3FilePath), null); assertEquals(Collections.singletonList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE)), getObjectTaggingResult.getTagSet()); } finally { // Delete test files from S3 storage. if (!s3Dao.listDirectory(s3FileTransferRequestParamsDto).isEmpty()) { s3Dao.deleteDirectory(s3FileTransferRequestParamsDto); } s3Operations.rollback(); // Restore the property sources so we don't affect other tests. restorePropertySourceInEnvironment(); } }