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 */ 011 012package org.nuxeo.ecm.automation.jsf.operations; 013 014import org.nuxeo.ecm.automation.OperationContext; 015import org.nuxeo.ecm.automation.core.Constants; 016import org.nuxeo.ecm.automation.core.annotations.Context; 017import org.nuxeo.ecm.automation.core.annotations.Operation; 018import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 019import org.nuxeo.ecm.automation.jsf.OperationHelper; 020import org.nuxeo.ecm.core.api.DocumentModel; 021import org.nuxeo.ecm.core.api.DocumentModelList; 022import org.nuxeo.ecm.webapp.documentsLists.DocumentsListsPersistenceManager; 023 024import static org.nuxeo.ecm.webapp.documentsLists.DocumentsListsManager.DEFAULT_WORKING_LIST; 025 026/** 027 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 028 */ 029@Operation(id = PushToWorklist.ID, category = Constants.CAT_UI, requires = Constants.SEAM_CONTEXT, label = "Push to Worklist", description = "Add the input document(s) to worklist. Returns back the document(s)", aliases = { "Seam.AddToWorklist" }) 030public class PushToWorklist { 031 032 public static final String ID = "WebUI.AddToWorklist"; 033 034 @Context 035 protected OperationContext ctx; 036 037 @OperationMethod 038 public DocumentModel run(DocumentModel doc) { 039 if (OperationHelper.isSeamContextAvailable()) { 040 OperationHelper.getDocumentListManager().addToWorkingList(DEFAULT_WORKING_LIST, doc); 041 } else { 042 DocumentsListsPersistenceManager pm = new DocumentsListsPersistenceManager(); 043 pm.addDocumentToPersistentList(ctx.getPrincipal().getName(), DEFAULT_WORKING_LIST, doc); 044 } 045 return doc; 046 } 047 048 @OperationMethod 049 public DocumentModelList run(DocumentModelList docs) { 050 if (OperationHelper.isSeamContextAvailable()) { 051 OperationHelper.getDocumentListManager().addToWorkingList(DEFAULT_WORKING_LIST, docs); 052 } else { 053 DocumentsListsPersistenceManager pm = new DocumentsListsPersistenceManager(); 054 for (DocumentModel doc : docs) { 055 pm.addDocumentToPersistentList(ctx.getPrincipal().getName(), DEFAULT_WORKING_LIST, doc); 056 } 057 } 058 return docs; 059 } 060 061}