use of cz.metacentrum.perun.webgui.json.JsonPostClient in project perun by CESNET.
the class DeleteGroup method deleteGroup.
/**
* Delete a group from VO in DB
*
* @param groupId ID of group to be deleted
*/
public void deleteGroup(final int groupId) {
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("group", new JSONNumber(groupId));
jsonQuery.put("force", new JSONNumber(1));
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Deleting group " + groupId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Group " + groupId + " successfully deleted!");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.json.JsonPostClient 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);
}
use of cz.metacentrum.perun.webgui.json.JsonPostClient 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);
}
use of cz.metacentrum.perun.webgui.json.JsonPostClient in project perun by CESNET.
the class BanExecServiceOnFacility method banExecService.
/**
* Attempts to ban selected exec service on facility
*
* @param execServiceId
*/
public void banExecService(final int execServiceId) {
this.execServiceId = execServiceId;
// test arguments
if (!this.testCreating()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Blocking exec service " + execServiceId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Exec service " + execServiceId + " blocked on facility.");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, prepareJSONObject());
}
use of cz.metacentrum.perun.webgui.json.JsonPostClient 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);
}
Aggregations