Search in sources :

Example 81 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class DeleteTask method deleteTask.

/**
	 * Deletes Task from DB
	 *
	 * @param taskId id of Task to be deleted
	 */
public void deleteTask(final int taskId) {
    this.taskId = taskId;
    // test arguments
    if (!this.testArguments()) {
        return;
    }
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("task", new JSONNumber(taskId));
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Deleting of Task: " + taskId + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Task: " + taskId + " deleted successfully.");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.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 82 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class RemoveMember method prepareJSONObject.

/**
	 * Prepares a JSON object
	 *
	 * @return JSONObject the whole query
	 */
private JSONObject prepareJSONObject() {
    JSONNumber group = new JSONNumber(groupId);
    JSONNumber member = new JSONNumber(memberId);
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("group", group);
    jsonQuery.put("member", member);
    return jsonQuery;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) JSONNumber(com.google.gwt.json.client.JSONNumber)

Example 83 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class RemoveMember method removeMemberFromGroup.

/**
	 * Attempts to remove member from group
	 *
	 * @param groupId id of group
	 * @param memberId ID of member to be removed from group
	 */
public void removeMemberFromGroup(final int groupId, final int memberId) {
    this.memberId = memberId;
    this.groupId = groupId;
    // test arguments
    if (!this.testRemoving()) {
        return;
    }
    // prepare json object
    JSONObject jsonQuery = prepareJSONObject();
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Removing member: " + memberId + " from group: " + groupId + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Member: " + memberId + " removed from group: " + groupId);
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.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 84 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class UpdateGroup method updateGroup.

/**
	 * Updates group details
	 * @param group Group with updated details
	 */
public void updateGroup(Group group) {
    if (group == null) {
        Window.alert("Group can't be null");
        return;
    }
    // GROUP OBJECT
    JSONObject oldGroup = new JSONObject(group);
    // RECONSTRUCT OBJECT
    JSONObject newGroup = new JSONObject();
    newGroup.put("id", oldGroup.get("id"));
    // fake new group short name as name in order to update
    newGroup.put("name", oldGroup.get("shortName"));
    newGroup.put("description", oldGroup.get("description"));
    newGroup.put("voId", oldGroup.get("voId"));
    newGroup.put("parentGroupId", oldGroup.get("parentGroupId"));
    newGroup.put("beanName", oldGroup.get("beanName"));
    newGroup.put("createdAt", oldGroup.get("createdAt"));
    newGroup.put("createdBy", oldGroup.get("createdBy"));
    newGroup.put("modifiedAt", oldGroup.get("modifiedAt"));
    newGroup.put("modifiedBy", oldGroup.get("modifiedBy"));
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("group", newGroup);
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Updating group failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            Group gp = jso.cast();
            session.getUiElements().setLogSuccessText("Group " + gp.getName() + " successfully updated!");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, jsonQuery);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) 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 85 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class CreateApplication method prepareJSONObject.

/**
	 * Prepares a JSON object.
	 * @return JSONObject - the whole query
	 */
private JSONObject prepareJSONObject() {
    // data to JSON array
    JSONArray data = new JSONArray();
    for (int i = 0; i < formData.size(); i++) {
        data.set(i, new JSONObject(formData.get(i)));
    }
    // query
    JSONObject query = new JSONObject();
    query.put("app", new JSONObject(application));
    query.put("data", data);
    return query;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) JSONArray(com.google.gwt.json.client.JSONArray)

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