List of usage examples for org.apache.commons.lang3.time DateUtils addDays
public static Date addDays(final Date date, final int amount)
From source file:org.cerberus.servlet.crud.countryenvironment.ReadApplicationObjectImage.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . java 2 s. co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs * @throws CerberusException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException { String charset = request.getCharacterEncoding(); String application = ParameterParserUtil .parseStringParamAndDecodeAndSanitize(request.getParameter("application"), "", charset); String object = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("object"), "", charset); int width = (!StringUtils.isEmpty(request.getParameter("w"))) ? Integer.valueOf(request.getParameter("w")) : -1; int height = (!StringUtils.isEmpty(request.getParameter("h"))) ? Integer.valueOf(request.getParameter("h")) : -1; ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IApplicationObjectService applicationObjectService = appContext.getBean(IApplicationObjectService.class); BufferedImage image = applicationObjectService.readImageByKey(application, object); BufferedImage b; if (image != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); /** * If width and height not defined, get image in real size */ if (width == -1 && height == -1) { b = image; } else { ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, height, true)); rop.setNumberOfThreads(4); b = rop.filter(image, null); } ImageIO.write(b, "png", baos); // byte[] bytesOut = baos.toByteArray(); } else { // create a buffered image ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes); b = ImageIO.read(bis); bis.close(); } response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); ImageIO.write(b, "png", response.getOutputStream()); }
From source file:org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionMedia.java
private void returnImage(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) throws IOException { int width = (!StringUtils.isEmpty(request.getParameter("w"))) ? Integer.valueOf(request.getParameter("w")) : 150;/*www . j a va 2 s. c o m*/ int height = (!StringUtils.isEmpty(request.getParameter("h"))) ? Integer.valueOf(request.getParameter("h")) : 100; Boolean real = request.getParameter("r") != null; BufferedImage image = null; BufferedImage b = null; filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator); File picture = new File(filePath + tc.getFileName()); LOG.debug("Accessing File : " + picture.getAbsolutePath()); try { if (real) { b = ImageIO.read(picture); ImageIO.write(b, "png", response.getOutputStream()); } else { image = ImageIO.read(picture); ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, height, true)); rop.setNumberOfThreads(4); b = rop.filter(image, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(b, "png", baos); } } catch (IOException e) { } response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Type", "PNG"); response.setHeader("Description", tc.getFileDesc()); ImageIO.write(b, "png", response.getOutputStream()); }
From source file:org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionMedia.java
private void returnFile(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {//from ww w. j ava 2 s . c o m String everything = ""; filePath = StringUtil.addSuffixIfNotAlready(filePath, "/"); LOG.debug("Accessing File : " + filePath + tc.getFileName()); try (FileInputStream inputStream = new FileInputStream(filePath + tc.getFileName())) { everything = IOUtils.toString(inputStream); response.getWriter().print(everything); } catch (FileNotFoundException e) { } catch (IOException e) { } response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Type", tc.getFileType()); response.setHeader("Description", tc.getFileDesc()); }
From source file:org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionMedia.java
private void returnText(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {/*from ww w . j a v a2s .c o m*/ response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Type", tc.getFileType()); response.setHeader("Description", tc.getFileDesc()); }
From source file:org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionMedia.java
private void returnNotSupported(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) { response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString()); response.setHeader("Type", tc.getFileType()); }
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,/* w w w . ja v a 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 a v a 2 s .c o m*/ 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 w w w . ja v a 2s.co m * @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);// ww w . j ava 2 s. c o 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(); } }
From source file:org.foxbpm.calendar.mybatis.cmd.GetWorkCalendarEndTimeCmd.java
public Date execute(CommandContext commandContext) { //?//from w ww.j a v a 2 s.c o m Calendar calendar = Calendar.getInstance(); calendar.setTime(begin); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH) + 1; day = calendar.get(Calendar.DATE); // calendarTypeEntity = getCalendarTypeById(ruleId); //?? initCalendarType(calendarTypeEntity); CalendarRuleEntity calendarRuleEntity = null; // for (int k = 0; k < calendarTypeEntity.getCalendarRuleEntities().size(); k++) { CalendarRuleEntity calRuleEntity = calendarTypeEntity.getCalendarRuleEntities().get(k); //?? if (calRuleEntity.getStatus() == FREESTATUS && calRuleEntity.getWorkdate() != null && calRuleEntity.getYear() == year && DateUtils.isSameDay(calRuleEntity.getWorkdate(), begin)) { // if (calRuleEntity.getCalendarPartEntities().size() == 0) { begin = DateUtils.addDays(begin, 1); calendar.setTime(begin); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); begin = calendar.getTime(); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH) + 1; day = calendar.get(Calendar.DATE); calendar.get(Calendar.HOUR); calendar.get(Calendar.MINUTE); calendar.get(Calendar.SECOND); } // ? ?? else { calendarRuleEntity = getCalendarRuleEntityWithHoliday(calRuleEntity); } } //? if (calRuleEntity.getWeek() != 0 && calRuleEntity.getYear() == year && calRuleEntity.getWeek() == DateCalUtils.dayForWeek(begin)) { calendarRuleEntity = calRuleEntity; } //? if (calendarRuleEntity == null) { continue; } // else { Calendar endCalendar = Calendar.getInstance(); Date endDate = CalculateEndTime(calendarRuleEntity); endCalendar.setTime(endDate); log.debug("" + endCalendar.getTime()); return endDate; } } log.debug("?"); return null; }