package org.ovirt.engine.api.restapi.resource;

import javax.ws.rs.core.Response;

import org.ovirt.engine.api.model.Group;
import org.ovirt.engine.api.model.Groups;
import org.ovirt.engine.api.resource.GroupResource;
import org.ovirt.engine.api.resource.GroupsResource;
import org.ovirt.engine.core.common.action.AddUserParameters;
import org.ovirt.engine.core.common.action.VdcActionType;
import org.ovirt.engine.core.common.businessentities.LdapGroup;
import org.ovirt.engine.core.common.businessentities.DbUser;
import org.ovirt.engine.core.common.interfaces.SearchType;
import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
import org.ovirt.engine.core.common.queries.VdcQueryType;

public class BackendGroupsResource extends BackendGroupsResourceBase implements GroupsResource {

    public BackendGroupsResource() {
        super(Group.class, LdapGroup.class, SUB_COLLECTIONS);
    }

    public BackendGroupsResource(String id, BackendDomainResource parent) {
        super(id, parent);
    }

    @Override
    public Groups list() {
        if (isFiltered()) {
            return mapDbGroupsCollection(getBackendCollection(DbUser.class, VdcQueryType.GetAllDbUsers, new VdcQueryParametersBase()));
        } else {
            return mapDbGroupsCollection(getGroupsCollection(SearchType.DBUser, getSearchPattern()));
        }
    }

    @Override
    public Response add(Group group) {
        validateParameters(group, "name");
        // somewhat counter-intuitively, the AddUserCommand is used
        // to add groups as well as users
        AddUserParameters newGroup = new AddUserParameters();
        newGroup.setAdGroup(getAdGroup(group));
        return performCreate(VdcActionType.AddUser, newGroup, new GroupIdResolver(newGroup.getAdGroup().getid()));
    }

    @Override
    @SingleEntityResource
    public GroupResource getGroupSubResource(String id) {
        return inject(new BackendGroupResource(id, this));
    }

}

@@ -488,212 +488,25 @@
 mon.
-businessentities.DbUser;%0Aimport org.ovirt.engine.core.common.interfaces.SearchType;%0Aimport org.ovirt.engine.core.common.queries.VdcQueryParametersBase;%0Aimport org.ovirt.engine.core.common.queries.VdcQuery
+interfaces.Search
 Type
@@ -867,193 +867,8 @@
 ) %7B%0A
-        if (isFiltered()) %7B%0A            return mapDbGroupsCollection(getBackendCollection(DbUser.class, VdcQueryType.GetAllDbUsers, new VdcQueryParametersBase()));%0A        %7D else %7B%0A    
     
@@ -965,18 +965,8 @@
 ));%0A
-        %7D%0A
     

Disable Get Groups For Non-Admin User