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.automation.io.services.enricher; 018 019import java.io.IOException; 020import java.util.List; 021 022import org.codehaus.jackson.JsonGenerator; 023import org.nuxeo.common.utils.StringUtils; 024import org.nuxeo.ecm.automation.jaxrs.io.documents.JsonDocumentListWriter; 025import org.nuxeo.ecm.automation.jaxrs.io.documents.JsonDocumentWriter; 026import org.nuxeo.ecm.core.api.CoreSession; 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.core.api.DocumentModelList; 029import org.nuxeo.ecm.core.io.marshallers.json.enrichers.ChildrenJsonEnricher; 030 031/** 032 * This enricher adds a document list with all children to the contextParameters map. It is provided as sample and may 033 * not be used directly. For instance if you have millions of children, it will get all of them. 034 * 035 * @since 5.7.3 036 * @deprecated This enricher was migrated to {@link ChildrenJsonEnricher} 037 */ 038@Deprecated 039public class ChildrenEnricher extends AbstractContentEnricher { 040 041 @Override 042 public void enrich(JsonGenerator jg, RestEvaluationContext ec) throws IOException { 043 DocumentModel doc = ec.getDocumentModel(); 044 CoreSession session = doc.getCoreSession(); 045 DocumentModelList children = session.getChildren(doc.getRef()); 046 List<String> props = ec.getHeaders().getRequestHeader(JsonDocumentWriter.DOCUMENT_PROPERTIES_HEADER); 047 String[] schemas = null; 048 if (props != null && !props.isEmpty()) { 049 schemas = StringUtils.split(props.get(0), ',', true); 050 } 051 JsonDocumentListWriter.writeDocuments(jg, children, schemas, ec.getRequest()); 052 } 053 054}