Skip to content
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

JS client API proposal #1848

Merged
merged 17 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package org.fao.geonet.kernel.setting;

import org.apache.commons.lang.StringUtils;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.NodeInfo;
import org.fao.geonet.constants.Geonet;
Expand Down Expand Up @@ -313,7 +314,9 @@ public final boolean setValues(final Map<String, String> values) {
for (Map.Entry<String, String> entry : values.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
setValue(key, value);
if (StringUtils.isNotEmpty(key)) {
setValue(key, value);
}
}
return success;
}
Expand Down
31 changes: 31 additions & 0 deletions core/src/main/java/org/fao/geonet/util/XslUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

package org.fao.geonet.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function;
import jeeves.component.ProfileManager;
import jeeves.server.ServiceConfig;
import jeeves.server.context.ServiceContext;
import net.objecthunter.exp4j.Expression;
import net.objecthunter.exp4j.ExpressionBuilder;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -165,6 +167,35 @@ public static String getSettingValue(String key) {
return "";
}

public static String getJsonSettingValue(String key, String path) {
if (key == null) {
return "";
}
try {
final ServiceContext serviceContext = ServiceContext.get();
if (serviceContext != null) {
SettingManager settingsMan = serviceContext.getBean(SettingManager.class);
if (settingsMan != null) {
String json = settingsMan.getValue(key);

ObjectMapper objectMapper = new ObjectMapper();
Object jsonObj = objectMapper.readValue(json, Object.class);

Object value = PropertyUtils.getProperty(jsonObj, path);
if (value != null) {
return value.toString();
} else {
return "";
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}


/**
* Check if bean is defined in the context
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,25 @@ public void serialize(Setting s, JsonGenerator jsonGenerator,
}

public static void writeSettingValue(Setting s, JsonGenerator jsonGenerator) throws IOException {
if (StringUtils.isNotEmpty(s.getValue())) {
if (s.getDataType() == SettingDataType.BOOLEAN) {
jsonGenerator.writeBoolean(Boolean.parseBoolean(s.getValue()));
} else if (s.getDataType() == SettingDataType.INT) {
jsonGenerator.writeNumber(Integer.parseInt(s.getValue()));
} else if (s.getDataType() == SettingDataType.JSON) {
ObjectMapper mapper = new ObjectMapper();
jsonGenerator.writeTree(mapper.readTree(s.getValue()));
try {
if (StringUtils.isNotEmpty(s.getValue())) {
if (s.getDataType() == SettingDataType.BOOLEAN) {
jsonGenerator.writeBoolean(Boolean.parseBoolean(s.getValue()));
} else if (s.getDataType() == SettingDataType.INT) {
jsonGenerator.writeNumber(Integer.parseInt(s.getValue()));
} else if (s.getDataType() == SettingDataType.JSON) {
ObjectMapper mapper = new ObjectMapper();
jsonGenerator.writeTree(mapper.readTree(s.getValue()));
} else {
jsonGenerator.writeString(s.getValue());
}
} else {
jsonGenerator.writeString(s.getValue());
jsonGenerator.writeNull();
}
} else {
} catch (Exception e) {
jsonGenerator.writeNull();
jsonGenerator.writeStringField("erroneousValue", s.getValue());
jsonGenerator.writeStringField("error", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2001-2016 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
* Rome - Italy. email: geonetwork@osgeo.org
*/

(function() {
goog.provide('gn_ui_config_directive');

var module = angular.module('gn_ui_config_directive', []);

module.directive('gnUiConfig', ['gnGlobalSettings',
function(gnGlobalSettings) {

return {
restrict: 'A',
scope: {
config: '=gnUiConfig',
id: '='
},
templateUrl: '../../catalog/components/admin/uiconfig/partials/' +
'uiconfig.html',
link: function(scope, element, attrs) {
var testAppUrl = '../../catalog/views/api/?config=';
scope.jsonConfig = angular.fromJson(scope.config);

scope.sortOrderChoices = ['', 'reverse'];


// ng-model can't bind to object key, so
// when key value change, reorganize object.
scope.updateKey = function(obj, new_key, id) {
var keys = Object.keys(obj);
var values = Object.values(obj);
var old_key = keys[id];
if (keys.indexOf(new_key) == -1 && new_key.length > 0) {
for (var i = 0, key; key = keys[i]; i++) {
delete obj[key];
}
keys[id] = new_key;
for (var i = 0, key; key = keys[i]; i++) {
obj[key] = values[i];
}
}
};

// Add an item to an array
// or duplicate last item multiplied by 10 (eg. hitsPerPage)
scope.addItem = function(array, item) {
if (angular.isArray(array)) {
array.push(item);
} else if (angular.isObject(array)) {
var key = Object.keys(item)[0];
array[key] = item[key];
}
};

// Remove item from array
scope.removeItem = function(array, index) {
if (angular.isArray(array)) {
array.splice(index, 1);
} else if (angular.isObject(array)) {
delete array[index];
}
};

scope.reset = function() {
angular.extend(scope.jsonConfig,
gnGlobalSettings.getDefaultConfig());
};

scope.testClientConfig = function() {
window.open(
testAppUrl +
encodeURIComponent(angular.toJson(scope.jsonConfig)),
'gnClientTestWindow');
};
}
};
}]);
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2001-2016 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
* Rome - Italy. email: geonetwork@osgeo.org
*/

(function() {
goog.provide('gn_ui_config');

goog.require('gn_ui_config_directive');

angular.module('gn_ui_config', [
'gn_ui_config_directive'
]);
})();
Loading