Compare commits

..

5 Commits

Author SHA1 Message Date
Michael Hoennig
70621fd482 always use jdbc:postgresql://localhost:5432/postgres for ImportTestData 2024-01-11 16:49:36 +01:00
Michael Hoennig
e9a8699aa1 delete test data before import 2024-01-11 16:49:10 +01:00
Michael Hoennig
1299b4e20a increase length of hs_office_contact.label to 96 2024-01-11 15:37:38 +01:00
Michael Hoennig
76ad26b747 amend test data (Paule -> Petra) which was confusingly similar to basic test data (Paul) + cleanup 2024-01-11 15:37:01 +01:00
Michael Hoennig
5162aa0606 add defaultPrefix to HsOfficeDebitorEntity.toString() 2024-01-11 15:34:23 +01:00
8 changed files with 175 additions and 60 deletions

View File

@ -25,11 +25,14 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@DisplayName("Debitor")
public class HsOfficeDebitorEntity implements Stringifyable {
// TODO: I would rather like to generate something matching this example:
// debitor(1234500: Test AG, tes)
// maybe remove withSepararator (always use ', ') and add withBusinessIdProp (with ': ' afterwards)?
private static Stringify<HsOfficeDebitorEntity> stringify =
stringify(HsOfficeDebitorEntity.class, "debitor")
.withProp(HsOfficeDebitorEntity::getDebitorNumber)
.withProp(HsOfficeDebitorEntity::getPartner)
// TODO: add defaultPrefix?
.withProp(HsOfficeDebitorEntity::getDefaultPrefix)
.withSeparator(": ")
.quotedValues(false);

View File

@ -7,7 +7,7 @@
create table if not exists hs_office_contact
(
uuid uuid unique references RbacObject (uuid) initially deferred,
label varchar(96) not null,
label varchar(128) not null,
postalAddress text,
emailAddresses text, -- TODO.feat: change to json
phoneNumbers text -- TODO.feat: change to json

View File

@ -26,9 +26,6 @@ create or replace function createRbacRolesForHsOfficeContact()
returns trigger
language plpgsql
strict as $$
declare
ownerRole uuid;
adminRole uuid;
begin
if TG_OP <> 'INSERT' then
raise exception 'invalid usage of TRIGGER AFTER INSERT';
@ -107,7 +104,7 @@ do language plpgsql $$
declare
addCustomerPermissions uuid[];
globalObjectUuid uuid;
globalAdminRoleUuid uuid ;
globalAdminRoleUuid uuid;
begin
call defineContext('granting global new-contact permission to global admin role', null, null, null);

View File

@ -22,11 +22,12 @@ class HsOfficeDebitorEntityUnitTest {
.debitorNumberPrefix(12345)
.build())
.billingContact(HsOfficeContactEntity.builder().label("some label").build())
.defaultPrefix("som")
.build();
final var result = given.toString();
assertThat(result).isEqualTo("debitor(1234567: some trade name)");
assertThat(result).isEqualTo("debitor(1234567: some trade name: som)");
}
@Test

View File

@ -215,9 +215,9 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
// then
allTheseDebitorsAreReturned(
result,
"debitor(1000111: First GmbH)",
"debitor(1000212: Second e.K.)",
"debitor(1000313: Third OHG)");
"debitor(1000111: First GmbH: fir)",
"debitor(1000212: Second e.K.: sec)",
"debitor(1000313: Third OHG: thi)");
}
@ParameterizedTest
@ -234,7 +234,9 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var result = debitorRepo.findDebitorByOptionalNameLike(null);
// then:
exactlyTheseDebitorsAreReturned(result, "debitor(1000111: First GmbH)", "debitor(1000120: First GmbH)");
exactlyTheseDebitorsAreReturned(result,
"debitor(1000111: First GmbH: fir)",
"debitor(1000120: First GmbH: fif)");
}
@Test
@ -262,8 +264,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var result = debitorRepo.findDebitorByDebitorNumber(1000313);
// then
// exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG)", "debitor(1000413: Fourth e.G.)");
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG)");
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG: thi)");
}
}
@ -279,7 +280,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var result = debitorRepo.findDebitorByOptionalNameLike("third contact");
// then
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG)");
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG: thi)");
}
}

View File

@ -56,11 +56,15 @@ import static org.assertj.core.api.Assertions.assertThat;
* which reads CSV files from the file system.
*/
@DataJpaTest
@Disabled
@DataJpaTest(properties = "spring.datasource.url=jdbc:postgresql://localhost:5432/postgres")
@Import({ Context.class, JpaAttempt.class })
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class ImportOfficeTables extends ContextBasedTest {
// TODO: use real rbacSuperuser for actual import
private static final String rbacSuperuser = "superuser-alex@hostsharing.net";
private static NavigableMap<Integer, HsOfficeContactEntity> contacts = new TreeMap<>();
private static NavigableMap<Integer, HsOfficePersonEntity> persons = new TreeMap<>();
private static NavigableMap<Integer, HsOfficePartnerEntity> partners = new TreeMap<>();
@ -105,9 +109,9 @@ public class ImportOfficeTables extends ContextBasedTest {
assertThat(contacts.toString()).isEqualTo("{}");
assertThat(debitors.toString()).isEqualToIgnoringWhitespace("""
{
7=debitor(1000700: null, null),
10=debitor(1001000: null, null),
12=debitor(1101200: null, null)}
7=debitor(1000700: null, null: mih),
10=debitor(1001000: null, null: xyz),
12=debitor(1101200: null, null: xxx)}
""");
assertThat(memberships.toString()).isEqualToIgnoringWhitespace("""
{
@ -133,7 +137,7 @@ public class ImportOfficeTables extends ContextBasedTest {
{
7=partner(Mellies, Michael: Herr Michael Mellies ),
10=partner(JM e.K.: Frau Dr. Jenny Meyer , JM e.K.),
12=partner(Test PS: Paule Schmidt , Test PS)
12=partner(Test PS: Petra Schmidt , Test PS)
}
""");
assertThat(contacts.toString()).isEqualToIgnoringWhitespace("""
@ -141,21 +145,21 @@ public class ImportOfficeTables extends ContextBasedTest {
71=contact(label='Herr Michael Mellies ', emailAddresses='mih@example.org'),
101=contact(label='Frau Dr. Jenny Meyer , JM e.K.', emailAddresses='jm@example.org'),
102=contact(label='Herr Andrew Meyer , JM e.K.', emailAddresses='am@example.org'),
121=contact(label='Paule Schmidt , Test PS', emailAddresses='ps@example.com')
121=contact(label='Petra Schmidt , Test PS', emailAddresses='ps@example.com')
}
""");
assertThat(persons.toString()).isEqualToIgnoringWhitespace("""
{
7=person(personType='UNKNOWN', tradeName='', familyName='Mellies', givenName='Michael'),
10=person(personType='UNKNOWN', tradeName='JM e.K.', familyName='Meyer', givenName='Jenny'),
12=person(personType='UNKNOWN', tradeName='Test PS', familyName='Schmidt', givenName='Paule')
12=person(personType='UNKNOWN', tradeName='Test PS', familyName='Schmidt', givenName='Petra')
}
""");
assertThat(debitors.toString()).isEqualToIgnoringWhitespace("""
{
7=debitor(1000700: Mellies, Michael),
10=debitor(1001000: JM e.K.),
12=debitor(1101200: Test PS)
7=debitor(1000700: Mellies, Michael: mih),
10=debitor(1001000: JM e.K.: xyz),
12=debitor(1101200: Test PS: xxx)
}
""");
assertThat(memberships.toString()).isEqualToIgnoringWhitespace("""
@ -241,36 +245,133 @@ public class ImportOfficeTables extends ContextBasedTest {
@Test
@Order(10)
@Commit
//@Rollback(false)
void persistEntities() {
context("superuser-alex@hostsharing.net"); // TODO: use real user for actual import
deleteTestDataFromHsOfficeTables();
resetFromHsOfficeSequences();
deleteFromTestTables();
deleteFromRbacTables();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
contacts.forEach((id, contact) -> em.persist(contact));
updateLegacyIds(contacts, "hs_office_contact_legacy_id", "contact_id");
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
persons.forEach((id, person) -> em.persist(person));
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
partners.forEach((id, partner) -> em.persist(partner));
updateLegacyIds(partners, "hs_office_partner_legacy_id", "bp_id");
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
debitors.forEach((id, debitor) -> em.persist(debitor));
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
memberships.forEach((id, membership) -> em.persist(membership));
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
bankAccounts.forEach((id, account) -> em.persist(account));
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
sepaMandates.forEach((id, mandate) -> em.persist(mandate));
updateLegacyIds(sepaMandates, "hs_office_sepamandate_legacy_id", "sepa_mandate_id");
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
coopShares.forEach((id, shareTransaction) -> em.persist(shareTransaction));
updateLegacyIds(coopShares, "hs_office_coopsharestransaction_legacy_id", "member_share_id");
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
coopAssets.forEach((id, assetTransaction) -> em.persist(assetTransaction));
updateLegacyIds(coopShares, "hs_office_coopassetstransaction_legacy_id", "member_asset_id");
}).assertSuccessful();
em.flush();
}
private <E extends HasUuid> void updateLegacyIds(Map<Integer, E> entities, final String legacyIdTable, final String legacyIdColumn) {
private void deleteTestDataFromHsOfficeTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("DELETE FROM hs_office_relationship WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_coopassetstransaction WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_coopassetstransaction_legacy_id WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_coopsharestransaction WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_coopsharestransaction_legacy_id WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_membership WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_sepamandate WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_sepamandate_legacy_id WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_debitor WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_bankaccount WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_partner WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_partner_details WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_contact WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM hs_office_person WHERE true").executeUpdate();
}).assertSuccessful();
}
private void resetFromHsOfficeSequences() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("ALTER SEQUENCE hs_office_contact_legacy_id_seq RESTART WITH 1000000000;").executeUpdate();
em.createNativeQuery("ALTER SEQUENCE hs_office_coopassetstransaction_legacy_id_seq RESTART WITH 1000000000;").executeUpdate();
em.createNativeQuery("ALTER SEQUENCE public.hs_office_coopsharestransaction_legacy_id_seq RESTART WITH 1000000000;").executeUpdate();
em.createNativeQuery("ALTER SEQUENCE public.hs_office_partner_legacy_id_seq RESTART WITH 1000000000;").executeUpdate();
em.createNativeQuery("ALTER SEQUENCE public.hs_office_sepamandate_legacy_id_seq RESTART WITH 1000000000;").executeUpdate();
});
}
private void deleteFromTestTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("DELETE FROM test_domain WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM test_package WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM test_customer WHERE true").executeUpdate();
}).assertSuccessful();
}
private void deleteFromRbacTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
final var usersNotToDelete = em.createNativeQuery("SELECT name FROM rbacuser WHERE name like 'superuser-%'").getResultList();
final var usersToDelete = em.createNativeQuery("SELECT name FROM rbacuser WHERE name not like 'superuser-%'").getResultList();
System.getenv();
});
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
// em.createNativeQuery("DELETE FROM rbacobject WHERE objecttable like 'hs_%'").executeUpdate();
// em.createNativeQuery("DELETE FROM rbacgrants WHERE true").executeUpdate();
// em.createNativeQuery("DELETE FROM rbacpermission WHERE true").executeUpdate();
// em.createNativeQuery("DELETE FROM rbacreference WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM rbacuser_rv WHERE name not like 'superuser-%'").executeUpdate();
em.createNativeQuery("DELETE FROM tx_journal WHERE true").executeUpdate();
em.createNativeQuery("DELETE FROM tx_context WHERE true").executeUpdate();
}).assertSuccessful();
}
private <E extends HasUuid> void updateLegacyIds(
Map<Integer, E> entities,
final String legacyIdTable,
final String legacyIdColumn) {
entities.forEach((id, entity) -> em.createNativeQuery("""
UPDATE ${legacyIdTable}
SET ${legacyIdColumn} = :legacyId
@ -321,7 +422,7 @@ public class ImportOfficeTables extends ContextBasedTest {
final var debitor = HsOfficeDebitorEntity.builder()
.partner(partner)
.debitorNumberSuffix((byte)0)
.debitorNumberSuffix((byte) 0)
.defaultPrefix(rec.getString("member_code").replace("hsh00-", ""))
.partner(partner)
.billingContact(partner.getContact())
@ -338,7 +439,9 @@ public class ImportOfficeTables extends ContextBasedTest {
final var membership = HsOfficeMembershipEntity.builder()
.partner(partner)
.memberNumber(rec.getInteger("member_id"))
.validity(toPostgresDateRange(rec.getLocalDate("member_since"), rec.getLocalDate("member_until")))
.validity(toPostgresDateRange(
rec.getLocalDate("member_since"),
rec.getLocalDate("member_until")))
.membershipFeeBillable(rec.isEmpty("member_role"))
.reasonForTermination(
isBlank(rec.getString("member_until"))
@ -390,6 +493,7 @@ public class ImportOfficeTables extends ContextBasedTest {
final var member = memberships.get(rec.getInteger("bp_id"));
final var assetTypeMapping = new HashMap<String, HsOfficeCoopAssetsTransactionType>() {
{
put("HANDOVER", HsOfficeCoopAssetsTransactionType.TRANSFER);
put("ADOPTION", HsOfficeCoopAssetsTransactionType.ADOPTION);
@ -402,7 +506,7 @@ public class ImportOfficeTables extends ContextBasedTest {
public HsOfficeCoopAssetsTransactionType get(final String key) {
final var value = super.get(key);
if ( value != null ) {
if (value != null) {
return value;
}
throw new IllegalStateException("no mapping value found for: " + key);
@ -481,7 +585,12 @@ public class ImportOfficeTables extends ContextBasedTest {
private void initContact(final HsOfficeContactEntity contact, final Record rec) {
contacts.put(rec.getInteger("contact_id"), contact);
contact.setLabel(toLabel(rec.getString("salut"), rec.getString("title"), rec.getString("first_name"), rec.getString("last_name"), rec.getString("firma")));
contact.setLabel(toLabel(
rec.getString("salut"),
rec.getString("title"),
rec.getString("first_name"),
rec.getString("last_name"),
rec.getString("firma")));
contact.setEmailAddresses(rec.getString("email"));
contact.setPostalAddress(toAddress(rec));
contact.setPhoneNumbers(toPhoneNumbers(rec));
@ -495,6 +604,7 @@ public class ImportOfficeTables extends ContextBasedTest {
}
return record;
}
private String toPhoneNumbers(final Record rec) {
final var result = new StringBuilder("{\n");
if (isNotBlank(rec.getString("phone_private")))
@ -510,7 +620,11 @@ public class ImportOfficeTables extends ContextBasedTest {
private String toAddress(final Record rec) {
final var result = new StringBuilder();
final var name = toName(rec.getString("salut"), rec.getString("title"), rec.getString("first_name"), rec.getString("last_name"));
final var name = toName(
rec.getString("salut"),
rec.getString("title"),
rec.getString("first_name"),
rec.getString("last_name"));
if (isNotBlank(name))
result.append(name + "\n");
if (isNotBlank(rec.getString("firma")))
@ -561,7 +675,6 @@ public class ImportOfficeTables extends ContextBasedTest {
return toLabel(salut, title, firstname, lastname, null);
}
private Reader resourceReader(@NotNull final String resourcePath) {
return new InputStreamReader(getClass().getClassLoader().getResourceAsStream(resourcePath));
}
@ -593,7 +706,7 @@ class Columns {
int indexOf(final String columnName) {
int index = columnNames.indexOf(columnName);
if ( index < 0 ) {
if (index < 0) {
throw new RuntimeException("column name '" + columnName + "' not found in: " + columnNames);
}
return index;

View File

@ -376,7 +376,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net");
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
.matches(mandate -> {
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(1000111: First GmbH)");
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(1000111: First GmbH: fir)");
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z - patched");
assertThat(mandate.getValidFrom()).isEqualTo("2020-06-05");
@ -417,7 +417,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest {
// finally, the sepaMandate is actually updated
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
.matches(mandate -> {
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(1000111: First GmbH)");
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(1000111: First GmbH: fir)");
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z");
assertThat(mandate.getValidity().asString()).isEqualTo("[2022-11-01,2023-01-01)");

View File

@ -2,4 +2,4 @@ contact_id; bp_id; salut; first_name; last_name; title; firma; co; street; zip
71; 7; Herr; Michael; Mellies; ; ; ; Kleine Freiheit 50; 26524; Hage; DE; ; +49 4931 123456; +49 1522 123456;; mih@example.org; billing,operation
101; 10; Frau; Jenny; Meyer; Dr.; JM e.K.;; Waldweg 5; 11001; Berlin; DE; +49 30 7777777; +49 30 8888888; ; +49 30 9999999; jm@example.org; billing
102; 10; Herr; Andrew; Meyer; ; JM e.K.;; Waldweg 5; 11001; Berlin; DE; +49 30 6666666; +49 30 5555555; ; +49 30 9999999; am@example.org; operation
121; 12; ; Paule; Schmidt; ; Test PS;; ; ; ; ; ; ; ; ; ps@example.com; billing,operation
121; 12; ; Petra; Schmidt; ; Test PS;; ; ; ; ; ; ; ; ; ps@example.com; billing,operation

1 contact_id bp_id salut first_name last_name title firma co street zipcode city country phone_private phone_office phone_mobile fax email roles
2 71 7 Herr Michael Mellies Kleine Freiheit 50 26524 Hage DE +49 4931 123456 +49 1522 123456 mih@example.org billing,operation
3 101 10 Frau Jenny Meyer Dr. JM e.K. Waldweg 5 11001 Berlin DE +49 30 7777777 +49 30 8888888 +49 30 9999999 jm@example.org billing
4 102 10 Herr Andrew Meyer JM e.K. Waldweg 5 11001 Berlin DE +49 30 6666666 +49 30 5555555 +49 30 9999999 am@example.org operation
5 121 12 Paule Petra Schmidt Test PS ps@example.com billing,operation