Search in sources :

Example 1 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project ORCID-Source by ORCID.

the class DateUtils method convertToXMLGregorianCalendar.

public static XMLGregorianCalendar convertToXMLGregorianCalendar(String dateString, boolean tidy) {
    String tidyDateString = dateString;
    if (tidy) {
        tidyDateString = tidy(dateString);
    }
    if (tidyDateString == null) {
        return null;
    }
    DatatypeFactory dataTypeFactory = createDataTypeFactory();
    try {
        return dataTypeFactory.newXMLGregorianCalendar(tidyDateString);
    } catch (IllegalArgumentException e) {
        return null;
    }
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory)

Example 2 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project zm-mailbox by Zimbra.

the class ExchangeEWSFreeBusyProvider method getFreeBusyForHost.

public List<FreeBusy> getFreeBusyForHost(String host, ArrayList<Request> req) throws IOException {
    int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
    List<FreeBusyResponseType> results = null;
    ArrayList<FreeBusy> ret = new ArrayList<FreeBusy>();
    Request r = req.get(0);
    long start = Request.offsetInterval(req.get(0).start, fb_interval);
    ServerInfo serverInfo = (ServerInfo) r.data;
    if (serverInfo == null) {
        ZimbraLog.fb.warn("no exchange server info for user " + r.email);
        return ret;
    }
    if (!serverInfo.enabled)
        return ret;
    ArrayOfMailboxData attendees = new ArrayOfMailboxData();
    for (Request request : req) {
        EmailAddress email = new EmailAddress();
        email.setAddress(request.email);
        MailboxData mailbox = new MailboxData();
        mailbox.setEmail(email);
        mailbox.setAttendeeType(MeetingAttendeeType.REQUIRED);
        attendees.getMailboxData().add(mailbox);
    }
    try {
        Duration duration = new Duration();
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        GregorianCalendar gregorianCalStart = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gregorianCalStart.setTimeInMillis(start);
        duration.setStartTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalStart));
        GregorianCalendar gregorianCalEnd = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gregorianCalEnd.setTimeInMillis(req.get(0).end);
        duration.setEndTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalEnd));
        FreeBusyViewOptionsType availabilityOpts = new FreeBusyViewOptionsType();
        availabilityOpts.setMergedFreeBusyIntervalInMinutes(fb_interval);
        availabilityOpts.getRequestedView().add("MergedOnly");
        availabilityOpts.setTimeWindow(duration);
        GetUserAvailabilityRequestType availabilityRequest = new GetUserAvailabilityRequestType();
        // TODO: check if we need to set request timezone
        SerializableTimeZone timezone = new SerializableTimeZone();
        timezone.setBias(0);
        SerializableTimeZoneTime standardTime = new SerializableTimeZoneTime();
        standardTime.setTime("00:00:00");
        standardTime.setDayOrder((short) 1);
        standardTime.setDayOfWeek(DayOfWeekType.SUNDAY);
        timezone.setStandardTime(standardTime);
        timezone.setDaylightTime(standardTime);
        availabilityRequest.setTimeZone(timezone);
        availabilityRequest.setFreeBusyViewOptions(availabilityOpts);
        availabilityRequest.setMailboxDataArray(attendees);
        RequestServerVersion serverVersion = new RequestServerVersion();
        serverVersion.setVersion(ExchangeVersionType.EXCHANGE_2010_SP_1);
        Holder<GetUserAvailabilityResponseType> availabilityResponse = new Holder<GetUserAvailabilityResponseType>();
        Holder<ServerVersionInfo> gfversionInfo = new Holder<ServerVersionInfo>();
        service.getUserAvailability(availabilityRequest, availabilityResponse, gfversionInfo);
        results = availabilityResponse.value.getFreeBusyResponseArray().getFreeBusyResponse();
    } catch (DatatypeConfigurationException dce) {
        ZimbraLog.fb.warn("getFreeBusyForHost DatatypeConfiguration failure", dce);
        return getEmptyList(req);
    } catch (Exception e) {
        ZimbraLog.fb.warn("getFreeBusyForHost failure", e);
        return getEmptyList(req);
    }
    for (Request re : req) {
        String fb = "";
        int i = 0;
        for (FreeBusyResponseType attendeeAvailability : results) {
            if (re.email == attendees.getMailboxData().get(i).getEmail().getAddress()) {
                if (ResponseClassType.SUCCESS != attendeeAvailability.getResponseMessage().getResponseClass()) {
                    ZimbraLog.fb.warn(attendeeAvailability.getResponseMessage().getMessageText());
                    ZimbraLog.fb.warn("Error in response. continuing to next one");
                    i++;
                    continue;
                }
                ZimbraLog.fb.debug("Availability for " + attendees.getMailboxData().get(i).getEmail().getAddress() + " [" + attendeeAvailability.getFreeBusyView().getMergedFreeBusy() + "]");
                fb = attendeeAvailability.getFreeBusyView().getMergedFreeBusy();
                if (fb == null) {
                    ZimbraLog.fb.warn("Merged view Free Busy info not avaiable");
                    //Avoid NPE.
                    fb = "";
                }
                break;
            }
            i++;
        }
        ret.add(new ExchangeFreeBusyProvider.ExchangeUserFreeBusy(fb, re.email, fb_interval, req.get(0).start, req.get(0).end));
    }
    return ret;
}
Also used : ServerInfo(com.zimbra.cs.fb.ExchangeFreeBusyProvider.ServerInfo) ArrayList(java.util.ArrayList) RequestServerVersion(com.microsoft.schemas.exchange.services._2006.types.RequestServerVersion) GetUserAvailabilityResponseType(com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityResponseType) ServerVersionInfo(com.microsoft.schemas.exchange.services._2006.types.ServerVersionInfo) FreeBusyResponseType(com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType) FreeBusyViewOptionsType(com.microsoft.schemas.exchange.services._2006.types.FreeBusyViewOptionsType) SerializableTimeZoneTime(com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZoneTime) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ArrayOfMailboxData(com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData) Holder(javax.xml.ws.Holder) MailboxData(com.microsoft.schemas.exchange.services._2006.types.MailboxData) ArrayOfMailboxData(com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData) GregorianCalendar(java.util.GregorianCalendar) Duration(com.microsoft.schemas.exchange.services._2006.types.Duration) SerializableTimeZone(com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZone) EmailAddress(com.microsoft.schemas.exchange.services._2006.types.EmailAddress) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GetUserAvailabilityRequestType(com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityRequestType)

Example 3 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project sic by belluccifranco.

the class AfipWebServiceSOAPClient method crearTicketRequerimientoAcceso.

public String crearTicketRequerimientoAcceso(String service, long ticketTime) {
    Date now = new Date();
    GregorianCalendar genenerationTime = new GregorianCalendar();
    GregorianCalendar expirationTime = new GregorianCalendar();
    DatatypeFactory datatypeFactory = null;
    String uniqueId = Long.toString(now.getTime() / 1000);
    expirationTime.setTime(new Date(now.getTime() + ticketTime));
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        LOGGER.error(ex.getMessage());
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_xml_factory"));
    }
    XMLGregorianCalendar XMLGenTime = datatypeFactory.newXMLGregorianCalendar(genenerationTime);
    XMLGregorianCalendar XMLExpTime = datatypeFactory.newXMLGregorianCalendar(expirationTime);
    String LoginTicketRequest_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<loginTicketRequest version=\"1.0\">" + "<header>" + "<uniqueId>" + uniqueId + "</uniqueId>" + "<generationTime>" + XMLGenTime + "</generationTime>" + "<expirationTime>" + XMLExpTime + "</expirationTime>" + "</header>" + "<service>" + service + "</service>" + "</loginTicketRequest>";
    return LoginTicketRequest_xml;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) BusinessServiceException(sic.service.BusinessServiceException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Date(java.util.Date)

Example 4 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project ddf by codice.

the class PredicateTest method testMultipleCriteria.

@Test
public void testMultipleCriteria() throws Exception {
    String methodName = "testMultipleCriteria";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    // test with temporal, spatial, and entry
    MockQuery query = new MockQuery();
    DatatypeFactory df = DatatypeFactory.newInstance();
    XMLGregorianCalendar start = df.newXMLGregorianCalendarDate(2011, 10, 25, 0);
    XMLGregorianCalendar end = df.newXMLGregorianCalendarDate(2011, 10, 27, 0);
    query.addTemporalFilter(start, end, Metacard.MODIFIED);
    String wkt = "POLYGON((0 10, 0 0, 10 0, 10 10, 0 10))";
    query.addSpatialFilter(wkt, 0.0, "Meter", "CONTAINS");
    // create entry criteria
    String catalogId = "ABC123";
    query.addEntryFilter(catalogId);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("POINT(5 5)");
    metacard.setId(catalogId);
    metacard.setCreatedDate(new Date());
    metacard.setExpirationDate(new Date());
    metacard.setEffectiveDate(new Date());
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
    Date modifiedDate = cal.toGregorianCalendar().getTime();
    metacard.setModifiedDate(modifiedDate);
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl
    Event testEvent = new Event("topic", properties);
    // input passes temporal, id, and geo
    SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
    Predicate pred = (Predicate) query.getFilter().accept(visitor, null);
    LOGGER.debug("Resulting Predicate: {}", pred);
    Filter filter = query.getFilter();
    FilterTransformer transform = new FilterTransformer();
    transform.setIndentation(2);
    String filterXml = transform.transform(filter);
    LOGGER.debug(filterXml);
    assertTrue(pred.matches(testEvent));
    // input passes temporal, id, but fails geo
    // geo out of range
    metacard.setLocation("POINT(5 50)");
    properties.clear();
    properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    // Below Pulled from PubSubProviderImpl
    contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    // input passes geo, and id, but fails temporal
    metacard.setLocation("POINT(5 5)");
    XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2011, 10, 28, 0);
    Date modifiedDate1 = cal1.toGregorianCalendar().getTime();
    // date out of range
    metacard.setModifiedDate(modifiedDate1);
    properties.clear();
    properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    // Below Pulled from PubSubProviderImpl
    contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    // input passes temporal, geo, but fails id
    XMLGregorianCalendar cal2 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
    Date modifiedDate2 = cal2.toGregorianCalendar().getTime();
    metacard.setModifiedDate(modifiedDate2);
    // bad id
    metacard.setId("invalid_id");
    properties.clear();
    properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    // Below Pulled from PubSubProviderImpl
    contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) HashMap(java.util.HashMap) SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Filter(org.opengis.filter.Filter) Event(org.osgi.service.event.Event) FilterTransformer(org.geotools.filter.FilterTransformer) Test(org.junit.Test)

Example 5 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project ddf by codice.

the class PredicateTest method testTemporal.

@Test
public void testTemporal() throws Exception {
    String methodName = "testTemporal";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    MockQuery query = new MockQuery();
    DatatypeFactory df = DatatypeFactory.newInstance();
    XMLGregorianCalendar start = df.newXMLGregorianCalendarDate(2011, 10, 25, 0);
    XMLGregorianCalendar end = df.newXMLGregorianCalendarDate(2011, 10, 27, 0);
    query.addTemporalFilter(start, end, Metacard.EFFECTIVE);
    SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
    Predicate pred = (Predicate) query.getFilter().accept(visitor, null);
    LOGGER.debug("Resulting Predicate: {}", pred);
    Filter filter = query.getFilter();
    FilterTransformer transform = new FilterTransformer();
    transform.setIndentation(2);
    String filterXml = transform.transform(filter);
    LOGGER.debug(filterXml);
    // input that passes temporal
    LOGGER.debug("\npass temporal.\n");
    MetacardImpl metacard = new MetacardImpl();
    metacard.setCreatedDate(new Date());
    metacard.setExpirationDate(new Date());
    metacard.setModifiedDate(new Date());
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
    Date effectiveDate = cal.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate);
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    Event testEvent = new Event("topic", properties);
    boolean b = pred.matches(testEvent);
    assertTrue(b);
    // input that fails temporal
    LOGGER.debug("\nfail temporal.  fail content type.\n");
    // time out of
    XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2012, 10, 30, 0);
    // range
    Date effectiveDate1 = cal1.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate1);
    LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Filter(org.opengis.filter.Filter) Event(org.osgi.service.event.Event) FilterTransformer(org.geotools.filter.FilterTransformer) Test(org.junit.Test)

Aggregations

DatatypeFactory (javax.xml.datatype.DatatypeFactory)18 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)13 Date (java.util.Date)7 GregorianCalendar (java.util.GregorianCalendar)7 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)7 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)5 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)5 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)5 Predicate (ddf.catalog.pubsub.predicate.Predicate)5 HashMap (java.util.HashMap)5 FilterTransformer (org.geotools.filter.FilterTransformer)5 Test (org.junit.Test)5 Filter (org.opengis.filter.Filter)5 Event (org.osgi.service.event.Event)5 ArrayList (java.util.ArrayList)3 FreeBusyResponseType (com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType)1 GetUserAvailabilityRequestType (com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityRequestType)1 GetUserAvailabilityResponseType (com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityResponseType)1 ArrayOfMailboxData (com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData)1