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
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
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)
|| to_char(debitorNumberSuffix, 'fm00') as idName
FROM hs_office_debitor AS debitor

View File

@ -59,14 +59,19 @@ public class HsOfficePersonEntity implements HasUuid, Stringifyable {
@ManyToOne(cascade = CascadeType.ALL)
@JoinFormula(
referencedColumnName = "uuid",
// FIXME: use _rv in sub-query
value = """
(SELECT partner.uuid AS uuid
(
SELECT DISTINCT partner.uuid AS uuid
FROM hs_office_partner partner
JOIN hs_office_relationship partnerRel
ON partnerRel.uuid = partner.partnerRoleUuid AND partnerRel.relType = 'PARTNER'
WHERE partnerRel.relHolderUuid = h1_0.uuid)
""") // FIXME: h1_0 is the generated self-reference, I should find a better solution
private HsOfficePartnerEntity optionalPartner; @Override
WHERE partnerRel.relHolderUuid = personUuid
) -- uuid would be ambiguous with outer uuid
""")
private HsOfficePartnerEntity optionalPartner;
@Override
public String toString() {
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
(
uuid uuid unique references RbacObject (uuid) initially deferred,
personUuid uuid GENERATED ALWAYS AS (uuid) stored, -- see usage in HsOfficePersonEntity
personType HsOfficePersonType not null,
tradeName varchar(96),
givenName varchar(48),

View File

@ -1,6 +1,6 @@
### 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
%%{init:{'flowchart':{'htmlLabels':false}}}%%

View File

@ -1,5 +1,5 @@
--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 $$
begin
call grantPermissionToRole(
globalAdmin(),
createPermission(NEW.uuid, 'INSERT', 'hs_office_debitor'));
createPermission(NEW.uuid, 'INSERT', 'hs_office_debitor'),
globalAdmin());
return NEW;
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
after insert on global
for each row
@ -259,10 +260,10 @@ create trigger hs_office_debitor_insert_permission_check_tg
JOIN hs_office_relationship partnerRel
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
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)
|| to_char(debitorNumberSuffix, 'fm00') as idName
FROM hs_office_debitor AS debitor
FROM hs_office_debitor AS debitor
$idName$);
--//

View File

@ -236,9 +236,9 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// then
allTheseDebitorsAreReturned(
result,
"debitor(D-1000111: P-10001, fir)",
"debitor(D-1000212: P-10002, sec)",
"debitor(D-1000313: P-10003, thi)");
"debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)",
"debitor(D-1000212: rel(relAnchor='LP Second e.K.', relType='ACCOUNTING', relHolder='LP Second e.K.'), sec)",
"debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
}
@ParameterizedTest
@ -302,7 +302,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = debitorRepo.findDebitorByOptionalNameLike("third contact");
// 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
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();
debitorRepo.deleteByUuid(givenDebitor.getUuid());