This commit is contained in:
Michael Hoennig 2024-02-05 11:34:46 +01:00
parent 73ea6b8ccc
commit c987cba53c
10 changed files with 27 additions and 26 deletions

View File

@ -27,8 +27,8 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
public class HsOfficeBankAccountEntity implements HasUuid, Stringifyable { public class HsOfficeBankAccountEntity implements HasUuid, Stringifyable {
private static Stringify<HsOfficeBankAccountEntity> toString = stringify(HsOfficeBankAccountEntity.class, "bankAccount") private static Stringify<HsOfficeBankAccountEntity> toString = stringify(HsOfficeBankAccountEntity.class, "bankAccount")
.withIdProp(HsOfficeBankAccountEntity::getIban)
.withProp(Fields.holder, HsOfficeBankAccountEntity::getHolder) .withProp(Fields.holder, HsOfficeBankAccountEntity::getHolder)
.withProp(Fields.iban, HsOfficeBankAccountEntity::getIban)
.withProp(Fields.bic, HsOfficeBankAccountEntity::getBic); .withProp(Fields.bic, HsOfficeBankAccountEntity::getBic);
@Id @Id

View File

@ -30,13 +30,15 @@ public class HsOfficePartnerEntity implements Stringifyable, HasUuid {
public static final String PARTNER_NUMBER_TAG = "P-"; public static final String PARTNER_NUMBER_TAG = "P-";
private static Stringify<HsOfficePartnerEntity> stringify = stringify(HsOfficePartnerEntity.class, "partner") private static Stringify<HsOfficePartnerEntity> stringify = stringify(HsOfficePartnerEntity.class, "partner")
.withIdProp(HsOfficePartnerEntity::getPartnerNumber) .withIdProp(HsOfficePartnerEntity::toShortString)
.withProp(p -> ofNullable(p.getPartnerRole()) .withProp(p -> ofNullable(p.getPartnerRole())
.map(HsOfficeRelationshipEntity::getRelHolder) .map(HsOfficeRelationshipEntity::getRelHolder)
.map(HsOfficePersonEntity::toShortString)) .map(HsOfficePersonEntity::toShortString)
.orElse(null))
.withProp(p -> ofNullable(p.getPartnerRole()) .withProp(p -> ofNullable(p.getPartnerRole())
.map(HsOfficeRelationshipEntity::getContact) .map(HsOfficeRelationshipEntity::getContact)
.map(HsOfficeContactEntity::toShortString)) .map(HsOfficeContactEntity::toShortString)
.orElse(null))
.withSeparator(", ") .withSeparator(", ")
.quotedValues(false); .quotedValues(false);

View File

@ -70,8 +70,8 @@ public final class Stringify<B> {
}) })
.map(propVal -> propName(propVal, "=") + optionallyQuoted(propVal)) .map(propVal -> propName(propVal, "=") + optionallyQuoted(propVal))
.collect(Collectors.joining(separator)); .collect(Collectors.joining(separator));
return idProp == null return idProp != null
? name + "(" + idProp + ": " + propValues + ")" ? name + "(" + idProp.apply(object) + ": " + propValues + ")"
: name + "(" + propValues + ")"; : name + "(" + propValues + ")";
} }

View File

@ -67,7 +67,7 @@ do language plpgsql $$
call createHsOfficePersonTestData('NP', null, 'Fouler', 'Ellie'); call createHsOfficePersonTestData('NP', null, 'Fouler', 'Ellie');
call createHsOfficePersonTestData('LP', 'Second e.K.', 'Smith', 'Peter'); call createHsOfficePersonTestData('LP', 'Second e.K.', 'Smith', 'Peter');
call createHsOfficePersonTestData('IF', 'Third OHG'); call createHsOfficePersonTestData('IF', 'Third OHG');
call createHsOfficePersonTestData('IF', 'Fourth eG'); call createHsOfficePersonTestData('LP', 'Fourth eG');
call createHsOfficePersonTestData('UF', 'Erben Bessler', 'Mel', 'Bessler'); call createHsOfficePersonTestData('UF', 'Erben Bessler', 'Mel', 'Bessler');
call createHsOfficePersonTestData('NP', null, 'Bessler', 'Anita'); call createHsOfficePersonTestData('NP', null, 'Bessler', 'Anita');
call createHsOfficePersonTestData('NP', null, 'Winkler', 'Paul'); call createHsOfficePersonTestData('NP', null, 'Winkler', 'Paul');

View File

@ -42,6 +42,8 @@ begin
if TG_OP = 'INSERT' then if TG_OP = 'INSERT' then
perform createRoleWithGrants( perform createRoleWithGrants(
hsOfficeRelationshipOwner(NEW), hsOfficeRelationshipOwner(NEW),
permissions => array['*'], permissions => array['*'],

View File

@ -30,13 +30,7 @@ declare
oldPartnerRole hs_office_relationship; oldPartnerRole hs_office_relationship;
newPartnerRole hs_office_relationship; newPartnerRole hs_office_relationship;
oldPersonX hs_office_person;
newPersonX hs_office_person;
oldContactX hs_office_contact;
newContactX hs_office_contact;
begin begin
select * from hs_office_relationship as r where r.uuid = NEW.partnerroleuuid into newPartnerRole; select * from hs_office_relationship as r where r.uuid = NEW.partnerroleuuid into newPartnerRole;
if TG_OP = 'INSERT' then if TG_OP = 'INSERT' then
@ -46,7 +40,9 @@ begin
perform createRoleWithGrants( perform createRoleWithGrants(
hsOfficePartnerOwner(NEW), hsOfficePartnerOwner(NEW),
permissions => array['*'], permissions => array['*'],
incomingSuperRoles => array[globalAdmin()] incomingSuperRoles => array[globalAdmin()],
outgoingSubRoles => array[
hsOfficeRelationshipOwner(newPartnerRole)]
); );
perform createRoleWithGrants( perform createRoleWithGrants(
@ -55,14 +51,14 @@ begin
incomingSuperRoles => array[ incomingSuperRoles => array[
hsOfficePartnerOwner(NEW)], hsOfficePartnerOwner(NEW)],
outgoingSubRoles => array[ outgoingSubRoles => array[
hsOfficeRelationshipTenant(newPartnerRole)] hsOfficeRelationshipAdmin(newPartnerRole)]
); );
perform createRoleWithGrants( perform createRoleWithGrants(
hsOfficePartnerAgent(NEW), hsOfficePartnerAgent(NEW),
incomingSuperRoles => array[ incomingSuperRoles => array[
hsOfficePartnerAdmin(NEW), hsOfficePartnerAdmin(NEW),
hsOfficeRelationshipAdmin(newPartnerRole)] hsOfficeRelationshipAgent(newPartnerRole)]
); );
perform createRoleWithGrants( perform createRoleWithGrants(

View File

@ -59,7 +59,7 @@ do language plpgsql $$
$$; $$;
-- TODO.refa: the code below could be moved to a generator, maybe even the code above. -- TODO.refa: the code below could be moved to a generator, maybe even the code above.
-- Additionally, the code below is not neccesary for all entities, specifiy when it is! -- Additionally, the code below is not necessary for all entities, specify when it is!
/** /**
Used by the trigger to prevent the add-partner-details to current user respectively assumed roles. Used by the trigger to prevent the add-partner-details to current user respectively assumed roles.

View File

@ -19,7 +19,7 @@ class HsOfficeBankAccountEntityUnitTest {
.iban("DE02370502990000684712") .iban("DE02370502990000684712")
.bic("COKSDE33") .bic("COKSDE33")
.build(); .build();
assertThat("" + givenBankAccount).isEqualTo("bankAccount(holder='given holder', iban='DE02370502990000684712', bic='COKSDE33')"); assertThat(givenBankAccount.toString()).isEqualTo("bankAccount(DE02370502990000684712: holder='given holder', bic='COKSDE33')");
} }
@Test @Test

View File

@ -519,7 +519,7 @@ public class ImportOfficeData extends ContextBasedTest {
jpaAttempt.transacted(() -> { jpaAttempt.transacted(() -> {
context(rbacSuperuser); context(rbacSuperuser);
coopAssets.forEach(this::persist); coopAssets.forEach(this::persist);
updateLegacyIds(coopShares, "hs_office_coopassetstransaction_legacy_id", "member_asset_id"); updateLegacyIds(coopAssets, "hs_office_coopassetstransaction_legacy_id", "member_asset_id");
}).assertSuccessful(); }).assertSuccessful();
} }

View File

@ -227,9 +227,11 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
// then // then
allThesePartnersAreReturned( allThesePartnersAreReturned(
result, result,
"partner(IF Third OHG: third contact)", "partner(P-10001: LP First GmbH, first contact)",
"partner(LP Second e.K.: second contact)", "partner(P-10002: LP Second e.K., second contact)",
"partner(LP First GmbH: first contact)"); "partner(P-10003: IF Third OHG, third contact)",
"partner(P-10004: LP Fourth eG, fourth contact)",
"partner(P-10010: NP Smith, Peter, sixth contact)");
} }
@Test @Test
@ -241,7 +243,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = partnerRepo.findPartnerByOptionalNameLike(null); final var result = partnerRepo.findPartnerByOptionalNameLike(null);
// then: // then:
exactlyThesePartnersAreReturned(result, "partner(LP First GmbH: first contact)"); exactlyThesePartnersAreReturned(result, "partner(P-10001: LP First GmbH: first contact)");
} }
} }
@ -257,7 +259,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = partnerRepo.findPartnerByOptionalNameLike("third contact"); final var result = partnerRepo.findPartnerByOptionalNameLike("third contact");
// then // then
exactlyThesePartnersAreReturned(result, "partner(IF Third OHG: third contact)"); exactlyThesePartnersAreReturned(result, "partner(P-10003: IF Third OHG, third contact)");
} }
} }
@ -276,7 +278,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
assertThat(result) assertThat(result)
.isNotNull() .isNotNull()
.extracting(Object::toString) .extracting(Object::toString)
.isEqualTo("partner(LP First GmbH: first contact)"); .isEqualTo("partner(P-10001: LP First GmbH, first contact)");
} }
} }
@ -317,7 +319,6 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
} }
@Test @Test
@Disabled // TODO: enable once partner.person and partner.contact are removed
public void partnerAgent_canNotUpdateRelatedPartner() { public void partnerAgent_canNotUpdateRelatedPartner() {
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");