Search in sources :

Example 81 with LocalDateTime

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();
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 82 with LocalDateTime

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");
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Person(org.qi4j.test.indexing.model.Person) Test(org.junit.Test)

Example 83 with LocalDateTime

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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval)

Example 84 with LocalDateTime

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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TreeMap(java.util.TreeMap) Interval(org.joda.time.Interval)

Example 85 with LocalDateTime

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)120 Test (org.junit.Test)73 Interval (org.joda.time.Interval)27 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)21 DateTime (org.joda.time.DateTime)18 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 LocalDate (org.joda.time.LocalDate)12 ArrayList (java.util.ArrayList)8 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Date (java.util.Date)6 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AccAccount (eu.bcvsolutions.idm.acc.entity.AccAccount)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4