Search in sources :

Example 6 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class CreateServiceMemberInVoTabItem method draw.

public Widget draw() {
    titleWidget.setText("Create service member");
    final TabItem tab = this;
    // draw the main tab
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    final ExtendedTextBox serviceUserName = new ExtendedTextBox();
    final ExtendedTextBox serviceUserEmail = new ExtendedTextBox();
    final ExtendedTextBox serviceUserLogin = new ExtendedTextBox();
    final ExtendedPasswordBox serviceUserPassword = new ExtendedPasswordBox();
    final ExtendedPasswordBox serviceUserPassword2 = new ExtendedPasswordBox();
    final ListBox namespace = new ListBox();
    final ExtendedTextBox certDN = new ExtendedTextBox();
    final ExtendedTextBox cacertDN = new ExtendedTextBox();
    final String serviceType = "SERVICE";
    serviceUserPassword.getTextBox().setWidth("200px");
    serviceUserPassword2.getTextBox().setWidth("200px");
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceUserName.getTextBox().getValue().trim().isEmpty()) {
                serviceUserName.setError("Name can't be empty!");
                return false;
            }
            serviceUserName.setOk();
            return true;
        }
    };
    serviceUserName.setValidator(nameValidator);
    final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (namespace.getSelectedIndex() == 0) {
                // do not validate if namespace is not selected
                serviceUserLogin.getTextBox().setValue(null);
                serviceUserLogin.setOk();
                return true;
            }
            if (serviceUserLogin.getTextBox().getValue().trim().isEmpty()) {
                serviceUserLogin.setError("Login can't be empty!");
                return false;
            }
            RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
            boolean match = regExp.test(serviceUserLogin.getTextBox().getValue().trim());
            if (!match) {
                serviceUserLogin.setError("Invalid format!");
                return false;
            }
            if (serviceUserLogin.isProcessing() || serviceUserLogin.isHardError()) {
                // keep original message
                return false;
            }
            serviceUserLogin.setOk();
            return true;
        }
    };
    serviceUserLogin.setValidator(loginValidator);
    final ExtendedTextBox.TextBoxValidator emailValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.isValidEmail(serviceUserEmail.getTextBox().getValue().trim())) {
                serviceUserEmail.setError("Wrong email format!");
                return false;
            }
            serviceUserEmail.setOk();
            return true;
        }
    };
    serviceUserEmail.setValidator(emailValidator);
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceUserPassword.getTextBox().getValue().trim().equals("")) {
                serviceUserPassword.setError("Password can't be empty!");
                return false;
            }
            // einfra check
            if ("einfra".equals(namespace.getSelectedValue())) {
                RegExp regExp2 = RegExp.compile("^[\\x20-\\x7E]{1,}$");
                if (regExp2.exec(serviceUserPassword.getTextBox().getValue()) == null) {
                    serviceUserPassword.setError("Password <b>can`t contain accented characters (diacritics)</b> or non-printing and control characters!");
                    return false;
                }
                // check on login in password if login is longer than 2 chars
                // TODO - check for name/surname too
                String pass = serviceUserPassword.getTextBox().getValue();
                String login = serviceUserLogin.getTextBox().getValue();
                if (login.length() > 2) {
                    if (Utils.normalizeString(pass).contains(Utils.normalizeString(login)) || Utils.normalizeString(pass).contains(Utils.normalizeString(Utils.reverseString((login))))) {
                        serviceUserPassword.setError("Password <b>can't contain login, name or surname</b>, not even backwards!");
                        return false;
                    }
                }
                // Check that password contains at least 3 of 4 character groups
                RegExp regExpDigit = RegExp.compile("^.*[0-9].*$");
                RegExp regExpLower = RegExp.compile("^.*[a-z].*$");
                RegExp regExpUpper = RegExp.compile("^.*[A-Z].*$");
                // FIXME - are those correct printable specific chars?
                RegExp regExpSpec = RegExp.compile("^.*[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E].*$");
                int matchCounter = 0;
                if (regExpDigit.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpLower.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpUpper.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpSpec.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (matchCounter < 3) {
                    serviceUserPassword.setError("Password must consist of <b>at least 3 of 4</b> character groups<ul><li>lower-case letters</li><li>upper-case letters</li><li>digits</li><li>special characters</li></ul>");
                    return false;
                }
                // check length
                if (serviceUserPassword.getTextBox().getValue().length() < 10) {
                    serviceUserPassword.setError("Password must be <b>at least 10 characters</b> long!");
                    return false;
                }
            }
            if (!serviceUserPassword.getTextBox().getValue().equals(serviceUserPassword2.getTextBox().getValue())) {
                serviceUserPassword.setOk();
                serviceUserPassword2.setError("Password in both textboxes must be the same!");
                return false;
            }
            serviceUserPassword.setOk();
            return true;
        }
    };
    serviceUserPassword.setValidator(validator);
    final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!serviceUserPassword2.getTextBox().getValue().equals(serviceUserPassword.getTextBox().getValue())) {
                serviceUserPassword2.setError("Password in both textboxes must be the same!");
                return false;
            } else {
                serviceUserPassword2.setOk();
                return true;
            }
        }
    };
    serviceUserPassword2.setValidator(validator2);
    /*
		final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (serviceUserPassword.getTextBox().getValue().trim().isEmpty()) {
					serviceUserPassword.setError("Password can't be empty !");
					return false;
				} else if (!serviceUserPassword.getTextBox().getValue().equals(serviceUserPassword2.getTextBox().getValue())) {
					serviceUserPassword.setError("Password in both textboxes must be the same !");
					return false;
				} else {
					serviceUserPassword.setOk();
					serviceUserPassword2.setOk();
					return true;
				}
			}
		};
		serviceUserPassword.setValidator(validator);

		final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (serviceUserPassword2.getTextBox().getValue().trim().isEmpty()) {
					serviceUserPassword2.setError("Password can't be empty !");
					return false;
				} else if (!serviceUserPassword2.getTextBox().getValue().equals(serviceUserPassword.getTextBox().getValue())) {
					serviceUserPassword2.setError("Password in both textboxes must be the same !");
					return false;
				} else {
					serviceUserPassword2.setOk();
					serviceUserPassword.setOk();
					return true;
				}
			}
		};
		serviceUserPassword2.setValidator(validator2);
		*/
    final ExtendedTextBox.TextBoxValidator certDNValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if ((certDN.getTextBox().getValue().trim().isEmpty() && cacertDN.getTextBox().getValue().trim().isEmpty()) || (!certDN.getTextBox().getValue().trim().isEmpty() && !cacertDN.getTextBox().getValue().trim().isEmpty())) {
                certDN.setOk();
                cacertDN.setOk();
                return true;
            } else {
                if (certDN.getTextBox().getValue().trim().isEmpty()) {
                    certDN.setError("Value can't be empty!");
                }
                if (cacertDN.getTextBox().getValue().trim().isEmpty()) {
                    cacertDN.setError("Value can't be empty!");
                }
            }
            return false;
        }
    };
    certDN.setValidator(certDNValidator);
    cacertDN.setValidator(certDNValidator);
    // make value empty
    namespace.addItem("Not selected", "");
    for (String name : Utils.getSupportedPasswordNamespaces()) {
        namespace.addItem(name.toUpperCase(), name);
    }
    final FlexTable layout = new FlexTable();
    layout.setCellPadding(5);
    layout.setHTML(0, 0, "<h3>1. Create service identity</h3>");
    layout.getFlexCellFormatter().setColSpan(0, 0, 3);
    layout.setHTML(1, 0, "<strong>Member's name: </strong>");
    layout.setWidget(1, 1, serviceUserName);
    layout.setHTML(2, 0, "<strong>Member's email: </strong>");
    layout.setWidget(2, 1, serviceUserEmail);
    layout.setHTML(3, 0, "<strong>Namespace: </strong>");
    layout.setWidget(3, 1, namespace);
    layout.setHTML(4, 0, "<strong>Login: </strong>");
    layout.setWidget(4, 1, serviceUserLogin);
    final Label label = new Label("You will be assigned with available login");
    label.setVisible(false);
    layout.setWidget(5, 0, label);
    layout.getFlexCellFormatter().setStyleName(5, 0, "inputFormInlineComment");
    layout.getFlexCellFormatter().setColSpan(5, 0, 2);
    layout.setHTML(6, 0, "<strong>Subject DN: </strong>");
    layout.setWidget(6, 1, certDN);
    layout.setHTML(7, 0, "<strong>Issuer DN: </strong>");
    layout.setWidget(7, 1, cacertDN);
    final FlexTable firstTabLayout = new FlexTable();
    firstTabLayout.setSize("100%", "100%");
    firstTabLayout.setVisible(false);
    final AddRemoveItemsTable<User> itemsTable = new AddRemoveItemsTable<User>(true);
    itemsTable.addItem(session.getUser());
    final VerticalPanel secondTabPanel = new VerticalPanel();
    secondTabPanel.setSize("100%", "100%");
    secondTabPanel.setVisible(false);
    mainTab.add(layout);
    mainTab.add(firstTabLayout);
    mainTab.add(secondTabPanel);
    // disable login by default (first option)
    serviceUserLogin.getTextBox().setEnabled(false);
    final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            // check
            if (!namespace.getSelectedValue().equals("mu") && namespace.getSelectedIndex() != 0 && !loginValidator.validateTextBox())
                return;
            if (!nameValidator.validateTextBox())
                return;
            if (!emailValidator.validateTextBox())
                return;
            if (!certDNValidator.validateTextBox())
                return;
            // change to lager tab
            session.getTabManager().changeStyleOfInnerTab(true);
            // first tab panel
            firstTabLayout.setHTML(0, 0, "<h3>2. Associate real users</h3>");
            firstTabLayout.getFlexCellFormatter().setColSpan(0, 0, 2);
            layout.setVisible(false);
            firstTabLayout.setVisible(true);
            final FindUsersInVo callback = new FindUsersInVo();
            // Service users can't own another Service or Guest (Sponsored) account.
            callback.hideService(true);
            // HORIZONTAL MENU
            TabMenu tabMenu = new TabMenu();
            // get the table
            final CellTable<User> table = callback.getTable();
            // search textbox
            ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

                @Override
                public void searchFor(String text) {
                    callback.searchFor(text, voId);
                    searchString = text;
                }
            }, ButtonTranslation.INSTANCE.searchUsers());
            final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.arrowRightIcon());
            cb.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent clickEvent) {
                    // check
                    if (itemsTable.getList().isEmpty()) {
                        new Confirm("No user associated", new HTML("You must associate at least one real user to service member."), true).show();
                        return;
                    }
                    // create member + user
                    CreateSpecificMember request = new CreateSpecificMember(JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            final Member member = jso.cast();
                            for (User u : itemsTable.getList()) {
                                if (u.getId() == session.getUser().getId()) {
                                    // set local authz if one of associated users is us
                                    session.addEditableUser(member.getUserId());
                                }
                            }
                            if (namespace.getSelectedIndex() == 0) {
                                // we didn't set login, hence skip password setting
                                session.getTabManager().closeTab(tab, true);
                                return;
                            }
                            // change to small tab
                            session.getTabManager().changeStyleOfInnerTab(false);
                            secondTabPanel.add(new HTML("<h3>3.Set password for: " + serviceUserLogin.getTextBox().getValue().trim() + "</h3>"));
                            final CustomButton button = new CustomButton("Set password", SmallIcons.INSTANCE.keyIcon());
                            button.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent clickEvent) {
                                    if (!validator.validateTextBox() || !validator2.validateTextBox()) {
                                        // one of input boxes for passwords is wrong
                                        return;
                                    }
                                    final String namespaceValue = namespace.getSelectedValue();
                                    if ("mu".equals(namespaceValue)) {
                                        final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                BasicOverlayType basic = jso.cast();
                                                final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                                                SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                    @Override
                                                    public void onFinished(JavaScriptObject jso) {
                                                        // VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
                                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                            @Override
                                                            public void onFinished(JavaScriptObject jso) {
                                                                // validate member when all kerberos logins are set
                                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                                req2.validateMemberAsync(member);
                                                            }
                                                        }));
                                                        // validate login returned from account generation
                                                        req.validatePassword(member.getUserId(), login, namespaceValue);
                                                        // show assigned login
                                                        UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                                    }

                                                    @Override
                                                    public void onError(PerunError error) {
                                                        UiElements.generateError(error, "Saving login failed", "You were assigned with login <b>" + login + "</b> in namespace MU but saving it to user failed. <b>Please copy your login and contact support at <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">" + Utils.perunReportEmailAddress() + "</a>.</b>");
                                                        // validate member when all logins are set
                                                        ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                        req2.validateMemberAsync(member);
                                                    }
                                                }));
                                                setLogin.setLogin(member.getUserId(), "mu", login);
                                            }
                                        }));
                                        final Map<String, String> params = new HashMap<String, String>();
                                        GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                RichMember rm = jso.cast();
                                                params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
                                                params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
                                                params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
                                                req.generateAccount(namespaceValue, serviceUserPassword.getTextBox().getValue(), params);
                                            }
                                        }));
                                        get.retrieveData();
                                    } else {
                                        // create password which sets also user ext sources
                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                // validate member when all kerberos logins are set
                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                req2.validateMemberAsync(member);
                                            }
                                        }));
                                        req.createPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue, serviceUserPassword.getTextBox().getValue());
                                    }
                                }
                            });
                            final CustomButton skipButton = new CustomButton("Skip", SmallIcons.INSTANCE.arrowRightIcon());
                            skipButton.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent clickEvent) {
                                    final String namespaceValue = namespace.getSelectedValue();
                                    if ("mu".equals(namespaceValue)) {
                                        final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                BasicOverlayType basic = jso.cast();
                                                final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                                                SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                    @Override
                                                    public void onFinished(JavaScriptObject jso) {
                                                        // VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
                                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                            @Override
                                                            public void onFinished(JavaScriptObject jso) {
                                                                // validate member when all kerberos logins are set
                                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                                req2.validateMemberAsync(member);
                                                            }
                                                        }));
                                                        // validate login returned from account generation
                                                        req.validatePassword(member.getUserId(), login, namespaceValue);
                                                        // show assigned login
                                                        UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                                    }

                                                    @Override
                                                    public void onError(PerunError error) {
                                                        // validate member when all logins are set
                                                        ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                        req2.validateMemberAsync(member);
                                                    }
                                                }));
                                                setLogin.setLogin(member.getUserId(), "mu", login);
                                            }
                                        }));
                                        final Map<String, String> params = new HashMap<String, String>();
                                        GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                RichMember rm = jso.cast();
                                                params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
                                                params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
                                                params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
                                                req.generateAccount(namespaceValue, null, params);
                                            }
                                        }));
                                        get.retrieveData();
                                    } else {
                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(skipButton, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                // validate member when all kerberos logins are set
                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(skipButton, tab, true));
                                                req2.validateMemberAsync(member);
                                            }
                                        }));
                                        // set empty password for service member if "skipped"
                                        req.createRandomPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue);
                                    }
                                }
                            });
                            FlexTable ft = new FlexTable();
                            ft.setStyleName("inputFormFlexTable");
                            ft.setWidth("400px");
                            ft.setHTML(0, 0, "Password:");
                            ft.setWidget(0, 1, serviceUserPassword);
                            ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
                            ft.setHTML(1, 0, "Re-type&nbsp;password:");
                            ft.setWidget(1, 1, serviceUserPassword2);
                            ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
                            if ("einfra".equals(namespace.getSelectedValue())) {
                                ft.setHTML(2, 0, "Password must <ul><li>contain only printing (non-accented) characters<li>be at least 10 characters long<li>consist of at least 3 of 4 character groups<ul><li>lower-case letters<li>upper-case letters<li>digits<li>special characters</ul></ul>");
                            } else {
                                ft.setHTML(2, 0, "Please <b>avoid using accented characters</b>. It might not be supported by all backend components and services.");
                            }
                            ft.getFlexCellFormatter().setColSpan(2, 0, 2);
                            ft.getCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
                            ft.setWidget(3, 1, skipButton);
                            ft.getFlexCellFormatter().addStyleName(3, 1, "align-right");
                            ft.setWidget(4, 1, button);
                            ft.getFlexCellFormatter().addStyleName(4, 1, "align-right");
                            secondTabPanel.add(ft);
                            // hide 2nd panel
                            firstTabLayout.setVisible(false);
                            // show 3rd panel
                            secondTabPanel.setVisible(true);
                        }
                    }));
                    request.createMember(voId, serviceUserName.getTextBox().getValue().trim(), serviceUserEmail.getTextBox().getValue().trim(), itemsTable.getList(), namespace.getValue(namespace.getSelectedIndex()), serviceUserLogin.getTextBox().getValue().trim(), certDN.getTextBox().getValue().trim(), cacertDN.getTextBox().getValue().trim(), serviceType);
                }
            });
            // we have ourselves already assigned
            // cb.setEnabled(false);
            CustomButton button = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected users to service member");
            button.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent clickEvent) {
                    ArrayList<User> list = callback.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        // skip self
                        ArrayList<User> list2 = new ArrayList<User>();
                        for (User user : list) {
                            if (user != null && user.getId() != session.getUser().getId()) {
                                list2.add(user);
                            }
                        }
                        itemsTable.addItems(list2);
                        cb.setEnabled(true);
                        callback.clearTableSelectedSet();
                    }
                }
            });
            button.setEnabled(false);
            tabMenu.addWidget(button);
            JsonUtils.addTableManagedButton(callback, table, button);
            // add finish button to menu
            tabMenu.addWidget(cb);
            // if some text has been searched before
            if (!searchString.equals("")) {
                searchBox.getTextBox().setText(searchString);
                callback.searchFor(searchString, voId);
            }
            final ScrollPanel sp = new ScrollPanel(table);
            table.addStyleName("perun-table");
            sp.addStyleName("perun-tableScrollPanel");
            session.getUiElements().resizeSmallTabPanel(sp, 350, tab);
            firstTabLayout.setWidget(1, 0, tabMenu);
            firstTabLayout.setWidget(2, 0, sp);
            firstTabLayout.setHTML(1, 1, "<h3>To be associated:</h3>");
            firstTabLayout.setWidget(2, 1, itemsTable);
            firstTabLayout.getFlexCellFormatter().setWidth(2, 0, "75%");
            firstTabLayout.getFlexCellFormatter().setWidth(2, 1, "25%");
            firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 1, HasVerticalAlignment.ALIGN_TOP);
            firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_TOP);
            // actions when added items or removed items
            itemsTable.setEvents(new AddRemoveItemsTable.HandleItemsAction<User>() {

                @Override
                public void onAdd(User object) {
                    cb.setEnabled(true);
                }

                @Override
                public void onRemove(User object) {
                    if (object.equals(session.getUser())) {
                        itemsTable.addItem(object);
                        UiElements.generateInfo("Can't remove yourself", "<p>You can't remove yourself yet. You wouldn't be able to finish service member configuration. Please remove yourself afterwards.");
                    }
                    if (itemsTable.getList().isEmpty()) {
                        cb.setEnabled(false);
                    }
                }
            });
        }
    });
    // check login availability
    serviceUserLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent keyUpEvent) {
            if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
                // do not trigger when no text input
                return;
            }
            final String login = serviceUserLogin.getTextBox().getValue().trim();
            final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
            // trigger new validation on checked input or if previously was hard error
            if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
                new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            BasicOverlayType bo = jso.cast();
                            serviceUserLogin.setProcessing(false);
                            if (!bo.getBoolean()) {
                                serviceUserLogin.setHardError("Login is already in use!");
                            } else {
                                serviceUserLogin.removeHardError();
                                loginValidator.validateTextBox();
                            }
                        }
                    }

                    @Override
                    public void onLoadingStart() {
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            serviceUserLogin.removeHardError();
                            serviceUserLogin.setProcessing(true);
                        }
                    }

                    @Override
                    public void onError(PerunError error) {
                        // response is relevant to current value
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
                                serviceUserLogin.setProcessing(false);
                                String text = error.getErrorInfo();
                                text = text.split(":", 2)[1];
                                text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
                                serviceUserLogin.setHardError(text);
                            } else {
                                // generic error
                                serviceUserLogin.setProcessing(false);
                                serviceUserLogin.setHardError("Unable to check if login is available!");
                            }
                        }
                    }
                }).retrieveData();
            }
        }
    });
    namespace.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (namespace.getSelectedIndex() == 0) {
                // do not set login
                serviceUserLogin.getTextBox().setEnabled(false);
                serviceUserLogin.getTextBox().setValue(null);
                loginValidator.validateTextBox();
                label.setVisible(false);
            } else if (namespace.getSelectedValue().equals("mu")) {
                serviceUserLogin.getTextBox().setEnabled(false);
                label.setVisible(true);
            } else {
                serviceUserLogin.getTextBox().setEnabled(true);
                label.setVisible(false);
            }
            if (namespace.getSelectedIndex() != 0) {
                // do not check login if not desired to set
                final String login = serviceUserLogin.getTextBox().getValue().trim();
                final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
                if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
                    new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
                            if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                                serviceUserLogin.setProcessing(false);
                                BasicOverlayType bo = jso.cast();
                                if (!bo.getBoolean()) {
                                    serviceUserLogin.setHardError("Login is already in use!");
                                } else {
                                    serviceUserLogin.removeHardError();
                                    loginValidator.validateTextBox();
                                }
                            }
                        }

                        @Override
                        public void onLoadingStart() {
                            if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                                serviceUserLogin.removeHardError();
                                serviceUserLogin.setProcessing(true);
                                loginValidator.validateTextBox();
                            }
                        }

                        @Override
                        public void onError(PerunError error) {
                            // response is relevant to current value
                            if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                                if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
                                    serviceUserLogin.setProcessing(false);
                                    String text = error.getErrorInfo();
                                    text = text.split(":", 2)[1];
                                    text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
                                    serviceUserLogin.setHardError(text);
                                } else {
                                    // generic error
                                    serviceUserLogin.setProcessing(false);
                                    serviceUserLogin.setHardError("Unable to check if login is available!");
                                }
                            }
                        }
                    }).retrieveData();
                }
            }
        }
    });
    if (session.isPerunAdmin()) {
        layout.setWidget(9, 0, cb);
        layout.getFlexCellFormatter().setHorizontalAlignment(9, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        layout.getFlexCellFormatter().setColSpan(9, 0, 2);
    } else {
        layout.setWidget(8, 0, cb);
        layout.getFlexCellFormatter().setHorizontalAlignment(8, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        layout.getFlexCellFormatter().setColSpan(8, 0, 2);
    }
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) IsLoginAvailable(cz.metacentrum.perun.webgui.json.usersManager.IsLoginAvailable) CellTable(com.google.gwt.user.cellview.client.CellTable) GenerateAccount(cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount) CreatePassword(cz.metacentrum.perun.webgui.json.usersManager.CreatePassword) ValidateMemberAsync(cz.metacentrum.perun.webgui.json.membersManager.ValidateMemberAsync) CreateSpecificMember(cz.metacentrum.perun.webgui.json.membersManager.CreateSpecificMember) RegExp(com.google.gwt.regexp.shared.RegExp) CreateSpecificMember(cz.metacentrum.perun.webgui.json.membersManager.CreateSpecificMember) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) HashMap(java.util.HashMap) Map(java.util.Map) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FindUsersInVo(cz.metacentrum.perun.webgui.json.membersManager.FindUsersInVo) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) SetLogin(cz.metacentrum.perun.webgui.json.usersManager.SetLogin) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 7 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class FacilityDetailTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()));
    // main widget panel
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    AbsolutePanel dp = new AbsolutePanel();
    final FlexTable menu = new FlexTable();
    menu.setCellSpacing(5);
    // Add facility information
    menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.databaseServerIcon()));
    Label facilityName = new Label();
    facilityName.setText(Utils.getStrippedStringWithEllipsis(facility.getName(), 40));
    facilityName.setStyleName("now-managing");
    facilityName.setTitle(facility.getName());
    menu.setWidget(0, 1, facilityName);
    menu.setHTML(0, 2, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, 2, "25px");
    int column = 3;
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            new GetEntityById(PerunEntity.FACILITY, facilityId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    facility = jso.cast();
                    open();
                    draw();
                }
            }).retrieveData();
        }
    };
    CustomButton change = new CustomButton("", ButtonTranslation.INSTANCE.editFacilityDetails(), SmallIcons.INSTANCE.applicationFormEditIcon());
    change.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // prepare confirm content
            session.getTabManager().addTabToCurrentTab(new EditFacilityDetailsTabItem(facility, events));
        }
    });
    menu.setWidget(0, column, change);
    column++;
    menu.setHTML(0, column, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, column, "25px");
    column++;
    if (JsonUtils.isExtendedInfoVisible()) {
        menu.setHTML(0, column, "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">" + facility.getId() + "</span>");
        column++;
        menu.setHTML(0, column, "&nbsp;");
        menu.getFlexCellFormatter().setWidth(0, column, "25px");
        column++;
    }
    menu.setHTML(0, column, "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">" + SafeHtmlUtils.fromString((facility.getDescription() != null) ? facility.getDescription() : "").asString() + "&nbsp;</span>");
    dp.add(menu);
    vp.add(dp);
    vp.setCellHeight(dp, "30px");
    // TAB PANEL
    tabPanel.clear();
    tabPanel.add(new FacilityResourcesTabItem(facility), "Resources");
    tabPanel.add(new FacilityAllowedGroupsTabItem(facility), "Allowed Groups");
    tabPanel.add(new FacilityStatusTabItem(facility), "Services status");
    tabPanel.add(new FacilitySettingsTabItem(facility), "Services settings");
    tabPanel.add(new FacilityDestinationsTabItem(facility), "Services destinations");
    tabPanel.add(new FacilityHostsTabItem(facility), "Hosts");
    tabPanel.add(new FacilityManagersTabItem(facility), "Managers");
    tabPanel.add(new FacilitySecurityTeamsTabItem(facility), "Security teams");
    tabPanel.add(new FacilityBlacklistTabItem(facility), "Blacklist");
    tabPanel.add(new FacilityOwnersTabItem(facility), "Owners");
    // Resize must be called after page fully displays
    Scheduler.get().scheduleDeferred(new Command() {

        @Override
        public void execute() {
            tabPanel.finishAdding();
        }
    });
    vp.add(tabPanel);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Command(com.google.gwt.user.client.Command)

Example 8 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class GroupDetailTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()));
    // main panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // The table
    AbsolutePanel dp = new AbsolutePanel();
    // dp.setStyleName("decoration");
    final FlexTable menu = new FlexTable();
    menu.setCellSpacing(5);
    // Add group information
    menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.groupIcon()));
    Label groupName = new Label();
    groupName.setText(Utils.getStrippedStringWithEllipsis(group.getName(), 40));
    groupName.setStyleName("now-managing");
    groupName.setTitle(group.getName());
    menu.setWidget(0, 1, groupName);
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            new GetEntityById(PerunEntity.RICH_GROUP, groupId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    group = jso.cast();
                    open();
                    draw();
                }
            }).retrieveData();
        }
    };
    menu.setHTML(0, 2, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, 2, "25px");
    int column = 3;
    CustomButton change;
    if (group.isCoreGroup()) {
        change = new CustomButton("", "Core group's name and description can't be changed", SmallIcons.INSTANCE.applicationFormEditIcon());
        change.setEnabled(false);
    } else {
        change = new CustomButton("", ButtonTranslation.INSTANCE.editGroupDetails(), SmallIcons.INSTANCE.applicationFormEditIcon());
    }
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        change.setEnabled(false);
    change.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new EditGroupDetailsTabItem(group, events));
        }
    });
    menu.setWidget(0, column, change);
    column++;
    menu.setHTML(0, column, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, column, "25px");
    column++;
    if (JsonUtils.isExtendedInfoVisible()) {
        menu.setHTML(0, column, "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">" + group.getId() + "</span>");
        column++;
        menu.setHTML(0, column, "&nbsp;");
        menu.getFlexCellFormatter().setWidth(0, column, "25px");
        column++;
    }
    /*
		String text = (((RichGroup)group).isSyncEnabled()) ? "Enabled" : "Disabled";

		text += (((RichGroup)group).getAuthoritativeGroup().equals("1")) ? " / Authoritative" : "";

		menu.setHTML(0, column, "<strong>Sync:</strong><br/><span class=\"inputFormInlineComment\">"+text+"</span>");

		column++;
		*/
    menu.setHTML(0, column, "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">" + SafeHtmlUtils.fromString((group.getDescription() != null) ? group.getDescription() : "").asString() + "&nbsp;</span>");
    dp.add(menu);
    vp.add(dp);
    vp.setCellHeight(dp, "30px");
    tabPanel.clear();
    tabPanel.add(new GroupMembersTabItem(group), "Members");
    if (!group.isCoreGroup()) {
        tabPanel.add(new SubgroupsTabItem(group), "Subgroups");
        tabPanel.add(new GroupRelationsTabItem(group), "Relations");
    }
    tabPanel.add(new GroupResourcesTabItem(group), "Resources");
    if (!group.isCoreGroup()) {
        tabPanel.add(new GroupApplicationsTabItem(group), "Applications");
        tabPanel.add(new GroupApplicationFormSettingsTabItem(group), "Application form");
    }
    tabPanel.add(new GroupSettingsTabItem(group), "Settings");
    if (!group.isCoreGroup()) {
        // core groups can't have managers
        tabPanel.add(new GroupManagersTabItem(group), "Managers");
    }
    if (!group.isCoreGroup()) {
        // core groups can't have ext sources
        tabPanel.add(new GroupExtSourcesTabItem(group), "External sources");
    }
    // Resize must be called after page fully displays
    Scheduler.get().scheduleDeferred(new Command() {

        @Override
        public void execute() {
            tabPanel.finishAdding();
        }
    });
    vp.add(tabPanel);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Command(com.google.gwt.user.client.Command) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById)

Example 9 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class GroupDetailTabItem method open.

public void open() {
    session.getUiElements().getMenu().openMenu(MainMenu.GROUP_ADMIN);
    if (vo == null) {
        new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                vo = jso.cast();
                session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "VO: " + vo.getName(), VosTabs.URL + UrlMapper.TAB_NAME_SEPARATOR + "detail?id=" + vo.getId(), "Group: " + group.getName(), getUrlWithParameters());
            }

            @Override
            public void onError(PerunError error) {
                session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "Group: " + group.getName(), getUrlWithParameters());
            }
        }).retrieveData();
    } else {
        session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "VO: " + vo.getName(), VosTabs.URL + UrlMapper.TAB_NAME_SEPARATOR + "detail?id=" + vo.getId(), "Group: " + group.getName(), getUrlWithParameters());
    }
    if (group != null) {
        session.setActiveGroup(group);
    } else {
        session.setActiveGroupId(groupId);
    }
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 10 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class GetAllRichSubGroups method getTable.

/**
 * Returns the table with subgroups.
 * @return
 */
public CellTable<RichGroup> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<RichGroup>(list);
    // Cell table
    table = new PerunTable<RichGroup>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<RichGroup> columnSortHandler = new ListHandler<RichGroup>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichGroup>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("Group has no sub-groups.");
    // checkbox column column
    table.addCheckBoxColumn();
    table.addIdColumn("Group ID", tableFieldUpdater);
    // Add a synchronization clicable icon column.
    Column<RichGroup, RichGroup> syncColumn = new Column<RichGroup, RichGroup>(new CustomClickableInfoCellWithImageResource("click")) {

        @Override
        public RichGroup getValue(RichGroup object) {
            return object;
        }

        @Override
        public String getCellStyleNames(Cell.Context context, RichGroup object) {
            if (tableFieldUpdater != null) {
                return super.getCellStyleNames(context, object) + " pointer image-hover";
            } else {
                return super.getCellStyleNames(context, object);
            }
        }
    };
    syncColumn.setFieldUpdater(new FieldUpdater<RichGroup, RichGroup>() {

        @Override
        public void update(int index, final RichGroup object, RichGroup value) {
            GetEntityById get = new GetEntityById(PerunEntity.RICH_GROUP, object.getId(), new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    final RichGroup object = jso.cast();
                    String name, syncEnabled, syncInterval, syncStartTimestamp, syncTimestamp, syncSuccessTimestamp, syncState, authGroup, syncTimes, syncSuccessStartTimestamp;
                    name = object.getName();
                    if (object.isSyncEnabled()) {
                        syncEnabled = "enabled";
                    } else {
                        syncEnabled = "disabled";
                    }
                    if (object.getSynchronizationInterval() == null) {
                        syncInterval = "N/A";
                    } else {
                        if (JsonUtils.checkParseInt(object.getSynchronizationInterval())) {
                            int time = Integer.parseInt(object.getSynchronizationInterval()) * 5 / 60;
                            if (time == 0) {
                                time = Integer.parseInt(object.getSynchronizationInterval()) * 5;
                                syncInterval = time + " minute(s)";
                            } else {
                                syncInterval = time + " hour(s)";
                            }
                        } else {
                            syncInterval = object.getSynchronizationInterval();
                        }
                    }
                    if (object.getSynchronizationTimes() != null && object.getSynchronizationTimes().length() > 0) {
                        syncTimes = object.getSynchronizationTimes().join(", ");
                    } else {
                        syncTimes = "N/A";
                    }
                    if (object.getLastSynchronizationState() == null) {
                        if (object.getLastSuccessSynchronizationTimestamp() != null) {
                            syncState = "OK";
                        } else {
                            syncState = "Not synced yet";
                        }
                    } else {
                        if (session.isPerunAdmin()) {
                            syncState = object.getLastSynchronizationState();
                        } else {
                            syncState = "Internal Error";
                        }
                    }
                    if (object.getLastSynchronizationTimestamp() == null) {
                        syncTimestamp = "N/A";
                    } else {
                        syncTimestamp = object.getLastSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getStartOfLastSynchronizationTimestamp() == null) {
                        syncStartTimestamp = "N/A";
                    } else {
                        syncStartTimestamp = object.getStartOfLastSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getLastSuccessSynchronizationTimestamp() == null) {
                        syncSuccessTimestamp = "N/A";
                    } else {
                        syncSuccessTimestamp = object.getLastSuccessSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getStartOfLastSuccessfulSynchronization() == null) {
                        syncSuccessStartTimestamp = "N/A";
                    } else {
                        syncSuccessStartTimestamp = object.getStartOfLastSuccessfulSynchronization().split("\\.")[0];
                    }
                    if (Objects.equals(object.getAuthoritativeGroup(), "1")) {
                        authGroup = "Yes";
                    } else {
                        authGroup = "No";
                    }
                    String html = "Group name: <b>" + SafeHtmlUtils.fromString(name).asString() + "</b><br>";
                    html += "Authoritative group: <b>" + SafeHtmlUtils.fromString(authGroup).asString() + "</b><br>";
                    html += "Synchronization: <b>" + SafeHtmlUtils.fromString(syncEnabled).asString() + "</b><br>";
                    html += "Sync. Interval: <b>" + SafeHtmlUtils.fromString(syncInterval).asString() + "</b><br>";
                    html += "Sync. Times: <b>" + SafeHtmlUtils.fromString(syncTimes).asString() + "</b><br>-----------------<br>";
                    if (object.isSyncEnabled()) {
                        html += "Last sync. state: <b>" + SafeHtmlUtils.fromString(syncState).asString() + "</b><br>";
                        html += "Last sync. timestamp (start): <b>" + SafeHtmlUtils.fromString(syncStartTimestamp).asString() + "</b><br>";
                        html += "Last sync. timestamp (end): <b>" + SafeHtmlUtils.fromString(syncTimestamp).asString() + "</b><br>";
                        html += "Last successful sync. timestamp (start): <b>" + SafeHtmlUtils.fromString(syncSuccessStartTimestamp).asString() + "</b><br>";
                        html += "Last successful sync. timestamp (end): <b>" + SafeHtmlUtils.fromString(syncSuccessTimestamp).asString() + "</b><br>";
                    }
                    FlexTable layout = new FlexTable();
                    layout.setWidth("450px");
                    layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.informationIcon())));
                    layout.setHTML(0, 1, "<p style=\"line-height: 1.2;\">" + html);
                    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");
                    final CustomButton okButton = new CustomButton("Force synchronization", SmallIcons.INSTANCE.arrowRefreshIcon());
                    okButton.addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            ForceGroupSynchronization call = new ForceGroupSynchronization(JsonCallbackEvents.disableButtonEvents(okButton));
                            call.synchronizeGroup(object.getId());
                        }
                    });
                    if (!session.isVoAdmin(object.getVoId()) && !session.isGroupAdmin(object.getId()))
                        okButton.setEnabled(false);
                    okButton.setVisible(object.isSyncEnabled());
                    final Confirm c = new Confirm("Group synchronization info", layout, okButton, null, true);
                    c.setHideOnButtonClick(false);
                    c.setCancelIcon(SmallIcons.INSTANCE.acceptIcon());
                    c.setCancelButtonText("OK");
                    c.setCancelClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            c.hide();
                        }
                    });
                    c.show();
                }
            });
            get.retrieveData();
        }
    });
    syncColumn.setSortable(true);
    columnSortHandler.setComparator(syncColumn, new Comparator<RichGroup>() {

        @Override
        public int compare(RichGroup o1, RichGroup o2) {
            if (o1 != null && o2 != null) {
                int o1val = 0;
                int o2val = 0;
                if (o1.isSyncEnabled())
                    o1val = 5;
                if (o2.isSyncEnabled())
                    o2val = 5;
                if (Objects.equals(o1.getAuthoritativeGroup(), "1"))
                    o1val = o1val + 3;
                if (Objects.equals(o2.getAuthoritativeGroup(), "1"))
                    o2val = o2val + 3;
                return o1val - o2val;
            }
            return 0;
        }
    });
    table.addColumn(syncColumn, "Sync");
    table.setColumnWidth(syncColumn, "70px");
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    return table;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RichGroup(cz.metacentrum.perun.webgui.model.RichGroup) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) Image(com.google.gwt.user.client.ui.Image) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) FlexTable(com.google.gwt.user.client.ui.FlexTable) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomClickableInfoCellWithImageResource(cz.metacentrum.perun.webgui.widgets.cells.CustomClickableInfoCellWithImageResource)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)18 GetEntityById (cz.metacentrum.perun.webgui.json.GetEntityById)18 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)18 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)9 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)8 Command (com.google.gwt.user.client.Command)4 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 HashMap (java.util.HashMap)3 RegExp (com.google.gwt.regexp.shared.RegExp)2 CreatePassword (cz.metacentrum.perun.webgui.json.usersManager.CreatePassword)2 GenerateAccount (cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount)2 SetLogin (cz.metacentrum.perun.webgui.json.usersManager.SetLogin)2 Attribute (cz.metacentrum.perun.webgui.model.Attribute)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 User (cz.metacentrum.perun.webgui.model.User)2 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2