📄 groupproxy.java
字号:
package com.gs.db;
import java.util.Iterator;
/**
* Protection proxy for the Group interface. It restricts access of certain
* methods to those that have the proper permissions to administer this object.
*
* @see Group
*/
public class GroupProxy implements Group {
private Group group;
private Authorization authorization;
private IofficePermissions permissions;
/**
* Create a proxy object by the an existing Group object.
* @param group the existing Group
* @param authorization the token to the calling code
* @permissions the permissions owned by the calling code
*/
public GroupProxy(Group group, Authorization authorization,
IofficePermissions permissions)
{
this.group = group;
this.authorization = authorization;
this.permissions = permissions;
}
/**
* Returns the id of the group.
*
* @return the id of the group.
*/
public int getID() {
return group.getID();
}
/**
* Returns the name of the group. For example, 'XYZ Admins'.
*
* @return the name of the group.
*/
public String getName() {
return group.getName();
}
/**
* Sets the name of the group. For example, 'XYZ Admins'.<p>
*
* This method is restricted to those with group administration permission.
*
* @param name the name for the group.
* @throws UnauthorizedException if does not have group admin permissions.
*/
public void setName(String name) throws UnauthorizedException {
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.setName(name);
}
else {
throw new UnauthorizedException();
}
}
/**
* Returns the description of the group. The description often summarizes
* a group's function, such as 'Administrators of the XYZ forum'.
*
* @return the description of the group.
*/
public String getDescription() {
return group.getDescription();
}
/**
* Sets the description of the group.
*
* The description often summarizes a group's function, such as
* 'Administrators '.<p>
*
* This method is restricted to those with group administration permission.
*
* @param name the description of the group.
* @throws UnauthorizedException if does not have group admin permissions.
*/
public void setDescription(String description) throws UnauthorizedException
{
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.setDescription(description);
}
else {
throw new UnauthorizedException();
}
}
/**
* Adds a member to the group.<p>
*
* This method is restricted to those with group administration permission.
*
* @param user the User to add to the group.
* @throws UnauthorizedException if does not have group admin permissions.
*/
public void addMember(User user) throws UnauthorizedException {
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN)||group.getName().equals("selfRegister")
||group.getName().equals("生产人员")||group.getName().equals("管理人员") )
{
group.addMember(user);
}
else {
throw new UnauthorizedException();
}
}
/**
* Removes a member from the group. If the User is not in the group, this
* method does nothing.<p>
*
* This method is restricted to those with group administration permission.
*
* @param user the User to remove from the group.
* @throws UnauthorizedException if does not have group admin permissions.
*/
public void removeMember(User user) throws UnauthorizedException {
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.removeMember(user);
}
else {
throw new UnauthorizedException();
}
}
/**
* Returns true if if the User is a member of the group.
*
* @return true if the User is a member of the group.
*/
public boolean isMember(User user) {
return group.isMember(user);
}
/**
* Returns the number of group members.
*
* @return the number of group members.
*/
public int getMemberCount() {
return group.getMemberCount();
}
/**
* An iterator for all the users that are members of the group.
*
* @return an Iterator for all members of the group.
*/
public Iterator members() {
return group.members();
}
/**
* Returns the permissions for the group that correspond to the
* passed-in Authorization.
*
* @param authorization the auth token to lookup permissions for.
*/
public IofficePermissions getPermissions(Authorization authorization) {
return group.getPermissions(authorization);
}
/**
* Returns true if the handle on the object has the permission specified.
* A list of possible permissions can be found in the ForumPermissions
* class. Certain methods of this class are restricted to certain
* permissions as specified in the method comments.
*
* @param type a permission type.
* @return true if the specified permission is valid.
* @see IofficePermissions
*/
public boolean hasPermission(int type) {
return permissions.get(type);
}
/**
* Returns true if the group is associated with a unit.
*
* @return true if the group is associated with a unit..
* @see Unit
*/
public boolean hasAssociateUnit() {
return group.hasAssociateUnit();
}
/**
* Returns the unit object that group is associated with
*
* @return the Unit object that group is associated with
* @see Unit
*/
public Unit getAssociateUnit(){ /* return null if not linked with Unit */
Unit unit = group.getAssociateUnit();
return new UnitProxy( unit, authorization, permissions);
}
/**
* Returns the priority level of the group in terms of being
* associated with a unit
* @return priority level
*/
public int getPriorityInUnit(){ /*return -1 if not linked with Unit*/
return group.getPriorityInUnit();
}
/**
* Grants administrator privileges of the group to a user.<p>
*
* This method is restricted to those with group administration permission.
*
* @param user the User to grant adminstrative privileges to.
* @throws UnauthorizedException if does not have group admin permissions.
*/
public void addAdministrator(User user) throws UnauthorizedException {
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.addAdministrator(user);
}
else {
throw new UnauthorizedException();
}
}
/**
* Revokes administrator privileges of the group to a user.<p>
*
* This method is restricted to those with group administration permission.
*
* @param user the User to grant adminstrative privileges to.
* @throws UnauthorizedException if does not have group admin permissions.
*/
public void removeAdministrator(User user) throws UnauthorizedException {
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.removeAdministrator(user);
}
else {
throw new UnauthorizedException();
}
}
/**
* Returns true if the User has group administrator permissions. Group
* administrators are also considered to be members.
*
* @return true if the User is an administrator of the group.
*/
public boolean isAdministrator(User user) {
return group.isAdministrator(user);
}
/**
* Returns the number of group administrators.
*
* @return the number of group administrators.
*/
public int getAdministratorCount() {
return group.getAdministratorCount();
}
/**
* An iterator for all the users that are administrators of the group.
*
* @return an Iterator for all administrators of the group.
*/
public Iterator administrators() {
return group.administrators();
}
/**
* Establish the association with a unit
*
*@thows UnauthorizedException if it doesnot have system-admin permission
* @see Unit
*/
public void linkToUnit(Unit unit) throws UnauthorizedException
{
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.linkToUnit(unit);
}
else {
throw new UnauthorizedException();
}
}
/**
* Break the association with with a unit
*
*@thows UnauthorizedException if it doesnot have system-admin permission
* @see Unit
*/
public void unlinkUnit() throws UnauthorizedException
{
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.unlinkUnit();
}
else {
throw new UnauthorizedException();
}
}
/**
* Set the priority level of the group
*
*@thows UnauthorizedException if it doesnot have system-admin permission
* @see Unit
*/
public void setPriority(int priority) throws UnauthorizedException
{
if (permissions.get(IofficePermissions.SYSTEM_ADMIN) ||
permissions.get(IofficePermissions.GROUP_ADMIN))
{
group.setPriority(priority);
}
else {
throw new UnauthorizedException();
}
}
/**
* Synonym of getPriorityInUnit
* @return the priority level of the group
*/
public int getPriority()
{
return group.getPriority();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -