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:de.escidoc.core.common.business.fedora.resources.GenericResource.java

License:Open Source License

/**
 * Set the last-modification-date.//ww  w . j a  v a  2 s  . c om
 * 
 * @param timestamp
 *            The new timestamp for the lastModificationDate.
 * @throws WebserverSystemException
 *             Thrown if requesting TripleStore failed.
 */
public void setLastModificationDate(final DateTime timestamp) throws WebserverSystemException {
    // this.lastModifiedDate = timestamp;
    try {
        setProperty(PropertyMapKeys.LAST_MODIFICATION_DATE, timestamp.toString());
    } catch (final TripleStoreSystemException e) {
        throw new WebserverSystemException(e);
    }
}

From source file:de.escidoc.core.common.business.fedora.resources.GenericVersionableResource.java

License:Open Source License

/**
 * Update the timestamp of the version within RELS-EXT.
 * /*  www .  ja v  a2s . com*/
 * @param newVersionTimestamp
 *            The timestamp of the version.
 * @throws WebserverSystemException
 *             Thrown in case of internal error.
 */
protected void updateRelsExtVersionTimestamp(final DateTime newVersionTimestamp)
        throws WebserverSystemException {

    // TODO this method should be better called
    // setLastModificationDate(timestamp)
    // (and override the inherited method)

    // last operation is to update the timestamp in RELS-EXT
    final Map<String, StartElementWithChildElements> updateElementsRelsExt = new TreeMap<String, StartElementWithChildElements>();

    updateElementsRelsExt.put(Constants.VERSION_NS_URI + Elements.ELEMENT_DATE,
            new StartElementWithChildElements(Constants.VERSION_NS_URI + Elements.ELEMENT_DATE,
                    Constants.VERSION_NS_URI, Constants.VERSION_NS_PREFIX, null, newVersionTimestamp.toString(),
                    null));

    // if status has changed to release than update latest-release/date
    try {
        if (hasVersionStatusChanged() && getVersionStatus().equals(Constants.STATUS_RELEASED)) {
            updateElementsRelsExt.put(Constants.RELEASE_NS_URI + Elements.ELEMENT_DATE,
                    new StartElementWithChildElements(Constants.RELEASE_NS_URI + Elements.ELEMENT_DATE,
                            Constants.RELEASE_NS_URI, Constants.RELEASE_NS_PREFIX, null,
                            newVersionTimestamp.toString(), null));
        }
    } catch (final IntegritySystemException e) {
        throw new WebserverSystemException(e);
    }

    updateRelsExt(updateElementsRelsExt, null);
    setLastModificationDate(newVersionTimestamp);
}

From source file:de.escidoc.core.common.business.fedora.resources.GenericVersionableResource.java

License:Open Source License

/**
 * Update Version History (WOV) with (last-modification) timestamp.
 * /*ww w  . j a va  2s  . c om*/
 * @param versionNo
 *            Number of version which is updated (mostly the latest, but not ever!) If null the latest version is
 *            updated.
 * @param timestamp
 *            The timestamp which is to write to WOV
 * @throws FedoraSystemException
 *             If Fedora reports an error.
 * @throws WebserverSystemException
 *             In case of an internal error.
 */
protected void updateWovTimestamp(final String versionNo, final DateTime timestamp)
        throws WebserverSystemException {

    try {
        final byte[] b = getWov().getStream();
        String tmpWov = new String(b, XmlUtility.CHARACTER_ENCODING);
        tmpWov = tmpWov.replaceAll(XmlTemplateProviderConstants.TIMESTAMP_PLACEHOLDER, timestamp.toString());
        setWov(new Datastream(Elements.ELEMENT_WOV_VERSION_HISTORY, getId(),
                tmpWov.getBytes(XmlUtility.CHARACTER_ENCODING), MediaType.TEXT_XML.toString()));
    } catch (final Exception e1) {
        throw new WebserverSystemException(e1);
    }
}

From source file:de.escidoc.core.common.business.fedora.resources.GenericVersionableResource.java

License:Open Source License

/**
 * Create a new event entry for WOV. (this version is an altered from Utility class and should replace it).
 * //from   w  ww.j a v a2s . c o m
 * @param latestModificationTimestamp
 *            The timestamp of the event.
 * @param newStatus
 *            The version status of the resource.
 * @param comment
 *            The event comment.
 * @return The new event entry
 * @throws de.escidoc.core.common.exceptions.system.WebserverSystemException
 * @throws de.escidoc.core.common.exceptions.system.IntegritySystemException
 */
protected String createEventXml(final DateTime latestModificationTimestamp, final String newStatus,
        final String comment) throws WebserverSystemException, IntegritySystemException {

    final HashMap<String, String> eventValues = new HashMap<String, String>();

    eventValues.put(XmlTemplateProviderConstants.VAR_EVENT_TYPE, newStatus);
    eventValues.put(XmlTemplateProviderConstants.VAR_EVENT_XMLID,
            'v' + getVersionData().getLatestVersion().getVersionNumber() + 'e' + System.currentTimeMillis());
    eventValues.put(XmlTemplateProviderConstants.VAR_EVENT_ID_TYPE, Constants.PREMIS_ID_TYPE_URL_RELATIVE);
    eventValues.put(XmlTemplateProviderConstants.VAR_EVENT_ID_VALUE,
            getHrefWithoutVersionNumber() + "/resources/" + Elements.ELEMENT_WOV_VERSION_HISTORY + '#'
                    + eventValues.get(XmlTemplateProviderConstants.VAR_EVENT_XMLID));
    eventValues.put(XmlTemplateProviderConstants.TIMESTAMP, latestModificationTimestamp.toString());
    eventValues.put(XmlTemplateProviderConstants.VAR_COMMENT, XmlUtility.escapeForbiddenXmlCharacters(comment));
    eventValues.put(XmlTemplateProviderConstants.VAR_AGENT_BASE_URI, Constants.USER_ACCOUNT_URL_BASE);
    eventValues.put(XmlTemplateProviderConstants.VAR_AGENT_TITLE, UserContext.getRealName());
    eventValues.put(XmlTemplateProviderConstants.VAR_AGENT_ID_TYPE, Constants.PREMIS_ID_TYPE_ESCIDOC);
    eventValues.put(XmlTemplateProviderConstants.VAR_AGENT_ID_VALUE, UserContext.getId());
    eventValues.put(XmlTemplateProviderConstants.VAR_OBJECT_ID_TYPE, Constants.PREMIS_ID_TYPE_ESCIDOC);
    eventValues.put(XmlTemplateProviderConstants.VAR_OBJECT_ID_VALUE, getId());

    return CommonFoXmlProvider.getInstance().getPremisEventXml(eventValues);
}

From source file:de.escidoc.core.common.business.fedora.resources.GenericVersionableResource.java

License:Open Source License

/**
 * Update Version History (WOV) with new event entry.
 * /*from w  w  w . j a  v  a2 s. c o m*/
 * @param versionNo
 *            Number of version which is updated (mostly the latest, but not ever!) If null the latest version is
 *            updated.
 * @param timestamp
 *            The timestamp which is to write to WOV
 * @param newEventEntry
 *            The event entry XML representation.
 * @throws FedoraSystemException
 *             If Fedora reports an error.
 * @throws WebserverSystemException
 *             In case of an internal error.
 */
protected void writeEventToWov(final String versionNo, final DateTime timestamp, final String newEventEntry)
        throws WebserverSystemException {

    /*
     * The event entry is written with the version timestamp. But this value used to be replaced within the later
     * persist() method when all datastreams are written.
     * 
     * FIXME make possible that also to older versions of the resource events could be added
     */

    final StaxParser sp = new StaxParser();

    final Map<String, StartElementWithChildElements> updateElementsWOV = new HashMap<String, StartElementWithChildElements>();
    // FIXME change first occurence of timestamp in version-history
    updateElementsWOV.put(TripleStoreUtility.PROP_VERSION_TIMESTAMP,
            new StartElementWithChildElements(TripleStoreUtility.PROP_VERSION_TIMESTAMP,
                    Constants.WOV_NAMESPACE_URI, Constants.WOV_NAMESPACE_PREFIX, null, timestamp.toString(),
                    null));

    final ItemRelsExtUpdateHandler ireuh = new ItemRelsExtUpdateHandler(updateElementsWOV, sp);
    ireuh.setPath("/version-history/version/");
    sp.addHandler(ireuh);

    final AddNewSubTreesToDatastream addNewSubtreesHandler = new AddNewSubTreesToDatastream("/version-history",
            sp);
    final StartElement pointer = new StartElement("version", Constants.WOV_NAMESPACE_URI, "escidocVersions",
            null);
    addNewSubtreesHandler.setPointerElement(pointer);
    final List<StartElementWithChildElements> elementsToAdd = new ArrayList<StartElementWithChildElements>();
    addNewSubtreesHandler.setSubtreeToInsert(elementsToAdd);
    sp.addHandler(addNewSubtreesHandler);

    try {
        sp.parse(getWov().getStream());
        final ByteArrayOutputStream newWovStream = addNewSubtreesHandler.getOutputStreams();

        final String newWovString = newWovStream.toString(XmlUtility.CHARACTER_ENCODING)
                .replaceFirst("(<" + Constants.WOV_NAMESPACE_PREFIX + ":events[^>]*>)", "$1" + newEventEntry);

        setWov(new Datastream(Elements.ELEMENT_WOV_VERSION_HISTORY, getId(),
                newWovString.getBytes(XmlUtility.CHARACTER_ENCODING), MediaType.TEXT_XML.toString()));
    } catch (final Exception e) {
        throw new WebserverSystemException(e);
    }
}

From source file:de.escidoc.core.common.business.fedora.resources.GenericVersionableResourcePid.java

License:Open Source License

/**
 * Update Version History (WOV) with PID.
 *
 * @param pid       persistent identifier
 * @param timestamp The timestamp of the assignment.
 * @throws WebserverSystemException   In case of an internal error.
 * @throws FedoraSystemException      If Fedora reports an error.
 * @throws TripleStoreSystemException If the triple store request failed.
 *///ww  w .  j a  va2 s .c om
public void updatePidToWov(final String pid, final DateTime timestamp) throws WebserverSystemException {

    // TODO add comment "objectPid added" to the version
    final StartElementWithChildElements pidElement = new StartElementWithChildElements(Elements.ELEMENT_PID,
            Constants.WOV_NAMESPACE_URI, Constants.WOV_NAMESPACE_PREFIX, null, pid, null);

    pidElement.addAttribute(new Attribute("timestamp", null, null, timestamp.toString()));
    pidElement.addAttribute(new Attribute("user", null, null, UserContext.getId()));

    final List<StartElementWithChildElements> elementsToAdd = new ArrayList<StartElementWithChildElements>();
    elementsToAdd.add(pidElement);

    final StaxParser sp = new StaxParser();
    final AddNewSubTreesToDatastream addNewSubtreesHandler = new AddNewSubTreesToDatastream(
            '/' + Elements.ELEMENT_WOV_VERSION_HISTORY, sp);

    final StartElement pointer = new StartElement("version", Constants.WOV_NAMESPACE_URI,
            Constants.WOV_NAMESPACE_PREFIX, null);

    try {
        pointer.addAttribute(new Attribute("objid", null, null, getFullId()));

        addNewSubtreesHandler.setPointerElement(pointer);
        addNewSubtreesHandler.setSubtreeToInsert(elementsToAdd);
        sp.addHandler(addNewSubtreesHandler);

        sp.parse(new ByteArrayInputStream(getWov().getStream()));
        final ByteArrayOutputStream wovExtNew = addNewSubtreesHandler.getOutputStreams();
        final byte[] wovNewBytes = wovExtNew.toByteArray();
        setWov(new Datastream(DATASTREAM_WOV, getId(), wovNewBytes, MediaType.TEXT_XML.toString()));
    } catch (final Exception e) {
        throw new WebserverSystemException(e);
    }
}

From source file:de.escidoc.core.common.business.fedora.Utility.java

License:Open Source License

/**
 * Prepare the XML for the return of all task oriented methods.
 * <p/>/*from  w  w  w  . jav  a2s .co  m*/
 * TODO either use velocity template and/or move to an own class (ReturnXY)
 *
 * @param lastModificationDate The last-modification-date of the resource.
 * @param content              The XML content elements of the result structure.
 * @return The result XML structure.
 * @throws SystemException Thrown if parsing last modification or retrieving xml:base failed.
 */
public static String prepareReturnXml(DateTime lastModificationDate, final String content) {

    if (lastModificationDate == null) {
        lastModificationDate = new DateTime(DateTimeZone.UTC);
    }

    String xml = Constants.XML_HEADER + "<result " + "xmlns=\"" + Constants.RESULT_NAMESPACE_URI + "\" "
            + "last-modification-date=\"" + lastModificationDate.toString() + '\"';

    xml += content == null ? " />" : ">\n" + content + "</result>\n";

    return xml;
}

From source file:de.escidoc.core.oai.business.renderer.VelocityXmlSetDefinitionRenderer.java

License:Open Source License

/**
 * Adds the values of the {@link SetDefinition} to the provided {@link Map}.
 *
 * @param setDefinition The {@link SetDefinition}.
 * @param values        The {@link Map} to add the values to.
 * @throws SystemException Thrown in case of an internal error.
 *//*www .  j av a  2  s.  c o m*/
private static void addSetDefinitionValues(final SetDefinition setDefinition,
        final Map<String, Object> values) {
    final DateTime lmd = new DateTime(setDefinition.getLastModificationDate(), DateTimeZone.UTC);
    values.put("setDefinitionLastModificationDate", lmd.toString());
    values.put("setDefinitionHref", setDefinition.getHref());
    final DateTime creationDate = new DateTime(setDefinition.getCreationDate(), DateTimeZone.UTC);
    values.put("setDefinitionCreationDate", creationDate.toString());
    values.put("setDefinitionName", setDefinition.getName());
    values.put("setDefinitionSpecification", setDefinition.getSpecification());
    values.put("setDefinitionQuery", setDefinition.getQuery());
    values.put("setDefinitionDescription", setDefinition.getDescription());
    values.put("setDefinitionId", setDefinition.getId());
    values.put("setDefinitionCreatedByTitle", setDefinition.getCreatorTitle());
    final String createdById = setDefinition.getCreatorId();
    final String cratedByHref = XmlUtility.getUserAccountHref(createdById);
    values.put("setDefinitionCreatedByHref", cratedByHref);
    values.put("setDefinitionCreatedById", createdById);
    values.put("setDefinitionModifiedByTitle", setDefinition.getModifiedByTitle());
    values.put("setDefinitionModifiedByHref", XmlUtility.getUserAccountHref(setDefinition.getModifiedById()));
    values.put("setDefinitionModifiedById", setDefinition.getModifiedById());

}

From source file:de.escidoc.core.om.business.renderer.VelocityXmlCommonRenderer.java

License:Open Source License

/**
 * Adds the common values to the provided map.
 *
 * @param resource The resource for that data shall be created.
 * @param values   The map to add values to.
 * @throws WebserverSystemException Thrown in case of an internal error.
 *//*from  w  ww .  j  ava 2s.  com*/
protected void addCommonValues(final GenericVersionableResourcePid resource, final Map values)
        throws WebserverSystemException {

    final DateTime lmd;
    try {
        lmd = resource.getLastModificationDate();
    } catch (final FedoraSystemException e1) {
        throw new WebserverSystemException(e1);
    }

    values.put(XmlTemplateProviderConstants.VAR_LAST_MODIFICATION_DATE, lmd.toString());

    addXlinkValues(values);
}

From source file:de.escidoc.core.om.business.renderer.VelocityXmlContextRenderer.java

License:Open Source License

/**
 * Adds the common values to the provided map.
 *
 * @param context The Context for that data shall be created.
 * @param values  The map to add values to.
 * @throws WebserverSystemException Thrown in case of an internal error.
 *//*from   w  ww  . j  av  a  2 s .c  o m*/
private void addCommonValues(final Context context, final Map<String, Object> values)
        throws WebserverSystemException {

    try {
        final DateTime lastModDate = context.getLastModificationDate();
        values.put(XmlTemplateProviderConstants.VAR_LAST_MODIFICATION_DATE, lastModDate.toString());
    } catch (FedoraSystemException e) {
        throw new WebserverSystemException("Error on getting last modification date.", e);
    }

    values.put("contextId", context.getId());
    values.put("contextTitle", context.getTitle());
    values.put("contextHref", context.getHref());

    addXlinkValues(values);
    addNamespaceValues(values);
}