Search in sources :

Example 31 with JSONObject

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

the class RemoveSecurityTeam method removeSecurityTeam.

/**
	 * Attempts to remove security team from facility, it first tests the values and then submits them.
	 *
	 * @param facility ID of facility which should have security team remove
	 * @param secTeam ID of SecurityTeam to be removed from facility
	 */
public void removeSecurityTeam(final int facility, final int secTeam) {
    this.facility = facility;
    this.secTeam = secTeam;
    // test arguments
    if (!this.testAdding()) {
        return;
    }
    // json object
    JSONObject jsonQuery = prepareJSONObject();
    // local events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Removing SecurityTeam " + secTeam + " from facility " + facility + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("SecurityTeam " + secTeam + " removed from facility " + facility);
            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 32 with JSONObject

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

the class UpdateFacility method updateFacility.

/**
	 * Updates facility details
	 *
	 * @param fac Facility with updated details
	 */
public void updateFacility(Facility fac) {
    if (fac == null) {
        UiElements.generateAlert("Error updating facility", "Facility to update can't be null.");
        return;
    }
    // GROUP OBJECT
    JSONObject oldFacility = new JSONObject(fac);
    // RECONSTRUCT OBJECT
    JSONObject newFacility = new JSONObject();
    newFacility.put("id", oldFacility.get("id"));
    newFacility.put("name", oldFacility.get("name"));
    newFacility.put("description", oldFacility.get("description"));
    newFacility.put("type", oldFacility.get("type"));
    newFacility.put("beanName", oldFacility.get("beanName"));
    newFacility.put("createdAt", oldFacility.get("createdAt"));
    newFacility.put("createdBy", oldFacility.get("createdBy"));
    newFacility.put("modifiedAt", oldFacility.get("modifiedAt"));
    newFacility.put("modifiedBy", oldFacility.get("modifiedBy"));
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("facility", newFacility);
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

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

        ;

        public void onFinished(JavaScriptObject jso) {
            Facility fac = jso.cast();
            session.getUiElements().setLogSuccessText("Facility " + fac.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) 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) Facility(cz.metacentrum.perun.webgui.model.Facility)

Example 33 with JSONObject

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

the class BanExecServiceOnFacility method prepareJSONObject.

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

Example 34 with JSONObject

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

the class AssignSecurityTeam method assignSecurityTeam.

/**
	 * Attempts to add security team to facility, it first tests the values and then submits them.
	 *
	 * @param facility ID of facility which should have security team added
	 * @param secTeam ID of SecurityTeam to be added to facility
	 */
public void assignSecurityTeam(final int facility, final int secTeam) {
    this.facility = facility;
    this.secTeam = secTeam;
    // test arguments
    if (!this.testAdding()) {
        return;
    }
    // json object
    JSONObject jsonQuery = prepareJSONObject();
    // local events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Adding SecurityTeam " + secTeam + " to facility " + facility + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("SecurityTeam " + secTeam + " added to facility " + facility);
            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 35 with JSONObject

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

the class DeleteResourceTag method prepareJSONObject.

/**
	 * Prepares a JSON object
	 * @return JSONObject the whole query
	 */
private JSONObject prepareJSONObject() {
    JSONObject jsonQuery = new JSONObject();
    JSONObject jsonTag = new JSONObject(tag);
    JSONObject newJsonTag = new JSONObject();
    newJsonTag.put("id", jsonTag.get("id"));
    newJsonTag.put("tagName", jsonTag.get("tagName"));
    newJsonTag.put("voId", jsonTag.get("voId"));
    jsonQuery.put("resourceTag", newJsonTag);
    return jsonQuery;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject)

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