Example usage for javax.xml.datatype DatatypeFactory newXMLGregorianCalendar

List of usage examples for javax.xml.datatype DatatypeFactory newXMLGregorianCalendar

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newXMLGregorianCalendar.

Prototype

public abstract XMLGregorianCalendar newXMLGregorianCalendar(final GregorianCalendar cal);

Source Link

Document

Create an XMLGregorianCalendar from a GregorianCalendar .

Usage

From source file:edu.duke.cabig.c3pr.domain.scheduler.runtime.job.CCTSNotificationMessageJob.java

private Notification convert(CCTSNotification notification) {
    try {/*from w w w  .  ja  v  a2  s.c o m*/
        Notification jaxbNotification = new Notification();
        jaxbNotification.setApplication(Application.C_3_PR);
        jaxbNotification.setEventType(EventType.fromValue(notification.getEventType()));
        if (notification.getTimestamp() != null) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(notification.getTimestamp());
            DatatypeFactory df = DatatypeFactory.newInstance();
            XMLGregorianCalendar xmlDate = df.newXMLGregorianCalendar(gc);
            jaxbNotification.setTimestamp(xmlDate);
        }
        BusinessObjectID businessObjectID = new BusinessObjectID();
        businessObjectID.setValue(notification.getIdentifierValue());
        businessObjectID.setType(notification.getIdentifierType());
        jaxbNotification.setObjectId(businessObjectID);

        return jaxbNotification;
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.fusesource.example.camel.ingest.FileIngestorRouteBuilderTest.java

@Test
public void testPositive() throws Exception {
    context.start();/*from  w  w  w  . ja v a2  s.c  om*/

    DatatypeFactory dtf = DatatypeFactory.newInstance();

    Set<String> expectedIds = new HashSet<String>();
    AggregateRecordType agt = new AggregateRecordType();
    agt.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));

    output.setExpectedMessageCount(10);

    for (int i = 0; i < 10; i++) {
        RecordType recordType = new RecordType();
        recordType.setId(String.valueOf(i));
        recordType.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
        recordType.setDescription("Record number: " + i);
        agt.getRecord().add(recordType);
        expectedIds.add(String.valueOf(i));
    }

    createAndMoveFile(agt);

    output.assertIsSatisfied();
    validateFileMove(false);

    for (Exchange exchange : output.getReceivedExchanges()) {
        assertTrue(expectedIds.remove(exchange.getIn().getBody(RecordType.class).getId()));
    }

    assertTrue(expectedIds.isEmpty());
}

From source file:com.fusesource.example.camel.ingest.FileIngestorRouteBuilderTest.java

@Test
@DirtiesContext// w  w w . j ava  2 s  .  c o  m
public void testJmsFailure() throws Exception {
    RouteDefinition routeDef = context.getRouteDefinition(FileIngestorRouteBuilder.ENQUEUE_RECORD_ROUTE_ID);

    routeDef.adviceWith(context, new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint(builder.getEnqueueRecordsDestinationUri()).choice().when()
                    .xpath("/example:record/example:id[text() = '1']", FileIngestorRouteBuilder.NAMESPACES)
                    .throwException(new JMSException("Simulated JMS Error!")).end();
        }
    });

    context.start();

    DatatypeFactory dtf = DatatypeFactory.newInstance();

    Set<String> expectedIds = new HashSet<String>();
    AggregateRecordType agt = new AggregateRecordType();
    agt.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));

    output.setExpectedMessageCount(9);

    for (int i = 0; i < 10; i++) {
        RecordType record = new RecordType();
        record.setId(String.valueOf(i));
        record.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
        record.setDescription("Record number: " + i);
        agt.getRecord().add(record);

        if (i != 1) {
            expectedIds.add(String.valueOf(i));
        }
    }

    createAndMoveFile(agt);

    output.assertIsSatisfied();
    validateFileMove(true);

    for (Exchange exchange : output.getReceivedExchanges()) {
        assertTrue(expectedIds.remove(exchange.getIn().getBody(RecordType.class).getId()));
    }

    assertTrue(expectedIds.isEmpty());

}

From source file:com.qut.middleware.delegator.openid.authn.impl.AuthnProcessorImpl.java

/**
 * Generates an XML gregorian calendar instance based on 0 offset UTC current time.
 *
 * @return The created calendar for the current UTC time, else null if an error
 * occurs creating the calendar./* w ww.  j ava  2  s  . c  o  m*/
 */
private XMLGregorianCalendar generateXMLCalendar() {
    GregorianCalendar calendar;

    SimpleTimeZone tz = new SimpleTimeZone(0, ConfigurationConstants.timeZone);
    calendar = new GregorianCalendar(tz);

    try {
        DatatypeFactory factory = DatatypeFactory.newInstance();
        return factory.newXMLGregorianCalendar(calendar);
    } catch (DatatypeConfigurationException e) {
        return null;
    }
}

From source file:com.fusesource.example.camel.process.camel.ProcessorRouteBuilderTest.java

@Test
@DirtiesContext/*from www . ja v  a  2 s .c  o m*/
public void testDuplicates() throws Exception {
    context.start();

    DatatypeFactory dtf = DatatypeFactory.newInstance();

    output.setExpectedMessageCount(1);

    RecordType recordType = new RecordType();
    recordType.setId("1");
    recordType.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
    recordType.setDescription("Record number: 1");

    trigger.sendBody(recordType);

    trigger.sendBody(recordType);

    output.assertIsSatisfied();
}

From source file:name.persistent.behaviours.RemoteGraphSupport.java

private void store(String type, HttpResponse resp, String... origins) throws Exception {
    ObjectConnection con = getObjectConnection();
    con.addDesignation(this, RemoteGraph.class);
    String via = getHeader(resp, "Via");
    if (via == null) {
        String url = getResource().stringValue();
        String authority = new ParsedURI(url).getAuthority();
        setPurlVia(PROTOCOL + " " + authority);
    } else {/*from w ww  .  jav  a  2  s.  c o m*/
        setPurlVia(via);
    }
    setPurlContentType(type);
    setPurlEtag(getHeader(resp, "ETag"));
    setPurlCacheControl(getHeader(resp, "Cache-Control"));
    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();
    setPurlLastValidated(df.newXMLGregorianCalendar(gc));
    gc.setTime(getDateHeader(resp, "Last-Modified"));
    setPurlLastModified(df.newXMLGregorianCalendar(gc));
    if (origins != null) {
        ObjectFactory of = con.getObjectFactory();
        for (String origin : origins) {
            if (origin != null) {
                Domain o = of.createObject(origin, Domain.class);
                getPurlAllowedOrigins().add(o);
            }
        }
    }
    for (Header hd : resp.getHeaders("Warning")) {
        if (hd.getValue().contains("111")) {
            // 111 "Revalidation failed"
            con.addDesignation(this, Unresolvable.class);
        }
    }
}

From source file:name.persistent.behaviours.RemoteGraphSupport.java

@Override
public boolean reload(String origin) throws Exception {
    String url = getResource().stringValue();
    BasicHttpRequest req = new BasicHttpRequest("GET", url);
    String type = getPurlContentType();
    if (type == null) {
        req.setHeader("Accept", "application/rdf+xml");
    } else {/*from   w w  w .j av  a2s.c  o m*/
        req.setHeader("Accept", type);
    }
    String etag = getPurlEtag();
    if (etag != null) {
        req.setHeader("If-None-Match", etag);
    }
    XMLGregorianCalendar modified = getPurlLastModified();
    if (modified != null) {
        Date date = modified.toGregorianCalendar().getTime();
        req.setHeader("If-Modified-Since", DateUtil.formatDate(date));
    }
    HttpResponse resp = requestRDF(req, 20);
    int code = resp.getStatusLine().getStatusCode();
    if (code == 304) {
        DatatypeFactory df = DatatypeFactory.newInstance();
        GregorianCalendar gc = new GregorianCalendar();
        setPurlLastValidated(df.newXMLGregorianCalendar(gc));
        setPurlCacheControl(getHeader(resp, "Cache-Control"));
    }
    if (code == 304 || code == 404) {
        HttpEntity entity = resp.getEntity();
        if (entity != null) {
            entity.consumeContent();
        }
        return true;
    }
    return importResponse(resp, origin);
}

From source file:com.fusesource.example.camel.process.camel.ProcessorRouteBuilderTest.java

@Test
@DirtiesContext/*from  ww  w.  java  2s  .c  o m*/
public void testNonRecoverableExternalServiceException() throws Exception {
    configureProcessRecordFailure(1, false);

    context.start();

    DatatypeFactory dtf = DatatypeFactory.newInstance();

    output.setExpectedMessageCount(0);
    dlq.setExpectedMessageCount(1);

    RecordType recordType = new RecordType();
    recordType.setId("1");
    recordType.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
    recordType.setDescription("Record number: 1");

    trigger.sendBody(recordType);

    output.assertIsSatisfied(1000);
    dlq.assertIsSatisfied();
}

From source file:com.fusesource.example.camel.process.camel.ProcessorRouteBuilderTest.java

@Test
@DirtiesContext//from  w w  w . j  a v  a  2s .co m
public void testRecoverableExternalServiceException() throws Exception {
    configureProcessRecordFailure(3, true);

    context.start();

    DatatypeFactory dtf = DatatypeFactory.newInstance();

    output.setExpectedMessageCount(1);

    dlq.setExpectedMessageCount(0);

    RecordType recordType = new RecordType();
    recordType.setId("1");
    recordType.setDate(dtf.newXMLGregorianCalendar(new GregorianCalendar()));
    recordType.setDescription("Record number: 1");

    trigger.sendBody(recordType);

    output.assertIsSatisfied();
    dlq.assertIsSatisfied(10000);
}

From source file:gov.nih.nci.integration.caaers.CaAERSParticipantServiceClientIntegrationTest.java

/**
 * Testcase for marshlling participant type
 * // w w  w.  j ava  2 s  .  c  o m
 * @throws JAXBException - JAXBException
 * @throws DatatypeConfigurationException - DatatypeConfigurationException
 */
@Test
public void marshalParticipantType() throws JAXBException, DatatypeConfigurationException {
    final ParticipantType pt = new ParticipantType();
    pt.setFirstName("fn");
    pt.setLastName("ln");
    pt.setEthnicity(EthnicityType.NOT_HISPANIC_OR_LATINO);
    pt.setGender(GenderType.MALE);
    final DatatypeFactory df = DatatypeFactory.newInstance();
    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(new Date().getTime());
    pt.setBirthDate(df.newXMLGregorianCalendar(gc));
    pt.setRace(RaceType.WHITE);

    final OrganizationAssignedIdentifierType orgId = new OrganizationAssignedIdentifierType();
    orgId.setType(ParticipantIdentifierType.MRN);
    orgId.setValue("123456");
    orgId.setPrimaryIndicator(true);
    final OrganizationType ot = new OrganizationType();
    ot.setName("UCSF)");
    ot.setNciInstituteCode("UCSF");
    orgId.setOrganization(ot);
    final ParticipantType.Identifiers ids = new ParticipantType.Identifiers();
    ids.getOrganizationAssignedIdentifier().add(orgId);
    pt.setIdentifiers(ids);

    final AssignmentType at = new AssignmentType();
    at.setStudySubjectIdentifier("456");
    final StudySiteType sst = new StudySiteType();
    final OrganizationType ot2 = new OrganizationType();
    ot2.setName("UCSF)");
    ot2.setNciInstituteCode("UCSF");
    sst.setOrganization(ot2);
    final StudyType st = new StudyType();
    final ReducedIdentifierType rit = new ReducedIdentifierType();
    rit.setType(StudyIdentifierType.SITE_IDENTIFIER);
    rit.setValue("1.2.3.4.5");
    final StudyType.Identifiers sids = new StudyType.Identifiers();
    sids.setIdentifier(rit);
    st.setIdentifiers(sids);
    sst.setStudy(st);
    at.setStudySite(sst);

    final Assignments ass = new Assignments();
    ass.getAssignment().add(at);
    pt.setAssignments(ass);

    final QName qname = new QName("http://webservice.caaers.cabig.nci.nih.gov/participant", "participant");
    final JAXBElement<ParticipantType> ptJaxbEle = new JAXBElement<ParticipantType>(qname,
            ParticipantType.class, pt);
    final StringWriter sw = new StringWriter();
    getMarshaller().marshal(ptJaxbEle, sw);
    Assert.assertNotNull(sw.toString());

    JAXBElement<ParticipantType> jaxbEle = (JAXBElement<ParticipantType>) getUnMarshaller()
            .unmarshal(new StreamSource(new StringReader(sw.toString())), ParticipantType.class);
    Assert.assertNotNull(jaxbEle);
    Assert.assertNotNull(jaxbEle.getValue());

    jaxbEle = (JAXBElement<ParticipantType>) getUnMarshaller()
            .unmarshal(new StreamSource(new StringReader(getPStr())), ParticipantType.class);
    Assert.assertNotNull(jaxbEle);
    final ParticipantType ptn = jaxbEle.getValue();
    Assert.assertNotNull(ptn);
}