Example usage for java.time ZoneId systemDefault

List of usage examples for java.time ZoneId systemDefault

Introduction

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

Prototype

public static ZoneId systemDefault() 

Source Link

Document

Gets the system default time-zone.

Usage

From source file:com.buffalokiwi.aerodrome.Aerodrome.java

private static void shipOrders(final JetAPIOrder orderApi) throws APIException, JetException {
    for (final String jetOrderId : orderApi.getOrderStatusTokens(OrderStatus.ACK, false)) {
        //..Get the order detail 
        final OrderRec order = orderApi.getOrderDetail(jetOrderId);

        //..A list of shipments 
        //..You can split the order up into however many shipments you want.
        final List<ShipmentRec> shipments = new ArrayList<>();

        //..a list of items in a shipment 
        final List<ShipmentItemRec> shipmentItems = new ArrayList<>();

        //..Create a return address object 
        final AddressRec returnAddress = new AddressRec("123 Sesame Street", "Suite 100", "Sesame", "AK",
                "38473");

        //..Create an rma number (can be custom for each item if you want)
        final String rmaNumber = "1234RMA";

        //..Turn those into ack order records
        for (final OrderItemRec item : order.getOrderItems()) {
            //..Create a builder for a new ShipmentItem by converting the retrieved
            //  order item to a Shipment Item
            final ShipmentItemRec.Builder builder = ShipmentItemRec.fromOrderItem(item);

            //..You can modify the quantity shipped or cancelled here, or just fulfill as it was ordered
            //..like this:
            //builder.setQuantity( 1 );
            //builder.setCancelQuantity( 1 );

            //...Set the return address
            builder.setReturnTo(returnAddress);

            //..Set the rma number if desired
            builder.setRmaNumber(rmaNumber);

            //..Build the item and add it to the items list 
            shipmentItems.add(builder.build());
        }//from   www . j a va2 s  .  co m

        //..Build a shipment for the items in the order
        //..You can create multiple shipments, and also mix cancellations 
        //  with shipments.
        final ShipmentRec shipment = new ShipmentRec.Builder()
                .setCarrier(order.getOrderDetail().getRequestShippingCarrier())
                .setTrackingNumber("Z123456780123456").setShipmentDate(new JetDate())
                .setExpectedDeliveryDate(new JetDate(ZonedDateTime.from(Instant.now())
                        .withZoneSameInstant(ZoneId.systemDefault()).plusDays(2)))
                .setShipFromZip("38473").setPickupDate(new JetDate()).setItems(shipmentItems).build();

        //..Add it to the list of shipments you're sending out.
        shipments.add(shipment);

        //..Create the final request object to tell jet about the shipment
        final ShipRequestRec shipmentRequest = new ShipRequestRec("", shipments);

        //..Send the shipment to jet
        orderApi.sendPutShipOrder(jetOrderId, shipmentRequest);
    }
}

From source file:com.inqool.dcap.office.indexer.indexer.SolrBulkIndexer.java

protected SolrInputDocument modelToSolrInputDoc(ZdoModel model) {
    logger.debug("Constructing new SolrInputDocument...");

    final Map<String, SolrInputField> fields = new HashMap<>();

    //Add all Dublin Core terms
    for (String property : DCTools.getDcTermList()) {
        SolrInputField field = new SolrInputField(property);
        List<String> values = model.getAll(new PropertyImpl("http://purl.org/dc/terms/" + property));
        if (values.isEmpty())
            continue;
        //Skip fields that were not ticked to be published
        String visible = model.get(new PropertyImpl("http://purl.org/dc/terms/" + property + "_visibility"));
        if ("false".equals(visible) || "0".equals(visible)) { //0 should not occur any more
            continue;
        }// ww  w  .  j av a  2  s .c o  m
        if ("isPartOf".equals(property)) { //remove ip address from isPartOf
            values.set(0, store.getOnlyIdFromUrl(values.get(0)));
        }
        if ("".equals(values.get(0))) {
            values.set(0, "unknown");
        }

        field.addValue(values, INDEX_TIME_BOOST);
        fields.put(property, field);

        //Suggester data
        if ("title".equals(property) || "creator".equals(property)) {
            SolrInputDocument suggesterDoc = new SolrInputDocument();
            String suggestVal = values.get(0).trim();
            if (!suggestVal.isEmpty() && !suggestVal.equals("unknown")) {
                suggesterDoc.addField("suggesterData", values.get(0).trim());
                dataForSuggester.add(suggesterDoc);
            }
        }
    }

    //Add system fields
    SolrInputField field = new SolrInputField("id");
    field.addValue(store.getOnlyIdFromUrl(model.getUrl()), INDEX_TIME_BOOST);
    fields.put("id", field);

    addSolrFieldFromFedoraProperty("inventoryId", ZdoTerms.inventoryId, model, fields);

    addSolrFieldFromFedoraProperty("zdoType", ZdoTerms.zdoType, model, fields);
    addSolrFieldFromFedoraProperty("zdoGroup", ZdoTerms.group, model, fields);
    addSolrFieldFromFedoraProperty("orgIdmId", ZdoTerms.organization, model, fields);
    addSolrFieldFromFedoraProperty("allowContentPublicly", ZdoTerms.allowContentPublicly, model, fields);
    addSolrFieldFromFedoraProperty("allowPdfExport", ZdoTerms.allowPdfExport, model, fields);
    addSolrFieldFromFedoraProperty("allowEpubExport", ZdoTerms.allowEpubExport, model, fields);
    addSolrFieldFromFedoraProperty("watermark", ZdoTerms.watermark, model, fields);
    addSolrFieldFromFedoraProperty("watermarkPosition", ZdoTerms.watermarkPosition, model, fields);
    addSolrFieldFromFedoraProperty("imgThumb", ZdoTerms.imgThumb, model, fields);
    addSolrFieldFromFedoraProperty("imgNormal", ZdoTerms.imgNormal, model, fields);

    String publishFromStr = model.get(ZdoTerms.publishFrom);
    if (publishFromStr != null) {
        String publishFromUtc = ZonedDateTime
                .ofInstant(Instant.ofEpochSecond(Long.valueOf(publishFromStr)), ZoneId.systemDefault())
                .withZoneSameInstant(ZoneOffset.UTC).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        addSolrField("publishFrom", publishFromUtc, fields);
    }
    String publishToStr = model.get(ZdoTerms.publishTo);
    if (publishToStr != null) {
        String publishToUtc = ZonedDateTime
                .ofInstant(Instant.ofEpochSecond(Long.valueOf(publishToStr)), ZoneId.systemDefault())
                .withZoneSameInstant(ZoneOffset.UTC).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        addSolrField("publishTo", publishToUtc, fields);
    }

    String created = model.get(DCTerms.created);
    if (created != null) {
        AtomicInteger yearStart = new AtomicInteger();
        AtomicInteger yearEnd = new AtomicInteger();
        AtomicBoolean startValid = new AtomicBoolean();
        AtomicBoolean endValid = new AtomicBoolean();
        YearNormalizer.normalizeCreatedYear(created, yearStart, startValid, yearEnd, endValid);
        if (startValid.get()) {
            addSolrField("yearStart", yearStart.get(), fields);
        } else {
            logger.warn("Year could not be normalized for input string " + created);
        }
        if (endValid.get()) {
            addSolrField("yearEnd", yearEnd.get(), fields);
        }
    }

    String orgName = orgNameMapping.get(model.get(ZdoTerms.organization));
    if (orgName == null) {
        orgName = "Neznm";
    }
    addSolrField("organization", orgName, fields);

    String documentTypeId = model.get(ZdoTerms.documentType); //type and subtype names must be found for id
    String documentSubTypeId = model.get(ZdoTerms.documentSubType);
    if (documentTypeId != null) {
        addSolrField("documentType", documentTypeAccess.getTypeNameForId(Integer.valueOf(documentTypeId)),
                fields);
    }
    if (documentSubTypeId != null) {
        addSolrField("documentSubType",
                documentTypeAccess.getSubTypeNameForId(Integer.valueOf(documentSubTypeId)), fields);
    }

    //Add customFields
    int fieldIndex = 0; //we actually start from 1
    do {
        fieldIndex++;
        String fieldName = model
                .get(new PropertyImpl("http://inqool.cz/zdo/1.0/customField_" + fieldIndex + "_name"));
        if (fieldName == null)
            break;
        fieldName = "customField_" + fieldName;
        String visible = model
                .get(new PropertyImpl("http://inqool.cz/zdo/1.0/customField_" + fieldIndex + "_visibility"));
        if ("false".equals(visible) || "0".equals(visible))
            continue;
        List<String> fieldValues = model
                .getAll(new PropertyImpl("http://inqool.cz/zdo/1.0/customField_" + fieldIndex));
        if ("".equals(fieldValues.get(0))) {
            fieldValues.set(0, "unknown");
        }
        SolrInputField customField = new SolrInputField(fieldName);
        customField.addValue(fieldValues, INDEX_TIME_BOOST);
        fields.put(fieldName, customField);
    } while (true);

    SolrInputDocument solrInputDocument = new SolrInputDocument(fields);
    return solrInputDocument;
}

From source file:ru.anr.base.BaseParent.java

/**
 * @param date//from   w ww .  j a va 2 s  .c o  m
 *            Date
 * @param locale
 *            Locale
 * @return formatted date
 */
public static String formatDate(long date, String locale) {

    return DateTimeFormatter
            .ofPattern("ru_RU".equals(locale) ? "dd.MM.yyyy HH:mm:ss z" : "dd/MM/yyyy HH:mm:ss z")
            .withZone(ZoneOffset.systemDefault())
            .format(LocalDateTime.ofInstant(Instant.ofEpochMilli(date), ZoneId.systemDefault()));
}

From source file:ru.anr.base.BaseParent.java

/**
 * @param pattern//from w  ww .  jav a  2s  .c o m
 *            patter
 * @param date
 *            date
 * @return formatted date
 */
public static String formatDate(String pattern, Calendar date) {

    return DateTimeFormatter.ofPattern(pattern).format(
            LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTimeInMillis()), ZoneId.systemDefault()));
}

From source file:net.ceos.project.poi.annotated.core.CsvHandler.java

/**
 * Apply a date time value at the field.
 * //from  w ww  . j  a va2 s .c om
 * @param value
 *            the value
 * @param formatMask
 *            the decorator mask
 * @param transformMask
 *            the transformation mask
 * @return false if problem otherwise true
 * @throws ConverterException
 *             the conversion exception type
 */
protected static String toLocalDate(final LocalDate value, final String formatMask, final String transformMask)
        throws ConverterException {
    String dateMasked = StringUtils.EMPTY;
    if (value != null) {
        try {
            if (StringUtils.isNotBlank(transformMask)) {
                // apply transformation mask
                dateMasked = applyMaskToDate(Date.from(value.atStartOfDay(ZoneId.systemDefault()).toInstant()),
                        transformMask);

            } else if (StringUtils.isNotBlank(formatMask)) {
                // apply format mask
                dateMasked = applyMaskToDate(Date.from(value.atStartOfDay(ZoneId.systemDefault()).toInstant()),
                        formatMask);

            } else {
                // default mask
                dateMasked = applyMaskToDate(Date.from(value.atStartOfDay(ZoneId.systemDefault()).toInstant()),
                        Constants.DD_MMM_YYYY_HH_MM_SS);
            }
        } catch (Exception e) {
            throw new ConverterException(ExceptionMessage.CONVERTER_LOCALDATE.getMessage(), e);
        }
    }
    return dateMasked;
}

From source file:org.openhab.binding.darksky.internal.handler.DarkSkyWeatherAndForecastHandler.java

private State getDateTimeTypeState(int value) {
    return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(value), ZoneId.systemDefault()));
}

From source file:eu.clarin.cmdi.vlo.importer.MetadataImporter.java

/**
 * Update "days since last import" field for all Solr records of dataRoot.
 * Notice that it will not touch records that have a "last seen" value newer
 * than today. Therefore this should be called <em>after</em> normal 
 * processing of data root!//from   w w w.  ja  v  a 2 s  . c om
 *
 * @param dataRoot
 * @throws SolrServerException
 * @throws IOException
 */
private void updateDaysSinceLastImport(DataRoot dataRoot) throws SolrServerException, IOException {
    LOG.info("Updating \"days since last import\" in Solr for: {}", dataRoot.getOriginName());

    SolrQuery query = new SolrQuery();
    query.setQuery(
            //we're going to process all records in the current data root...
            FacetConstants.FIELD_DATA_PROVIDER + ":" + ClientUtils.escapeQueryChars(dataRoot.getOriginName())
                    + " AND "
                    // ...that have a "last seen" value _older_ than today (on update/initialisation all records get 0 so we can skip the rest)
                    + FacetConstants.FIELD_LAST_SEEN + ":[* TO NOW-1DAY]");
    query.setFields(FacetConstants.FIELD_ID, FacetConstants.FIELD_LAST_SEEN);
    int fetchSize = 1000;
    query.setRows(fetchSize);
    QueryResponse rsp = solrServer.query(query);

    final long totalResults = rsp.getResults().getNumFound();
    final LocalDate nowDate = LocalDate.now();

    final int docsListSize = config.getMaxDocsInList();
    List<SolrInputDocument> updateDocs = new ArrayList<>(docsListSize);

    Boolean updatedDocs = false;
    int offset = 0;

    while (offset < totalResults) {
        query.setStart(offset);
        query.setRows(fetchSize);

        for (SolrDocument doc : solrServer.query(query).getResults()) {
            updatedDocs = true;

            String recordId = (String) doc.getFieldValue(FacetConstants.FIELD_ID);
            Date lastImportDate = (Date) doc.getFieldValue(FacetConstants.FIELD_LAST_SEEN);
            LocalDate oldDate = lastImportDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            long daysSinceLastSeen = DAYS.between(oldDate, nowDate);

            SolrInputDocument updateDoc = new SolrInputDocument();
            updateDoc.setField(FacetConstants.FIELD_ID, recordId);

            Map<String, Long> partialUpdateMap = new HashMap<>();
            partialUpdateMap.put("set", daysSinceLastSeen);
            updateDoc.setField(FacetConstants.FIELD_DAYS_SINCE_LAST_SEEN, partialUpdateMap);

            updateDocs.add(updateDoc);

            if (updateDocs.size() == docsListSize) {
                solrServer.add(updateDocs);
                if (serverError != null) {
                    throw new SolrServerException(serverError);
                }
                updateDocs = new ArrayList<>(docsListSize);
            }
        }
        offset += fetchSize;
        LOG.info("Updating \"days since last import\": {} out of {} records updated", offset, totalResults);
    }

    if (!updateDocs.isEmpty()) {
        solrServer.add(updateDocs);
        if (serverError != null) {
            throw new SolrServerException(serverError);
        }
    }

    if (updatedDocs) {
        solrServer.commit();
    }

    LOG.info("Updating \"days since last import\" done.");
}

From source file:net.ceos.project.poi.annotated.core.CsvHandler.java

/**
 * Apply a date time value at the field.
 * /*from  w ww  .  ja va  2 s  .co m*/
 * @param value
 *            the value
 * @param formatMask
 *            the decorator mask
 * @param transformMask
 *            the transformation mask
 * @return false if problem otherwise true
 * @throws ConverterException
 *             the conversion exception type
 */
protected static String toLocalDateTime(final LocalDateTime value, final String formatMask,
        final String transformMask) throws ConverterException {
    String dateMasked = StringUtils.EMPTY;
    if (value != null) {
        try {
            if (StringUtils.isNotBlank(transformMask)) {
                // apply transformation mask
                dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()),
                        transformMask);

            } else if (StringUtils.isNotBlank(formatMask)) {
                // apply format mask
                dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()),
                        formatMask);

            } else {
                // default mask
                dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()),
                        Constants.DD_MMM_YYYY_HH_MM_SS);
            }
        } catch (Exception e) {
            throw new ConverterException(ExceptionMessage.CONVERTER_LOCALDATETIME.getMessage(), e);
        }
    }
    return dateMasked;
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

private void populateArtifactEditor(ArtifactCondition artifactConditionToPopulateWith) {
    cbAttributeType.setSelected(true);/*from  w  ww .jav  a 2s .  c o  m*/
    comboBoxArtifactName.setSelectedItem(artifactConditionToPopulateWith.getArtifactTypeName());
    comboBoxAttributeComparison
            .setSelectedItem(artifactConditionToPopulateWith.getRelationalOperator().getSymbol());
    comboBoxAttributeName.setSelectedItem(artifactConditionToPopulateWith.getAttributeTypeName());
    BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType = artifactConditionToPopulateWith
            .getAttributeValueType();
    comboBoxValueType.setSelectedItem(valueType.getLabel());
    comboBoxValueType
            .setEnabled(null == attributeTypeMap.get(artifactConditionToPopulateWith.getAttributeTypeName()));
    if (valueType == BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME) {
        Instant instant = Instant
                .ofEpochMilli(artifactConditionToPopulateWith.getDateTimeValue().toDate().getTime());
        dateTimePicker.setDateTime(LocalDateTime.ofInstant(instant, ZoneId.systemDefault()));
    } else {
        tbAttributeValue.setText(artifactConditionToPopulateWith.getStringRepresentationOfValue());
    }
}

From source file:io.stallion.dataAccess.db.DB.java

/**
 * Trys to convert java type into what is needed by JDBC to store to the database.
 *
 * @param o//from w w  w.  jav  a 2  s  . c o  m
 * @param col
 * @param arg
 * @return
 */
public Object convertColumnArg(Model o, Col col, Object arg) {

    if (arg == null && col.getDefaultValue() != null) {
        arg = col.getDefaultValue();
    }
    if (col.getAttributeConverter() != null) {
        arg = col.getAttributeConverter().convertToDatabaseColumn(arg);
    } else if (arg != null && !StringUtils.isBlank(col.getConverterClassName())) {
        AttributeConverter converter = this.getConverter(col.getConverterClassName());
        arg = converter.convertToDatabaseColumn(arg);
    } else if (arg instanceof LocalDateTime) {
        arg = new Timestamp(((LocalDateTime) arg).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
    } else if (arg instanceof ZonedDateTime) {
        arg = new Timestamp(((ZonedDateTime) arg).toInstant().toEpochMilli());
    } else if (arg instanceof Enum) {
        return arg.toString();
    }
    return arg;
}