use of cz.metacentrum.perun.webgui.json.JsonPostClient in project perun by CESNET.
the class CreateOwner method createOwner.
/**
* Attempts to create owner, it first tests the values and then submits them.
*
* @param ownerName name of future owner
* @param ownerContact owners contact (mail, phone, vo etc.)
* @param ownerType type of owner (administrative, technical)
*/
public void createOwner(final String ownerName, final String ownerContact, final String ownerType) {
this.ownerName = ownerName;
this.ownerContact = ownerContact;
this.ownerType = ownerType;
// test arguments
if (!this.testCreating()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Creating owner: " + ownerName + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Owner " + ownerName + " created.");
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 DeleteOwner method deleteOwner.
/**
* Attempts to delete owner, it first tests the values and then submits them.
*
* @param ownerId ID of owner to be deleted
*/
public void deleteOwner(final int ownerId) {
this.ownerId = ownerId;
// test arguments
if (!this.testDeleting()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Deleting Owner: " + ownerId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Owner " + ownerId + " deleted.");
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 UpdateUser method updateUser.
/**
* Updates user details
* @param user User with updated details
*/
public void updateUser(User user) {
if (user == null) {
UiElements.generateAlert("Parameter error", "User to update can't be null");
return;
}
// OBJECT
JSONObject oldUser = new JSONObject(user);
// RECONSTRUCT OBJECT
JSONObject newUser = new JSONObject();
newUser.put("id", oldUser.get("id"));
newUser.put("firstName", oldUser.get("firstName"));
newUser.put("middleName", oldUser.get("middleName"));
newUser.put("lastName", oldUser.get("lastName"));
newUser.put("titleBefore", oldUser.get("titleBefore"));
newUser.put("titleAfter", oldUser.get("titleAfter"));
newUser.put("serviceUser", oldUser.get("serviceUser"));
newUser.put("sponsoredUser", oldUser.get("sponsoredUser"));
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("user", newUser);
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Updating user failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
User u = jso.cast();
session.getUiElements().setLogSuccessText("User " + u.getFullNameWithTitles() + " 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 DeleteAttribute method deleteAttributeDefinition.
/**
* Deletes attribute definition from DB - make RPC call
*
* @param attrDefId - ID of attribute definition which should be deleted
*/
public void deleteAttributeDefinition(final int attrDefId) {
this.attrDefId = attrDefId;
// test arguments
if (!this.testDeleting()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Deleting attribute definition: " + attrDefId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Attribute definition: " + attrDefId + " sucessfully deleted.");
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 FillAttributes method fillAttributes.
/**
* Attempts to fill some attributes on entity
*
* @param ids defines which type of attribute will be filled (member_resource, resource etc.)
* @param attributes list of attributes to fill
*/
public void fillAttributes(final Map<String, Integer> ids, final ArrayList<Attribute> attributes) {
this.ids = ids;
this.attributes = attributes;
// test arguments
if (!this.testRemoving()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Filling attributes failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Attributes successfully filled !");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, prepareJSONObject());
}
Aggregations