use of com.google.gwt.json.client.JSONObject in project perun by CESNET.
the class AddAdmin method prepareJSONObjectForGroup.
/**
* Prepares a JSON object
*
* @return JSONObject the whole query
*/
private JSONObject prepareJSONObjectForGroup() {
JSONObject jsonQuery = new JSONObject();
if (entity.equals(PerunEntity.VIRTUAL_ORGANIZATION)) {
jsonQuery.put("vo", new JSONNumber(entityId));
} else if (entity.equals(PerunEntity.GROUP)) {
jsonQuery.put("group", new JSONNumber(entityId));
} else if (entity.equals(PerunEntity.FACILITY)) {
jsonQuery.put("facility", new JSONNumber(entityId));
} else if (entity.equals(PerunEntity.SECURITY_TEAM)) {
jsonQuery.put("securityTeam", new JSONNumber(entityId));
}
jsonQuery.put("authorizedGroup", new JSONNumber(userId));
return jsonQuery;
}
use of com.google.gwt.json.client.JSONObject in project perun by CESNET.
the class AddExtSource method addGroupExtSource.
/**
* Attempts to add external source to Group in DB - make RPC call
*
* @param groupId ID of Group, where should be ext source added
* @param extSourceId ID of external source to be added
*/
public void addGroupExtSource(final int groupId, final int extSourceId) {
this.extSourceId = extSourceId;
// create whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("source", new JSONNumber(extSourceId));
jsonQuery.put("group", new JSONNumber(groupId));
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding external source: " + extSourceId + " to group: " + groupId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("External source: " + extSourceId + " successfully added to group: " + groupId);
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of com.google.gwt.json.client.JSONObject in project perun by CESNET.
the class RemoveExtSource method removeVoExtSource.
/**
* Attempts to remove external source from VO
*
* @param voId ID of VO, where we should remove ext source
* @param extSourceId ID of external source to be removed
*/
public void removeVoExtSource(final int voId, final int extSourceId) {
this.voId = voId;
this.extSourceId = extSourceId;
// test arguments
if (!this.testRemoving()) {
return;
}
// json object
JSONObject jsonQuery = prepareJSONObject();
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Removing external source: " + extSourceId + " from VO: " + voId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("External source: " + extSourceId + " successfully removed from VO: " + voId);
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of com.google.gwt.json.client.JSONObject in project perun by CESNET.
the class SetAttributes method prepareJSONObject.
/**
* Prepares a JSON object.
* @return JSONObject the whole query
*/
private JSONObject prepareJSONObject() {
// create whole JSON query
JSONObject jsonQuery = new JSONObject();
// create attrs field
JSONArray array = new JSONArray();
// create attributes
for (int i = 0; i < attributes.size(); i++) {
// skip attribute with empty or null value
if (attributes.get(i).getValue() == null || attributes.get(i).getValue().equalsIgnoreCase("")) {
continue;
}
// create Json object from attribute
JSONObject attr = new JSONObject(attributes.get(i));
// get only interested in properties
JSONValue id = attr.get("id");
JSONValue friendlyName = attr.get("friendlyName");
JSONValue namespace = attr.get("namespace");
JSONValue type = attr.get("type");
JSONValue description = attr.get("description");
JSONValue value = attr.get("value");
JSONValue displayName = attr.get("displayName");
// create new Attribute jsonObject
JSONObject newAttr = new JSONObject();
newAttr.put("value", value);
newAttr.put("id", id);
newAttr.put("type", type);
newAttr.put("description", description);
newAttr.put("namespace", namespace);
newAttr.put("friendlyName", friendlyName);
newAttr.put("displayName", displayName);
// put attribute into array
array.set(array.size(), newAttr);
}
for (Map.Entry<String, Integer> attrIds : this.ids.entrySet()) {
jsonQuery.put(attrIds.getKey(), new JSONNumber(attrIds.getValue()));
}
jsonQuery.put("attributes", array);
return jsonQuery;
}
use of com.google.gwt.json.client.JSONObject in project perun by CESNET.
the class CreateAuthorship method createAuthorship.
/**
* Attempts to create a new Authorship, it first tests the values and then submits them.
*
* @param pubId ID of publication
* @param userId ID of user
*/
public void createAuthorship(final int pubId, final int userId) {
this.userId = userId;
this.pubId = pubId;
// test arguments
if (!this.testCreating()) {
return;
}
// json object
JSONObject jsonQuery = prepareJSONObject();
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding Author: " + userId + " for publication: " + pubId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Author: " + userId + " successfully added for publication: " + pubId);
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
Aggregations