@Test(expected = ValidationException.class) public void testExtractTimeStamps_badFilename() throws ParseException, ValidationException { final TimeStampExtractor extractor = new TimeStampExtractor("yyyyMMdd", "${startDate}*.dim"); extractor.extractTimeStamps("something20110603.dim"); }
createGroupIndices(0, yearIndex, monthIndex, dayIndex, doyIndex, hourIndex, minuteIndex, secondIndex, indices, startDateGroupIndices); createGroupIndices(startDateGroupIndices.size(), yearIndex, monthIndex, dayIndex, doyIndex, hourIndex, minuteIndex, secondIndex, indices, stopDateGroupIndices);
private ProductData.UTC createTime(Matcher matcher, Map<DateType, Integer> groupIndices) { final String startYearGroup = getString(matcher, DateType.YEAR, groupIndices); final String startMonthGroup = getString(matcher, DateType.MONTH, groupIndices); final String startDayGroup = getString(matcher, DateType.DAY, groupIndices); final String startDoyGroup = getString(matcher, DateType.DAY_OF_YEAR, groupIndices); final String startHourGroup = getString(matcher, DateType.HOUR, groupIndices); final String startMinuteGroup = getString(matcher, DateType.MINUTE, groupIndices); final String startSecondGroup = getString(matcher, DateType.SECOND, groupIndices); String pattern = createPattern(startYearGroup, startMonthGroup, startDayGroup, startDoyGroup, startHourGroup, startMinuteGroup, startSecondGroup); final ProductData.UTC startTime; try { startTime = ProductData.UTC.parse( startYearGroup + startMonthGroup + startDayGroup + startDoyGroup + startHourGroup + startMinuteGroup + startSecondGroup, pattern); } catch (ParseException e) { throw new IllegalStateException(e); } return startTime; }
public FilenameDateExtractor() { timeStampExtractor = new TimeStampExtractor("yyyyMMdd", "${startDate}_*.shp"); }
public boolean isValidFilename(File file) { try { timeStampExtractor.extractTimeStamps(file.getName()); return true; } catch (ValidationException ignored) { return false; } }
/** * Creates a new instance with the given date and file interpretation patterns. * * @param dateInterpretationPattern the date interpretation pattern; see class documentation for specification. * @param filenameInterpretationPattern the filename interpretation pattern; see class documentation for specification. * * @throws IllegalStateException if the filename interpretation pattern contains neither <i>${startDate}</i> nor * <i>endDate</i>. */ public TimeStampExtractor(String dateInterpretationPattern, String filenameInterpretationPattern) { datePattern = dateInterpretationPattern; filenamePattern = filenameInterpretationPattern; init(); }
@Test public void testInit() throws Exception { new TimeStampExtractor("yyyyMMdd", "*${startDate}*.dim"); new TimeStampExtractor("yyyyMMdd", "*${startDate}*${endDate}.dim"); new TimeStampExtractor("yyyyMMdd", "*${endDate}.dim"); try { new TimeStampExtractor("yyyyMMdd", "something.dim"); fail(); } catch (IllegalStateException expected) { // ok } }
public ProductData.UTC getDate(File file) { try { if (isValidFilename(file)) { return timeStampExtractor.extractTimeStamps(file.getName())[0]; } } catch (ValidationException ignored) { } return null; } }
public static List<String[]> recommendPatterns(String fileName) { fileName = replaceColon(fileName); List<String[]> patternCombinations = new ArrayList<String[]>(); for (String dateString : DATE_PATTERNS) { dateString = replaceColon(dateString); final Pattern datePattern = convertDateStringToPattern(dateString); Matcher matcher = datePattern.matcher(fileName); if (matcher.matches()) { TimeStampExtractor timeStampExtractor = new TimeStampExtractor(dateString, FILENAME_PATTERNS[0]); try { timeStampExtractor.extractTimeStamps(fileName); patternCombinations.add(new String[]{insertColon(dateString), FILENAME_PATTERNS[0]}); try { timeStampExtractor = new TimeStampExtractor(insertColon(dateString), FILENAME_PATTERNS[1]); timeStampExtractor.extractTimeStamps(fileName); patternCombinations.add(new String[]{dateString, FILENAME_PATTERNS[1]}); } catch (ValidationException e) { //do nothing } } catch (ValidationException e) { //do nothing } } } return patternCombinations; }
@Override public void actionPerformed(ActionEvent e) { if (StringUtils.isNotNullAndNotEmpty(datePatternComboBox.getEditor().getItem().toString()) && StringUtils.isNotNullAndNotEmpty(fileNamePatternComboBox.getEditor().getItem().toString())) { timeStampExtractor = new TimeStampExtractor(datePatternComboBox.getSelectedItem().toString(), fileNamePatternComboBox.getSelectedItem().toString()); } else { timeStampExtractor = null; } startDate = startTimePicker.getDate(); endDate = stopTimePicker.getDate(); updateUIState(); applyButton.setEnabled(false); fireFilterChangedEvent(); } });
private boolean fitsToUserSpecifiedTimeRange(OpendapLeaf leaf) { try { final ProductData.UTC[] timeStamps = timeStampExtractor.extractTimeStamps(leaf.getName());
private void init() { createGroupIndices(); final boolean filenameHasStartTime = filenamePattern.contains(START_DATE_PLACEHOLDER); final boolean filenameHasStopTime = filenamePattern.contains(END_DATE_PLACEHOLDER); if (filenameHasStopTime && filenameHasStartTime) { timeStampAccess = new RangeTimeAccess(); } else if (filenameHasStartTime || filenameHasStopTime) { timeStampAccess = new SingleTimeAccess(); } else { throw new IllegalStateException(MessageFormat.format( "Filename interpretation pattern ''{0} needs to contain at least one of ''{1}'' and ''{2}''.", filenamePattern, START_DATE_PLACEHOLDER, END_DATE_PLACEHOLDER)); } timeStampAccess.init(); }
@Test public void testExtractTimeStamps_withDOY() throws ParseException, ValidationException { final TimeStampExtractor extractor = new TimeStampExtractor("yyyyDDD", "A${startDate}.L3m_DAY_SST_4"); ProductData.UTC[] dateRange = extractor.extractTimeStamps("A2010159.L3m_DAY_SST_4"); assertEquals(2, dateRange.length); assertEquals(ProductData.UTC.parse("2010-06-08:00:00:00", "yyyy-MM-dd:HH:mm:ss").getAsDate().getTime(), dateRange[0].getAsDate().getTime()); assertEquals(dateRange[0].getAsDate().getTime(), dateRange[1].getAsDate().getTime()); }
timeStampExtractor = new TimeStampExtractor(dateInterpretationPattern, filenameInterpretationPattern);
if (extractTimeFromFilename && file != null) { String fileName = file.getName(); final ProductData.UTC[] timeStamps = timeStampExtractor.extractTimeStamps(fileName); product.setStartTime(timeStamps[0]); product.setEndTime(timeStamps[1]);
@Test public void testExtractTimeStamps_5() throws ParseException, ValidationException { final TimeStampExtractor extractor = new TimeStampExtractor("yyyyMMdd_hh_mm_ss", "*${startDate}*.dim"); ProductData.UTC[] dateRange = extractor.extractTimeStamps("something20110601_12_53_10_bas_wac_acr_1200.dim"); assertEquals(2, dateRange.length); assertEquals(ProductData.UTC.parse("2011-06-01-12-53-10", "yyyy-MM-dd-hh-mm-ss").getAsDate().getTime(), dateRange[0].getAsDate().getTime()); assertEquals(dateRange[0].getAsDate().getTime(), dateRange[1].getAsDate().getTime()); }
@Test public void testAccept_UserEndFileStart() throws Exception { final JCheckBox filterCheckBox = new JCheckBox(); filterCheckBox.setSelected(true); TimeRangeFilter filter = new TimeRangeFilter(filterCheckBox); filter.startDate = null; filter.endDate = new GregorianCalendar(2010, 0, 2, 12, 37, 15).getTime(); filter.timeStampExtractor = new TimeStampExtractor("yyyyMMdd:hhmmss", "*${startDate}*"); assertTrue(filter.accept(new OpendapLeaf("sth__20080101:192345.nc", createNullDataset()))); assertFalse(filter.accept(new OpendapLeaf("sth__20111231:192345.nc", createNullDataset()))); }
@Test public void testExtractTimeStamps_1() throws ParseException, ValidationException { final TimeStampExtractor extractor = new TimeStampExtractor("yyyyMMdd", "${startDate}*.dim"); final ProductData.UTC[] timeStamps = extractor.extractTimeStamps("20111103_est_wac_wew_1200.dim"); assertEquals(timeStamps.length, 2); assertEquals(ProductData.UTC.parse("2011-11-03", "yyyy-MM-dd").getAsDate().getTime(), timeStamps[0].getAsDate().getTime()); assertEquals(timeStamps[0].getAsDate().getTime(), timeStamps[1].getAsDate().getTime()); }
@Test public void testAccept_UserStartFileBoth() throws Exception { final JCheckBox filterCheckBox = new JCheckBox(); filterCheckBox.setSelected(true); TimeRangeFilter filter = new TimeRangeFilter(filterCheckBox); filter.startDate = new GregorianCalendar(2010, 0, 1, 12, 37, 15).getTime(); filter.endDate = null; filter.timeStampExtractor = new TimeStampExtractor("yyyyMMdd:hhmmss", "*${startDate}*${endDate}*"); assertTrue(filter.accept(new OpendapLeaf("sth__20100101:192345___20100102:012345__.nc", createNullDataset()))); assertFalse(filter.accept(new OpendapLeaf("sth__20091231:192345___20100102:012345__.nc", createNullDataset()))); assertFalse(filter.accept(new OpendapLeaf("sth__20091231:192345___20091231:233012__.nc", createNullDataset()))); }
@Test public void testExtractTimeStamps_7() throws ParseException, ValidationException { final TimeStampExtractor extractor = new TimeStampExtractor("yyyyMMdd_hhmmss", "*${startDate}*"); ProductData.UTC[] dateRange = extractor.extractTimeStamps( "MER_RR__2CNACR20070123_101652_000000072055_00008_25613_0000.nc"); assertEquals(2, dateRange.length); assertEquals(ProductData.UTC.parse("2007-01-23:10:16:52", "yyyy-MM-dd:HH:mm:ss").getAsDate().getTime(), dateRange[0].getAsDate().getTime()); assertEquals(dateRange[0].getAsDate().getTime(), dateRange[1].getAsDate().getTime()); }