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:edu.internet2.middleware.shibboleth.idp.profile.saml2.SSOProfileHandler.java

License:Open Source License

/**
 * Creates an authentication statement for the current request.
 * //from   ww  w  .j ava 2 s  .  co  m
 * @param requestContext current request context
 * 
 * @return constructed authentication statement
 */
protected AuthnStatement buildAuthnStatement(SSORequestContext requestContext) {
    Saml2LoginContext loginContext = requestContext.getLoginContext();

    AuthnContext authnContext = buildAuthnContext(requestContext);

    AuthnStatement statement = authnStatementBuilder.buildObject();
    statement.setAuthnContext(authnContext);
    statement.setAuthnInstant(loginContext != null ? loginContext.getAuthenticationInstant() : null);

    Session session = getUserSession(requestContext.getInboundMessageTransport());
    if (session != null) {
        statement.setSessionIndex(session.getSessionID());
    }

    long maxSPSessionLifetime = requestContext.getProfileConfiguration().getMaximumSPSessionLifetime();
    if (maxSPSessionLifetime > 0) {
        DateTime lifetime = new DateTime(DateTimeZone.UTC).plus(maxSPSessionLifetime);
        log.debug("Explicitly setting SP session expiration time to '{}'", lifetime.toString());
        statement.setSessionNotOnOrAfter(lifetime);
    }

    statement.setSubjectLocality(buildSubjectLocality(requestContext));

    return statement;
}

From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngester.java

License:Open Source License

private Section handleBeginning(final XMLEventReader rdr, final String content, final Communication cptr)
        throws XMLStreamException, ConcreteException {
    // The first type is always a document start event. Skip it.
    rdr.nextEvent();//from  w ww.  j  a va2 s . co m

    // The second type is a document block. Skip it.
    rdr.nextEvent();

    // The third type is a whitespace block. Skip it.
    rdr.nextEvent();

    // The next type is a docid start tag.
    rdr.nextEvent();

    // Text of the docid.
    Characters cc = rdr.nextEvent().asCharacters();
    String idTxt = cc.getData().trim();
    cptr.setId(idTxt);

    // The next part is the docid end element. Skip.
    rdr.nextEvent();

    // Whitespace. Skip.
    rdr.nextEvent();

    // Reader is now pointing at the doctype.
    // XMLEvent doctypeStart = rdr.nextEvent();
    rdr.nextEvent();
    // StartElement dtse = doctypeStart.asStartElement();

    // Doc type content.
    Characters docTypeChars = rdr.nextEvent().asCharacters();
    String docTypeContent = docTypeChars.getData().trim();
    cptr.setType(docTypeContent);

    // Doctype end. Skip.
    rdr.nextEvent();
    // Whitespace. skip.
    rdr.nextEvent();
    // Datetime start.
    rdr.nextEvent();

    // Datetime value.
    Characters dtChars = rdr.nextEvent().asCharacters();
    // TODO: parse this

    String dtValue = dtChars.getData().trim();
    DateTime dt = this.dtf.parseDateTime(dtValue).toDateTime(DateTimeZone.UTC);
    LOGGER.debug("Got DateTime: {}", dt.toString());
    long millis = dt.getMillis();
    cptr.setStartTime(millis / 1000);

    // Datetime end.
    rdr.nextEvent();
    // WS
    rdr.nextEvent();
    // Body begin.
    rdr.nextEvent();
    // WS
    rdr.nextEvent();

    // Headline begin.
    XMLEvent hl = rdr.nextEvent();
    StartElement hlse = hl.asStartElement();
    QName hlqn = hlse.getName();
    final String hlPart = hlqn.getLocalPart();
    LOGGER.debug("QN: {}", hlPart);

    // Headline text.
    Characters hlChars = rdr.nextEvent().asCharacters();
    final int charOff = hlChars.getLocation().getCharacterOffset();
    final int clen = hlChars.getData().length();

    // Construct section, text span, etc.
    final int endTextOffset = charOff + clen;
    final String hlText = content.substring(charOff, endTextOffset);

    SimpleImmutableEntry<Integer, Integer> pads = trimSpacing(hlText);
    TextSpan ts = new TextSpan(charOff + pads.getKey(), endTextOffset - pads.getValue());

    Section s = new Section();
    s.setKind("headline");
    s.setTextSpan(ts);
    List<Integer> intList = new ArrayList<>();
    intList.add(0);
    s.setNumberList(intList);
    return s;
}

From source file:edu.mit.ll.graphulo.pig.backend.AccumuloBinaryConverter.java

License:Apache License

@Override
public byte[] toBytes(DateTime dt) throws IOException {
    return dt.toString().getBytes(UTF8);
}

From source file:edu.unc.lib.deposit.normalize.Proquest2N3BagJob.java

License:Apache License

private void normalizePackage(File packageDir, Model model, Bag depositBag) {

    // Generate a uuid for the main object
    PID primaryPID = new PID("uuid:" + UUID.randomUUID());
    Resource primaryResource;/*from   w  w w.j av a2 s  .  c  o m*/

    // Identify the important files from the deposit
    File dataFile = null, contentFile = null, attachmentDir = null;

    File[] files = packageDir.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            attachmentDir = file;
        } else if (file.getName().endsWith(DATA_SUFFIX)) {
            dataFile = file;
        } else {
            contentFile = file;
        }
    }

    long lastModified = -1;
    File zipFile = new File(packageDir.getAbsolutePath() + ".zip");
    try (ZipFile zip = new ZipFile(zipFile)) {
        ZipArchiveEntry entry = zip.getEntry(contentFile.getName());
        lastModified = entry.getTime();
    } catch (IOException e) {
        log.error("Failed to read zip file located at {}.zip", packageDir.getAbsolutePath(), e);
    }

    if (lastModified == -1) {
        lastModified = zipFile.lastModified();
    }

    DateTime modified = new DateTime(lastModified, DateTimeZone.UTC);

    // Deserialize the data document
    SAXBuilder builder = new SAXBuilder();
    Element dataRoot = null;
    Document mods = null;
    try {

        Document dataDocument = builder.build(dataFile);
        dataRoot = dataDocument.getRootElement();

        // Transform the data into MODS and store it to its final resting place
        mods = extractMods(primaryPID, dataRoot, modified);
    } catch (TransformerException e) {
        failJob(e, Type.NORMALIZATION, "Failed to transform metadata to MODS");
    } catch (Exception e) {
        failJob(e, Type.NORMALIZATION, "Unable to deserialize the metadata file");
    }

    // Detect if there are any attachments
    List<?> attachmentElements = dataRoot.getChild("DISS_content").getChildren("DISS_attachment");

    if (attachmentElements == null || attachmentElements.size() == 0) {

        // Simple object with the content as its source data
        primaryResource = populateSimple(model, primaryPID, contentFile);
    } else {
        String title = mods.getRootElement().getChild("titleInfo", MODS_V3_NS).getChildText("title",
                MODS_V3_NS);

        // Has attachments, so it is an aggregate
        primaryResource = populateAggregate(model, primaryPID, attachmentElements, attachmentDir, contentFile,
                title);
    }

    // Store primary resource as child of the deposit
    depositBag.add(primaryResource);

    // Add the data file as a metadata datastream of the primary object
    setSourceMetadata(model, primaryResource, dataFile);

    // Capture other metadata, like embargoes
    setEmbargoUntil(model, primaryResource, dataRoot);

    // Creation date for the content file
    model.add(primaryResource, cdrprop(model, dateCreated), modified.toString(), XSDDatatype.XSDdateTime);
}

From source file:edu.unc.lib.dl.services.DigitalObjectManagerImpl.java

License:Apache License

/**
 * @param lastKnownGoodTime//w ww .  j a  va 2s  . co  m
 * @param pids
 */
private void dumpRollbackInfo(DateTime lastKnownGoodTime, List<PID> pids, String reason) {
    StringBuffer sb = new StringBuffer();
    sb.append("DATA CORRUPTION LOG:\n").append("REASON:").append(reason).append("\n")
            .append("LAST KNOWN GOOD TIME: ").append(lastKnownGoodTime.toString()).append("\n")
            .append(pids.size()).append(" FEDORA PIDS CREATED OR MODIFIED:\n");
    for (PID p : pids) {
        sb.append(p.getPid()).append("\n");
    }
    log.error(sb.toString());
}

From source file:eu.enhan.timelord.domain.util.DateTimeToStringConverter.java

License:Open Source License

@Override
public String convert(DateTime source) {
    return source.toString();
}

From source file:eu.esdihumboldt.hale.common.headless.impl.WorkspaceServiceImpl.java

License:Open Source License

/**
 * @see WorkspaceService#leaseWorkspace(ReadableDuration)
 *//*from   w  w w . j  a v a 2s .  com*/
@Override
public String leaseWorkspace(ReadableDuration duration) {
    File workspace = newFolder();

    DateTime leaseEnd = DateTime.now().plus(duration);

    File configFile = configFile(workspace);

    PropertiesFile props;
    try {
        props = new PropertiesFile(configFile);
        props.setProperty(PROPERTY_LEASE_END, leaseEnd.toString());
        props.save();
    } catch (IOException e) {
        throw new IllegalStateException("Can't write to workspace folder", e);
    }

    log.info("Leasing workspace " + workspace.getName() + " until " + leaseEnd.toString());

    return workspace.getName();
}

From source file:eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact.java

License:Open Source License

/**
 * Acceptance date/time not before report creation date/time.
 *
 * @param creationDate   The report creation date/time.
 * @param acceptanceDate The acceptance date/time.
 * @param minutes        A threshold in minutes to compensate for incorrect clock synchronization of the exchanging systems.
 *//*from   w  w  w. j ava 2  s.  c om*/
public boolean acceptanceDateNotBeforeCreationDate(Date creationDate, Date acceptanceDate, int minutes) {

    boolean acceptanceDateNotAfterCreationDate = true;
    if (creationDate != null && acceptanceDate != null) {
        DateTime creationDateTime = new DateTime(creationDate).toDateTime(DateTimeZone.UTC)
                .plusMinutes(minutes);
        DateTime acceptanceDateTime = new DateTime(acceptanceDate).toDateTime(DateTimeZone.UTC);
        log.debug("creationDate is {}", creationDateTime.toString());
        log.debug("acceptanceDateTime is {}", acceptanceDateTime.toString());
        acceptanceDateNotAfterCreationDate = acceptanceDateTime.toDate().before(creationDateTime.toDate());

    }
    return acceptanceDateNotAfterCreationDate;
}

From source file:eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact.java

License:Open Source License

/**
 * Message creation date/time not in the past.
 *
 * @param creationDate The Message creation date/time to be verified.
 * @param minutes      A threshold in minutes to compensate for incorrect clock synchronization of the exchanging systems.
 *///from   w w  w.  java2 s . c  o m
public boolean dateNotInPast(Date creationDate, int minutes) {

    boolean notInPast = true;
    if (creationDate != null) {
        DateTime now = eu.europa.ec.fisheries.uvms.commons.date.DateUtils.nowUTC();
        log.debug("now is {}", now.toString());
        now = now.plusMinutes(minutes);
        DateTime creationDateUTC = new DateTime(creationDate).toDateTime(DateTimeZone.UTC);
        log.debug("creationDate is {}", creationDateUTC.toString());
        notInPast = !creationDateUTC.toDate().before(now.toDate());
    }
    return notInPast;
}

From source file:eu.europeana.uim.gui.cp.server.IntegrationSeviceProxyImpl.java

License:EUPL

@Override
public RepoxExecutionStatusDTO performRepoxRemoteOperation(RepoxOperationType operationType,
        String collectionID) {/*from ww w. j av  a  2 s.  co  m*/

    ExpandedOsgiEngine engine = getEngine();
    RepoxUIMService repoxService = engine.getRepoxService();
    StorageEngine<?> stengine = engine.getRegistry().getStorageEngine();

    RepoxExecutionStatusDTO result = new RepoxExecutionStatusDTO();
    Collection<?> coll = null;

    try {
        coll = stengine.findCollection(collectionID);
    } catch (StorageEngineException e) {

        e.printStackTrace();

        return result;
    }

    switch (operationType) {

    case VIEW_HARVEST_LOG:
        try {
            String log = repoxService.getHarvestLog(coll);
            result.setOperationMessage("Successfully Fetched Latest Harvest Log for Current Collection");
            result.setLogMessage(log);
        } catch (HarvestingOperationException e) {

            result.setOperationMessage("Error fetching Harvest Log!");
            result.setLogMessage(e.getMessage());
        }
        break;

    case INITIATE_COMPLETE_HARVESTING:
        try {
            repoxService.initiateHarvestingfromUIMObj(coll, true);
            result.setOperationMessage("Successfully initiated FULL harvesting for " + coll.getName());
            result.setLogMessage("Harvesting initiated.");
        } catch (HarvestingOperationException e) {
            result.setOperationMessage("Error initiating a harvesting process for the current collection!");
            result.setLogMessage(e.getMessage());
        }

        break;

    case INITIATE_INCREMENTAL_HARVESTING:
        try {
            repoxService.initiateHarvestingfromUIMObj(coll, true);
            result.setOperationMessage("Successfully initiated INCREMENTAL harvesting for " + coll.getName());
            result.setLogMessage("Harvesting initiated.");
        } catch (HarvestingOperationException e) {
            result.setOperationMessage("Error initiating a harvesting process for the current collection!");
            result.setLogMessage(e.getMessage());
        }

        break;

    case SCHEDULE_HARVESTING:

        DateTime ingestionDate = new DateTime();

        try {
            ScheduleInfo info = new ScheduleInfo();
            repoxService.scheduleHarvestingfromUIMObj(coll, info);
            result.setOperationMessage("Successfully Performed Scheduling for given dataset ");
            result.setLogMessage("Harvesting Date: " + ingestionDate.toString());
        } catch (HarvestingOperationException e) {
            result.setOperationMessage("Scheduling failed for given dataset ");
            result.setLogMessage(e.getMessage());
        }
        break;

    }

    return result;
}