001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-api/api/src/java/org/sakaiproject/content/api/GroupAwareEntity.java $
003: * $Id: GroupAwareEntity.java 13360 2006-08-03 21:35:13Z jimeng@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.content.api;
021:
022: import java.util.Collection;
023:
024: import org.sakaiproject.entity.api.Entity;
025: import org.sakaiproject.time.api.Time;
026:
027: /**
028: * <p>
029: * GroupAwareEntity is an interface that must be implemented for entity types that are to be group aware.
030: * </p>
031: */
032: public interface GroupAwareEntity extends Entity {
033: /**
034: * Access the groups defined for this entity.
035: *
036: * @return A Collection of references to Group objects defined for this entity; empty if none are defined.
037: */
038: public Collection getGroups();
039:
040: /**
041: * Access the groups, as Group objects, defined for this entity.
042: *
043: * @return A Collection (Group) of group objects defined for this entity; empty if none are defined.
044: */
045: public Collection getGroupObjects();
046:
047: /**
048: * Access the access mode defined locally for the entity.
049: *
050: * @return The access mode for the entity.
051: */
052: public AccessMode getAccess();
053:
054: /**
055: * Access the groups inherited by this entity.
056: *
057: * @return A Collection of Group objects defined locally for this entity; empty if none are defined.
058: */
059: public Collection getInheritedGroups();
060:
061: /**
062: * Access the groups, as Group objects, inherited by this entity.
063: *
064: * @return A Collection (Group) of group objects defined for this entity; empty if none are defined.
065: */
066: public Collection getInheritedGroupObjects();
067:
068: /**
069: * Access the actual access mode used to compute who has access to the entity
070: * (usually SITE or GROUPED, but not INHERITED). This may be defined locally
071: * or inherited from elsewhere for the entity. If the local access mode is
072: * INHERITED, the actual access mode must be retrieved from elsewhere.
073: *
074: * @return The actual access mode for the entity.
075: */
076: public AccessMode getInheritedAccess();
077:
078: /**
079: * Access the release date before which this entity should not be available to users
080: * except those with adequate permission (what defines "adequate permission" is TBD).
081: * @return The date/time at which the entity may be accessed by all users.
082: */
083: public Time getReleaseDate();
084:
085: /**
086: * Access the retract date after which this entity should not be available to users
087: * except those with adequate permission (what defines "adequate permission" is TBD).
088: * @return The date/time at which access to the entity should be restricted.
089: */
090: public Time getRetractDate();
091:
092: /**
093: * Access the raw availability setting for this entity: is it set to "hide" or "show".
094: * Does not take into account the release or retract dates.
095: * @return
096: */
097: public boolean isHidden();
098:
099: /**
100: * Calculate the avilability based on whether the item is hidden and (if not) whether
101: * it has a releaseDate or retractDate and (if so) neither of them restrict availabity
102: * right now.
103: * @return true if the entity is available now, false otherwise.
104: */
105: public boolean isAvailable();
106:
107: /**
108: * <p>
109: * AccessMode enumerates different access modes for the entity: site-wide or grouped.
110: * </p>
111: */
112: public class AccessMode {
113: protected final String m_id;
114:
115: private AccessMode(String id) {
116: m_id = id;
117: }
118:
119: public String toString() {
120: return m_id;
121: }
122:
123: public boolean equals(Object obj) {
124: boolean rv = false;
125:
126: if (obj instanceof AccessMode) {
127: rv = ((AccessMode) obj).toString().equals(
128: this .toString());
129: }
130:
131: return rv;
132: }
133:
134: static public AccessMode fromString(String access) {
135: if (SITE.m_id.equals(access))
136: return SITE;
137: if (GROUPED.m_id.equals(access))
138: return GROUPED;
139: if (INHERITED.m_id.equals(access))
140: return INHERITED;
141: //if (PUBLIC.m_id.equals(access)) return PUBLIC;
142: return null;
143: }
144:
145: /** public access to the entity */
146: //public static final AccessMode PUBLIC = new AccessMode("public");
147: /** channel (site) level access to the entity */
148: public static final AccessMode SITE = new AccessMode("site");
149:
150: /** grouped access; only members of the getGroup() groups (authorization groups) have access */
151: public static final AccessMode GROUPED = new AccessMode(
152: "grouped");
153:
154: /** inherited access; must look up a hierarchy to determine actual access */
155: public static final AccessMode INHERITED = new AccessMode(
156: "inherited");
157:
158: }
159: }
|