hs-office-partner-details
This commit is contained in:
@ -23,7 +23,7 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
|
||||
JOIN HsOfficePersonEntity person ON person.uuid = partner.person
|
||||
JOIN HsOfficeContactEntity contact ON contact.uuid = debitor.billingContact
|
||||
WHERE :name is null
|
||||
OR partner.birthName like concat(:name, '%')
|
||||
OR partner.details.birthName like concat(:name, '%')
|
||||
OR person.tradeName like concat(:name, '%')
|
||||
OR person.familyName like concat(:name, '%')
|
||||
OR person.givenName like concat(:name, '%')
|
||||
|
@ -72,6 +72,8 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
entityToSave.setPerson(personRepo.findByUuid(body.getPersonUuid()).orElseThrow(
|
||||
() -> new NoSuchElementException("cannot find person uuid " + body.getPersonUuid())
|
||||
));
|
||||
entityToSave.setDetails(map(body.getDetails(), HsOfficePartnerDetailsEntity.class));
|
||||
entityToSave.getDetails().setUuid(UUID.randomUUID());
|
||||
|
||||
final var saved = partnerRepo.save(entityToSave);
|
||||
|
||||
@ -129,14 +131,13 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
|
||||
final var current = partnerRepo.findByUuid(partnerUuid).orElseThrow();
|
||||
|
||||
new HsOfficePartnerEntityPatcher(em, current, contactRepo::findByUuid, personRepo::findByUuid).apply(body);
|
||||
new HsOfficePartnerEntityPatcher(em, current).apply(body);
|
||||
|
||||
final var saved = partnerRepo.save(current);
|
||||
final var mapped = map(saved, HsOfficePartnerResource.class);
|
||||
return ResponseEntity.ok(mapped);
|
||||
}
|
||||
|
||||
|
||||
final BiConsumer<HsOfficePartnerEntity, HsOfficePartnerResource> PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> {
|
||||
resource.setPerson(map(entity.getPerson(), HsOfficePersonResource.class));
|
||||
resource.setContact(map(entity.getContact(), HsOfficeContactResource.class));
|
||||
@ -145,11 +146,11 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
// TODO.impl: user postmapper + getReference
|
||||
private HsOfficePartnerEntity mapToHsOfficePartnerEntity(final HsOfficePartnerInsertResource resource) {
|
||||
final var entity = new HsOfficePartnerEntity();
|
||||
entity.setBirthday(resource.getBirthday());
|
||||
entity.setBirthName(resource.getBirthName());
|
||||
entity.setDateOfDeath(resource.getDateOfDeath());
|
||||
entity.setRegistrationNumber(resource.getRegistrationNumber());
|
||||
entity.setRegistrationOffice(resource.getRegistrationOffice());
|
||||
// entity.setBirthday(resource.getBirthday());
|
||||
// entity.setBirthName(resource.getBirthName());
|
||||
// entity.setDateOfDeath(resource.getDateOfDeath());
|
||||
// entity.setRegistrationNumber(resource.getRegistrationNumber());
|
||||
// entity.setRegistrationOffice(resource.getRegistrationOffice());
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.Stringify;
|
||||
import net.hostsharing.hsadminng.Stringifyable;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.Stringify.stringify;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hs_office_partner_details_rv")
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("PartnerDetails")
|
||||
public class HsOfficePartnerDetailsEntity implements Stringifyable {
|
||||
|
||||
private static Stringify<HsOfficePartnerDetailsEntity> stringify = stringify(
|
||||
HsOfficePartnerDetailsEntity.class,
|
||||
"partnerDetails")
|
||||
.withProp(HsOfficePartnerDetailsEntity::getRegistrationOffice)
|
||||
.withProp(HsOfficePartnerDetailsEntity::getRegistrationNumber)
|
||||
.withProp(HsOfficePartnerDetailsEntity::getBirthday)
|
||||
.withProp(HsOfficePartnerDetailsEntity::getBirthday)
|
||||
.withProp(HsOfficePartnerDetailsEntity::getDateOfDeath)
|
||||
.withSeparator(", ")
|
||||
.quotedValues(false);
|
||||
|
||||
private @Id UUID uuid;
|
||||
|
||||
private @Column(name = "registrationoffice") String registrationOffice;
|
||||
private @Column(name = "registrationnumber") String registrationNumber;
|
||||
private @Column(name = "birthname") String birthName;
|
||||
private @Column(name = "birthday") LocalDate birthday;
|
||||
private @Column(name = "dateofdeath") LocalDate dateOfDeath;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stringify.apply(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return registrationNumber != null ? registrationNumber
|
||||
: birthName != null ? birthName
|
||||
: birthday != null ? birthday.toString()
|
||||
: dateOfDeath != null ? dateOfDeath.toString() : "<empty details>";
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.OptionalFromJson;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerDetailsPatchResource;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.UUID;
|
||||
|
||||
class HsOfficePartnerDetailsEntityPatcher implements EntityPatcher<HsOfficePartnerDetailsPatchResource> {
|
||||
|
||||
private final EntityManager em;
|
||||
private final HsOfficePartnerDetailsEntity entity;
|
||||
|
||||
HsOfficePartnerDetailsEntityPatcher(
|
||||
final EntityManager em,
|
||||
final HsOfficePartnerDetailsEntity entity) {
|
||||
this.em = em;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(final HsOfficePartnerDetailsPatchResource resource) {
|
||||
if (resource != null) {
|
||||
OptionalFromJson.of(resource.getRegistrationOffice()).ifPresent(entity::setRegistrationOffice);
|
||||
OptionalFromJson.of(resource.getRegistrationNumber()).ifPresent(entity::setRegistrationNumber);
|
||||
OptionalFromJson.of(resource.getBirthday()).ifPresent(entity::setBirthday);
|
||||
OptionalFromJson.of(resource.getBirthName()).ifPresent(entity::setBirthName);
|
||||
OptionalFromJson.of(resource.getDateOfDeath()).ifPresent(entity::setDateOfDeath);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ import net.hostsharing.hsadminng.Stringify;
|
||||
import net.hostsharing.hsadminng.Stringifyable;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import org.hibernate.annotations.NotFound;
|
||||
import org.hibernate.annotations.NotFoundAction;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
@ -32,18 +34,17 @@ public class HsOfficePartnerEntity implements Stringifyable {
|
||||
private @Id UUID uuid;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "personuuid")
|
||||
@JoinColumn(name = "personuuid", nullable = false)
|
||||
private HsOfficePersonEntity person;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "contactuuid")
|
||||
@JoinColumn(name = "contactuuid", nullable = false)
|
||||
private HsOfficeContactEntity contact;
|
||||
|
||||
private @Column(name = "registrationoffice") String registrationOffice;
|
||||
private @Column(name = "registrationnumber") String registrationNumber;
|
||||
private @Column(name = "birthname") String birthName;
|
||||
private @Column(name = "birthday") LocalDate birthday;
|
||||
private @Column(name = "dateofdeath") LocalDate dateOfDeath;
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH}, optional = true)
|
||||
@JoinColumn(name = "detailsuuid", nullable = true)
|
||||
@NotFound(action= NotFoundAction.IGNORE)
|
||||
private HsOfficePartnerDetailsEntity details;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -17,18 +17,11 @@ import java.util.function.Supplier;
|
||||
class HsOfficePartnerEntityPatcher implements EntityPatcher<HsOfficePartnerPatchResource> {
|
||||
private final EntityManager em;
|
||||
private final HsOfficePartnerEntity entity;
|
||||
private final Function<UUID, Optional<HsOfficeContactEntity>> fetchContact;
|
||||
private final Function<UUID, Optional<HsOfficePersonEntity>> fetchPerson;
|
||||
|
||||
HsOfficePartnerEntityPatcher(
|
||||
final EntityManager em,
|
||||
final HsOfficePartnerEntity entity,
|
||||
final Function<UUID, Optional<HsOfficeContactEntity>> fetchContact,
|
||||
final Function<UUID, Optional<HsOfficePersonEntity>> fetchPerson) {
|
||||
final HsOfficePartnerEntity entity) {
|
||||
this.em = em;
|
||||
this.entity = entity;
|
||||
this.fetchContact = fetchContact;
|
||||
this.fetchPerson = fetchPerson;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,11 +34,8 @@ class HsOfficePartnerEntityPatcher implements EntityPatcher<HsOfficePartnerPatch
|
||||
verifyNotNull(newValue, "person");
|
||||
entity.setPerson(em.getReference(HsOfficePersonEntity.class, newValue));
|
||||
});
|
||||
OptionalFromJson.of(resource.getRegistrationOffice()).ifPresent(entity::setRegistrationOffice);
|
||||
OptionalFromJson.of(resource.getRegistrationNumber()).ifPresent(entity::setRegistrationNumber);
|
||||
OptionalFromJson.of(resource.getBirthday()).ifPresent(entity::setBirthday);
|
||||
OptionalFromJson.of(resource.getBirthName()).ifPresent(entity::setBirthName);
|
||||
OptionalFromJson.of(resource.getDateOfDeath()).ifPresent(entity::setDateOfDeath);
|
||||
|
||||
new HsOfficePartnerDetailsEntityPatcher(em, entity.getDetails()).apply(resource.getDetails());
|
||||
}
|
||||
|
||||
private void verifyNotNull(final UUID newValue, final String propertyName) {
|
||||
|
@ -16,7 +16,7 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
|
||||
JOIN HsOfficeContactEntity contact ON contact.uuid = partner.contact
|
||||
JOIN HsOfficePersonEntity person ON person.uuid = partner.person
|
||||
WHERE :name is null
|
||||
OR partner.birthName like concat(:name, '%')
|
||||
OR partner.details.birthName like concat(:name, '%')
|
||||
OR contact.label like concat(:name, '%')
|
||||
OR person.tradeName like concat(:name, '%')
|
||||
OR person.givenName like concat(:name, '%')
|
||||
|
Reference in New Issue
Block a user