001/* 002 * (C) Copyright 2014 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 * <a href="mailto:glefevre@nuxeo.com">Gildas</a> 016 */ 017package org.nuxeo.ecm.collections.core.automation; 018 019import org.nuxeo.ecm.automation.core.Constants; 020import org.nuxeo.ecm.automation.core.annotations.Context; 021import org.nuxeo.ecm.automation.core.annotations.Operation; 022import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 023import org.nuxeo.ecm.automation.core.annotations.Param; 024import org.nuxeo.ecm.collections.api.CollectionManager; 025import org.nuxeo.ecm.core.api.CoreSession; 026import org.nuxeo.ecm.core.api.DocumentModel; 027 028/** 029 * Class for the operation to create a Collection. 030 * 031 * @since 5.9.4 032 */ 033@Operation(id = CreateCollectionOperation.ID, category = Constants.CAT_DOCUMENT, label = "Create a collection", description = "Create a new collection. " 034 + "This is returning the document serialization of the created collection.", aliases = { "Collection.CreateCollection" }) 035public class CreateCollectionOperation { 036 037 public static final String ID = "Collection.Create"; 038 039 @Context 040 protected CoreSession session; 041 042 @Context 043 protected CollectionManager collectionManager; 044 045 @Param(name = "name") 046 protected String name; 047 048 @Param(name = "description", required = false) 049 protected String description; 050 051 @OperationMethod 052 public DocumentModel run(DocumentModel doc) { 053 return collectionManager.createCollection(session, name, description, doc.getPathAsString()); 054 } 055 056 @OperationMethod 057 public DocumentModel run() { 058 return collectionManager.createCollection(session, name, description, null); 059 } 060}