Skip to content

Commit

Permalink
REST for collection and its ogclinks, metadata, description
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Jun 20, 2017
1 parent fbaf104 commit b764980
Show file tree
Hide file tree
Showing 13 changed files with 553 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class LinkFeatureComparator implements Comparator<SimpleFeature> {

static final LinkFeatureComparator INSTANCE = new LinkFeatureComparator();
public static final LinkFeatureComparator INSTANCE = new LinkFeatureComparator();

private LinkFeatureComparator() {
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,11 @@ protected boolean hasOutputProperty(Query query, Name property, boolean included
return includedByDefault;
}

final String localPart = property.getLocalPart();
final String namespaceURI = property.getNamespaceURI();
for (PropertyName pn : query.getProperties()) {
if (property.getLocalPart().equals(pn.getPropertyName())
&& property.getNamespaceURI().equals(pn.getNamespaceContext().getURI(""))) {
if (localPart.equals(pn.getPropertyName())
&& namespaceURI.equals(pn.getNamespaceContext().getURI(""))) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public JDBCOpenSearchAccess(Repository repository, Name delegateStoreName, Strin
private FeatureType buildCollectionFeatureType(DataStore delegate) throws IOException {
SimpleFeatureType flatSchema = delegate.getSchema(COLLECTION);

TypeBuilder typeBuilder = new TypeBuilder(CommonFactoryFinder.getFeatureTypeFactory(null));
TypeBuilder typeBuilder = new OrderedTypeBuilder();

// map the source attributes
for (AttributeDescriptor ad : flatSchema.getAttributeDescriptors()) {
Expand Down Expand Up @@ -184,7 +184,7 @@ private AttributeDescriptor buildFeatureListDescriptor(Name name, SimpleFeatureT
private FeatureType buildProductFeatureType(DataStore delegate) throws IOException {
SimpleFeatureType flatSchema = delegate.getSchema(PRODUCT);

TypeBuilder typeBuilder = new TypeBuilder(CommonFactoryFinder.getFeatureTypeFactory(null));
TypeBuilder typeBuilder = new OrderedTypeBuilder();

// map the source attributes
AttributeTypeBuilder ab = new AttributeTypeBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* (c) 2017 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.opensearch.eo.store;

import java.util.Collection;
import java.util.LinkedHashSet;

import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.TypeBuilder;
import org.opengis.feature.type.FeatureTypeFactory;
import org.opengis.feature.type.PropertyDescriptor;

class OrderedTypeBuilder extends TypeBuilder {

static final FeatureTypeFactory TYPE_FACTORY = CommonFactoryFinder.getFeatureTypeFactory(null);

public OrderedTypeBuilder() {
super(TYPE_FACTORY);
}

@Override
protected Collection<PropertyDescriptor> newCollection() {
return new LinkedHashSet<PropertyDescriptor>();
}

}
34 changes: 18 additions & 16 deletions src/community/oseo/oseo-core/src/test/resources/oseo-rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,24 @@ paths:
description: Success
examples:
application/json: |
[
{
"offering": "http://www.opengis.net/spec/owc/1.0/req/atom/wms",
"method": "GET",
"code": "GetCapabilities",
"type": "application/xml",
"href": "${BASE_URL}/sentinel1/ows?service=wms&version=1.3.0&request=GetCapabilities"
},
{
"offering": "http://www.opengis.net/spec/owc/1.0/req/atom/wms",
"method": "GET",
"code": "GetMap",
"type": "image/jpeg",
"href": "${BASE_URL}/landsat8/LS8_RGB/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fjpeg&STYLES&LAYERS=landsat8%3ALS8_RGB&SRS=EPSG%3A4326&WIDTH=800&HEIGHT=600&BBOX=-180%2C-90%2C180%2C90"
}
]
{
links: [
{
"offering": "http://www.opengis.net/spec/owc/1.0/req/atom/wms",
"method": "GET",
"code": "GetCapabilities",
"type": "application/xml",
"href": "${BASE_URL}/sentinel1/ows?service=wms&version=1.3.0&request=GetCapabilities"
},
{
"offering": "http://www.opengis.net/spec/owc/1.0/req/atom/wms",
"method": "GET",
"code": "GetMap",
"type": "image/jpeg",
"href": "${BASE_URL}/landsat8/LS8_RGB/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fjpeg&STYLES&LAYERS=landsat8%3ALS8_RGB&SRS=EPSG%3A4326&WIDTH=800&HEIGHT=600&BBOX=-180%2C-90%2C180%2C90"
}
]
}
404:
description: The specified collection cannot be found
put:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,32 @@
package org.geoserver.opensearch.rest;

import java.io.IOException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.Consumer;

import org.geoserver.opensearch.eo.OpenSearchAccessProvider;
import org.geoserver.opensearch.eo.store.OpenSearchAccess;
import org.geoserver.opensearch.eo.store.OpenSearchAccess.ProductClass;
import org.geoserver.rest.RestBaseController;
import org.geoserver.rest.RestException;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.collection.BaseSimpleFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.opengis.feature.Feature;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.Name;
import org.opengis.feature.type.PropertyDescriptor;
import org.opengis.filter.FilterFactory2;
import org.springframework.http.HttpStatus;

/**
Expand All @@ -19,6 +40,10 @@
*/
public abstract class AbstractOpenSearchController extends RestBaseController {

static final String SOURCE_NAME = "SourceName";

static final FilterFactory2 FF = CommonFactoryFinder.getFilterFactory2();

protected OpenSearchAccessProvider accessProvider;

public AbstractOpenSearchController(OpenSearchAccessProvider accessProvider) {
Expand All @@ -28,18 +53,123 @@ public AbstractOpenSearchController(OpenSearchAccessProvider accessProvider) {
protected OpenSearchAccess getOpenSearchAccess() throws IOException {
return accessProvider.getOpenSearchAccess();
}

protected void validateMin(Integer value, int min, String name) {
if(value != null && value < min) {
throw new RestException("Invalid parameter " + name + ", should be at least " + min, HttpStatus.BAD_REQUEST);
if (value != null && value < min) {
throw new RestException("Invalid parameter " + name + ", should be at least " + min,
HttpStatus.BAD_REQUEST);
}
}

protected void validateMax(Integer value, int max, String name) {
if(value != null && value > max) {
throw new RestException("Invalid parameter " + name + ", should be at most " + max, HttpStatus.BAD_REQUEST);
if (value != null && value > max) {
throw new RestException("Invalid parameter " + name + ", should be at most " + max,
HttpStatus.BAD_REQUEST);
}
}

protected SimpleFeatureType mapFeatureTypeToSimple(FeatureType schema,
Consumer<SimpleFeatureTypeBuilder> extraAttributeBuilder) {
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
for (PropertyDescriptor pd : schema.getDescriptors()) {
// skip multivalue, metadata and quicklook
final Name propertyName = pd.getName();
if (pd.getMaxOccurs() > 1
|| OpenSearchAccess.METADATA_PROPERTY_NAME.equals(propertyName)
|| OpenSearchAccess.QUICKLOOK_PROPERTY_NAME.equals(propertyName)
|| "htmlDescription".equalsIgnoreCase(propertyName.getLocalPart())
|| "id".equals(propertyName.getLocalPart())) {
continue;
}
Name name = propertyName;
String uri = name.getNamespaceURI();
String prefix = null;
if (OpenSearchAccess.EO_NAMESPACE.equals(uri)) {
prefix = "eo";
} else {
for (ProductClass pc : ProductClass.values()) {
if (pc.getNamespace().equals(uri)) {
prefix = pc.getPrefix();
break;
}
}
}
String mappedName;
if (prefix != null) {
mappedName = prefix + ":" + name.getLocalPart();
} else {
mappedName = name.getLocalPart();
}
tb.userData(SOURCE_NAME, name);
tb.add(mappedName, pd.getType().getBinding());
}
tb.setName(schema.getName());
extraAttributeBuilder.accept(tb);
SimpleFeatureType targetSchema = tb.buildFeatureType();
return targetSchema;
}

protected SimpleFeature mapFeatureToSimple(Feature f, SimpleFeatureType targetSchema,
Consumer<SimpleFeatureBuilder> extraValueBuilder) {
SimpleFeatureBuilder fb = new SimpleFeatureBuilder(targetSchema);
List<AttributeDescriptor> attributeDescriptors = targetSchema.getAttributeDescriptors();
String identifier = f.getIdentifier().getID();
for (AttributeDescriptor ad : attributeDescriptors) {
Name sourceName = (Name) ad.getUserData().get(SOURCE_NAME);
Property p = f.getProperty(sourceName);
if (p != null) {
Object value = p.getValue();
if (value != null) {
fb.set(ad.getLocalName(), value);
if ("eo:identifier".equals(ad.getLocalName()) && value instanceof String) {
identifier = (String) value;
}
}
}
}
extraValueBuilder.accept(fb);

return fb.buildFeature(identifier);
}

/**
* Un-maps OSEO related attributes to a prefix:name for for json encoding
*
* @param fc
* @return
*/
protected SimpleFeatureCollection toSimpleFeatureCollection(
FeatureCollection<FeatureType, Feature> fc,
Consumer<SimpleFeatureTypeBuilder> extraAttributeBuilder,
Consumer<SimpleFeatureBuilder> extraValuesBuilder) {
SimpleFeatureType targetSchema = mapFeatureTypeToSimple(fc.getSchema(),
extraAttributeBuilder);

return new BaseSimpleFeatureCollection(targetSchema) {

@Override
public SimpleFeatureIterator features() {
FeatureIterator<Feature> features = fc.features();
return new SimpleFeatureIterator() {

@Override
public SimpleFeature next() throws NoSuchElementException {
Feature f = features.next();
return mapFeatureToSimple(f, targetSchema, extraValuesBuilder);
}

@Override
public boolean hasNext() {
return features.hasNext();
}

@Override
public void close() {
features.close();
}
};
}
};
}

}

0 comments on commit b764980

Please sign in to comment.