Example usage for org.joda.time DateTime toString

List of usage examples for org.joda.time DateTime toString

Introduction

In this page you can find the example usage for org.joda.time DateTime toString.

Prototype

@ToString
public String toString() 

Source Link

Document

Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).

Usage

From source file:com.actimem.blog.jackson.customtypes.DateTimeSerializer.java

License:Apache License

@Override
public void serialize(DateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
    gen.writeString(value.toString());
}

From source file:com.actionml.DateTimeAdapter.java

License:Apache License

public JsonElement serialize(DateTime src, Type type, JsonSerializationContext context) {
    return new JsonPrimitive(src.toString());
}

From source file:com.alfaariss.oa.util.saml2.idp.SAML2IDP.java

License:Open Source License

/**
 * Returns a metadata provider with the metadata of the organization.
 * <br>//  w ww  .j a  v  a 2  s .c o  m
 * If the provider was set externally, this provider is returned. <br/>
 * When the SAML2IDP has been serialized/deserialized, a MetadataProvider
 * based on the (static) metadata is returned. Otherwise, a new
 * MetadataProvider is constructed that retrieves its metadata from the
 * configured file- and/or url-source.
 *
 * @return The initialized MetadataProvider with the metadata for this
 * organization or NULL when no metadata is available.
 * @throws OAException If metadata is invalid or could not be accessed
 */
public MetadataProvider getMetadataProvider() throws OAException {
    if (_oMetadataProvider != null) {
        _oLogger.debug("Returning existing MetadataProvider for SAML2 IDP '" + _sID + "'");
        return _oMetadataProvider;
    }

    // If there is a local metadata document available, return the
    // MetadataProvider that is based on this document
    if (_oMetadataXMLObject != null) {
        _oLogger.debug("Creating new XMLObject MetadataProvider for SAML2 IDP '" + _sID + "'");

        XMLObjectMetadataProvider oMP = new XMLObjectMetadataProvider(_oMetadataXMLObject);
        oMP.initialize();
        _oMetadataProvider = oMP;
        return oMP;
    }
    if (_sMetadata != null) {
        _oLogger.debug("Creating new XML-String MetadataProvider for SAML2 IDP '" + _sID + "'");

        // This is the case after de-serialization (i.e. when session resumes)
        // Re-instantiate XMLProvider from retrieved metadata
        // No cache re-evaluation, but this performs better
        try {
            BasicParserPool parserPool = new BasicParserPool();
            parserPool.setNamespaceAware(true);

            StringReader oSR = new StringReader(_sMetadata);

            _oMetadataXMLObject = XMLObjectHelper.unmarshallFromReader(parserPool, oSR);

            XMLObjectMetadataProvider oMP = new XMLObjectMetadataProvider(_oMetadataXMLObject);
            oMP.initialize();

            _oMetadataProvider = oMP;
            return oMP;

        } catch (XMLParserException e) {
            _oLogger.warn("XMLParser exception with establishing metadata for SAML2IDP, trying file/url: "
                    + e.getMessage());
        } catch (UnmarshallingException e) {
            _oLogger.warn("Unmarshalling exception with establishing metadata for SAML2IDP, trying file/url: "
                    + e.getMessage());
        }
    }

    _oLogger.debug("Creating new MetadataProvider from configured source for SAML2 IDP '" + _sID + "'");

    // First time a MetadataProvider request is being handled for this SAML2IDP instance:
    MetadataProviderConfiguration oMPC = new MetadataProviderConfiguration(_sMetadataURL, _iMetadataTimeout,
            _sMetadataFile, _sMetadata);
    String sConfiguredProviderFingerprint = oMPC.getFingerprint();

    IMetadataProviderManager oMPM = null;
    MetadataProvider oMP = null;

    if (_sMPMId != null) {
        oMPM = MdMgrManager.getInstance().getMetadataProviderManager(_sMPMId);
    }

    // Can we get a managed MetadataProvider?
    if (oMPM != null) {
        oMP = oMPM.getProviderFor(_sID, _dLastModified);
    }

    if (oMP != null) {
        // Is it still valid?
        String sCachedProviderFingerprint = MetadataProviderUtil.getMetadataProviderFingerprint(oMP);

        if (!sCachedProviderFingerprint.equals(sConfiguredProviderFingerprint)) {
            _oLogger.info("Metadata configuration changed; re-initializing metadata for IDP " + _sID);
            // No longer valid; invalidate the version from cache
            oMPM.removeProviderFor(_sID);
            oMP = null;
        } else // For the purpose of logging:
        if (_oLogger.isDebugEnabled()) {
            String sNextRefresh = null;

            if (oMP instanceof AbstractReloadingMetadataProvider) {
                DateTime oNextRefresh = ((AbstractReloadingMetadataProvider) oMP).getNextRefresh();
                sNextRefresh = oNextRefresh.toString();
            }
            _oLogger.debug("Using cached MetadataProvider for IDP " + _sID
                    + (sNextRefresh == null ? "" : " (next refresh: " + sNextRefresh + ")"));
        }
    }

    if (oMP == null) {
        oMP = MetadataProviderUtil.createMetadataProvider(_sID, oMPC, oMPM);
    }

    _oMetadataProvider = oMP;

    return _oMetadataProvider;
}

From source file:com.alfaariss.oa.util.saml2.SAML2Requestor.java

License:Open Source License

/**
 * Helper method to initialize the MetadataProvider for the SAML2Requestor
 * Wrapper around MPManager: re-uses cached version, or creates a new version
 * when configuration was changed (since _dLastModified) or when cached version 
 * was expired.<br/>/*from   w w  w .  j  av a2 s. co m*/
 * 
 * @throws OAException thrown when unrecoverable error occurred
 */
private void initMetadataProvider() throws OAException {
    String sInstanceMPFingerprint = _oMetadataProviderConfig.getFingerprint();

    if (sInstanceMPFingerprint.equals(MetadataProviderConfiguration.FINGERPRINT_PROVIDER_UNKNOWN)) {
        _logger.warn("No optional available metadata for requestor with id: " + _sID);
        return;
    }

    // Establish MetadataProvider for Requestor:
    IMetadataProviderManager oMPM = null;
    MetadataProvider oMP = null;

    oMPM = MdMgrManager.getInstance().getMetadataProviderManager(_sMPMId);

    if (oMPM == null)
        _logger.warn("MetadataProviderManager '" + _sMPMId + "'is not available for Requestor '" + _sID
                + "'; possible thread leak?");

    // Try to get MetadataProvider from manager
    if (oMPM != null)
        oMP = oMPM.getProviderFor(_sID, _dLastModified);

    // Is the cached MetadataProvider still valid?
    if (oMP != null) {
        String sCachedMPFingerprint = MetadataProviderUtil.getMetadataProviderFingerprint(oMP);

        if (!sCachedMPFingerprint.equals(sInstanceMPFingerprint)) {
            _logger.info("Metadata configuration changed; re-initializing metadata for " + _sID);
            // No longer valid; invalidate the version from cache
            oMPM.removeProviderFor(_sID);
            oMP = null;
        } else {
            // For the purpose of logging:
            if (_logger.isDebugEnabled()) {
                String sNextRefresh = null;

                if (oMP instanceof AbstractReloadingMetadataProvider) {
                    DateTime oNextRefresh = ((AbstractReloadingMetadataProvider) oMP).getNextRefresh();
                    sNextRefresh = oNextRefresh.toString();
                }
                _logger.debug("Using cached MetadataProvider for " + _sID
                        + (sNextRefresh == null ? "" : " (next refresh: " + sNextRefresh + ")"));
            }
        }
    }

    if (oMP == null) {
        oMP = MetadataProviderUtil.createMetadataProvider(_sID, _oMetadataProviderConfig, oMPM);

        if (oMP != null) {
            _logger.debug("New MetadataProvider was established for " + _sID);
        } else {
            _logger.debug("No MetadataProvider could be established for " + _sID);
        }
    }

    _oMetadataProvider = oMP;
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.mapping.OslpGetConfigurationResponseToConfigurationConverter.java

License:Open Source License

private DateTime convertSummerTimeWinterTimeDetails(final String timeDetails) {
    final int month = Integer.parseInt(timeDetails.substring(0, 2));
    final int day = Integer.parseInt(timeDetails.substring(2, 3));
    final int hour = Integer.parseInt(timeDetails.substring(3, 5));
    final int minutes = Integer.parseInt(timeDetails.substring(5, 7));

    LOGGER.info("month: {}, day: {}, hour: {}, minutes: {}", month, day, hour, minutes);

    final int year = DateTime.now().getYear();
    final int dayOfMonth = this.getLastDayOfMonth(month, day);
    final DateTime dateTime = new DateTime(year, month, dayOfMonth, hour, minutes);

    LOGGER.info("dateTime: {}", dateTime.toString());

    return dateTime;
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

License:Apache License

/**
 * Get todays events. A convenience method for easy testing
 * //from   w w w .  j ava2s . c  om
 * @param calendarId
 *            the calendar id
 * @return the events today
 * @throws Exception
 *             the exception
 */
public ArrayNode getEventsToday(@Optional @Name("calendarId") final String calendarId) throws Exception {
    final DateTime now = DateTime.now();
    final DateTime timeMin = now.minusMillis(now.getMillisOfDay());
    final DateTime timeMax = timeMin.plusDays(1);

    return getEvents(timeMin.toString(), timeMax.toString(), calendarId);
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

License:Apache License

/**
 * Get busy intervals of today. A convenience method for easy testing
 * //  ww  w. j a  v a 2 s .c  o  m
 * @param calendarId
 *            optional calendar id. If not provided, the default calendar is
 *            used
 * @param timeZone
 *            Time zone used in the response. Optional. The default is UTC.
 * @return the busy today
 * @throws Exception
 *             the exception
 */
public ArrayNode getBusyToday(@Optional @Name("calendarId") final String calendarId,
        @Optional @Name("timeZone") final String timeZone) throws Exception {
    final DateTime now = DateTime.now();
    final DateTime timeMin = now.minusMillis(now.getMillisOfDay());
    final DateTime timeMax = timeMin.plusDays(1);

    return getBusy(timeMin.toString(), timeMax.toString(), calendarId, timeZone);
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

License:Apache License

/**
 * Quick create an event.//  ww w  . j a v  a 2s  .c om
 * 
 * @param start
 *            the start
 * @param end
 *            the end
 * @param summary
 *            the summary
 * @param location
 *            the location
 * @param calendarId
 *            the calendar id
 * @return the object node
 * @throws Exception
 *             the exception
 */
public ObjectNode createEventQuick(@Optional @Name("start") String start, @Optional @Name("end") String end,
        @Optional @Name("summary") final String summary, @Optional @Name("location") final String location,
        @Optional @Name("calendarId") final String calendarId) throws Exception {
    final ObjectNode event = JOM.createObjectNode();

    if (start == null) {
        // set start to current time, rounded to hours
        DateTime startDate = DateTime.now();
        startDate = startDate.plusHours(1);
        startDate = startDate.minusMinutes(startDate.getMinuteOfHour());
        startDate = startDate.minusSeconds(startDate.getSecondOfMinute());
        startDate = startDate.minusMillis(startDate.getMillisOfSecond());
        start = startDate.toString();
    }
    final ObjectNode startObj = JOM.createObjectNode();
    startObj.put("dateTime", start);
    event.put("start", startObj);
    if (end == null) {
        // set end to start +1 hour
        final DateTime startDate = new DateTime(start);
        final DateTime endDate = startDate.plusHours(1);
        end = endDate.toString();
    }
    final ObjectNode endObj = JOM.createObjectNode();
    endObj.put("dateTime", end);
    event.put("end", endObj);
    if (summary != null) {
        event.put("summary", summary);
    }
    if (location != null) {
        event.put("location", location);
    }

    return createEvent(event, calendarId);
}

From source file:com.almende.eve.agent.MeetingAgent.java

License:Apache License

/**
 * Apply the constraints of the the activity (for example duration)
 * //  ww w . ja v  a  2 s.c om
 * @param activity
 * @return changed Returns true if the activity is changed
 */
private boolean applyConstraints() {
    final Activity activity = getState().get("activity", Activity.class);
    boolean changed = false;
    if (activity == null) {
        return false;
    }

    // constraints on attendees/resources
    /*
     * TODO: copy actual attendees to status.attendees
     * List<Attendee> constraintsAttendees =
     * activity.withConstraints().withAttendees();
     * List<Attendee> attendees = new ArrayList<Attendee>();
     * for (Attendee attendee : constraintsAttendees) {
     * attendees.add(attendee.clone());
     * }
     * activity.withStatus().setAttendees(attendees);
     * // TODO: is it needed to check if the attendees are changed?
     */

    // check time constraints
    final Long duration = activity.withConstraints().withTime().getDuration();
    if (duration != null) {
        final String start = activity.withStatus().getStart();
        final String end = activity.withStatus().getEnd();
        if (start != null && end != null) {
            final DateTime startTime = new DateTime(start);
            DateTime endTime = new DateTime(end);
            final Interval interval = new Interval(startTime, endTime);
            if (interval.toDurationMillis() != duration) {
                LOG.info("status did not match constraints. " + "Changed end time to match the duration of "
                        + duration + " ms");

                // duration does not match. adjust the end time
                endTime = startTime.plus(duration);
                activity.withStatus().setEnd(endTime.toString());
                activity.withStatus().setUpdated(DateTime.now().toString());

                changed = true;
            }
        }
    }

    // location constraints
    final String newLocation = activity.withConstraints().withLocation().getSummary();
    final String oldLocation = activity.withStatus().withLocation().getSummary();
    if (newLocation != null && !newLocation.equals(oldLocation)) {
        activity.withStatus().withLocation().setSummary(newLocation);
        changed = true;
    }

    if (changed) {
        // store the updated activity
        getState().put("activity", activity);
    }
    return changed;
}

From source file:com.almende.eve.agent.MeetingAgent.java

License:Apache License

/**
 * Retrieve the busy intervals of a calendar agent
 * /*from   w w w.j  av  a  2s. com*/
 * @param agent
 */
private void updateBusyInterval(@Name("agent") final String agent) {
    try {
        // create parameters with the boundaries of the interval to be
        // retrieved
        final ObjectNode params = JOM.createObjectNode();
        final DateTime timeMin = DateTime.now();
        final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS);
        params.put("timeMin", timeMin.toString());
        params.put("timeMax", timeMax.toString());

        // exclude the event managed by this agent from the busy intervals
        final String eventId = getAgentData(agent).eventId;
        if (eventId != null) {
            final ArrayNode excludeEventIds = JOM.createArrayNode();
            excludeEventIds.add(eventId);
            params.put("excludeEventIds", excludeEventIds);
        }

        // get the busy intervals from the agent
        final ArrayNode array = send(URI.create(agent), "getBusy", params, ArrayNode.class);

        // convert from ArrayNode to List
        final List<Interval> busy = new ArrayList<Interval>();
        for (int i = 0; i < array.size(); i++) {
            final ObjectNode obj = (ObjectNode) array.get(i);
            final String start = obj.has("start") ? obj.get("start").asText() : null;
            final String end = obj.has("end") ? obj.get("end").asText() : null;
            busy.add(new Interval(new DateTime(start), new DateTime(end)));
        }

        // store the interval in the state
        putAgentBusy(agent, busy);

    } catch (final JSONRPCException e) {
        addIssue(TYPE.warning, Issue.JSONRPCEXCEPTION, e.getMessage());
        LOG.log(Level.WARNING, "", e);
    } catch (final Exception e) {
        addIssue(TYPE.warning, Issue.EXCEPTION, e.getMessage());
        LOG.log(Level.WARNING, "", e);
    }
}