001/*
002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     "Guillaume Renard"
018 */
019
020package org.nuxeo.ecm.restapi.server.jaxrs.adapters;
021
022import javax.ws.rs.Produces;
023import javax.ws.rs.core.MediaType;
024
025import org.nuxeo.ecm.core.api.NuxeoPrincipal;
026import org.nuxeo.ecm.platform.query.api.PageProviderDefinition;
027import org.nuxeo.ecm.platform.query.api.PageProviderService;
028import org.nuxeo.ecm.restapi.server.jaxrs.usermanager.GroupObject;
029import org.nuxeo.ecm.webengine.model.WebAdapter;
030import org.nuxeo.runtime.api.Framework;
031
032/**
033 * @since 8.2
034 */
035@WebAdapter(name = GroupMemberUsersAdapter.NAME, type = "GroupMemberUsers")
036@Produces({ "application/json+nxentity", MediaType.APPLICATION_JSON })
037public class GroupMemberUsersAdapter extends PaginableAdapter<NuxeoPrincipal> {
038
039    public static final String NAME = "users";
040    public static final String PAGE_PROVIDER_NAME = "nuxeo_group_member_users_listing";
041
042    protected String query;
043
044    @Override
045    protected void initialize(Object... args) {
046        super.initialize(args);
047        query = ctx.getRequest().getParameter("q");
048    }
049
050    @Override
051    protected PageProviderDefinition getPageProviderDefinition() {
052        PageProviderService ppService = Framework.getService(PageProviderService.class);
053        return ppService.getPageProviderDefinition(PAGE_PROVIDER_NAME);
054    }
055
056    @Override
057    protected Object[] getParams() {
058        return new Object[] { ((GroupObject) getTarget()).doGetArtifact(), query };
059    }
060
061}