Search in sources :

Example 11 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class FiqlSearchConditionBuilderTest method testNotEqualToDuration.

@Test
public void testNotEqualToDuration() throws ParseException, DatatypeConfigurationException {
    Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);
    String ret = b.is("foo").notEqualTo(d).query();
    assertEquals("foo!=-P0Y0M1DT12H0M0S", ret);
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 12 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class FiqlSearchConditionBuilderTest method testEqualToDuration.

@Test
public void testEqualToDuration() throws ParseException, DatatypeConfigurationException {
    Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);
    String ret = b.is("foo").equalTo(d).query();
    assertEquals("foo==-P0Y0M1DT12H0M0S", ret);
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 13 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class Servant method createSequence.

Object createSequence(Message message) {
    LOG.fine("Creating sequence");
    final ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
    AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
    Message outMessage = message.getExchange().getOutMessage();
    if (null != outMessage) {
        RMContextUtils.storeMAPs(maps, outMessage, false, false);
    }
    EncoderDecoder codec = protocol.getCodec();
    CreateSequenceType create = codec.convertReceivedCreateSequence(getParameter(message));
    Destination destination = reliableEndpoint.getDestination();
    CreateSequenceResponseType createResponse = new CreateSequenceResponseType();
    createResponse.setIdentifier(destination.generateSequenceIdentifier());
    DestinationPolicyType dp = reliableEndpoint.getManager().getDestinationPolicy();
    if (dp.getMaxSequences() > 0 && destination.getProcessingSequenceCount() >= dp.getMaxSequences()) {
        throw new RuntimeException("Sequence creation refused");
    }
    Duration supportedDuration = dp.getSequenceExpiration();
    if (null == supportedDuration) {
        supportedDuration = DatatypeFactory.PT0S;
    }
    Expires ex = create.getExpires();
    if (null != ex) {
        Duration effectiveDuration = ex.getValue();
        // PT0S represents 0 second and the shortest duration but in ws-rm, considered the longest
        if (DatatypeFactory.PT0S.equals(effectiveDuration) || (!DatatypeFactory.PT0S.equals(supportedDuration) && supportedDuration.isShorterThan(effectiveDuration))) {
            effectiveDuration = supportedDuration;
        }
        ex = new Expires();
        ex.setValue(effectiveDuration);
        createResponse.setExpires(ex);
    }
    OfferType offer = create.getOffer();
    if (null != offer) {
        AcceptType accept = new AcceptType();
        if (dp.isAcceptOffers()) {
            Source source = reliableEndpoint.getSource();
            LOG.fine("Accepting inbound sequence offer");
            // AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
            accept.setAcksTo(RMUtils.createReference(maps.getTo().getValue()));
            SourceSequence seq = new SourceSequence(offer.getIdentifier(), null, createResponse.getIdentifier(), protocol);
            seq.setExpires(offer.getExpires());
            seq.setTarget(create.getAcksTo());
            source.addSequence(seq);
            source.setCurrent(createResponse.getIdentifier(), seq);
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Making offered sequence the current sequence for responses to " + createResponse.getIdentifier().getValue());
            }
        } else {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Refusing inbound sequence offer");
            }
            accept.setAcksTo(RMUtils.createNoneReference());
        }
        createResponse.setAccept(accept);
    }
    DestinationSequence seq = new DestinationSequence(createResponse.getIdentifier(), create.getAcksTo(), destination, protocol);
    seq.setCorrelationID(maps.getMessageID().getValue());
    destination.addSequence(seq);
    LOG.fine("returning " + createResponse);
    return codec.convertToSend(createResponse);
}
Also used : Message(org.apache.cxf.message.Message) Duration(javax.xml.datatype.Duration) DestinationPolicyType(org.apache.cxf.ws.rm.manager.DestinationPolicyType) CreateSequenceResponseType(org.apache.cxf.ws.rm.v200702.CreateSequenceResponseType) AcceptType(org.apache.cxf.ws.rm.v200702.AcceptType) OfferType(org.apache.cxf.ws.rm.v200702.OfferType) CreateSequenceType(org.apache.cxf.ws.rm.v200702.CreateSequenceType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) Expires(org.apache.cxf.ws.rm.v200702.Expires)

Example 14 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class SourceSequence method setExpires.

public void setExpires(Expires ex) {
    Duration d = null;
    expires = null;
    if (null != ex) {
        d = ex.getValue();
    }
    if (null != d && !d.equals(DatatypeFactory.PT0S)) {
        Date now = new Date();
        expires = new Date(now.getTime() + ex.getValue().getTimeInMillis(now));
    }
}
Also used : Duration(javax.xml.datatype.Duration) Date(java.util.Date)

Example 15 with Duration

use of javax.xml.datatype.Duration in project wikidata-query-rdf by wikimedia.

the class WikibaseDateUnitTest method durations.

@Test
public void durations() throws DatatypeConfigurationException {
    WikibaseDate wbDate = new WikibaseDate(2016, 8, 5, 0, 0, 0);
    Duration d = DatatypeFactory.newInstance().newDuration("P7D");
    WikibaseDate wdDate7days = wbDate.addDuration(d);
    assertEquals(jodaSeconds(2016, 8, 12, 0, 0, 0), wdDate7days.secondsSinceEpoch());
    wdDate7days = wbDate.addDuration(d.negate());
    assertEquals(jodaSeconds(2016, 7, 29, 0, 0, 0), wdDate7days.secondsSinceEpoch());
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

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