diff --git a/ccm-core/src/main/java/org/libreccm/core/GroupMembership.java b/ccm-core/src/main/java/org/libreccm/core/GroupMembership.java new file mode 100644 index 000000000..eb5c57c62 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/core/GroupMembership.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2015 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.core; + +import java.io.Serializable; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "group_memberships") +public class GroupMembership implements Serializable { + + private static final long serialVersionUID = 1897274442468035089L; + + @Id + @Column(name = "membership_id") + @GeneratedValue(strategy = GenerationType.AUTO) + private long membershipId; + + @ManyToOne + private UserGroup group; + + @ManyToOne + private User user; + + public long getMembershipId() { + return membershipId; + } + + protected void setMembershipId(final long membershipId) { + this.membershipId = membershipId; + } + + public UserGroup getGroup() { + return group; + } + + protected void setGroup(final UserGroup group) { + this.group = group; + } + + public User getUser() { + return user; + } + + protected void setUser(final User user) { + this.user = user; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 37 * hash + + (int) (this.membershipId ^ (this.membershipId >>> 32)); + hash = 37 * hash + Objects.hashCode(this.group); + hash = 37 * hash + Objects.hashCode(this.user); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final GroupMembership other = (GroupMembership) obj; + if (!other.canEqual(this)) { + return false; + } + + if (this.membershipId != other.membershipId) { + return false; + } + if (!Objects.equals(this.group, other.group)) { + return false; + } + return Objects.equals(this.user, other.user); + } + + public boolean canEqual(final Object obj) { + return obj instanceof GroupMembership; + } + + @Override + public String toString() { + return String.format("%s{ " + + "membershipId = %d, " + + "user = %s, " + + "group = %s, " + + " }," + + super.toString(), + Objects.toString(user), + Objects.toString(group)); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/core/Role.java b/ccm-core/src/main/java/org/libreccm/core/Role.java new file mode 100644 index 000000000..3ef200106 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/core/Role.java @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2015 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.core; + +import java.io.Serializable; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import org.hibernate.validator.constraints.NotBlank; + +/** + * + * @author Jens Pelzetter + */ +@Entity +@Table(name = "roles") +public class Role implements Serializable { + + private static final long serialVersionUID = 3314358449751376350L; + + @Id + @Column(name = "role_id") + @GeneratedValue(strategy = GenerationType.AUTO) + private long roleId; + + @Column(name = "name", length = 512) + @NotBlank + private String name; + + @ManyToOne + private UserGroup sourceGroup; + + @OneToOne + private UserGroup implicitGroup; + + @Column(name = "description") + private String description; + + public Role() { + //Nothing + } + + public long getRoleId() { + return roleId; + } + + public void setRoleId(final long roleId) { + this.roleId = roleId; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public UserGroup getSourceGroup() { + return sourceGroup; + } + + protected void setSourceGroup(final UserGroup sourceGroup) { + this.sourceGroup = sourceGroup; + } + + public UserGroup getImplicitGroup() { + return implicitGroup; + } + + protected void setImplicitGroup(final UserGroup implicitGroup) { + this.implicitGroup = implicitGroup; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + (int) (this.roleId ^ (this.roleId >>> 32)); + hash = 59 * hash + Objects.hashCode(this.name); + hash = 59 * hash + Objects.hashCode(this.sourceGroup); + hash = 59 * hash + Objects.hashCode(this.implicitGroup); + hash = 59 * hash + Objects.hashCode(this.description); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Role other = (Role) obj; + if (!other.canEqual(this)) { + return false; + } + + if (this.roleId != other.roleId) { + return false; + } + if (!Objects.equals(this.name, other.getName())) { + return false; + } + if (!Objects.equals(this.sourceGroup, other.getSourceGroup())) { + return false; + } + if (!Objects.equals(this.implicitGroup, other.getImplicitGroup())) { + return false; + } + return Objects.equals(this.description, other.getDescription()); + } + + public boolean canEqual(final Object obj) { + return obj instanceof Role; + } + + @Override + public String toString() { + return String.format("%s{ " + + "roleId = %d, " + + "name = \"%s\", " + + "sourceGroup = %s, " + + "implicitGroup = %s, " + + " }", + super.toString(), + roleId, + name, + sourceGroup.toString(), + implicitGroup.toString()); + } + +}