Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import ddf.catalog.data.Metacard;
import ddf.catalog.data.types.Core;
import ddf.catalog.source.UnsupportedQueryException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -129,7 +129,7 @@ public class CswCqlFilterTest {
initDefaultCswFilterDelegate(
initCswSourceConfiguration(CswAxisOrder.LON_LAT, CswConstants.CSW_TYPE));

private final Date date = getDate();
private Date date;

private final String propertyName = DEFAULT_PROPERTY_NAME;

Expand Down Expand Up @@ -231,7 +231,7 @@ public class CswCqlFilterTest {

private final String propertyIsEqualToContentType = "type" + SPACE + EQUALS + SPACE + "'myType'";

private final String propertyIsEqualToWithDate = getPropertyIsEqualToWithDate(getDate());
private String propertyIsEqualToWithDate;

private final String propertyIsEqualToWithBoolean =
DEFAULT_PROPERTY_NAME + SPACE + EQUALS + SPACE + TRUE;
Expand Down Expand Up @@ -616,6 +616,8 @@ private static Operation getOperation() {

@Before
public void setup() {
date = getDate();
propertyIsEqualToWithDate = getPropertyIsEqualToWithDate(getDate());
Hints.putSystemDefault(
Hints.CRS_AUTHORITY_FACTORY,
"org.geotools.referencing.factory.epsg.hsql.ThreadedHsqlEpsgFactory");
Expand Down Expand Up @@ -1499,15 +1501,23 @@ public void testDisjointPropertyOwsBoundingBoxPolygon() throws UnsupportedQueryE
}

private Date getDate() {
String dateString = "Jun 11 2002";
SimpleDateFormat formatter = new SimpleDateFormat("MMM d yyyy");
Date aDate = null;
final String dateString = "Jun 11 2002";

// Define the formatter for the input pattern
java.time.format.DateTimeFormatter formatter =
java.time.format.DateTimeFormatter.ofPattern("MMM dd yyyy", java.util.Locale.ENGLISH);

Date date = null;
// Parse the input date-time with MST, then convert to America/Denver to ensure that
// region-specific rules are applied correctly when parsing
LocalDate localDate;
try {
aDate = formatter.parse(dateString);
} catch (ParseException e) {
localDate = LocalDate.parse(dateString, formatter);
date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return aDate;
return date;
}

private String getPropertyIsEqualToWithDate(Date aDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
import java.io.IOException;
import java.io.StringWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
Expand Down Expand Up @@ -140,7 +142,7 @@ public class CswFilterDelegateTest {

private static final String DISTANCE_GEO_FILTER_PROP_MAP_KEY = "distance";

private static final Date SAMPLE_NON_ISO_8601_DATE;
private static Date sampleNonIso8601Date;

// NOTE: The contents of these maps ARE mutable
private static final Map<String, String> POS_LIST_GEO_FILTER_PROP_MAP = new HashMap<>();
Expand All @@ -167,15 +169,6 @@ public class CswFilterDelegateTest {

private static Marshaller marshaller = null;

static {
try {
SAMPLE_NON_ISO_8601_DATE = new SimpleDateFormat("MMM d yyyy").parse("Jun 11 2003");
} catch (ParseException pe) {
LOGGER.error("Unable to instantiate SAMPLE_NON_ISO_8601_DATE", pe);
throw new RuntimeException();
}
}

private final CswFilterDelegate cswFilterDelegateLatLon =
createCswFilterDelegate(
initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE));
Expand Down Expand Up @@ -309,7 +302,7 @@ public class CswFilterDelegateTest {
createComparisonFilterString(
ComparisonOperator.PROPERTY_IS_EQUAL_TO,
DEFAULT_PROPERTY_NAME,
convertDateToIso8601Format(SAMPLE_NON_ISO_8601_DATE).toString());
convertDateToIso8601Format(sampleNonIso8601Date).toString());

private final String propertyIsEqualToXmlWithBoolean =
createComparisonFilterString(
Expand Down Expand Up @@ -778,6 +771,27 @@ public static void setupTestClass() throws JAXBException, ParseException {
map.put("ogc", "http://www.opengis.net/ogc");
NamespaceContext ctx = new SimpleNamespaceContext(map);
XMLUnit.setXpathNamespaceContext(ctx);

sampleNonIso8601Date = getNonIso8601Date();
}

private static Date getNonIso8601Date() {
final String dateString = "Jun 11 2003";

java.time.format.DateTimeFormatter formatter =
java.time.format.DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH);

Date date = null;
// Parse the input date-time with MST, then convert to America/Denver to ensure that
// region-specific rules are applied correctly when parsing
LocalDate localDate;
try {
localDate = LocalDate.parse(dateString, formatter);
date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return date;
}

private static FilterCapabilities getMockFilterCapabilities() {
Expand Down Expand Up @@ -1518,11 +1532,10 @@ public void testConfigurableMetacardMappingApiso()
public void testPropertyIsEqualToDateLiteral()
throws JAXBException, ParseException, SAXException, IOException {

LOGGER.debug("Input date: {}", SAMPLE_NON_ISO_8601_DATE);
LOGGER.debug(
"ISO 8601 formatted date: {}", convertDateToIso8601Format(SAMPLE_NON_ISO_8601_DATE));
LOGGER.debug("Input date: {}", sampleNonIso8601Date);
LOGGER.debug("ISO 8601 formatted date: {}", convertDateToIso8601Format(sampleNonIso8601Date));
FilterType filterType =
cswFilterDelegateLatLon.propertyIsEqualTo(propertyName, SAMPLE_NON_ISO_8601_DATE);
cswFilterDelegateLatLon.propertyIsEqualTo(propertyName, sampleNonIso8601Date);
assertXMLEqual(propertyIsEqualToXmlWithNonIso8601Date, getXmlFromMarshaller(filterType));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.xml.bind.JAXBContext;
Expand All @@ -62,6 +62,7 @@
import net.opengis.gml.v_3_1_1.MultiPolygonType;
import net.opengis.gml.v_3_1_1.PointType;
import net.opengis.gml.v_3_1_1.PolygonType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType;
import org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsConstants;
import org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper;
Expand All @@ -70,6 +71,7 @@
import org.custommonkey.xmlunit.XMLUnit;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
Expand All @@ -78,6 +80,7 @@

@SuppressWarnings("FieldCanBeLocal")
public class WfsFilterDelegateTest {
private static final Logger LOGGER = LoggerFactory.getLogger(WfsFilterDelegateTest.class);

private static final JAXBContext JAXB_CONTEXT = initJaxbContext();

Expand Down Expand Up @@ -110,11 +113,9 @@ public class WfsFilterDelegateTest {

private static final String NO_OP = "NoOp";

private final Date date = getDate();

private final Date endDate = getEndDate();
private Date date;

private static final Logger LOGGER = LoggerFactory.getLogger(WfsFilterDelegateTest.class);
private Date endDate;

private static final String FILTER_QNAME_LOCAL_PART = "Filter";

Expand Down Expand Up @@ -179,7 +180,7 @@ public class WfsFilterDelegateTest {
+ "</PropertyIsNotEqualTo>"
+ "</Filter>";

private String propertyIsEqualToXmlDate = getPropertyEqualToXmlDate();
private String propertyIsEqualToXmlDate;

private final String propertyNotEqualToXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Filter xmlns:ns2=\"http://www.opengis.net/gml\" xmlns=\"http://www.opengis.net/ogc\" xmlns:ns3=\"http://www.w3.org/1999/xlink\">"
Expand All @@ -197,7 +198,7 @@ public class WfsFilterDelegateTest {
+ "</PropertyIsNotEqualTo>"
+ "</Filter>";

private final String propertyNotEqualToXmlDate = getPropertyNotEqualToXmlDate();
private String propertyNotEqualToXmlDate;

private final String propertyNotEqualToXmlBoolean =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
Expand Down Expand Up @@ -233,7 +234,7 @@ public class WfsFilterDelegateTest {
+ "</PropertyIsGreaterThan>"
+ "</Filter>";

private final String propertyGreaterThanXmlDate = getPropertyGreaterThanXmlDate();
private String propertyGreaterThanXmlDate;

private final String propertyGreaterThanOrEqualToXmlLiteral =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
Expand All @@ -260,8 +261,7 @@ public class WfsFilterDelegateTest {
+ "</PropertyIsGreaterThanOrEqualTo>"
+ "</Filter>";

private final String propertyGreaterThanOrEqualToXmlDate =
getPropertyGreaterThanOrEqualToXmlDate();
private String propertyGreaterThanOrEqualToXmlDate;

private final String propertyLessThanXmlLiteral =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
Expand All @@ -288,7 +288,7 @@ public class WfsFilterDelegateTest {
+ "</PropertyIsLessThan>"
+ "</Filter>";

private final String propertyLessThanXmlDate = getPropertyLessThanXmlDate();
private String propertyLessThanXmlDate;

private final String propertyLessThanOrEqualToXmlLiteral =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
Expand All @@ -315,7 +315,7 @@ public class WfsFilterDelegateTest {
+ "</PropertyIsLessThanOrEqualTo>"
+ "</Filter>";

private final String propertyLessThanOrEqualToXmlDate = getPropertyLessThanOrEqualToXmlDate();
private String propertyLessThanOrEqualToXmlDate;

private final String propertyIsLikeXmlLiteral =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
Expand Down Expand Up @@ -404,12 +404,26 @@ public class WfsFilterDelegateTest {
+ "</PropertyIsBetween>"
+ "</Filter>";

private final String propertyBetweenXmlDate = getPropertyBetweenXmlDate();
private String propertyBetweenXmlDate;

private FeatureMetacardType featureMetacardType = mock(FeatureMetacardType.class);

private MetacardMapper metacardMapper = mock(MetacardMapper.class);

@Before
public void setup() {
// init date
date = getDate();
endDate = getEndDate();
propertyIsEqualToXmlDate = getPropertyEqualToXmlDate();
propertyNotEqualToXmlDate = getPropertyNotEqualToXmlDate();
propertyGreaterThanXmlDate = getPropertyGreaterThanXmlDate();
propertyGreaterThanOrEqualToXmlDate = getPropertyGreaterThanOrEqualToXmlDate();
propertyLessThanXmlDate = getPropertyLessThanXmlDate();
propertyLessThanOrEqualToXmlDate = getPropertyLessThanOrEqualToXmlDate();
propertyBetweenXmlDate = getPropertyBetweenXmlDate();
}

@Test(expected = IllegalArgumentException.class)
public void testWfsFilterDelegateNullFeatureMetacardType() {
new WfsFilterDelegate(
Expand Down Expand Up @@ -661,9 +675,7 @@ public void testPropertyIsNotEqualToStringMatchCase()
@Test
public void testPropertyIsNotEqualToDate() throws JAXBException, SAXException, IOException {
WfsFilterDelegate delegate = createSinglePropertyDelegate();

FilterType filter = delegate.propertyIsNotEqualTo(MOCK_PROPERTY, date);

assertXMLEqual(propertyNotEqualToXmlDate, marshal(filter));
}

Expand Down Expand Up @@ -1580,7 +1592,7 @@ public void testIntersectsMultipleProperties() {
public void testAllGmlPropertiesBlacklisted() {
whenGeom(MOCK_GEOM, MOCK_GEOM2, false, false);

List<String> supportedGeo = Collections.singletonList(SPATIAL_OPERATORS.INTERSECTS.getValue());
List<String> supportedGeo = singletonList(SPATIAL_OPERATORS.INTERSECTS.getValue());
WfsFilterDelegate delegate =
new WfsFilterDelegate(
featureMetacardType,
Expand Down Expand Up @@ -2036,32 +2048,38 @@ private static JAXBContext initJaxbContext() {
return jaxbContext;
}

private Date getDate() {
String dateString = "Jun 11 2002";
SimpleDateFormat formatter = new SimpleDateFormat("MMM d yyyy");
Date date = null;
try {
date = formatter.parse(dateString);
} catch (ParseException e) {
LOGGER.error(e.getMessage(), e);
}
return date;
private static Date getEndDate() {
final String JUN_11_2002 = "Jun 11 2002";

return getDate(JUN_11_2002);
}

private Date getEndDate() {
String dateString = "Jul 11 2002";
SimpleDateFormat formatter = new SimpleDateFormat("MMM d yyyy");
private static Date getDate() {
final String JUN_11_2002 = "Jun 11 2002";

return getDate(JUN_11_2002);
}

private static @Nullable Date getDate(String dateString) {
// Define the formatter for the input pattern
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("MMM dd yyyy", java.util.Locale.ENGLISH);

Date date = null;
// Parse the input date-time with MST, then convert to America/Denver to ensure that
// region-specific rules are applied correctly when parsing
LocalDate localDate;
try {
date = formatter.parse(dateString);
} catch (ParseException e) {
localDate = LocalDate.parse(dateString, formatter);
date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return date;
}

private DateTime convertDateToIso8601Format(Date inputDate) {
return new DateTime(inputDate, DateTimeZone.UTC);
private String convertDateToIso8601Format(Date inputDate) {
return new DateTime(inputDate, DateTimeZone.UTC).toString();
}

private String getPropertyEqualToXmlDate() {
Expand Down Expand Up @@ -2212,7 +2230,7 @@ private WfsFilterDelegate setupFilterDelegate(
when(featureMetacardType.getGmlProperties()).thenReturn(gmlProps);
when(featureMetacardType.isQueryable(MOCK_GEOM)).thenReturn(true);

List<String> supportedGeo = Collections.singletonList(spatialOpType);
List<String> supportedGeo = singletonList(spatialOpType);
return new WfsFilterDelegate(
featureMetacardType,
metacardMapper,
Expand Down
Loading