move Parter+Debitor person+contact to related Relationsship #20

Merged
hsh-michaelhoennig merged 101 commits from remove-direct-partner-person-and-contact into master 2024-03-28 12:15:14 +01:00
6 changed files with 43 additions and 36 deletions
Showing only changes of commit 690454d80f - Show all commits

View File

@ -113,7 +113,7 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
JOIN hs_office_relationship partnerRel JOIN hs_office_relationship partnerRel
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER' ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
JOIN hs_office_relationship debitorRel JOIN hs_office_relationship debitorRel
ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND partnerRel.relType = 'ACCOUNTING' ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND debitorRel.relType = 'ACCOUNTING'
WHERE debitorRel.uuid = debitor.debitorRelUuid) WHERE debitorRel.uuid = debitor.debitorRelUuid)
|| to_char(debitorNumberSuffix, 'fm00') as idName || to_char(debitorNumberSuffix, 'fm00') as idName
FROM hs_office_debitor AS debitor FROM hs_office_debitor AS debitor

View File

@ -59,14 +59,19 @@ public class HsOfficePersonEntity implements HasUuid, Stringifyable {
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@JoinFormula( @JoinFormula(
referencedColumnName = "uuid", referencedColumnName = "uuid",
// FIXME: use _rv in sub-query
value = """ value = """
(SELECT partner.uuid AS uuid (
SELECT DISTINCT partner.uuid AS uuid
FROM hs_office_partner partner FROM hs_office_partner partner
JOIN hs_office_relationship partnerRel JOIN hs_office_relationship partnerRel
ON partnerRel.uuid = partner.partnerRoleUuid AND partnerRel.relType = 'PARTNER' ON partnerRel.uuid = partner.partnerRoleUuid AND partnerRel.relType = 'PARTNER'
WHERE partnerRel.relHolderUuid = h1_0.uuid) WHERE partnerRel.relHolderUuid = personUuid
""") // FIXME: h1_0 is the generated self-reference, I should find a better solution ) -- uuid would be ambiguous with outer uuid
private HsOfficePartnerEntity optionalPartner; @Override """)
private HsOfficePartnerEntity optionalPartner;
@Override
public String toString() { public String toString() {
return toString.apply(this); return toString.apply(this);
} }

View File

@ -17,6 +17,7 @@ CREATE CAST (character varying as HsOfficePersonType) WITH INOUT AS IMPLICIT;
create table if not exists hs_office_person create table if not exists hs_office_person
( (
uuid uuid unique references RbacObject (uuid) initially deferred, uuid uuid unique references RbacObject (uuid) initially deferred,
personUuid uuid GENERATED ALWAYS AS (uuid) stored, -- see usage in HsOfficePersonEntity
personType HsOfficePersonType not null, personType HsOfficePersonType not null,
tradeName varchar(96), tradeName varchar(96),
givenName varchar(48), givenName varchar(48),

View File

@ -1,6 +1,6 @@
### rbac debitor ### rbac debitor
This code generated was by RbacViewMermaidFlowchartGenerator at 2024-03-12T16:22:27.339854728. This code generated was by RbacViewMermaidFlowchartGenerator at 2024-03-16T10:26:46.080386825.
```mermaid ```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%% %%{init:{'flowchart':{'htmlLabels':false}}}%%

View File

@ -1,5 +1,5 @@
--liquibase formatted sql --liquibase formatted sql
-- This code generated was by RbacViewPostgresGenerator at 2024-03-12T16:22:27.348469700. -- This code generated was by RbacViewPostgresGenerator at 2024-03-16T10:26:46.091076286.
-- ============================================================================ -- ============================================================================
@ -220,11 +220,12 @@ create or replace function hs_office_debitor_global_insert_tf()
strict as $$ strict as $$
begin begin
call grantPermissionToRole( call grantPermissionToRole(
globalAdmin(), createPermission(NEW.uuid, 'INSERT', 'hs_office_debitor'),
createPermission(NEW.uuid, 'INSERT', 'hs_office_debitor')); globalAdmin());
return NEW; return NEW;
end; $$; end; $$;
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
create trigger z_hs_office_debitor_global_insert_tg create trigger z_hs_office_debitor_global_insert_tg
after insert on global after insert on global
for each row for each row
@ -259,7 +260,7 @@ create trigger hs_office_debitor_insert_permission_check_tg
JOIN hs_office_relationship partnerRel JOIN hs_office_relationship partnerRel
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER' ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
JOIN hs_office_relationship debitorRel JOIN hs_office_relationship debitorRel
ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND partnerRel.relType = 'ACCOUNTING' ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND debitorRel.relType = 'ACCOUNTING'
WHERE debitorRel.uuid = debitor.debitorRelUuid) WHERE debitorRel.uuid = debitor.debitorRelUuid)
|| to_char(debitorNumberSuffix, 'fm00') as idName || to_char(debitorNumberSuffix, 'fm00') as idName
FROM hs_office_debitor AS debitor FROM hs_office_debitor AS debitor

View File

@ -236,9 +236,9 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// then // then
allTheseDebitorsAreReturned( allTheseDebitorsAreReturned(
result, result,
"debitor(D-1000111: P-10001, fir)", "debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)",
"debitor(D-1000212: P-10002, sec)", "debitor(D-1000212: rel(relAnchor='LP Second e.K.', relType='ACCOUNTING', relHolder='LP Second e.K.'), sec)",
"debitor(D-1000313: P-10003, thi)"); "debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
} }
@ParameterizedTest @ParameterizedTest
@ -302,7 +302,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = debitorRepo.findDebitorByOptionalNameLike("third contact"); final var result = debitorRepo.findDebitorByOptionalNameLike("third contact");
// then // then
exactlyTheseDebitorsAreReturned(result, "debitor(D-1000313: P-10003, thi)"); exactlyTheseDebitorsAreReturned(result, "debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
} }
} }
@ -536,7 +536,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_debitor#1000420:FourtheG-fourthcontact.agent"); context("superuser-alex@hostsharing.net", "hs_office_debitor#D-1000420.agent");
assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent(); assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent();
debitorRepo.deleteByUuid(givenDebitor.getUuid()); debitorRepo.deleteByUuid(givenDebitor.getUuid());