001/**
002 * Copyright 2016 Tampere University of Technology, Pori Department
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 */
016package service.tut.pori.apilta.alerts.datatypes;
017
018import java.util.Set;
019
020import javax.xml.bind.annotation.XmlAccessType;
021import javax.xml.bind.annotation.XmlAccessorType;
022import javax.xml.bind.annotation.XmlElement;
023import javax.xml.bind.annotation.XmlElementWrapper;
024import javax.xml.bind.annotation.XmlEnum;
025import javax.xml.bind.annotation.XmlRootElement;
026
027import core.tut.pori.users.UserIdentity;
028
029/**
030 * 
031 * user for alert group
032 */
033@XmlRootElement(name=core.tut.pori.users.Definitions.ELEMENT_USER_IDENTITY)
034@XmlAccessorType(XmlAccessType.NONE)
035public class AlertUserIdentity extends UserIdentity {
036  /** serial version UID */
037  private static final long serialVersionUID = 2525582092128969017L;
038  @XmlElementWrapper(name=Definitions.ELEMENT_PERMISSION_LIST)
039  @XmlElement(name=Definitions.ELEMENT_PERMISSION)
040  private Set<UserPermission> _permissions = null;
041
042  /**
043   * 
044   * user permission for a group/user
045   *
046   */
047  @XmlEnum
048  public enum UserPermission {
049    /** the user can read alerts that are in this group */
050    READ_ALERTS(1),
051    /** the user can post new alerts into this group */
052    POST_ALERT(2),
053    /** the user can modify existing alerts of this group */
054    MODIFY_ALERTS(3),
055    /** user can read the alert group details, including group users */
056    READ_GROUP(4),
057    /** the user can modify the alert group */
058    MODIFY_GROUP(5);
059    
060    private int _value;
061    
062    /**
063     * 
064     * @param value
065     */
066    private UserPermission(int value) {
067      _value = value;
068    }
069    
070    /**
071     * 
072     * @return the permission as an integer value
073     */
074    public int toInt() {
075      return _value;
076    }
077    
078    /**
079     * 
080     * @param value
081     * @return the integer as user permission
082     * @throws IllegalArgumentException on bad value
083     */
084    public static UserPermission fromInt(int value) throws IllegalArgumentException {
085      for(UserPermission p : values()){
086        if(p._value == value){
087          return p;
088        }
089      }
090      throw new IllegalArgumentException("Invalid value: "+value);
091    }
092  } // enum UserPermission
093
094  /**
095   * @return the permissions
096   * @see #setPermissions(Set)
097   */
098  public Set<UserPermission> getPermissions() {
099    return _permissions;
100  }
101
102  /**
103   * @param permissions the permissions to set
104   * @see #getPermissions()
105   */
106  public void setPermissions(Set<UserPermission> permissions) {
107    _permissions = permissions;
108  }
109}