-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an action route that returns the fields information for WFS layers #670
Add an action route that returns the fields information for WFS layers #670
Conversation
control-base/src/main/java/fi/nls/oskari/util/WFSGetLayerFields.java
Outdated
Show resolved
Hide resolved
64e4567
to
3c7b125
Compare
3c7b125
to
ea107d9
Compare
|
||
@Override | ||
public void handleAction(ActionParameters params) throws ActionException { | ||
final int layerId = ConversionHelper.getInt(params.getRequiredParam(PARAM_LAYER_ID), -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final int layerId = ConversionHelper.getInt(params.getRequiredParam(PARAM_LAYER_ID), -1); | |
final int layerId = params.getRequiredParamInt(PARAM_LAYER_ID) |
} | ||
|
||
private OskariLayer getLayer(int layerId) throws ActionException { | ||
final OskariLayer layer = layerService.find(layerId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run this through the PermissionHelper as in https://github.com/oskariorg/oskari-server/blob/master/control-base/src/main/java/fi/nls/oskari/control/layer/GetLayerTileHandler.java#L67
The helper will throw a ActionDeniedException if the user doesn't have permission to view the layer -> they shouldn't get to see the attributes/configurations we have on that layer either.
if (layer == null) { | ||
throw new ActionException("Layer not found: " + layerId); | ||
} | ||
return layer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return layer; | |
if (!OskariLayer.TYPE_WFS.equals(layer.getType()) { | |
throw new ActionParamsException("Only WFS supported. Wrong layer type: " + layer.getType()); | |
} | |
return layer; |
* | ||
*/ | ||
private static JSONObject getCollectionFields(OskariLayer layer) throws ServiceException { | ||
String url = layer.getUrl() + "collections/" + layer.getName() + "/items"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use https://github.com/oskariorg/oskari-server/blob/master/service-wfs3/src/main/java/org/oskari/service/wfs3/OskariWFS3Client.java#L229 OskariWFS3Client.getItemsPath(layer.getUrl(), layer.getName());
(make the static method public on the client) so it's easier to see where OGC API Features services are called. I don't think we should use the existing client for getting the features since it's probably doing too much for what we need here. We could use OskariWFS3Client.validateResponse(conn, CONTENT_TYPE_GEOJSON);
though for sanity checking the response.
while (attributeNames.hasNext()) { | ||
String attributeName = (String) attributeNames.next(); | ||
String attributeType = propertyTypes.getString(attributeName); | ||
attributeType = attributeType.split(":")[1]; // remove xml namespace prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure there is a ':' character included and not assume there is. Most probably have it but there's always the chance that XML default namespace is set based on the featuretype.
OskariLayerService mockLayerService = mock(OskariLayerServiceMybatisImpl.class); | ||
OskariLayer wfsLayer = new OskariLayer(); | ||
wfsLayer.setType("WFS"); | ||
final String rawJsonStr = "{\"data\": {\"locale\": {\"fi\": {\"field-en\": \"field-fi\"}}}}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"field-en": "field-fi"
is a bit misleading here. Rename to something like "test-attribute": "label for fi"
or similar.
private static void mockOskariComponentManager() throws JSONException { | ||
OskariLayerService mockLayerService = getMockLayerService(); | ||
PowerMockito.mockStatic(OskariComponentManager.class); | ||
when(OskariComponentManager.getComponentOfType(OskariLayerService.class)).thenReturn(mockLayerService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we've mostly used setters on handlers for setting up mock services with init() checking if the services have been set before overwriting them with values from the component manager. But this is ok since it looks like it's not leaking the mocks between tests.
|
||
private OskariLayer getWFSLayer(String version) { | ||
OskariLayer layer = new OskariLayer(); | ||
layer.setType("WFS"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layer.setType("WFS"); | |
layer.setType(OskariLayer.TYPE_WFS); |
e61eabb
to
60657d8
Compare
The result is structured as: { "attributes": { "attr-1": "string", "attr-2": "number", ... "attr-n": "unknown", }, "geometryField": "geometry", "locale": { "en": { "attr-1: "attr-1-en" ... }, "fi": { "attr-1": "attr-1-fi" ... }, ... } }
60657d8
to
3ab105e
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
For anyone following Oskari development/PRs: future plans/goals include using this as a replacement and unifying at least these:
|
The result is structured as: