switch to HsOfficeRelationRbacEntity + HsOfficeRelationBaseEntity as subclasses of HsOfficeRelation, now tests pass

This commit is contained in:
Michael Hoennig 2024-08-03 18:53:19 +02:00
parent cdd35ef4b8
commit b41dce5c6c
35 changed files with 290 additions and 363 deletions

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.booking.project;
import lombok.*; import lombok.*;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
@ -81,7 +81,7 @@ public class HsBookingProjectEntity implements Stringifyable, RbacObject<HsBooki
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
NOT_NULL) NOT_NULL)
.importEntityAlias("debitorRel", HsOfficeRelationEntity.class, usingCase(DEBITOR), .importEntityAlias("debitorRel", HsOfficeRelation.class, usingCase(DEBITOR),
dependsOnColumn("debitorUuid"), dependsOnColumn("debitorUuid"),
fetchedBySql(""" fetchedBySql("""
SELECT ${columns} SELECT ${columns}

View File

@ -32,8 +32,8 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@MappedSuperclass @MappedSuperclass
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor @AllArgsConstructor(access = AccessLevel.PROTECTED)
@SuperBuilder(toBuilder = true) @SuperBuilder(toBuilder = true)
@FieldNameConstants @FieldNameConstants
@DisplayName("Contact") @DisplayName("Contact")

View File

@ -5,8 +5,8 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeDebitors
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorInsertResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorResource;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository;
import net.hostsharing.hsadminng.mapper.Mapper; import net.hostsharing.hsadminng.mapper.Mapper;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
@ -38,7 +38,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
private HsOfficeDebitorRepository debitorRepo; private HsOfficeDebitorRepository debitorRepo;
@Autowired @Autowired
private HsOfficeRelationRepository relRepo; private HsOfficeRelationBareRepository relBareRepo;
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@ -82,12 +82,12 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class); final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class);
if ( body.getDebitorRel() != null ) { if ( body.getDebitorRel() != null ) {
body.getDebitorRel().setType(DEBITOR.name()); body.getDebitorRel().setType(DEBITOR.name());
final var debitorRel = mapper.map(body.getDebitorRel(), HsOfficeRelationEntity.class); final var debitorRel = mapper.map(body.getDebitorRel(), HsOfficeRelation.class);
entityToSave.setDebitorRel(relRepo.save(debitorRel)); entityToSave.setDebitorRel(relBareRepo.save(debitorRel));
} else { } else {
final var debitorRelOptional = relRepo.findByUuid(body.getDebitorRelUuid()); final var debitorRelOptional = relBareRepo.findByUuid(body.getDebitorRelUuid());
debitorRelOptional.ifPresentOrElse( debitorRelOptional.ifPresentOrElse(
debitorRel -> {entityToSave.setDebitorRel(relRepo.save(debitorRel));}, debitorRel -> {entityToSave.setDebitorRel(relBareRepo.save(debitorRel));},
() -> { throw new EntityNotFoundException("ERROR: [400] debitorRelUuid not found: " + body.getDebitorRelUuid());}); () -> { throw new EntityNotFoundException("ERROR: [400] debitorRelUuid not found: " + body.getDebitorRelUuid());});
} }

View File

@ -8,7 +8,8 @@ import lombok.Setter;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
@ -66,7 +67,7 @@ public class HsOfficeDebitorEntity implements RbacObject<HsOfficeDebitorEntity>,
private static Stringify<HsOfficeDebitorEntity> stringify = private static Stringify<HsOfficeDebitorEntity> stringify =
stringify(HsOfficeDebitorEntity.class, "debitor") stringify(HsOfficeDebitorEntity.class, "debitor")
.withIdProp(HsOfficeDebitorEntity::toShortString) .withIdProp(HsOfficeDebitorEntity::toShortString)
.withProp(e -> ofNullable(e.getDebitorRel()).map(HsOfficeRelationEntity::toShortString).orElse(null)) .withProp(e -> ofNullable(e.getDebitorRel()).map(HsOfficeRelation::toShortString).orElse(null))
.withProp(HsOfficeDebitorEntity::getDefaultPrefix) .withProp(HsOfficeDebitorEntity::getDefaultPrefix)
.quotedValues(false); .quotedValues(false);
@ -101,7 +102,7 @@ public class HsOfficeDebitorEntity implements RbacObject<HsOfficeDebitorEntity>,
@ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = false, fetch = FetchType.LAZY) @ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "debitorreluuid", nullable = false) @JoinColumn(name = "debitorreluuid", nullable = false)
private HsOfficeRelationEntity debitorRel; private HsOfficeRelationBareEntity debitorRel;
@Column(name = "billable", nullable = false) @Column(name = "billable", nullable = false)
private Boolean billable; // not a primitive because otherwise the default would be false private Boolean billable; // not a primitive because otherwise the default would be false
@ -188,7 +189,7 @@ public class HsOfficeDebitorEntity implements RbacObject<HsOfficeDebitorEntity>,
"defaultPrefix") "defaultPrefix")
.toRole("global", ADMIN).grantPermission(INSERT) .toRole("global", ADMIN).grantPermission(INSERT)
.importRootEntityAliasProxy("debitorRel", HsOfficeRelationEntity.class, usingCase(DEBITOR), .importRootEntityAliasProxy("debitorRel", HsOfficeRelation.class, usingCase(DEBITOR),
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
dependsOnColumn("debitorRelUuid")) dependsOnColumn("debitorRelUuid"))
.createPermission(DELETE).grantedTo("debitorRel", OWNER) .createPermission(DELETE).grantedTo("debitorRel", OWNER)
@ -202,7 +203,7 @@ public class HsOfficeDebitorEntity implements RbacObject<HsOfficeDebitorEntity>,
.toRole("refundBankAccount", ADMIN).grantRole("debitorRel", AGENT) .toRole("refundBankAccount", ADMIN).grantRole("debitorRel", AGENT)
.toRole("debitorRel", AGENT).grantRole("refundBankAccount", REFERRER) .toRole("debitorRel", AGENT).grantRole("refundBankAccount", REFERRER)
.importEntityAlias("partnerRel", HsOfficeRelationEntity.class, usingDefaultCase(), .importEntityAlias("partnerRel", HsOfficeRelation.class, usingDefaultCase(),
dependsOnColumn("debitorRelUuid"), dependsOnColumn("debitorRelUuid"),
fetchedBySql(""" fetchedBySql("""
SELECT ${columns} SELECT ${columns}

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.EntityPatcher;
import net.hostsharing.hsadminng.mapper.OptionalFromJson; import net.hostsharing.hsadminng.mapper.OptionalFromJson;
@ -25,7 +25,7 @@ class HsOfficeDebitorEntityPatcher implements EntityPatcher<HsOfficeDebitorPatch
public void apply(final HsOfficeDebitorPatchResource resource) { public void apply(final HsOfficeDebitorPatchResource resource) {
OptionalFromJson.of(resource.getDebitorRelUuid()).ifPresent(newValue -> { OptionalFromJson.of(resource.getDebitorRelUuid()).ifPresent(newValue -> {
verifyNotNull(newValue, "debitorRel"); verifyNotNull(newValue, "debitorRel");
entity.setDebitorRel(em.getReference(HsOfficeRelationEntity.class, newValue)); entity.setDebitorRel(em.getReference(HsOfficeRelationBareEntity.class, newValue));
}); });
Optional.ofNullable(resource.getBillable()).ifPresent(entity::setBillable); Optional.ofNullable(resource.getBillable()).ifPresent(entity::setBillable);
OptionalFromJson.of(resource.getVatId()).ifPresent(entity::setVatId); OptionalFromJson.of(resource.getVatId()).ifPresent(entity::setVatId);

View File

@ -8,7 +8,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
@ -165,7 +165,7 @@ public class HsOfficeMembershipEntity implements RbacObject<HsOfficeMembershipEn
.withRestrictedViewOrderBy(SQL.projection("validity")) .withRestrictedViewOrderBy(SQL.projection("validity"))
.withUpdatableColumns("validity", "membershipFeeBillable", "status") .withUpdatableColumns("validity", "membershipFeeBillable", "status")
.importEntityAlias("partnerRel", HsOfficeRelationEntity.class, usingDefaultCase(), .importEntityAlias("partnerRel", HsOfficeRelation.class, usingDefaultCase(),
dependsOnColumn("partnerUuid"), dependsOnColumn("partnerUuid"),
fetchedBySql(""" fetchedBySql("""
SELECT ${columns} SELECT ${columns}

View File

@ -9,9 +9,9 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartne
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRelInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRelInsertResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.mapper.Mapper; import net.hostsharing.hsadminng.mapper.Mapper;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
@ -43,7 +43,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
private HsOfficePartnerRepository partnerRepo; private HsOfficePartnerRepository partnerRepo;
@Autowired @Autowired
private HsOfficeRelationRepository relationRepo; private HsOfficeRelationBareRepository relationRepo;
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@ -142,7 +142,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
return ResponseEntity.ok(mapped); return ResponseEntity.ok(mapped);
} }
private void optionallyCreateExPartnerRelation(final HsOfficePartnerEntity saved, final HsOfficeRelationEntity previousPartnerRel) { private void optionallyCreateExPartnerRelation(final HsOfficePartnerEntity saved, final HsOfficeRelation previousPartnerRel) {
if (!saved.getPartnerRel().getUuid().equals(previousPartnerRel.getUuid())) { if (!saved.getPartnerRel().getUuid().equals(previousPartnerRel.getUuid())) {
relationRepo.save(previousPartnerRel.toBuilder().uuid(null).type(EX_PARTNER).build()); relationRepo.save(previousPartnerRel.toBuilder().uuid(null).type(EX_PARTNER).build());
} }
@ -156,8 +156,8 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
return entityToSave; return entityToSave;
} }
private HsOfficeRelationEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) { private HsOfficeRelationBareEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) {
final var entity = new HsOfficeRelationRbacEntity(); final var entity = new HsOfficeRelationBareEntity();
entity.setType(HsOfficeRelationType.PARTNER); entity.setType(HsOfficeRelationType.PARTNER);
entity.setAnchor(ref(HsOfficePersonEntity.class, resource.getAnchorUuid())); entity.setAnchor(ref(HsOfficePersonEntity.class, resource.getAnchorUuid()));
entity.setHolder(ref(HsOfficePersonEntity.class, resource.getHolderUuid())); entity.setHolder(ref(HsOfficePersonEntity.class, resource.getHolderUuid()));

View File

@ -8,8 +8,9 @@ import lombok.Setter;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContact; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContact;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
@ -47,11 +48,11 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject<HsOffice
private static Stringify<HsOfficePartnerEntity> stringify = stringify(HsOfficePartnerEntity.class, "partner") private static Stringify<HsOfficePartnerEntity> stringify = stringify(HsOfficePartnerEntity.class, "partner")
.withIdProp(HsOfficePartnerEntity::toShortString) .withIdProp(HsOfficePartnerEntity::toShortString)
.withProp(p -> ofNullable(p.getPartnerRel()) .withProp(p -> ofNullable(p.getPartnerRel())
.map(HsOfficeRelationEntity::getHolder) .map(HsOfficeRelation::getHolder)
.map(HsOfficePersonEntity::toShortString) .map(HsOfficePersonEntity::toShortString)
.orElse(null)) .orElse(null))
.withProp(p -> ofNullable(p.getPartnerRel()) .withProp(p -> ofNullable(p.getPartnerRel())
.map(HsOfficeRelationEntity::getContact) .map(HsOfficeRelation::getContact)
.map(HsOfficeContact::toShortString) .map(HsOfficeContact::toShortString)
.orElse(null)) .orElse(null))
.quotedValues(false); .quotedValues(false);
@ -68,7 +69,7 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject<HsOffice
@ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = false, fetch = FetchType.LAZY) @ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "partnerreluuid", nullable = false) @JoinColumn(name = "partnerreluuid", nullable = false)
private HsOfficeRelationEntity partnerRel; private HsOfficeRelationBareEntity partnerRel;
@ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = true, fetch = FetchType.LAZY) @ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = true, fetch = FetchType.LAZY)
@JoinColumn(name = "detailsuuid") @JoinColumn(name = "detailsuuid")
@ -103,7 +104,7 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject<HsOffice
.withUpdatableColumns("partnerRelUuid") .withUpdatableColumns("partnerRelUuid")
.toRole("global", ADMIN).grantPermission(INSERT) .toRole("global", ADMIN).grantPermission(INSERT)
.importRootEntityAliasProxy("partnerRel", HsOfficeRelationEntity.class, .importRootEntityAliasProxy("partnerRel", HsOfficeRelation.class,
usingDefaultCase(), usingDefaultCase(),
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
dependsOnColumn("partnerRelUuid")) dependsOnColumn("partnerRelUuid"))

View File

@ -1,7 +1,7 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.EntityPatcher;
import net.hostsharing.hsadminng.mapper.OptionalFromJson; import net.hostsharing.hsadminng.mapper.OptionalFromJson;
@ -21,7 +21,7 @@ class HsOfficePartnerEntityPatcher implements EntityPatcher<HsOfficePartnerPatch
public void apply(final HsOfficePartnerPatchResource resource) { public void apply(final HsOfficePartnerPatchResource resource) {
OptionalFromJson.of(resource.getPartnerRelUuid()).ifPresent(newValue -> { OptionalFromJson.of(resource.getPartnerRelUuid()).ifPresent(newValue -> {
verifyNotNull(newValue, "partnerRel"); verifyNotNull(newValue, "partnerRel");
entity.setPartnerRel(em.getReference(HsOfficeRelationEntity.class, newValue)); entity.setPartnerRel(em.getReference(HsOfficeRelationBareEntity.class, newValue));
}); });
new HsOfficePartnerDetailsEntityPatcher(em, entity.getDetails()).apply(resource.getDetails()); new HsOfficePartnerDetailsEntityPatcher(em, entity.getDetails()).apply(resource.getDetails());

View File

@ -15,7 +15,7 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
@Query(""" @Query("""
SELECT partner FROM HsOfficePartnerEntity partner SELECT partner FROM HsOfficePartnerEntity partner
JOIN HsOfficeRelationEntity rel ON rel.uuid = partner.partnerRel.uuid JOIN HsOfficeRelationBareEntity rel ON rel.uuid = partner.partnerRel.uuid
JOIN HsOfficeContactBareEntity contact ON contact.uuid = rel.contact.uuid JOIN HsOfficeContactBareEntity contact ON contact.uuid = rel.contact.uuid
JOIN HsOfficePersonEntity person ON person.uuid = rel.holder.uuid JOIN HsOfficePersonEntity person ON person.uuid = rel.holder.uuid
WHERE :name is null WHERE :name is null

View File

@ -0,0 +1,83 @@
package net.hostsharing.hsadminng.hs.office.relation;
import lombok.*;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable;
import jakarta.persistence.*;
import jakarta.persistence.Column;
import java.util.UUID;
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@MappedSuperclass
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Setter
@SuperBuilder(toBuilder = true)
@FieldNameConstants
public class HsOfficeRelation implements RbacObject<HsOfficeRelation>, Stringifyable {
private static Stringify<HsOfficeRelation> toString = stringify(HsOfficeRelation.class, "rel")
.withProp(Fields.anchor, HsOfficeRelation::getAnchor)
.withProp(Fields.type, HsOfficeRelation::getType)
.withProp(Fields.mark, HsOfficeRelation::getMark)
.withProp(Fields.holder, HsOfficeRelation::getHolder)
.withProp(Fields.contact, HsOfficeRelation::getContact);
private static Stringify<HsOfficeRelation> toShortString = stringify(HsOfficeRelation.class, "rel")
.withProp(Fields.anchor, HsOfficeRelation::getAnchor)
.withProp(Fields.type, HsOfficeRelation::getType)
.withProp(Fields.holder, HsOfficeRelation::getHolder);
@Id
@GeneratedValue
private UUID uuid;
@Version
private int version;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "anchoruuid")
private HsOfficePersonEntity anchor;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "holderuuid")
private HsOfficePersonEntity holder;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "contactuuid")
private HsOfficeContactBareEntity contact;
@Column(name = "type")
@Enumerated(EnumType.STRING)
private HsOfficeRelationType type;
@Column(name = "mark")
private String mark;
@Override
public HsOfficeRelation load() {
RbacObject.super.load();
anchor.load();
holder.load();
contact.load();
return this;
}
@Override
public String toString() {
return toString.apply(this);
}
@Override
public String toShortString() {
return toShortString.apply(this);
}
}

View File

@ -11,14 +11,9 @@ import jakarta.persistence.Table;
@Entity @Entity
@Table(name = "hs_office_relation") @Table(name = "hs_office_relation")
@SuperBuilder
@NoArgsConstructor @NoArgsConstructor
@Getter @Getter
@Setter @Setter
public class HsOfficeRelationBareEntity extends HsOfficeRelationEntity { @SuperBuilder(toBuilder = true)
public class HsOfficeRelationBareEntity extends HsOfficeRelation {
@Override
public HsOfficeRelationEntityBuilder<?, ?> toBuilder() {
return null; // FIXME: also the ugly generics, if possible
}
} }

View File

@ -8,11 +8,11 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public interface HsOfficeRelationRepository extends Repository<HsOfficeRelationEntity, UUID> { public interface HsOfficeRelationBareRepository extends Repository<HsOfficeRelationBareEntity, UUID> {
Optional<HsOfficeRelationEntity> findByUuid(UUID id); Optional<HsOfficeRelationBareEntity> findByUuid(UUID id);
default List<HsOfficeRelationEntity> findRelationRelatedToPersonUuidAndRelationType(@NotNull UUID personUuid, HsOfficeRelationType relationType) { default List<HsOfficeRelationBareEntity> findRelationRelatedToPersonUuidAndRelationType(@NotNull UUID personUuid, HsOfficeRelationType relationType) {
return findRelationRelatedToPersonUuidAndRelationTypeString(personUuid, relationType.toString()); return findRelationRelatedToPersonUuidAndRelationTypeString(personUuid, relationType.toString());
} }
@ -20,16 +20,16 @@ public interface HsOfficeRelationRepository extends Repository<HsOfficeRelationE
SELECT p.* FROM hs_office_relation_rv AS p SELECT p.* FROM hs_office_relation_rv AS p
WHERE p.anchorUuid = :personUuid OR p.holderUuid = :personUuid WHERE p.anchorUuid = :personUuid OR p.holderUuid = :personUuid
""", nativeQuery = true) """, nativeQuery = true)
List<HsOfficeRelationEntity> findRelationRelatedToPersonUuid(@NotNull UUID personUuid); List<HsOfficeRelationBareEntity> findRelationRelatedToPersonUuid(@NotNull UUID personUuid);
@Query(value = """ @Query(value = """
SELECT p.* FROM hs_office_relation_rv AS p SELECT p.* FROM hs_office_relation_rv AS p
WHERE (:relationType IS NULL OR p.type = cast(:relationType AS HsOfficeRelationType)) WHERE (:relationType IS NULL OR p.type = cast(:relationType AS HsOfficeRelationType))
AND ( p.anchorUuid = :personUuid OR p.holderUuid = :personUuid) AND ( p.anchorUuid = :personUuid OR p.holderUuid = :personUuid)
""", nativeQuery = true) """, nativeQuery = true)
List<HsOfficeRelationEntity> findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); List<HsOfficeRelationBareEntity> findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType);
HsOfficeRelationEntity save(final HsOfficeRelationEntity entity); HsOfficeRelationBareEntity save(final HsOfficeRelation entity);
long count(); long count();

View File

@ -31,7 +31,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
private Mapper mapper; private Mapper mapper;
@Autowired @Autowired
private HsOfficeRelationRepository relationRepo; private HsOfficeRelationRbacRepository relationRbacRepo;
@Autowired @Autowired
private HsOfficePersonRepository holderRepo; private HsOfficePersonRepository holderRepo;
@ -51,7 +51,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
final HsOfficeRelationTypeResource relationType) { final HsOfficeRelationTypeResource relationType) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var entities = relationRepo.findRelationRelatedToPersonUuidAndRelationType(personUuid, final var entities = relationRbacRepo.findRelationRelatedToPersonUuidAndRelationType(personUuid,
mapper.map(relationType, HsOfficeRelationType.class)); mapper.map(relationType, HsOfficeRelationType.class));
final var resources = mapper.mapList(entities, HsOfficeRelationResource.class, final var resources = mapper.mapList(entities, HsOfficeRelationResource.class,
@ -81,7 +81,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
() -> new NoSuchElementException("cannot find contactUuid " + body.getContactUuid()) () -> new NoSuchElementException("cannot find contactUuid " + body.getContactUuid())
)); ));
final var saved = relationRepo.save(entityToSave); final var saved = relationRbacRepo.save(entityToSave);
final var uri = final var uri =
MvcUriComponentsBuilder.fromController(getClass()) MvcUriComponentsBuilder.fromController(getClass())
@ -102,7 +102,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var result = relationRepo.findByUuid(relationUuid); final var result = relationRbacRepo.findByUuid(relationUuid);
if (result.isEmpty()) { if (result.isEmpty()) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
@ -117,7 +117,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
final UUID relationUuid) { final UUID relationUuid) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var result = relationRepo.deleteByUuid(relationUuid); final var result = relationRbacRepo.deleteByUuid(relationUuid);
if (result == 0) { if (result == 0) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
@ -135,17 +135,17 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var current = relationRepo.findByUuid(relationUuid).orElseThrow(); final var current = relationRbacRepo.findByUuid(relationUuid).orElseThrow();
new HsOfficeRelationEntityPatcher(em, current).apply(body); new HsOfficeRelationEntityPatcher(em, current).apply(body);
final var saved = relationRepo.save(current); final var saved = relationRbacRepo.save(current);
final var mapped = mapper.map(saved, HsOfficeRelationResource.class); final var mapped = mapper.map(saved, HsOfficeRelationResource.class);
return ResponseEntity.ok(mapped); return ResponseEntity.ok(mapped);
} }
final BiConsumer<HsOfficeRelationEntity, HsOfficeRelationResource> RELATION_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { final BiConsumer<HsOfficeRelationRbacEntity, HsOfficeRelationResource> RELATION_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> {
resource.setAnchor(mapper.map(entity.getAnchor(), HsOfficePersonResource.class)); resource.setAnchor(mapper.map(entity.getAnchor(), HsOfficePersonResource.class));
resource.setHolder(mapper.map(entity.getHolder(), HsOfficePersonResource.class)); resource.setHolder(mapper.map(entity.getHolder(), HsOfficePersonResource.class));
resource.setContact(mapper.map(entity.getContact(), HsOfficeContactResource.class)); resource.setContact(mapper.map(entity.getContact(), HsOfficeContactResource.class));

View File

@ -1,179 +0,0 @@
package net.hostsharing.hsadminng.hs.office.relation;
import lombok.*;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable;
import jakarta.persistence.*;
import jakarta.persistence.Column;
import java.io.IOException;
import java.util.UUID;
import static jakarta.persistence.InheritanceType.TABLE_PER_CLASS;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inOtherCases;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingDefaultCase;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Nullable.NOT_NULL;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.*;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetchedByDependsOnColumn;
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@Entity
@Inheritance(strategy = TABLE_PER_CLASS)
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public abstract class HsOfficeRelationEntity implements RbacObject<HsOfficeRelationEntity>, Stringifyable {
private static Stringify<HsOfficeRelationEntity> toString = stringify(HsOfficeRelationEntity.class, "rel")
.withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor)
.withProp(Fields.type, HsOfficeRelationEntity::getType)
.withProp(Fields.mark, HsOfficeRelationEntity::getMark)
.withProp(Fields.holder, HsOfficeRelationEntity::getHolder)
.withProp(Fields.contact, HsOfficeRelationEntity::getContact);
private static Stringify<HsOfficeRelationEntity> toShortString = stringify(HsOfficeRelationEntity.class, "rel")
.withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor)
.withProp(Fields.type, HsOfficeRelationEntity::getType)
.withProp(Fields.holder, HsOfficeRelationEntity::getHolder);
@Id
@GeneratedValue
private UUID uuid;
@Version
private int version;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "anchoruuid")
private HsOfficePersonEntity anchor;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "holderuuid")
private HsOfficePersonEntity holder;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "contactuuid")
private HsOfficeContactBareEntity contact;
@Column(name = "type")
@Enumerated(EnumType.STRING)
private HsOfficeRelationType type;
@Column(name = "mark")
private String mark;
@Override
public HsOfficeRelationEntity load() {
RbacObject.super.load();
anchor.load();
holder.load();
contact.load();
return this;
}
@Override
public String toString() {
return toString.apply(this);
}
@Override
public String toShortString() {
return toShortString.apply(this);
}
public abstract <T extends HsOfficeRelationEntity> HsOfficeRelationEntityBuilder<T, ?> toBuilder();
public static RbacView rbac() {
return rbacViewFor("relation", HsOfficeRelationEntity.class)
.withIdentityView(SQL.projection("""
(select idName from hs_office_person_iv p where p.uuid = anchorUuid)
|| '-with-' || target.type || '-'
|| (select idName from hs_office_person_iv p where p.uuid = holderUuid)
"""))
.withRestrictedViewOrderBy(SQL.expression(
"(select idName from hs_office_person_iv p where p.uuid = target.holderUuid)"))
.withUpdatableColumns("contactUuid")
.importEntityAlias("anchorPerson", HsOfficePersonEntity.class, usingDefaultCase(),
dependsOnColumn("anchorUuid"),
directlyFetchedByDependsOnColumn(),
NOT_NULL)
.importEntityAlias("holderPerson", HsOfficePersonEntity.class, usingDefaultCase(),
dependsOnColumn("holderUuid"),
directlyFetchedByDependsOnColumn(),
NOT_NULL)
.importEntityAlias("contact", HsOfficeContactRbacEntity.class, usingDefaultCase(),
dependsOnColumn("contactUuid"),
directlyFetchedByDependsOnColumn(),
NOT_NULL)
.switchOnColumn("type",
inCaseOf("REPRESENTATIVE", then -> {
then.createRole(OWNER, (with) -> {
with.owningUser(CREATOR);
with.incomingSuperRole(GLOBAL, ADMIN);
with.incomingSuperRole("holderPerson", ADMIN);
with.permission(DELETE);
})
.createSubRole(ADMIN, (with) -> {
with.outgoingSubRole("anchorPerson", OWNER);
with.permission(UPDATE);
})
.createSubRole(AGENT, (with) -> {
with.incomingSuperRole("anchorPerson", ADMIN);
})
.createSubRole(TENANT, (with) -> {
with.incomingSuperRole("contact", ADMIN);
with.outgoingSubRole("anchorPerson", REFERRER);
with.outgoingSubRole("holderPerson", REFERRER);
with.outgoingSubRole("contact", REFERRER);
with.permission(SELECT);
});
}),
// inCaseOf("DEBITOR", then -> {}), TODO.spec: needs to be defined
inOtherCases(then -> {
then.createRole(OWNER, (with) -> {
with.owningUser(CREATOR);
with.incomingSuperRole(GLOBAL, ADMIN);
with.incomingSuperRole("anchorPerson", ADMIN);
with.permission(DELETE);
})
.createSubRole(ADMIN, (with) -> {
with.permission(UPDATE);
})
.createSubRole(AGENT, (with) -> {
// TODO.rbac: we need relation:PROXY, to allow changing the relation contact.
// the alternative would be to move this to the relation:ADMIN role,
// but then the partner holder person could update the partner relation itself,
// see partner entity.
with.incomingSuperRole("holderPerson", ADMIN);
})
.createSubRole(TENANT, (with) -> {
with.incomingSuperRole("contact", ADMIN);
with.outgoingSubRole("anchorPerson", REFERRER);
with.outgoingSubRole("holderPerson", REFERRER);
with.outgoingSubRole("contact", REFERRER);
with.permission(SELECT);
});
}))
.toRole("anchorPerson", ADMIN).grantPermission(INSERT);
}
public static void main(String[] args) throws IOException {
rbac().generateWithBaseFileName("5-hs-office/503-relation/5033-hs-office-relation-rbac");
}
}

View File

@ -11,9 +11,9 @@ import java.util.UUID;
class HsOfficeRelationEntityPatcher implements EntityPatcher<HsOfficeRelationPatchResource> { class HsOfficeRelationEntityPatcher implements EntityPatcher<HsOfficeRelationPatchResource> {
private final EntityManager em; private final EntityManager em;
private final HsOfficeRelationEntity entity; private final HsOfficeRelation entity;
HsOfficeRelationEntityPatcher(final EntityManager em, final HsOfficeRelationEntity entity) { HsOfficeRelationEntityPatcher(final EntityManager em, final HsOfficeRelation entity) {
this.em = em; this.em = em;
this.entity = entity; this.entity = entity;
} }

View File

@ -34,16 +34,11 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
@Entity @Entity
@Table(name = "hs_office_relation_rv") @Table(name = "hs_office_relation_rv")
@SuperBuilder
@NoArgsConstructor @NoArgsConstructor
@Getter @Getter
@Setter @Setter
public class HsOfficeRelationRbacEntity extends HsOfficeRelationEntity { @SuperBuilder(toBuilder = true)
public class HsOfficeRelationRbacEntity extends HsOfficeRelation {
@Override
public HsOfficeRelationRbacEntityBuilder<HsOfficeRelationRbacEntity, ?> toBuilder() {
return null;
}
public static RbacView rbac() { public static RbacView rbac() {
return rbacViewFor("relation", HsOfficeRelationRbacEntity.class) return rbacViewFor("relation", HsOfficeRelationRbacEntity.class)

View File

@ -0,0 +1,37 @@
package net.hostsharing.hsadminng.hs.office.relation;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface HsOfficeRelationRbacRepository extends Repository<HsOfficeRelationRbacEntity, UUID> {
Optional<HsOfficeRelationRbacEntity> findByUuid(UUID id);
default List<HsOfficeRelationRbacEntity> findRelationRelatedToPersonUuidAndRelationType(@NotNull UUID personUuid, HsOfficeRelationType relationType) {
return findRelationRelatedToPersonUuidAndRelationTypeString(personUuid, relationType.toString());
}
@Query(value = """
SELECT p.* FROM hs_office_relation_rv AS p
WHERE p.anchorUuid = :personUuid OR p.holderUuid = :personUuid
""", nativeQuery = true)
List<HsOfficeRelationRbacEntity> findRelationRelatedToPersonUuid(@NotNull UUID personUuid);
@Query(value = """
SELECT p.* FROM hs_office_relation_rv AS p
WHERE (:relationType IS NULL OR p.type = cast(:relationType AS HsOfficeRelationType))
AND ( p.anchorUuid = :personUuid OR p.holderUuid = :personUuid)
""", nativeQuery = true)
List<HsOfficeRelationRbacEntity> findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType);
HsOfficeRelationRbacEntity save(final HsOfficeRelationRbacEntity entity);
long count();
int deleteByUuid(UUID uuid);
}

View File

@ -6,7 +6,7 @@ import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
@ -110,7 +110,7 @@ public class HsOfficeSepaMandateEntity implements Stringifyable, RbacObject<HsOf
.withRestrictedViewOrderBy(expression("validity")) .withRestrictedViewOrderBy(expression("validity"))
.withUpdatableColumns("reference", "agreement", "validity") .withUpdatableColumns("reference", "agreement", "validity")
.importEntityAlias("debitorRel", HsOfficeRelationEntity.class, usingCase(DEBITOR), .importEntityAlias("debitorRel", HsOfficeRelation.class, usingCase(DEBITOR),
dependsOnColumn("debitorUuid"), dependsOnColumn("debitorUuid"),
fetchedBySql(""" fetchedBySql("""
SELECT ${columns} SELECT ${columns}

View File

@ -14,7 +14,7 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerDetailsEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity; import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity;
@ -127,7 +127,7 @@ public class ImportOfficeData extends CsvDataImport {
static Map<Integer, HsOfficeDebitorEntity> debitors = new WriteOnceMap<>(); static Map<Integer, HsOfficeDebitorEntity> debitors = new WriteOnceMap<>();
static Map<Integer, HsOfficeMembershipEntity> memberships = new WriteOnceMap<>(); static Map<Integer, HsOfficeMembershipEntity> memberships = new WriteOnceMap<>();
static Map<Integer, HsOfficeRelationEntity> relations = new WriteOnceMap<>(); static Map<Integer, HsOfficeRelation> relations = new WriteOnceMap<>();
static Map<Integer, HsOfficeSepaMandateEntity> sepaMandates = new WriteOnceMap<>(); static Map<Integer, HsOfficeSepaMandateEntity> sepaMandates = new WriteOnceMap<>();
static Map<Integer, HsOfficeBankAccountEntity> bankAccounts = new WriteOnceMap<>(); static Map<Integer, HsOfficeBankAccountEntity> bankAccounts = new WriteOnceMap<>();
static Map<Integer, HsOfficeCoopSharesTransactionEntity> coopShares = new WriteOnceMap<>(); static Map<Integer, HsOfficeCoopSharesTransactionEntity> coopShares = new WriteOnceMap<>();
@ -1053,7 +1053,7 @@ public class ImportOfficeData extends CsvDataImport {
return containsRole(rec, "partner"); return containsRole(rec, "partner");
} }
private static HsOfficeRelationEntity addRelation( private static HsOfficeRelationBareEntity addRelation(
final HsOfficeRelationType type, final HsOfficeRelationType type,
final HsOfficePersonEntity anchor, final HsOfficePersonEntity anchor,
final HsOfficePersonEntity holder, final HsOfficePersonEntity holder,

View File

@ -8,8 +8,9 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
import org.json.JSONException; import org.json.JSONException;
@ -64,7 +65,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@Autowired @Autowired
HsOfficeRelationRepository relRepo; HsOfficeRelationBareRepository relRepo;
@Autowired @Autowired
JpaAttempt jpaAttempt; JpaAttempt jpaAttempt;
@ -726,7 +727,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
.debitorNumberSuffix(nextDebitorSuffix()) .debitorNumberSuffix(nextDebitorSuffix())
.billable(true) .billable(true)
.debitorRel( .debitorRel(
HsOfficeRelationRbacEntity.builder() HsOfficeRelationBareEntity.builder()
.type(DEBITOR) .type(DEBITOR)
.anchor(givenPartner.getPartnerRel().getHolder()) .anchor(givenPartner.getPartnerRel().getHolder())
.holder(givenPartner.getPartnerRel().getHolder()) .holder(givenPartner.getPartnerRel().getHolder())

View File

@ -2,8 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance;
@ -22,10 +21,7 @@ import static org.mockito.Mockito.lenient;
@TestInstance(PER_CLASS) @TestInstance(PER_CLASS)
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<HsOfficeDebitorPatchResource, HsOfficeDebitorEntity> {
HsOfficeDebitorPatchResource,
HsOfficeDebitorEntity
> {
private static final UUID INITIAL_DEBITOR_UUID = UUID.randomUUID(); private static final UUID INITIAL_DEBITOR_UUID = UUID.randomUUID();
private static final UUID INITIAL_DEBITOR_REL_UUID = UUID.randomUUID(); private static final UUID INITIAL_DEBITOR_REL_UUID = UUID.randomUUID();
@ -45,20 +41,21 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID();
private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID();
private final HsOfficeRelationEntity givenInitialDebitorRel = HsOfficeRelationRbacEntity.builder() private final HsOfficeRelationBareEntity givenInitialDebitorRel = HsOfficeRelationBareEntity.builder()
.uuid(INITIAL_DEBITOR_REL_UUID) .uuid(INITIAL_DEBITOR_REL_UUID)
.build(); .build();
private final HsOfficeBankAccountEntity givenInitialBankAccount = HsOfficeBankAccountEntity.builder() private final HsOfficeBankAccountEntity givenInitialBankAccount = HsOfficeBankAccountEntity.builder()
.uuid(INITIAL_REFUND_BANK_ACCOUNT_UUID) .uuid(INITIAL_REFUND_BANK_ACCOUNT_UUID)
.build(); .build();
@Mock @Mock
private EntityManager em; private EntityManager em;
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeRelationBareEntity.class), any())).thenAnswer(invocation ->
HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeRelationBareEntity.builder().uuid(invocation.getArgument(1)).build());
lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation ->
HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build());
} }
@ -142,8 +139,8 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
); );
} }
private HsOfficeRelationEntity newDebitorRel(final UUID uuid) { private HsOfficeRelationBareEntity newDebitorRel(final UUID uuid) {
return HsOfficeRelationRbacEntity.builder() return HsOfficeRelationBareEntity.builder()
.uuid(uuid) .uuid(uuid)
.build(); .build();
} }

View File

@ -4,15 +4,14 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class HsOfficeDebitorEntityUnitTest { class HsOfficeDebitorEntityUnitTest {
private HsOfficeRelationEntity givenDebitorRel = HsOfficeRelationRbacEntity.builder() private HsOfficeRelationBareEntity givenDebitorRel = HsOfficeRelationBareEntity.builder()
.anchor(HsOfficePersonEntity.builder() .anchor(HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("some partner trade name") .tradeName("some partner trade name")

View File

@ -5,8 +5,9 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
@ -92,7 +93,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.partner(givenPartner) .partner(givenPartner)
.debitorNumberSuffix("21") .debitorNumberSuffix("21")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationBareEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
@ -125,7 +126,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix("21") .debitorNumberSuffix("21")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationBareEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
@ -160,7 +161,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("fourth contact")); final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("fourth contact"));
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix("22") .debitorNumberSuffix("22")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationBareEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenDebitorPerson) .holder(givenDebitorPerson)
@ -332,7 +333,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
givenDebitor.setDebitorRel(HsOfficeRelationRbacEntity.builder() givenDebitor.setDebitorRel(HsOfficeRelationBareEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenNewPartnerPerson) .anchor(givenNewPartnerPerson)
.holder(givenNewBillingPerson) .holder(givenNewBillingPerson)
@ -489,7 +490,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
if (withPartner) { if (withPartner) {
assertThat(foundEntity.getPartner()).isNotNull(); assertThat(foundEntity.getPartner()).isNotNull();
} }
assertThat(foundEntity.getDebitorRel()).extracting(HsOfficeRelationEntity::toString) assertThat(foundEntity.getDebitorRel()).extracting(HsOfficeRelation::toString)
.isEqualTo(saved.getDebitorRel().toString()); .isEqualTo(saved.getDebitorRel().toString());
}); });
} }
@ -617,7 +618,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var newDebitor = HsOfficeDebitorEntity.builder() final var newDebitor = HsOfficeDebitorEntity.builder()
.partner(givenPartner) .partner(givenPartner)
.debitorNumberSuffix("20") .debitorNumberSuffix("20")
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationBareEntity.builder()
.type(HsOfficeRelationType.DEBITOR) .type(HsOfficeRelationType.DEBITOR)
.anchor(givenPartnerPerson) .anchor(givenPartnerPerson)
.holder(givenPartnerPerson) .holder(givenPartnerPerson)

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareTestEntity.TEST_BARE_CONTACT; import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareTestEntity.TEST_BARE_CONTACT;
import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER; import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER;
@ -14,7 +14,7 @@ public class TestHsOfficeDebitor {
public static final HsOfficeDebitorEntity TEST_DEBITOR = HsOfficeDebitorEntity.builder() public static final HsOfficeDebitorEntity TEST_DEBITOR = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX) .debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX)
.debitorRel(HsOfficeRelationRbacEntity.builder() .debitorRel(HsOfficeRelationBareEntity.builder()
.holder(HsOfficePersonEntity.builder().build()) .holder(HsOfficePersonEntity.builder().build())
.anchor(HsOfficePersonEntity.builder().build()) .anchor(HsOfficePersonEntity.builder().build())
.contact(TEST_BARE_CONTACT) .contact(TEST_BARE_CONTACT)

View File

@ -3,13 +3,13 @@ package net.hostsharing.hsadminng.hs.office.partner;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
@ -42,7 +42,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@Autowired @Autowired
HsOfficeRelationRepository relationRepo; HsOfficeRelationBareRepository relationRepo;
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -180,7 +180,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.post("http://localhost/api/hs/office/partners") .post("http://localhost/api/hs/office/partners")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(400) .statusCode(400)
.body("message", is("Unable to find " + HsOfficeContactRbacEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID)); .body("message", is("Unable to find " + HsOfficeContactBareEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
// @formatter:on // @formatter:on
} }
@ -406,7 +406,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
// and an ex-partner-relation got created // and an ex-partner-relation got created
final var anchorpartnerPersonUUid = givenPartner.getPartnerRel().getAnchor().getUuid(); final var anchorpartnerPersonUUid = givenPartner.getPartnerRel().getAnchor().getUuid();
assertThat(relationRepo.findRelationRelatedToPersonUuidAndRelationType(anchorpartnerPersonUUid, EX_PARTNER)) assertThat(relationRepo.findRelationRelatedToPersonUuidAndRelationType(anchorpartnerPersonUUid, EX_PARTNER))
.map(HsOfficeRelationEntity::toShortString) .map(HsOfficeRelation::toShortString)
.contains("rel(anchor='LP Hostsharing eG', type='EX_PARTNER', holder='UF Erben Bessler')"); .contains("rel(anchor='LP Hostsharing eG', type='EX_PARTNER', holder='UF Erben Bessler')");
} }
@ -517,7 +517,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
} }
} }
private HsOfficeRelationEntity givenSomeTemporaryPartnerRel( private HsOfficeRelationBareEntity givenSomeTemporaryPartnerRel(
final String partnerHolderName, final String partnerHolderName,
final String contactName) { final String contactName) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
@ -526,7 +526,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow(); final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow();
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow(); final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow();
final var partnerRel = new HsOfficeRelationRbacEntity(); final var partnerRel = new HsOfficeRelationBareEntity();
partnerRel.setType(HsOfficeRelationType.PARTNER); partnerRel.setType(HsOfficeRelationType.PARTNER);
partnerRel.setAnchor(givenMandantPerson); partnerRel.setAnchor(givenMandantPerson);
partnerRel.setHolder(givenPerson); partnerRel.setHolder(givenPerson);
@ -558,6 +558,6 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
cleanupAllNew(HsOfficePartnerEntity.class); cleanupAllNew(HsOfficePartnerEntity.class);
// TODO: should not be necessary anymore, once it's deleted via after delete trigger // TODO: should not be necessary anymore, once it's deleted via after delete trigger
cleanupAllNew(HsOfficeRelationEntity.class); cleanupAllNew(HsOfficeRelationBareEntity.class);
} }
} }

View File

@ -3,8 +3,8 @@ package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository;
import net.hostsharing.hsadminng.mapper.Mapper; import net.hostsharing.hsadminng.mapper.Mapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
@ -54,7 +54,7 @@ class HsOfficePartnerControllerRestTest {
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@MockBean @MockBean
HsOfficeRelationRepository relationRepo; HsOfficeRelationBareRepository relationRepo;
@MockBean @MockBean
EntityManager em; EntityManager em;
@ -176,7 +176,7 @@ class HsOfficePartnerControllerRestTest {
when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0); when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0);
final UUID givenRelationUuid = UUID.randomUUID(); final UUID givenRelationUuid = UUID.randomUUID();
when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationRbacEntity.builder() when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationBareEntity.builder()
.uuid(givenRelationUuid) .uuid(givenRelationUuid)
.build()); .build());
when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0); when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0);

View File

@ -3,8 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance;
@ -49,8 +48,8 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeRelationBareEntity.class), any())).thenAnswer(invocation ->
HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeRelationBareEntity.builder().uuid(invocation.getArgument(1)).build());
} }
@Override @Override
@ -58,7 +57,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
final var entity = HsOfficePartnerEntity.builder() final var entity = HsOfficePartnerEntity.builder()
.uuid(INITIAL_PARTNER_UUID) .uuid(INITIAL_PARTNER_UUID)
.partnerNumber(12345) .partnerNumber(12345)
.partnerRel(HsOfficeRelationRbacEntity.builder() .partnerRel(HsOfficeRelationBareEntity.builder()
.holder(givenInitialPerson) .holder(givenInitialPerson)
.contact(givenInitialContact) .contact(givenInitialContact)
.build()) .build())
@ -90,10 +89,9 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
); );
} }
private static HsOfficeRelationEntity newPartnerRel(final UUID uuid) { private static HsOfficeRelationBareEntity newPartnerRel(final UUID uuid) {
final var newPartnerRel = HsOfficeRelationRbacEntity.builder() return HsOfficeRelationBareEntity.builder()
.uuid(uuid) .uuid(uuid)
.build(); .build();
return newPartnerRel;
} }
} }

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -13,7 +13,7 @@ class HsOfficePartnerEntityUnitTest {
private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder() private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder()
.partnerNumber(12345) .partnerNumber(12345)
.partnerRel(HsOfficeRelationRbacEntity.builder() .partnerRel(HsOfficeRelationBareEntity.builder()
.anchor(HsOfficePersonEntity.builder() .anchor(HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("Hostsharing eG") .tradeName("Hostsharing eG")

View File

@ -3,9 +3,8 @@ package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
@ -43,7 +42,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@Autowired @Autowired
HsOfficeRelationRepository relationRepo; HsOfficeRelationBareRepository relationRepo;
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -113,7 +112,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
final var newRelation = HsOfficeRelationRbacEntity.builder() final var newRelation = HsOfficeRelationBareEntity.builder()
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
.type(HsOfficeRelationType.PARTNER) .type(HsOfficeRelationType.PARTNER)
.anchor(givenMandantPerson) .anchor(givenMandantPerson)
@ -463,12 +462,12 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
private HsOfficeRelationEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) { private HsOfficeRelationBareEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) {
final var givenMandantorPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var givenMandantorPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0); final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contact).get(0); final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contact).get(0);
final var partnerRel = HsOfficeRelationRbacEntity.builder() final var partnerRel = HsOfficeRelationBareEntity.builder()
.holder(givenPartnerPerson) .holder(givenPartnerPerson)
.type(HsOfficeRelationType.PARTNER) .type(HsOfficeRelationType.PARTNER)
.anchor(givenMandantorPerson) .anchor(givenMandantorPerson)

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON; import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON;
@ -15,7 +15,7 @@ public class TestHsOfficePartner {
return HsOfficePartnerEntity.builder() return HsOfficePartnerEntity.builder()
.partnerNumber(10001) .partnerNumber(10001)
.partnerRel( .partnerRel(
HsOfficeRelationRbacEntity.builder() HsOfficeRelationBareEntity.builder()
.holder(HsOfficePersonEntity.builder() .holder(HsOfficePersonEntity.builder()
.personType(LEGAL_PERSON) .personType(LEGAL_PERSON)
.tradeName("Hostsharing eG") .tradeName("Hostsharing eG")

View File

@ -43,7 +43,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
Context contextMock; Context contextMock;
@Autowired @Autowired
HsOfficeRelationRepository relationRepo; HsOfficeRelationBareRepository relationBareRepo;
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -161,7 +161,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
.extract().header("Location"); // @formatter:on .extract().header("Location"); // @formatter:on
// finally, the new relation can be accessed under the generated UUID // finally, the new relation can be accessed under the generated UUID
final var newUserUuid = toCleanup(HsOfficeRelationEntity.class, UUID.fromString( final var newUserUuid = toCleanup(HsOfficeRelation.class, UUID.fromString(
location.substring(location.lastIndexOf('/') + 1))); location.substring(location.lastIndexOf('/') + 1)));
assertThat(newUserUuid).isNotNull(); assertThat(newUserUuid).isNotNull();
} }
@ -331,12 +331,12 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
} }
} }
private HsOfficeRelationEntity findRelation( private HsOfficeRelation findRelation(
final String anchorPersonName, final String anchorPersonName,
final String holderPersoneName) { final String holderPersoneName) {
final var anchorPersonUuid = personRepo.findPersonByOptionalNameLike(anchorPersonName).get(0).getUuid(); final var anchorPersonUuid = personRepo.findPersonByOptionalNameLike(anchorPersonName).get(0).getUuid();
final var holderPersonUuid = personRepo.findPersonByOptionalNameLike(holderPersoneName).get(0).getUuid(); final var holderPersonUuid = personRepo.findPersonByOptionalNameLike(holderPersoneName).get(0).getUuid();
final var givenRelation = relationRepo final var givenRelation = relationBareRepo
.findRelationRelatedToPersonUuid(anchorPersonUuid) .findRelationRelatedToPersonUuid(anchorPersonUuid)
.stream() .stream()
.filter(r -> r.getHolder().getUuid().equals(holderPersonUuid)) .filter(r -> r.getHolder().getUuid().equals(holderPersonUuid))
@ -379,7 +379,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
// finally, the relation is actually updated // finally, the relation is actually updated
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent().get() assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isPresent().get()
.matches(rel -> { .matches(rel -> {
assertThat(rel.getAnchor().getTradeName()).contains("Bessler"); assertThat(rel.getAnchor().getTradeName()).contains("Bessler");
assertThat(rel.getHolder().getFamilyName()).contains("Winkler"); assertThat(rel.getHolder().getFamilyName()).contains("Winkler");
@ -408,7 +408,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
.statusCode(204); // @formatter:on .statusCode(204); // @formatter:on
// then the given relation is gone // then the given relation is gone
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isEmpty(); assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isEmpty();
} }
@Test @Test
@ -427,7 +427,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
.statusCode(403); // @formatter:on .statusCode(403); // @formatter:on
// then the given relation is still there // then the given relation is still there
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty(); assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isNotEmpty();
} }
@Test @Test
@ -446,24 +446,24 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
.statusCode(404); // @formatter:on .statusCode(404); // @formatter:on
// then the given relation is still there // then the given relation is still there
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty(); assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isNotEmpty();
} }
} }
private HsOfficeRelationEntity givenSomeTemporaryRelationBessler() { private HsOfficeRelation givenSomeTemporaryRelationBessler() {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0);
final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("seventh contact").get(0); final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("seventh contact").get(0);
final var newRelation = HsOfficeRelationRbacEntity.builder() final var newRelation = HsOfficeRelationBareEntity.builder()
.type(HsOfficeRelationType.REPRESENTATIVE) .type(HsOfficeRelationType.REPRESENTATIVE)
.anchor(givenAnchorPerson) .anchor(givenAnchorPerson)
.holder(givenHolderPerson) .holder(givenHolderPerson)
.contact(givenContact) .contact(givenContact)
.build(); .build();
assertThat(toCleanup(relationRepo.save(newRelation))).isEqualTo(newRelation); assertThat(toCleanup(relationBareRepo.save(newRelation))).isEqualTo(newRelation);
return newRelation; return newRelation;
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();

View File

@ -1,7 +1,6 @@
package net.hostsharing.hsadminng.hs.office.relation; package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
@ -22,9 +21,9 @@ import static org.mockito.Mockito.lenient;
@TestInstance(PER_CLASS) @TestInstance(PER_CLASS)
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< class HsOfficeRelationPatcherUnitTest extends PatchUnitTestBase<
HsOfficeRelationPatchResource, HsOfficeRelationPatchResource,
HsOfficeRelationEntity HsOfficeRelation
> { > {
static final UUID INITIAL_RELATION_UUID = UUID.randomUUID(); static final UUID INITIAL_RELATION_UUID = UUID.randomUUID();
@ -35,8 +34,8 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeContactBareEntity.class), any())).thenAnswer(invocation ->
HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeContactBareEntity.builder().uuid(invocation.getArgument(1)).build());
} }
final HsOfficePersonEntity givenInitialAnchorPerson = HsOfficePersonEntity.builder() final HsOfficePersonEntity givenInitialAnchorPerson = HsOfficePersonEntity.builder()
@ -50,7 +49,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
.build(); .build();
@Override @Override
protected HsOfficeRelationEntity newInitialEntity() { protected HsOfficeRelation newInitialEntity() {
final var entity = new HsOfficeRelationRbacEntity(); final var entity = new HsOfficeRelationRbacEntity();
entity.setUuid(INITIAL_RELATION_UUID); entity.setUuid(INITIAL_RELATION_UUID);
entity.setType(HsOfficeRelationType.REPRESENTATIVE); entity.setType(HsOfficeRelationType.REPRESENTATIVE);
@ -66,7 +65,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
} }
@Override @Override
protected HsOfficeRelationEntityPatcher createPatcher(final HsOfficeRelationEntity relation) { protected HsOfficeRelationEntityPatcher createPatcher(final HsOfficeRelation relation) {
return new HsOfficeRelationEntityPatcher(em, relation); return new HsOfficeRelationEntityPatcher(em, relation);
} }
@ -77,7 +76,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
"contact", "contact",
HsOfficeRelationPatchResource::setContactUuid, HsOfficeRelationPatchResource::setContactUuid,
PATCHED_CONTACT_UUID, PATCHED_CONTACT_UUID,
HsOfficeRelationEntity::setContact, HsOfficeRelation::setContact,
newContact(PATCHED_CONTACT_UUID)) newContact(PATCHED_CONTACT_UUID))
.notNullable() .notNullable()
); );

View File

@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
@Autowired @Autowired
HsOfficeRelationRepository relationRepo; HsOfficeRelationRbacRepository relationRbacRepo;
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -64,7 +64,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewRelation() { public void testHostsharingAdmin_withoutAssumedRole_canCreateNewRelation() {
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var count = relationRepo.count(); final var count = relationRbacRepo.count();
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").stream() final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").stream()
.filter(p -> p.getPersonType() == UNINCORPORATED_FIRM) .filter(p -> p.getPersonType() == UNINCORPORATED_FIRM)
.findFirst().orElseThrow(); .findFirst().orElseThrow();
@ -83,16 +83,16 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
.mark("operations-announce") .mark("operations-announce")
.contact(givenContact) .contact(givenContact)
.build(); .build();
return toCleanup(relationRepo.save(newRelation)); return toCleanup(relationRbacRepo.save(newRelation));
}); });
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelationEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelation::getUuid).isNotNull();
assertThatRelationIsPersisted(result.returnedValue()); assertThatRelationIsPersisted(result.returnedValue());
assertThat(relationRepo.count()).isEqualTo(count + 1); assertThat(relationRbacRepo.count()).isEqualTo(count + 1);
final var stored = relationRepo.findByUuid(result.returnedValue().getUuid()); final var stored = relationRbacRepo.findByUuid(result.returnedValue().getUuid());
assertThat(stored).isNotEmpty().map(HsOfficeRelationEntity::toString).get() assertThat(stored).isNotEmpty().map(HsOfficeRelation::toString).get()
.isEqualTo("rel(anchor='UF Erben Bessler', type='SUBSCRIBER', mark='operations-announce', holder='NP Winkler, Paul', contact='fourth contact')"); .isEqualTo("rel(anchor='UF Erben Bessler', type='SUBSCRIBER', mark='operations-announce', holder='NP Winkler, Paul', contact='fourth contact')");
} }
@ -119,7 +119,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
.type(HsOfficeRelationType.REPRESENTATIVE) .type(HsOfficeRelationType.REPRESENTATIVE)
.contact(givenContact) .contact(givenContact)
.build(); .build();
return toCleanup(relationRepo.save(newRelation)); return toCleanup(relationRbacRepo.save(newRelation));
}); });
// then // then
@ -156,8 +156,8 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
); );
} }
private void assertThatRelationIsPersisted(final HsOfficeRelationEntity saved) { private void assertThatRelationIsPersisted(final HsOfficeRelation saved) {
final var found = relationRepo.findByUuid(saved.getUuid()); final var found = relationRbacRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString()); assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
} }
} }
@ -174,7 +174,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
.findFirst().orElseThrow(); .findFirst().orElseThrow();
// when // when
final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid()); final var result = relationRbacRepo.findRelationRelatedToPersonUuid(person.getUuid());
// then // then
allTheseRelationsAreReturned( allTheseRelationsAreReturned(
@ -193,7 +193,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
.findFirst().orElseThrow(); .findFirst().orElseThrow();
// when: // when:
final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid()); final var result = relationRbacRepo.findRelationRelatedToPersonUuid(person.getUuid());
// then: // then:
exactlyTheseRelationsAreReturned( exactlyTheseRelationsAreReturned(
@ -225,7 +225,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
givenRelation.setContact(givenContact); givenRelation.setContact(givenContact);
return toCleanup(relationRepo.save(givenRelation).load()); return toCleanup(relationRbacRepo.save(givenRelation).load());
}); });
// then // then
@ -242,7 +242,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
result.returnedValue(), result.returnedValue(),
"hs_office_contact#fifthcontact:ADMIN"); "hs_office_contact#fifthcontact:ADMIN");
relationRepo.deleteByUuid(givenRelation.getUuid()); relationRbacRepo.deleteByUuid(givenRelation.getUuid());
} }
@Test @Test
@ -260,7 +260,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerAnita:AGENT"); context("superuser-alex@hostsharing.net", "hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerAnita:AGENT");
givenRelation.setContact(null); givenRelation.setContact(null);
return relationRepo.save(givenRelation); return relationRbacRepo.save(givenRelation);
}); });
// then // then
@ -283,7 +283,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact:ADMIN"); context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact:ADMIN");
givenRelation.setContact(null); // TODO givenRelation.setContact(null); // TODO
return relationRepo.save(givenRelation); return relationRbacRepo.save(givenRelation);
}); });
// then // then
@ -291,16 +291,16 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
"[403] Subject ", " is not allowed to update hs_office_relation uuid"); "[403] Subject ", " is not allowed to update hs_office_relation uuid");
} }
private void assertThatRelationActuallyInDatabase(final HsOfficeRelationEntity saved) { private void assertThatRelationActuallyInDatabase(final HsOfficeRelation saved) {
final var found = relationRepo.findByUuid(saved.getUuid()); final var found = relationRbacRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get() assertThat(found).isNotEmpty().get()
.isNotSameAs(saved) .isNotSameAs(saved)
.extracting(HsOfficeRelationEntity::toString) .extracting(HsOfficeRelation::toString)
.isEqualTo(saved.toString()); .isEqualTo(saved.toString());
} }
private void assertThatRelationIsVisibleForUserWithRole( private void assertThatRelationIsVisibleForUserWithRole(
final HsOfficeRelationEntity entity, final HsOfficeRelation entity,
final String assumedRoles) { final String assumedRoles) {
jpaAttempt.transacted(() -> { jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", assumedRoles); context("superuser-alex@hostsharing.net", assumedRoles);
@ -309,11 +309,11 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
} }
private void assertThatRelationIsNotVisibleForUserWithRole( private void assertThatRelationIsNotVisibleForUserWithRole(
final HsOfficeRelationEntity entity, final HsOfficeRelation entity,
final String assumedRoles) { final String assumedRoles) {
jpaAttempt.transacted(() -> { jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", assumedRoles); context("superuser-alex@hostsharing.net", assumedRoles);
final var found = relationRepo.findByUuid(entity.getUuid()); final var found = relationRbacRepo.findByUuid(entity.getUuid());
assertThat(found).isEmpty(); assertThat(found).isEmpty();
}).assertSuccessful(); }).assertSuccessful();
} }
@ -332,14 +332,14 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
relationRepo.deleteByUuid(givenRelation.getUuid()); relationRbacRepo.deleteByUuid(givenRelation.getUuid());
}); });
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(jpaAttempt.transacted(() -> { assertThat(jpaAttempt.transacted(() -> {
context("superuser-fran@hostsharing.net", null); context("superuser-fran@hostsharing.net", null);
return relationRepo.findByUuid(givenRelation.getUuid()); return relationRbacRepo.findByUuid(givenRelation.getUuid());
}).assertSuccessful().returnedValue()).isEmpty(); }).assertSuccessful().returnedValue()).isEmpty();
} }
@ -353,8 +353,8 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("contact-admin@eleventhcontact.example.com"); context("contact-admin@eleventhcontact.example.com");
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent(); assertThat(relationRbacRepo.findByUuid(givenRelation.getUuid())).isPresent();
relationRepo.deleteByUuid(givenRelation.getUuid()); relationRbacRepo.deleteByUuid(givenRelation.getUuid());
}); });
// then // then
@ -363,7 +363,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
"[403] Subject ", " not allowed to delete hs_office_relation"); "[403] Subject ", " not allowed to delete hs_office_relation");
assertThat(jpaAttempt.transacted(() -> { assertThat(jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
return relationRepo.findByUuid(givenRelation.getUuid()); return relationRbacRepo.findByUuid(givenRelation.getUuid());
}).assertSuccessful().returnedValue()).isPresent(); // still there }).assertSuccessful().returnedValue()).isPresent(); // still there
} }
@ -379,7 +379,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
return relationRepo.deleteByUuid(givenRelation.getUuid()); return relationRbacRepo.deleteByUuid(givenRelation.getUuid());
}); });
// then // then
@ -408,7 +408,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
"[creating relation test-data FirstGmbH-Firby, hs_office_relation, INSERT]"); "[creating relation test-data FirstGmbH-Firby, hs_office_relation, INSERT]");
} }
private HsOfficeRelationEntity givenSomeTemporaryRelationBessler(final String holderPerson, final String contact) { private HsOfficeRelationRbacEntity givenSomeTemporaryRelationBessler(final String holderPerson, final String contact) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
@ -421,23 +421,23 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
.contact(givenContact) .contact(givenContact)
.build(); .build();
return toCleanup(relationRepo.save(newRelation)); return toCleanup(relationRbacRepo.save(newRelation));
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
void exactlyTheseRelationsAreReturned( void exactlyTheseRelationsAreReturned(
final List<HsOfficeRelationEntity> actualResult, final List<HsOfficeRelationRbacEntity> actualResult,
final String... relationNames) { final String... relationNames) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsOfficeRelationEntity::toString) .extracting(HsOfficeRelation::toString)
.containsExactlyInAnyOrder(relationNames); .containsExactlyInAnyOrder(relationNames);
} }
void allTheseRelationsAreReturned( void allTheseRelationsAreReturned(
final List<HsOfficeRelationEntity> actualResult, final List<HsOfficeRelationRbacEntity> actualResult,
final String... relationNames) { final String... relationNames) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsOfficeRelationEntity::toString) .extracting(HsOfficeRelation::toString)
.contains(relationNames); .contains(relationNames);
} }
} }

View File

@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class HsOfficeRelationEntityUnitTest { class HsOfficeRelationUnitTest {
private HsOfficePersonEntity anchor = HsOfficePersonEntity.builder() private HsOfficePersonEntity anchor = HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)