001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016
017package org.ametys.plugins.repository.jcr;
018
019import java.util.Map;
020import java.util.Set;
021
022import javax.jcr.Node;
023
024import org.ametys.core.group.GroupIdentity;
025import org.ametys.core.user.UserIdentity;
026import org.ametys.plugins.repository.AmetysObject;
027import org.ametys.plugins.repository.AmetysObjectIterable;
028import org.ametys.plugins.repository.AmetysRepositoryException;
029import org.ametys.plugins.repository.ModifiableACLAmetysObject;
030import org.ametys.plugins.repository.RepositoryIntegrityViolationException;
031import org.ametys.plugins.repository.TraversableAmetysObject;
032import org.ametys.plugins.repository.UnknownAmetysObjectException;
033
034/**
035 * Default implementation of a {@link TraversableAmetysObject}, backed by a JCR node.<br>
036 * This implementation heavily relies on its {@link DefaultTraversableAmetysObjectFactory} counterpart.
037 * @param <F> the actual type of factory.
038 */
039public class DefaultTraversableAmetysObject<F extends DefaultTraversableAmetysObjectFactory> extends SimpleAmetysObject<F> implements JCRTraversableAmetysObject, ModifiableACLAmetysObject
040{
041    private DefaultTraversableAmetysObjectFactory _traversableFactory;
042    
043    /**
044     * Creates a DefaultTraversableAmetysObject.
045     * @param node the node backing this {@link AmetysObject}.
046     * @param parentPath the parent path in the Ametys hierarchy.
047     * @param factory the {@link DefaultTraversableAmetysObjectFactory} which creates the AmetysObject.
048     */
049    public DefaultTraversableAmetysObject(Node node, String parentPath, F factory)
050    {
051        super(node, parentPath, factory);
052        _traversableFactory = factory;
053    }
054
055    public boolean hasChild(String name) throws AmetysRepositoryException
056    {
057        return _traversableFactory.hasChild(this, name);
058    }
059
060    @SuppressWarnings("unchecked")
061    public <A extends AmetysObject> A createChild(String name, String type) throws AmetysRepositoryException, RepositoryIntegrityViolationException
062    {
063        return (A) _traversableFactory.createChild(this, name, type);
064    }
065    
066    @SuppressWarnings("unchecked")
067    public <A extends AmetysObject> A getChild(String path) throws AmetysRepositoryException, UnknownAmetysObjectException
068    {
069        return (A) _traversableFactory.getChild(this, path);
070    }
071
072    public <A extends AmetysObject> AmetysObjectIterable<A> getChildren() throws AmetysRepositoryException
073    {
074        return _traversableFactory.getChildren(this);
075    }
076
077    @Override
078    public Set<String> getAllowedProfilesForAnyConnectedUser()
079    {
080        return ACLJCRAmetysObjectHelper.getAllowedProfilesForAnyConnectedUser(getNode());
081    }
082
083    @Override
084    public void addAllowedProfilesForAnyConnectedUser(Set<String> profileIds)
085    {
086        ACLJCRAmetysObjectHelper.addAllowedProfilesForAnyConnectedUser(getNode(), profileIds);
087    }
088    
089    @Override
090    public void removeAllowedProfilesForAnyConnectedUser(Set<String> profileIds)
091    {
092        ACLJCRAmetysObjectHelper.removeAllowedProfilesForAnyConnectedUser(getNode(), profileIds);
093    }
094    
095    @Override
096    public Set<String> getDeniedProfilesForAnyConnectedUser()
097    {
098        return ACLJCRAmetysObjectHelper.getDeniedProfilesForAnyConnectedUser(getNode());
099    }
100    
101    @Override
102    public void addDeniedProfilesForAnyConnectedUser(Set<String> profileIds)
103    {
104        ACLJCRAmetysObjectHelper.addDeniedProfilesForAnyConnectedUser(getNode(), profileIds);
105    }
106    
107    @Override
108    public void removeDeniedProfilesForAnyConnectedUser(Set<String> profileIds)
109    {
110        ACLJCRAmetysObjectHelper.removeDeniedProfilesForAnyConnectedUser(getNode(), profileIds);
111    }
112    
113    @Override
114    public Set<String> getAllowedProfilesForAnonymous()
115    {
116        return ACLJCRAmetysObjectHelper.getAllowedProfilesForAnonymous(getNode());
117    }
118    
119    @Override
120    public void addAllowedProfilesForAnonymous(Set<String> profileIds)
121    {
122        ACLJCRAmetysObjectHelper.addAllowedProfilesForAnonymous(getNode(), profileIds);
123    }
124    
125    @Override
126    public void removeAllowedProfilesForAnonymous(Set<String> profileIds)
127    {
128        ACLJCRAmetysObjectHelper.removeAllowedProfilesForAnonymous(getNode(), profileIds);
129    }
130    
131    @Override
132    public Set<String> getDeniedProfilesForAnonymous()
133    {
134        return ACLJCRAmetysObjectHelper.getDeniedProfilesForAnonymous(getNode());
135    }
136    
137    @Override
138    public void addDeniedProfilesForAnonymous(Set<String> profileIds)
139    {
140        ACLJCRAmetysObjectHelper.addDeniedProfilesForAnonymous(getNode(), profileIds);
141    }
142    
143    @Override
144    public void removeDeniedProfilesForAnonymous(Set<String> profileIds)
145    {
146        ACLJCRAmetysObjectHelper.removeDeniedProfilesForAnonymous(getNode(), profileIds);
147    }
148    
149    @Override
150    public Set<String> getAllowedProfilesForUser(UserIdentity user)
151    {
152        return ACLJCRAmetysObjectHelper.getAllowedProfilesForUser(getNode(), user);
153    }
154    
155    @Override
156    public Map<UserIdentity, Set<String>> getAllowedProfilesForUsers()
157    {
158        return ACLJCRAmetysObjectHelper.getAllowedProfilesForUsers(getNode());
159    }
160
161    @Override
162    public Set<UserIdentity> getAllowedUsers(String profileId)
163    {
164        return ACLJCRAmetysObjectHelper.getAllowedUsers(getNode(), profileId);
165    }
166
167    @Override
168    public void addAllowedUsers(Set<UserIdentity> users, String profileId)
169    {
170        ACLJCRAmetysObjectHelper.addAllowedUsers(users, getNode(), profileId);
171    }
172    
173    @Override
174    public void removeAllowedUsers(Set<UserIdentity> users, String profileId)
175    {
176        ACLJCRAmetysObjectHelper.removeAllowedUsers(users, getNode(), profileId);
177    }
178    
179    @Override
180    public void removeAllowedUsers(Set<UserIdentity> users)
181    {
182        ACLJCRAmetysObjectHelper.removeAllowedUsers(users, getNode());
183    }
184    
185    @Override
186    public Map<GroupIdentity, Set<String>> getAllowedProfilesForGroups()
187    {
188        return ACLJCRAmetysObjectHelper.getAllowedProfilesForGroups(getNode());
189    }
190
191    @Override
192    public Set<GroupIdentity> getAllowedGroups(String profileId)
193    {
194        return ACLJCRAmetysObjectHelper.getAllowedGroups(getNode(), profileId);
195    }
196
197    @Override
198    public void addAllowedGroups(Set<GroupIdentity> groups, String profileId)
199    {
200        ACLJCRAmetysObjectHelper.addAllowedGroups(groups, getNode(), profileId);
201    }
202    
203    @Override
204    public void removeAllowedGroups(Set<GroupIdentity> groups, String profileId)
205    {
206        ACLJCRAmetysObjectHelper.removeAllowedGroups(groups, getNode(), profileId);
207    }
208    
209    @Override
210    public void removeAllowedGroups(Set<GroupIdentity> groups)
211    {
212        ACLJCRAmetysObjectHelper.removeAllowedGroups(groups, getNode());
213    }
214    
215    @Override
216    public Set<String> getDeniedProfilesForUser(UserIdentity user)
217    {
218        return ACLJCRAmetysObjectHelper.getDeniedProfilesForUser(getNode(), user);
219    }
220    
221    @Override
222    public Map<UserIdentity, Set<String>> getDeniedProfilesForUsers()
223    {
224        return ACLJCRAmetysObjectHelper.getDeniedProfilesForUsers(getNode());
225    }
226
227    @Override
228    public Set<UserIdentity> getDeniedUsers(String profileId)
229    {
230        return ACLJCRAmetysObjectHelper.getDeniedUsers(getNode(), profileId);
231    }
232    
233    @Override
234    public void addDeniedUsers(Set<UserIdentity> users, String profileId)
235    {
236        ACLJCRAmetysObjectHelper.addDeniedUsers(users, getNode(), profileId);
237    }
238    
239    @Override
240    public void removeDeniedUsers(Set<UserIdentity> users, String profileId)
241    {
242        ACLJCRAmetysObjectHelper.removeDeniedUsers(users, getNode(), profileId);
243    }
244    
245    @Override
246    public void removeDeniedUsers(Set<UserIdentity> users)
247    {
248        ACLJCRAmetysObjectHelper.removeDeniedUsers(users, getNode());
249    }
250    
251    @Override
252    public Map<GroupIdentity, Set<String>> getDeniedProfilesForGroups()
253    {
254        return ACLJCRAmetysObjectHelper.getDeniedProfilesForGroups(getNode());
255    }
256
257    @Override
258    public Set<GroupIdentity> getDeniedGroups(String profileId)
259    {
260        return ACLJCRAmetysObjectHelper.getDeniedGroups(getNode(), profileId);
261    }
262
263    @Override
264    public void addDeniedGroups(Set<GroupIdentity> groups, String profileId)
265    {
266        ACLJCRAmetysObjectHelper.addDeniedGroups(groups, getNode(), profileId);
267    }
268    
269    @Override
270    public void removeDeniedGroups(Set<GroupIdentity> groups, String profileId)
271    {
272        ACLJCRAmetysObjectHelper.removeDeniedGroups(groups, getNode(), profileId);
273    }
274    
275    @Override
276    public void removeDeniedGroups(Set<GroupIdentity> groups)
277    {
278        ACLJCRAmetysObjectHelper.removeDeniedGroups(groups, getNode());
279    }
280    
281    @Override
282    public boolean isInheritanceDisallowed()
283    {
284        return ACLJCRAmetysObjectHelper.isInheritanceDisallowed(getNode());
285    }
286    
287    @Override
288    public void disallowInheritance(boolean disallow)
289    {
290        ACLJCRAmetysObjectHelper.disallowInheritance(getNode(), disallow);
291    }
292}