Example usage for java.time LocalDateTime ofInstant

List of usage examples for java.time LocalDateTime ofInstant

Introduction

In this page you can find the example usage for java.time LocalDateTime ofInstant.

Prototype

public static LocalDateTime ofInstant(Instant instant, ZoneId zone) 

Source Link

Document

Obtains an instance of LocalDateTime from an Instant and zone ID.

Usage

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

private void populateArtifactEditor(ArtifactCondition artifactConditionToPopulateWith) {
    cbAttributeType.setSelected(true);//from w w  w  . java2s .  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:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepository.java

List<Date> getUserAssignmentPartitions(Date fromTime, Date toTime) {
    final LocalDateTime startTime = LocalDateTime.ofInstant(fromTime.toInstant(), ZoneId.systemDefault())
            .withMinute(0).withSecond(0).withNano(0);
    final LocalDateTime endTime = LocalDateTime.ofInstant(toTime.toInstant(), ZoneId.systemDefault())
            .withMinute(0).withSecond(0).withNano(0);
    final long hours = Duration.between(startTime, endTime).toHours();
    return LongStream.rangeClosed(0, hours).mapToObj(startTime::plusHours)
            .map(t -> Date.from(t.atZone(ZoneId.systemDefault()).toInstant())).collect(Collectors.toList());
}

From source file:net.di2e.ecdr.describe.generator.DescribeGeneratorImpl.java

protected void setRecordRate(MetricsType metrics, Map<String, TemporalCoverageHolder> timeMap) {
    TemporalCoverageHolder tc = timeMap.containsKey("modified")
            ? (TemporalCoverageHolder) timeMap.get("modified")
            : (timeMap.containsKey("effective") ? (TemporalCoverageHolder) timeMap.get("effective")
                    : (TemporalCoverageHolder) timeMap.get("created"));
    try {/* w ww . j a v a2  s .  co m*/
        if (tc != null) {
            Date startDate = tc.getStartDate();
            if (startDate != null) {
                long totalHits = metrics.getCount();
                LocalDateTime start = LocalDateTime.ofInstant(startDate.toInstant(), ZoneId.systemDefault());
                Duration duration = Duration.between(start, LocalDateTime.now());
                RecordRateType rate = new RecordRateType();
                metrics.setRecordRate(rate);
                long dur = totalHits / duration.toHours();
                if (dur < 15L) {
                    dur = totalHits / duration.toDays();
                    if (dur < 4L) {
                        dur = totalHits * 30L / duration.toDays();
                        if (dur < 10L) {
                            dur = totalHits * 365L / duration.toDays();
                            rate.setFrequency("Yearly");
                        } else {
                            rate.setFrequency("Monthly");
                        }
                    } else {
                        rate.setFrequency("Daily");
                    }
                } else if (totalHits > 1000L) {
                    dur = duration.toMinutes();
                    if (totalHits > 1000L) {
                        dur = duration.toMillis() / 1000L;
                        rate.setFrequency("Second");
                    } else {
                        rate.setFrequency("Minute");
                    }
                } else {
                    rate.setFrequency("Hourly");
                }

                rate.setValue((int) dur);
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Could not set record rate: {}", e.getMessage(), e);
    }
}

From source file:net.tourbook.photo.Photo.java

private void setupPhoto(final File photoImageFile, final IPath photoImagePath) {

    final String photoImageFilePathName = photoImageFile.getAbsolutePath();
    final long lastModified = photoImageFile.lastModified();

    imageFile = photoImageFile;/*from  w  w  w .  j av a2s  .  co  m*/

    imageFileName = photoImageFile.getName();
    imageFilePathName = photoImageFilePathName;

    imagePathName = photoImagePath.removeLastSegments(1).toOSString();
    imageFileExt = photoImagePath.getFileExtension();

    imageFileSize = photoImageFile.length();
    _imageFileLastModified = LocalDateTime.ofInstant(//
            Instant.ofEpochMilli(lastModified),
            //            ZoneOffset.UTC
            ZoneId.systemDefault()
    //
    );

    // initially sort by file date until exif data are loaded
    imageExifTime = lastModified;

    _uniqueId = photoImageFilePathName;

    /*
     * initialize image keys and loading states
     */
    _imageKeyThumb = getImageKeyThumb(photoImageFilePathName);
    _imageKeyHQ = getImageKeyHQ(photoImageFilePathName);
    _imageKeyOriginal = Util.computeMD5(photoImageFilePathName + "_Original");//$NON-NLS-1$

    _isImageFileAvailable = photoImageFile.exists();

    if (_isImageFileAvailable) {

        _photoLoadingStateThumb = PhotoLoadingState.UNDEFINED;
        _photoLoadingStateHQ = PhotoLoadingState.UNDEFINED;
        _photoLoadingStateOriginal = PhotoLoadingState.UNDEFINED;

        _isLoadingError = false;

    } else {

        _photoLoadingStateThumb = PhotoLoadingState.IMAGE_IS_INVALID;
        _photoLoadingStateHQ = PhotoLoadingState.IMAGE_IS_INVALID;
        _photoLoadingStateOriginal = PhotoLoadingState.IMAGE_IS_INVALID;

        _isLoadingError = true;
    }
}

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:edu.usu.sdl.openstorefront.service.ComponentServiceImpl.java

@Override
public void processComponentIntegration(String componentId, String integrationConfigId) {
    ComponentIntegration integrationExample = new ComponentIntegration();
    integrationExample.setActiveStatus(ComponentIntegration.ACTIVE_STATUS);
    integrationExample.setComponentId(componentId);
    ComponentIntegration integration = persistenceService.queryOneByExample(ComponentIntegration.class,
            integrationExample);/*from ww w  .  j a  v a 2 s .  co  m*/
    if (integration != null) {

        boolean run = true;
        if (RunStatus.WORKING.equals(integration.getStatus())) {
            //check for override
            String overrideTime = PropertiesManager.getValue(PropertiesManager.KEY_JOB_WORKING_STATE_OVERRIDE,
                    "30");
            if (integration.getLastStartTime() != null) {
                LocalDateTime maxLocalDateTime = LocalDateTime
                        .ofInstant(integration.getLastStartTime().toInstant(), ZoneId.systemDefault());
                maxLocalDateTime.plusMinutes(Convert.toLong(overrideTime));
                if (maxLocalDateTime.compareTo(LocalDateTime.now()) <= 0) {
                    log.log(Level.FINE, "Overriding the working state...assume it was stuck.");
                    run = true;
                } else {
                    run = false;
                }
            } else {
                throw new OpenStorefrontRuntimeException("Missing Last Start time.  Data is corrupt.",
                        "Delete the job (Integration) and recreate it.", ErrorTypeCode.INTEGRATION);
            }
        }

        if (run) {
            Component component = persistenceService.findById(Component.class, integration.getComponentId());
            ComponentIntegration liveIntegration = persistenceService.findById(ComponentIntegration.class,
                    integration.getComponentId());

            log.log(Level.FINE, MessageFormat.format("Processing Integration for: {0}", component.getName()));

            liveIntegration.setStatus(RunStatus.WORKING);
            liveIntegration.setLastStartTime(TimeUtil.currentDate());
            liveIntegration.setUpdateDts(TimeUtil.currentDate());
            liveIntegration.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
            persistenceService.persist(liveIntegration);

            ComponentIntegrationConfig integrationConfigExample = new ComponentIntegrationConfig();
            integrationConfigExample.setActiveStatus(ComponentIntegrationConfig.ACTIVE_STATUS);
            integrationConfigExample.setComponentId(componentId);
            integrationConfigExample.setIntegrationConfigId(integrationConfigId);

            List<ComponentIntegrationConfig> integrationConfigs = persistenceService
                    .queryByExample(ComponentIntegrationConfig.class, integrationConfigExample);
            boolean errorConfig = false;
            if (integrationConfigs.isEmpty() == false) {
                for (ComponentIntegrationConfig integrationConfig : integrationConfigs) {
                    ComponentIntegrationConfig liveConfig = persistenceService.findById(
                            ComponentIntegrationConfig.class, integrationConfig.getIntegrationConfigId());
                    try {
                        log.log(Level.FINE,
                                MessageFormat.format("Working on {1} Configuration for Integration for: {0}",
                                        component.getName(), integrationConfig.getIntegrationType()));

                        liveConfig.setStatus(RunStatus.WORKING);
                        liveConfig.setLastStartTime(TimeUtil.currentDate());
                        liveConfig.setUpdateDts(TimeUtil.currentDate());
                        liveConfig.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
                        persistenceService.persist(liveConfig);

                        BaseIntegrationHandler baseIntegrationHandler = BaseIntegrationHandler
                                .getIntegrationHandler(integrationConfig);
                        if (baseIntegrationHandler != null) {
                            baseIntegrationHandler.processConfig();
                        } else {
                            throw new OpenStorefrontRuntimeException(
                                    "Intergration handler not supported for "
                                            + integrationConfig.getIntegrationType(),
                                    "Add handler", ErrorTypeCode.INTEGRATION);
                        }

                        liveConfig.setStatus(RunStatus.COMPLETE);
                        liveConfig.setLastEndTime(TimeUtil.currentDate());
                        liveConfig.setUpdateDts(TimeUtil.currentDate());
                        liveConfig.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
                        persistenceService.persist(liveConfig);

                        log.log(Level.FINE,
                                MessageFormat.format("Completed {1} Configuration for Integration for: {0}",
                                        component.getName(), integrationConfig.getIntegrationType()));
                    } catch (Exception e) {
                        errorConfig = true;
                        //This is a critical loop
                        ErrorInfo errorInfo = new ErrorInfo(e, null);
                        SystemErrorModel errorModel = getSystemService().generateErrorTicket(errorInfo);

                        //put in fail state
                        liveConfig.setStatus(RunStatus.ERROR);
                        liveConfig.setErrorMessage(errorModel.getMessage());
                        liveConfig.setErrorTicketNumber(errorModel.getErrorTicketNumber());
                        liveConfig.setLastEndTime(TimeUtil.currentDate());
                        liveConfig.setUpdateDts(TimeUtil.currentDate());
                        liveConfig.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
                        persistenceService.persist(liveConfig);

                        log.log(Level.FINE,
                                MessageFormat.format("Failed on {1} Configuration for Integration for: {0}",
                                        component.getName(), integrationConfig.getIntegrationType()),
                                e);
                    }
                }
            } else {
                log.log(Level.WARNING,
                        MessageFormat.format(
                                "No Active Integration configs for: {0} (Integration is doing nothing)",
                                component.getName()));
            }

            if (errorConfig) {
                liveIntegration.setStatus(RunStatus.ERROR);
            } else {
                liveIntegration.setStatus(RunStatus.COMPLETE);
            }
            liveIntegration.setLastEndTime(TimeUtil.currentDate());
            liveIntegration.setUpdateDts(TimeUtil.currentDate());
            liveIntegration.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
            persistenceService.persist(liveIntegration);

            log.log(Level.FINE, MessageFormat.format("Completed Integration for: {0}", component.getName()));
        } else {
            log.log(Level.FINE, MessageFormat.format(
                    "Not time to run integration or the system is currently working on the integration. Component Id: {0}",
                    componentId));
        }
    } else {
        log.log(Level.WARNING, MessageFormat
                .format("There is no active integration for this component. Id: {0}", componentId));
    }
}