SEPA-Mandate signed date and patcher
This commit is contained in:
@@ -18,7 +18,7 @@ import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.*;
|
||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
|
||||
@Entity
|
||||
@@ -73,13 +73,22 @@ public class HsOfficeMembershipEntity implements Stringifyable {
|
||||
private HsOfficeReasonForTermination reasonForTermination;
|
||||
|
||||
public void setValidFrom(final LocalDate validFrom) {
|
||||
validity = toPostgresDateRange(validFrom, getValidity().upper());
|
||||
setValidity(toPostgresDateRange(validFrom, getValidTo()));
|
||||
}
|
||||
|
||||
public void setValidTo(final LocalDate validTo) {
|
||||
validity = toPostgresDateRange(getValidity().lower(), validTo);
|
||||
setValidity(toPostgresDateRange(getValidFrom(), validTo));
|
||||
}
|
||||
|
||||
public LocalDate getValidFrom() {
|
||||
return lowerInclusiveFromPostgresDateRange(getValidity());
|
||||
}
|
||||
|
||||
public LocalDate getValidTo() {
|
||||
return upperInclusiveFromPostgresDateRange(getValidity());
|
||||
}
|
||||
|
||||
|
||||
public Range<LocalDate> getValidity() {
|
||||
if (validity == null) {
|
||||
validity = Range.infinite(LocalDate.class);
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.office.sepamandate;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntityPatcher;
|
||||
import net.hostsharing.hsadminng.mapper.Mapper;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeSepaMandatesApi;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateInsertResource;
|
||||
@@ -32,7 +34,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
|
||||
private Mapper mapper;
|
||||
|
||||
@Autowired
|
||||
private HsOfficeSepaMandateRepository SepaMandateRepo;
|
||||
private HsOfficeSepaMandateRepository sepaMandateRepo;
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
@@ -45,7 +47,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
|
||||
final String iban) {
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var entities = SepaMandateRepo.findSepaMandateByOptionalIban(iban);
|
||||
final var entities = sepaMandateRepo.findSepaMandateByOptionalIban(iban);
|
||||
|
||||
final var resources = mapper.mapList(entities, HsOfficeSepaMandateResource.class,
|
||||
SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER);
|
||||
@@ -63,7 +65,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
|
||||
|
||||
final var entityToSave = mapper.map(body, HsOfficeSepaMandateEntity.class, SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER);
|
||||
|
||||
final var saved = SepaMandateRepo.save(entityToSave);
|
||||
final var saved = sepaMandateRepo.save(entityToSave);
|
||||
|
||||
final var uri =
|
||||
MvcUriComponentsBuilder.fromController(getClass())
|
||||
@@ -84,7 +86,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
|
||||
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var result = SepaMandateRepo.findByUuid(sepaMandateUuid);
|
||||
final var result = sepaMandateRepo.findByUuid(sepaMandateUuid);
|
||||
if (result.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
@@ -100,7 +102,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
|
||||
final UUID sepaMandateUuid) {
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var result = SepaMandateRepo.deleteByUuid(sepaMandateUuid);
|
||||
final var result = sepaMandateRepo.deleteByUuid(sepaMandateUuid);
|
||||
if (result == 0) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
@@ -118,11 +120,11 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
|
||||
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var current = SepaMandateRepo.findByUuid(sepaMandateUuid).orElseThrow();
|
||||
final var current = sepaMandateRepo.findByUuid(sepaMandateUuid).orElseThrow();
|
||||
|
||||
current.setValidity(toPostgresDateRange(current.getValidity().lower(), body.getValidTo()));
|
||||
new HsOfficeSepaMandateEntityPatcher(current).apply(body);
|
||||
|
||||
final var saved = SepaMandateRepo.save(current);
|
||||
final var saved = sepaMandateRepo.save(current);
|
||||
final var mapped = mapper.map(saved, HsOfficeSepaMandateResource.class, SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER);
|
||||
return ResponseEntity.ok(mapped);
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.*;
|
||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
|
||||
@Entity
|
||||
@@ -33,6 +34,7 @@ public class HsOfficeSepaMandateEntity implements Stringifyable {
|
||||
private static Stringify<HsOfficeSepaMandateEntity> stringify = stringify(HsOfficeSepaMandateEntity.class)
|
||||
.withProp(e -> e.getBankAccount().getIban())
|
||||
.withProp(HsOfficeSepaMandateEntity::getReference)
|
||||
.withProp(HsOfficeSepaMandateEntity::getAgreement)
|
||||
.withProp(e -> e.getValidity().asString())
|
||||
.withSeparator(", ")
|
||||
.quotedValues(false);
|
||||
@@ -51,8 +53,27 @@ public class HsOfficeSepaMandateEntity implements Stringifyable {
|
||||
|
||||
private @Column(name = "reference") String reference;
|
||||
|
||||
@Column(name="agreement", columnDefinition = "date")
|
||||
private LocalDate agreement;
|
||||
|
||||
@Column(name = "validity", columnDefinition = "daterange")
|
||||
private Range<LocalDate> validity;
|
||||
private Range<LocalDate> validity = Range.infinite(LocalDate.class);
|
||||
|
||||
public void setValidFrom(final LocalDate validFrom) {
|
||||
setValidity(toPostgresDateRange(validFrom, getValidTo()));
|
||||
}
|
||||
|
||||
public void setValidTo(final LocalDate validTo) {
|
||||
setValidity(toPostgresDateRange(getValidFrom(), validTo));
|
||||
}
|
||||
|
||||
public LocalDate getValidFrom() {
|
||||
return lowerInclusiveFromPostgresDateRange(getValidity());
|
||||
}
|
||||
|
||||
public LocalDate getValidTo() {
|
||||
return upperInclusiveFromPostgresDateRange(getValidity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -63,4 +84,5 @@ public class HsOfficeSepaMandateEntity implements Stringifyable {
|
||||
public String toShortString() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package net.hostsharing.hsadminng.hs.office.sepamandate;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandatePatchResource;
|
||||
import net.hostsharing.hsadminng.mapper.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.mapper.OptionalFromJson;
|
||||
|
||||
public class HsOfficeSepaMandateEntityPatcher implements EntityPatcher<HsOfficeSepaMandatePatchResource> {
|
||||
|
||||
private final HsOfficeSepaMandateEntity entity;
|
||||
|
||||
public HsOfficeSepaMandateEntityPatcher(final HsOfficeSepaMandateEntity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(final HsOfficeSepaMandatePatchResource resource) {
|
||||
OptionalFromJson.of(resource.getReference()).ifPresent(
|
||||
entity::setReference);
|
||||
OptionalFromJson.of(resource.getAgreement()).ifPresent(
|
||||
entity::setAgreement);
|
||||
OptionalFromJson.of(resource.getValidFrom()).ifPresent(
|
||||
entity::setValidFrom);
|
||||
OptionalFromJson.of(resource.getValidTo()).ifPresent(
|
||||
entity::setValidTo);
|
||||
}
|
||||
}
|
@@ -9,14 +9,25 @@ import java.time.LocalDate;
|
||||
public class PostgresDateRange {
|
||||
|
||||
public static Range<LocalDate> toPostgresDateRange(
|
||||
final LocalDate validFrom,
|
||||
final LocalDate validTo) {
|
||||
return validFrom != null
|
||||
? validTo != null
|
||||
? Range.closedOpen(validFrom, validTo.plusDays(1))
|
||||
: Range.closedInfinite(validFrom)
|
||||
: validTo != null
|
||||
? Range.infiniteOpen(validTo.plusDays(1))
|
||||
final LocalDate lowerInclusive,
|
||||
final LocalDate upperInclusive) {
|
||||
return lowerInclusive != null
|
||||
? upperInclusive != null
|
||||
? Range.closedOpen(lowerInclusive, upperInclusive.plusDays(1))
|
||||
: Range.closedInfinite(lowerInclusive)
|
||||
: upperInclusive != null
|
||||
? Range.infiniteOpen(upperInclusive.plusDays(1))
|
||||
: Range.infinite(LocalDate.class);
|
||||
}
|
||||
|
||||
public static LocalDate lowerInclusiveFromPostgresDateRange(
|
||||
final Range<LocalDate> range) {
|
||||
return range.lower();
|
||||
}
|
||||
|
||||
public static LocalDate upperInclusiveFromPostgresDateRange(
|
||||
final Range<LocalDate> range) {
|
||||
return range.upper() != null ? range.upper().minusDays(1) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ map:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
||||
/api/hs/office/debitors/{debitorUUID}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
||||
/api/hs/office/sepamandates/{debitorUUID}:
|
||||
/api/hs/office/sepamandates/{sepaMandateUUID}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
||||
/api/hs/office/memberships/{membershipUUID}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
||||
|
@@ -15,6 +15,9 @@ components:
|
||||
$ref: './hs-office-bankaccount-schemas.yaml#/components/schemas/HsOfficeBankAccount'
|
||||
reference:
|
||||
type: string
|
||||
agreement:
|
||||
type: string
|
||||
format: date
|
||||
validFrom:
|
||||
type: string
|
||||
format: date
|
||||
@@ -25,9 +28,21 @@ components:
|
||||
HsOfficeSepaMandatePatch:
|
||||
type: object
|
||||
properties:
|
||||
reference:
|
||||
type: string
|
||||
nullable: true
|
||||
agreement:
|
||||
type: string
|
||||
format: date
|
||||
nullable: true
|
||||
validFrom:
|
||||
type: string
|
||||
format: date
|
||||
nullable: true
|
||||
validTo:
|
||||
type: string
|
||||
format: date
|
||||
nullable: true
|
||||
additionalProperties: false
|
||||
|
||||
HsOfficeSepaMandateInsert:
|
||||
@@ -44,6 +59,10 @@ components:
|
||||
reference:
|
||||
type: string
|
||||
nullable: false
|
||||
agreement:
|
||||
type: string
|
||||
format: date
|
||||
nullable: false
|
||||
validFrom:
|
||||
type: string
|
||||
format: date
|
||||
@@ -56,5 +75,6 @@ components:
|
||||
- debitorUuid
|
||||
- bankAccountUuid
|
||||
- reference
|
||||
- agreement
|
||||
- validFrom
|
||||
additionalProperties: false
|
||||
|
@@ -10,6 +10,7 @@ create table if not exists hs_office_sepamandate
|
||||
debitorUuid uuid not null references hs_office_debitor(uuid),
|
||||
bankAccountUuid uuid not null references hs_office_bankaccount(uuid),
|
||||
reference varchar(96) not null,
|
||||
agreement date not null,
|
||||
validity daterange not null
|
||||
);
|
||||
--//
|
||||
|
@@ -102,6 +102,7 @@ call generateRbacIdentityView('hs_office_sepamandate', idNameExpression => 'targ
|
||||
call generateRbacRestrictedView('hs_office_sepamandate',
|
||||
orderby => 'target.reference',
|
||||
columnUpdates => $updates$
|
||||
agreement = new.agreement,
|
||||
validity = new.validity
|
||||
$updates$);
|
||||
--//
|
||||
|
@@ -31,8 +31,8 @@ begin
|
||||
raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor;
|
||||
raise notice '- using bankAccount (%): %', relatedBankAccount.uuid, relatedBankAccount;
|
||||
insert
|
||||
into hs_office_sepamandate (uuid, debitoruuid, bankAccountuuid, reference, validity)
|
||||
values (uuid_generate_v4(), relatedDebitor.uuid, relatedBankAccount.uuid, 'ref'||idName, daterange('20221001' , '20261231', '[]'));
|
||||
into hs_office_sepamandate (uuid, debitoruuid, bankAccountuuid, reference, agreement, validity)
|
||||
values (uuid_generate_v4(), relatedDebitor.uuid, relatedBankAccount.uuid, 'ref'||idName, '20220930', daterange('20221001' , '20261231', '[]'));
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
|
Reference in New Issue
Block a user