Search in sources :

Example 1 with AttachEntityToTagParameters

use of org.ovirt.engine.core.common.action.AttachEntityToTagParameters in project ovirt-engine by oVirt.

the class HostListModel method postOnAssignTags.

@Override
public void postOnAssignTags(Map<Guid, Boolean> attachedTags) {
    TagListModel model = (TagListModel) getWindow();
    ArrayList<Guid> hostIds = new ArrayList<>();
    for (Object item : getSelectedItems()) {
        VDS vds = (VDS) item;
        hostIds.add(vds.getId());
    }
    // prepare attach/detach lists
    ArrayList<Guid> tagsToAttach = new ArrayList<>();
    ArrayList<Guid> tagsToDetach = new ArrayList<>();
    if (model.getItems() != null && model.getItems().size() > 0) {
        ArrayList<TagModel> tags = (ArrayList<TagModel>) model.getItems();
        TagModel rootTag = tags.get(0);
        TagModel.recursiveEditAttachDetachLists(rootTag, attachedTags, tagsToAttach, tagsToDetach);
    }
    ArrayList<ActionParametersBase> prmsToAttach = new ArrayList<>();
    for (Guid tag_id : tagsToAttach) {
        prmsToAttach.add(new AttachEntityToTagParameters(tag_id, hostIds));
    }
    Frontend.getInstance().runMultipleAction(ActionType.AttachVdsToTag, prmsToAttach);
    ArrayList<ActionParametersBase> prmsToDetach = new ArrayList<>();
    for (Guid tag_id : tagsToDetach) {
        prmsToDetach.add(new AttachEntityToTagParameters(tag_id, hostIds));
    }
    Frontend.getInstance().runMultipleAction(ActionType.DetachVdsFromTag, prmsToDetach);
    cancel();
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) AttachEntityToTagParameters(org.ovirt.engine.core.common.action.AttachEntityToTagParameters) JsSingleValueStringObject(org.ovirt.engine.ui.frontend.utils.JsSingleValueStringObject) TagListModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel) Guid(org.ovirt.engine.core.compat.Guid) TagModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 2 with AttachEntityToTagParameters

use of org.ovirt.engine.core.common.action.AttachEntityToTagParameters in project ovirt-engine by oVirt.

the class UserListModel method postOnAssignTags.

@Override
public void postOnAssignTags(Map<Guid, Boolean> attachedTags) {
    TagListModel model = (TagListModel) getWindow();
    ArrayList<Guid> userIds = new ArrayList<>();
    ArrayList<Guid> grpIds = new ArrayList<>();
    for (Object item : getSelectedItems()) {
        DbUser user = (DbUser) item;
        if (user.isGroup()) {
            grpIds.add(user.getId());
        } else {
            userIds.add(user.getId());
        }
    }
    // prepare attach/detach lists
    ArrayList<Guid> tagsToAttach = new ArrayList<>();
    ArrayList<Guid> tagsToDetach = new ArrayList<>();
    if (model.getItems() != null && model.getItems().size() > 0) {
        ArrayList<TagModel> tags = (ArrayList<TagModel>) model.getItems();
        TagModel rootTag = tags.get(0);
        TagModel.recursiveEditAttachDetachLists(rootTag, attachedTags, tagsToAttach, tagsToDetach);
    }
    ArrayList<ActionParametersBase> usersToAttach = new ArrayList<>();
    ArrayList<ActionParametersBase> grpsToAttach = new ArrayList<>();
    for (Guid tag_id : tagsToAttach) {
        if (userIds.size() > 0) {
            usersToAttach.add(new AttachEntityToTagParameters(tag_id, userIds));
        }
        if (grpIds.size() > 0) {
            grpsToAttach.add(new AttachEntityToTagParameters(tag_id, grpIds));
        }
    }
    if (usersToAttach.size() > 0) {
        Frontend.getInstance().runMultipleAction(ActionType.AttachUserToTag, usersToAttach);
    }
    if (grpsToAttach.size() > 0) {
        Frontend.getInstance().runMultipleAction(ActionType.AttachUserGroupToTag, grpsToAttach);
    }
    ArrayList<ActionParametersBase> usersToDetach = new ArrayList<>();
    ArrayList<ActionParametersBase> grpsToDetach = new ArrayList<>();
    for (Guid tag_id : tagsToDetach) {
        if (userIds.size() > 0) {
            usersToDetach.add(new AttachEntityToTagParameters(tag_id, userIds));
        }
        if (grpIds.size() > 0) {
            grpsToDetach.add(new AttachEntityToTagParameters(tag_id, grpIds));
        }
    }
    if (usersToDetach.size() > 0) {
        Frontend.getInstance().runMultipleAction(ActionType.DetachUserFromTag, usersToDetach);
    }
    if (grpsToDetach.size() > 0) {
        Frontend.getInstance().runMultipleAction(ActionType.DetachUserGroupFromTag, grpsToDetach);
    }
    cancel();
}
Also used : ArrayList(java.util.ArrayList) AttachEntityToTagParameters(org.ovirt.engine.core.common.action.AttachEntityToTagParameters) TagListModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel) Guid(org.ovirt.engine.core.compat.Guid) TagModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 3 with AttachEntityToTagParameters

use of org.ovirt.engine.core.common.action.AttachEntityToTagParameters in project ovirt-engine by oVirt.

the class VmListModel method postOnAssignTags.

@Override
public void postOnAssignTags(Map<Guid, Boolean> attachedTags) {
    TagListModel model = (TagListModel) getWindow();
    ArrayList<Guid> vmIds = new ArrayList<>();
    for (Object item : getSelectedItems()) {
        VM vm = (VM) item;
        vmIds.add(vm.getId());
    }
    // prepare attach/detach lists
    ArrayList<Guid> tagsToAttach = new ArrayList<>();
    ArrayList<Guid> tagsToDetach = new ArrayList<>();
    if (model.getItems() != null && model.getItems().size() > 0) {
        ArrayList<TagModel> tags = (ArrayList<TagModel>) model.getItems();
        TagModel rootTag = tags.get(0);
        TagModel.recursiveEditAttachDetachLists(rootTag, attachedTags, tagsToAttach, tagsToDetach);
    }
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    for (Guid a : tagsToAttach) {
        parameters.add(new AttachEntityToTagParameters(a, vmIds));
    }
    Frontend.getInstance().runMultipleAction(ActionType.AttachVmsToTag, parameters);
    parameters = new ArrayList<>();
    for (Guid a : tagsToDetach) {
        parameters.add(new AttachEntityToTagParameters(a, vmIds));
    }
    Frontend.getInstance().runMultipleAction(ActionType.DetachVmFromTag, parameters);
    cancel();
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) AttachEntityToTagParameters(org.ovirt.engine.core.common.action.AttachEntityToTagParameters) TagListModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel) Guid(org.ovirt.engine.core.compat.Guid) TagModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Aggregations

ArrayList (java.util.ArrayList)3 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 AttachEntityToTagParameters (org.ovirt.engine.core.common.action.AttachEntityToTagParameters)3 Guid (org.ovirt.engine.core.compat.Guid)3 TagListModel (org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel)3 TagModel (org.ovirt.engine.ui.uicommonweb.models.tags.TagModel)3 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)1 JsSingleValueStringObject (org.ovirt.engine.ui.frontend.utils.JsSingleValueStringObject)1