db-migration #10

Merged
hsh-michaelhoennig merged 74 commits from db-migration into master 2024-01-23 15:11:24 +01:00
Showing only changes of commit 683c2f0ce4 - Show all commits

View File

@ -49,7 +49,6 @@ import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateR
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Fail.fail;
/* /*
* This 'test' includes the complete legacy 'office' data import. * This 'test' includes the complete legacy 'office' data import.
@ -102,8 +101,8 @@ import static org.assertj.core.api.Fail.fail;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class ImportOfficeTables extends ContextBasedTest { public class ImportOfficeTables extends ContextBasedTest {
@Value("${spring.datasource.url}") @Value("${spring.datasource.username}")
private String jdbcUrl; private String postgresAdminUser;
// TODO: use real rbacSuperuser for actual import // TODO: use real rbacSuperuser for actual import
private static final String rbacSuperuser = "superuser-alex@hostsharing.net"; private static final String rbacSuperuser = "superuser-alex@hostsharing.net";
@ -145,16 +144,16 @@ public class ImportOfficeTables extends ContextBasedTest {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if ( !"admin".equals(System.getenv("ADMIN_USER") )) { if ( !"admin".equals(postgresAdminUser) ) {
return; return;
} }
// no contacts yet => mostly null values // no contacts yet => mostly null values
assertThat(partners.toString()).isEqualToIgnoringWhitespace(""" assertThat(partners.toString()).isEqualToIgnoringWhitespace("""
{ {
7=partner(null, null: null), 7=partner(null, null),
10=partner(null, null: null), 10=partner(null, null),
12=partner(null, null: null) 12=partner(null, null)
} }
"""); """);
assertThat(contacts.toString()).isEqualTo("{}"); assertThat(contacts.toString()).isEqualTo("{}");
@ -184,7 +183,7 @@ public class ImportOfficeTables extends ContextBasedTest {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if ( !"admin".equals(System.getenv("HSADMINNG_POSTGRES_ADMIN_USERNAME") )) { if ( !"admin".equals(postgresAdminUser) ) {
return; return;
} }
@ -245,7 +244,7 @@ public class ImportOfficeTables extends ContextBasedTest {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if ( !"admin".equals(System.getenv("HSADMINNG_POSTGRES_ADMIN_USERNAME") )) { if ( !"admin".equals(postgresAdminUser) ) {
return; return;
} }
@ -274,7 +273,7 @@ public class ImportOfficeTables extends ContextBasedTest {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if ( !"admin".equals(System.getenv("HSADMINNG_POSTGRES_ADMIN_USERNAME") )) { if ( !"admin".equals(postgresAdminUser) ) {
return; return;
} }
@ -299,7 +298,7 @@ public class ImportOfficeTables extends ContextBasedTest {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if ( !"admin".equals(System.getenv("ADMIN_USER") )) { if ( !"admin".equals(postgresAdminUser) ) {
return; return;
} }
@ -657,7 +656,6 @@ public class ImportOfficeTables extends ContextBasedTest {
.map(this::trimAll) .map(this::trimAll)
.map(row -> new Record(columns, row)) .map(row -> new Record(columns, row))
.forEach(rec -> { .forEach(rec -> {
if (isNotBlank(rec.getString("roles"))) {
final var contactId = rec.getInteger("contact_id"); final var contactId = rec.getInteger("contact_id");
final var partner = partners.get(rec.getInteger("bp_id")); final var partner = partners.get(rec.getInteger("bp_id"));
@ -672,11 +670,16 @@ public class ImportOfficeTables extends ContextBasedTest {
final var contact = HsOfficeContactEntity.builder().build(); final var contact = HsOfficeContactEntity.builder().build();
contacts.put(contactId, initContact(contact, rec)); contacts.put(contactId, initContact(contact, rec));
var imported = false;
if (rec.getString("roles").contains("contractual")) { if (rec.getString("roles").contains("contractual")) {
assertThat(partner.getContact()).isNull();
partner.setContact(contact); partner.setContact(contact);
imported = true;
} }
if (rec.getString("roles").contains("billing")) { if (rec.getString("roles").contains("billing")) {
assertThat(debitor.getBillingContact()).isNull();
debitor.setBillingContact(contact); debitor.setBillingContact(contact);
imported = true;
} }
if (rec.getString("roles").contains("operation")) { if (rec.getString("roles").contains("operation")) {
final var rel = HsOfficeRelationshipEntity.builder() final var rel = HsOfficeRelationshipEntity.builder()
@ -686,9 +689,26 @@ public class ImportOfficeTables extends ContextBasedTest {
.relType(HsOfficeRelationshipType.TECHNICAL_CONTACT) .relType(HsOfficeRelationshipType.TECHNICAL_CONTACT)
.build(); .build();
relationships.put(contactId, rel); relationships.put(contactId, rel);
imported = true;
} }
} else { if (rec.getString("roles").contains("representative")) {
fail("contact without role: " + rec); final var rel = HsOfficeRelationshipEntity.builder()
.relAnchor(partner.getPerson())
.relHolder(person)
.contact(contact)
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
.build();
relationships.put(contactId, rel);
imported = true;
}
if (!imported) {
final var rel = HsOfficeRelationshipEntity.builder()
.relAnchor(partner.getPerson())
.relHolder(person)
.contact(contact)
.relType(HsOfficeRelationshipType.UNKNOWN)
.build();
relationships.put(contactId, rel);
} }
}); });
} }