use of java.time.Period in project knime-core by knime.
the class PeriodLongValueRenderer method setValue.
@Override
protected void setValue(final Object value) {
if (value instanceof PeriodValue) {
Period period = ((PeriodValue) value).getPeriod();
super.setValue(DurationPeriodFormatUtils.formatPeriodLong(period));
} else {
super.setValue(value);
}
}
use of java.time.Period in project knime-core by knime.
the class DateTimeBasedRowFilterNodeDialog method checkGranularity.
/**
* Checks if granularity can be applied on column
*/
private void checkGranularity() {
String warning = "";
final TemporalAmount periodOrDuration = Granularity.fromString(((SettingsModelString) m_dialogCompNumericalGranularity.getModel()).getStringValue()).getPeriodOrDuration(1);
if (periodOrDuration instanceof Period && m_dialogCompColSelection.getSelectedAsSpec().getType().isCompatible(LocalTimeValue.class)) {
warning = ((SettingsModelString) m_dialogCompNumericalGranularity.getModel()).getStringValue() + " cannot be applied on a time!";
}
if (periodOrDuration instanceof Duration && m_dialogCompColSelection.getSelectedAsSpec().getType().isCompatible(LocalDateValue.class)) {
warning = ((SettingsModelString) m_dialogCompNumericalGranularity.getModel()).getStringValue() + " cannot be applied on a date!";
}
if (!warning.equals("")) {
((JComponent) m_dialogCompNumericalGranularity.getComponentPanel().getComponent(1)).setBorder(BorderFactory.createLineBorder(Color.RED));
m_typeWarningLabel.setText(warning);
} else {
((JComponent) m_dialogCompNumericalGranularity.getComponentPanel().getComponent(1)).setBorder(null);
}
}
use of java.time.Period in project knime-core by knime.
the class LoopStartWindowNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
LoopStartWindowConfiguration config = new LoopStartWindowConfiguration();
config.setEventWindowSize((Integer) m_windowSizeSpinner.getValue());
config.setEventStepSize((Integer) m_stepSizeSpinner.getValue());
config.setLimitWindow(m_limitWindowCheckBox.isSelected());
if (m_forwardRButton.isSelected()) {
config.setWindowDefinition(WindowDefinition.FORWARD);
} else if (m_backwardRButton.isSelected()) {
config.setWindowDefinition(WindowDefinition.BACKWARD);
} else {
config.setWindowDefinition(WindowDefinition.CENTRAL);
}
if (m_rowTrigRButton.isSelected()) {
config.setTrigger(Trigger.ROW);
} else {
config.setTrigger(Trigger.TIME);
if (m_columnSelector == null || m_columnSelector.getSelectedAsSpec() == null) {
throw new InvalidSettingsException("No valid time column has been chosen");
}
/* Check if step size is smaller than 0. */
try {
if (m_stepSizeTime.getText() != null && Double.parseDouble(m_stepSizeTime.getText()) < 0) {
throw new InvalidSettingsException("Step size '" + m_stepSizeTime.getText() + "' invalid. Step size must be greater than 0.");
}
} catch (NumberFormatException e) {
}
try {
if (m_windowSizeTime.getText() != null && Double.parseDouble(m_windowSizeTime.getText()) < 0) {
throw new InvalidSettingsException("Window size '" + m_windowSizeTime.getText() + "' invalid. Window size must be greater than 0.");
}
} catch (NumberFormatException e) {
}
/* Check that either no unit is selected or that the given input does not contain any letters. */
if (m_startTimeUnit.getSelectedItem() != Unit.NO_UNIT && !m_stepSizeTime.getText().matches("^[0-9]+$")) {
throw new InvalidSettingsException("Step size: input '" + m_stepSizeTime.getText() + "' invalid. Only integers are allowed when unit '" + m_startTimeUnit.getSelectedItem() + "' is chosen");
}
if (m_timeWindowUnit.getSelectedItem() != Unit.NO_UNIT && !m_windowSizeTime.getText().matches("^[0-9]+$")) {
throw new InvalidSettingsException("Window size: input '" + m_windowSizeTime.getText() + "' invalid. Only integers are allowed when unit '" + m_timeWindowUnit.getSelectedItem() + "' is chosen");
}
try {
Duration startDur = null;
/* If unit is milliseconds we have it to change to seconds for parsing. */
if (((Unit) m_startTimeUnit.getSelectedItem()) == Unit.MILLISECONDS) {
double tempStart = Double.parseDouble(m_stepSizeTime.getText());
tempStart /= 1000;
startDur = DurationPeriodFormatUtils.parseDuration(tempStart + Unit.SECONDS.getUnitLetter());
} else {
startDur = DurationPeriodFormatUtils.parseDuration(m_stepSizeTime.getText() + ((Unit) m_startTimeUnit.getSelectedItem()).getUnitLetter());
}
/* Limit step size to 24h */
if (m_columnSelector.getSelectedAsSpec().getType().equals(DataType.getType(LocalTimeCell.class))) {
Duration temp = Duration.ofHours(24);
if (startDur.compareTo(temp) > 0) {
throw new InvalidSettingsException("Step size must not be greater than 24h when LocalTime is selected");
} else if (startDur.compareTo(Duration.ZERO) == 0 || startDur.isNegative()) {
throw new InvalidSettingsException("Step size '" + m_stepSizeTime.getText() + ((Unit) m_startTimeUnit.getSelectedItem()).getUnitLetter() + "' invalid. Step size must be greater than 0.");
}
}
if (m_columnSelector.getSelectedAsSpec().getType().equals(DataType.getType(LocalDateCell.class))) {
throw new InvalidSettingsException("Step size: Duration based step size '" + m_stepSizeTime.getText() + "' is not allowed for type LocalDate. Note that 'm' is reserved for minutes, use 'M' for months.");
}
config.setTimeStepSize(m_stepSizeTime.getText());
} catch (DateTimeParseException e) {
try {
Period startPer = DurationPeriodFormatUtils.parsePeriod(m_stepSizeTime.getText() + ((Unit) m_startTimeUnit.getSelectedItem()).getUnitLetter());
/* Period is not allowed. */
if (m_columnSelector.getSelectedAsSpec().getType().equals(DataType.getType(LocalTimeCell.class))) {
throw new InvalidSettingsException("Step size: Date based step size '" + m_stepSizeTime.getText() + "' is not allowed for type LocalTime. Note that 'M' is reserved for months, use 'm' for minutes.");
} else if (m_centralRButton.isSelected()) {
throw new InvalidSettingsException("Step size: Date based step size '" + m_stepSizeTime.getText() + "' is not allowed for central windowing. Note that 'M' is reserved for months, use 'm' for minutes.");
}
if (startPer.isZero() || startPer.isNegative()) {
throw new InvalidSettingsException("Step size '" + m_stepSizeTime.getText() + ((Unit) m_startTimeUnit.getSelectedItem()).getUnitLetter() + "' invalid. Step Size must be greater than 0");
}
config.setTimeStepSize(m_stepSizeTime.getText());
} catch (DateTimeParseException e2) {
throw new InvalidSettingsException("Step size: '" + m_stepSizeTime.getText() + "' is not a valid duration. Note that 'M' is reserved for months, use 'm' for minutes.");
}
}
try {
Duration windowDur = null;
/* If unit is milliseconds we have it to change to seconds for parsing. */
if (((Unit) m_timeWindowUnit.getSelectedItem()) == Unit.MILLISECONDS) {
double tempWindow = Double.parseDouble(m_windowSizeTime.getText());
tempWindow /= 1000;
windowDur = DurationPeriodFormatUtils.parseDuration(tempWindow + Unit.SECONDS.getUnitLetter());
} else {
windowDur = DurationPeriodFormatUtils.parseDuration(m_windowSizeTime.getText() + ((Unit) m_timeWindowUnit.getSelectedItem()).getUnitLetter());
}
/* Limit window to 24h */
if (m_columnSelector.getSelectedAsSpec().getType().equals(DataType.getType(LocalTimeCell.class))) {
Duration temp = Duration.ofHours(24);
if (windowDur.compareTo(temp) > 0) {
throw new InvalidSettingsException("Window size must not be greater than 24h when LocalTime is selected");
} else if (windowDur.isZero() || windowDur.isNegative()) {
throw new InvalidSettingsException("Window size '" + m_windowSizeTime.getText() + ((Unit) m_timeWindowUnit.getSelectedItem()).getUnitLetter() + "' invalid. Window size must be greater than 0");
}
}
if (m_columnSelector.getSelectedAsSpec().getType().equals(DataType.getType(LocalDateCell.class))) {
throw new InvalidSettingsException("Window size: Time based window size '" + m_windowSizeTime.getText() + "' is not allowed for type LocalDate. Note that 'm' is reserved for minutes, use 'M' for months.");
}
config.setTimeWindowSize(m_windowSizeTime.getText());
} catch (DateTimeParseException e) {
try {
Period windowPer = DurationPeriodFormatUtils.parsePeriod(m_windowSizeTime.getText() + ((Unit) m_timeWindowUnit.getSelectedItem()).getUnitLetter());
/* Period is not allowed. */
if (m_columnSelector.getSelectedAsSpec().getType().equals(DataType.getType(LocalTimeCell.class))) {
throw new InvalidSettingsException("Window size: Date based window size '" + m_windowSizeTime.getText() + "' is not allowed for type LocalTime. Note that 'M' is reserved for months, use 'm' for minutes.");
} else if (m_centralRButton.isSelected()) {
throw new InvalidSettingsException("Window size: Date based window size '" + m_windowSizeTime.getText() + "' is not allowed for central windowing. Note that 'M' is reserved for months, use 'm' for minutes.");
}
if (windowPer.isZero() || windowPer.isNegative()) {
throw new InvalidSettingsException("Window size '" + m_windowSizeTime.getText() + ((Unit) m_timeWindowUnit.getSelectedItem()).getUnitLetter() + "' invalid. Window size must be greater than 0");
}
config.setTimeWindowSize(m_windowSizeTime.getText());
} catch (DateTimeParseException e2) {
throw new InvalidSettingsException("Window size: '" + m_windowSizeTime.getText() + "' is not a valid duration. Note that 'M' is reserved for months, use 'm' for minutes.");
}
}
config.setTimeWindowUnit((Unit) m_timeWindowUnit.getSelectedItem());
config.setTimeStepUnit((Unit) m_startTimeUnit.getSelectedItem());
}
config.setUseSpecifiedStartTime(m_useSpecifiedStartTimeCheckBox.isSelected());
config.saveSettingsTo(settings);
m_specifiedStartTime.saveSettingsTo(settings);
m_columnSelector.saveSettingsTo(settings);
}
use of java.time.Period in project knime-core by knime.
the class LoopStartWindowNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (m_windowConfig == null) {
m_windowConfig = new LoopStartWindowConfiguration();
setWarningMessage("Using default: " + m_windowConfig);
}
DataTableSpec tableSpec = inSpecs[0];
if (m_windowConfig.getTrigger() == Trigger.TIME) {
if (!tableSpec.containsName(m_timeColumnName)) {
throw new InvalidSettingsException("Selected time column '" + m_timeColumnName + "' does not exist in input table.");
}
DataColumnSpec columnSpec = tableSpec.getColumnSpec(m_timeColumnName);
/* Check if the cells have the same type as the specified start time. */
if (m_windowConfig.useSpecifiedStartTime()) {
Temporal specifiedStartTime = m_timeConfig.getSelectedDateTime();
if (specifiedStartTime == null) {
throw new InvalidSettingsException("Specified start time is not compatible with selected time column '" + m_timeColumnName + "'");
}
}
/* Check if period is set for LocalTime */
TemporalAmount start = getTemporalAmount(m_windowConfig.getTimeStepSize() + m_windowConfig.getTimeStepUnit().getUnitLetter());
if (m_windowConfig.getTimeStepSize() == null) {
throw new InvalidSettingsException("No temporal step size set.");
}
if (start == null) {
throw new InvalidSettingsException("Given step size couldn't be matched to type Duration or Period.");
} else if (start instanceof Period && columnSpec.getType().equals(DataType.getType(LocalTimeCell.class))) {
throw new InvalidSettingsException("Step size: Period type not allowed for LocalTime");
}
TemporalAmount window = getTemporalAmount(m_windowConfig.getTimeWindowSize() + m_windowConfig.getTimeWindowUnit().getUnitLetter());
if (m_windowConfig.getTimeWindowSize() == null) {
throw new InvalidSettingsException("No window size set.");
}
if (window == null) {
throw new InvalidSettingsException("Given window size couldn't be machted to type Duration or Period.");
} else if (start instanceof Period && columnSpec.getType().equals(DataType.getType(LocalTimeCell.class))) {
throw new InvalidSettingsException("Window size: Period type not allowed for LocalTime");
}
}
return inSpecs;
}
use of java.time.Period in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilySnapshotsManagerImpl method deleteSnapshotByFamily.
@Override
public void deleteSnapshotByFamily(Long familyId) {
checkArgument(familyId > 0, i18n.translate("argument.nonNegative", familyId));
Optional.ofNullable(familyRepository.findOne(familyId)).ifPresent(family -> {
Optional.ofNullable(economicRepository.findTopByFamilyFamilyIdOrderByIdDesc(familyId)).ifPresent(snapshotEconomicEntity -> {
LocalDateTime now = LocalDateTime.now();
LocalDateTime dateOfSnapshot = snapshotEconomicEntity.getCreatedAt();
Period intervalPeriod = Period.between(dateOfSnapshot.toLocalDate(), now.toLocalDate());
if (intervalPeriod.getDays() < MAX_DAYS_DELETE_SNAPSHOT) {
SnapshotEconomicEntity snapshotEconomicEntityAux = snapshotEconomicEntity;
snapshotIndicatorPriorityRepository.delete(snapshotIndicatorPriorityRepository.findBySnapshotIndicatorId(snapshotEconomicEntity.getSnapshotIndicator().getId()));
economicRepository.delete(snapshotEconomicEntity);
snapshotIndicatorRepository.delete(snapshotEconomicEntityAux.getSnapshotIndicator());
}
});
family.setActive(false);
familyRepository.save(family);
});
}
Aggregations