Search in sources :

Example 1 with And

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

the class TestWorkspaceQueryService method testRun.

@SuppressWarnings("unchecked")
@Test
public void testRun() throws SchedulerException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    String workspaceId = "3";
    QueryUpdateSubscriber queryUpdateSubscriber = mock(QueryUpdateSubscriber.class);
    WorkspaceService workspaceService = mock(WorkspaceService.class);
    CatalogFramework catalogFramework = mock(CatalogFramework.class);
    FilterBuilder filterBuilder = mock(FilterBuilder.class);
    Scheduler scheduler = mock(Scheduler.class);
    when(scheduler.getContext()).thenReturn(mock(SchedulerContext.class));
    Supplier<Optional<Scheduler>> schedulerSupplier = () -> Optional.of(scheduler);
    SecurityService securityService = new SecurityService() {

        @Override
        public Subject getSystemSubject() {
            return mock(Subject.class);
        }

        @Override
        public Map<String, Serializable> addSystemSubject(Map<String, Serializable> properties) {
            return properties;
        }
    };
    FilterService filterService = mock(FilterService.class);
    when(filterService.getModifiedDateFilter(any())).thenReturn(mock(Filter.class));
    when(filterBuilder.anyOf(Mockito.any(Filter.class))).thenReturn(mock(Or.class));
    when(filterBuilder.allOf(Mockito.<Filter>anyVararg())).thenReturn(mock(And.class));
    WorkspaceQueryServiceImpl workspaceQueryServiceImpl = new WorkspaceQueryServiceImpl(queryUpdateSubscriber, workspaceService, catalogFramework, filterBuilder, schedulerSupplier, securityService, filterService);
    workspaceQueryServiceImpl.setQueryTimeInterval(60);
    String ecql = "area( Polygon((10 10, 20 10, 20 20, 10 10)) ) BETWEEN 10000 AND 30000";
    WorkspaceMetacardImpl workspaceMetacard = mock(WorkspaceMetacardImpl.class);
    when(workspaceMetacard.getId()).thenReturn(workspaceId);
    QueryMetacardImpl queryMetacardWithSource = mock(QueryMetacardImpl.class);
    when(queryMetacardWithSource.getSources()).thenReturn(Collections.singletonList("SomeSource"));
    when(queryMetacardWithSource.getCql()).thenReturn(ecql);
    Attribute id1 = mock(Attribute.class);
    when(id1.getValue()).thenReturn("1");
    when(queryMetacardWithSource.getAttribute(Metacard.ID)).thenReturn(id1);
    QueryMetacardImpl queryMetacardWithoutSource = mock(QueryMetacardImpl.class);
    when(queryMetacardWithoutSource.getSources()).thenReturn(Collections.emptyList());
    when(queryMetacardWithoutSource.getCql()).thenReturn(ecql);
    Attribute id2 = mock(Attribute.class);
    when(id2.getValue()).thenReturn("2");
    when(queryMetacardWithoutSource.getAttribute(Metacard.ID)).thenReturn(id2);
    Map<String, Pair<WorkspaceMetacardImpl, List<QueryMetacardImpl>>> queryMetacards = Collections.singletonMap(id2.getValue().toString(), new ImmutablePair<>(workspaceMetacard, Arrays.asList(queryMetacardWithSource, queryMetacardWithoutSource)));
    when(workspaceService.getQueryMetacards()).thenReturn(queryMetacards);
    long hitCount1 = 10;
    long hitCount2 = 20;
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getHits()).thenReturn(hitCount1).thenReturn(hitCount2);
    when(catalogFramework.query(any())).thenReturn(queryResponse);
    workspaceQueryServiceImpl.setSubject(new Subject() {

        @Override
        public boolean isGuest() {
            return false;
        }

        @Override
        public Object getPrincipal() {
            return null;
        }

        @Override
        public PrincipalCollection getPrincipals() {
            return null;
        }

        @Override
        public boolean isPermitted(String s) {
            return false;
        }

        @Override
        public boolean isPermitted(Permission permission) {
            return false;
        }

        @Override
        public boolean[] isPermitted(String... strings) {
            return new boolean[0];
        }

        @Override
        public boolean[] isPermitted(List<Permission> list) {
            return new boolean[0];
        }

        @Override
        public boolean isPermittedAll(String... strings) {
            return false;
        }

        @Override
        public boolean isPermittedAll(Collection<Permission> collection) {
            return false;
        }

        @Override
        public void checkPermission(String s) throws AuthorizationException {
        }

        @Override
        public void checkPermission(Permission permission) throws AuthorizationException {
        }

        @Override
        public void checkPermissions(String... strings) throws AuthorizationException {
        }

        @Override
        public void checkPermissions(Collection<Permission> collection) throws AuthorizationException {
        }

        @Override
        public boolean hasRole(String s) {
            return false;
        }

        @Override
        public boolean[] hasRoles(List<String> list) {
            return new boolean[0];
        }

        @Override
        public boolean hasAllRoles(Collection<String> collection) {
            return false;
        }

        @Override
        public void checkRole(String s) throws AuthorizationException {
        }

        @Override
        public void checkRoles(Collection<String> collection) throws AuthorizationException {
        }

        @Override
        public void checkRoles(String... strings) throws AuthorizationException {
        }

        @Override
        public void login(AuthenticationToken authenticationToken) throws AuthenticationException {
        }

        @Override
        public boolean isAuthenticated() {
            return false;
        }

        @Override
        public boolean isRemembered() {
            return false;
        }

        @Override
        public Session getSession() {
            return null;
        }

        @Override
        public Session getSession(boolean b) {
            return null;
        }

        @Override
        public void logout() {
        }

        @Override
        public <V> V execute(Callable<V> callable) throws ExecutionException {
            try {
                return callable.call();
            } catch (Exception e) {
                throw new ExecutionException(e);
            }
        }

        @Override
        public void execute(Runnable runnable) {
        }

        @Override
        public <V> Callable<V> associateWith(Callable<V> callable) {
            return null;
        }

        @Override
        public Runnable associateWith(Runnable runnable) {
            return null;
        }

        @Override
        public void runAs(PrincipalCollection principalCollection) throws NullPointerException, IllegalStateException {
        }

        @Override
        public boolean isRunAs() {
            return false;
        }

        @Override
        public PrincipalCollection getPreviousPrincipals() {
            return null;
        }

        @Override
        public PrincipalCollection releaseRunAs() {
            return null;
        }
    });
    workspaceQueryServiceImpl.setCronString("0 0 0 * * ?");
    workspaceQueryServiceImpl.setQueryTimeoutMinutes(5L);
    workspaceQueryServiceImpl.run();
    ArgumentCaptor<Map> argumentCaptor = ArgumentCaptor.forClass(Map.class);
    verify(queryUpdateSubscriber).notify(argumentCaptor.capture());
    Map queryUpdateSubscriberArgumentRaw = argumentCaptor.getValue();
    Map<String, Pair<WorkspaceMetacardImpl, Long>> queryUpdateSubscriberArgument = (Map<String, Pair<WorkspaceMetacardImpl, Long>>) queryUpdateSubscriberArgumentRaw;
    assertThat(queryUpdateSubscriberArgument.get(workspaceId).getRight(), is(hitCount1 + hitCount2));
}
Also used : Serializable(java.io.Serializable) Or(org.opengis.filter.Or) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) AuthorizationException(org.apache.shiro.authz.AuthorizationException) AuthenticationException(org.apache.shiro.authc.AuthenticationException) QueryMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.QueryMetacardImpl) CatalogFramework(ddf.catalog.CatalogFramework) SchedulerContext(org.quartz.SchedulerContext) Permission(org.apache.shiro.authz.Permission) Optional(java.util.Optional) WorkspaceService(org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceService) And(org.opengis.filter.And) QueryUpdateSubscriber(org.codice.ddf.catalog.ui.query.monitor.api.QueryUpdateSubscriber) Map(java.util.Map) Attribute(ddf.catalog.data.Attribute) Scheduler(org.quartz.Scheduler) FilterService(org.codice.ddf.catalog.ui.query.monitor.api.FilterService) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) Callable(java.util.concurrent.Callable) FilterBuilder(ddf.catalog.filter.FilterBuilder) SecurityService(org.codice.ddf.catalog.ui.query.monitor.api.SecurityService) ExecutionException(org.apache.shiro.subject.ExecutionException) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Subject(ddf.security.Subject) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SchedulerException(org.quartz.SchedulerException) FederationException(ddf.catalog.federation.FederationException) AuthorizationException(org.apache.shiro.authz.AuthorizationException) ExecutionException(org.apache.shiro.subject.ExecutionException) AuthenticationException(org.apache.shiro.authc.AuthenticationException) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Session(org.apache.shiro.session.Session) Test(org.junit.Test)

Example 2 with And

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

the class TestWorkspaceServiceImpl method testGetWorkspaceMetacardsByWorkspaceId.

@Test
public void testGetWorkspaceMetacardsByWorkspaceId() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    String id = "123";
    String subject = "subject";
    mockCatalogFrameworkQuery(id, subject);
    Filter workspaceTagFilter = mockWorkspaceTagFilter();
    Filter metacardIdFilter = mock(Filter.class);
    when(filterService.buildMetacardIdFilter(id)).thenReturn(metacardIdFilter);
    And andFilter = mock(And.class);
    when(filterBuilder.allOf(metacardIdFilter, workspaceTagFilter)).thenReturn(andFilter);
    Or orFilter = mock(Or.class);
    when(filterBuilder.anyOf(Collections.singletonList(andFilter))).thenReturn(orFilter);
    List<WorkspaceMetacardImpl> workspaceMetacards = workspaceService.getWorkspaceMetacards(Collections.singleton(id));
    assertMetacardList(id, subject, workspaceMetacards);
}
Also used : Or(org.opengis.filter.Or) WorkspaceMetacardFilter(org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceMetacardFilter) Filter(org.opengis.filter.Filter) And(org.opengis.filter.And) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 3 with And

use of org.opengis.filter.And in project polymap4-core by Polymap4.

the class NumberGradient2FilterEditor method initValues.

protected void initValues() {
    annotation = (NumberRange) prop.info().getAnnotation(NumberRange.class);
    df = NumberFormat.getInstance(Polymap.getSessionLocale());
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(0);
    List<Mapped<Filter, N>> values = prop.get().values();
    // defaults
    if (values.isEmpty()) {
        minimumValue = annotation.from();
        maximumValue = annotation.to();
        breakpoints = 10;
    } else // from prop
    {
        And first = (And) values.get(0).key();
        BinaryComparisonOperator lessThan = (BinaryComparisonOperator) first.getChildren().get(0);
        propertyName = ((PropertyName) lessThan.getExpression1()).getPropertyName();
        String value = (String) ((Literal) lessThan.getExpression2()).getValue();
        lowerBound = Double.parseDouble(value);
        And last = (And) values.get(values.size() - 1).key();
        BinaryComparisonOperator greaterThan = (BinaryComparisonOperator) last.getChildren().get(0);
        value = (String) ((Literal) greaterThan.getExpression2()).getValue();
        upperBound = Double.parseDouble(value);
        minimumValue = values.get(0).value().doubleValue();
        maximumValue = values.get(values.size() - 1).value().doubleValue();
        breakpoints = values.size() + 1;
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) And(org.opengis.filter.And) Literal(org.opengis.filter.expression.Literal) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator)

Example 4 with And

use of org.opengis.filter.And in project polymap4-core by Polymap4.

the class ColorGradient2FilterEditor method initValues.

protected void initValues() {
    List<Mapped<Filter, java.awt.Color>> values = prop.get().values();
    df = NumberFormat.getInstance(Polymap.getSessionLocale());
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(0);
    // defaults
    if (values.isEmpty()) {
        minimumValue = Color.LIGHT_GRAY;
        maximumValue = Color.BLACK;
        breakpoints = 10;
    } else // from prop
    {
        And first = (And) values.get(0).key();
        BinaryComparisonOperator lessThan = (BinaryComparisonOperator) first.getChildren().get(0);
        propertyName = ((PropertyName) lessThan.getExpression1()).getPropertyName();
        String value = (String) ((Literal) lessThan.getExpression2()).getValue();
        lowerBound = Double.parseDouble(value);
        And last = (And) values.get(values.size() - 1).key();
        BinaryComparisonOperator greaterThan = (BinaryComparisonOperator) last.getChildren().get(0);
        value = (String) ((Literal) greaterThan.getExpression2()).getValue();
        upperBound = Double.parseDouble(value);
        // minimumValue = values.get( 0 ).value().doubleValue();
        // maximumValue = values.get( values.size() - 1 ).value().doubleValue();
        breakpoints = values.size() + 1;
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) And(org.opengis.filter.And) Literal(org.opengis.filter.expression.Literal) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator)

Example 5 with And

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

the class OpenSearchFilterVisitorTest method testMultipleFiltersWhereOneFilterIsIgnored.

/**
 * Test that other {@link Filter}s are still visited when a {@link Filter} is ignored. The {@link
 * Filter}s in this test are the same as {@link #testMultipleFilters} except that the temporal
 * criteria is from {@link #testNotModifiedTemporalFilter()}.
 */
@Test
public void testMultipleFiltersWhereOneFilterIsIgnored() {
    During duringFilter = (During) geotoolsFilterBuilder.attribute(SOME_ATTRIBUTE_NAME).during().dates(START_DATE, END_DATE);
    Contains containsFilter = (Contains) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).containing().wkt(WKT_POLYGON);
    And andFilter = geotoolsFilterBuilder.allOf(duringFilter, containsFilter);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    openSearchFilterVisitorObject.setCurrentNest(NestedTypes.AND);
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(andFilter, openSearchFilterVisitorObject);
    assertThat(result.getTemporalSearch(), is(nullValue()));
    assertThat(result.getGeometrySearches(), contains(hasToString(is(WKT_POLYGON))));
}
Also used : And(org.opengis.filter.And) Contains(org.opengis.filter.spatial.Contains) During(org.opengis.filter.temporal.During) Test(org.junit.Test)

Aggregations

And (org.opengis.filter.And)9 Test (org.junit.Test)7 Filter (org.opengis.filter.Filter)5 WorkspaceMetacardImpl (org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl)3 Or (org.opengis.filter.Or)3 QueryResponse (ddf.catalog.operation.QueryResponse)2 WorkspaceMetacardFilter (org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceMetacardFilter)2 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)2 Literal (org.opengis.filter.expression.Literal)2 Mapped (org.polymap.core.style.model.feature.MappedValues.Mapped)2 CatalogFramework (ddf.catalog.CatalogFramework)1 Attribute (ddf.catalog.data.Attribute)1 FederationException (ddf.catalog.federation.FederationException)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 Subject (ddf.security.Subject)1