Skip to content

Commit

Permalink
Couple of fixes and adding wfs3 to the community release
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Mar 7, 2018
1 parent 75f9b83 commit e4921fa
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/community/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<descriptor>release/ext-nsg-wfs-profile.xml</descriptor>
<descriptor>release/ext-netcdf-ghrsst.xml</descriptor>
<descriptor>release/ext-mongodb.xml</descriptor>
<descriptor>release/ext-wfs3.xml</descriptor>
</descriptors>
</configuration>
</plugin>
Expand Down Expand Up @@ -257,6 +258,7 @@
<module>netcdf-ghrsst</module>
<module>mongodb</module>
<module>taskmanager</module>
<module>wfs3</module>
</modules>
</profile>
<profile>
Expand Down
17 changes: 17 additions & 0 deletions src/community/release/ext-wfs3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<assembly>
<id>wfs3-plugin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>release/target/dependency</directory>
<outputDirectory></outputDirectory>
<includes>
<include>gs-wfs3-*.jar</include>
<include>jackson-dataformat-yaml*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
5 changes: 5 additions & 0 deletions src/community/release/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@
<artifactId>gs-mongodb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.geoserver.community</groupId>
<artifactId>gs-wfs3</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -30,12 +31,14 @@
* The class contains a makeshift object model for Swagger, based on observation, not actual spec reading and probably
* not formally correct, but good enough for the moment (looks like Java libs are more concentrated on code generation,
* but somewhere in there, if it does not have too many dependencies, there is probably a proper object model for this).
*
* Actually, found this after implementing the class, https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-models.
* It might be used for re-implementing this class in a cleaner, less error prone and more general way (although, think about
* <p>
* Actually, found this after implementing the class, https://github
* .com/swagger-api/swagger-core/tree/master/modules/swagger-models.
* It might be used for re-implementing this class in a cleaner, less error prone and more general way (although,
* think about
* streaming support for large API documents too)
*/
@JsonPropertyOrder({ "openapi", "info", "paths", "parameters" })
@JsonPropertyOrder({"openapi", "info", "paths", "parameters"})
public class APIDocument {

private static final String TYPE_STRING = "string";
Expand All @@ -55,14 +58,13 @@ public class APIDocument {
private static final Reference REF_EXCEPTION = new Reference("#/components/schemas/exception");
private static final String TAG_CAPABILITIES = "Capabilities";
private static final Response ERROR_RESPONSE;

static {
ERROR_RESPONSE = new Response("An error occurred");
ERROR_RESPONSE.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withReference(REF_EXCEPTION));
ERROR_RESPONSE.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
}




public class Info {
public String getTitle() {
Expand Down Expand Up @@ -120,7 +122,7 @@ public String getReference() {
}

public static class Type {

String type;

public Type(String type) {
Expand Down Expand Up @@ -193,7 +195,7 @@ public void addResponse(String status, Response response) {
public static class Response {
String description;
Map<String, FormatDescription> content;


public Response(String description) {
this.description = description;
Expand All @@ -214,18 +216,18 @@ public Map<String, FormatDescription> getContent() {
public void setContent(Map<String, FormatDescription> content) {
this.content = content;
}

public void addFormat(String name, FormatDescription format) {
if (content == null) {
content = new HashMap<>();
}
content.put(name, format);
}
}

public static class FormatDescription {
Object schema;

public FormatDescription withReference(String reference) {
this.schema = new Reference(reference);
return this;
Expand All @@ -235,7 +237,7 @@ public FormatDescription withReference(Reference reference) {
this.schema = reference;
return this;
}

public FormatDescription withType(String type) {
this.schema = new Type(type);
return this;
Expand All @@ -250,7 +252,7 @@ public void setSchema(Object schema) {
}

}

public static class Items {
String type;
Object minimum;
Expand Down Expand Up @@ -280,14 +282,14 @@ public void setMaximum(Object maximum) {
this.maximum = maximum;
}
}

public static class Parameter {
String name;
String in;
Boolean required;
String description;
Schema schema;
String style;
String style;
String type;
Items items;

Expand Down Expand Up @@ -346,7 +348,7 @@ public String getType() {
public void setType(String type) {
this.type = type;
}

public Parameter withType(String type) {
this.type = type;
return this;
Expand Down Expand Up @@ -417,7 +419,7 @@ public void addRequired(String name) {
public Map<String, Parameter> getProperties() {
return properties;
}

public void setProperties(Map<String, Parameter> properties) {
this.properties = properties;
}
Expand Down Expand Up @@ -491,9 +493,9 @@ public Integer getMaxItems() {
public void setMaxItems(Integer maxItems) {
this.maxItems = maxItems;
}

}

private final WFSInfo wfs;
private final Catalog catalog;
private String openapi = "3.0.0";
Expand Down Expand Up @@ -524,7 +526,8 @@ public Map<String, Object> getPaths() {
caps.setOperationId("describeCollections");
caps.addParameter(REF_FORMAT);
Response contents = new Response("The feature collections shared by this API");
contents.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withReference("'#/components/schemas/content"));
contents.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withReference
("'#/components/schemas/content"));
contents.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
caps.addResponse("200", contents);
caps.addResponse("default", ERROR_RESPONSE);
Expand All @@ -549,7 +552,8 @@ public Map<String, Object> getPaths() {
" conforms to");
conformance.addTag(TAG_CAPABILITIES);
Response conformanceResponse = new Response("the URIs of all requirements classes supported by the server");
conformanceResponse.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withReference("#/components/schemas/req-classes"));
conformanceResponse.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withReference
("#/components/schemas/req-classes"));
conformance.addResponse("200", conformanceResponse);
conformance.addResponse("default", ERROR_RESPONSE);
result.put("/api/conformance", Collections.singletonMap("get", conformance));
Expand Down Expand Up @@ -585,17 +589,17 @@ public Map<String, Object> getPaths() {

return result;
}

public Map<String, Object> getComponents() {
Map<String, Object> components = new LinkedHashMap<>();
components.put("parameters", getParameters());
components.put("schemas", getSchemas());
return components;
}

protected Map<String, Parameter> getParameters() {
Map<String, Parameter> parameters = new LinkedHashMap<>();

Parameter count = new Parameter();
count.setName("count");
count.setIn(IN_QUERY);
Expand Down Expand Up @@ -657,13 +661,13 @@ protected Map<String, Parameter> getParameters() {
idSchema.setType(TYPE_STRING);
id.setSchema(idSchema);
parameters.put("id", id);

return parameters;
}

protected Map<String, Schema> getSchemas() {
Map<String, Schema> schemas = new LinkedHashMap<>();

Schema exception = new Schema();
exception.setType(TYPE_OBJECT);
exception.addRequired("code");
Expand All @@ -685,17 +689,21 @@ protected Map<String, Schema> getSchemas() {
reqClasses.addExample("http://www.opengis.net/spec/wfs-1/3.0/req/html");
reqClasses.addExample("http://www.opengis.net/spec/wfs-1/3.0/req/geojson");
schemas.put("exception", exception);

return schemas;
}

protected Map<String, FormatDescription> getAvailableFormats() {
Map<String, FormatDescription> descriptions = new TreeMap<>();
Collection featureProducers = GeoServerExtensions.extensions(WFSGetFeatureOutputFormat.class);
for (Iterator i = featureProducers.iterator(); i.hasNext(); ) {
WFSGetFeatureOutputFormat format = (WFSGetFeatureOutputFormat) i.next();
// TODO: get better collaboration from content
String formatName = format.getOutputFormats().iterator().next();
Set<String> formats = format.getOutputFormats();
if (formats.isEmpty()) {
continue;
}
String formatName = formats.iterator().next();
if (formatName.contains("text") || formatName.contains("csv")) {
descriptions.put(formatName, new FormatDescription().withType(TYPE_STRING));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public Object read(Object request, Map kvp, Map rawKvp) throws Exception {
Object format = kvp.get("f");
setFormat(kvp, rawKvp, format);
} else if (request != null) {
String header = dispatcherRequest.getHttpRequest().getHeader(HttpHeaders.ACCEPT);
if (header != null) {
String[] formats = header.split("\\s*,\\s");
// TODO: check supported formats and pick the first that's actually supported
String format = formats[0];
setFormat(kvp, rawKvp, format);
}
// ignoring for the moment, until the HTML output formats are ready, otherwise
// it won't show up in the browser
// String header = dispatcherRequest.getHttpRequest().getHeader(HttpHeaders.ACCEPT);
// if (header != null) {
// String[] formats = header.split("\\s*,\\s*");
// // TODO: check supported formats and pick the first that's actually supported
// String format = formats[0];
// setFormat(kvp, rawKvp, format);
// }
}

return super.read(request, kvp, rawKvp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public void write(Object value, OutputStream output, Operation operation) throws
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.writeValue(output, value);
}

@Override
public String getAttachmentFileName(Object value, Operation operation) {
return "api" + (isJsonFormat(operation) ? ".json" : ".yaml");
}
}

0 comments on commit e4921fa

Please sign in to comment.