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 java.util.List; 015 016import org.nuxeo.ecm.automation.OperationContext; 017import org.nuxeo.ecm.automation.core.Constants; 018import org.nuxeo.ecm.automation.core.annotations.Context; 019import org.nuxeo.ecm.automation.core.annotations.Operation; 020import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 021import org.nuxeo.ecm.automation.jsf.OperationHelper; 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.core.api.DocumentModelList; 024import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl; 025import org.nuxeo.ecm.webapp.documentsLists.DocumentsListsManager; 026import org.nuxeo.ecm.webapp.documentsLists.DocumentsListsPersistenceManager; 027 028/** 029 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 030 */ 031@Operation(id = FetchFromWorklist.ID, category = Constants.CAT_FETCH, requires = Constants.SEAM_CONTEXT, label = "UI Worklist", description = "Get worklist content from the UI context.") 032public class FetchFromWorklist { 033 034 public static final String ID = "Seam.FetchFromWorklist"; 035 036 @Context 037 protected OperationContext ctx; 038 039 @OperationMethod 040 public DocumentModelList run() { 041 List<DocumentModel> res = null; 042 if (OperationHelper.isSeamContextAvailable()) { 043 res = OperationHelper.getDocumentListManager().getWorkingList(DocumentsListsManager.DEFAULT_WORKING_LIST); 044 } else { 045 DocumentsListsPersistenceManager pm = new DocumentsListsPersistenceManager(); 046 res = pm.loadPersistentDocumentsLists(ctx.getCoreSession(), ctx.getPrincipal().getName(), 047 DocumentsListsManager.DEFAULT_WORKING_LIST); 048 } 049 return new DocumentModelListImpl(res); 050 } 051}