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);
}
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);
}
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);
}
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));
}
}
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());
}
Aggregations