Example usage for org.joda.time.format ISODateTimeFormat dateTime

List of usage examples for org.joda.time.format ISODateTimeFormat dateTime

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTime.

Prototype

public static DateTimeFormatter dateTime() 

Source Link

Document

Returns a formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).

Usage

From source file:com.pungwe.db.io.DBObjectWriter.java

License:Apache License

private void writeDate(DateTime date) throws IOException {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    output.writeUTF(fmt.print(date));
}

From source file:com.pzybrick.iote2e.common.utils.Iote2eUtils.java

License:Apache License

/**
 * Gets the date now utc 8601./*from ww  w .j ava2s  .c o  m*/
 *
 * @return the date now utc 8601
 */
public static String getDateNowUtc8601() {
    return ISODateTimeFormat.dateTime().print(new DateTime().toDateTime(DateTimeZone.UTC));
}

From source file:com.pzybrick.iote2e.stream.request.Iote2eRequestRouterHandlerSparkDbImpl.java

License:Apache License

/**
 * Insert each block.//from w  w  w  .  jav a  2  s.  c o  m
 *
 * @param iote2eRequests the iote 2 e requests
 * @param con the con
 * @param cachePrepStmtsByTableName the cache prep stmts by table name
 * @throws Exception the exception
 */
private void insertEachBlock(List<Iote2eRequest> iote2eRequests, Connection con,
        Map<String, PreparedStatement> cachePrepStmtsByTableName) throws Exception {
    final DateTimeFormatter dtfmt = ISODateTimeFormat.dateTime();
    String tableName = null;
    String request_uuid = null;
    PreparedStatement pstmt = null;
    try {
        int cntToCommit = 0;
        for (Iote2eRequest iote2eRequest : iote2eRequests) {
            tableName = iote2eRequest.getSourceType().toString();
            pstmt = getPreparedStatement(tableName, con, cachePrepStmtsByTableName);
            if (pstmt != null) {
                cntToCommit++;
                request_uuid = iote2eRequest.getRequestUuid().toString();
                int offset = 1;
                // First set of values are the same on every table
                pstmt.setString(offset++, request_uuid);
                pstmt.setString(offset++, iote2eRequest.getLoginName().toString());
                pstmt.setString(offset++, iote2eRequest.getSourceName().toString());
                Timestamp timestamp = new Timestamp(
                        dtfmt.parseDateTime(iote2eRequest.getRequestTimestamp().toString()).getMillis());
                pstmt.setTimestamp(offset++, timestamp);
                // Next value(s)/types are specific to the table
                // For this simple example, assume one value passed as string
                String value = iote2eRequest.getPairs().values().iterator().next().toString();
                if ("temperature".compareToIgnoreCase(tableName) == 0) {
                    // temp_f
                    pstmt.setFloat(offset++, new Float(value));
                } else if ("humidity".compareToIgnoreCase(tableName) == 0) {
                    // pct_humidity
                    pstmt.setFloat(offset++, new Float(value));
                } else if ("switch".compareToIgnoreCase(tableName) == 0) {
                    // switch_state
                    pstmt.setInt(offset++, Integer.parseInt(value));
                } else if ("heartbeat".compareToIgnoreCase(tableName) == 0) {
                    // heartbeat_state
                    pstmt.setInt(offset++, Integer.parseInt(value));
                }
                pstmt.execute();
            }
        }
        if (cntToCommit > 0)
            con.commit();
    } catch (SQLException sqlEx) {
        con.rollback();
        // Suppress duplicate rows, assume the are the same and were sent over Kafka > 1 time
        if (iote2eRequests.size() == 1) {
            if (sqlEx.getSQLState() != null && sqlEx.getSQLState().startsWith("23"))
                logger.debug("Skipping duplicate row, table={}, request_uuid={}", tableName, request_uuid);
            else {
                logger.error("Error on insert for pstmt: {}", pstmt.toString());
                throw sqlEx;
            }
        } else {
            throw sqlEx;
        }
    } catch (Exception e2) {
        con.rollback();
        throw e2;
    }
}

From source file:com.quinsoft.zeidon.standardoe.WriteOisToJsonStream.java

License:Open Source License

private EntityDef writeEntity(EntityInstanceImpl ei, EntityDef lastEntityDef) throws Exception {
    try {//www  . ja va 2s . c o m
        // See if we need to open or close an array field.
        final EntityDef entityDef = ei.getEntityDef();
        if (lastEntityDef != entityDef) {
            if (lastEntityDef != null)
                jg.writeEndArray();

            lastEntityDef = entityDef;
            jg.writeArrayFieldStart(camelCaseName(entityDef.getName()));
        }

        jg.writeStartObject();
        boolean writePersistent = writeEntityMeta(ei);
        for (AttributeDef attributeDef : entityDef.getAttributes()) {
            // If the attribute is not persistent and we're only writing persisten
            // then go to the next one.
            if (attributeDef.isPersistent() && !writePersistent)
                continue;

            if (attributeDef.isDerived())
                continue;

            AttributeInstanceImpl attrib = ei.getAttribute(attributeDef);
            if (attrib.isNull() && !attrib.isUpdated())
                continue;

            AttributeValue attribValue = ei.getInternalAttribute(attributeDef);

            // Check for integer, double, or boolean so that it gets written without quotes.
            // TODO: Do this more dynamically.
            Domain domain = attributeDef.getDomain();
            String jsonName = camelCaseName(attributeDef.getName());
            if (domain instanceof IntegerDomain)
                jg.writeNumberField(jsonName, attrib.getInteger());
            else if (domain instanceof DoubleDomain)
                jg.writeNumberField(jsonName, attrib.getDouble());
            else if (domain instanceof BooleanDomain)
                jg.writeBooleanField(jsonName, attrib.getBoolean());
            else if (domain instanceof LongDomain)
                jg.writeNumberField(jsonName, (Long) attrib.getValue());
            else if (domain instanceof BigDecimalDomain)
                jg.writeNumberField(jsonName, (BigDecimal) attrib.getValue());
            else if (domain instanceof DateTimeDomain)
                jg.writeStringField(jsonName, ISODateTimeFormat.dateTime().print((DateTime) attrib.getValue()));
            else {
                String value = attribValue.getString(ei.getTask(), attributeDef);
                jg.writeStringField(jsonName, value);
            }

            if (attributeDef.isPersistent())
                writeAttributeMeta(attribValue, attributeDef);
        }

        // Loop through the children and add them.
        EntityDef lastChildEntityDef = null;
        for (EntityInstanceImpl child : ei.getDirectChildren(true, false)) {
            lastChildEntityDef = writeEntity(child, lastChildEntityDef);
        }

        if (lastChildEntityDef != null)
            jg.writeEndArray();

        jg.writeEndObject();

        return entityDef;
    } catch (Exception e) {
        throw ZeidonException.wrapException(e).prependEntityInstance(ei);
    }
}

From source file:com.reveldigital.api.util.DateTypeFormatter.java

License:Apache License

/**
 * Create date formatter/*from   w  ww  .  j a  va 2  s.  co m*/
 */
public DateTypeFormatter() {
    formats = new DateTimeFormatter[4];
    formats[0] = ISODateTimeFormat.dateTime(); //.withZone(DateTimeZone.UTC);
    formats[1] = new DateTimeFormatterBuilder().appendPattern(DATE_TIME_FORMAT).toFormatter();
    formats[2] = new DateTimeFormatterBuilder().appendPattern(DATE_ONLY_FORMAT).toFormatter();
    formats[3] = new DateTimeFormatterBuilder().appendPattern(TIME_ONLY_FORMAT).toFormatter();
}

From source file:com.rusticisoftware.tincan.internal.StatementBase.java

License:Apache License

@Override
public ObjectNode toJSONNode(TCAPIVersion version) {
    ObjectNode node = Mapper.getInstance().createObjectNode();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();

    node.put("actor", this.getActor().toJSONNode(version));
    node.put("verb", this.getVerb().toJSONNode(version));
    node.put("object", this.getObject().toJSONNode(version));

    if (this.result != null) {
        node.put("result", this.getResult().toJSONNode(version));
    }/*  ww  w  . ja  v a 2  s .  c  o  m*/
    if (this.context != null) {
        node.put("context", this.getContext().toJSONNode(version));
    }
    if (this.timestamp != null) {
        node.put("timestamp", fmt.print(this.getTimestamp()));
    }

    //Include 1.0.x specific fields if asking for 1.0.x version
    if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
        if (this.getAttachments() != null && this.getAttachments().size() > 0) {
            ArrayNode attachmentsNode = Mapper.getInstance().createArrayNode();
            for (Attachment attachment : this.getAttachments()) {
                attachmentsNode.add(attachment.toJSONNode(version));
            }
            node.put("attachments", attachmentsNode);
        }
    }

    return node;
}

From source file:com.rusticisoftware.tincan.Statement.java

License:Apache License

@Override
public ObjectNode toJSONNode(TCAPIVersion version) {
    ObjectNode node = super.toJSONNode(version);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();

    if (this.id != null) {
        node.put("id", this.getId().toString());
    }//from   w w w  .  j  av a  2 s  .  c o m
    if (this.stored != null) {
        node.put("stored", fmt.print(this.getStored()));
    }
    if (this.authority != null) {
        node.put("authority", this.getAuthority().toJSONNode(version));
    }

    //Include 0.95 specific fields if asking for 0.95 version
    if (TCAPIVersion.V095.equals(version)) {
        if (this.getVoided() != null) {
            node.put("voided", this.getVoided());
        }
    }

    //Include 1.0.x specific fields if asking for 1.0.x version
    if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
        if (this.getVersion() != null) {
            node.put("version", this.getVersion().toString());
        }
    }

    return node;
}

From source file:com.rusticisoftware.tincan.v095.StatementsQuery.java

License:Apache License

public HashMap<String, String> toParameterMap() throws IOException {
    HashMap<String, String> params = new HashMap<String, String>();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();

    if (this.getVerbID() != null) {
        params.put("verb", this.getVerbID().toString());
    }//from   w  w w.  ja  v a 2 s  .  c  om
    if (this.getObject() != null) {
        params.put("object", this.getObject().toJSON(version));
    }
    if (this.getRegistration() != null) {
        params.put("registration", this.getRegistration().toString());
    }
    if (this.getContext() != null) {
        params.put("context", this.getContext().toString());
    }
    if (this.getActor() != null) {
        params.put("actor", this.getActor().toJSON(version));
    }
    if (this.getSince() != null) {
        params.put("since", fmt.print(this.getSince()));
    }
    if (this.getUntil() != null) {
        params.put("until", fmt.print(this.getUntil()));
    }
    if (this.getLimit() != null) {
        params.put("limit", this.getLimit().toString());
    }
    if (this.getAuthoritative() != null) {
        params.put("authoritative", this.getAuthoritative().toString());
    }
    if (this.getSparse() != null) {
        params.put("sparse", this.getSparse().toString());
    }
    if (this.getInstructor() != null) {
        params.put("instructor", this.getInstructor().toJSON(version));
    }
    if (this.getAscending() != null) {
        params.put("ascending", this.getAscending().toString());
    }

    return params;
}

From source file:com.rusticisoftware.tincan.v10x.StatementsQuery.java

License:Apache License

public HashMap<String, String> toParameterMap() throws IOException {
    HashMap<String, String> params = new HashMap<String, String>();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();

    if (this.getAgent() != null) {
        params.put("agent", this.getAgent().toJSON(version));
    }//from ww  w  .j a va 2 s.com
    if (this.getVerbID() != null) {
        params.put("verb", this.getVerbID().toString());
    }
    if (this.getActivityID() != null) {
        params.put("activity", this.getActivityID().toString());
    }
    if (this.getRegistration() != null) {
        params.put("registration", this.getRegistration().toString());
    }
    if (this.getRelatedActivities() != null) {
        params.put("related_activities", this.getRelatedActivities().toString());
    }
    if (this.getRelatedAgents() != null) {
        params.put("related_agents", this.getRelatedAgents().toString());
    }
    if (this.getSince() != null) {
        params.put("since", fmt.print(this.getSince()));
    }
    if (this.getUntil() != null) {
        params.put("until", fmt.print(this.getUntil()));
    }
    if (this.getLimit() != null) {
        params.put("limit", this.getLimit().toString());
    }
    if (this.getFormat() != null) {
        params.put("format", this.getFormat().toString().toLowerCase());
    }
    if (this.getAscending() != null) {
        params.put("ascending", this.getAscending().toString());
    }

    if (this.getAttachments() != null) {
        params.put("attachments", this.getAttachments().toString());
    }

    return params;
}

From source file:com.semanticcms.core.sitemap.SiteMapIndexServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    List<Tuple2<Book, ReadableInstant>> sitemapBooks = getSitemapBooks(getServletContext(), req, resp);
    final DateTimeFormatter iso8601 = ISODateTimeFormat.dateTime();

    resp.resetBuffer();//from w  w w. ja va  2 s . c om
    resp.setContentType(CONTENT_TYPE);
    resp.setCharacterEncoding(ENCODING);
    PrintWriter out = resp.getWriter();
    out.println("<?xml version=\"1.0\" encoding=\"" + ENCODING + "\"?>");
    out.println("<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
    for (Tuple2<Book, ReadableInstant> sitemapBook : sitemapBooks) {
        writeSitemap(req, resp, out, sitemapBook.getElement1(), sitemapBook.getElement2(), iso8601);
    }
    out.println("</sitemapindex>");
}