List of usage examples for org.joda.time DateTime toString
@ToString
public String toString()
From source file:fr.gouv.vitam.query.construct.request.InRequest.java
License:Open Source License
/** * Add an In Value to an existing In Request * * @param inValue//from ww w . j ava 2s. c o m * @return the InRequest * @throws InvalidCreateOperationException */ public final InRequest addInValue(final Date... inValue) throws InvalidCreateOperationException { if (currentREQUEST != REQUEST.in && currentREQUEST != REQUEST.nin) { throw new InvalidCreateOperationException( "Cannot add an InValue since this is not an In Request: " + currentREQUEST); } final ArrayNode array = (ArrayNode) currentObject; if (stringVals == null) { stringVals = new HashSet<String>(); } for (final Date val : inValue) { final DateTime dateTime = new DateTime(val); final String sdate = dateTime.toString(); if (!stringVals.contains(sdate)) { ObjectNode elt = JsonHandler.createObjectNode().put(DATE, sdate); array.add(elt); stringVals.add(sdate); } } return this; }
From source file:fr.gouv.vitam.query.construct.request.RangeRequest.java
License:Open Source License
/** * Range Query constructor/*from w w w . j a v a 2s . c o m*/ * * @param variableName * @param from * gt, gte * @param valueFrom * @param to * lt, lte * @param valueTo * @throws InvalidCreateOperationException */ public RangeRequest(final String variableName, final REQUEST from, final Date valueFrom, final REQUEST to, final Date valueTo) throws InvalidCreateOperationException { super(); if (variableName == null || variableName.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + currentREQUEST + " cannot be updated with empty variable name"); } switch (from) { case gt: case gte: break; default: throw new InvalidCreateOperationException("Request " + from + " is not a valid Compare Request"); } switch (to) { case lt: case lte: break; default: throw new InvalidCreateOperationException("Request " + to + " is not a valid Compare Request"); } final ObjectNode sub = ((ObjectNode) currentObject).putObject(REQUEST.range.exactToken()) .putObject(variableName.trim()); final DateTime dateFrom = new DateTime(valueFrom); final DateTime dateTo = new DateTime(valueTo); sub.putObject(from.exactToken()).put(DATE, dateFrom.toString()); sub.putObject(to.exactToken()).put(DATE, dateTo.toString()); currentREQUEST = REQUEST.range; setReady(true); }
From source file:fr.gouv.vitam.query.construct.request.Request.java
License:Open Source License
protected final void createRequestVariableValue(final REQUEST request, final String variableName, final Date value) throws InvalidCreateOperationException { if (variableName == null || variableName.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + request + " cannot be created with empty variable name"); }//from ww w. j av a 2s.c o m currentObject = ((ObjectNode) currentObject).putObject(request.exactToken()); final DateTime dateTime = new DateTime(value); ((ObjectNode) currentObject).putObject(variableName.trim()).put(DATE, dateTime.toString()); }
From source file:fr.gouv.vitam.query.construct.request.TermRequest.java
License:Open Source License
/** * Term Request constructor from Map//from www . j a v a 2s. c o m * * @param variableNameValue */ public TermRequest(final Map<String, Object> variableNameValue) { super(); currentObject = ((ObjectNode) currentObject).putObject(REQUEST.term.exactToken()); final ObjectNode node = (ObjectNode) currentObject; for (final Entry<String, Object> entry : variableNameValue.entrySet()) { final String name = entry.getKey(); if (name == null || name.trim().isEmpty()) { continue; } Object val = entry.getValue(); if (val instanceof Boolean) { node.put(name.trim(), (Boolean) val); } else if (val instanceof Long) { node.put(name.trim(), (Long) val); } else if (val instanceof Double) { node.put(name.trim(), (Double) val); } else if (val instanceof Date) { final DateTime dateTime = new DateTime(val); node.putObject(name.trim()).put(DATE, dateTime.toString()); } else { node.put(name.trim(), val.toString()); } } currentREQUEST = REQUEST.term; setReady(true); }
From source file:fr.gouv.vitam.query.construct.request.TermRequest.java
License:Open Source License
/** * Add other Term sub requests to Term Request * * @param variableName//from w w w . j a va2s . c o m * @param value * @return the TermRequest * @throws InvalidCreateOperationException */ public final TermRequest addTermRequest(final String variableName, final Date value) throws InvalidCreateOperationException { if (currentREQUEST != REQUEST.term) { throw new InvalidCreateOperationException( "Cannot add a term element since this is not a Term Request: " + currentREQUEST); } if (variableName == null || variableName.trim().isEmpty()) { throw new InvalidCreateOperationException( "Request " + currentREQUEST + " cannot be updated with empty variable name"); } final DateTime dateTime = new DateTime(value); ((ObjectNode) currentObject).putObject(variableName.trim()).put(DATE, dateTime.toString()); return this; }
From source file:google.registry.backup.CommitLogCheckpointAction.java
License:Open Source License
@Override public void run() { final CommitLogCheckpoint checkpoint = strategy.computeCheckpoint(); logger.info("Generated candidate checkpoint for time " + checkpoint.getCheckpointTime()); ofy().transact(new VoidWork() { @Override//from ww w .j a va 2 s . co m public void vrun() { DateTime lastWrittenTime = CommitLogCheckpointRoot.loadRoot().getLastWrittenTime(); if (isBeforeOrAt(checkpoint.getCheckpointTime(), lastWrittenTime)) { logger.info("Newer checkpoint already written at time: " + lastWrittenTime); return; } ofy().saveWithoutBackup().entities(checkpoint, CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime())); // Enqueue a diff task between previous and current checkpoints. taskEnqueuer.enqueue(getQueue(QUEUE_NAME), withUrl(ExportCommitLogDiffAction.PATH) .param(LOWER_CHECKPOINT_TIME_PARAM, lastWrittenTime.toString()) .param(UPPER_CHECKPOINT_TIME_PARAM, checkpoint.getCheckpointTime().toString())); } }); }
From source file:google.registry.rdap.RdapJsonFormatter.java
License:Open Source License
/** * Creates an RDAP event object as defined by RFC 7483. */// ww w.j a v a2 s .c om private static ImmutableMap<String, Object> makeEvent(RdapEventAction eventAction, @Nullable String eventActor, DateTime eventDate) { ImmutableMap.Builder<String, Object> jsonBuilder = new ImmutableMap.Builder<>(); jsonBuilder.put("eventAction", eventAction.getDisplayName()); if (eventActor != null) { jsonBuilder.put("eventActor", eventActor); } jsonBuilder.put("eventDate", eventDate.toString()); return jsonBuilder.build(); }
From source file:google.registry.rde.RdeStagingReducer.java
License:Open Source License
private void reduceWithLock(final PendingDeposit key, Iterator<DepositFragment> fragments) { logger.infofmt("RdeStagingReducer %s", key); // Normally this is done by BackendServlet but it's not present in MapReduceServlet. Security.addProvider(new BouncyCastleProvider()); // Construct things that Dagger would inject if this wasn't serialized. Ghostryde ghostryde = new Ghostryde(ghostrydeBufferSize); PGPPublicKey stagingKey = PgpHelper.loadPublicKeyBytes(stagingKeyBytes); GcsUtils cloudStorage = new GcsUtils(createGcsService(RetryParams.getDefaultInstance()), gcsBufferSize); RdeCounter counter = new RdeCounter(); // Determine some basic things about the deposit. final RdeMode mode = key.mode(); final String tld = key.tld(); final DateTime watermark = key.watermark(); final int revision = RdeRevision.getNextRevision(tld, watermark, mode); String id = RdeUtil.timestampToId(watermark); String prefix = RdeNamingUtils.makeRydeFilename(tld, watermark, mode, 1, revision); GcsFilename xmlFilename = new GcsFilename(bucket, prefix + ".xml.ghostryde"); GcsFilename xmlLengthFilename = new GcsFilename(bucket, prefix + ".xml.length"); GcsFilename reportFilename = new GcsFilename(bucket, prefix + "-report.xml.ghostryde"); // These variables will be populated as we write the deposit XML and used for other files. boolean failed = false; long xmlLength; XjcRdeHeader header;//from w ww . j a v a2 s.c om // Write a gigantic XML file to GCS. We'll start by opening encrypted out/err file handles. logger.infofmt("Writing %s", xmlFilename); try (OutputStream gcsOutput = cloudStorage.openOutputStream(xmlFilename); Ghostryde.Encryptor encryptor = ghostryde.openEncryptor(gcsOutput, stagingKey); Ghostryde.Compressor kompressor = ghostryde.openCompressor(encryptor); Ghostryde.Output gOutput = ghostryde.openOutput(kompressor, prefix + ".xml", watermark); Writer output = new OutputStreamWriter(gOutput, UTF_8)) { // Output the top portion of the XML document. output.write(marshaller.makeHeader(id, watermark, RdeResourceType.getUris(mode), revision)); // Output XML fragments emitted to us by RdeStagingMapper while counting them. while (fragments.hasNext()) { DepositFragment fragment = fragments.next(); if (!fragment.xml().isEmpty()) { output.write(fragment.xml()); counter.increment(fragment.type()); } if (!fragment.error().isEmpty()) { failed = true; logger.severe(fragment.error()); } } for (IdnTableEnum idn : IdnTableEnum.values()) { output.write(marshaller.marshalIdn(idn.getTable())); counter.increment(RdeResourceType.IDN); } // Output XML that says how many resources were emitted. header = counter.makeHeader(tld, mode); output.write(marshaller.marshalStrictlyOrDie(new XjcRdeHeaderElement(header))); // Output the bottom of the XML document. output.write(marshaller.makeFooter()); // And we're done! How many raw XML bytes did we write? output.flush(); xmlLength = gOutput.getBytesWritten(); } catch (IOException | PGPException e) { throw new RuntimeException(e); } // If an entity was broken, abort after writing as much logs/deposit data as possible. verify(!failed, "RDE staging failed for TLD %s", tld); // Write a file to GCS containing the byte length (ASCII) of the raw unencrypted XML. // // This is necessary because RdeUploadAction creates a tar file which requires that the length // be outputted. We don't want to have to decrypt the entire ghostryde file to determine the // length, so we just save it separately. logger.infofmt("Writing %s", xmlLengthFilename); try (OutputStream gcsOutput = cloudStorage.openOutputStream(xmlLengthFilename)) { gcsOutput.write(Long.toString(xmlLength).getBytes(US_ASCII)); } catch (IOException e) { throw new RuntimeException(e); } // Write a tiny XML file to GCS containing some information about the deposit. // // This will be sent to ICANN once we're done uploading the big XML to the escrow provider. if (mode == RdeMode.FULL) { logger.infofmt("Writing %s", reportFilename); String innerName = prefix + "-report.xml"; try (OutputStream gcsOutput = cloudStorage.openOutputStream(reportFilename); Ghostryde.Encryptor encryptor = ghostryde.openEncryptor(gcsOutput, stagingKey); Ghostryde.Compressor kompressor = ghostryde.openCompressor(encryptor); Ghostryde.Output output = ghostryde.openOutput(kompressor, innerName, watermark)) { counter.makeReport(id, watermark, header, revision).marshal(output, UTF_8); } catch (IOException | PGPException | XmlException e) { throw new RuntimeException(e); } } // Now that we're done, kick off RdeUploadAction and roll forward the cursor transactionally. ofy().transact(new VoidWork() { @Override public void vrun() { Registry registry = Registry.get(tld); DateTime position = getCursorTimeOrStartOfTime( ofy().load().key(Cursor.createKey(key.cursor(), registry)).now()); DateTime newPosition = key.watermark().plus(key.interval()); if (!position.isBefore(newPosition)) { logger.warning("Cursor has already been rolled forward."); return; } verify(position.equals(key.watermark()), "Partial ordering of RDE deposits broken: %s %s", position, key); ofy().save().entity(Cursor.create(key.cursor(), newPosition, registry)).now(); logger.infofmt("Rolled forward %s on %s cursor to %s", key.cursor(), tld, newPosition); RdeRevision.saveRevision(tld, watermark, mode, revision); if (mode == RdeMode.FULL) { taskEnqueuer.enqueue(getQueue("rde-upload"), withUrl(RdeUploadAction.PATH).param(RequestParameters.PARAM_TLD, tld)); } else { taskEnqueuer.enqueue(getQueue("brda"), withUrl(BrdaCopyAction.PATH).param(RequestParameters.PARAM_TLD, tld) .param(RdeModule.PARAM_WATERMARK, watermark.toString())); } } }); }
From source file:gov.nih.nci.calims2.taglib.form.DateTextBoxTag.java
License:BSD License
private String getIsoValue() { Object value = getValue();/* w w w . j a va 2 s . co m*/ if (value == null) { return null; } DateTime date = null; if (value instanceof Calendar || value instanceof Date) { date = new DateTime(value); } if (value instanceof DateTime) { date = (DateTime) value; } return (date != null) ? date.toString() : null; }
From source file:info.gehrels.voting.web.DateTimeFormatter.java
License:Open Source License
@Override public String print(DateTime dateTime, Locale locale) { return dateTime.toString(); }