List of usage examples for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY
long MILLIS_PER_DAY
To view the source code for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY.
Click Source Link
From source file:org.vpac.ndg.task.GraphicsFileCreatorTest.java
@Test public void testGraphicsFileCreator() throws TaskException, TaskInitialisationException, IOException { final String datasetName = "testDs"; String srcImageLocation = "../../data/small_landsat/LS7_ETM_095_082_20100116_B30.nc"; Path srcImage = Paths.get(srcImageLocation); // Set up source image Path tempDir = FileUtils.createTmpLocation(); Path uploadedFile = tempDir.resolve(srcImage.getFileName()); try {/*www . ja v a 2 s. c om*/ FileUtils.copy(srcImage, uploadedFile); } catch (IOException e) { throw new TaskException( String.format(Constant.ERR_COPY_FILE_FAILED, srcImageLocation, uploadedFile.toString())); } // Set up creation time final Date created = Utils.parseDate("2012-03-19"); // Set up resolution CellSize resolution = CellSize.m100; transformImage = new GraphicsFile(uploadedFile); transformImage.setResolution(resolution); // Set up dataset Dataset dataset = datasetDao.findDatasetByName(datasetName, resolution); if (dataset == null) { dataset = new Dataset(datasetName, resolution, DateUtils.MILLIS_PER_DAY); datasetDao.create(dataset); Band band = new Band("Band1", true, false); band.setNodata(transformImage.getFileInformation().getNoData()); band.setType(transformImage.getFileInformation().getDataType()); datasetDao.addBand(dataset.getId(), band); } // Get the timeslice for this upload TimeSlice timeSlice = datasetDao.findTimeSlice(dataset.getId(), created); if (timeSlice == null) { timeSlice = datasetDao.addTimeSlice(dataset.getId(), new TimeSlice(created)); } FileInformation fi = transformImage.getFileInformation(); Point<Integer> firstTile = nng.mapToTile(fi.getBbox().getUlCorner(), transformImage.getResolution()); Point<Integer> lastTile = nng.mapToTile(fi.getBbox().getLrCorner(), transformImage.getResolution()); int expectedNumOfTiles = (lastTile.getX() - firstTile.getX() + 1) * (lastTile.getY() - firstTile.getY() + 1); // Create an empty container to capture all tilebands tilebands = new ArrayList<TileBand>(); tilebandCreator.setSource(transformImage.getBounds()); tilebandCreator.setTarget(tilebands); tilebandCreator.setTimeSlice(timeSlice); // FIXME: Get the actual target band from somewhere - e.g. add it as a // column to the Upload table. tilebandCreator.setBand(datasetDao.getBands(dataset.getId()).get(0)); List<GraphicsFile> sourceList = new ArrayList<GraphicsFile>(); sourceList.add(transformImage); tileTransformer.setSource(sourceList); tileTransformer.setTarget(tilebands); tileTransformer.setEpsgId(transformImage.getEpsgId()); // For testing not need to delete source and target tileTransformer.setCleanupSource(false); tileTransformer.setCleanupTarget(false); committer.setSource(tilebands); committer.setBounds(transformImage.getBounds()); committer.setTarget(timeSlice); taskPipeline = new TaskPipeline(); taskPipeline.addTask(tilebandCreator); taskPipeline.addTask(tileTransformer); taskPipeline.addTask(committer); taskPipeline.initialise(); try { // Run tasks as a transaction taskPipeline.run(); } catch (TaskException e) { log.error("TaskException {}", e); // Roll back tasks as a transaction taskPipeline.rollback(); throw e; } catch (RuntimeException e) { log.error("RuntimeException {}", e); // Roll back tasks as a transaction taskPipeline.rollback(); } // Cleaning up required for each task taskPipeline.finalise(); assertEquals(expectedNumOfTiles, tilebands.size()); List<GraphicsFile> images = new ArrayList<GraphicsFile>(); gfCreator.setSource(tilebands); gfCreator.setTarget(images); taskPipeline = new TaskPipeline(); taskPipeline.addTask(gfCreator); taskPipeline.initialise(); try { // Run tasks as a transaction taskPipeline.run(); } catch (TaskException e) { log.error("TaskException {}", e); // Roll back tasks as a transaction taskPipeline.rollback(); } catch (RuntimeException e) { log.error("RuntimeException {}", e); // Roll back tasks as a transaction taskPipeline.rollback(); } // Cleaning up required for each task taskPipeline.finalise(); // Remove test data in temporary upload location try { FileUtils.removeDirectory(tempDir); } catch (IOException e) { log.error("Could not delete temporary directory: {}", e); } }
From source file:org.vpac.ndg.task.TileAggregatorTest.java
@Before public void setUp() throws Exception { gdal.AllRegister();/*from www . ja v a 2 s .c o m*/ taskPipeline = new TaskPipeline(); final String datasetName = "testDs"; // Set up original image String originalFileLocation = "../../data/small_landsat/LS7_ETM_095_082_20100116_B30.nc"; Path originalImage = Paths.get(originalFileLocation); Assert.assertTrue(Files.exists(originalImage)); // Set up source image tempDir = FileUtils.createTmpLocation(); uploadedFile = tempDir.resolve(originalImage.getFileName()); try { FileUtils.copy(originalImage, uploadedFile); } catch (IOException e) { throw new TaskException( String.format(Constant.ERR_COPY_FILE_FAILED, originalFileLocation, uploadedFile.toString())); } sourceImage = new GraphicsFile(uploadedFile); sourceList = new ArrayList<GraphicsFile>(); sourceList.add(sourceImage); // Set up creation time final Date created = Utils.parseDate("2012-03-19"); // Set up resolution CellSize resolution = CellSize.m100; // Set up dataset Dataset dataset = datasetDao.findDatasetByName(datasetName, resolution); if (dataset == null) { dataset = new Dataset(datasetName, resolution, DateUtils.MILLIS_PER_DAY); datasetDao.create(dataset); } // Find or create band FileInformation fi = sourceImage.getFileInformation(); band = bandDao.find(dataset.getId(), "Band1"); if (band == null) { band = new Band("Band1", false, false); band.setNodata(fi.getNoData()); band.setType(fi.getDataType()); datasetDao.addBand(dataset.getId(), band); } else { //assertEquals("Band nodata value does not match import", band.getNodata(), fi.getNoData()); //assertEquals("Band data type does not match import", band.getType(), fi.getDataType()); } // Get the timeslice for this upload timeSlice = datasetDao.findTimeSlice(dataset.getId(), created); if (timeSlice == null) { timeSlice = datasetDao.addTimeSlice(dataset.getId(), new TimeSlice(created)); } FileInformation sourceFileInfo = sourceImage.getFileInformation(); // Get all required extents List<Tile> tiles = tileManager.getTiles(sourceFileInfo.getBbox(), resolution); source = new ArrayList<TileBand>(); for (Tile tile : tiles) { TileBand tileband = new TileBand(tile, band, timeSlice); source.add(tileband); log.debug("tileband: {}", tileband.getTileNameWithExtention()); } target = new ScalarReceiver<>(); }
From source file:org.vpac.ndg.task.TileBandCreatorTest.java
@Test public void testTilebandCreator() throws TaskException, TaskInitialisationException, IOException { final String datasetName = "testDs"; String srcImageLocation = "../../data/small_landsat/LS7_ETM_095_082_20100116_B30.nc"; Path srcImage = Paths.get(srcImageLocation); assertTrue(Files.exists(srcImage)); // Set up source image Path tempDir = FileUtils.createTmpLocation(); Path uploadedFile = tempDir.resolve(srcImage.getFileName()); try {/*from w ww . j ava2 s . c o m*/ FileUtils.copy(srcImage, uploadedFile); } catch (IOException e) { throw new TaskException( String.format(Constant.ERR_COPY_FILE_FAILED, srcImageLocation, uploadedFile.toString())); } // Set up creation time final Date created = Utils.parseDate("2012-03-19"); // Set up resolution CellSize resolution = CellSize.m100; transformImage = new GraphicsFile(uploadedFile); transformImage.setResolution(resolution); // Set up dataset Dataset dataset = datasetDao.findDatasetByName(datasetName, resolution); if (dataset == null) { dataset = new Dataset(datasetName, resolution, DateUtils.MILLIS_PER_DAY); datasetDao.create(dataset); } // Find or create band FileInformation fi = transformImage.getFileInformation(); Band band = bandDao.find(dataset.getId(), "Band1"); if (band == null) { band = new Band("Band1", false, false); band.setNodata(fi.getNoData()); band.setType(fi.getDataType()); datasetDao.addBand(dataset.getId(), band); } else { //assertEquals("Band nodata value does not match import", band.getNodata(), fi.getNoData()); //assertEquals("Band data type does not match import", band.getType(), fi.getDataType()); } // Get the timeslice for this upload TimeSlice timeSlice = datasetDao.findTimeSlice(dataset.getId(), created); if (timeSlice == null) { timeSlice = new TimeSlice(created); datasetDao.addTimeSlice(dataset.getId(), timeSlice); } Point<Integer> firstTile = nng.mapToTile(fi.getBbox().getUlCorner(), transformImage.getResolution()); Point<Integer> lastTile = nng.mapToTile(fi.getBbox().getLrCorner(), transformImage.getResolution()); int expectedNumOfTiles = (lastTile.getX() - firstTile.getX() + 1) * (lastTile.getY() - firstTile.getY() + 1); // Create an empty container to capture all tilebands tilebands = new ArrayList<TileBand>(); tilebandCreator.setSource(transformImage.getBounds()); tilebandCreator.setTarget(tilebands); tilebandCreator.setTimeSlice(timeSlice); tilebandCreator.setBand(band); taskPipeline = new TaskPipeline(); taskPipeline.addTask(tilebandCreator); taskPipeline.initialise(); try { // Run tasks as a transaction taskPipeline.run(); } catch (TaskException e) { // Roll back tasks as a transaction taskPipeline.rollback(); // Report error log.error("{}", e); throw e; } finally { // Cleaning up required for each task taskPipeline.finalise(); } // Check whether the execution is successful. assertEquals(expectedNumOfTiles, tilebands.size()); // Remove test data in temporary upload location try { FileUtils.removeDirectory(tempDir); } catch (IOException e) { log.error("Could not delete temporary directory. {}", e); } }
From source file:org.vpac.ndg.task.TileTransformerTest.java
@Before public void setUp() throws Exception { gdal.AllRegister();// w w w . j a v a2s . c o m taskPipeline = new TaskPipeline(); final String datasetName = "testDs"; // Set up original image Path originalImage = Paths.get("../../data/small_landsat/LS7_ETM_095_082_20100116_B30.nc"); if (!Files.exists(originalImage)) { return; } // Set up source image tmpUploadLocation = FileUtils.createTmpLocation(); Path uploadedFileLocation = tmpUploadLocation.resolve(originalImage.getFileName()); try { FileUtils.copy(originalImage, uploadedFileLocation); } catch (IOException e) { throw new TaskException( String.format(Constant.ERR_COPY_FILE_FAILED, originalImage, uploadedFileLocation)); } sourceImage = new GraphicsFile(uploadedFileLocation); source = new ArrayList<GraphicsFile>(); source.add(sourceImage); // Set up creation time final Date created = Utils.parseDate("2012-03-19"); // Set up resolution CellSize resolution = CellSize.m100; // Set up dataset // Set up dataset Dataset dataset = datasetDao.findDatasetByName(datasetName, resolution); if (dataset == null) { dataset = new Dataset(datasetName, resolution, DateUtils.MILLIS_PER_DAY); datasetDao.create(dataset); } // Find or create band FileInformation fi = sourceImage.getFileInformation(); Band band = bandDao.find(dataset.getId(), "Band1"); if (band == null) { band = new Band("Band1", false, false); band.setNodata(fi.getNoData()); band.setType(fi.getDataType()); datasetDao.addBand(dataset.getId(), band); } else { //assertEquals("Band nodata value does not match import", band.getNodata(), fi.getNoData()); //assertEquals("Band data type does not match import", band.getType(), fi.getDataType()); } // Get the timeslice for this upload TimeSlice timeSlice = datasetDao.findTimeSlice(dataset.getId(), created); if (timeSlice == null) { timeSlice = new TimeSlice(created); datasetDao.addTimeSlice(dataset.getId(), timeSlice); } FileInformation sourceFileInfo = sourceImage.getFileInformation(); // Get all required extents List<Tile> tiles = tileManager.getTiles(sourceFileInfo.getBbox(), resolution); target = new ArrayList<TileBand>(); for (Tile tile : tiles) { TileBand tileband = new TileBand(tile, band, timeSlice); target.add(tileband); log.debug("tileband: {}", tileband.getTileNameWithExtention()); } }
From source file:org.vpac.ndg.task.VrtBuilderTest.java
@Before public void setUp() throws Exception { gdal.AllRegister();//w ww. ja v a2 s.com taskPipeline = new TaskPipeline(); final String datasetName = "testDs"; // Set up original image String originalFileLocation = "../../data/small_landsat/LS7_ETM_095_082_20100116_B30.nc"; Path originalImage = Paths.get(originalFileLocation); assertTrue(Files.exists(originalImage)); // Set up source image tempDir = FileUtils.createTmpLocation(); uploadedFile = tempDir.resolve(originalImage.getFileName()); try { FileUtils.copy(originalImage, uploadedFile); } catch (IOException e) { throw new TaskException( String.format(Constant.ERR_COPY_FILE_FAILED, originalFileLocation, uploadedFile.toString())); } sourceImage = new GraphicsFile(uploadedFile); sourceList = new ArrayList<GraphicsFile>(); sourceList.add(sourceImage); // Set up creation time final Date created = Utils.parseDate("2012-03-19"); // Set up resolution CellSize resolution = CellSize.m100; // Set up dataset Dataset dataset = datasetDao.findDatasetByName(datasetName, resolution); if (dataset == null) { dataset = new Dataset(datasetName, resolution, DateUtils.MILLIS_PER_DAY); datasetDao.create(dataset); } // Find or create band FileInformation fi = sourceImage.getFileInformation(); band = bandDao.find(dataset.getId(), "Band1"); if (band == null) { band = new Band("Band1", false, false); band.setNodata(fi.getNoData()); band.setType(fi.getDataType()); datasetDao.addBand(dataset.getId(), band); } else { //assertEquals("Band nodata value does not match import", band.getNodata(), fi.getNoData()); //assertEquals("Band data type does not match import", band.getType(), fi.getDataType()); } // Get the timeslice for this upload timeSlice = datasetDao.findTimeSlice(dataset.getId(), created); if (timeSlice == null) { timeSlice = new TimeSlice(created); datasetDao.addTimeSlice(dataset.getId(), timeSlice); } FileInformation sourceFileInfo = sourceImage.getFileInformation(); // Get all required extents List<Tile> tiles = tileManager.getTiles(sourceFileInfo.getBbox(), resolution); source = new ArrayList<TileBand>(); for (Tile tile : tiles) { TileBand tileband = new TileBand(tile, band, timeSlice); source.add(tileband); log.debug("tileband: {}", tileband.getTileNameWithExtention()); } }
From source file:org.vpac.ndg.Utils.java
public static long parseTemporalPrecision(String precision) throws IllegalArgumentException { Matcher m;//from w ww. j a v a 2 s . c o m m = TIME_PATTERN_SI.matcher(precision); if (m.matches()) { String number = m.group(1); String units = m.group(2); long n = Long.parseLong(number); switch (units) { case "": case "ms": case "millisecond": case "milliseconds": return n; case "s": case "second": case "seconds": return n * DateUtils.MILLIS_PER_SECOND; case "m": case "minute": case "minutes": return n * DateUtils.MILLIS_PER_MINUTE; case "h": case "hour": case "hours": return n * DateUtils.MILLIS_PER_HOUR; case "d": case "day": case "days": return n * DateUtils.MILLIS_PER_DAY; case "week": case "weeks": return n * DateUtils.MILLIS_PER_DAY * 7; case "month": case "months": // http://en.wikipedia.org/wiki/Month#Synodic_month return n * 2551442890l; case "a": case "y": case "year": case "years": // 365.25 days return n * DateUtils.MILLIS_PER_SECOND * 31557600; } } throw new IllegalArgumentException(String.format("Could not parse precision \"%s\".", precision)); }
From source file:phex.gui.actions.BanHostActionUtils.java
public static BanHostActionMenu createActionMenu(BanHostActionProvider addressProvider) { FWAction[] actions = new FWAction[4]; JMenu mainMenu = new JMenu(Localizer.getString("BanHostAction_BanHost")); mainMenu.setIcon(GUIRegistry.getInstance().getPlafIconPack().getIcon("Security.BanHost")); // 1 day// w w w .j ava 2 s. c o m BanHostAction action = new BanHostAction(Localizer.getString("BanHostAction_1Day"), addressProvider, ExpiryDate.getExpiryDate(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY)); actions[0] = action; mainMenu.add(action); // 7 days action = new BanHostAction(Localizer.getString("BanHostAction_7Days"), addressProvider, ExpiryDate.getExpiryDate(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY * 7)); actions[1] = action; mainMenu.add(action); // never action = new BanHostAction(Localizer.getString("BanHostAction_Unlimited"), addressProvider, ExpiryDate.getExpiryDate(ExpiryDate.EXPIRES_NEVER)); actions[2] = action; mainMenu.add(action); // custom action = new BanHostAction(Localizer.getString("BanHostAction_Custom"), addressProvider, null); actions[3] = action; mainMenu.add(action); // we return an extra wrapper class to have the option of two return // values. BanHostActionMenu actionMenu = new BanHostActionMenu(); actionMenu.menu = mainMenu; actionMenu.actions = actions; return actionMenu; }
From source file:phex.gui.actions.BanHostActionUtils.java
public static FWAction createToolBarAction(BanHostActionProvider addressProvider) { // 7 days/*from w ww . j a v a 2s . co m*/ BanHostAction action = new BanHostAction(Localizer.getString("BanHostAction_BanHost"), GUIRegistry.getInstance().getPlafIconPack().getIcon("Security.BanHost"), Localizer.getString("BanHostAction_TTTBanHost7Days"), addressProvider, ExpiryDate.getExpiryDate(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY * 7)); return action; }
From source file:phex.gui.actions.GUIActionPerformer.java
public static void banHosts(DestAddress[] addresses) { PhexSecurityManager securityMgr = PhexSecurityManager.getInstance(); long expiryTime = System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY * 7; ExpiryDate expiryDate = new ExpiryDate(expiryTime); for (int i = 0; i < addresses.length; i++) { IpAddress ip = addresses[i].getIpAddress(); if (ip == null) { continue; }//from w w w. j av a 2 s.c o m securityMgr.createIPAccessRule(Localizer.getString("UserBanned"), true, IPAccessRule.SINGLE_ADDRESS, ip.getHostIP(), null, false, expiryDate, true); } }
From source file:phex.gui.dialogs.security.SecurityRuleDialog.java
private void initAfterExpiryDateContent(ExpiryDate expiryDate) { long time = expiryDate.getTime(); long currentTime = System.currentTimeMillis(); long timeDiff = time - currentTime; int days;/*from w ww.java 2s .c om*/ int hours; int minutes; if (timeDiff <= 0) { days = 0; hours = 0; minutes = 0; } else { days = (int) Math.floor(timeDiff / (double) DateUtils.MILLIS_PER_DAY); timeDiff -= days * DateUtils.MILLIS_PER_DAY; hours = (int) Math.floor(timeDiff / (double) DateUtils.MILLIS_PER_HOUR); timeDiff -= hours * DateUtils.MILLIS_PER_HOUR; minutes = (int) Math.ceil(timeDiff / (double) DateUtils.MILLIS_PER_MINUTE); } daysTF.setText(String.valueOf(days)); hoursTF.setText(String.valueOf(hours)); minutesTF.setText(String.valueOf(minutes)); }