/** * Adds a number of days to a timestamp returning a new object. The original {@code Timestamp} is unchanged. * * @param timestamp the timestamp, not null * @param amount the amount to add, may be negative * * @return the new {@code Timestamp} with the amount added */ public static Timestamp addDays(Timestamp timestamp, int amount) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timestamp.getTime()); return new Timestamp(addDays(calendar.getTime(), amount).getTime()); }
/** * Adds a number of days to a timestamp returning a new object. The original {@code Timestamp} is unchanged. * * @param timestamp the timestamp, not null * @param amount the amount to add, may be negative * * @return the new {@code Timestamp} with the amount added */ public static Timestamp addDays(Timestamp timestamp, int amount) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timestamp.getTime()); return new Timestamp(addDays(calendar.getTime(), amount).getTime()); }
@Test public void testAddDays() { Timestamp testTimestamp = Timestamp.valueOf("2015-12-21 10:34:11"); int daysDiff = 99; assertEquals(Timestamp.valueOf("2016-03-29 10:34:11"), HerdDateUtils.addDays(testTimestamp, daysDiff)); assertEquals(testTimestamp, HerdDateUtils.addDays(testTimestamp, 0)); assertEquals(Timestamp.valueOf("2015-09-13 10:34:11"), HerdDateUtils.addDays(testTimestamp, -daysDiff)); }
Timestamp updatedOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -updatedOnThresholdInDays); Timestamp createdOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -storagePolicyRuleValue); Date primaryPartitionValueThreshold = new Date(HerdDateUtils.addDays(currentTimestamp, -storagePolicyRuleValue).getTime());
Timestamp updatedOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -updatedOnThresholdInDays); Timestamp createdOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -storagePolicyRuleValue); Date primaryPartitionValueThreshold = new Date(HerdDateUtils.addDays(currentTimestamp, -storagePolicyRuleValue).getTime());
storageUnitEntities.get(1).setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, 1)); storageUnitEntities.get(2).setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, -1)); storageUnitEntities.get(3).setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(4).setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(5).setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, -2));
Date primaryPartitionValueThreshold = new Date(HerdDateUtils.addDays(currentTimestamp, -retentionPeriodInDays).getTime());
Date primaryPartitionValueThreshold = new Date(HerdDateUtils.addDays(currentTimestamp, -retentionPeriodInDays).getTime());
/** * Apply a predicate for registration date range filter. * * @param registrationDateRangeFilter the registration date range filter, not null * @param businessObjectDataEntity the business object data entity * @param builder the query builder * @param predicate the predicate to be updated * * @return the predicate with added registration date range filter */ private Predicate applyRegistrationDateRangeFilter(RegistrationDateRangeFilter registrationDateRangeFilter, Root<BusinessObjectDataEntity> businessObjectDataEntity, CriteriaBuilder builder, Predicate predicate) { // Apply predicate for registration start date and removed the time portion of the date. if (registrationDateRangeFilter.getStartRegistrationDate() != null) { predicate = builder.and(predicate, builder.greaterThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.createdOn), HerdDateUtils.resetTimeToMidnight(registrationDateRangeFilter.getStartRegistrationDate()))); } // Apply predicate for registration end date. Removed time portion of the date and added one day to get the result till the end of the day if (registrationDateRangeFilter.getEndRegistrationDate() != null) { predicate = builder.and(predicate, builder.lessThan(businessObjectDataEntity.get(BusinessObjectDataEntity_.createdOn), HerdDateUtils.addDays(HerdDateUtils.resetTimeToMidnight(registrationDateRangeFilter.getEndRegistrationDate()), 1))); } return predicate; }
storageUnitEntities.get(1).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, 1)); storageUnitEntities.get(2).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -1)); storageUnitEntities.get(3).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(4).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(5).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(6).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
/** * Apply a predicate for registration date range filter. * * @param registrationDateRangeFilter the registration date range filter, not null * @param businessObjectDataEntity the business object data entity * @param builder the query builder * @param predicate the predicate to be updated * * @return the predicate with added registration date range filter */ private Predicate applyRegistrationDateRangeFilter(RegistrationDateRangeFilter registrationDateRangeFilter, Root<BusinessObjectDataEntity> businessObjectDataEntity, CriteriaBuilder builder, Predicate predicate) { // Apply predicate for registration start date and removed the time portion of the date. if (registrationDateRangeFilter.getStartRegistrationDate() != null) { predicate = builder.and(predicate, builder.greaterThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.createdOn), HerdDateUtils.resetTimeToMidnight(registrationDateRangeFilter.getStartRegistrationDate()))); } // Apply predicate for registration end date. Removed time portion of the date and added one day to get the result till the end of the day if (registrationDateRangeFilter.getEndRegistrationDate() != null) { predicate = builder.and(predicate, builder.lessThan(businessObjectDataEntity.get(BusinessObjectDataEntity_.createdOn), HerdDateUtils.addDays(HerdDateUtils.resetTimeToMidnight(registrationDateRangeFilter.getEndRegistrationDate()), 1))); } return predicate; }
storageUnitEntities.get(1).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, 1)); storageUnitEntities.get(2).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -1)); storageUnitEntities.get(3).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(4).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(5).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2)); storageUnitEntities.get(6).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
storageUnitEntity.setFinalDestroyOn(HerdDateUtils.addDays(currentTime, businessObjectDataDestroyDto.getFinalDestroyInDays()));
storageUnitEntity.setFinalDestroyOn(HerdDateUtils.addDays(currentTime, businessObjectDataDestroyDto.getFinalDestroyInDays()));
@Test public void testPrepareToInitiateRestore() 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 database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Get the current time and compute the expected timestamp value. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); Timestamp expectedTimestamp = HerdDateUtils.addDays(currentTime, EXPIRATION_IN_DAYS); // Execute a before step for the initiate a business object data restore request. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); // Validate that restore expiration time is set correctly on the storage unit. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); assertNotNull(storageUnitEntity.getRestoreExpirationOn()); Long differenceInMilliseconds = storageUnitEntity.getRestoreExpirationOn().getTime() - expectedTimestamp.getTime(); assertTrue(Math.abs(differenceInMilliseconds) < 1000); }
storageUnitEntity.setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, localExpirationInDays));
storageUnitEntity.setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, localExpirationInDays));
start = HerdDateUtils.getXMLGregorianCalendarValue(HerdDateUtils.addDays(businessObjectDataEntity.getCreatedOn(), -1)); end = HerdDateUtils.getXMLGregorianCalendarValue(HerdDateUtils.addDays(businessObjectDataEntity.getCreatedOn(), 1)); businessObjectDataSearchKey.setRegistrationDateRangeFilter(new RegistrationDateRangeFilter(start, end)); List<BusinessObjectData> result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE); start = HerdDateUtils.getXMLGregorianCalendarValue(HerdDateUtils.addDays(businessObjectDataEntity.getCreatedOn(), -1)); businessObjectDataSearchKey.setRegistrationDateRangeFilter(new RegistrationDateRangeFilter(start, null)); result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE); end = HerdDateUtils.getXMLGregorianCalendarValue(HerdDateUtils.addDays(businessObjectDataEntity.getCreatedOn(), 1)); businessObjectDataSearchKey.setRegistrationDateRangeFilter(new RegistrationDateRangeFilter(null, end)); result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE); start = HerdDateUtils.getXMLGregorianCalendarValue(HerdDateUtils.addDays(businessObjectDataEntity.getCreatedOn(), 1)); businessObjectDataSearchKey.setRegistrationDateRangeFilter(new RegistrationDateRangeFilter(start, null)); result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE); end = HerdDateUtils.getXMLGregorianCalendarValue(HerdDateUtils.addDays(businessObjectDataEntity.getCreatedOn(), -1)); businessObjectDataSearchKey.setRegistrationDateRangeFilter(new RegistrationDateRangeFilter(null, end)); result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE);