Example usage for java.time ZoneId of

List of usage examples for java.time ZoneId of

Introduction

In this page you can find the example usage for java.time ZoneId of.

Prototype

public static ZoneId of(String zoneId) 

Source Link

Document

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

Usage

From source file:org.apache.james.mailbox.elasticsearch.json.IndexableMessageTest.java

@Test
public void textShouldContainsBodyWhenBody() throws Exception {
    MailboxMessage mailboxMessage = mock(MailboxMessage.class);
    TestId mailboxId = TestId.of(1);//from   ww w . jav  a 2 s  .c  o  m
    when(mailboxMessage.getMailboxId()).thenReturn(mailboxId);
    when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream("\nMy body".getBytes()));
    when(mailboxMessage.createFlags()).thenReturn(new Flags());

    IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage,
            ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(),
            ZoneId.of("Europe/Paris"));

    assertThat(indexableMessage.getText()).isEqualTo("My body");
}

From source file:org.silverpeas.core.webapi.calendar.CalendarEntity.java

/**
 * Merges into given calendar instance the data from the entity.<br>
 * System data are not merged (id, creation date, update date, ...)
 * @param calendar the calendar which will get the new data.
 * @return the given calendar instance with merged data.
 * @throw javax.ws.rs.WebApplicationException if given calendar does not exist.
 *//* w w  w.j  a  v a2  s  . c om*/
public Calendar merge(Calendar calendar) {
    calendar.setTitle(getTitle());
    if (getExternalUrl() != null) {
        try {
            calendar.setExternalCalendarUrl(getExternalUrl().toURL());
        } catch (MalformedURLException e) {
            throw new WebApplicationException(e);
        }
    }
    if (isDefined(getZoneId())) {
        calendar.setZoneId(ZoneId.of(getZoneId()));
    } else {
        throw new WebApplicationException("zoneId must exist into calendar attributes",
                Response.Status.NOT_ACCEPTABLE);
    }
    return calendar;
}

From source file:io.manasobi.utils.DateUtils.java

public static LocalDateTime convertToDateTime(long timeMillis) {
    Date date = new Date(timeMillis);
    return date.toInstant().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime();
}

From source file:dk.dma.ais.packet.AisPacketCSVOutputSink.java

private void addTimestampPretty(List fields, AisPacket packet) {
    final long timestamp = packet.getBestTimestamp();
    if (timestamp >= 0)
        fields.add(DateTimeFormatter.ofPattern("dd/MM/uuuu HH:mm:ss")
                .format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.of("UTC"))));
    else/*w w w. java 2s  .  c  o m*/
        fields.add("null");
}

From source file:com.streamsets.pipeline.stage.origin.http.HttpClientSource.java

/** {@inheritDoc} */
@Override/*  ww  w  .j  av a 2 s  .  com*/
protected List<ConfigIssue> init() {
    List<ConfigIssue> issues = super.init();
    errorRecordHandler = new DefaultErrorRecordHandler(getContext()); // NOSONAR

    conf.basic.init(getContext(), Groups.HTTP.name(), BASIC_CONFIG_PREFIX, issues);
    conf.dataFormatConfig.init(getContext(), conf.dataFormat, Groups.HTTP.name(), DATA_FORMAT_CONFIG_PREFIX,
            issues);
    conf.init(getContext(), Groups.HTTP.name(), "conf.", issues);
    if (conf.client.tlsConfig.isEnabled()) {
        conf.client.tlsConfig.init(getContext(), Groups.TLS.name(), TLS_CONFIG_PREFIX, issues);
    }

    resourceVars = getContext().createELVars();
    resourceEval = getContext().createELEval(RESOURCE_CONFIG_NAME);

    bodyVars = getContext().createELVars();
    bodyEval = getContext().createELEval(REQUEST_BODY_CONFIG_NAME);
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(ZoneId.of(conf.timeZoneID)));
    TimeEL.setCalendarInContext(bodyVars, calendar);

    headerVars = getContext().createELVars();
    headerEval = getContext().createELEval(HEADER_CONFIG_NAME);

    stopVars = getContext().createELVars();
    stopEval = getContext().createELEval(STOP_CONFIG_NAME);

    next = null;
    haveMorePages = false;

    if (conf.responseStatusActionConfigs != null) {
        final String cfgName = "conf.responseStatusActionConfigs";
        final EnumSet<ResponseAction> backoffRetries = EnumSet.of(ResponseAction.RETRY_EXPONENTIAL_BACKOFF,
                ResponseAction.RETRY_LINEAR_BACKOFF);

        for (HttpResponseActionConfigBean actionConfig : conf.responseStatusActionConfigs) {
            final HttpResponseActionConfigBean prevAction = statusToActionConfigs
                    .put(actionConfig.getStatusCode(), actionConfig);

            if (prevAction != null) {
                issues.add(getContext().createConfigIssue(Groups.HTTP.name(), cfgName, Errors.HTTP_17,
                        actionConfig.getStatusCode()));
            }
            if (backoffRetries.contains(actionConfig.getAction()) && actionConfig.getBackoffInterval() <= 0) {
                issues.add(getContext().createConfigIssue(Groups.HTTP.name(), cfgName, Errors.HTTP_15));
            }
            if (actionConfig.getStatusCode() >= 200 && actionConfig.getStatusCode() < 300) {
                issues.add(getContext().createConfigIssue(Groups.HTTP.name(), cfgName, Errors.HTTP_16));
            }
        }
    }
    this.timeoutActionConfig = conf.responseTimeoutActionConfig;

    // Validation succeeded so configure the client.
    if (issues.isEmpty()) {
        try {
            configureClient(issues);
        } catch (StageException e) {
            // should not happen on initial connect
            ExceptionUtils.throwUndeclared(e);
        }
    }
    return issues;
}

From source file:com.baasbox.controllers.actions.filters.WrapResponse.java

private void setServerTime(Http.Response response) {
    ZonedDateTime date = ZonedDateTime.now(ZoneId.of("GMT"));
    String httpDate = DateTimeFormatter.RFC_1123_DATE_TIME.format(date);
    response.setHeader("Date", httpDate);
}

From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java

@Test
public void simpleEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
    MailboxMessage mail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mail.eml"))),
            new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
            propertyBuilder, MAILBOX_ID);
    mail.setModSeq(MOD_SEQ);//w  w w  . j a  va  2s .c  o  m
    mail.setUid(UID);
    assertThatJson(messageToElasticSearchJson.convertToJson(mail,
            ImmutableList.of(new MockMailboxSession("user1").getUser(),
                    new MockMailboxSession("user2").getUser()))).when(IGNORING_ARRAY_ORDER)
                            .when(IGNORING_VALUES)
                            .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/mail.json")));
}

From source file:org.apache.james.mailbox.elasticsearch.json.IndexableMessageTest.java

@Test
public void textShouldContainsAllFieldsWhenAllSet() throws Exception {
    MailboxMessage mailboxMessage = mock(MailboxMessage.class);
    TestId mailboxId = TestId.of(1);/*from  w  w  w  .  j  a  v  a 2 s . co  m*/
    when(mailboxMessage.getMailboxId()).thenReturn(mailboxId);
    when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream(
            IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml"))));
    when(mailboxMessage.createFlags()).thenReturn(new Flags());

    IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage,
            ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(),
            ZoneId.of("Europe/Paris"));

    assertThat(indexableMessage.getText()).isEqualTo("Ad Min admin@opush.test " + "a@test a@test B b@test "
            + "c@test c@test " + "dD d@test " + "my subject " + "Mail content\n" + "\n" + "-- \n" + "Ad Min\n");
}

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

@Test
public void testMigrationWithExistingRecord() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();

    try {/*from   ww w.ja v a 2s  .co m*/
        eventMigrationRepository.insertMigrationData(event.getId(), "1.4",
                ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1), EventMigration.Status.COMPLETE.toString());
        eventRepository.updatePrices("CHF", 40, false, BigDecimal.ONE, "STRIPE", event.getId(),
                PriceContainer.VatStatus.NOT_INCLUDED, 1000);
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        //assertEquals(buildTimestamp, eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());

        List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
        assertNotNull(tickets);
        assertFalse(tickets.isEmpty());
        assertEquals(20, tickets.size());
        assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}

From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java

@Test
public void recursiveEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"));
    MailboxMessage recursiveMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))),
            new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
            propertyBuilder, MAILBOX_ID);
    recursiveMail.setModSeq(MOD_SEQ);/* ww  w  .  j a va  2 s  . com*/
    recursiveMail.setUid(UID);
    assertThatJson(messageToElasticSearchJson.convertToJson(recursiveMail,
            ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER)
                    .when(IGNORING_VALUES)
                    .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMail.json")));
}