001/* 002 * (C) Copyright 2011 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.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 * ataillefer 016 */ 017package org.nuxeo.ecm.platform.task.core.helpers; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.nuxeo.ecm.core.api.NuxeoGroup; 023import org.nuxeo.ecm.core.api.NuxeoPrincipal; 024 025/** 026 * Helper class for dealing with task actors. 027 * <p> 028 * Provides a method to build the task actors list. 029 * 030 * @author ataillefer 031 */ 032public final class TaskActorsHelper { 033 034 /** 035 * Prevent instantiation. 036 */ 037 private TaskActorsHelper() { 038 // Final class 039 } 040 041 /** 042 * Gets the task actors list: prefixed and unprefixed names of the principal and all its groups. 043 * 044 * @param principal the principal 045 * @return the actors and group 046 */ 047 public static List<String> getTaskActors(NuxeoPrincipal principal) { 048 049 List<String> actors = new ArrayList<String>(); 050 051 String name = principal.getName(); 052 actors.add(name); 053 if (!name.startsWith(NuxeoPrincipal.PREFIX)) { 054 actors.add(NuxeoPrincipal.PREFIX + name); 055 } else { 056 actors.add(name.substring(NuxeoPrincipal.PREFIX.length())); 057 } 058 for (String group : principal.getAllGroups()) { 059 actors.add(group); 060 if (!group.startsWith(NuxeoGroup.PREFIX)) { 061 actors.add(NuxeoGroup.PREFIX + group); 062 } else { 063 actors.add(group.substring(NuxeoGroup.PREFIX.length())); 064 } 065 } 066 067 return actors; 068 } 069}