List of usage examples for java.time LocalDateTime compareTo
@Override public int compareTo(ChronoLocalDateTime<?> other)
From source file:Main.java
public static void main(String[] args) { LocalDateTime a = LocalDateTime.of(2012, 6, 30, 12, 00); LocalDateTime b = LocalDateTime.of(2012, 7, 1, 12, 00); System.out.println(a.compareTo(b)); System.out.println(a.compareTo(a)); }
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);// w ww .java 2s .c om 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)); } }
From source file:org.talend.dataprep.api.filter.SimpleFilterService.java
/** * Create a predicate that checks if the date value is within a range [min, max[ * * @param columnId The column id/*from w ww . j av a 2s .co m*/ * @param start The start value * @param end The end value * @return The date range predicate */ private Predicate<DataSetRow> createDateRangePredicate(final String columnId, final String start, final String end, final RowMetadata rowMetadata) { try { final long minTimestamp = Long.parseLong(start); final long maxTimestamp = Long.parseLong(end); final LocalDateTime minDate = dateManipulator.fromEpochMillisecondsWithSystemOffset(minTimestamp); final LocalDateTime maxDate = dateManipulator.fromEpochMillisecondsWithSystemOffset(maxTimestamp); return safeDate(r -> { final ColumnMetadata columnMetadata = rowMetadata.getById(columnId); final LocalDateTime columnValue = getDateParser().parse(r.get(columnId), columnMetadata); return minDate.compareTo(columnValue) == 0 || (minDate.isBefore(columnValue) && maxDate.isAfter(columnValue)); }); } catch (Exception e) { LOGGER.debug("Unable to create date range predicate.", e); throw new IllegalArgumentException( "Unsupported query, malformed date 'range' (expected timestamps in min and max properties)."); } }
From source file:org.talend.dataprep.transformation.actions.date.CompareDates.java
@Override protected int doCompare(ComparisonRequest comparisonRequest) { if (StringUtils.isEmpty(comparisonRequest.value1) // || StringUtils.isEmpty(comparisonRequest.value2)) { return ERROR_COMPARE_RESULT; }/*from w w w .j av a 2s .c o m*/ try { final DateParser dateParser = Providers.get(DateParser.class); final LocalDateTime temporalAccessor1 = dateParser.parse(comparisonRequest.value1, comparisonRequest.colMetadata1); // we compare with the format of the first column when the comparison is with a CONSTANT final LocalDateTime temporalAccessor2 = dateParser.parse(comparisonRequest.value2, comparisonRequest.mode.equals(CONSTANT_MODE) ? // comparisonRequest.colMetadata2 : comparisonRequest.colMetadata1); return temporalAccessor1.compareTo(temporalAccessor2); } catch (Exception e) { return ERROR_COMPARE_RESULT; } }