Example usage for java.time Instant toString

List of usage examples for java.time Instant toString

Introduction

In this page you can find the example usage for java.time Instant toString.

Prototype

@Override
public String toString() 

Source Link

Document

A string representation of this instant using ISO-8601 representation.

Usage

From source file:com.orange.cepheus.cep.SubscriptionManager.java

private void periodicSubscriptionTask() {

    Instant now = Instant.now();
    Instant nextSubscriptionTaskDate = now.plusMillis(subscriptionPeriodicity);
    logger.info("Launch of the periodic subscription task at {}", now.toString());

    // Futures will use the current subscription list.
    // So that they will not add old subscriptions to a new configuration.
    Subscriptions subscriptions = this.subscriptions;

    for (EventTypeIn eventType : eventTypeIns) {
        SubscribeContext subscribeContext = null;
        for (Provider provider : eventType.getProviders()) {

            boolean deadlineIsPassed = false;
            Instant subscriptionDate = provider.getSubscriptionDate();
            if (subscriptionDate != null) {
                Instant subscriptionEndDate = subscriptionDate.plus(Duration.parse(subscriptionDuration));
                // check if deadline is passed
                if (nextSubscriptionTaskDate.compareTo(subscriptionEndDate) >= 0) {
                    deadlineIsPassed = true;
                    String subscriptionId = provider.getSubscriptionId();
                    // if delay is passed then clear the subscription info in provider et suppress subscription
                    if (subscriptionId != null) {
                        subscriptions.removeSubscription(subscriptionId);
                        provider.setSubscriptionId(null);
                        provider.setSubscriptionDate(null);
                    }//from   w ww  .  jav  a2  s .com
                }
            }
            //Send subscription if subscription is a new subscription or we do not receive a response (subscriptionDate is null)
            //Send subscription if deadline is passed
            if ((subscriptionDate == null) || deadlineIsPassed) {
                // lazy build body request only when the first request requires it
                if (subscribeContext == null) {
                    subscribeContext = buildSubscribeContext(eventType);
                }
                subscribeProvider(provider, subscribeContext, subscriptions);
            }
        }
    }
}

From source file:com.arrow.acs.client.api.ApiAbstract.java

private void addHeaders(HttpRequestBase msg, Instant timestamp, String signature) {
    Validate.notNull(msg, "msg is null");
    Validate.notNull(timestamp, "timestamp is null");
    Validate.notEmpty(apiConfig.getApiKey(), "apiKey is empty");
    msg.addHeader(HttpHeaders.CONTENT_TYPE, MIME_APPLICATION_JSON);
    msg.addHeader(HttpHeaders.ACCEPT, MIME_APPLICATION_JSON);
    msg.addHeader(ApiHeaders.X_ARROW_APIKEY, apiConfig.getApiKey());
    msg.addHeader(ApiHeaders.X_ARROW_DATE, timestamp.toString());
    msg.addHeader(ApiHeaders.X_ARROW_VERSION, ApiHeaders.X_ARROW_VERSION_1);
    msg.addHeader(ApiHeaders.X_ARROW_SIGNATURE, signature);
}

From source file:com.arrow.acs.client.api.ApiAbstract.java

private ApiRequestSigner getSigner(HttpRequestBase request, Instant timestamp) {
    Validate.notNull(request, "request is null");
    Validate.notNull(timestamp, "timestamp is null");
    Validate.notEmpty(apiConfig.getApiKey(), "apiKey is empty");
    Validate.notEmpty(apiConfig.getSecretKey(), "secretKey is empty");
    return ApiRequestSigner.create(apiConfig.getSecretKey()).method(request.getMethod())
            .canonicalUri(request.getURI().getPath()).apiKey(apiConfig.getApiKey())
            .timestamp(timestamp.toString());
}

From source file:org.codice.ddf.admin.insecure.defaults.service.DefaultUsersDeletionScheduler.java

private boolean createTempFile(Instant instant) {
    try {//from www. j a v a 2 s  .com
        if (getTempTimestampFilePath().toFile().createNewFile()) {
            Files.write(getTempTimestampFilePath(), instant.toString().getBytes(StandardCharsets.UTF_8));
            return true;
        }
    } catch (IOException e) {
        LOGGER.debug("Unable to access the temporary file", e);
    }
    return false;
}

From source file:org.sakaiproject.contentreview.turnitin.oc.ContentReviewServiceTurnitinOC.java

private String getSubmissionId(ContentReviewItem item, String fileName, Site site, Assignment assignment) {
    String userID = item.getUserId();

    String submissionId = null;//from  w  w w  .j  a  v  a  2  s.c  o m
    try {

        // Build header maps
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("owner", userID);
        data.put("title", fileName);
        Instant eulaTimestamp = getUserEULATimestamp(userID);
        String eulaVersion = getUserEULAVersion(userID);
        if (eulaTimestamp != null && StringUtils.isNotEmpty(eulaVersion)) {
            Map<String, Object> eula = new HashMap<String, Object>();
            eula.put("accepted_timestamp", eulaTimestamp.toString());
            eula.put("language", getUserEulaLocale(userID));
            eula.put("version", eulaVersion);
            data.put("eula", eula);
        }
        if (assignment != null) {
            Map<String, Object> metadata = new HashMap<String, Object>();
            Map<String, Object> group = new HashMap<String, Object>();
            group.put("id", assignment.getId());
            group.put("name", assignment.getTitle());
            group.put("type", "ASSIGNMENT");
            metadata.put("group", group);
            if (site != null) {
                Map<String, Object> groupContext = new HashMap<String, Object>();
                groupContext.put("id", site.getId());
                groupContext.put("name", site.getTitle());
                metadata.put("group_context", groupContext);
            }
            data.put("metadata", metadata);
        }
        HashMap<String, Object> response = makeHttpCall("POST", getNormalizedServiceUrl() + "submissions",
                SUBMISSION_REQUEST_HEADERS, data, null);

        // Get response:
        int responseCode = !response.containsKey(RESPONSE_CODE) ? 0 : (int) response.get(RESPONSE_CODE);
        String responseMessage = !response.containsKey(RESPONSE_MESSAGE) ? ""
                : (String) response.get(RESPONSE_MESSAGE);
        String responseBody = !response.containsKey(RESPONSE_BODY) ? "" : (String) response.get(RESPONSE_BODY);

        // create JSONObject from responseBody
        JSONObject responseJSON = JSONObject.fromObject(responseBody);

        if ((responseCode >= 200) && (responseCode < 300)) {
            String status = responseJSON.containsKey("status") ? responseJSON.getString("status") : null;
            if (STATUS_CREATED.equals(status) && responseJSON.containsKey("id")) {
                submissionId = responseJSON.getString("id");
            } else {
                log.error("getSubmissionId response: " + responseMessage);
                item.setLastError("Unexpected response from Turnitin. Response code is " + responseCode + ". "
                        + (STATUS_CREATED.equals(status) ? "Expected a Turnitin ID, but none was provided"
                                : "Status is: " + status));
            }
        } else {
            log.error("getSubmissionId response code: " + responseCode + ", " + responseMessage + ", "
                    + responseJSON);
            item.setLastError(responseCode + " - " + responseMessage);
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        item.setLastError("A problem occurred communicating with Turnitin");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        item.setLastError("An unknown / unhandled error has occurred");
    }

    return submissionId;
}

From source file:org.trellisldp.rosid.file.FileResourceService.java

private void init() throws IOException {
    for (final Map.Entry<String, String> storage : partitions.entrySet()) {
        final File data = storage.getValue().startsWith("file:") ? new File(create(storage.getValue()))
                : new File(storage.getValue());
        LOGGER.info("Using resource data directory for '{}': {}", storage.getKey(), data.getAbsolutePath());
        if (!data.exists()) {
            data.mkdirs();/*from  w w  w .  j a  v a2  s . co m*/
        }
        if (!data.canWrite()) {
            throw new IOException("Cannot write to " + data.getAbsolutePath());
        }
        final IRI identifier = rdf.createIRI(TRELLIS_PREFIX + storage.getKey());
        final IRI authIdentifier = rdf.createIRI(TRELLIS_PREFIX + storage.getKey() + "#auth");
        final File root = resourceDirectory(partitions, identifier);
        final File rootData = new File(root, RESOURCE_JOURNAL);

        if (!root.exists() || !rootData.exists()) {
            LOGGER.info("Initializing root container for '{}'", identifier.getIRIString());
            root.mkdirs();
            final Instant time = now();
            final IRI skolem = (IRI) skolemize(rdf.createBlankNode());
            final Stream<Quad> quads = of(
                    rdf.createQuad(Trellis.PreferServerManaged, identifier, RDF.type, LDP.Container),
                    rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, RDF.type, ACL.Authorization),
                    rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.mode, ACL.Read),
                    rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.mode, ACL.Write),
                    rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.mode, ACL.Control),
                    rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.accessTo, identifier),
                    rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.agentClass, FOAF.Agent),
                    rdf.createQuad(Trellis.PreferAudit, identifier, PROV.wasGeneratedBy, skolem),
                    rdf.createQuad(Trellis.PreferAudit, skolem, RDF.type, PROV.Activity),
                    rdf.createQuad(Trellis.PreferAudit, skolem, RDF.type, AS.Create),
                    rdf.createQuad(Trellis.PreferAudit, skolem, PROV.wasAssociatedWith,
                            Trellis.RepositoryAdministrator),
                    rdf.createQuad(Trellis.PreferAudit, skolem, PROV.generatedAtTime,
                            rdf.createLiteral(time.toString(), XSD.dateTime)));
            RDFPatch.write(rootData, empty(), quads, now());
            CachedResource.write(root, identifier);
        }
    }
}

From source file:org.trellisldp.triplestore.TriplestoreResourceService.java

private void storeResource(final IRI identifier, final Dataset dataset, final Instant eventTime,
        final OperationType type) {
    final Literal time = rdf.createLiteral(eventTime.toString(), XSD.dateTime);
    try {/*from  ww  w.  jav  a2s. c  om*/
        rdfConnection.update(buildUpdateRequest(identifier, time, dataset, type));
    } catch (final Exception ex) {
        throw new RuntimeTrellisException("Could not update data for " + identifier, ex);
    }
}

From source file:org.trellisldp.triplestore.TriplestoreResourceServiceTest.java

@Test
public void testInitializeRoot2() {
    final Instant early = now();
    final JenaDataset dataset = rdf.createDataset();
    dataset.add(Trellis.PreferServerManaged, root, RDF.type, LDP.BasicContainer);
    dataset.add(Trellis.PreferServerManaged, root, DC.modified,
            rdf.createLiteral(early.toString(), XSD.dateTime));

    final RDFConnection rdfConnection = connect(wrap(dataset.asJenaDatasetGraph()));
    final TriplestoreResourceService svc = new TriplestoreResourceService(rdfConnection);
    svc.initialize();//  w  w w .  j a va  2s. c om

    final Resource res = svc.get(root).toCompletableFuture().join();
    assertAll("Check resource", checkResource(res, root, LDP.BasicContainer, early));
    assertAll("Check resource stream", checkResourceStream(res, 0L, 0L, 0L, 0L, 0L));
}