import-cancelled-memberships-if-booking-exist (#36)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/36 Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
@ -19,13 +19,7 @@ import org.hibernate.annotations.JoinFormula;
|
||||
import org.hibernate.annotations.NotFound;
|
||||
import org.hibernate.annotations.NotFoundAction;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Version;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import java.io.IOException;
|
||||
|
@ -2,7 +2,11 @@ package net.hostsharing.hsadminng.hs.office.membership;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.range.PostgreSQLRangeType;
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
||||
@ -13,17 +17,32 @@ import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
import net.hostsharing.hsadminng.stringify.Stringifyable;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.PrePersist;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Version;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.*;
|
||||
import static io.hypersistence.utils.hibernate.type.range.Range.emptyRange;
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.lowerInclusiveFromPostgresDateRange;
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.upperInclusiveFromPostgresDateRange;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Nullable.NOT_NULL;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.*;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.DELETE;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.INSERT;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.SELECT;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.UPDATE;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.ADMIN;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.AGENT;
|
||||
@ -50,7 +69,7 @@ public class HsOfficeMembershipEntity implements RbacObject, Stringifyable {
|
||||
.withProp(e -> MEMBER_NUMBER_TAG + e.getMemberNumber())
|
||||
.withProp(e -> e.getPartner().toShortString())
|
||||
.withProp(e -> e.getValidity().asString())
|
||||
.withProp(HsOfficeMembershipEntity::getReasonForTermination)
|
||||
.withProp(HsOfficeMembershipEntity::getStatus)
|
||||
.quotedValues(false);
|
||||
|
||||
@Id
|
||||
@ -75,9 +94,9 @@ public class HsOfficeMembershipEntity implements RbacObject, Stringifyable {
|
||||
@Column(name = "membershipfeebillable", nullable = false)
|
||||
private Boolean membershipFeeBillable; // not primitive to force setting the value
|
||||
|
||||
@Column(name = "reasonfortermination")
|
||||
@Column(name = "status")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private HsOfficeReasonForTermination reasonForTermination;
|
||||
private HsOfficeMembershipStatus status;
|
||||
|
||||
public void setValidFrom(final LocalDate validFrom) {
|
||||
setValidity(toPostgresDateRange(validFrom, getValidTo()));
|
||||
@ -97,7 +116,7 @@ public class HsOfficeMembershipEntity implements RbacObject, Stringifyable {
|
||||
|
||||
public Range<LocalDate> getValidity() {
|
||||
if (validity == null) {
|
||||
validity = Range.infinite(LocalDate.class);
|
||||
validity = emptyRange(LocalDate.class);
|
||||
}
|
||||
return validity;
|
||||
}
|
||||
@ -121,8 +140,8 @@ public class HsOfficeMembershipEntity implements RbacObject, Stringifyable {
|
||||
|
||||
@PrePersist
|
||||
void init() {
|
||||
if (getReasonForTermination() == null) {
|
||||
setReasonForTermination(HsOfficeReasonForTermination.NONE);
|
||||
if (getStatus() == null) {
|
||||
setStatus(HsOfficeMembershipStatus.INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +154,7 @@ public class HsOfficeMembershipEntity implements RbacObject, Stringifyable {
|
||||
JOIN hs_office_partner AS p ON p.uuid = m.partnerUuid
|
||||
"""))
|
||||
.withRestrictedViewOrderBy(SQL.projection("validity"))
|
||||
.withUpdatableColumns("validity", "membershipFeeBillable", "reasonForTermination")
|
||||
.withUpdatableColumns("validity", "membershipFeeBillable", "status")
|
||||
|
||||
.importEntityAlias("partnerRel", HsOfficeRelationEntity.class,
|
||||
dependsOnColumn("partnerUuid"),
|
||||
|
@ -23,9 +23,9 @@ public class HsOfficeMembershipEntityPatcher implements EntityPatcher<HsOfficeMe
|
||||
public void apply(final HsOfficeMembershipPatchResource resource) {
|
||||
OptionalFromJson.of(resource.getValidTo()).ifPresent(
|
||||
entity::setValidTo);
|
||||
Optional.ofNullable(resource.getReasonForTermination())
|
||||
.map(v -> mapper.map(v, HsOfficeReasonForTermination.class))
|
||||
.ifPresent(entity::setReasonForTermination);
|
||||
Optional.ofNullable(resource.getStatus())
|
||||
.map(v -> mapper.map(v, HsOfficeMembershipStatus.class))
|
||||
.ifPresent(entity::setStatus);
|
||||
OptionalFromJson.of(resource.getMembershipFeeBillable()).ifPresent(
|
||||
entity::setMembershipFeeBillable);
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package net.hostsharing.hsadminng.hs.office.membership;
|
||||
|
||||
public enum HsOfficeMembershipStatus {
|
||||
INVALID, ACTIVE, CANCELLED, TRANSFERRED, DECEASED, LIQUIDATED, EXPULSED, UNKNOWN;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package net.hostsharing.hsadminng.hs.office.membership;
|
||||
|
||||
public enum HsOfficeReasonForTermination {
|
||||
NONE, CANCELLATION, TRANSFER, DEATH, LIQUIDATION, EXPULSION, UNKNOWN;
|
||||
}
|
@ -3,15 +3,17 @@ components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsOfficeReasonForTermination:
|
||||
HsOfficeMembershipStatus:
|
||||
type: string
|
||||
enum:
|
||||
- NONE
|
||||
- CANCELLATION
|
||||
- TRANSFER
|
||||
- DEATH
|
||||
- LIQUIDATION
|
||||
- EXPULSION
|
||||
- INVALID
|
||||
- ACTIVE
|
||||
- CANCELLED
|
||||
- TRANSFERRED
|
||||
- DECEASED
|
||||
- LIQUIDATED
|
||||
- EXPULSED
|
||||
- UNKNOWN
|
||||
|
||||
HsOfficeMembership:
|
||||
type: object
|
||||
@ -38,8 +40,8 @@ components:
|
||||
validTo:
|
||||
type: string
|
||||
format: date
|
||||
reasonForTermination:
|
||||
$ref: '#/components/schemas/HsOfficeReasonForTermination'
|
||||
status:
|
||||
$ref: '#/components/schemas/HsOfficeMembershipStatus'
|
||||
membershipFeeBillable:
|
||||
type: boolean
|
||||
|
||||
@ -50,9 +52,8 @@ components:
|
||||
type: string
|
||||
format: date
|
||||
nullable: true
|
||||
reasonForTermination:
|
||||
nullable: true
|
||||
$ref: '#/components/schemas/HsOfficeReasonForTermination'
|
||||
status:
|
||||
$ref: '#/components/schemas/HsOfficeMembershipStatus'
|
||||
membershipFeeBillable:
|
||||
nullable: true
|
||||
type: boolean
|
||||
@ -79,8 +80,8 @@ components:
|
||||
type: string
|
||||
format: date
|
||||
nullable: true
|
||||
reasonForTermination:
|
||||
$ref: '#/components/schemas/HsOfficeReasonForTermination'
|
||||
status:
|
||||
$ref: '#/components/schemas/HsOfficeMembershipStatus'
|
||||
membershipFeeBillable:
|
||||
nullable: false
|
||||
type: boolean
|
||||
|
@ -1,4 +1,4 @@
|
||||
openapi: 3.0.1
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: Hostsharing hsadmin-ng API
|
||||
version: v0
|
||||
|
@ -4,9 +4,18 @@
|
||||
--changeset hs-office-membership-MAIN-TABLE:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficeReasonForTermination AS ENUM ('NONE', 'CANCELLATION', 'TRANSFER', 'DEATH', 'LIQUIDATION', 'EXPULSION', 'UNKNOWN');
|
||||
CREATE TYPE HsOfficeMembershipStatus AS ENUM (
|
||||
'INVALID',
|
||||
'ACTIVE',
|
||||
'CANCELLED',
|
||||
'TRANSFERRED',
|
||||
'DECEASED',
|
||||
'LIQUIDATED',
|
||||
'EXPULSED',
|
||||
'UNKNOWN'
|
||||
);
|
||||
|
||||
CREATE CAST (character varying as HsOfficeReasonForTermination) WITH INOUT AS IMPLICIT;
|
||||
CREATE CAST (character varying as HsOfficeMembershipStatus) WITH INOUT AS IMPLICIT;
|
||||
|
||||
create table if not exists hs_office_membership
|
||||
(
|
||||
@ -15,7 +24,7 @@ create table if not exists hs_office_membership
|
||||
partnerUuid uuid not null references hs_office_partner(uuid),
|
||||
memberNumberSuffix char(2) not null check (memberNumberSuffix::text ~ '^[0-9][0-9]$'),
|
||||
validity daterange not null,
|
||||
reasonForTermination HsOfficeReasonForTermination not null default 'NONE',
|
||||
status HsOfficeMembershipStatus not null default 'ACTIVE',
|
||||
membershipFeeBillable boolean not null default true,
|
||||
|
||||
UNIQUE(partnerUuid, memberNumberSuffix)
|
||||
|
@ -172,7 +172,7 @@ call generateRbacRestrictedView('hs_office_membership',
|
||||
$updates$
|
||||
validity = new.validity,
|
||||
membershipFeeBillable = new.membershipFeeBillable,
|
||||
reasonForTermination = new.reasonForTermination
|
||||
status = new.status
|
||||
$updates$);
|
||||
--//
|
||||
|
||||
|
@ -28,8 +28,8 @@ begin
|
||||
raise notice 'creating test Membership: M-% %', forPartnerNumber, newMemberNumberSuffix;
|
||||
raise notice '- using partner (%): %', relatedPartner.uuid, relatedPartner;
|
||||
insert
|
||||
into hs_office_membership (uuid, partneruuid, memberNumberSuffix, validity, reasonfortermination)
|
||||
values (uuid_generate_v4(), relatedPartner.uuid, newMemberNumberSuffix, daterange('20221001' , null, '[]'), 'NONE');
|
||||
into hs_office_membership (uuid, partneruuid, memberNumberSuffix, validity, status)
|
||||
values (uuid_generate_v4(), relatedPartner.uuid, newMemberNumberSuffix, daterange('20221001' , null, '[]'), 'ACTIVE');
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
|
Reference in New Issue
Block a user