Search in sources :

Example 71 with JSONObject

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;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) JSONNumber(com.google.gwt.json.client.JSONNumber)

Example 72 with JSONObject

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);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 73 with JSONObject

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);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 74 with JSONObject

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;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) JSONArray(com.google.gwt.json.client.JSONArray) JSONNumber(com.google.gwt.json.client.JSONNumber) HashMap(java.util.HashMap) Map(java.util.Map)

Example 75 with JSONObject

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);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JSONObject (com.google.gwt.json.client.JSONObject)227 JSONNumber (com.google.gwt.json.client.JSONNumber)109 JSONString (com.google.gwt.json.client.JSONString)74 JSONArray (com.google.gwt.json.client.JSONArray)62 PerunError (cz.metacentrum.perun.webgui.model.PerunError)55 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)54 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)54 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)50 JSONValue (com.google.gwt.json.client.JSONValue)13 HashMap (java.util.HashMap)12 Map (java.util.Map)8 ArrayList (java.util.ArrayList)6 JsArrayString (com.google.gwt.core.client.JsArrayString)3 User (cz.metacentrum.perun.webgui.model.User)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Command (com.google.gwt.user.client.Command)2 Contact (com.googlecode.gwtphonegap.client.contacts.Contact)2 ContactField (com.googlecode.gwtphonegap.client.contacts.ContactField)2 StringCallback (com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback)2