Search in sources :

Example 1 with SetAttributeRights

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

the class CreateAttributeDefinitionTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // creates HTML elements
    final ExtendedTextBox attributeDisplayName = new ExtendedTextBox();
    final ExtendedTextBox attributeName = new ExtendedTextBox();
    final ExtendedTextBox attributeDescription = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (attributeName.getTextBox().getText().trim().isEmpty()) {
                attributeName.setError("Name of attribute can't be empty.");
            } else if (!attributeName.getTextBox().getText().trim().matches(Utils.ATTRIBUTE_FRIENDLY_NAME_MATCHER)) {
                attributeName.setError("Name of attribute can contain only letters, numbers, dash and colon.");
            } else {
                attributeName.setOk();
                return true;
            }
            return false;
        }
    };
    final ExtendedTextBox.TextBoxValidator descriptionValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDescription.getTextBox().getText().trim().isEmpty()) {
                attributeDescription.setOk();
                return true;
            } else {
                attributeDescription.setError("Description of attribute can't be empty.");
                return false;
            }
        }
    };
    final ExtendedTextBox.TextBoxValidator displayNameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDisplayName.getTextBox().getText().trim().isEmpty()) {
                attributeDisplayName.setOk();
                return true;
            } else {
                attributeDisplayName.setError("Display name of attribute can't be empty.");
                return false;
            }
        }
    };
    attributeName.setValidator(nameValidator);
    attributeDisplayName.setValidator(displayNameValidator);
    attributeDescription.setValidator(descriptionValidator);
    final ListBox entityListBox = new ListBox();
    final ListBox definitionListBox = new ListBox();
    final ListBox typeListBox = new ListBox();
    // fill listboxs with pre-defined values
    entityListBox.addItem("facility", "urn:perun:facility:");
    entityListBox.addItem("resource", "urn:perun:resource:");
    entityListBox.addItem("group", "urn:perun:group:");
    entityListBox.addItem("group_resource", "urn:perun:group_resource:");
    entityListBox.addItem("host", "urn:perun:host:");
    entityListBox.addItem("member", "urn:perun:member:");
    entityListBox.addItem("member_group", "urn:perun:member_group:");
    entityListBox.addItem("member_resource", "urn:perun:member_resource:");
    entityListBox.addItem("user", "urn:perun:user:");
    entityListBox.addItem("user_ext_source", "urn:perun:ues:");
    entityListBox.addItem("user_facility", "urn:perun:user_facility:");
    entityListBox.addItem("vo", "urn:perun:vo:");
    entityListBox.addItem("entityless", "urn:perun:entityless:");
    definitionListBox.addItem("def", "attribute-def:def");
    definitionListBox.addItem("opt", "attribute-def:opt");
    definitionListBox.addItem("virt", "attribute-def:virt");
    definitionListBox.addItem("core", "attribute-def:core");
    typeListBox.addItem("String", "java.lang.String");
    typeListBox.addItem("Integer", "java.lang.Integer");
    typeListBox.addItem("Boolean", "java.lang.Boolean");
    typeListBox.addItem("Array", "java.util.ArrayList");
    typeListBox.addItem("LinkedHashMap", "java.util.LinkedHashMap");
    // prepare layout for this tab
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    TabMenu menu = new TabMenu();
    // BUTTONS
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createAttributeDefinition());
    menu.addWidget(createButton);
    // close tab events & enable, disable buttons
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(createButton, this, true);
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (nameValidator.validateTextBox() && descriptionValidator.validateTextBox() && displayNameValidator.validateTextBox()) {
                String displayName = attributeDisplayName.getTextBox().getText().trim();
                String friendlyName = attributeName.getTextBox().getText().trim();
                String description = attributeDescription.getTextBox().getText().trim();
                String namespace = entityListBox.getValue(entityListBox.getSelectedIndex()) + definitionListBox.getValue(definitionListBox.getSelectedIndex());
                String type = typeListBox.getValue(typeListBox.getSelectedIndex());
                boolean isUnique = unique.getValue();
                CreateAttribute request = new CreateAttribute(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        AttributeDefinition a = jso.cast();
                        ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
                        AttributeRights right = AttributeRights.create(a.getId(), "SELF");
                        list.add(getRightsFromWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, right));
                        AttributeRights right2 = AttributeRights.create(a.getId(), "VOADMIN");
                        list.add(getRightsFromWidgets(voRead, voWrite, right2));
                        AttributeRights right3 = AttributeRights.create(a.getId(), "GROUPADMIN");
                        list.add(getRightsFromWidgets(groupRead, groupWrite, right3));
                        AttributeRights right4 = AttributeRights.create(a.getId(), "FACILITYADMIN");
                        list.add(getRightsFromWidgets(facilityRead, facilityWrite, right4));
                        // after update - update rights
                        SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                enableDisableWidgets(true);
                                closeTabEvents.onFinished(jso);
                            }

                            @Override
                            public void onLoadingStart() {
                                enableDisableWidgets(false);
                            }

                            @Override
                            public void onError(PerunError error) {
                                enableDisableWidgets(true);
                            }
                        }));
                        request.setAttributeRights(list);
                    }
                }));
                request.createAttributeDefinition(displayName, friendlyName, description, namespace, type, isUnique);
            }
        }
    });
    // insert layout
    layout.setHTML(0, 0, "Friendly name:");
    layout.setWidget(0, 1, attributeName);
    layout.setHTML(1, 0, "Display name:");
    layout.setWidget(1, 1, attributeDisplayName);
    layout.setHTML(2, 0, "Description:");
    layout.setWidget(2, 1, attributeDescription);
    layout.setHTML(3, 0, "Entity:");
    layout.setWidget(3, 1, entityListBox);
    layout.setHTML(4, 0, "Definition type:");
    layout.setWidget(4, 1, definitionListBox);
    layout.setHTML(5, 0, "Value type:");
    layout.setWidget(5, 1, typeListBox);
    layout.setHTML(6, 0, "Unique:");
    layout.setWidget(6, 1, unique);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>SELF_PUBLIC</strong>");
    rightsTable.setHTML(0, 3, "<strong>SELF_VO</strong>");
    rightsTable.setHTML(0, 4, "<strong>VO</strong>");
    rightsTable.setHTML(0, 5, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 6, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, selfReadPublic);
    rightsTable.setWidget(2, 2, selfWritePublic);
    rightsTable.setWidget(1, 3, selfReadVo);
    rightsTable.setWidget(2, 3, selfWriteVo);
    rightsTable.setWidget(1, 4, voRead);
    rightsTable.setWidget(2, 4, voWrite);
    rightsTable.setWidget(1, 5, groupRead);
    rightsTable.setWidget(2, 5, groupWrite);
    rightsTable.setWidget(1, 6, facilityRead);
    rightsTable.setWidget(2, 6, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    vp.add(layout);
    vp.add(rightsTable);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) CreateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.CreateAttribute) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)

Example 2 with SetAttributeRights

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

the class EntitylessAttributesDetailTabItem method draw.

@Override
public Widget draw() {
    titleWidget.setText(def.getName());
    final TabItem tab = this;
    // create main panel for content
    final FlexTable mainPage = new FlexTable();
    mainPage.setWidth("100%");
    final ExtendedTextBox description = new ExtendedTextBox();
    description.setWidth("100%");
    description.getTextBox().setText(def.getDescription());
    final ExtendedTextBox.TextBoxValidator validator = () -> {
        if (description.getTextBox().getText().trim().isEmpty()) {
            description.setError("Description can't be empty.");
            return false;
        }
        description.setOk();
        return true;
    };
    final ExtendedTextBox displayName = new ExtendedTextBox();
    displayName.setWidth("100%");
    displayName.getTextBox().setText(def.getDisplayName());
    final ExtendedTextBox.TextBoxValidator validatorName = () -> {
        if (displayName.getTextBox().getText().trim().isEmpty()) {
            displayName.setError("Display name can't be empty.");
            return false;
        }
        displayName.setOk();
        return true;
    };
    description.setValidator(validator);
    displayName.setValidator(validatorName);
    // unique.setEnabled(false);
    unique.setValue(def.isUnique());
    if (Arrays.asList("core", "virt").contains(def.getDefinition()) || def.getEntity().equals("entityless")) {
        unique.setEnabled(false);
    } else {
        unique.addValueChangeHandler(valueChangeEvent -> {
            if (valueChangeEvent.getValue()) {
                UiElements.generateAlert("Change confirmation", "Changing attribute to UNIQUE might take a lot of time if there is large number of entities with set values. Perun will check uniqueness during the process. If values are not unique, conversion will be stopped.<p style=\"color:red;\">We strongly recommend to refresh whole browser window after conversion is DONE to prevent errors when modyfying attributes from GUI.", clickEvent -> {
                    ConvertAttributeToUnique convert = new ConvertAttributeToUnique(new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            unique.setValue(true);
                            unique.setEnabled(false);
                            def.setUnique(true);
                        }

                        @Override
                        public void onError(PerunError error) {
                            unique.setValue(false);
                            unique.setEnabled(true);
                            def.setUnique(false);
                        }

                        @Override
                        public void onLoadingStart() {
                            unique.setEnabled(false);
                        }
                    });
                    convert.convertAttributeDefinitionToUnique(def.getId());
                }, clickEvent -> {
                    // action canceled
                    unique.setValue(false);
                });
            } else {
                UiElements.generateInfo("Change not allowed", "Once converted to UNIQUE, attributes can't be converted back to non-unique.");
                unique.setValue(true);
            }
        });
    }
    FlexTable attributeDetailTable = new FlexTable();
    attributeDetailTable.setStyleName("inputFormFlexTable");
    final CustomButton updateButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save attribute details");
    updateButton.addClickHandler(event -> {
        final ArrayList<AttributeRights> list = new ArrayList<>();
        for (AttributeRights r : rights) {
            if (r.getRole().equalsIgnoreCase("SELF")) {
                list.add(getRightsFromWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r));
            } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                list.add(getRightsFromWidgets(voRead, voWrite, r));
            } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                list.add(getRightsFromWidgets(groupRead, groupWrite, r));
            } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                list.add(getRightsFromWidgets(facilityRead, facilityWrite, r));
            }
        }
        if ((!Objects.equals(def.getDescription(), description.getTextBox().getText().trim()) || !Objects.equals(def.getDisplayName(), displayName.getTextBox().getText().trim()))) {
            if (!validator.validateTextBox() || !validatorName.validateTextBox())
                return;
            def.setDescription(description.getTextBox().getText().trim());
            def.setDisplayName(displayName.getTextBox().getText().trim());
            UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // after update - update rights
                    SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            enableDisableWidgets(true);
                        }

                        @Override
                        public void onLoadingStart() {
                            enableDisableWidgets(false);
                        }

                        @Override
                        public void onError(PerunError error) {
                            enableDisableWidgets(true);
                        }
                    }));
                    request.setAttributeRights(list);
                }
            }));
            request.updateAttribute(def);
        } else {
            // after update - update rights
            SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    enableDisableWidgets(true);
                }

                @Override
                public void onLoadingStart() {
                    enableDisableWidgets(false);
                }

                @Override
                public void onError(PerunError error) {
                    enableDisableWidgets(true);
                }
            }));
            request.setAttributeRights(list);
        }
    });
    attributeDetailTable.setHTML(0, 0, "Display name:");
    attributeDetailTable.setWidget(0, 1, displayName);
    attributeDetailTable.setHTML(1, 0, "Description:");
    attributeDetailTable.setWidget(1, 1, description);
    attributeDetailTable.setHTML(2, 0, "Unique:");
    attributeDetailTable.setWidget(2, 1, unique);
    for (int i = 0; i < attributeDetailTable.getRowCount(); i++) {
        attributeDetailTable.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>SELF_PUBLIC</strong>");
    rightsTable.setHTML(0, 3, "<strong>SELF_VO</strong>");
    rightsTable.setHTML(0, 4, "<strong>VO</strong>");
    rightsTable.setHTML(0, 5, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 6, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, selfReadPublic);
    rightsTable.setWidget(2, 2, selfWritePublic);
    rightsTable.setWidget(1, 3, selfReadVo);
    rightsTable.setWidget(2, 3, selfWriteVo);
    rightsTable.setWidget(1, 4, voRead);
    rightsTable.setWidget(2, 4, voWrite);
    rightsTable.setWidget(1, 5, groupRead);
    rightsTable.setWidget(2, 5, groupWrite);
    rightsTable.setWidget(1, 6, facilityRead);
    rightsTable.setWidget(2, 6, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(updateButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", event -> session.getTabManager().closeTab(tab, isRefreshParentOnClose())));
    CustomButton showKeys = new CustomButton();
    showKeys.setText("show keys");
    showKeys.addClickHandler(clickEvent -> session.getTabManager().addTab(new EntitylessAttributeEditKeyTabItem(def)));
    menu.addWidget(showKeys);
    GetAttributeRights rightsCall = new GetAttributeRights(def.getId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            rights = JsonUtils.jsoAsList(jso);
            for (AttributeRights r : rights) {
                if (r.getRole().equalsIgnoreCase("SELF")) {
                    setRightsToWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r);
                } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                    setRightsToWidgets(voRead, voWrite, r);
                } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                    setRightsToWidgets(groupRead, groupWrite, r);
                } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                    setRightsToWidgets(facilityRead, facilityWrite, r);
                }
            }
            enableDisableWidgets(true);
            rightsTable.setVisible(true);
        }

        @Override
        public void onError(PerunError error) {
            enableDisableWidgets(true);
            rightsTable.setVisible(false);
        }

        @Override
        public void onLoadingStart() {
            enableDisableWidgets(false);
            rightsTable.setVisible(false);
        }
    });
    rightsCall.retrieveData();
    // create new instance for jsonCall
    final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId());
    services.setCheckable(false);
    CellTable<Service> attrDefTable = services.getTable((index, object, value) -> session.getTabManager().addTab(new ServiceDetailTabItem(object)));
    attrDefTable.setStyleName("perun-table");
    ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
    scrollTable.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(scrollTable, 350, this);
    // set content to page
    mainPage.setWidget(0, 0, menu);
    mainPage.getFlexCellFormatter().setColSpan(0, 0, 2);
    mainPage.setWidget(1, 0, attributeDetailTable);
    mainPage.setWidget(1, 1, rightsTable);
    mainPage.getFlexCellFormatter().setWidth(1, 0, "50%");
    mainPage.getFlexCellFormatter().setWidth(1, 1, "50%");
    HTML title = new HTML("<p>Required by service</p>");
    title.setStyleName("subsection-heading");
    mainPage.setWidget(2, 0, title);
    mainPage.getFlexCellFormatter().setColSpan(2, 0, 2);
    // put page into scroll panel
    mainPage.setWidget(3, 0, scrollTable);
    mainPage.getFlexCellFormatter().setColSpan(3, 0, 2);
    mainPage.getFlexCellFormatter().setHeight(3, 0, "100%");
    this.contentWidget.setWidget(mainPage);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Arrays(java.util.Arrays) Service(cz.metacentrum.perun.webgui.model.Service) ImageResource(com.google.gwt.resources.client.ImageResource) SmallIcons(cz.metacentrum.perun.webgui.client.resources.SmallIcons) com.google.gwt.user.client.ui(com.google.gwt.user.client.ui) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) ArrayList(java.util.ArrayList) GetServicesByAttrDefinition(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) UiElements(cz.metacentrum.perun.webgui.client.UiElements) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ConvertAttributeToUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) PerunWebSession(cz.metacentrum.perun.webgui.client.PerunWebSession) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Objects(java.util.Objects) PerunError(cz.metacentrum.perun.webgui.model.PerunError) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) UpdateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ButtonType(cz.metacentrum.perun.webgui.client.resources.ButtonType) CellTable(com.google.gwt.user.cellview.client.CellTable) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UpdateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ArrayList(java.util.ArrayList) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) Service(cz.metacentrum.perun.webgui.model.Service) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ConvertAttributeToUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) GetServicesByAttrDefinition(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition)

Example 3 with SetAttributeRights

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

the class AttributeDefinitionDetailTabItem method draw.

public Widget draw() {
    titleWidget.setText(def.getName());
    final TabItem tab = this;
    // create main panel for content
    final FlexTable mainPage = new FlexTable();
    mainPage.setWidth("100%");
    final ExtendedTextBox description = new ExtendedTextBox();
    description.setWidth("100%");
    description.getTextBox().setText(def.getDescription());
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (description.getTextBox().getText().trim().isEmpty()) {
                description.setError("Description can't be empty.");
                return false;
            }
            description.setOk();
            return true;
        }
    };
    final ExtendedTextBox displayName = new ExtendedTextBox();
    displayName.setWidth("100%");
    displayName.getTextBox().setText(def.getDisplayName());
    final ExtendedTextBox.TextBoxValidator validatorName = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (displayName.getTextBox().getText().trim().isEmpty()) {
                displayName.setError("Display name can't be empty.");
                return false;
            }
            displayName.setOk();
            return true;
        }
    };
    description.setValidator(validator);
    displayName.setValidator(validatorName);
    CheckBox unique = new CheckBox();
    unique.setValue(def.isUnique());
    if (Arrays.asList("core", "virt").contains(def.getDefinition()) || def.getEntity().equals("entityless")) {
        unique.setEnabled(false);
    } else {
        unique.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

            @Override
            public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
                if (valueChangeEvent.getValue()) {
                    UiElements.generateAlert("Change confirmation", "Changing attribute to UNIQUE might take a lot of time if there is large number of entities with set values. Perun will check uniqueness during the process. If values are not unique, conversion will be stopped.<p style=\"color:red;\">We strongly recommend to refresh whole browser window after conversion is DONE to prevent errors when modifying attributes from GUI.", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            ConvertAttributeToUnique convert = new ConvertAttributeToUnique(new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    unique.setValue(true);
                                    unique.setEnabled(true);
                                    def.setUnique(true);
                                }

                                @Override
                                public void onError(PerunError error) {
                                    unique.setValue(false);
                                    unique.setEnabled(true);
                                    def.setUnique(false);
                                }

                                @Override
                                public void onLoadingStart() {
                                    unique.setEnabled(false);
                                }
                            });
                            convert.convertAttributeDefinitionToUnique(def.getId());
                        }
                    }, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            // action canceled
                            unique.setValue(false);
                        }
                    });
                } else {
                    ConvertAttributeToNonUnique convert = new ConvertAttributeToNonUnique(new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            unique.setValue(false);
                            unique.setEnabled(true);
                            def.setUnique(false);
                        }

                        @Override
                        public void onError(PerunError error) {
                            unique.setValue(true);
                            unique.setEnabled(true);
                            def.setUnique(true);
                        }

                        @Override
                        public void onLoadingStart() {
                            unique.setEnabled(false);
                        }
                    });
                    convert.convertAttributeDefinitionToNonUnique(def.getId());
                }
            }
        });
    }
    FlexTable attributeDetailTable = new FlexTable();
    attributeDetailTable.setStyleName("inputFormFlexTable");
    final CustomButton updateButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save attribute details");
    updateButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
            for (AttributeRights r : rights) {
                if (r.getRole().equalsIgnoreCase("SELF")) {
                    list.add(getRightsFromWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r));
                } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                    list.add(getRightsFromWidgets(voRead, voWrite, r));
                } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                    list.add(getRightsFromWidgets(groupRead, groupWrite, r));
                } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                    list.add(getRightsFromWidgets(facilityRead, facilityWrite, r));
                }
            }
            if ((!Objects.equals(def.getDescription(), description.getTextBox().getText().trim()) || !Objects.equals(def.getDisplayName(), displayName.getTextBox().getText().trim()))) {
                if (!validator.validateTextBox() || !validatorName.validateTextBox())
                    return;
                def.setDescription(description.getTextBox().getText().trim());
                def.setDisplayName(displayName.getTextBox().getText().trim());
                UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // after update - update rights
                        SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                enableDisableWidgets(true);
                            }

                            @Override
                            public void onLoadingStart() {
                                enableDisableWidgets(false);
                            }

                            @Override
                            public void onError(PerunError error) {
                                enableDisableWidgets(true);
                            }
                        }));
                        request.setAttributeRights(list);
                    }
                }));
                request.updateAttribute(def);
            } else {
                // after update - update rights
                SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        enableDisableWidgets(true);
                    }

                    @Override
                    public void onLoadingStart() {
                        enableDisableWidgets(false);
                    }

                    @Override
                    public void onError(PerunError error) {
                        enableDisableWidgets(true);
                    }
                }));
                request.setAttributeRights(list);
            }
        }
    });
    attributeDetailTable.setHTML(0, 0, "Display name:");
    attributeDetailTable.setWidget(0, 1, displayName);
    attributeDetailTable.setHTML(1, 0, "Description:");
    attributeDetailTable.setWidget(1, 1, description);
    attributeDetailTable.setHTML(2, 0, "Unique:");
    attributeDetailTable.setWidget(2, 1, unique);
    for (int i = 0; i < attributeDetailTable.getRowCount(); i++) {
        attributeDetailTable.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>SELF_PUBLIC</strong>");
    rightsTable.setHTML(0, 3, "<strong>SELF_VO</strong>");
    rightsTable.setHTML(0, 4, "<strong>VO</strong>");
    rightsTable.setHTML(0, 5, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 6, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, selfReadPublic);
    rightsTable.setWidget(2, 2, selfWritePublic);
    rightsTable.setWidget(1, 3, selfReadVo);
    rightsTable.setWidget(2, 3, selfWriteVo);
    rightsTable.setWidget(1, 4, voRead);
    rightsTable.setWidget(2, 4, voWrite);
    rightsTable.setWidget(1, 5, groupRead);
    rightsTable.setWidget(2, 5, groupWrite);
    rightsTable.setWidget(1, 6, facilityRead);
    rightsTable.setWidget(2, 6, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(updateButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    GetAttributeRights rightsCall = new GetAttributeRights(def.getId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            rights = JsonUtils.jsoAsList(jso);
            for (AttributeRights r : rights) {
                if (r.getRole().equalsIgnoreCase("SELF")) {
                    setRightsToWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r);
                } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                    setRightsToWidgets(voRead, voWrite, r);
                } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                    setRightsToWidgets(groupRead, groupWrite, r);
                } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                    setRightsToWidgets(facilityRead, facilityWrite, r);
                }
            }
            enableDisableWidgets(true);
            rightsTable.setVisible(true);
        }

        @Override
        public void onError(PerunError error) {
            enableDisableWidgets(true);
            rightsTable.setVisible(false);
        }

        @Override
        public void onLoadingStart() {
            enableDisableWidgets(false);
            rightsTable.setVisible(false);
        }
    });
    rightsCall.retrieveData();
    // create new instance for jsonCall
    final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId());
    services.setCheckable(false);
    CellTable<Service> attrDefTable = services.getTable(new FieldUpdater<Service, String>() {

        @Override
        public void update(int index, Service object, String value) {
            session.getTabManager().addTab(new ServiceDetailTabItem(object));
        }
    });
    attrDefTable.setStyleName("perun-table");
    ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
    scrollTable.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(scrollTable, 350, this);
    // set content to page
    mainPage.setWidget(0, 0, menu);
    mainPage.getFlexCellFormatter().setColSpan(0, 0, 2);
    mainPage.setWidget(1, 0, attributeDetailTable);
    mainPage.setWidget(1, 1, rightsTable);
    mainPage.getFlexCellFormatter().setWidth(1, 0, "50%");
    mainPage.getFlexCellFormatter().setWidth(1, 1, "50%");
    HTML title = new HTML("<p>Required by service</p>");
    title.setStyleName("subsection-heading");
    mainPage.setWidget(2, 0, title);
    mainPage.getFlexCellFormatter().setColSpan(2, 0, 2);
    // put page into scroll panel
    mainPage.setWidget(3, 0, scrollTable);
    mainPage.getFlexCellFormatter().setColSpan(3, 0, 2);
    mainPage.getFlexCellFormatter().setHeight(3, 0, "100%");
    this.contentWidget.setWidget(mainPage);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) UpdateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ArrayList(java.util.ArrayList) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) ConvertAttributeToNonUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToNonUnique) Service(cz.metacentrum.perun.webgui.model.Service) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ConvertAttributeToUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) GetServicesByAttrDefinition(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 SetAttributeRights (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)3 AttributeRights (cz.metacentrum.perun.webgui.model.AttributeRights)3 PerunError (cz.metacentrum.perun.webgui.model.PerunError)3 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)3 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 ArrayList (java.util.ArrayList)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 ConvertAttributeToUnique (cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique)2 GetAttributeRights (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights)2 UpdateAttribute (cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute)2 GetServicesByAttrDefinition (cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition)2 AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)2 Service (cz.metacentrum.perun.webgui.model.Service)2 ServiceDetailTabItem (cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem)2 ImageResource (com.google.gwt.resources.client.ImageResource)1