Skip to content

Commit

Permalink
Support for Tag backend. (#396)
Browse files Browse the repository at this point in the history
* Implemented CRUD operation for tags.

* Implemented tag association to the resource.

* Added test for tag management.

* Added log messages.

* Added DB creation scripts for tag tables.

* Added javadoc to tag REST service.

* Refactoring.

* Added count in get all tags operation result.

* Added filtering by tag for the extJS get all operation.

* Exposed get all tags operation to anonymous users.

* Refactored nameLike path variable handling.

* Introduced AssociatedEntityFilter abstraction.

* Set distinct in resource count query.

* Added null check to nameLike path variable handling.

* Refactored nameLike query variable handling.

* Added DB migration scripts.

* Handled on delete cascade actions on tags.

* Fixed hash calculation for StoredData to avoid stack overflow.

* Fixed bug that was removing tag association after updates.

* Signalled failing assertion in rest client test.

* Fixed tag list serialization when null.

* Handled names in filters that contain commas.
  • Loading branch information
axl8713 authored Feb 6, 2025
1 parent 87ac2a9 commit 703c5e4
Show file tree
Hide file tree
Showing 47 changed files with 2,075 additions and 267 deletions.
25 changes: 25 additions & 0 deletions doc/sql/002_create_schema_oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@
foreign key (group_id)
references gs_usergroup;

create table gs_tag (
id number(19,0) not null,
color varchar2(255 char) not null,
description varchar2(255 char),
"name" varchar2(255 char) not null,
primary key (id)
);

create table gs_resource_tags (
tag_id number(19,0) not null,
resource_id number(19,0) not null,
primary key (tag_id, resource_id)
);

alter table gs_resource_tags
add constraint fk_resource_tags_resource
foreign key (resource_id)
references gs_resource(id)
on delete cascade;

alter table gs_resource_tags
add constraint fk_resource_tags_tag
foreign key (tag_id)
references gs_tag(id);

create index idx_attribute_name on gs_attribute (name);

create index idx_attribute_resource on gs_attribute (resource_id);
Expand Down
25 changes: 25 additions & 0 deletions doc/sql/002_create_schema_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ SET search_path TO geostore;
foreign key (group_id)
references gs_usergroup;

create table gs_tag (
id int8 not null,
color varchar(255) not null,
description varchar(255) null,
"name" varchar(255) not null,
constraint gs_tag_pkey primary key (id)
);

create table gs_resource_tags (
tag_id int8 not null,
resource_id int8 not null,
constraint gs_resource_tags_pkey primary key (tag_id, resource_id)
);

alter table gs_resource_tags
add constraint fk_resource_tags_resource
foreign key (resource_id)
references gs_resource(id)
on delete cascade;

alter table gs_resource_tags
add constraint fk_resource_tags_tag
foreign key (tag_id)
references gs_tag(id);

create index idx_attribute_name on gs_attribute (name);

create index idx_attribute_resource on gs_attribute (resource_id);
Expand Down
25 changes: 25 additions & 0 deletions doc/sql/migration/h2/h2-migration-from-v.2.1.0-to-v2.3.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE gs_tag (
id BIGINT NOT NULL,
color VARCHAR(255) NOT NULL,
description VARCHAR(255),
name VARCHAR(255) NOT NULL,
CONSTRAINT gs_tag_pkey PRIMARY KEY (id)
);

CREATE TABLE gs_resource_tags (
tag_id BIGINT NOT NULL,
resource_id BIGINT NOT NULL,
CONSTRAINT gs_resource_tags_pkey PRIMARY KEY (tag_id, resource_id)
);

-- Add foreign key constraints to gs_resource_tags
ALTER TABLE gs_resource_tags
ADD CONSTRAINT fk_resource_tags_resource
FOREIGN KEY (resource_id)
REFERENCES gs_resource(id)
ON DELETE CASCADE;

ALTER TABLE gs_resource_tags
ADD CONSTRAINT fk_resource_tags_tag
FOREIGN KEY (tag_id)
REFERENCES gs_tag(id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
create table gs_tag (
id number(19,0) not null,
color varchar2(255 char) not null,
description varchar2(255 char),
"name" varchar2(255 char) not null,
primary key (id)
);

create table gs_resource_tags (
tag_id number(19,0) not null,
resource_id number(19,0) not null,
primary key (tag_id, resource_id)
);

-- Add foreign key constraints to gs_resource_tags
alter table gs_resource_tags
add constraint fk_resource_tags_resource
foreign key (resource_id)
references gs_resource(id)
on delete cascade;

alter table gs_resource_tags
add constraint fk_resource_tags_tag
foreign key (tag_id)
references gs_tag(id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
create table gs_tag (
id int8 not null,
color varchar(255) not null,
description varchar(255) null,
"name" varchar(255) not null,
constraint gs_tag_pkey primary key (id)
);

create table gs_resource_tags (
tag_id int8 not null,
resource_id int8 not null,
constraint gs_resource_tags_pkey primary key (tag_id, resource_id)
);

-- Add foreign key constraints to gs_resource_tags
alter table gs_resource_tags
add constraint fk_resource_tags_resource
foreign key (resource_id)
references gs_resource(id)
on delete cascade;

alter table gs_resource_tags
add constraint fk_resource_tags_tag
foreign key (tag_id)
references gs_tag(id);
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
Expand All @@ -49,6 +51,8 @@
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

/**
* Class Resource.
Expand Down Expand Up @@ -119,6 +123,10 @@ public class Resource implements Serializable, CycleRecoverable {
@OneToMany(mappedBy = "resource", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<SecurityRule> security;

@ManyToMany(mappedBy = "resources", fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
private Set<Tag> tags;

/** @return the id */
public Long getId() {
return id;
Expand Down Expand Up @@ -169,6 +177,26 @@ public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}

/** @return the creator username */
public String getCreator() {
return creator;
}

/** @param creator the creator username */
public void setCreator(String creator) {
this.creator = creator;
}

/** @return the editor username */
public String getEditor() {
return editor;
}

/** @param editor the creator username */
public void setEditor(String editor) {
this.editor = editor;
}

/** @return the advertised */
public Boolean isAdvertised() {
return advertised;
Expand Down Expand Up @@ -232,24 +260,12 @@ public void setSecurity(List<SecurityRule> security) {
this.security = security;
}

/** @return the creator username */
public String getCreator() {
return creator;
}

/** @param creator the creator username */
public void setCreator(String creator) {
this.creator = creator;
}

/** @return the editor username */
public String getEditor() {
return editor;
public Set<Tag> getTags() {
return tags;
}

/** @param editor the creator username */
public void setEditor(String editor) {
this.editor = editor;
public void setTags(Set<Tag> tags) {
this.tags = tags;
}

/*
Expand Down Expand Up @@ -314,6 +330,11 @@ public String toString() {
builder.append("advertised=").append(advertised);
}

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

builder.append(']');

return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public int hashCode() {
int result = 1;
result = (prime * result) + ((data == null) ? 0 : data.hashCode());
result = (prime * result) + ((id == null) ? 0 : id.hashCode());
result = (prime * result) + ((resource == null) ? 0 : resource.hashCode());
result = (int) ((prime * result) + ((resource == null) ? 0 : resource.getId()));

return result;
}
Expand Down
Loading

0 comments on commit 703c5e4

Please sign in to comment.