enable import of a single contact for multiple roles
This commit is contained in:
parent
19f962cf2e
commit
683c2f0ce4
@ -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.isNotBlank;
|
||||
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.
|
||||
@ -102,8 +101,8 @@ import static org.assertj.core.api.Fail.fail;
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class ImportOfficeTables extends ContextBasedTest {
|
||||
|
||||
@Value("${spring.datasource.url}")
|
||||
private String jdbcUrl;
|
||||
@Value("${spring.datasource.username}")
|
||||
private String postgresAdminUser;
|
||||
|
||||
// TODO: use real rbacSuperuser for actual import
|
||||
private static final String rbacSuperuser = "superuser-alex@hostsharing.net";
|
||||
@ -145,16 +144,16 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if ( !"admin".equals(System.getenv("ADMIN_USER") )) {
|
||||
if ( !"admin".equals(postgresAdminUser) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// no contacts yet => mostly null values
|
||||
assertThat(partners.toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
7=partner(null, null: null),
|
||||
10=partner(null, null: null),
|
||||
12=partner(null, null: null)
|
||||
7=partner(null, null),
|
||||
10=partner(null, null),
|
||||
12=partner(null, null)
|
||||
}
|
||||
""");
|
||||
assertThat(contacts.toString()).isEqualTo("{}");
|
||||
@ -184,7 +183,7 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if ( !"admin".equals(System.getenv("HSADMINNG_POSTGRES_ADMIN_USERNAME") )) {
|
||||
if ( !"admin".equals(postgresAdminUser) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -245,7 +244,7 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if ( !"admin".equals(System.getenv("HSADMINNG_POSTGRES_ADMIN_USERNAME") )) {
|
||||
if ( !"admin".equals(postgresAdminUser) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -274,7 +273,7 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if ( !"admin".equals(System.getenv("HSADMINNG_POSTGRES_ADMIN_USERNAME") )) {
|
||||
if ( !"admin".equals(postgresAdminUser) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -299,7 +298,7 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if ( !"admin".equals(System.getenv("ADMIN_USER") )) {
|
||||
if ( !"admin".equals(postgresAdminUser) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -657,7 +656,6 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
.map(this::trimAll)
|
||||
.map(row -> new Record(columns, row))
|
||||
.forEach(rec -> {
|
||||
if (isNotBlank(rec.getString("roles"))) {
|
||||
final var contactId = rec.getInteger("contact_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();
|
||||
contacts.put(contactId, initContact(contact, rec));
|
||||
|
||||
var imported = false;
|
||||
if (rec.getString("roles").contains("contractual")) {
|
||||
assertThat(partner.getContact()).isNull();
|
||||
partner.setContact(contact);
|
||||
imported = true;
|
||||
}
|
||||
if (rec.getString("roles").contains("billing")) {
|
||||
assertThat(debitor.getBillingContact()).isNull();
|
||||
debitor.setBillingContact(contact);
|
||||
imported = true;
|
||||
}
|
||||
if (rec.getString("roles").contains("operation")) {
|
||||
final var rel = HsOfficeRelationshipEntity.builder()
|
||||
@ -686,9 +689,26 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
.relType(HsOfficeRelationshipType.TECHNICAL_CONTACT)
|
||||
.build();
|
||||
relationships.put(contactId, rel);
|
||||
imported = true;
|
||||
}
|
||||
} else {
|
||||
fail("contact without role: " + rec);
|
||||
if (rec.getString("roles").contains("representative")) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user