use of org.joda.time.LocalDateTime in project qi4j-sdk by Qi4j.
the class AbstractValueCompositeSerializationTest method buildSomeValue.
/**
* @return a SomeValue ValueComposite whose state is populated with test data.
*/
private SomeValue buildSomeValue() {
ValueBuilder<SomeValue> builder = module.newValueBuilder(SomeValue.class);
SomeValue proto = builder.prototype();
proto.anotherList().get().add(module.newValue(AnotherValue.class));
ValueBuilder<SpecificCollection> specificColBuilder = module.newValueBuilder(SpecificCollection.class);
SpecificCollection specificColProto = specificColBuilder.prototype();
List<String> genericList = new ArrayList<>(2);
genericList.add("Some");
genericList.add("String");
specificColProto.genericList().set(genericList);
proto.specificCollection().set(specificColBuilder.newInstance());
/*
ValueBuilder<SpecificValue> specificValue = module.newValueBuilder(SpecificValue.class);
specificValue.prototype().item().set("Foo");
proto.specificValue().set(specificValue.newInstance());
*/
ValueBuilder<AnotherValue> valueBuilder = module.newValueBuilder(AnotherValue.class);
valueBuilder.prototype().val1().set("Foo");
valueBuilder.prototypeFor(AnotherValueInternalState.class).val2().set("Bar");
AnotherValue anotherValue = valueBuilder.newInstance();
// FIXME Some Control Chars are not supported in JSON nor in XML, what should we do about it?
// Should Qi4j Core ensure the chars used in strings are supported by the whole stack?
// proto.string().set( "Foo\"Bar\"\nTest\f\t\b" );
proto.string().set("Foo\"Bar\"\nTest\t");
proto.string2().set("/Foo/bar");
proto.number().set(42L);
proto.date().set(new Date());
proto.dateTime().set(new DateTime());
proto.localDate().set(new LocalDate());
proto.localDateTime().set(new LocalDateTime());
proto.entityReference().set(EntityReference.parseEntityReference("12345"));
proto.stringIntMap().get().put("foo", 42);
// Can't put more than one entry in Map because this test rely on the fact that the underlying implementations
// maintain a certain order but it's not the case on some JVMs. On OpenJDK 8 they are reversed for example.
// This should not be enforced tough as both the Map API and the JSON specification state that name-value pairs
// are unordered.
// As a consequence this test should be enhanced to be Map order independant.
//
// proto.stringIntMap().get().put( "bar", 67 );
proto.stringValueMap().get().put("foo", anotherValue);
proto.another().set(anotherValue);
proto.serializable().set(new SerializableObject());
proto.foo().set(module.newValue(FooValue.class));
proto.fooValue().set(module.newValue(FooValue.class));
proto.customFoo().set(module.newValue(CustomFooValue.class));
proto.customFooValue().set(module.newValue(CustomFooValue.class));
// Arrays
// TODO FIXME Disabled as ValueComposite equality fails here
//proto.primitiveByteArray().set( new byte[]
// {
// 9, -12, 42, -12, 127, 23, -128, 73
// } );
//proto.byteArray().set( new Byte[]
// {
// 9, null, -12, 23, -12, 127, -128, 73
// } );
// NestedEntities
proto.barAssociation().set(buildBarEntity("bazar in barAssociation"));
proto.barEntityAssociation().set(buildBarEntity("bazar in barEntityAssociation"));
proto.barManyAssociation().add(buildBarEntity("bazar ONE in barManyAssociation"));
proto.barManyAssociation().add(buildBarEntity("bazar TWO in barManyAssociation"));
proto.barEntityManyAssociation().add(buildBarEntity("bazar ONE in barEntityManyAssociation"));
proto.barEntityManyAssociation().add(buildBarEntity("bazar TWO in barEntityManyAssociation"));
return builder.newInstance();
}
use of org.joda.time.LocalDateTime in project qi4j-sdk by Qi4j.
the class AbstractQueryTest method script43_LocalDateTime.
@Test
public void script43_LocalDateTime() {
QueryBuilder<Person> qb = this.module.newQueryBuilder(Person.class);
Person person = templateFor(Person.class);
Query<Person> query = unitOfWork.newQuery(qb.where(and(gt(person.localDateTimeValue(), new LocalDateTime("2005-03-04T13:24:35", UTC)), lt(person.localDateTimeValue(), new LocalDateTime("2015-03-04T13:24:35", UTC)))));
System.out.println("*** script43_LocalDateTime: " + query);
verifyUnorderedResults(query, "Jack Doe");
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ConsecutiveDaysTimeframe method getIntervals.
public List<TimeframeInterval> getIntervals(LocalDateTime now) {
if (start != null && end != null) {
LocalDateTime earliestStartNextOccurrence = start.toNextOccurrence(now);
LocalDateTime latestEndNextOccurrence = end.toNextOccurrence(now);
LocalDateTime earliestStartDateTime = earliestStartNextOccurrence;
if (latestEndNextOccurrence.isBefore(earliestStartNextOccurrence) && now.isBefore(latestEndNextOccurrence)) {
earliestStartDateTime = start.toLastOccurrence(now);
}
LocalDateTime latestEndDateTime = end.toNextOccurrence(earliestStartDateTime);
Interval interval = new Interval(earliestStartDateTime.toDateTime(), latestEndDateTime.toDateTime()).withChronology(ISOChronology.getInstance());
TimeframeInterval timeframeInterval = new TimeframeInterval(this, interval);
return Collections.singletonList(timeframeInterval);
}
return null;
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class Schedule method getCurrentOrNextTimeframeInterval.
/**
* Returns the current or next timeframe if the remaining time is greater than maximum running time; otherwise the next timeframe is returned.
* @param now the time reference
* @param schedules the list of timeframes to choose from (current timeframe has to be first)
* @param onlyAlreadyStarted consider only timeframe intervals already started
* @param onlySufficient if true consider timeframe already started only if time to interval end exceeds min running time
* @return the next timeframe becoming valid or null
*/
public static TimeframeInterval getCurrentOrNextTimeframeInterval(LocalDateTime now, List<Schedule> schedules, boolean onlyAlreadyStarted, boolean onlySufficient) {
if (schedules == null || schedules.size() == 0) {
return null;
}
Map<Long, TimeframeInterval> startDelayOfTimeframeInterval = new TreeMap<>();
for (Schedule schedule : schedules) {
Timeframe timeframe = schedule.getTimeframe();
timeframe.setSchedule(schedule);
List<TimeframeInterval> timeframeIntervals = timeframe.getIntervals(now);
for (TimeframeInterval timeframeInterval : timeframeIntervals) {
Interval interval = timeframeInterval.getInterval();
if (interval.contains(now.toDateTime())) {
// interval already started ...
if (onlySufficient) {
if (now.plusSeconds(schedule.getMaxRunningTime()).plusSeconds(additionalRunningTime).isBefore(new LocalDateTime(interval.getEnd()))) {
// ... with remaining running time sufficient
return timeframeInterval;
}
} else {
return timeframeInterval;
}
} else if (!onlyAlreadyStarted) {
// interval starts in future
startDelayOfTimeframeInterval.put(interval.getStartMillis() - now.toDateTime().getMillis(), timeframeInterval);
}
}
}
if (startDelayOfTimeframeInterval.size() > 0) {
Long startDelay = startDelayOfTimeframeInterval.keySet().iterator().next();
return startDelayOfTimeframeInterval.get(startDelay);
}
return null;
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class SempControllerTest method createSempTimeFrame_TimeFrameOverMidnight_AfterMidnight.
@Test
public void createSempTimeFrame_TimeFrameOverMidnight_AfterMidnight() {
ApplianceLogger logger = new ApplianceLogger(LoggerFactory.getLogger(Appliance.class));
logger.setApplianceId(DEVICE_ID);
LocalDateTime now = toToday(0, 30, 0);
Schedule schedule = new Schedule(7200, 7200, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
de.avanux.smartapplianceenabler.semp.webservice.Timeframe sempTimeFrame = sempController.createSempTimeFrame(logger, DEVICE_ID, schedule, interval, 0, 0, now);
Assert.assertEquals(0, (long) sempTimeFrame.getEarliestStart());
Assert.assertEquals(12600, (long) sempTimeFrame.getLatestEnd());
}
Aggregations