Package org.opentides.bean.user

Source Code of org.opentides.bean.user.UserRole

/*
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.   
*/

package org.opentides.bean.user;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.opentides.bean.Auditable;
import org.opentides.bean.AuditableField;
import org.opentides.bean.BaseEntity;

@Entity
@AttributeOverride(name = "id", column = @Column(insertable = false, updatable = false))
@Table(name = "AUTHORITIES")
public class UserRole extends BaseEntity implements Auditable {
  private static final long serialVersionUID = -2779918759002560767L;

  @Column(name = "USERNAME")
  private String username;

  @Column(name = "AUTHORITY")
  private String role;
 
  // userGroup is nullable, to support username linkage
  @ManyToOne(optional = false)
  @JoinColumn(name = "USERGROUP_ID", nullable = true)
  private UserGroup userGroup;

  public UserRole() {
    super();
  }

  public UserRole(UserGroup userGroup, String role) {
    Date now = new Date();
    this.setUserGroup(userGroup);
    this.setRole(role);
    this.setCreateDate(now);
    this.setUpdateDate(now);
  }

  public String getRole() {
    return role;
  }

  public void setRole(String role) {
    this.role = role;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  /**
   * @return the userGroup
   */
  public UserGroup getUserGroup() {
    return userGroup;
  }

  /**
   * @param userGroup
   *            the userGroup to set
   */
  public void setUserGroup(UserGroup userGroup) {
    this.userGroup = userGroup;
  }

  /* (non-Javadoc)
   * @see org.opentides.bean.Auditable#getPrimaryField()
   */
  @Override
  public AuditableField getPrimaryField() {
    return new AuditableField("role","Role");
  }
 
  public List<AuditableField> getAuditableFields() {
    List<AuditableField> props = new ArrayList<AuditableField>();
    props.add(new AuditableField("userGroup.name","Name"));
    props.add(new AuditableField("role","Role"));
    return props;
  }
 
  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
    final int PRIME = 31;
    int result = 1;
    result = PRIME * result + ((role == null) ? 0 : role.hashCode());
    return result;
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    final UserRole other = (UserRole) obj;
    if (role == null) {
      if (other.role != null)
        return false;
    } else if (!role.equals(other.role))
      return false;
    return true;
  }

}
TOP

Related Classes of org.opentides.bean.user.UserRole

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.