Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user group attributes #278

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/sql/002_create_schema_oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
unique (name, user_id)
);

create table gs_user_group_attribute (
id number(19,0) not null,
name varchar2(255 char) not null,
string varchar2(255 char),
userGroup_id number(19,0) not null,
primary key (id)
);

create table gs_usergroup (
id number(19,0) not null,
groupName varchar2(255 char) not null,
Expand Down Expand Up @@ -191,6 +199,14 @@
foreign key (user_id)
references gs_user;

create index idx_user_group_attr_name on gs_user_group_attribute (name);

create index idx_user_group_attr_text on gs_user_group_attribute (string);

create index idx_attr_user_group on gs_user_group_attribute (userGroup_id);

alter table gs_user_group_attribute add constraint fk_ugattrib_user_group foreign key (userGroup_id) references gs_usergroup;

create index idx_usergroup_name on gs_usergroup (groupName);

create sequence hibernate_sequence;
16 changes: 16 additions & 0 deletions doc/sql/002_create_schema_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ psql -U geostore_test -d geostore -f 002_create_schema_postgres.sql
primary key (id),
unique (groupName)
);

create table gs_user_group_attribute (
id bigint not null,
name varchar(255) not null,
string varchar(255),
userGroup_id bigint not null,
primary key (id)
);

create table gs_usergroup_members (
user_id int8 not null,
Expand Down Expand Up @@ -129,6 +137,14 @@ psql -U geostore_test -d geostore -f 002_create_schema_postgres.sql
foreign key (resource_id)
references gs_resource;

create index idx_user_group_attr_name on gs_user_group_attribute (name);

create index idx_user_group_attr_text on gs_user_group_attribute (string);

create index idx_attr_user_group on gs_user_group_attribute (userGroup_id);

alter table gs_user_group_attribute add constraint fk_ugattrib_user_group foreign key (userGroup_id) references gs_usergroup;

create index idx_category_type on gs_category (name);

create index idx_resource_name on gs_resource (name);
Expand Down
16 changes: 16 additions & 0 deletions doc/sql/migration/h2/h2-migration-from-v.1.5.0-to-v2.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create table gs_user_group_attribute (
id bigint primary key,
name varchar(255) not null,
string varchar(255),
userGroup_id bigint not null
);



create index idx_user_group_attr_name on gs_user_group_attribute (name);

create index idx_user_group_attr_text on gs_user_group_attribute (string);

create index idx_attr_user_group on gs_user_group_attribute (userGroup_id);

alter table gs_user_group_attribute add constraint fk_ugattrib_user_group foreign key (userGroup_id) references gs_usergroup;
17 changes: 17 additions & 0 deletions doc/sql/migration/oracle/oracle-migration-from-v.1.5.0-to-v2.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
create table gs_user_group_attribute (
id number(19,0) not null,
name varchar2(255 char) not null,
string varchar2(255 char),
userGroup_id number(19,0) not null,
primary key (id)
);



create index idx_user_group_attr_name on gs_user_group_attribute (name);

create index idx_user_group_attr_text on gs_user_group_attribute (string);

create index idx_attr_user_group on gs_user_group_attribute (userGroup_id);

alter table gs_user_group_attribute add constraint fk_ugattrib_user_group foreign key (userGroup_id) references gs_usergroup;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
create table gs_user_group_attribute (
id bigint not null,
name varchar(255) not null,
string varchar(255),
userGroup_id bigint not null,
primary key (id)
);



create index idx_user_group_attr_name on gs_user_group_attribute (name);

create index idx_user_group_attr_text on gs_user_group_attribute (string);

create index idx_attr_user_group on gs_user_group_attribute (userGroup_id);

alter table gs_user_group_attribute add constraint fk_ugattrib_user_group foreign key (userGroup_id) references gs_usergroup;
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;

/**
Expand Down Expand Up @@ -80,14 +79,18 @@ public class UserGroup implements Serializable {
/*
* Only To allow the CASCADING operation
*/
@OneToMany(mappedBy = "group", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@OneToMany(mappedBy = "group",
cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<SecurityRule> security;

@Type(type="yes_no")
@Column(nullable = false,updatable =true)
private boolean enabled=true;

private transient List<User> users = new ArrayList<User>();

@OneToMany(mappedBy = "userGroup", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<UserGroupAttribute> attributes;

@XmlTransient
public List<User> getUsers() {
Expand Down Expand Up @@ -177,6 +180,21 @@ public void setDescription(String description) {
this.description = description;
}

/**
* @return the attribute
*/
@XmlTransient
public List<UserGroupAttribute> getAttributes() {
return attributes;
}

/**
* @param attributes the attribute to set
*/
public void setAttributes(List<UserGroupAttribute> attributes) {
this.attributes = attributes;
}

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -213,6 +231,7 @@ public int hashCode() {
result = (prime * result) + ((groupName == null) ? 0 : groupName.hashCode());
result = (prime * result) + ((id == null) ? 0 : id.hashCode());
result = (prime * result) + ((security == null) ? 0 : security.hashCode());
result = (prime * result) + ((attributes == null) ? 0 : attributes.hashCode());

return result;
}
Expand Down Expand Up @@ -257,6 +276,14 @@ public boolean equals(Object obj) {
return false;
}

if (attributes == null) {
if (other.attributes != null) {
return false;
}
} else if (!attributes.equals(other.attributes)) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package it.geosolutions.geostore.core.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.Serializable;

@Entity(name="UserGroupAttribute")
@Table(name="gs_user_group_attribute", indexes = {
@Index(name = "idx_user_group_attr_name", columnList = "name"),
@Index(name = "idx_user_group_attr_text", columnList = "string"),
@Index(name= "idx_attr_user_group", columnList = "usergroup_id")
})

@XmlRootElement(name = "UserGroupAttribute")
public class UserGroupAttribute implements Serializable {

@Id
@GeneratedValue
private Long id;

@Column(name = "name", nullable = false, updatable = true)
private String name;

@Column(name = "string", nullable = true, updatable = true)
private String value;

@ManyToOne(optional = false)
@JoinColumn(foreignKey=@ForeignKey(name="fk_ugattrib_user_group"))
private UserGroup userGroup;

/**
* @return the id
*/
@XmlTransient
public Long getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

/**
* @return the value
*/
public String getValue() {
return value;
}

/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}

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

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

/*
* (non-Javadoc) @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName()).append('[');

if (id != null) {
builder.append("id=").append(id);
}

if (name != null) {
builder.append(", ");
builder.append("name=").append(name);
}

if (value != null) {
builder.append(", ");
builder.append("value=").append(value);
}

builder.append(']');

return builder.toString();
}

/*
* (non-Javadoc) @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((id == null) ? 0 : id.hashCode());
result = (prime * result) + ((name == null) ? 0 : name.hashCode());
result = (prime * result) + ((userGroup == null) ? 0 : userGroup.hashCode());
result = (prime * result) + ((value == null) ? 0 : value.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 (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}

UserGroupAttribute other = (UserGroupAttribute) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (userGroup == null) {
if (other.userGroup != null) {
return false;
}
} else if (!userGroup.equals(other.userGroup)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}

return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package it.geosolutions.geostore.core.dao;

import it.geosolutions.geostore.core.model.UserGroupAttribute;

public interface UserGroupAttributeDAO extends RestrictedGenericDAO<UserGroupAttribute> {
}
Loading