Compare commits
No commits in common. "70621fd482c770540392f38ea9ecc53549f6ad3b" and "90508df42d3bdae77d7bee22a88cc5f78d98326b" have entirely different histories.
70621fd482
...
90508df42d
@ -25,14 +25,11 @@ 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)
|
||||
.withProp(HsOfficeDebitorEntity::getDefaultPrefix)
|
||||
// TODO: add defaultPrefix?
|
||||
.withSeparator(": ")
|
||||
.quotedValues(false);
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
create table if not exists hs_office_contact
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
label varchar(128) not null,
|
||||
label varchar(96) not null,
|
||||
postalAddress text,
|
||||
emailAddresses text, -- TODO.feat: change to json
|
||||
phoneNumbers text -- TODO.feat: change to json
|
||||
|
@ -26,6 +26,9 @@ 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';
|
||||
|
@ -22,12 +22,11 @@ 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: som)");
|
||||
assertThat(result).isEqualTo("debitor(1234567: some trade name)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -215,9 +215,9 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
|
||||
// then
|
||||
allTheseDebitorsAreReturned(
|
||||
result,
|
||||
"debitor(1000111: First GmbH: fir)",
|
||||
"debitor(1000212: Second e.K.: sec)",
|
||||
"debitor(1000313: Third OHG: thi)");
|
||||
"debitor(1000111: First GmbH)",
|
||||
"debitor(1000212: Second e.K.)",
|
||||
"debitor(1000313: Third OHG)");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -234,9 +234,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
|
||||
final var result = debitorRepo.findDebitorByOptionalNameLike(null);
|
||||
|
||||
// then:
|
||||
exactlyTheseDebitorsAreReturned(result,
|
||||
"debitor(1000111: First GmbH: fir)",
|
||||
"debitor(1000120: First GmbH: fif)");
|
||||
exactlyTheseDebitorsAreReturned(result, "debitor(1000111: First GmbH)", "debitor(1000120: First GmbH)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -264,7 +262,8 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
|
||||
final var result = debitorRepo.findDebitorByDebitorNumber(1000313);
|
||||
|
||||
// then
|
||||
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG: thi)");
|
||||
// exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG)", "debitor(1000413: Fourth e.G.)");
|
||||
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +279,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
|
||||
final var result = debitorRepo.findDebitorByOptionalNameLike("third contact");
|
||||
|
||||
// then
|
||||
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG: thi)");
|
||||
exactlyTheseDebitorsAreReturned(result, "debitor(1000313: Third OHG)");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,15 +56,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* which reads CSV files from the file system.
|
||||
*/
|
||||
|
||||
@Disabled
|
||||
@DataJpaTest(properties = "spring.datasource.url=jdbc:postgresql://localhost:5432/postgres")
|
||||
@DataJpaTest
|
||||
@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<>();
|
||||
@ -109,9 +105,9 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
assertThat(contacts.toString()).isEqualTo("{}");
|
||||
assertThat(debitors.toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
7=debitor(1000700: null, null: mih),
|
||||
10=debitor(1001000: null, null: xyz),
|
||||
12=debitor(1101200: null, null: xxx)}
|
||||
7=debitor(1000700: null, null),
|
||||
10=debitor(1001000: null, null),
|
||||
12=debitor(1101200: null, null)}
|
||||
""");
|
||||
assertThat(memberships.toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
@ -137,7 +133,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: Petra Schmidt , Test PS)
|
||||
12=partner(Test PS: Paule Schmidt , Test PS)
|
||||
}
|
||||
""");
|
||||
assertThat(contacts.toString()).isEqualToIgnoringWhitespace("""
|
||||
@ -145,21 +141,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='Petra Schmidt , Test PS', emailAddresses='ps@example.com')
|
||||
121=contact(label='Paule 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='Petra')
|
||||
12=person(personType='UNKNOWN', tradeName='Test PS', familyName='Schmidt', givenName='Paule')
|
||||
}
|
||||
""");
|
||||
assertThat(debitors.toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
7=debitor(1000700: Mellies, Michael: mih),
|
||||
10=debitor(1001000: JM e.K.: xyz),
|
||||
12=debitor(1101200: Test PS: xxx)
|
||||
7=debitor(1000700: Mellies, Michael),
|
||||
10=debitor(1001000: JM e.K.),
|
||||
12=debitor(1101200: Test PS)
|
||||
}
|
||||
""");
|
||||
assertThat(memberships.toString()).isEqualToIgnoringWhitespace("""
|
||||
@ -245,133 +241,36 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
@Test
|
||||
@Order(10)
|
||||
@Commit
|
||||
//@Rollback(false)
|
||||
void persistEntities() {
|
||||
|
||||
deleteTestDataFromHsOfficeTables();
|
||||
resetFromHsOfficeSequences();
|
||||
deleteFromTestTables();
|
||||
deleteFromRbacTables();
|
||||
context("superuser-alex@hostsharing.net"); // TODO: use real user for actual import
|
||||
|
||||
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 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) {
|
||||
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
|
||||
@ -439,9 +338,7 @@ 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"))
|
||||
@ -493,7 +390,6 @@ 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);
|
||||
@ -585,12 +481,7 @@ 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));
|
||||
@ -604,7 +495,6 @@ 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")))
|
||||
@ -620,11 +510,7 @@ 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")))
|
||||
@ -675,6 +561,7 @@ 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));
|
||||
}
|
||||
|
@ -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: fir)");
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(1000111: First GmbH)");
|
||||
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: fir)");
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(1000111: First GmbH)");
|
||||
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)");
|
||||
|
@ -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; ; Petra; Schmidt; ; Test PS;; ; ; ; ; ; ; ; ; ps@example.com; billing,operation
|
||||
121; 12; ; Paule; Schmidt; ; Test PS;; ; ; ; ; ; ; ; ; ps@example.com; billing,operation
|
||||
|
|
Loading…
Reference in New Issue
Block a user