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.apache.commons.lang.builder.ReflectionToStringBuilder; 023 import org.apache.commons.lang.builder.ToStringStyle; 024 import org.sonar.api.database.BaseIdentifiable; 025 026 import javax.persistence.Column; 027 import javax.persistence.Entity; 028 import javax.persistence.Table; 029 030 /** 031 * @since 1.12 032 */ 033 @Entity 034 @Table(name = "group_roles") 035 public class GroupRole extends BaseIdentifiable { 036 037 public static final Integer ANYONE_GROUP_ID = null; 038 039 @Column(name = "group_id") 040 private Integer groupId; 041 042 @Column(name = "role") 043 private String role; 044 045 @Column(name = "resource_id") 046 private Integer resourceId; 047 048 public static GroupRole buildGlobalRole(Integer groupId, String role) { 049 return new GroupRole().setGroupId(groupId).setRole(role); 050 } 051 052 public static GroupRole buildResourceRole(Integer groupId, String role, Integer resourceId) { 053 return new GroupRole().setGroupId(groupId).setRole(role).setResourceId(resourceId); 054 } 055 056 public Integer getGroupId() { 057 return groupId; 058 } 059 060 public GroupRole setGroupId(Integer groupId) { 061 this.groupId = groupId; 062 return this; 063 } 064 065 public String getRole() { 066 return role; 067 } 068 069 public GroupRole setRole(String role) { 070 this.role = role; 071 return this; 072 } 073 074 public Integer getResourceId() { 075 return resourceId; 076 } 077 078 public GroupRole setResourceId(Integer resourceId) { 079 this.resourceId = resourceId; 080 return this; 081 } 082 083 public boolean isAnyone() { 084 return groupId==ANYONE_GROUP_ID; 085 } 086 087 @Override 088 public String toString() { 089 return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); 090 } 091 }