Package org.geotools.filter

Examples of org.geotools.filter.SortByImpl


        final Query query = new Query(typeName);
       
        final PropertyName propertyName = FeatureUtilities.DEFAULT_FILTER_FACTORY.property(attribute);
        query.setPropertyNames(Arrays.asList(attribute, secondAttribute));
       
        final SortByImpl[] sb = new SortByImpl[]{new SortByImpl(propertyName, SortOrder.ASCENDING)};
        // Checking whether it supports sorting capabilities
        if(granuleCatalog.getQueryCapabilities(typeName).supportsSorting(sb)){
            query.setSortBy(sb);
        }
       
View Full Code Here


                        if (expr != null) {
                            FilterAttributeExtractor extractor = new FilterAttributeExtractor();
                            expr.accept(extractor, null);
       
                            for (String att : extractor.getAttributeNameSet()) {
                                sort.add(new SortByImpl(filterFac.property(att), sortBy.getSortOrder()));
                            }
                        }
                    } 
                }
            }

            if (query instanceof JoiningQuery) {
                FilterAttributeExtractor extractor = new FilterAttributeExtractor();
                mapping.getFeatureIdExpression().accept(extractor, null);
               
                if (!Expression.NIL.equals(mapping.getFeatureIdExpression())
                        && !(mapping.getFeatureIdExpression() instanceof Literal)
                        && extractor.getAttributeNameSet().isEmpty()) {
                    // GEOS-5618: getID() and functions in idExpression aren't supported with joining
                    String ns = mapping.namespaces.getPrefix(mapping.getTargetFeature().getName()
                            .getNamespaceURI());
                    String separator = mapping.getTargetFeature().getName().getSeparator();
                    String typeName = mapping.getTargetFeature().getLocalName();
                    throw new UnsupportedOperationException(
                            String.format(
                                    "idExpression '%s' for targetElement '%s%s%s' cannot be translated into SQL, "
                                            + "therefore is not supported with joining!"
                                            + "\nPlease make sure idExpression is mapped into existing database fields, "
                                            + "and only use functions that are supported by your database."
                                            + "\nIf this cannot be helped, you can turn off joining in app-schema.properties file.",
                                    mapping.getFeatureIdExpression(), ns, separator, typeName));
                }
               
                JoiningQuery jQuery = new JoiningQuery(newQuery);
                jQuery.setDenormalised(((JoiningQuery) query).isDenormalised());
                jQuery.setQueryJoins(((JoiningQuery) query).getQueryJoins());
                jQuery.setSubset(((JoiningQuery) query).isSubset());

                for (String att : extractor.getAttributeNameSet()) {
                    sort.add(new SortByImpl(filterFac.property(att), SortOrder.ASCENDING));
                    jQuery.addId(att);
                }

               
                unrolledQuery = jQuery;
View Full Code Here

                        // which clause?
                        // ASCENDING
                        element = element.trim();
                        if (element.endsWith(Utils.ASCENDING_ORDER_IDENTIFIER)) {
                            String attribute = element.substring(0, element.length() - 2);
                            clauses.add(new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property(attribute), SortOrder.ASCENDING));
                            LOGGER.fine("Added clause ASCENDING on attribute:" + attribute);
                        } else
                        // DESCENDING
                        if (element.contains(Utils.DESCENDING_ORDER_IDENTIFIER)) {
                            String attribute = element.substring(0, element.length() - 2);
                            clauses.add(new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property(attribute), SortOrder.DESCENDING));
                            LOGGER.fine("Added clause DESCENDING on attribute:" + attribute);
                        } else {
                            LOGGER.fine("Ignoring sort clause :" + element);
                        }
                    } catch (Exception e) {
View Full Code Here

            };

            SortOrder so = SortOrder.valueOf("CAT_ID");
            assertEquals(pureShapefile, fs.getQueryCapabilities().supportsSorting(
                    new SortBy[] { new SortByImpl(propertyName, so) }));

            ds.dispose();

        } catch (Exception ex) {
            Assert.fail(ex.getMessage());
View Full Code Here

        UniqueVisitor v = new MyUniqueVisitor(p);
        v.setPreserveOrder(true);
        v.setStartIndex(0);
        v.setMaxFeatures(2);
        Query q = new Query( tname("ft1"));
        q.setSortBy(new SortBy[] { new SortByImpl(p, SortOrder.ASCENDING)});
        dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
        assertFalse(visited);
        Set result = v.getResult().toSet();
        assertEquals(2, result.size());
        assertEquals("one", result.iterator().next());
View Full Code Here

        UniqueVisitor v = new MyUniqueVisitor(p);
        v.setPreserveOrder(true);
        v.setStartIndex(1);
        v.setMaxFeatures(2);
        Query q = new Query( tname("ft1"));
        q.setSortBy(new SortBy[] { new SortByImpl(p, SortOrder.ASCENDING)});
        dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
        assertFalse(visited);
        Set result = v.getResult().toSet();
        assertEquals(2, result.size());
        assertEquals("two", result.iterator().next());
View Full Code Here

            // max number of elements
            query.setMaxFeatures(1);
           
            // sorting
            final SortBy[] clauses=new SortBy[]{
                new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("ingestion"),SortOrder.DESCENDING),
                new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("elevation"),SortOrder.ASCENDING),
            };
            query.setSortBy(clauses);
     
    }
   
    // checking that we get a single feature and that feature is correct
    final Collection<GranuleDescriptor> features = new ArrayList<GranuleDescriptor>();
    rasterManager.getGranuleDescriptors(query, new GranuleCatalogVisitor() {
                   
                    @Override
                    public void visit(GranuleDescriptor granule, Object o) {
                        features.add(granule);
                       
                    }
                });
    assertEquals(features.size(), 1);
    GranuleDescriptor granule=features.iterator().next();
    SimpleFeature sf=granule.getOriginator();
    assertNotNull(sf);
    Object ingestion = sf.getAttribute("ingestion");
    assertTrue(ingestion instanceof Timestamp);
    final GregorianCalendar gc=  new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    gc.setTimeInMillis(1225497600000l);
    assertEquals(0,(((Timestamp)ingestion).compareTo(gc.getTime())));   
    Object elevation = sf.getAttribute("elevation");
    assertTrue(elevation instanceof Integer);
    assertEquals(((Integer)elevation).intValue(), 0);
   
   
   
    // Reverting order (the previous timestamp shouldn't match anymore)
    final SortBy[] clauses=new SortBy[]{
                          new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("ingestion"),SortOrder.ASCENDING),
                          new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("elevation"),SortOrder.DESCENDING),
              };
              query.setSortBy(clauses);
             
           // checking that we get a single feature and that feature is correct
                  features.clear();
View Full Code Here

     */
    private void sortBy(Query query, DimensionDescriptor timeDimension, DimensionDescriptor elevationDimension) {
        final List<SortBy> clauses = new ArrayList<SortBy>();
        // TODO: Check sortBy clause is supported
        if (timeDimension != null) {
            clauses.add(new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property(timeDimension.getStartAttribute()),
                    SortOrder.DESCENDING));
        }
        if (elevationDimension != null) {
            clauses.add(new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property(elevationDimension.getStartAttribute()),
                    SortOrder.ASCENDING));
        }
        final SortBy[] sb = clauses.toArray(new SortBy[] {});
        query.setSortBy(sb);
       
View Full Code Here

   
    @Test
    public void testSortAscend() throws IOException {
        Query queryImage = new Query("Record");
        queryImage.setFilter(FF.equals(FF.property("dc:type/dc:value", CSWRecordDescriptor.NAMESPACES), FF.literal("http://purl.org/dc/dcmitype/Image")));
        queryImage.setSortBy(new SortBy[] {new SortByImpl(FF.property("dc:title/dc:value", CSWRecordDescriptor.NAMESPACES), SortOrder.ASCENDING)});
       
        FeatureCollection records = store.getRecords(queryImage, Transaction.AUTO_COMMIT);
        // there are only 3 records with Image type
        assertEquals(3, records.size());
       
View Full Code Here

   
    @Test
    public void testSortDescend() throws IOException {
        Query queryImage = new Query("Record");
        queryImage.setFilter(FF.equals(FF.property("dc:type/dc:value", CSWRecordDescriptor.NAMESPACES), FF.literal("http://purl.org/dc/dcmitype/Image")));
        queryImage.setSortBy(new SortBy[] {new SortByImpl(FF.property("dc:title/dc:value", CSWRecordDescriptor.NAMESPACES), SortOrder.DESCENDING)});
       
        FeatureCollection records = store.getRecords(queryImage, Transaction.AUTO_COMMIT);
        // there are only 3 records with Image type
        assertEquals(3, records.size());
       
View Full Code Here

TOP

Related Classes of org.geotools.filter.SortByImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.