use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class HandleApplication method approveApplication.
/**
* Approve application
*
* @param app
*/
public void approveApplication(final Application app) {
this.appId = app.getId();
// test arguments
if (!this.testApplication()) {
return;
}
// new events
final JsonCallbackEvents newEvents = new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Approving application failed.");
events.onError(error);
}
@Override
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Application approved.");
events.onFinished(jso);
}
@Override
public void onLoadingStart() {
events.onLoadingStart();
}
};
final JSONObject appIdObj = new JSONObject();
appIdObj.put("appId", new JSONNumber(appId));
final JSONObject idObj = new JSONObject();
idObj.put("id", new JSONNumber(appId));
// check if can be approved
JsonPostClient jspc = new JsonPostClient(new JsonCallbackEvents() {
@Override
public void onError(final PerunError error) {
session.getUiElements().setLogErrorText("Checking approval failed.");
events.onError(error);
if (error == null) {
PerunError e = (PerunError) JsonUtils.parseJson("{\"errorId\":\"0\",\"name\":\"Cross-site request\",\"type\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteType() + "\",\"message\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteText() + "\"}").cast();
JsonErrorHandler.alertBox(e);
} else if (!error.getName().equals("CantBeApprovedException")) {
JsonErrorHandler.alertBox(error);
} else {
FlexTable layout = new FlexTable();
layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.errorIcon())));
if ("NOT_ACADEMIC".equals(error.getReason())) {
layout.setHTML(0, 1, "<p>User is not active academia member and application shouldn't be approved.<p><b>LoA:</b> " + SafeHtmlUtils.fromString(app.getExtSourceLoa() + "").asString() + "</br><b>IdP category:</b> " + (!(error.getCategory().equals("")) ? SafeHtmlUtils.fromString(error.getCategory()).asString() : "N/A") + "</br><b>Affiliation:</b> " + (!(error.getAffiliation().equals("")) ? SafeHtmlUtils.fromString(error.getAffiliation().replace(";", ", ")).asString() : "N/A") + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
}
if ("NOT_ELIGIBLE".equals(error.getReason())) {
layout.setHTML(0, 1, "<p>User is not eligible for CESNET services and application shouldn't be approved." + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
} else {
layout.setHTML(0, 1, "<p>" + SafeHtmlUtils.fromString(error.getErrorInfo()).asString() + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
}
layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
if (error.isSoft()) {
Confirm c = new Confirm("Application shouldn't be approved", layout, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// ok approve sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
}
}, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
events.onFinished(null);
}
}, true);
c.setOkButtonText("Approve anyway");
c.setNonScrollable(true);
c.show();
} else {
Confirm c = new Confirm("Application can't be approved", layout, true);
c.setNonScrollable(true);
c.show();
}
}
}
@Override
public void onFinished(JavaScriptObject jso) {
if (app.getUser() != null) {
// ok approve sending data
JsonPostClient jspc2 = new JsonPostClient(newEvents);
jspc2.sendData(JSON_URL_APPROVE, prepareJSONObject());
} else {
JsonPostClient checkJspc = new JsonPostClient(new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Approving application failed.");
events.onError(error);
}
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Identity> users = JsonUtils.jsoAsList(jso);
if (users != null && !users.isEmpty()) {
FlexTable ft = new FlexTable();
ft.setWidth("600px");
ft.setHTML(0, 0, "<p><strong>Following similar user(s) were found in system:");
ft.getFlexCellFormatter().setColSpan(0, 0, 3);
ft.setHTML(1, 0, "<strong>" + ApplicationMessages.INSTANCE.name() + "</strong>");
ft.setHTML(1, 1, "<strong>" + ApplicationMessages.INSTANCE.email() + "</strong>");
ft.setHTML(1, 2, "<strong>" + ApplicationMessages.INSTANCE.organization() + "</strong>");
int i = 2;
for (Identity user : users) {
ft.setHTML(i, 0, SafeHtmlUtils.fromString(user.getName()).asString());
if (user.getEmail() != null && !user.getEmail().isEmpty()) {
ft.setHTML(i, 1, SafeHtmlUtils.fromString(user.getEmail()).asString());
} else {
ft.setHTML(i, 1, "N/A");
}
if (user.getOrganization() != null && !user.getOrganization().isEmpty()) {
ft.setHTML(i, 2, SafeHtmlUtils.fromString(user.getOrganization()).asString());
} else {
ft.setHTML(i, 2, "N/A");
}
i++;
}
String type = "";
if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
type = "cert";
} else if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceIdp")) {
type = "fed";
}
ft.setHTML(i, 0, "<p>Please contact new applicant with question, if he/she isn't already member of any other VO." + "<ul><li>If YES, ask him/her to join identities at <a href=\"" + Utils.getIdentityConsolidatorLink(type, false) + "\" target=\"_blank\">identity consolidator</a> before approving this application." + "</li><li>If NO, you can approve this application anyway. " + "</li><li>If UNSURE, contact <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">support</a> to help you.</li></ul>");
ft.getFlexCellFormatter().setColSpan(i, 0, 3);
i++;
ft.setHTML(i, 0, "<strong>Do you wish to approve this application anyway ?</strong>");
ft.getFlexCellFormatter().setColSpan(i, 0, 3);
Confirm c = new Confirm("Similar users found!", ft, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// ok approve sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
}
}, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
events.onFinished(null);
}
}, true);
c.setOkButtonText("Approve");
c.setNonScrollable(true);
c.show();
} else {
// ok approve sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
}
}
@Override
public void onLoadingStart() {
events.onLoadingStart();
}
});
checkJspc.sendData("registrarManager/checkForSimilarUsers", appIdObj);
}
}
@Override
public void onLoadingStart() {
events.onLoadingStart();
}
});
// we have own error handling
jspc.setHidden(true);
jspc.sendData(JSON_URL_CHECK, idObj);
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class SendInvitation method inviteUser.
/**
* Send request to invite user
*/
public void inviteUser(String email, String name, String language) {
if (email == null || email.isEmpty()) {
UiElements.generateAlert("Input error", "Email address to send invitation to is empty.");
return;
}
if (!JsonUtils.isValidEmail(email)) {
UiElements.generateAlert("Input error", "Email address format is not valid.");
return;
}
/*
if (name == null || name.isEmpty()) {
UiElements.generateAlert("Input error", "Name of user to invite can't be empty.");
return;
}
*/
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Inviting user failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("User invited.");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// query
JSONObject query = new JSONObject();
query.put("voId", new JSONNumber(voId));
if (groupId != 0) {
query.put("groupId", new JSONNumber(groupId));
}
if (name != null && !name.isEmpty())
query.put("name", new JSONString(name));
query.put("email", new JSONString(email));
if (language != null && !language.isEmpty()) {
query.put("language", new JSONString(language));
} else {
query.put("language", new JSONObject(null));
}
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, query);
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class ValidateMemberAsync method validateMemberAsync.
/**
* Attempts to create member in VO from candidate
*
* @param member
*/
public void validateMemberAsync(final Member member) {
this.member = member;
// test arguments
if (!this.testAdding()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Validating member: " + member.getId() + " failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Member " + member.getId() + " validated !");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.setHidden(hidden);
jspc.sendData(JSON_URL, prepareJSONObject());
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents 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.JsonCallbackEvents in project perun by CESNET.
the class AddApplicationMail method addMail.
/**
* Adds new ApplicationMail
*
* @param appMail
* @param id
*/
public void addMail(ApplicationMail appMail, int id) {
this.appMail = appMail;
this.id = id;
// test arguments
if (!this.testCreating()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding email failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Email added.");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, prepareJSONObject());
}
Aggregations