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:alfio.manager.EventManager.java

private int insertEvent(EventModification em) {
    String paymentProxies = collectPaymentProxies(em);
    BigDecimal vat = !em.isInternal() || em.isFreeOfCharge() ? BigDecimal.ZERO : em.getVatPercentage();
    String privateKey = UUID.randomUUID().toString();
    ZoneId zoneId = ZoneId.of(em.getZoneId());
    String currentVersion = flyway.info().current().getVersion().getVersion();
    return eventRepository.insert(em.getShortName(), em.getEventType(), em.getDisplayName(), em.getWebsiteUrl(),
            em.getExternalUrl(), em.isInternal() ? em.getTermsAndConditionsUrl() : "", em.getImageUrl(),
            em.getFileBlobId(), em.getLocation(), em.getLatitude(), em.getLongitude(),
            em.getBegin().toZonedDateTime(zoneId), em.getEnd().toZonedDateTime(zoneId), em.getZoneId(),
            em.getCurrency(), em.getAvailableSeats(), em.isInternal() && em.isVatIncluded(), vat,
            paymentProxies, privateKey, em.getOrganizationId(), em.getLocales(), em.getVatStatus(),
            em.getPriceInCents(), currentVersion, Event.Status.DRAFT).getKey();
}

From source file:net.nikr.eve.jeveasset.gui.tabs.tracker.TrackerTab.java

private Date getFromDate() {
    LocalDate date = jFrom.getDate();
    if (date == null) {
        return null;
    }//from w  w w  .j av a 2  s . co m
    Instant instant = date.atStartOfDay().atZone(ZoneId.of("GMT")).toInstant(); //Start of day - GMT
    return Date.from(instant);
}

From source file:net.nikr.eve.jeveasset.gui.tabs.tracker.TrackerTab.java

private Date getToDate() {
    LocalDate date = jTo.getDate();
    if (date == null) {
        return null;
    }/*from   ww w  .ja  va 2 s.co  m*/
    Instant instant = date.atTime(23, 59, 59).atZone(ZoneId.of("GMT")).toInstant(); //End of day - GMT
    return Date.from(instant);
}

From source file:net.nikr.eve.jeveasset.gui.tabs.tracker.TrackerTab.java

private LocalDate dateToLocalDate(Date date) {
    Instant instant = date.toInstant();
    return LocalDateTime.ofInstant(instant, ZoneId.of("GMT")).toLocalDate();
}

From source file:org.fcrepo.integration.http.api.FedoraVersioningIT.java

@Test
public void testDatetimeNegotiationLDPRv() throws Exception {
    final CloseableHttpClient customClient = createClient(true);
    final DateTimeFormatter FMT = RFC_1123_DATE_TIME.withZone(ZoneId.of("UTC"));

    createVersionedContainer(id);/*from  w  w w .ja v a 2 s.c om*/
    final String memento1 = FMT.format(ISO_INSTANT.parse("2017-06-10T11:41:00Z", Instant::from));
    final String version1Uri = createLDPRSMementoWithExistingBody(memento1);
    final String memento2 = FMT.format(ISO_INSTANT.parse("2016-06-17T11:41:00Z", Instant::from));
    final String version2Uri = createLDPRSMementoWithExistingBody(memento2);

    final String request1Datetime = FMT.format(ISO_INSTANT.parse("2017-01-12T00:00:00Z", Instant::from));
    final HttpGet getMemento = getObjMethod(id);
    getMemento.addHeader(ACCEPT_DATETIME, request1Datetime);

    try (final CloseableHttpResponse response = customClient.execute(getMemento)) {
        assertEquals("Did not get FOUND response", FOUND.getStatusCode(), getStatus(response));
        assertNoMementoDatetimeHeaderPresent(response);
        assertEquals("Did not get Location header", version2Uri, response.getFirstHeader(LOCATION).getValue());
        assertEquals("Did not get Content-Length == 0", "0",
                response.getFirstHeader(CONTENT_LENGTH).getValue());
    }

    final String request2Datetime = FMT.format(ISO_INSTANT.parse("2018-01-10T00:00:00Z", Instant::from));
    final HttpGet getMemento2 = getObjMethod(id);
    getMemento2.addHeader(ACCEPT_DATETIME, request2Datetime);

    try (final CloseableHttpResponse response = customClient.execute(getMemento2)) {
        assertEquals("Did not get FOUND response", FOUND.getStatusCode(), getStatus(response));
        assertNoMementoDatetimeHeaderPresent(response);
        assertEquals("Did not get Location header", version1Uri, response.getFirstHeader(LOCATION).getValue());
        assertEquals("Did not get Content-Length == 0", "0",
                response.getFirstHeader(CONTENT_LENGTH).getValue());
    }
}

From source file:org.fcrepo.integration.http.api.FedoraVersioningIT.java

@Test
public void testDatetimeNegotiationNoMementos() throws Exception {
    final CloseableHttpClient customClient = createClient(true);
    final DateTimeFormatter FMT = RFC_1123_DATE_TIME.withZone(ZoneId.of("UTC"));

    createVersionedContainer(id);//from ww w .  j ava  2 s.  c  o  m
    final String requestDatetime = FMT.format(ISO_INSTANT.parse("2017-01-12T00:00:00Z", Instant::from));
    final HttpGet getMemento = getObjMethod(id);
    getMemento.addHeader(ACCEPT_DATETIME, requestDatetime);

    try (final CloseableHttpResponse response = customClient.execute(getMemento)) {
        assertEquals("Did not get NOT_FOUND response", NOT_FOUND.getStatusCode(), getStatus(response));
        assertNull("Did not expect a Location header", response.getFirstHeader(LOCATION));
        assertNotEquals("Did not get Content-Length > 0", 0,
                response.getFirstHeader(CONTENT_LENGTH).getValue());
    }
}

From source file:org.fcrepo.integration.http.api.FedoraVersioningIT.java

@Test
public void testGetLDPRSMementoHeaders() throws Exception {
    final DateTimeFormatter FMT = RFC_1123_DATE_TIME.withZone(ZoneId.of("UTC"));
    createVersionedContainer(id);//  w  w  w  . ja  v a 2  s  .c  om

    final String memento1 = FMT.format(ISO_INSTANT.parse("2001-06-10T16:41:00Z", Instant::from));
    final String version1Uri = createLDPRSMementoWithExistingBody(memento1);
    final HttpGet getRequest = new HttpGet(version1Uri);

    try (final CloseableHttpResponse response = execute(getRequest)) {
        assertMementoDatetimeHeaderMatches(response, memento1);
        checkForLinkHeader(response, MEMENTO_TYPE, "type");
        checkForLinkHeader(response, subjectUri, "original");
        checkForLinkHeader(response, subjectUri, "timegate");
        checkForLinkHeader(response, subjectUri + "/" + FCR_VERSIONS, "timemap");
        checkForLinkHeader(response, RESOURCE.toString(), "type");
        assertNoLinkHeader(response, VERSIONED_RESOURCE.toString(), "type");
        assertNoLinkHeader(response, VERSIONING_TIMEMAP_TYPE.toString(), "type");
        assertNoLinkHeader(response, version1Uri + "/" + FCR_ACL, "acl");
    }
}

From source file:org.fcrepo.integration.http.api.FedoraVersioningIT.java

@Test
public void testGetLDPNRMementoHeaders() throws Exception {
    final DateTimeFormatter FMT = RFC_1123_DATE_TIME.withZone(ZoneId.of("UTC"));
    createVersionedBinary(id, "text/plain", "This is some versioned content");

    final String memento1 = FMT.format(ISO_INSTANT.parse("2001-06-10T16:41:00Z", Instant::from));
    final String version1Uri = createLDPNRMementoWithExistingBody(memento1);
    final HttpGet getRequest = new HttpGet(version1Uri);

    try (final CloseableHttpResponse response = execute(getRequest)) {
        assertMementoDatetimeHeaderMatches(response, memento1);
        checkForLinkHeader(response, MEMENTO_TYPE, "type");
        checkForLinkHeader(response, subjectUri, "original");
        checkForLinkHeader(response, subjectUri, "timegate");
        checkForLinkHeader(response, subjectUri + "/" + FCR_VERSIONS, "timemap");
        checkForLinkHeader(response, NON_RDF_SOURCE.toString(), "type");
        assertNoLinkHeader(response, VERSIONED_RESOURCE.toString(), "type");
        assertNoLinkHeader(response, VERSIONING_TIMEMAP_TYPE.toString(), "type");
        assertNoLinkHeader(response, version1Uri + "/" + FCR_ACL, "acl");
    }/*from w  w  w  . j ava2  s. c om*/
}

From source file:com.streamsets.pipeline.stage.origin.jdbc.cdc.oracle.OracleCDCSource.java

@Override
public List<ConfigIssue> init() {
    List<ConfigIssue> issues = super.init();
    errorRecordHandler = new DefaultErrorRecordHandler(getContext());
    useLocalBuffering = !getContext().isPreview() && configBean.bufferLocally;
    if (!hikariConfigBean.driverClassName.isEmpty()) {
        try {//from   w ww  . j  ava  2  s .  c om
            Class.forName(hikariConfigBean.driverClassName);
        } catch (ClassNotFoundException e) {
            LOG.error("Hikari Driver class not found.", e);
            issues.add(getContext().createConfigIssue(Groups.LEGACY.name(), DRIVER_CLASSNAME,
                    JdbcErrors.JDBC_28, e.toString()));
        }
    }
    issues = hikariConfigBean.validateConfigs(getContext(), issues);
    if (connection == null) { // For tests, we set a mock connection
        try {
            dataSource = jdbcUtil.createDataSourceForRead(hikariConfigBean);
            connection = dataSource.getConnection();
            connection.setAutoCommit(false);
        } catch (StageException | SQLException e) {
            LOG.error("Error while connecting to DB", e);
            issues.add(
                    getContext().createConfigIssue(Groups.JDBC.name(), CONNECTION_STR, JDBC_00, e.toString()));
            return issues;
        }
    }

    recordQueue = new LinkedBlockingQueue<>(2 * configBean.baseConfigBean.maxBatchSize);
    String container = configBean.pdb;

    List<SchemaAndTable> schemasAndTables;

    try {
        initializeStatements();
        alterSession();
    } catch (SQLException ex) {
        LOG.error("Error while creating statement", ex);
        issues.add(getContext().createConfigIssue(Groups.JDBC.name(), CONNECTION_STR, JDBC_00,
                hikariConfigBean.getConnectionString()));
    }
    zoneId = ZoneId.of(configBean.dbTimeZone);
    dateTimeColumnHandler = new DateTimeColumnHandler(zoneId);
    String commitScnField;
    BigDecimal scn = null;
    try {
        scn = getEndingSCN();
        switch (configBean.startValue) {
        case SCN:
            if (new BigDecimal(configBean.startSCN).compareTo(scn) > 0) {
                issues.add(getContext().createConfigIssue(CDC.name(), "oracleCDCConfigBean.startSCN", JDBC_47,
                        scn.toPlainString()));
            }
            break;
        case LATEST:
            // If LATEST is used, use now() as the startDate and proceed as if a startDate was specified
            configBean.startDate = nowAtDBTz().format(dateTimeColumnHandler.dateFormatter);
            // fall-through
        case DATE:
            try {
                LocalDateTime startDate = dateTimeColumnHandler.getDate(configBean.startDate);
                if (startDate.isAfter(nowAtDBTz())) {
                    issues.add(getContext().createConfigIssue(CDC.name(), "oracleCDCConfigBean.startDate",
                            JDBC_48));
                }
            } catch (DateTimeParseException ex) {
                LOG.error("Invalid date", ex);
                issues.add(
                        getContext().createConfigIssue(CDC.name(), "oracleCDCConfigBean.startDate", JDBC_49));
            }
            break;
        default:
            throw new IllegalStateException("Unknown start value!");
        }
    } catch (SQLException ex) {
        LOG.error("Error while getting SCN", ex);
        issues.add(getContext().createConfigIssue(CREDENTIALS.name(), USERNAME, JDBC_42));
    }

    try (Statement reusedStatement = connection.createStatement()) {
        int majorVersion = getDBVersion(issues);
        // If version is 12+, then the check for table presence must be done in an alternate container!
        if (majorVersion == -1) {
            return issues;
        }
        if (majorVersion >= 12) {
            if (!StringUtils.isEmpty(container)) {
                String switchToPdb = "ALTER SESSION SET CONTAINER = " + configBean.pdb;
                try {
                    reusedStatement.execute(switchToPdb);
                } catch (SQLException ex) {
                    LOG.error("Error while switching to container: " + container, ex);
                    issues.add(getContext().createConfigIssue(Groups.CREDENTIALS.name(), USERNAME, JDBC_40,
                            container));
                    return issues;
                }
                containerized = true;
            }
        }

        schemasAndTables = new ArrayList<>();
        for (SchemaTableConfigBean tables : configBean.baseConfigBean.schemaTableConfigs) {

            tables.schema = configBean.baseConfigBean.caseSensitive ? tables.schema
                    : tables.schema.toUpperCase();
            tables.table = configBean.baseConfigBean.caseSensitive ? tables.table : tables.table.toUpperCase();
            if (tables.excludePattern != null) {
                tables.excludePattern = configBean.baseConfigBean.caseSensitive ? tables.excludePattern
                        : tables.excludePattern.toUpperCase();
            }
            Pattern p = StringUtils.isEmpty(tables.excludePattern) ? null
                    : Pattern.compile(tables.excludePattern);

            try (ResultSet rs = jdbcUtil.getTableAndViewMetadata(connection, tables.schema, tables.table)) {
                while (rs.next()) {
                    String schemaName = rs.getString(TABLE_METADATA_TABLE_SCHEMA_CONSTANT);
                    String tableName = rs.getString(TABLE_METADATA_TABLE_NAME_CONSTANT);
                    if (p == null || !p.matcher(tableName).matches()) {
                        schemaName = schemaName.trim();
                        tableName = tableName.trim();
                        schemasAndTables.add(new SchemaAndTable(schemaName, tableName));
                    }
                }
            }
        }

        validateTablePresence(reusedStatement, schemasAndTables, issues);
        if (!issues.isEmpty()) {
            return issues;
        }
        for (SchemaAndTable schemaAndTable : schemasAndTables) {
            try {
                tableSchemas.put(schemaAndTable, getTableSchema(schemaAndTable));
                if (scn != null) {
                    tableSchemaLastUpdate.put(schemaAndTable, scn);
                }
            } catch (SQLException ex) {
                LOG.error("Error while switching to container: " + container, ex);
                issues.add(getContext().createConfigIssue(Groups.CREDENTIALS.name(), USERNAME, JDBC_50));
            }
        }
        container = CDB_ROOT;
        if (majorVersion >= 12) {
            try {
                switchContainer.execute();
                LOG.info("Switched to CDB$ROOT to start LogMiner.");
            } catch (SQLException ex) {
                // Fatal only if we switched to a PDB earlier
                if (containerized) {
                    LOG.error("Error while switching to container: " + container, ex);
                    issues.add(getContext().createConfigIssue(Groups.CREDENTIALS.name(), USERNAME, JDBC_40,
                            container));
                    return issues;
                }
                // Log it anyway
                LOG.info("Switching containers failed, ignoring since there was no PDB switch", ex);
            }
        }
        commitScnField = majorVersion >= 11 ? "COMMIT_SCN" : "CSCN";
    } catch (SQLException ex) {
        LOG.error("Error while creating statement", ex);
        issues.add(getContext().createConfigIssue(Groups.JDBC.name(), CONNECTION_STR, JDBC_00,
                hikariConfigBean.getConnectionString()));
        return issues;
    }

    final String ddlTracking = shouldTrackDDL ? " + DBMS_LOGMNR.DDL_DICT_TRACKING" : "";

    final String readCommitted = useLocalBuffering ? "" : "+ DBMS_LOGMNR.COMMITTED_DATA_ONLY";

    this.logMinerProcedure = "BEGIN" + " DBMS_LOGMNR.START_LOGMNR(" + " {}," + " {},"
            + " OPTIONS => DBMS_LOGMNR." + configBean.dictionary.name()
            + "          + DBMS_LOGMNR.CONTINUOUS_MINE" + readCommitted
            + "          + DBMS_LOGMNR.NO_SQL_DELIMITER" + ddlTracking + ");" + " END;";

    final String base = "SELECT SCN, USERNAME, OPERATION_CODE, TIMESTAMP, SQL_REDO, TABLE_NAME, "
            + commitScnField
            + ", SEQUENCE#, CSF, XIDUSN, XIDSLT, XIDSQN, RS_ID, SSN, SEG_OWNER, ROLLBACK, ROW_ID "
            + " FROM V$LOGMNR_CONTENTS" + " WHERE ";

    final String tableCondition = getListOfSchemasAndTables(schemasAndTables);

    final String commitRollbackCondition = Utils.format("OPERATION_CODE = {} OR OPERATION_CODE = {}",
            COMMIT_CODE, ROLLBACK_CODE);

    final String operationsCondition = "OPERATION_CODE IN (" + getSupportedOperations() + ")";

    final String restartNonBufferCondition = Utils.format("((" + commitScnField + " = ? AND SEQUENCE# > ?) OR "
            + commitScnField + "  > ?)" + (shouldTrackDDL ? " OR (OPERATION_CODE = {} AND SCN > ?)" : ""),
            DDL_CODE);

    if (useLocalBuffering) {
        selectString = String.format("%s ((%s AND (%s)) OR (%s))", base, tableCondition, operationsCondition,
                commitRollbackCondition);
    } else {
        selectString = base + " (" + tableCondition + " AND (" + operationsCondition + "))" + "AND ("
                + restartNonBufferCondition + ")";
    }

    try {
        initializeLogMnrStatements();
    } catch (SQLException ex) {
        LOG.error("Error while creating statement", ex);
        issues.add(getContext().createConfigIssue(Groups.JDBC.name(), CONNECTION_STR, JDBC_00,
                hikariConfigBean.getConnectionString()));
    }

    if (configBean.dictionary == DictionaryValues.DICT_FROM_REDO_LOGS) {
        try {
            startLogMnrForRedoDict();
        } catch (Exception ex) {
            LOG.warn("Error while attempting to start LogMiner to load dictionary", ex);
            issues.add(getContext().createConfigIssue(Groups.CDC.name(), "oracleCDCConfigBean.dictionary",
                    JDBC_44, ex));
        }
    }

    if (useLocalBuffering && configBean.bufferLocation == BufferingValues.ON_DISK) {
        File tmpDir = new File(System.getProperty("java.io.tmpdir"));
        String relativePath = getContext().getSdcId() + "/" + getContext().getPipelineId() + "/"
                + getContext().getStageInfo().getInstanceName();
        this.txnBufferLocation = new File(tmpDir, relativePath);

        try {
            if (txnBufferLocation.exists()) {
                FileUtils.deleteDirectory(txnBufferLocation);
                LOG.info("Deleted " + txnBufferLocation.toString());
            }
            Files.createDirectories(txnBufferLocation.toPath());
            LOG.info("Created " + txnBufferLocation.toString());
        } catch (IOException ex) {
            Throwables.propagate(ex);
        }
    }

    if (configBean.bufferLocally) {
        if (configBean.parseQuery) {
            parsingExecutor = Executors.newFixedThreadPool(configBean.parseThreadPoolSize,
                    new ThreadFactoryBuilder().setNameFormat("Oracle CDC Origin Parse Thread - %d").build());
        } else {
            parsingExecutor = Executors.newSingleThreadExecutor(
                    new ThreadFactoryBuilder().setNameFormat("Oracle CDC Origin Parse Thread - %d").build());
        }
    }

    if (configBean.txnWindow >= configBean.logminerWindow) {
        issues.add(getContext().createConfigIssue(Groups.CDC.name(), "oracleCDCConfigBean.logminerWindow",
                JDBC_81));
    }
    version = useLocalBuffering ? VERSION_UNCOMMITTED : VERSION_STR;
    delay = getContext().createGauge("Read Lag (seconds)");
    return issues;
}