Skip to content

Commit

Permalink
Editor / Geopublication / Misc fix. (#8092)
Browse files Browse the repository at this point in the history
* Editor / Geopublication / Misc fix.

* Admin configuration / Show reset password only once the mapserver is
  created. Removed unused code
* API / Fix ZIP file publication and coverage removal (probably related to GeoServer API
  changes - tested with version 2.25.1)
* Editor / Fix zoom to layer due to mapservice change, do not show
  styler if not configured

* Editor / Geopublication / Avoid NPE if style can't be created on GS side.
  • Loading branch information
fxprunayre authored Oct 11, 2024
1 parent 58a713c commit c7f8e8b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,14 @@ public boolean createDatastore(String ws, String ds, String file) throws IOExcep
} else if (file.startsWith("file://")) {
type = "external";
}
boolean isZip = ".zip".equals(extension);

Log.debug(Geonet.GEOPUBLISH, "Creating datastore " + ds + " in workspace " + ws + " from file " + file);
int status = sendREST(GeoServerRest.METHOD_PUT, "/workspaces/" + ws
+ "/datastores/" + ds + "/" + type + extension, file, null,
"text/plain", false);
int status = sendREST(GeoServerRest.METHOD_PUT,
"/workspaces/" + ws + "/datastores/" + ds + "/" + type + (isZip ? ".shp" : extension),
file, null,
(isZip ? "application/zip" : "text/plain"),
false);

return status == 201;
}
Expand Down Expand Up @@ -473,18 +476,20 @@ public boolean createStyle(String ws, String layer, String sldbody) {
}
if (sldbody.isEmpty() || (!sldbody.isEmpty() && status != 200)) {
String info = getLayerInfo(layer);
Element layerProperties = Xml.loadString(info, false);
String styleName = layerProperties.getChild("defaultStyle")
.getChild("name").getText();

Log.debug(Geonet.GEOPUBLISH, "Getting default style for " + styleName + " to apply to layer " + layer + " in workspace " + ws);
/* get the default style (polygon, line, point) from the global styles */
status = sendREST(GeoServerRest.METHOD_GET, "/styles/" + styleName
+ ".sld?quietOnNotFound=true", null, null, null, true);

status = sendREST(GeoServerRest.METHOD_PUT, url + "/" + layer
+ "_style", getResponse(), null,
"application/vnd.ogc.sld+xml", true);
if (info != null) {
Element layerProperties = Xml.loadString(info, false);
String styleName = layerProperties.getChild("defaultStyle")
.getChild("name").getText();

Log.debug(Geonet.GEOPUBLISH, "Getting default style for " + styleName + " to apply to layer " + layer + " in workspace " + ws);
/* get the default style (polygon, line, point) from the global styles */
status = sendREST(GeoServerRest.METHOD_GET, "/styles/" + styleName
+ ".sld?quietOnNotFound=true", null, null, null, true);

status = sendREST(GeoServerRest.METHOD_PUT, url + "/" + layer
+ "_style", getResponse(), null,
"application/vnd.ogc.sld+xml", true);
}
}
checkResponseCode(status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ public static boolean publishExternal(String file, GeoServerRest g, ACTION actio
if (!g.deleteLayer(dsName))
report += "Layer: " + g.getStatus();
if (isRaster) {

if (!g.deleteCoverage(dsName, dsName))
report += "Coverage: " + g.getStatus();
if (!g.deleteCoverageStore(dsName))
report += "Coveragestore: " + g.getStatus();
} else {
if (!g.deleteFeatureType(dsName, dsName))
report += "Feature type: " + g.getStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@
gnMap
.addWmsFromScratch(map, scope.gsNode.wmsurl, scope.layerName, false)
.then(
function (o) {
if (o.layer) {
gnMap.zoomLayerToExtent(o.layer, map);
scope.layer = o.layer;
function (layer) {
if (layer) {
gnMap.zoomLayerToExtent(layer, map);
scope.layer = layer;
}
},
function (o) {
if (o.layer) {
gnMap.zoomLayerToExtent(o.layer, map);
scope.layer = o.layer;
function (layer) {
if (layer) {
gnMap.zoomLayerToExtent(layer, map);
scope.layer = layer;
}
}
);
Expand All @@ -218,7 +218,12 @@
scope.$watch("gsNode", function (n, o) {
if (n != o) {
scope.checkNode(scope.gsNode.id);
scope.hasStyler = !angular.isArray(scope.gsNode.stylerurl);
scope.hasStyler = scope.gsNode.stylerurl !== "";
}
});
scope.$watch("layerName", function (n, o) {
if (n != o) {
scope.checkNode(scope.gsNode.id);
}
});

Expand Down Expand Up @@ -307,7 +312,6 @@
scope.hidden = false;
}
scope.mapId = "map-geopublisher";
// FIXME: only one publisher in a page ?
scope.ref = r.ref;
scope.refParent = r.refParent;
scope.name = r.name;
Expand All @@ -323,14 +327,17 @@
}

// Build layer name based on file name
scope.layerName = r.name.replace(/.zip$|.gpkg$|.tif$|.tiff$|.ecw$/, "");
scope.wmsLayerName = scope.layerName;
scope.layerName = r.name
.split("/")
.pop()
.replace(/.zip$|.gpkg$|.tif$|.tiff$|.ecw$/, "");
if (scope.layerName.match("^jdbc")) {
scope.wmsLayerName = scope.layerName.split("#")[1];
} else if (scope.layerName.match("^file")) {
scope.wmsLayerName = scope.layerName
.replace(/.*\//, "")
.replace(/.zip$|.gpkg$|.tif$|.tiff$|.ecw$/, "");
} else {
scope.wmsLayerName =
(scope.gsNode.namespacePrefix !== ""
? scope.gsNode.namespacePrefix + ":"
: "") + scope.layerName;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<button
type="button"
class="btn btn-default"
data-ng-hide="mapserverSelected.id === ''"
data-ng-click="resetMapServerPassword(mapserverSelected.id)"
>
<i class="fa fa-lock"></i>&nbsp;
Expand Down Expand Up @@ -134,42 +135,11 @@
class="form-control"
required=""
data-ng-model="mapserverSelected.configurl"
placeholder="http://"
placeholder="http://localhost/geoserver/rest"
/>
</div>
</div>

<fieldset data-ng-show="operation === 'ADD_NODE'">
<legend data-translate="">useAccount</legend>

<div class="form-group">
<label class="control-label col-sm-3" data-translate="">username</label>

<div class="col-sm-9">
<input
type="text"
class="form-control"
required=""
data-ng-model="mapserverSelected.username"
/>
</div>
</div>

<div class="form-group">
<label class="control-label col-sm-3" data-translate="">password</label>

<div class="col-sm-9">
<input
type="password"
class="form-control"
required="required"
autocomplete="new-password"
data-ng-model="mapserverSelected.password"
/>
</div>
</div>
</fieldset>

<div class="form-group">
<label class="control-label col-sm-3" data-translate="">workspace</label>

Expand Down Expand Up @@ -222,7 +192,7 @@
class="form-control"
required=""
data-ng-model="mapserverSelected.wmsurl"
placeholder="http://"
placeholder="http://localhost/geoserer/wms"
/>
</div>
</div>
Expand All @@ -237,7 +207,7 @@
class="form-control"
required=""
data-ng-model="mapserverSelected.wfsurl"
placeholder="http://"
placeholder="http://localhost/geoserver/wfs"
/>
</div>
</div>
Expand All @@ -252,7 +222,7 @@
class="form-control"
required=""
data-ng-model="mapserverSelected.wcsurl"
placeholder="http://"
placeholder="http://localhost/geoserver/wcs"
/>
</div>
</div>
Expand Down

0 comments on commit c7f8e8b

Please sign in to comment.