feature/prefixes-for-partner-member-debitor-in-api #122
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR;
|
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR;
|
||||||
|
import static net.hostsharing.hsadminng.repr.TaggedNumber.cropTag;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
|
||||||
@ -53,11 +54,11 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final String name,
|
final String name,
|
||||||
final Integer debitorNumber) {
|
final String debitorNumber) {
|
||||||
context.define(currentSubject, assumedRoles);
|
context.define(currentSubject, assumedRoles);
|
||||||
|
|
||||||
final var entities = debitorNumber != null
|
final var entities = debitorNumber != null
|
||||||
? debitorRepo.findDebitorByDebitorNumber(debitorNumber)
|
? debitorRepo.findDebitorByDebitorNumber(cropTag("D-", debitorNumber))
|
||||||
: debitorRepo.findDebitorByOptionalNameLike(name);
|
: debitorRepo.findDebitorByOptionalNameLike(name);
|
||||||
|
|
||||||
final var resources = mapper.mapList(entities, HsOfficeDebitorResource.class);
|
final var resources = mapper.mapList(entities, HsOfficeDebitorResource.class);
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.debitor;
|
package net.hostsharing.hsadminng.hs.office.debitor;
|
||||||
|
|
||||||
|
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -16,13 +18,16 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
|
|||||||
JOIN HsOfficePartnerEntity partner
|
JOIN HsOfficePartnerEntity partner
|
||||||
ON partner.partnerRel.holder = debitor.debitorRel.anchor
|
ON partner.partnerRel.holder = debitor.debitorRel.anchor
|
||||||
AND partner.partnerRel.type = 'PARTNER' AND debitor.debitorRel.type = 'DEBITOR'
|
AND partner.partnerRel.type = 'PARTNER' AND debitor.debitorRel.type = 'DEBITOR'
|
||||||
WHERE cast(partner.partnerNumber as integer) = :partnerNumber
|
WHERE partner.partnerNumber = :partnerNumber
|
||||||
AND cast(debitor.debitorNumberSuffix as integer) = :debitorNumberSuffix
|
AND debitor.debitorNumberSuffix = :debitorNumberSuffix
|
||||||
""")
|
""")
|
||||||
List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int partnerNumber, byte debitorNumberSuffix);
|
List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int partnerNumber, String debitorNumberSuffix);
|
||||||
|
|
||||||
default List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int debitorNumber) {
|
default List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int debitorNumber) {
|
||||||
return findDebitorByDebitorNumber( debitorNumber/100, (byte) (debitorNumber%100));
|
final var partnerNumber = debitorNumber / 100;
|
||||||
|
final String suffix = String.format("%02d", debitorNumber % 100);
|
||||||
|
final var result = findDebitorByDebitorNumber(partnerNumber, suffix);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
|
@ -131,7 +131,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
|
|||||||
if (entity.getValidity().hasUpperBound()) {
|
if (entity.getValidity().hasUpperBound()) {
|
||||||
resource.setValidTo(entity.getValidity().upper().minusDays(1));
|
resource.setValidTo(entity.getValidity().upper().minusDays(1));
|
||||||
}
|
}
|
||||||
resource.getDebitor().setDebitorNumber(entity.getDebitor().getDebitorNumber());
|
resource.getDebitor().setDebitorNumber("D-" + entity.getDebitor().getDebitorNumber());
|
||||||
};
|
};
|
||||||
|
|
||||||
final BiConsumer<HsOfficeSepaMandateInsertResource, HsOfficeSepaMandateEntity> SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
|
final BiConsumer<HsOfficeSepaMandateInsertResource, HsOfficeSepaMandateEntity> SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
|
||||||
|
@ -12,10 +12,10 @@ components:
|
|||||||
debitorRel:
|
debitorRel:
|
||||||
$ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation'
|
$ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation'
|
||||||
debitorNumber:
|
debitorNumber:
|
||||||
type: integer
|
type: string
|
||||||
format: int32
|
minLength: 9
|
||||||
minimum: 1000000
|
maxLength: 9
|
||||||
maximum: 9999999
|
pattern: 'D-[0-9]{7}'
|
||||||
debitorNumberSuffix:
|
debitorNumberSuffix:
|
||||||
type: string
|
type: string
|
||||||
pattern: '^[0-9][0-9]$'
|
pattern: '^[0-9][0-9]$'
|
||||||
|
@ -17,7 +17,10 @@ get:
|
|||||||
in: query
|
in: query
|
||||||
required: false
|
required: false
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: string
|
||||||
|
minLength: 9
|
||||||
|
maxLength: 9
|
||||||
|
pattern: 'D-[0-9]{7}'
|
||||||
description: Debitor number of the requested debitor.
|
description: Debitor number of the requested debitor.
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
|
@ -238,7 +238,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
|||||||
@Test
|
@Test
|
||||||
@Order(2011)
|
@Order(2011)
|
||||||
@Requires("Person: Test AG")
|
@Requires("Person: Test AG")
|
||||||
@Produces("Debitor: Billing GmbH")
|
@Produces("Debitor: D-3101000 - Test AG - main debitor")
|
||||||
void shouldCreateExternalDebitorForPartner() {
|
void shouldCreateExternalDebitorForPartner() {
|
||||||
new CreateExternalDebitorForPartner(this)
|
new CreateExternalDebitorForPartner(this)
|
||||||
.given("partnerPersonTradeName", "Test AG")
|
.given("partnerPersonTradeName", "Test AG")
|
||||||
@ -283,7 +283,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
|||||||
void shouldCreateSepaMandateForDebitor() {
|
void shouldCreateSepaMandateForDebitor() {
|
||||||
new CreateSepaMandateForDebitor(this)
|
new CreateSepaMandateForDebitor(this)
|
||||||
// existing debitor
|
// existing debitor
|
||||||
.given("debitorNumber", "3101000")
|
.given("debitorNumber", "D-3101000")
|
||||||
|
|
||||||
// new sepa-mandate
|
// new sepa-mandate
|
||||||
.given("mandateReference", "Test AG - main debitor")
|
.given("mandateReference", "Test AG - main debitor")
|
||||||
|
Loading…
Reference in New Issue
Block a user