* updataMetadataRecord, add or delete a online source link.
*/
public Element exec(Element params, ServiceContext context)
throws Exception {
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
MapServerRepository repo = context.getBean(MapServerRepository.class);
SettingManager settingsManager = gc.getBean(SettingManager.class);
String baseUrl = settingsManager.getSiteURL(context);
ACTION action = ACTION.valueOf(Util.getParam(params, "action"));
if (action.equals(ACTION.LIST)) {
return loadDbConfiguration(context);
} else if (action.equals(ACTION.ADD_NODE)) {
MapServer m = new MapServer()
.setName(Util.getParam(params, "name", ""))
.setDescription(Util.getParam(params, "description", ""))
.setConfigurl(Util.getParam(params, "configurl", ""))
.setWmsurl(Util.getParam(params, "wmsurl", ""))
.setWfsurl(Util.getParam(params, "wfsurl", ""))
.setWcsurl(Util.getParam(params, "wcsurl", ""))
.setStylerurl(Util.getParam(params, "stylerurl", ""))
.setUsername(Util.getParam(params, "username", ""))
.setPassword(Util.getParam(params, "password", ""))
.setNamespace(Util.getParam(params, "namespace", ""))
.setNamespacePrefix(Util.getParam(params, "namespaceprefix", ""));
context.getBean(MapServerRepository.class).save(m);
return new Element(action.toString())
.setText("ok")
.setAttribute("id", String.valueOf(m.getId()));
} else if (action.equals(ACTION.REMOVE_NODE)) {
MapServer m = repo.findOneById(Util.getParam(params, "id"));
if (m != null) {
repo.delete(m);
}
return new Element(action.toString()).setText("ok");
} else if (action.equals(ACTION.UPDATE_NODE)) {
MapServer m = repo.findOneById(Util.getParam(params, "id"));
if (m != null) {
m.setName(Util.getParam(params, "name", ""))
.setDescription(Util.getParam(params, "description", ""))
.setConfigurl(Util.getParam(params, "configurl", ""))
.setWmsurl(Util.getParam(params, "wmsurl", ""))
.setWfsurl(Util.getParam(params, "wfsurl", ""))
.setWcsurl(Util.getParam(params, "wcsurl", ""))
.setStylerurl(Util.getParam(params, "stylerurl", ""))
.setNamespace(Util.getParam(params, "namespace", ""))
.setNamespacePrefix(Util.getParam(params, "namespaceprefix", ""));
repo.save(m);
}
return new Element(action.toString()).setText("ok");
} else if (action.equals(ACTION.UPDATE_NODE_ACCOUNT)) {
MapServer m = repo.findOneById(Util.getParam(params, "id"));
if (m != null) {
m.setUsername(Util.getParam(params, "username", ""))
.setPassword(Util.getParam(params, "password", ""));
repo.save(m);
}
return new Element(action.toString()).setText("ok");
} else if (action.equals(ACTION.CREATE) || action.equals(ACTION.UPDATE)
|| action.equals(ACTION.DELETE) || action.equals(ACTION.GET)) {
// Check parameters
String nodeId = Util.getParam(params, "nodeId");
String metadataId = Util.getParam(params, "metadataId");
String metadataUuid = Util.getParam(params, "metadataUuid", "");
// purge \\n from metadataTitle - geoserver prefers layer titles on a single line
String metadataTitle = Util.getParam(params, "metadataTitle", "").replace("\\n","");
// unescape \\n from metadataAbstract so they're properly sent to geoserver
String metadataAbstract = Util.getParam(params, "metadataAbstract", "").replace("\\n","\n");
MapServer m = repo.findOneById(nodeId);
GeoServerNode g = new GeoServerNode(m);
final GeonetHttpRequestFactory requestFactory = context.getBean(GeonetHttpRequestFactory.class);
GeoServerRest gs = new GeoServerRest(requestFactory, g.getUrl(),
g.getUsername(), g.getUserpassword(),