Search in sources :

Example 61 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError 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> " + app.getExtSourceLoa() + "</br><b>IdP category:</b> " + (!(error.getCategory().equals("")) ? error.getCategory() : "N/A") + "</br><b>Affiliation:</b> " + (!(error.getAffiliation().equals("")) ? error.getAffiliation().replace(";", ", ") : "N/A") + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
                } else {
                    layout.setHTML(0, 1, "<p>" + error.getErrorInfo() + ((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, user.getName());
                                if (user.getEmail() != null && !user.getEmail().isEmpty()) {
                                    ft.setHTML(i, 1, user.getEmail());
                                } else {
                                    ft.setHTML(i, 1, "N/A");
                                }
                                if (user.getOrganization() != null && !user.getOrganization().isEmpty()) {
                                    ft.setHTML(i, 2, user.getOrganization());
                                } 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);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FlexTable(com.google.gwt.user.client.ui.FlexTable) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) JSONString(com.google.gwt.json.client.JSONString) Image(com.google.gwt.user.client.ui.Image) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError) Identity(cz.metacentrum.perun.webgui.model.Identity)

Example 62 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class HandleApplication method rejectApplication.

/**
	 * Reject application
	 *
	 * @param appId
	 * @param reason
	 */
public void rejectApplication(int appId, String reason) {
    this.appId = appId;
    this.reason = reason;
    // test arguments
    if (!this.testApplication()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

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

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Application rejected.");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL_REJECT, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 63 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class CreateSpecificMember method createMember.

/**
	 * Attempts to create service member in VO
	 *
	 * @param voId vo where member should be created
	 * @param name name of service member
	 * @param email email of service member
	 * @param users list of real users
	 * @param namespace namespace to create login in
	 * @param login users login in namespace
	 * @param certDN users cert DN
	 * @param caCertDN users CA cert DN
	 */
public void createMember(final int voId, final String name, final String email, ArrayList<User> users, String namespace, String login, String certDN, String caCertDN, String specificUserType) {
    this.voId = voId;
    this.name = name;
    this.email = email;
    this.users = users;
    this.login = login;
    this.namespace = namespace;
    this.certDN = certDN;
    this.caCertDN = caCertDN;
    this.specificUserType = specificUserType;
    // test arguments
    if (!this.testAdding()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Creating member: " + name + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Member " + name + " created !");
            // call validation asynchronously
            Member mem = jso.cast();
            ValidateMemberAsync request = new ValidateMemberAsync();
            request.setHidden(true);
            request.validateMemberAsync(mem);
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError) Member(cz.metacentrum.perun.webgui.model.Member)

Example 64 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class DeleteMember method deleteMember.

/**
	 * Attempts to delete member in VO
	 *
	 * @param memberId ID of member which should be deleted
	 */
public void deleteMember(final int memberId) {
    this.memberId = memberId;
    // test arguments
    if (!this.testAdding()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Deleting member: " + memberId + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Member: " + memberId + " deleted!");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 65 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class DeleteTask method deleteTask.

/**
	 * Deletes Task from DB
	 *
	 * @param taskId id of Task to be deleted
	 */
public void deleteTask(final int taskId) {
    this.taskId = taskId;
    // test arguments
    if (!this.testArguments()) {
        return;
    }
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("task", new JSONNumber(taskId));
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Deleting of Task: " + taskId + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Task: " + taskId + " deleted successfully.");
            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) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

PerunError (cz.metacentrum.perun.webgui.model.PerunError)177 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)173 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)167 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)126 JSONObject (com.google.gwt.json.client.JSONObject)55 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)36 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)36 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)30 ArrayList (java.util.ArrayList)30 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)27 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)21 JSONNumber (com.google.gwt.json.client.JSONNumber)17 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)16 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)16 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)15 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)11 Attribute (cz.metacentrum.perun.webgui.model.Attribute)10 HashMap (java.util.HashMap)10 JSONString (com.google.gwt.json.client.JSONString)8 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)8