feature/use-case-acceptance-tests #116
@ -77,17 +77,13 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
"ERROR: [400] exactly one of debitorRel and debitorRelUuid must be supplied, but found both");
|
"ERROR: [400] exactly one of debitorRel and debitorRelUuid must be supplied, but found both");
|
||||||
Validate.isTrue(body.getDebitorRel() != null || body.getDebitorRelUuid() != null,
|
Validate.isTrue(body.getDebitorRel() != null || body.getDebitorRelUuid() != null,
|
||||||
"ERROR: [400] exactly one of debitorRel and debitorRelUuid must be supplied, but found none");
|
"ERROR: [400] exactly one of debitorRel and debitorRelUuid must be supplied, but found none");
|
||||||
Validate.isTrue(body.getDebitorRel() == null ||
|
|
||||||
body.getDebitorRel().getType() == null || DEBITOR.name().equals(body.getDebitorRel().getType()),
|
|
||||||
"ERROR: [400] debitorRel.type must be '"+DEBITOR.name()+"' or null for default");
|
|
||||||
Validate.isTrue(body.getDebitorRel() == null || body.getDebitorRel().getMark() == null,
|
Validate.isTrue(body.getDebitorRel() == null || body.getDebitorRel().getMark() == null,
|
||||||
"ERROR: [400] debitorRel.mark must be null");
|
"ERROR: [400] debitorRel.mark must be null");
|
||||||
|
|
||||||
final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class);
|
final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class);
|
||||||
try {
|
|
||||||
if (body.getDebitorRel() != null) {
|
if (body.getDebitorRel() != null) {
|
||||||
body.getDebitorRel().setType(DEBITOR.name());
|
|
||||||
final var debitorRel = mapper.map("debitorRel.", body.getDebitorRel(), HsOfficeRelationRealEntity.class);
|
final var debitorRel = mapper.map("debitorRel.", body.getDebitorRel(), HsOfficeRelationRealEntity.class);
|
||||||
|
debitorRel.setType(DEBITOR);
|
||||||
entityValidator.validateEntityExists("debitorRel.anchorUuid", debitorRel.getAnchor());
|
entityValidator.validateEntityExists("debitorRel.anchorUuid", debitorRel.getAnchor());
|
||||||
entityValidator.validateEntityExists("debitorRel.holderUuid", debitorRel.getHolder());
|
entityValidator.validateEntityExists("debitorRel.holderUuid", debitorRel.getHolder());
|
||||||
entityValidator.validateEntityExists("debitorRel.contactUuid", debitorRel.getContact());
|
entityValidator.validateEntityExists("debitorRel.contactUuid", debitorRel.getContact());
|
||||||
@ -102,22 +98,6 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final var partnerRel = em.createNativeQuery("""
|
|
||||||
SELECT partnerRel.*
|
|
||||||
FROM hs_office.relation AS partnerRel
|
|
||||||
JOIN hs_office.relation AS debitorRel
|
|
||||||
ON debitorRel.type = 'DEBITOR' AND debitorRel.anchorUuid = partnerRel.holderUuid
|
|
||||||
WHERE partnerRel.type = 'PARTNER'
|
|
||||||
AND :NEW_DebitorRelUuid = debitorRel.uuid
|
|
||||||
""").setParameter("NEW_DebitorRelUuid", entityToSave.getDebitorRel().getUuid()).getResultList();
|
|
||||||
|
|
||||||
|
|
||||||
final var debitorRel = em.createNativeQuery("""
|
|
||||||
SELECT debitorRel.*
|
|
||||||
FROM hs_office.relation AS debitorRel
|
|
||||||
WHERE :NEW_DebitorRelUuid = debitorRel.uuid
|
|
||||||
""").setParameter("NEW_DebitorRelUuid", entityToSave.getDebitorRel().getUuid()).getResultList();
|
|
||||||
|
|
||||||
final var savedEntity = debitorRepo.save(entityToSave);
|
final var savedEntity = debitorRepo.save(entityToSave);
|
||||||
em.flush();
|
em.flush();
|
||||||
em.refresh(savedEntity);
|
em.refresh(savedEntity);
|
||||||
@ -129,9 +109,6 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
.toUri();
|
.toUri();
|
||||||
final var mapped = mapper.map(savedEntity, HsOfficeDebitorResource.class);
|
final var mapped = mapper.map(savedEntity, HsOfficeDebitorResource.class);
|
||||||
return ResponseEntity.created(uri).body(mapped);
|
return ResponseEntity.created(uri).body(mapped);
|
||||||
} catch (final RuntimeException exc) {
|
|
||||||
throw exc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,7 +74,7 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
debitorRel:
|
debitorRel:
|
||||||
$ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelationInsert'
|
$ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelationSubInsert'
|
||||||
debitorRelUuid:
|
debitorRelUuid:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
@ -41,6 +41,7 @@ components:
|
|||||||
format: uuid
|
format: uuid
|
||||||
nullable: true
|
nullable: true
|
||||||
|
|
||||||
|
# arbitrary relation with explicit type
|
||||||
HsOfficeRelationInsert:
|
HsOfficeRelationInsert:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -64,3 +65,24 @@ components:
|
|||||||
- holderUuid
|
- holderUuid
|
||||||
- type
|
- type
|
||||||
- contactUuid
|
- contactUuid
|
||||||
|
|
||||||
|
# relation created as a sub-element with implicitly known type
|
||||||
|
HsOfficeRelationSubInsert:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
anchorUuid:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
holderUuid:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
mark:
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
contactUuid:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
required:
|
||||||
|
- anchorUuid
|
||||||
|
- holderUuid
|
||||||
|
- contactUuid
|
||||||
|
@ -46,7 +46,6 @@ public class CreateExternalDebitorForPartner extends UseCase<CreateExternalDebit
|
|||||||
return httpPost("/api/hs/office/debitors", usingJsonBody("""
|
return httpPost("/api/hs/office/debitors", usingJsonBody("""
|
||||||
{
|
{
|
||||||
"debitorRel": {
|
"debitorRel": {
|
||||||
"type": "DEBITOR", // FIXME: should be defaulted to DEBITOR
|
|
||||||
"anchorUuid": ${partnerPersonUuid},
|
"anchorUuid": ${partnerPersonUuid},
|
||||||
"holderUuid": ${Person: Billing GmbH},
|
"holderUuid": ${Person: Billing GmbH},
|
||||||
"contactUuid": ${Contact: Billing GmbH - Test AG billing}
|
"contactUuid": ${Contact: Billing GmbH - Test AG billing}
|
||||||
|
Loading…
Reference in New Issue
Block a user