Skip to content

Commit

Permalink
🐛 (208): Fix insertion issues with test-data
Browse files Browse the repository at this point in the history
- increment by 1 instead of 50
- every endpoint is authenticated
  • Loading branch information
Manuel Klaus committed Dec 23, 2024
1 parent 5340ddd commit c509160
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 63 deletions.
96 changes: 43 additions & 53 deletions backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,65 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Index;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.persistence.*;

import java.util.Objects;
import java.util.Set;

@Entity
@Table(indexes = @Index(columnList = "parent_id"))
@NamedQueries({
@NamedQuery(name = "Bommel.GetParentsRecursive", query = """
with parents as (
select n.parent.id as bommel
from Bommel n
where n.id = :startId
union
select n.parent.id as bommel
from Bommel n
join parents c on n.id = c.bommel
) cycle bommel set cycleMark using cyclePath
select n as bommel, cycleMark as cycleMark, cyclePath as cyclePath
from Bommel n
join parents c on n.id = c.bommel
"""),
@NamedQuery(name = "Bommel.GetChildrenRecursive", query = """
with children_query as (
select n.id as bommel
from Bommel n
where n.id = :startId
union
select n.id as bommel
from Bommel n
join children_query c on n.parent.id = c.bommel
) cycle bommel set cycleMark using cyclePath
select n as bommel, cycleMark as cycleMark, cyclePath as cyclePath
from Bommel n
join children_query c on n.id = c.bommel
where n.id != :startId or cycleMark = true
""")
})
@NamedQuery(name = "Bommel.GetParentsRecursive", query = """
with parents as (
select n.parent.id as bommel
from Bommel n
where n.id = :startId
union
select n.parent.id as bommel
from Bommel n
join parents c on n.id = c.bommel
) cycle bommel set cycleMark using cyclePath
select n as bommel, cycleMark as cycleMark, cyclePath as cyclePath
from Bommel n
join parents c on n.id = c.bommel
""")
@NamedQuery(name = "Bommel.GetChildrenRecursive", query = """
with children_query as (
select n.id as bommel
from Bommel n
where n.id = :startId
union
select n.id as bommel
from Bommel n
join children_query c on n.parent.id = c.bommel
) cycle bommel set cycleMark using cyclePath
select n as bommel, cycleMark as cycleMark, cyclePath as cyclePath
from Bommel n
join children_query c on n.id = c.bommel
where n.id != :startId or cycleMark = true
""")
@SequenceGenerator(name = "Bommel_SEQ", allocationSize = 1)
public class Bommel extends PanacheEntity {
public static final String DEFAULT_ROOT_BOMMEL_EMOJI = "\uD83C\uDF33"; // tree

private String name;
private String emoji;

@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.REFRESH })
@ManyToOne(cascade = {CascadeType.DETACH, CascadeType.REFRESH})
private Member responsibleMember;

@OneToOne(mappedBy = "rootBommel", cascade = { CascadeType.DETACH, CascadeType.REFRESH, CascadeType.PERSIST,
CascadeType.MERGE })
@OneToOne(mappedBy = "rootBommel", cascade = {CascadeType.DETACH, CascadeType.REFRESH, CascadeType.PERSIST,
CascadeType.MERGE})
private Organization organization;

@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH, CascadeType.DETACH })
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH, CascadeType.DETACH})
private Bommel parent;

@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.DETACH,
CascadeType.REMOVE }, mappedBy = "parent")
@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.DETACH,
CascadeType.REMOVE}, mappedBy = "parent")
private Set<Bommel> children;

/**
Expand Down Expand Up @@ -164,9 +154,9 @@ public boolean equals(Object o) {
&& Objects.equals(getName(), bommel.getName())
&& Objects.equals(getResponsibleMember(), bommel.getResponsibleMember())
&& Objects.equals(getParent() != null ? getParent().id : null,
bommel.getParent() != null ? bommel.getParent().id : null)
bommel.getParent() != null ? bommel.getParent().id : null)
&& Objects.equals(getOrganization() != null ? getOrganization().getId() : null,
bommel.getOrganization() != null ? bommel.getOrganization().getId() : null)
bommel.getOrganization() != null ? bommel.getOrganization().getId() : null)
&& Objects.equals(getChildren(), bommel.getChildren());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Collection;

@Entity
@SequenceGenerator(name = "Member_SEQ", allocationSize = 1)
public class Member extends PanacheEntity {

// TODO: Add OneToMany to Bommel here and test it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package app.hopps.org.jpa;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
Expand All @@ -15,6 +11,7 @@
import java.util.Set;

@Entity
@SequenceGenerator(name = "Organization_SEQ", allocationSize = 1)
public class Organization extends PanacheEntity {

@NotBlank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import app.hopps.org.jpa.Member;
import app.hopps.org.rest.RestValidator.ValidationResult;
import io.quarkus.security.Authenticated;
import jakarta.inject.Inject;
import jakarta.validation.Validator;
import jakarta.ws.rs.*;
Expand All @@ -15,6 +16,7 @@
import org.slf4j.LoggerFactory;

@Path("/member")
@Authenticated
public class MemberResource {

private static final Logger LOG = LoggerFactory.getLogger(MemberResource.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import app.hopps.org.jpa.OrganizationRepository;
import app.hopps.org.rest.RestValidator.ValidationResult;
import app.hopps.org.rest.model.NewOrganizationInput;
import io.quarkus.security.Authenticated;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.validation.Validator;
Expand All @@ -24,6 +25,7 @@
import java.util.Map;

@Path("/organization")
@Authenticated
public class OrganizationResource {

private static final Logger LOG = LoggerFactory.getLogger(OrganizationResource.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ quarkus.banner.path=banner.txt
%prod.quarkus.management.enabled=true
quarkus.smallrye-openapi.store-schema-directory=target/openapi
#
quarkus.http.auth.permission.rest.paths=*
quarkus.http.auth.permission.rest.policy=authenticated
quarkus.http.auth.permission.management.paths=/q*
quarkus.http.auth.permission.management.policy=permit
#
########################################
# Database
########################################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alter sequence Bommel_SEQ INCREMENT BY 1;
alter sequence Member_SEQ INCREMENT BY 1;
alter sequence Organization_SEQ INCREMENT BY 1;

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
insert into Organization (type, id, slug, name, website, plz, city, street, number)
values
(0, 2, 'gruenes-herz-ev', 'Grünes Herz e.V.', 'https://gruenes-herz.de/', '27324', 'Schweringen', 'Am Lennestein', '110'),
(0, 3, 'kaeltekrieger', 'Eishockeyclub Kältekrieger e.V.', 'https://kaeltekrieger.de/', '89129', 'Langenau', 'August-Brust-Straße', '78'),
(0, 4, 'buehnefrei-ev', 'Theatervereine Bühnefrei e.V.', 'https://bühnefrei.de/', '33397', 'Rietberg', 'Dechant-Karthaus-Straße', '172');
values (0, 2, 'gruenes-herz-ev', 'Grünes Herz e.V.', 'https://gruenes-herz.de/', '27324', 'Schweringen',
'Am Lennestein', '110'),
(0, 3, 'kaeltekrieger', 'Eishockeyclub Kältekrieger e.V.', 'https://kaeltekrieger.de/', '89129', 'Langenau',
'August-Brust-Straße', '78'),
(0, 4, 'buehnefrei-ev', 'Theatervereine Bühnefrei e.V.', 'https://bühnefrei.de/', '33397', 'Rietberg',
'Dechant-Karthaus-Straße', '172');

insert into member
(id, email, firstName, lastName)
(id, email, firstName, lastName)
values
-- gruenes-herz-ev
(2, '[email protected]', 'Emanuel', 'Urban'),
Expand Down Expand Up @@ -102,3 +104,7 @@ where id = 3;
update Organization
set rootBommel_id = 23
where id = 4;

select setval('Bommel_SEQ', 30, true);
select setval('Organization_SEQ', 4, true);
select setval('Member_SEQ', 20, true);

0 comments on commit c509160

Please sign in to comment.