001/* 002 * (C) Copyright 2013 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 * dmetzler 018 */ 019package org.nuxeo.ecm.restapi.server.jaxrs.adapters; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.Path; 023import javax.ws.rs.PathParam; 024import javax.ws.rs.Produces; 025import javax.ws.rs.core.MediaType; 026 027import org.nuxeo.ecm.automation.core.util.Paginable; 028import org.nuxeo.ecm.core.api.DocumentModel; 029import org.nuxeo.ecm.platform.query.api.PageProviderDefinition; 030import org.nuxeo.ecm.platform.query.api.PageProviderService; 031import org.nuxeo.ecm.webengine.model.WebAdapter; 032import org.nuxeo.runtime.api.Framework; 033 034/** 035 * Adapter that expose a page provider that needs only one parameter that is the document Id 036 * 037 * @since 5.7.2 038 */ 039@WebAdapter(name = PageProviderAdapter.NAME, type = "PageProviderService") 040@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON + "+esentity" }) 041public class PageProviderAdapter extends DocumentModelListPaginableAdapter { 042 043 public static final String NAME = "pp"; 044 045 private String pageProviderName = "CURRENT_DOC_CHILDREN"; 046 047 @Override 048 protected PageProviderDefinition getPageProviderDefinition() { 049 PageProviderService ppService = Framework.getService(PageProviderService.class); 050 return ppService.getPageProviderDefinition(pageProviderName); 051 } 052 053 @Override 054 protected Object[] getParams() { 055 return new Object[] { getTarget().getAdapter(DocumentModel.class).getId() }; 056 } 057 058 @GET 059 @Path("{pageProviderName}") 060 public Paginable<DocumentModel> getProviderDocs(@PathParam("pageProviderName") String providerName) 061 { 062 pageProviderName = providerName; 063 return super.getPaginableEntries(); 064 } 065 066}