001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     dmetzler
016 */
017package org.nuxeo.ecm.restapi.server.jaxrs.adapters;
018
019import javax.ws.rs.Produces;
020import javax.ws.rs.core.MediaType;
021
022import org.nuxeo.ecm.core.api.DocumentModel;
023import org.nuxeo.ecm.platform.query.api.PageProviderDefinition;
024import org.nuxeo.ecm.platform.query.api.PageProviderService;
025import org.nuxeo.ecm.webengine.model.WebAdapter;
026import org.nuxeo.runtime.api.Framework;
027
028/**
029 * Adapter that returns the children of the pointed resource
030 *
031 * @since 5.7.2
032 */
033@WebAdapter(name = ChildrenAdapter.NAME, type = "ChildrenService")
034@Produces({ "application/json+nxentity", "application/json+esentity", MediaType.APPLICATION_JSON })
035public class ChildrenAdapter extends DocumentModelListPaginableAdapter {
036
037    public static final String NAME = "children";
038
039    @Override
040    protected PageProviderDefinition getPageProviderDefinition() {
041        PageProviderService ppService = Framework.getLocalService(PageProviderService.class);
042        return ppService.getPageProviderDefinition("CURRENT_DOC_CHILDREN");
043    }
044
045    @Override
046    protected Object[] getParams() {
047        return new Object[] { getTarget().getAdapter(DocumentModel.class).getId() };
048    }
049}