Example usage for javax.xml.datatype DatatypeFactory newXMLGregorianCalendarDate

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

Introduction

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

Prototype

public XMLGregorianCalendar newXMLGregorianCalendarDate(final int year, final int month, final int day,
        final int timezone) 

Source Link

Document

Create a Java representation of XML Schema builtin datatype date or g* .

Usage

From source file:com.kcs.core.utilities.Utility.java

public static XMLGregorianCalendar getXMLGregorianCalendarDate(Date date)
        throws DatatypeConfigurationException {
    if (Utility.isNotNull(date)) {
        GregorianCalendar arrgCtrDate = new GregorianCalendar();
        arrgCtrDate.setTime(date);/* w  ww.  j  a  v a  2  s .  c om*/
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendarDate(
                arrgCtrDate.get(Calendar.YEAR), arrgCtrDate.get(Calendar.MONTH) + 1,
                arrgCtrDate.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED);
        return xmlGregorianCalendar;
    }
    return null;
}

From source file:gov.nih.nci.cabig.caaers.api.InvestigatorMigratorServiceTest.java

private void modifyDates(Staff staff) throws Exception {

    DatatypeFactory df = DatatypeFactory.newInstance();
    Calendar gcNow = GregorianCalendar.getInstance();
    int year = gcNow.get(Calendar.YEAR);
    int month = gcNow.get(Calendar.MONTH) + 1;
    int day = gcNow.get(Calendar.DAY_OF_MONTH);
    int tz = DatatypeConstants.FIELD_UNDEFINED;

    XMLGregorianCalendar currXmlCal = df.newXMLGregorianCalendarDate(year, month, day, tz);
    XMLGregorianCalendar furXmlCal = df.newXMLGregorianCalendarDate(year + 1, month, day, tz);

    if (staff != null) {
        List<InvestigatorType> investigatorTypeList = staff.getInvestigator();
        for (InvestigatorType investigatorType : investigatorTypeList) {
            for (SiteInvestigatorType siType : investigatorType.getSiteInvestigator()) {
                siType.setStartDate(currXmlCal);
                siType.setEndDate(furXmlCal);
            }/*from w ww.  j  a  va 2  s.c  om*/
        }
    }

}

From source file:gov.nih.nci.cabig.caaers.api.ResearchStaffMigratorServiceTest.java

private void modifyDates(gov.nih.nci.cabig.caaers.integration.schema.researchstaff.Staff staff)
        throws Exception {

    DatatypeFactory df = DatatypeFactory.newInstance();
    Calendar gcNow = GregorianCalendar.getInstance();
    int year = gcNow.get(Calendar.YEAR);
    int month = gcNow.get(Calendar.MONTH) + 1;
    int day = gcNow.get(Calendar.DAY_OF_MONTH);
    int tz = DatatypeConstants.FIELD_UNDEFINED;

    XMLGregorianCalendar currXmlCal = df.newXMLGregorianCalendarDate(year, month, day, tz);
    XMLGregorianCalendar furXmlCal = df.newXMLGregorianCalendarDate(year + 1, month, day, tz);

    List<ResearchStaffType> researchStaffList = staff.getResearchStaff();
    List<SiteResearchStaffType> siteRsTypeList;
    List<SiteResearchStaffRoleType> siteRsRoleTypeList;
    for (ResearchStaffType researchStaffType : researchStaffList) {
        siteRsTypeList = researchStaffType.getSiteResearchStaffs().getSiteResearchStaff();
        for (SiteResearchStaffType sRsType : siteRsTypeList) {
            siteRsRoleTypeList = sRsType.getSiteResearchStaffRoles().getSiteResearchStaffRole();
            for (SiteResearchStaffRoleType sRsRoleType : siteRsRoleTypeList) {
                sRsRoleType.setStartDate(currXmlCal);
                sRsRoleType.setEndDate(furXmlCal);
            }/*from www .  ja v a  2 s.c  o m*/
        }
    }
}

From source file:ddf.catalog.pubsub.PredicateTest.java

@Test
public void testTemporalNullMetadata() throws Exception {
    String methodName = "testTemporalNullMetadata";
    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);/* w w  w . j  a v  a  2 s  .co  m*/
    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());

    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);
    // no contextual map containing indexed contextual data

    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    Event testEvent = new Event("topic", properties);
    boolean b = pred.matches(testEvent);
    assertTrue(b);

    LOGGER.debug("***************  END: " + methodName + "  *****************");
}

From source file:ddf.catalog.pubsub.PredicateTest.java

@Test
public void testTemporalNullOperation() throws Exception {
    String methodName = "testTemporalNullOperation";
    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);/*from  w ww.  j  a  v a  2 s.  co  m*/
    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, null);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);

    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    Event testEvent = new Event("topic", properties);
    boolean b = pred.matches(testEvent);
    assertTrue(b);

    LOGGER.debug("***************  END: " + methodName + "  *****************");
}

From source file:ddf.catalog.pubsub.PredicateTest.java

@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);/*from  ww  w . ja v a 2s  .co  m*/
    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");
    XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2012, 10, 30, 0); // time out of
    // 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 + "  *****************");
}

From source file:ddf.catalog.pubsub.PredicateTest.java

@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);//w  w  w  . j ava2  s .  c o  m

    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
    metacard.setLocation("POINT(5 50)"); // geo out of range
    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();
    metacard.setModifiedDate(modifiedDate1); // date out of range
    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);
    metacard.setId("invalid_id"); // bad 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 + "  *****************");
}

From source file:ddf.catalog.pubsub.PredicateTest.java

@Test
public void testMultipleCriteriaWithContentTypes() throws Exception {
    String methodName = "testMultipleCriteriaWithContentTypes";
    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);

    // create content type criteria
    String version1 = "version1";
    String type1 = "type1";

    List<MockTypeVersionsExtension> extensions = new ArrayList<>();
    MockTypeVersionsExtension ext1 = new MockTypeVersionsExtension();
    List<String> ext1Versions = ext1.getVersions();
    ext1Versions.add(version1);/*  ww  w . j ava  2s  . c o m*/
    ext1.setExtensionTypeName(type1);
    extensions.add(ext1);

    query.addTypeFilter(extensions);

    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 both temporal and content type
    LOGGER.debug("\npass temporal and pass content type.\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_CONTENT_TYPE_KEY, type1 + "," + version1);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    Event testEvent = new Event("topic", properties);
    boolean b = pred.matches(testEvent);
    assertTrue(b);

    // input that fails both temporal and content type
    LOGGER.debug("\nfail temporal.  fail content type.\n");
    XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2012, 10, 30, 0); // time out of
    // 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_CONTENT_TYPE_KEY, "invalid_type" + "," + version1);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));

    // input that passes temporal and fails content type
    LOGGER.debug("\npass temporal.  fail content type\n");
    XMLGregorianCalendar cal2 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); // time in
    // range
    Date effectiveDate2 = cal2.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate2);
    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_CONTENT_TYPE_KEY, "invalid_type" + "," + version1);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));

    // input that fails temporal and passes content type
    LOGGER.debug("\nfail temporal.  pass content type\n");
    XMLGregorianCalendar cal3 = df.newXMLGregorianCalendarDate(2012, 10, 26, 0); // time out of
    // range
    Date effectiveDate3 = cal3.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate3);
    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_CONTENT_TYPE_KEY, type1 + "," + version1);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));

    // multiple content types
    LOGGER.debug("\nTesting multiple content types.\n");

    String type2 = "type2";
    String version2 = "version2";
    MockTypeVersionsExtension ext2 = new MockTypeVersionsExtension();
    List<String> ext2Versions = ext2.getVersions();
    ext2Versions.add(version2);
    ext2.setExtensionTypeName(type2);
    extensions.add(ext2);

    // No version
    String type3 = "type3";
    MockTypeVersionsExtension ext3 = new MockTypeVersionsExtension();
    ext3.setExtensionTypeName(type3);
    extensions.add(ext3);

    MockQuery query2 = new MockQuery();
    query2.addTemporalFilter(start, end, Metacard.EFFECTIVE);
    query2.addTypeFilter(extensions);
    SubscriptionFilterVisitor visitor1 = new SubscriptionFilterVisitor();
    Predicate pred1 = (Predicate) query2.getFilter().accept(visitor1, null);
    LOGGER.debug("resulting predicate: " + pred1);

    // Create metacard for input
    // time and contentType match
    XMLGregorianCalendar cal4 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); // time in
    // range
    Date effectiveDate4 = cal4.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate4);
    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_CONTENT_TYPE_KEY, type1 + "," + version1);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertTrue(pred1.matches(testEvent));

    // time and contentType match against content type 3 with any version
    XMLGregorianCalendar cal5 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); // time in
    // range
    Date effectiveDate5 = cal5.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate5);
    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_CONTENT_TYPE_KEY, type3 + "," + "random_version");
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertTrue(pred1.matches(testEvent));

    // time matches and contentType matches type2
    XMLGregorianCalendar cal6 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); // time in
    // range
    Date effectiveDate6 = cal6.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate6);
    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_CONTENT_TYPE_KEY, type2 + "," + version2);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertTrue(pred1.matches(testEvent));

    // time matches and content type doesn't match
    XMLGregorianCalendar cal7 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); // time in
    // range
    Date effectiveDate7 = cal7.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate7);
    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_CONTENT_TYPE_KEY, type2 + "," + version1);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertFalse(pred1.matches(testEvent));

    LOGGER.debug("***************  END: " + methodName + "  *****************");
}

From source file:org.eclipse.smila.ontology.records.SesameValueHelper.java

/**
 * create a Sesame date literal value from a SMILA date value.
 * //from  www .  j av a  2s .  co  m
 * @param connection
 *          repository connection
 * @param literal
 *          a SMILA literal with a date value.
 * @return a Sesame date literal, if all goes well. Else return a string literal as fallback.
 */
private org.openrdf.model.Literal createDateLiteral(final RepositoryConnection connection,
        final Value literal) {
    try {
        final DatatypeFactory factory = DatatypeFactory.newInstance();
        final Calendar cal = Calendar.getInstance();
        cal.setTime(literal.asDate());
        // TODO: Support timezone here? I think one should use date/times if this should be handled timezone specific.
        // A date is the same on the whole planet, so always write it as a UTC literal.
        // final int zoneOffsetMinutes = cal.get(Calendar.ZONE_OFFSET) / MILLISECONDS_PER_MINUTE;
        final XMLGregorianCalendar time = factory.newXMLGregorianCalendarDate(cal.get(Calendar.YEAR),
                cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), 0); // zoneOffsetMinutes);
        return connection.getValueFactory().createLiteral(time);
    } catch (final Exception ex) {
        _log.warn("cuold not create a time literal from value '" + literal + "', just adding a string literal",
                ex);
        return connection.getValueFactory().createLiteral(literal.toString());
    }
}

From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java

private Header createSAFTHeader(DateTime startDate, DateTime endDate, FinantialInstitution finantialInstitution,
        String auditVersion) {//from w w  w. j av  a  2  s  .c om

    Header header = new Header();
    DatatypeFactory dataTypeFactory;
    try {

        dataTypeFactory = DatatypeFactory.newInstance();

        // AuditFileVersion
        header.setAuditFileVersion(auditVersion);

        // BusinessName - Nome da Empresa
        header.setBusinessName(finantialInstitution.getCompanyName());
        header.setCompanyName(finantialInstitution.getName());

        // CompanyAddress
        AddressStructurePT companyAddress = null;
        //TODOJN Locale por resolver
        companyAddress = convertAddressToAddressPT(finantialInstitution.getAddress(),
                finantialInstitution.getZipCode(),
                finantialInstitution.getMunicipality() != null
                        ? finantialInstitution.getMunicipality().getLocalizedName(new Locale("pt"))
                        : "---",
                finantialInstitution.getAddress());
        header.setCompanyAddress(companyAddress);

        // CompanyID
        /*
         * Obtem -se pela concatena??o da conservat?ria do registo comercial
         * com o n?mero do registo comercial, separados pelo car?cter
         * espa?o. Nos casos em que n?o existe o registo comercial, deve ser
         * indicado o NIF.
         */
        header.setCompanyID(finantialInstitution.getComercialRegistrationCode());

        // CurrencyCode
        /*
         * 1.11 * C?digo de moeda (CurrencyCode) . . . . . . . Preencher com
         * ?EUR?
         */
        header.setCurrencyCode(finantialInstitution.getCurrency().getCode());

        // DateCreated
        DateTime now = new DateTime();
        header.setDateCreated(convertToXMLDateTime(dataTypeFactory, now));

        // Email
        // header.setEmail(StringUtils.EMPTY);

        // EndDate
        header.setEndDate(convertToXMLDateTime(dataTypeFactory, endDate));

        // Fax
        // header.setFax(StringUtils.EMPTY);

        // FiscalYear
        /*
         * Utilizar as regras do c?digo do IRC, no caso de per?odos
         * contabil?sticos n?o coincidentes com o ano civil. (Ex: per?odo de
         * tributa??o de 01 -10 -2008 a 30 -09 -2009 corresponde FiscalYear
         * 2008). Inteiro 4
         */
        header.setFiscalYear(endDate.getYear());

        // Ir obter a data do ?ltimo
        // documento(por causa de submeter em janeiro, documentos de
        // dezembro)

        // HeaderComment
        // header.setHeaderComment(org.apache.commons.lang.StringUtils.EMPTY);

        // ProductCompanyTaxID
        // Preencher com o NIF da entidade produtora do software
        header.setProductCompanyTaxID(SaftConfig.PRODUCT_COMPANY_TAX_ID());

        // ProductID
        /*
         * 1.16 * Nome do produto (ProductID). . . . . . . . . . . Nome do
         * produto que gera o SAF -T (PT) . . . . . . . . . . . Deve ser
         * indicado o nome comercial do software e o da empresa produtora no
         * formato ?Nome produto/nome empresa?.
         */
        header.setProductID(SaftConfig.PRODUCT_ID());

        // Product Version
        header.setProductVersion(SaftConfig.PRODUCT_VERSION());

        // SoftwareCertificateNumber
        header.setSoftwareCertificateNumber(BigInteger.valueOf(SaftConfig.SOFTWARE_CERTIFICATE_NUMBER()));

        // StartDate
        header.setStartDate(dataTypeFactory.newXMLGregorianCalendarDate(startDate.getYear(),
                startDate.getMonthOfYear(), startDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED));

        // TaxAccountingBasis
        /*
         * Deve ser preenchido com: contabilidade; facturao; ?I? ? dados
         * integrados de factura??o e contabilidade; ?S? ? autofactura??o;
         * ?P? ? dados parciais de factura??o
         */
        header.setTaxAccountingBasis("P");

        // TaxEntity
        /*
         * Identifica??o do estabelecimento (TaxEntity) No caso do ficheiro
         * de factura??o dever? ser especificado a que estabelecimento diz
         * respeito o ficheiro produzido, se aplic?vel, caso contr?rio,
         * dever? ser preenchido com a especifica??o ?Global?. No caso do
         * ficheiro de contabilidade ou integrado, este campo dever? ser
         * preenchido com a especifica??o ?Sede?. Texto 20
         */
        header.setTaxEntity("Global");

        // TaxRegistrationNumber
        /*
         * N?mero de identifica??o fiscal da empresa
         * (TaxRegistrationNumber). Preencher com o NIF portugu?s sem
         * espa?os e sem qualquer prefixo do pa?s. Inteiro 9
         */
        try {
            header.setTaxRegistrationNumber(Integer.parseInt(finantialInstitution.getFiscalNumber()));
        } catch (Exception ex) {
            throw new RuntimeException("Invalid Fiscal Number.");
        }

        // header.setTelephone(finantialInstitution.get);

        // header.setWebsite(finantialInstitution.getEmailContact());

        return header;
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
        return null;
    }
}