use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class FindUsersByIdsNotInRpc method retrieveData.
/**
* Retrieves data from RPC
*/
public void retrieveData() {
String[] ids = searchString.split(",");
if (ids.length == 0) {
return;
}
idsCount = ids.length;
onLoadingStart();
for (String id : ids) {
// trims the whitespace
id = id.trim();
try {
int idint = Integer.parseInt(id);
GetEntityById req = new GetEntityById(PerunEntity.USER, idint, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
idsFound++;
// add to result
int i = result.size();
result.set(i, new JSONObject(jso));
isFinished();
}
public void onError(PerunError err) {
idsFound++;
isFinished();
}
});
req.retrieveData();
} catch (Exception e) {
}
}
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class RequestPreferredEmailChange method requestChange.
/**
* Request change of preferred email
*
* @param user
* @param email
*/
public void requestChange(final User user, final String email) {
this.user = user;
this.email = email;
// test arguments
if (!this.testRemoving()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Requesting change of preferred email failed.");
// custom events
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Request to change preferred email was submitted.");
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.JsonCallbackEvents in project perun by CESNET.
the class UpdateNameTitles method updateUserTitles.
/**
* Updates user details
* @param user User with updated details
*/
public void updateUserTitles(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"));
// 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.JsonCallbackEvents in project perun by CESNET.
the class RemoveAttributes method removeAttributes.
/**
* Attempts to remove some attributes from entity
*
* @param ids defines which type of attribute will be removed (member, user, member_resource, etc.)
* @param attributes list of attributes to remove
*/
public void removeAttributes(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("Removing attributes failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Attributes successfully removed !");
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.JsonCallbackEvents in project perun by CESNET.
the class CreateCategory method createCategory.
/**
* Attempts to create a new Category, it first tests the values and then submits them.
*
* @param name Category name
* @param rank Category ranking
*/
public void createCategory(final String name, double rank) {
this.name = name;
this.rank = rank;
// 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("Creating category " + name + " failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Category " + name + " created.");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
Aggregations