001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.api.security; 021 022 import org.sonar.api.database.BaseIdentifiable; 023 024 import javax.persistence.Column; 025 import javax.persistence.Entity; 026 import javax.persistence.Table; 027 028 /** 029 * @since 1.12 030 */ 031 @Entity 032 @Table(name = "group_roles") 033 public class GroupRole extends BaseIdentifiable { 034 035 public static final Integer ANYONE_GROUP_ID = null; 036 037 @Column(name = "group_id") 038 private Integer groupId; 039 040 @Column(name = "role") 041 private String role; 042 043 @Column(name = "resource_id") 044 private Integer resourceId; 045 046 public static GroupRole buildGlobalRole(Integer groupId, String role) { 047 return new GroupRole().setGroupId(groupId).setRole(role); 048 } 049 050 public static GroupRole buildResourceRole(Integer groupId, String role, Integer resourceId) { 051 return new GroupRole().setGroupId(groupId).setRole(role).setResourceId(resourceId); 052 } 053 054 public Integer getGroupId() { 055 return groupId; 056 } 057 058 public GroupRole setGroupId(Integer groupId) { 059 this.groupId = groupId; 060 return this; 061 } 062 063 public String getRole() { 064 return role; 065 } 066 067 public GroupRole setRole(String role) { 068 this.role = role; 069 return this; 070 } 071 072 public Integer getResourceId() { 073 return resourceId; 074 } 075 076 public GroupRole setResourceId(Integer resourceId) { 077 this.resourceId = resourceId; 078 return this; 079 } 080 081 public boolean isAnyone() { 082 return groupId==ANYONE_GROUP_ID; 083 } 084 }