Search in sources :

Example 1 with FilterFactory

use of org.opengis.filter.FilterFactory in project ddf by codice.

the class OpenSearchQueryTest method testOgcFilterEvaluateContextualLike.

@Test
@Ignore
public void testOgcFilterEvaluateContextualLike() throws Exception {
    // String input = "abc_cat_dog_xyz";
    String input = "<ns1:thing xmlns:ns1=\"http://ddf.codice.org/mynamespace\">cat</ns1:thing>";
    // String searchTerm = "cat";
    // List<Filter> filters = new ArrayList<Filter>();
    FilterFactory filterFactory = new FilterFactoryImpl();
    // Filter filter = filterFactory.like( filterFactory.property( "AnyText" ), searchTerm );
    // Filter filter = filterFactory.equal( filterFactory.property( "thing" ),
    // filterFactory.literal( searchTerm ), false );
    // Filter filter = filterFactory.like( filterFactory.property( Query.ANY_TEXT ), searchTerm,
    // "*", "?", "\\" );
    // Filter filter = filterFactory.equal( filterFactory.property( Query.ANY_TEXT ),
    // searchTerm, false );
    // Filter filter = filterFactory.like( filterFactory.property( Query.ANY_TEXT ), searchTerm,
    // "*", "?", "\\" );
    Calendar.getInstance().getTime();
    String startDate = "2011-10-8T05:48:27.891-07:00";
    String endDate = "2011-10-10T06:18:27.581-07:00";
    TemporalFilter temporalFilter = new TemporalFilter(startDate, endDate);
    // WORKS Filter filter = filterFactory.between( filterFactory.literal( new Date() ),
    // filterFactory.literal( temporalFilter.getStartDate() ), filterFactory.literal(
    // temporalFilter.getEndDate() ) );
    Filter filter = filterFactory.between(filterFactory.literal(new Date()), filterFactory.literal(temporalFilter.getStartDate()), filterFactory.literal(temporalFilter.getEndDate()));
    FilterTransformer transform = new FilterTransformer();
    transform.setIndentation(2);
    LOGGER.debug(transform.transform(filter));
    // VisualizingVisitor vv = new VisualizingVisitor() ;
    // filter.accept(vv, null) ;
    // vv.getMap();
    boolean result = filter.evaluate(input);
    LOGGER.debug("result = {}", result);
// filters.add( filter );
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Date(java.util.Date) FilterTransformer(org.geotools.filter.FilterTransformer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with FilterFactory

use of org.opengis.filter.FilterFactory in project ddf by codice.

the class TestPubSubOgcFilter method testContextualFeatureEvaluate.

@Test
@Ignore
public void testContextualFeatureEvaluate() throws TransformerException {
    SimpleFeature feature = generateSampleFeature();
    FilterFactory filterFactory = new FilterFactoryImpl();
    PropertyIsEqualTo filter = filterFactory.equal(filterFactory.property("name"), filterFactory.literal("FirstFeature"), true);
    printFilter(filter);
    assertTrue(filter.evaluate(feature));
}
Also used : PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with FilterFactory

use of org.opengis.filter.FilterFactory in project ddf by codice.

the class TestCswSource method testAbsoluteTemporalSearchTwoRanges.

@Test
public void testAbsoluteTemporalSearchTwoRanges() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
    // Setup
    String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n" + "<GetRecords resultType=\"results\" outputFormat=\"application/xml\"\r\n" + "    outputSchema=\"http://www.opengis.net/cat/csw/2.0.2\" startPosition=\"1\"\r\n" + "    maxRecords=\"10\" service=\"CSW\" version=\"2.0.2\"" + "    xmlns=\"http://www.opengis.net/cat/csw/2.0.2\"" + "    xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\"" + "    xmlns:ogc=\"http://www.opengis.net/ogc\">\r\n" + "    <Query typeNames=\"csw:Record\">\r\n" + "        <ElementSetName>full</ElementSetName>\r\n" + "        <Constraint version=\"1.1.0\">\r\n" + "            <ogc:Filter>\r\n" + "                <ogc:Or>\r\n" + "                    <ogc:PropertyIsBetween>\r\n" + "                        <ogc:PropertyName>effective</ogc:PropertyName>\r\n" + "                        <ogc:LowerBoundary>\r\n" + "                            <ogc:Literal>START1_DATE_TIME</ogc:Literal>\r\n" + "                        </ogc:LowerBoundary>\r\n" + "                        <ogc:UpperBoundary>\r\n" + "                            <ogc:Literal>END1_DATE_TIME</ogc:Literal>\r\n" + "                        </ogc:UpperBoundary>\r\n" + "                    </ogc:PropertyIsBetween>\r\n" + "                    <ogc:PropertyIsBetween>\r\n" + "                        <ogc:PropertyName>effective</ogc:PropertyName>\r\n" + "                        <ogc:LowerBoundary>\r\n" + "                            <ogc:Literal>START2_DATE_TIME</ogc:Literal>\r\n" + "                        </ogc:LowerBoundary>\r\n" + "                        <ogc:UpperBoundary>\r\n" + "                            <ogc:Literal>END2_DATE_TIME</ogc:Literal>\r\n" + "                        </ogc:UpperBoundary>\r\n" + "                    </ogc:PropertyIsBetween>\r\n" + "                </ogc:Or>\r\n" + "            </ogc:Filter>\r\n" + "        </Constraint>\r\n" + "    </Query>\r\n" + "</GetRecords>\r\n";
    final int pageSize = 10;
    final int numRecordsReturned = 1;
    final long numRecordsMatched = 10;
    setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
    try {
        configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
    } catch (CswException e) {
        fail("Could not configure Mock Remote CSW: " + e.getMessage());
    }
    DateTime startDate = new DateTime(2012, 5, 1, 0, 0, 0, 0);
    DateTime endDate = new DateTime(2012, 12, 31, 0, 0, 0, 0);
    DateTime startDate2 = new DateTime(2013, 5, 1, 0, 0, 0, 0);
    DateTime endDate2 = new DateTime(2013, 12, 31, 0, 0, 0, 0);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    // Load the expected start and end date time into the excepted result
    // XML
    expectedXml = expectedXml.replace("START1_DATE_TIME", fmt.print(startDate));
    expectedXml = expectedXml.replace("END1_DATE_TIME", fmt.print(endDate));
    expectedXml = expectedXml.replace("START2_DATE_TIME", fmt.print(startDate2));
    expectedXml = expectedXml.replace("END2_DATE_TIME", fmt.print(endDate2));
    // Single absolute time range to search across
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter temporalFilter1 = builder.attribute(Metacard.EFFECTIVE).is().during().dates(startDate.toDate(), endDate.toDate());
    Filter temporalFilter2 = builder.attribute(Metacard.EFFECTIVE).is().during().dates(startDate2.toDate(), endDate2.toDate());
    Filter temporalFilter = filterFactory.or(temporalFilter1, temporalFilter2);
    QueryImpl temporalQuery = new QueryImpl(temporalFilter);
    temporalQuery.setPageSize(pageSize);
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    cswSource.query(new QueryRequestImpl(temporalQuery));
    // Verify
    ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
    try {
        verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
    } catch (CswException e) {
        fail("Could not verify Mock CSW record count " + e.getMessage());
    }
    GetRecordsType getRecordsType = captor.getValue();
    String xml = getGetRecordsTypeAsXml(getRecordsType);
    Diff xmlDiff = new Diff(expectedXml, xml);
    if (!xmlDiff.similar()) {
        LOGGER.error("Unexpected XML request sent");
        LOGGER.error("Expected: {}", expectedXml);
        LOGGER.error("Actual: {}", xml);
    }
    assertXMLEqual(expectedXml, xml);
}
Also used : Diff(org.custommonkey.xmlunit.Diff) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) DateTime(org.joda.time.DateTime) FilterFactory(org.opengis.filter.FilterFactory) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 4 with FilterFactory

use of org.opengis.filter.FilterFactory in project ddf by codice.

the class TestQueryImpl method setUp.

/**
     * Create the filter2 one time to use for all of the tests
     */
@BeforeClass
public static void setUp() {
    FilterFactory filterFactory = new FilterFactoryImpl();
    // Dummy filter copied from another test
    filter1 = filterFactory.like(filterFactory.property(Metacard.METADATA), "million", DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, "^", false);
    filter2 = filterFactory.like(filterFactory.property(Metacard.METADATA), "zillion", DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, "^", false);
}
Also used : FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) BeforeClass(org.junit.BeforeClass)

Example 5 with FilterFactory

use of org.opengis.filter.FilterFactory in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalizeBlueTest method createChannelSelection.

/**
 * Creates the channel selection object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelection(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("StretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1"));
    options.put("maxValue", ff.literal("5"));
    SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
Also used : SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) Expression(org.opengis.filter.expression.Expression) ChannelSelection(org.geotools.styling.ChannelSelection) FilterFactory(org.opengis.filter.FilterFactory)

Aggregations

FilterFactory (org.opengis.filter.FilterFactory)88 Test (org.junit.Test)72 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)42 Filter (org.opengis.filter.Filter)38 QueryImpl (ddf.catalog.operation.impl.QueryImpl)33 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)30 Expression (org.opengis.filter.expression.Expression)24 SourceResponse (ddf.catalog.operation.SourceResponse)21 ArrayList (java.util.ArrayList)18 Metacard (ddf.catalog.data.Metacard)17 SolrProviderTest (ddf.catalog.source.solr.SolrProviderTest)17 ContrastEnhancement (org.geotools.styling.ContrastEnhancement)12 SelectedChannelType (org.geotools.styling.SelectedChannelType)12 Date (java.util.Date)11 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)11 ChannelSelection (org.geotools.styling.ChannelSelection)10 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)8 Result (ddf.catalog.data.Result)8 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 QueryResponse (ddf.catalog.operation.QueryResponse)8