Search in sources :

Example 16 with Duration

use of javax.xml.datatype.Duration in project apache-kafka-on-k8s by banzaicloud.

the class StreamsResetter method maybeReset.

private void maybeReset(final String groupId, final Consumer<byte[], byte[]> client, final Set<TopicPartition> inputTopicPartitions) throws Exception {
    if (inputTopicPartitions.size() > 0) {
        System.out.println("Following input topics offsets will be reset to (for consumer group " + groupId + ")");
        if (options.has(toOffsetOption)) {
            resetOffsetsTo(client, inputTopicPartitions, options.valueOf(toOffsetOption));
        } else if (options.has(toEarliestOption)) {
            client.seekToBeginning(inputTopicPartitions);
        } else if (options.has(toLatestOption)) {
            client.seekToEnd(inputTopicPartitions);
        } else if (options.has(shiftByOption)) {
            shiftOffsetsBy(client, inputTopicPartitions, options.valueOf(shiftByOption));
        } else if (options.has(toDatetimeOption)) {
            final String ts = options.valueOf(toDatetimeOption);
            final long timestamp = getDateTime(ts);
            resetToDatetime(client, inputTopicPartitions, timestamp);
        } else if (options.has(byDurationOption)) {
            final String duration = options.valueOf(byDurationOption);
            final Duration durationParsed = DatatypeFactory.newInstance().newDuration(duration);
            resetByDuration(client, inputTopicPartitions, durationParsed);
        } else if (options.has(fromFileOption)) {
            final String resetPlanPath = options.valueOf(fromFileOption);
            final Map<TopicPartition, Long> topicPartitionsAndOffset = getTopicPartitionOffsetFromResetPlan(resetPlanPath);
            resetOffsetsFromResetPlan(client, inputTopicPartitions, topicPartitionsAndOffset);
        } else {
            client.seekToBeginning(inputTopicPartitions);
        }
        for (final TopicPartition p : inputTopicPartitions) {
            System.out.println("Topic: " + p.topic() + " Partition: " + p.partition() + " Offset: " + client.position(p));
        }
    }
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) Duration(javax.xml.datatype.Duration)

Example 17 with Duration

use of javax.xml.datatype.Duration in project msgraph-sdk-java by microsoftgraph.

the class OutlookTests method testGetFindMeetingTimes.

@Test
public void testGetFindMeetingTimes() {
    TestBase testBase = new TestBase();
    // Get the first user in the tenant
    User me = testBase.graphClient.me().buildRequest().get();
    IUserCollectionPage users = testBase.graphClient.users().buildRequest().get();
    User tenantUser = users.getCurrentPage().get(0);
    // Ensure that the user grabbed is not the logged-in user
    if (tenantUser.mail.equals(me.mail)) {
        tenantUser = users.getCurrentPage().get(1);
    }
    ArrayList<AttendeeBase> attendees = new ArrayList<AttendeeBase>();
    AttendeeBase attendeeBase = new AttendeeBase();
    EmailAddress email = new EmailAddress();
    email.address = tenantUser.mail;
    attendeeBase.emailAddress = email;
    attendees.add(attendeeBase);
    try {
        DatatypeFactory.newInstance().newDuration("PT30M");
        Duration duration = DatatypeFactory.newInstance().newDuration("PT30M");
        MeetingTimeSuggestionsResult result = testBase.graphClient.me().findMeetingTimes(attendees, null, null, duration, 10, true, false, 10.0).buildRequest().post();
        assertNotNull(result);
    } catch (Exception e) {
        Assert.fail("Duration could not be created from String");
    }
}
Also used : User(com.microsoft.graph.models.extensions.User) IUserCollectionPage(com.microsoft.graph.requests.extensions.IUserCollectionPage) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) EmailAddress(com.microsoft.graph.models.extensions.EmailAddress) Test(org.junit.Test)

Example 18 with Duration

use of javax.xml.datatype.Duration in project rdf4j by eclipse.

the class LiteralsTest method testGetDurationValueLiteralDuration.

@Test
public final void testGetDurationValueLiteralDuration() throws Exception {
    DatatypeFactory dtFactory = DatatypeFactory.newInstance();
    Duration fallback = dtFactory.newDuration(true, 1, 1, 1, 1, 1, 1);
    Duration result = Literals.getDurationValue(vf.createLiteral("P5Y"), fallback);
    assertNotNull(result);
    assertFalse(result.equals(fallback));
    assertEquals(5, result.getYears());
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 19 with Duration

use of javax.xml.datatype.Duration in project webtools.sourceediting by eclipse.

the class FnAdjustTimeToTimeZone method adjustTime.

/**
 * Evaluate the function using the arguments passed.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the fn:dateTime operation.
 */
public static ResultSequence adjustTime(Collection args, DynamicContext dc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expectedArgs());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (argiter.hasNext()) {
        arg2 = (ResultSequence) argiter.next();
    }
    XSTime time = (XSTime) arg1.first();
    XSDayTimeDuration timezone = null;
    if (arg2.empty()) {
        if (time.timezoned()) {
            XSTime localized = new XSTime(time.calendar(), null);
            return localized;
        } else {
            return arg1;
        }
    }
    XMLGregorianCalendar xmlCalendar = null;
    if (time.tz() != null) {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) time.normalizeCalendar(time.calendar(), time.tz()));
    } else {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int) time.second(), 0);
    }
    timezone = (XSDayTimeDuration) arg2.first();
    if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
        throw DynamicError.invalidTimezone();
    }
    if (time.tz() == null) {
        return new XSTime(time.calendar(), timezone);
    }
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSTime(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 20 with Duration

use of javax.xml.datatype.Duration in project webtools.sourceediting by eclipse.

the class FnAdjustDateToTimeZone method adjustDate.

/**
 * Evaluate the function using the arguments passed.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the fn:dateTime operation.
 */
public static ResultSequence adjustDate(Collection args, DynamicContext dc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expectedArgs());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (argiter.hasNext()) {
        arg2 = (ResultSequence) argiter.next();
    }
    XSDate date = (XSDate) arg1.item(0);
    XSDayTimeDuration timezone = null;
    if (arg2.empty()) {
        if (date.timezoned()) {
            XSDate localized = new XSDate(date.calendar(), null);
            return localized;
        }
        return arg1;
    }
    timezone = (XSDayTimeDuration) arg2.item(0);
    if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
        throw DynamicError.invalidTimezone();
    }
    if (date.tz() == null) {
        return new XSDate(date.calendar(), timezone);
    }
    XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) date.normalizeCalendar(date.calendar(), date.tz()));
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSDate(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XSDate(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)

Aggregations

Duration (javax.xml.datatype.Duration)110 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)50 Test (org.junit.Test)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ArrayList (java.util.ArrayList)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 GregorianCalendar (java.util.GregorianCalendar)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 Date (java.util.Date)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 Calendar (java.util.Calendar)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 Collection (java.util.Collection)4 NodeValue (org.apache.jena.sparql.expr.NodeValue)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 Task (com.evolveum.midpoint.task.api.Task)3