List of usage examples for org.joda.time DateTime toString
public String toString(String pattern)
From source file:gg.pistol.sweeper.gui.PollPage.java
License:Open Source License
private AbstractTableModel createTableModel() { return new AbstractTableModel() { @Override//from www . j a v a 2s. c o m public int getRowCount() { return targets.size(); } @Override public int getColumnCount() { return 7; } @Override public Object getValueAt(int rowIndex, int columnIndex) { switch (columnIndex) { case 0: return sweeper.getCurrentPoll().getMark(targets.get(rowIndex)) == SweeperPoll.Mark.DECIDE_LATER; case 1: return sweeper.getCurrentPoll().getMark(targets.get(rowIndex)) == SweeperPoll.Mark.RETAIN; case 2: return sweeper.getCurrentPoll().getMark(targets.get(rowIndex)) == SweeperPoll.Mark.DELETE; case 3: return targets.get(rowIndex).getName(); case 4: if (targets.get(rowIndex).getType() == Target.Type.FILE) { return i18n.getString(I18n.RESOURCE_TYPE_FILE_ID); } else { return i18n.getString(I18n.RESOURCE_TYPE_DIRECTORY_ID); } case 5: return formatSize(targets.get(rowIndex).getSize()); case 6: DateTime date = targets.get(rowIndex).getModificationDate(); return date == null ? i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_DATE_UNKNOWN_ID) : date.toString(DateTimeFormat.patternForStyle("MM", i18n.getLocale())); } return null; } @Override public String getColumnName(int column) { switch (column) { case 0: return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_DECIDE_LATER_ID); case 1: return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_RETAIN_ID); case 2: return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_DELETE_ID); case 3: return i18n.getString(I18n.RESOURCE_NAME_ID); case 4: return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_TYPE_ID); case 5: return i18n.getString(I18n.RESOURCE_SIZE_ID); case 6: return i18n.getString(I18n.RESOURCE_MODIFIED_ID); } return null; } @Override public Class<?> getColumnClass(int columnIndex) { return columnIndex < 3 ? Boolean.class : String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return columnIndex < 3; } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { SweeperPoll.Mark mark = null; switch (columnIndex) { case 0: mark = SweeperPoll.Mark.DECIDE_LATER; break; case 1: mark = SweeperPoll.Mark.RETAIN; break; case 2: mark = SweeperPoll.Mark.DELETE; break; } sweeper.getCurrentPoll().mark(targets.get(rowIndex), mark); // Go to the next poll and back to update the statistics. sweeper.nextPoll(); sweeper.previousPoll(); statDelete.setText(i18n.getString(I18n.PAGE_POLL_STAT_DELETE_ID, formatInt(sweeper.getCount().getToDeleteTargets()), formatSize(sweeper.getCount().getToDeleteSize()))); fireTableRowsUpdated(rowIndex, rowIndex); } }; }
From source file:gg.view.importhistory.ImportHistoryTopComponent.java
License:Open Source License
/** Creates a new instance of ImportHistoryTopComponent */ public ImportHistoryTopComponent() { initComponents();//from ww w. j a v a 2 s. c om setName(NbBundle.getMessage(ImportHistoryTopComponent.class, "CTL_ImportHistoryTopComponent")); setToolTipText(NbBundle.getMessage(ImportHistoryTopComponent.class, "HINT_ImportHistoryTopComponent")); setIcon(ImageUtilities.loadImage(ICON_PATH, true)); putClientProperty(TopComponent.PROP_DRAGGING_DISABLED, Boolean.TRUE); putClientProperty(TopComponent.PROP_UNDOCKING_DISABLED, Boolean.TRUE); // Initialize the table that shows the file imports eTableImportHistory.setModel(new DefaultTableModel(new Object[][] {}, new String[] { NbBundle.getMessage(ImportHistoryTopComponent.class, "ImportHistoryTopComponent.ImportedOn"), NbBundle.getMessage(ImportHistoryTopComponent.class, "ImportHistoryTopComponent.File"), NbBundle.getMessage(ImportHistoryTopComponent.class, "ImportHistoryTopComponent.Duration"), NbBundle.getMessage(ImportHistoryTopComponent.class, "ImportHistoryTopComponent.Success") }) { Class[] types = new Class[] { DateTime.class, String.class, Long.class, String.class }; @Override public Class getColumnClass(int columnIndex) { return types[columnIndex]; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int row, int column) { switch (column) { case COLUMN_IMPORTED_ON: DateTime dateTime = (DateTime) super.getValueAt(row, column); return dateTime.toString("EEEE d MMMM yyyy - HH:mm"); case COLUMN_FILE_PATH: return super.getValueAt(row, column); case COLUMN_DURATION: long duration = (Long) super.getValueAt(row, column); duration = duration / 1000; // Transform into seconds return duration; case COLUMN_SUCCESS: boolean success = (Boolean) super.getValueAt(row, column); if (success) { return NbBundle.getMessage(ImportHistoryTopComponent.class, "ImportHistoryTopComponent.Yes"); } else { return NbBundle.getMessage(ImportHistoryTopComponent.class, "ImportHistoryTopComponent.No"); } default: throw new AssertionError("Unknown column: " + column); } } }); // Set the properties of the table that shows the file imports eTableImportHistory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); eTableImportHistory.setColumnHidingAllowed(false); eTableImportHistory.setPopupUsedFromTheCorner(false); eTableImportHistory.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // Left align the durations DefaultTableCellRenderer leftRenderer = new DefaultTableCellRenderer(); leftRenderer.setHorizontalAlignment(JLabel.LEFT); eTableImportHistory.getColumnModel().getColumn(COLUMN_DURATION).setCellRenderer(leftRenderer); // No filter can be applied to this view FieldsVisibility fieldsVisibility = new FieldsVisibility(); associateLookup(Lookups.singleton(fieldsVisibility)); }
From source file:gobblin.compaction.dataset.TimeBasedSubDirDatasetsFinder.java
License:Apache License
/** * Each subdir in {@link DatasetsFinder#inputDir} is considered a dataset, if it satisfies blacklist and whitelist. *//*from w w w. j ava 2 s . c o m*/ @Override public Set<Dataset> findDistinctDatasets() throws IOException { Set<Dataset> datasets = Sets.newHashSet(); for (FileStatus datasetsFileStatus : this.fs.globStatus(new Path(inputDir, subDirPattern))) { log.info("Scanning directory : " + datasetsFileStatus.getPath().toString()); if (datasetsFileStatus.isDirectory()) { String datasetName = getDatasetName(datasetsFileStatus.getPath().toString(), inputDir); if (DatasetFilterUtils.survived(datasetName, this.blacklist, this.whitelist)) { log.info("Found dataset: " + datasetName); Path inputPath = new Path(this.inputDir, new Path(datasetName, this.inputSubDir)); Path inputLatePath = new Path(this.inputDir, new Path(datasetName, this.inputLateSubDir)); Path outputPath = new Path(this.destDir, new Path(datasetName, this.destSubDir)); Path outputLatePath = new Path(this.destDir, new Path(datasetName, this.destLateSubDir)); Path outputTmpPath = new Path(this.tmpOutputDir, new Path(datasetName, this.destSubDir)); double priority = this.getDatasetPriority(datasetName); String folderStructure = getFolderStructure(); for (FileStatus status : this.fs.globStatus(new Path(inputPath, folderStructure))) { Path jobInputPath = status.getPath(); DateTime folderTime = null; try { folderTime = getFolderTime(jobInputPath, inputPath); } catch (RuntimeException e) { log.warn("{} is not a valid folder. Will be skipped due to exception.", jobInputPath, e); continue; } if (folderWithinAllowedPeriod(jobInputPath, folderTime)) { Path jobInputLatePath = appendFolderTime(inputLatePath, folderTime); Path jobOutputPath = appendFolderTime(outputPath, folderTime); Path jobOutputLatePath = appendFolderTime(outputLatePath, folderTime); Path jobOutputTmpPath = appendFolderTime(outputTmpPath, folderTime); Dataset timeBasedDataset = new Dataset.Builder().withPriority(priority) .withDatasetName(datasetName) .addInputPath(this.recompactDatasets ? jobOutputPath : jobInputPath) .addInputLatePath(this.recompactDatasets ? jobOutputLatePath : jobInputLatePath) .withOutputPath(jobOutputPath).withOutputLatePath(jobOutputLatePath) .withOutputTmpPath(jobOutputTmpPath).build(); // Stores the extra information for timeBasedDataset timeBasedDataset.setJobProp(MRCompactor.COMPACTION_JOB_DEST_PARTITION, folderTime.toString(this.timeFormatter)); timeBasedDataset.setJobProp(MRCompactor.COMPACTION_INPUT_PATH_TIME, folderTime.getMillis()); datasets.add(timeBasedDataset); } } } } } return datasets; }
From source file:gobblin.compaction.dataset.TimeBasedSubDirDatasetsFinder.java
License:Apache License
protected Path appendFolderTime(Path path, DateTime folderTime) { return new Path(path, folderTime.toString(this.timeFormatter)); }
From source file:gobblin.compaction.mapreduce.MRCompactorTimeBasedJobPropCreator.java
License:Open Source License
@Override protected List<State> createJobProps() throws IOException { List<State> allJobProps = Lists.newArrayList(); if (!fs.exists(this.topicInputDir)) { LOG.warn("Input folder " + this.topicInputDir + " does not exist. Skipping topic " + topic); return allJobProps; }/*from ww w . j av a2 s. c om*/ String folderStructure = getFolderStructure(); for (FileStatus status : this.fs.globStatus(new Path(this.topicInputDir, folderStructure))) { DateTime folderTime = null; try { folderTime = getFolderTime(status.getPath()); } catch (RuntimeException e) { LOG.warn(status.getPath() + " is not a valid folder. Will be skipped."); continue; } Path jobOutputDir = new Path(this.topicOutputDir, folderTime.toString(this.timeFormatter)); Path jobTmpDir = new Path(this.topicTmpDir, folderTime.toString(this.timeFormatter)); if (folderWithinAllowedPeriod(status.getPath(), folderTime)) { if (!folderAlreadyCompacted(jobOutputDir)) { allJobProps.add(createJobProps(status.getPath(), jobOutputDir, jobTmpDir, this.deduplicate)); } else { List<Path> newDataFiles = getNewDataInFolder(status.getPath(), jobOutputDir); if (newDataFiles.isEmpty()) { LOG.info(String.format("Folder %s already compacted. Skipping", jobOutputDir)); } else { allJobProps.add( createJobPropsForLateData(status.getPath(), jobOutputDir, jobTmpDir, newDataFiles)); } } } } return allJobProps; }
From source file:gov.nih.nci.calims2.ui.util.springmvc.CustomDateTimeEditor.java
License:BSD License
/** * {@inheritDoc}//from www. j av a 2 s . c om */ public String getAsText() { DateTime value = (DateTime) getValue(); return (value != null) ? value.toString(formatter) : ""; }
From source file:gov.usgs.anss.query.cwb.messages.MessageFormatter.java
License:Open Source License
public static String miniSeedSummary(DateTime now, Collection<MiniSeed> miniSeed) { // 02:07:45.992Z Query on NZAPZ HHZ10 000431 mini-seed blks 2009 001:00:00:00.0083 2009 001:00:30:00.438 ns=180044 Iterator<MiniSeed> iter = miniSeed.iterator(); if (!iter.hasNext()) { return String.format("%sZ No mini-seed blocks returned.", now.toString(nowFormat)); }/*from w w w .ja va2 s . com*/ MiniSeed ms = iter.next(); int numSamples = ms.getNsamp(); DateTime begin = new DateTime(ms.getGregorianCalendar().getTimeInMillis(), DateTimeZone.forID("UTC")); while (iter.hasNext()) { ms = iter.next(); numSamples += ms.getNsamp(); } DateTime end = new DateTime(ms.getEndTime().getTimeInMillis(), DateTimeZone.forID("UTC")); return String.format("%sZ Query on %s %06d mini-seed blks %s %s ns=%d", now.toString(nowFormat), ms.getSeedName(), miniSeed.size(), begin.toString(msFormat), end.toString(msFormat), numSamples); }
From source file:gov.usgs.anss.query.filefactory.SacFileFactory.java
License:Open Source License
public void makeFiles(DateTime begin, double duration, String nsclSelectString, String mask) { cwbServer.query(begin, duration, nsclSelectString); if (cwbServer.hasNext()) { do {/* w w w. ja va 2 s . c om*/ SacTimeSeries sac = makeTimeSeries(cwbServer.getNext(), begin, duration, this.fill, this.gaps, this.trim); if (sac != null) { if (this.event != null) { SacHeaders.setEventHeader(sac, this.event); if (this.picks) { if (this.synthetic == null) { SacHeaders.setPhasePicks(sac, this.event); } else { SacHeaders.setPhasePicks(sac, this.event, this.extendedPhases, this.synthetic); } } else { if (this.synthetic != null) { SacHeaders.setPhasePicks(sac, this.extendedPhases, this.synthetic); } } } else { if (this.customEvent != null) { SacHeaders.setEventHeader(sac, this.customEvent.getEventTime(), this.customEvent.getEventLat(), this.customEvent.getEventLon(), this.customEvent.getEventDepth(), this.customEvent.getEventMag(), this.customEvent.getEventMagType().magNum(), this.customEvent.getEventType().eventTypeNum()); } if (this.synthetic != null) { SacHeaders.setPhasePicks(sac, this.extendedPhases, this.synthetic); } } outputFile(sac, begin, mask, this.pzunit); } else { // TODO logger message about null data } } while (cwbServer.hasNext()); } else { logger.info(String.format("No matching data for \"%s\", at begin time %s, duration %.2fs, on %s:%d", nsclSelectString, begin.toString("YYYY/MM/dd HH:mm:ss"), duration, cwbServer.getHost(), cwbServer.getPort())); } }
From source file:graphene.dao.es.BasicESDAO.java
License:Apache License
protected BoolQueryBuilder buildBooleanConstraints(final PropertyMatchDescriptorHelper pmdh, BoolQueryBuilder bool) {//from w w w . j a va 2 s . c om final String key = pmdh.getKey(); final G_Constraint constraint = pmdh.getConstraint(); boolean constraintUsed = false; boolean createdNew = false; if (bool == null) { bool = QueryBuilders.boolQuery(); createdNew = true; } String[] fieldArray = new String[1]; fieldArray[0] = key; final Map<String, ArrayList<String>> fieldMappings = dao.getFieldMappings(); if (ValidationUtils.isValid(fieldMappings)) { final ArrayList<String> specificFields = fieldMappings.get(key); if (specificFields != null) { fieldArray = specificFields.toArray(new String[specificFields.size()]); } else { logger.warn("Could not find specific fields for the key " + pmdh.getKey()); } // Try the singleton range first if (ValidationUtils.isValid(pmdh.getSingletonRange())) { final String text = (String) pmdh.getSingletonRange().getValue(); switch (constraint) { case EQUALS: for (final String sf : fieldArray) { bool = bool.must(QueryBuilders.matchPhraseQuery(sf, text)); constraintUsed = true; } break; case CONTAINS: bool = bool.should(QueryBuilders.multiMatchQuery(text, fieldArray)); constraintUsed = true; break; case STARTS_WITH: for (final String sf : fieldArray) { bool = bool.should(QueryBuilders.prefixQuery(sf, text.toLowerCase())); constraintUsed = true; } break; case NOT: for (final String sf : fieldArray) { bool = bool.mustNot(QueryBuilders.matchPhraseQuery(sf, text)); constraintUsed = true; } break; case LIKE: bool = bool.must(QueryBuilders.fuzzyLikeThisQuery(fieldArray).likeText(text)); constraintUsed = true; break; default: break; } } else if (ValidationUtils.isValid(pmdh.getListRange())) { for (final Object text : pmdh.getListRange().getValues()) { switch (constraint) { case EQUALS: bool = bool.must(QueryBuilders.matchPhraseQuery(key, text)); constraintUsed = true; break; case CONTAINS: bool = bool.should(QueryBuilders.multiMatchQuery(text, fieldArray)); // bool = bool.should(QueryBuilders.matchPhraseQuery(key, text)); constraintUsed = true; break; case STARTS_WITH: bool = bool.must(QueryBuilders.matchPhrasePrefixQuery(key, text)); constraintUsed = true; break; case NOT: bool = bool.mustNot(QueryBuilders.matchPhraseQuery(key, text)); constraintUsed = true; break; default: break; } } } else if (ValidationUtils.isValid(pmdh.getBoundedRange())) { final G_BoundedRange br = pmdh.getBoundedRange(); // Enumerate any specific fields that this range can apply to. String[] rangeFieldArray = new String[1]; rangeFieldArray[0] = key; final ArrayList<String> specificRangeFields = dao.getRangeMappings().get(pmdh.getKey()); if (specificRangeFields != null) { rangeFieldArray = specificRangeFields.toArray(new String[specificRangeFields.size()]); } else { logger.warn("Could not find specific fields for the key " + pmdh.getKey()); } Object start = null; Object end = null; if (br.getStart() != null) { switch (pmdh.getType()) { case LONG: start = br.getStart(); break; case STRING: start = br.getStart().toString(); break; case DATE: final DateTime dt = (DateTime) br.getStart(); start = dt.toString(DATE_FORMAT); break; default: break; } } if (br.getEnd() != null) { switch (pmdh.getType()) { case LONG: end = br.getEnd(); break; case STRING: end = br.getEnd().toString(); break; case DATE: final DateTime dt = (DateTime) br.getEnd(); end = dt.toString(DATE_FORMAT); break; default: break; } } for (final String sf : rangeFieldArray) { if (ValidationUtils.isValid(start, end)) { bool = bool.should(QueryBuilders.rangeQuery(sf).from(start).to(end)); constraintUsed = true; } else if (ValidationUtils.isValid(start)) { bool = bool.should(QueryBuilders.rangeQuery(sf).gt(start)); constraintUsed = true; } else if (ValidationUtils.isValid(end)) { bool = bool.should(QueryBuilders.rangeQuery(sf).lt(end)); constraintUsed = true; } } } else { logger.error("Unknown range type for " + pmdh); } } else { logger.error("No field mappings available"); } if ((constraintUsed == false) && (createdNew == true)) { // boolean was created but not used. bool = null; } return bool; }
From source file:graphene.services.UserServiceImpl.java
License:Apache License
@Override public G_Workspace createTempWorkspaceForUser(final String userId) { final G_User user = getUser(userId); G_Workspace w = null;/*from ww w . ja v a 2 s . c o m*/ if (ValidationUtils.isValid(user)) { // we need a valid user in order to create the workspace. final DateTime time = DateTime.now(); w = new G_Workspace(); w.setActive(true); w.setCreated(time.getMillis()); w.setModified(time.getMillis()); w.setDescription("New Workspace"); w.setTitle(user.getUsername() + " - Workspace" + time.toString("YYYYmmDD-HHMMSS")); } else { logger.error("Could not find user " + userId + " to create a temp workspace for."); } return w; }