001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.core.operations.document; 013 014import org.nuxeo.ecm.automation.core.Constants; 015import org.nuxeo.ecm.automation.core.annotations.Context; 016import org.nuxeo.ecm.automation.core.annotations.Operation; 017import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 018import org.nuxeo.ecm.automation.core.annotations.Param; 019import org.nuxeo.ecm.automation.core.collectors.DocumentModelListCollector; 020import org.nuxeo.ecm.core.api.CoreSession; 021import org.nuxeo.ecm.core.api.DocumentModel; 022import org.nuxeo.ecm.core.api.DocumentModelList; 023import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl; 024 025/** 026 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 027 */ 028@Operation(id = MultiPublishDocument.ID, category = Constants.CAT_DOCUMENT, label = "Multi-Publish", description = "Publish the input document(s) into several target sections. The target is evaluated to a document list (can be a path, UID or EL expression). Existing proxy is overridden if the override attribute is set. Returns a list with the created proxies.", aliases = { "Document.MultiPublish" }) 029public class MultiPublishDocument { 030 031 public static final String ID = "Document.PublishToSections"; 032 033 @Context 034 protected CoreSession session; 035 036 @Param(name = "target") 037 protected DocumentModelList target; 038 039 @Param(name = "override", required = false, values = "true") 040 protected boolean override = true; 041 042 @OperationMethod(collector = DocumentModelListCollector.class) 043 public DocumentModelList run(DocumentModel doc) { 044 DocumentModelListImpl docs = new DocumentModelListImpl(); 045 for (DocumentModel t : target) { 046 docs.add(session.publishDocument(doc, t, override)); 047 } 048 return docs; 049 } 050 051}