001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (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 * Thierry Delprat 016 * * 017 */ 018 019package org.nuxeo.ecm.platform.computedgroups; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.nuxeo.runtime.api.Framework; 025 026/** 027 * Computed group implementation class. Delegates part of the implementation logic to the {@link ComputedGroupsService} 028 * that is pluggable. 029 * 030 * @author Thierry Delprat 031 */ 032public class NuxeoComputedGroup implements ComputedGroup { 033 034 private static final long serialVersionUID = 1L; 035 036 protected String name; 037 038 protected List<String> parents; 039 040 protected List<String> subGroups; 041 042 protected List<String> members; 043 044 private String label; 045 046 public NuxeoComputedGroup(String name) { 047 this(name, null); 048 } 049 050 public NuxeoComputedGroup(String name, String label) { 051 this.name = name; 052 this.label = label; 053 } 054 055 @Override 056 public List<String> getMemberUsers() { 057 if (members == null) { 058 ComputedGroupsService cgs = Framework.getLocalService(ComputedGroupsService.class); 059 if (cgs != null) { 060 members = cgs.getComputedGroupMembers(name); 061 } 062 if (members == null) { 063 members = new ArrayList<String>(); 064 } 065 } 066 return members; 067 } 068 069 @Override 070 public String getName() { 071 return name; 072 } 073 074 @Override 075 public String getLabel() { 076 if (label != null) { 077 return label; 078 } 079 return getName(); 080 } 081 082 @Override 083 public List<String> getParentGroups() { 084 if (parents == null) { 085 ComputedGroupsService cgs = Framework.getLocalService(ComputedGroupsService.class); 086 if (cgs != null) { 087 parents = cgs.getComputedGroupParent(name); 088 } 089 if (parents == null) { 090 parents = new ArrayList<String>(); 091 } 092 } 093 return parents; 094 } 095 096 @Override 097 public List<String> getMemberGroups() { 098 if (subGroups == null) { 099 ComputedGroupsService cgs = Framework.getLocalService(ComputedGroupsService.class); 100 if (cgs != null) { 101 subGroups = cgs.getComputedGroupSubGroups(name); 102 } 103 if (subGroups == null) { 104 subGroups = new ArrayList<String>(); 105 } 106 } 107 return subGroups; 108 } 109 110 @Override 111 public void setMemberGroups(List<String> groups) { 112 throw new UnsupportedOperationException("Computed groups are read only"); 113 } 114 115 @Override 116 public void setMemberUsers(List<String> users) { 117 throw new UnsupportedOperationException("Computed groups are read only"); 118 } 119 120 @Override 121 public void setName(String name) { 122 throw new UnsupportedOperationException("Computed groups are read only"); 123 } 124 125 @Override 126 public void setLabel(String label) { 127 throw new UnsupportedOperationException("Computed groups are read only"); 128 } 129 130 @Override 131 public void setParentGroups(List<String> groups) { 132 throw new UnsupportedOperationException("Computed groups are read only"); 133 } 134 135}