Search in sources :

Example 21 with Attribute

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

the class AttributeComparator method compare.

/**
	 * Compares the two objects
	 *
	 * @param obj1 First object
	 * @param obj2 Second object
	 */
public int compare(T obj1, T obj2) {
    Attribute o1 = obj1.cast();
    Attribute o2 = obj2.cast();
    switch(this.attr) {
        case TRANSLATED_NAME:
            return this.compareByName(o1, o2);
        case TRANSLATED_DESCRIPTION:
            return this.compareByDescription(o1, o2);
    }
    return 0;
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 22 with Attribute

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

the class RichMemberComparator method compareByEmail.

/**
	 * Compares RichMembers by emails
	 * @param o1
	 * @param o2
	 * @return
	 */
private int compareByEmail(RichMember o1, RichMember o2) {
    Attribute at1 = o1.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
    Attribute at2 = o2.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
    if (at1 == null || at1.getValue() == null || "null".equalsIgnoreCase(at1.getValue())) {
        at1 = o1.getAttribute("urn:perun:member:attribute-def:def:mail");
    }
    if (at2 == null || at2.getValue() == null || "null".equalsIgnoreCase(at2.getValue())) {
        at2 = o2.getAttribute("urn:perun:member:attribute-def:def:mail");
    }
    String at1value = "";
    String at2value = "";
    if (at1 != null && at1.getValue() != null && !"null".equalsIgnoreCase(at1.getValue())) {
        at1value = at1.getValue();
    }
    if (at2 != null && at2.getValue() != null && !"null".equalsIgnoreCase(at2.getValue())) {
        at2value = at2.getValue();
    }
    return Collator.getInstance().compare(at1value, at2value);
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 23 with Attribute

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

the class RichMemberComparator method compareByOrganization.

/**
	 * Compares RichMembers by organizations
	 * @param o1
	 * @param o2
	 * @return
	 */
private int compareByOrganization(RichMember o1, RichMember o2) {
    Attribute at1 = o1.getAttribute("urn:perun:member:attribute-def:def:organization");
    Attribute at2 = o2.getAttribute("urn:perun:member:attribute-def:def:organization");
    if (at1 == null || at1.getValue() == null || "null".equalsIgnoreCase(at1.getValue())) {
        at1 = o1.getAttribute("urn:perun:user:attribute-def:def:organization");
    }
    if (at2 == null || at2.getValue() == null || "null".equalsIgnoreCase(at2.getValue())) {
        at2 = o2.getAttribute("urn:perun:user:attribute-def:def:organization");
    }
    String at1value = "";
    String at2value = "";
    if (at1 != null && at1.getValue() != null && !"null".equalsIgnoreCase(at1.getValue())) {
        at1value = at1.getValue();
    }
    if (at2 != null && at2.getValue() != null && !"null".equalsIgnoreCase(at2.getValue())) {
        at2value = at2.getValue();
    }
    return Collator.getInstance().compare(at1value, at2value);
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 24 with Attribute

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

the class RichUserComparator method compareByEmail.

/**
	 * Compares RichMembers by emails
	 * @param o1
	 * @param o2
	 * @return
	 */
private int compareByEmail(User o1, User o2) {
    Attribute at1 = o1.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
    Attribute at2 = o2.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
    String at1value = "";
    String at2value = "";
    if (at1 != null && at1.getValue() != null && !"null".equalsIgnoreCase(at1.getValue())) {
        at1value = at1.getValue();
    }
    if (at2 != null && at2.getValue() != null && !"null".equalsIgnoreCase(at2.getValue())) {
        at2value = at2.getValue();
    }
    return Collator.getInstance().compare(at1value, at2value);
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 25 with Attribute

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

the class SetNewAttributeTabItem method draw.

public Widget draw() {
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    // correct IDS for getting attrDefs
    if (ids.containsKey("resourceToGetServicesFrom")) {
        if (!ids.containsKey("resource")) {
            ids.put("resource", ids.get("resourceToGetServicesFrom"));
            ids.remove("resourceToGetServicesFrom");
        }
    }
    if (ids.containsKey("workWithUserAttributes")) {
        ids.remove("workWithUserAttributes");
    }
    if (ids.containsKey("workWithGroupAttributes")) {
        ids.remove("workWithGroupAttributes");
    }
    // set tab name
    String label = titleWidget.getText() + " (";
    for (Map.Entry<String, Integer> entry : ids.entrySet()) {
        label += entry.getKey() + ":" + String.valueOf(entry.getValue()) + " ";
    }
    label = label.substring(0, label.length() - 1) + ")";
    titleWidget.setText(label);
    // helper text
    String entityIds = "";
    for (Map.Entry<String, Integer> item : ids.entrySet()) {
        entityIds = entityIds.concat(" " + item.getKey() + ": " + item.getValue());
    }
    HTML helper = new HTML();
    String helperInside = "<p>Enter new values and press Enter key. Save changes by clicking on \"Save changes\" button. Values will be set for<strong>" + entityIds + ".</strong></p>";
    helper.setHTML(helperInside);
    // callback
    final GetAttributesDefinitionWithRights attrDef = new GetAttributesDefinitionWithRights(ids);
    // remove already used attributes from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            if (!inUse.isEmpty()) {
                for (Attribute a : inUse) {
                    attrDef.removeFromTable(a);
                }
            }
        }
    };
    attrDef.setEvents(localEvents);
    // filter core attributes
    attrDef.switchCore();
    // which entities to show
    Set<String> namespaces = getNamespacesForEntities(ids.keySet());
    // show only these attributes
    attrDef.setEntities(namespaces);
    // get table
    CellTable<Attribute> table = attrDef.getTable();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    // add save button
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, buttonTranslation.saveNewAttributes());
    final JsonCallbackEvents events = JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab);
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // Save the attributes
            ArrayList<Attribute> list = attrDef.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // separated list by entity
                ArrayList<Attribute> facilityList = new ArrayList<Attribute>();
                ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
                ArrayList<Attribute> userList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberGroupList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> resourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> hostList = new ArrayList<Attribute>();
                ArrayList<Attribute> voList = new ArrayList<Attribute>();
                ArrayList<Attribute> uesList = new ArrayList<Attribute>();
                for (Attribute a : list) {
                    if (a.getEntity().equalsIgnoreCase("facility")) {
                        facilityList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("user_facility")) {
                        userFacilityList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("resource")) {
                        resourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("user")) {
                        userList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member_resource")) {
                        memberResourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member")) {
                        memberList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("group")) {
                        groupList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("group_resource")) {
                        groupResourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("host")) {
                        hostList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("vo")) {
                        voList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member_group")) {
                        memberGroupList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("ues")) {
                        uesList.add(a);
                    }
                }
                // GROUPING BY IDS
                // GROUPING BY IDS
                SetAttributes request = new SetAttributes(events);
                if (ids.size() == 4 && ids.containsKey("facility") && ids.containsKey("user") && ids.containsKey("member") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(userList);
                    sendList.addAll(memberResourceList);
                    sendList.addAll(userFacilityList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("facility") && ids.containsKey("user")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(userList);
                    sendList.addAll(userFacilityList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("member") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(memberResourceList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("group") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(groupList);
                    sendList.addAll(groupResourceList);
                    // call proper method in RPC
                    ids.put("workWithGroupAttributes", 1);
                    request.setAttributes(ids, sendList);
                    ids.remove("workWithGroupAttributes");
                } else if (ids.size() == 2 && ids.containsKey("member") && ids.containsKey("user")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(userList);
                    // call proper method in RPC
                    ids.put("workWithUserAttributes", 1);
                    request.setAttributes(ids, sendList);
                    ids.remove("workWithUserAttributes");
                } else if (ids.size() == 2 && ids.containsKey("group") && ids.containsKey("member")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberGroupList);
                    // call proper method in RPC
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 1 && ids.containsKey("group")) {
                    request.setAttributes(ids, groupList);
                } else if (ids.size() == 1 && ids.containsKey("resource")) {
                    request.setAttributes(ids, resourceList);
                } else if (ids.size() == 1 && ids.containsKey("facility")) {
                    request.setAttributes(ids, facilityList);
                } else if (ids.size() == 1 && ids.containsKey("vo")) {
                    request.setAttributes(ids, voList);
                } else if (ids.size() == 1 && ids.containsKey("host")) {
                    request.setAttributes(ids, hostList);
                } else if (ids.size() == 1 && ids.containsKey("member")) {
                    request.setAttributes(ids, memberList);
                } else if (ids.size() == 1 && ids.containsKey("user")) {
                    request.setAttributes(ids, userList);
                } else if (ids.size() == 1 && ids.containsKey("userExtSource")) {
                    request.setAttributes(ids, uesList);
                } else {
                    String combination = "";
                    for (String key : ids.keySet()) {
                        combination += key + ": " + ids.get(key) + " | ";
                    }
                    UiElements.generateAlert("Wrong entities combination", "Unsupported combination of attributes to set: " + combination);
                }
            }
        }
    });
    menu.addWidget(saveButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addWidget(helper);
    mainTab.add(menu);
    mainTab.setCellHeight(menu, "30px");
    // table wrapper
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // do not resize like perun table to prevent wrong width in inner tab
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    // add table to the page
    mainTab.add(sp);
    //saveButton.setEnabled(false);
    //JsonUtils.addTableManagedButton(attrDef, table, saveButton);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetAttributesDefinitionWithRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinitionWithRights) 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)

Aggregations

Attribute (cz.metacentrum.perun.webgui.model.Attribute)58 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)17 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)17 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)16 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)16 ArrayList (java.util.ArrayList)16 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)15 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)15 HashMap (java.util.HashMap)14 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)12 PerunError (cz.metacentrum.perun.webgui.model.PerunError)10 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)9 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)9 Map (java.util.Map)9 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)7 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)7 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)7 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)7 Column (com.google.gwt.user.cellview.client.Column)6