split PersonEntity/Repo into Rbac and Real Entity/Repo and use in Relation for faster lazy loading #130
@ -36,7 +36,7 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
|
|||||||
JOIN HsOfficePartnerEntity partner
|
JOIN HsOfficePartnerEntity partner
|
||||||
ON partner.partnerRel.holder = debitor.debitorRel.anchor
|
ON partner.partnerRel.holder = debitor.debitorRel.anchor
|
||||||
AND partner.partnerRel.type = 'PARTNER' AND debitor.debitorRel.type = 'DEBITOR'
|
AND partner.partnerRel.type = 'PARTNER' AND debitor.debitorRel.type = 'DEBITOR'
|
||||||
JOIN HsOfficePersonEntity person
|
JOIN HsOfficePersonRealEntity person
|
||||||
ON person.uuid = partner.partnerRel.holder.uuid
|
ON person.uuid = partner.partnerRel.holder.uuid
|
||||||
OR person.uuid = debitor.debitorRel.holder.uuid
|
OR person.uuid = debitor.debitorRel.holder.uuid
|
||||||
JOIN HsOfficeContactRealEntity contact
|
JOIN HsOfficeContactRealEntity contact
|
||||||
|
@ -9,7 +9,7 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartne
|
|||||||
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.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.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||||
@ -166,8 +166,8 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
|||||||
private HsOfficeRelationRealEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) {
|
private HsOfficeRelationRealEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) {
|
||||||
final var entity = new HsOfficeRelationRealEntity();
|
final var entity = new HsOfficeRelationRealEntity();
|
||||||
entity.setType(HsOfficeRelationType.PARTNER);
|
entity.setType(HsOfficeRelationType.PARTNER);
|
||||||
entity.setAnchor(ref(HsOfficePersonEntity.class, resource.getAnchorUuid()));
|
entity.setAnchor(ref(HsOfficePersonRealEntity.class, resource.getAnchorUuid()));
|
||||||
entity.setHolder(ref(HsOfficePersonEntity.class, resource.getHolderUuid()));
|
entity.setHolder(ref(HsOfficePersonRealEntity.class, resource.getHolderUuid()));
|
||||||
entity.setContact(ref(HsOfficeContactRealEntity.class, resource.getContactUuid()));
|
entity.setContact(ref(HsOfficeContactRealEntity.class, resource.getContactUuid()));
|
||||||
em.persist(entity);
|
em.persist(entity);
|
||||||
return entity;
|
return entity;
|
||||||
|
@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||||
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.HsOfficePerson;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
|
||||||
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
||||||
@ -51,7 +51,7 @@ public class HsOfficePartnerEntity implements Stringifyable, BaseEntity<HsOffice
|
|||||||
.withIdProp(HsOfficePartnerEntity::toShortString)
|
.withIdProp(HsOfficePartnerEntity::toShortString)
|
||||||
.withProp(p -> ofNullable(p.getPartnerRel())
|
.withProp(p -> ofNullable(p.getPartnerRel())
|
||||||
.map(HsOfficeRelation::getHolder)
|
.map(HsOfficeRelation::getHolder)
|
||||||
.map(HsOfficePersonEntity::toShortString)
|
.map(HsOfficePerson::toShortString)
|
||||||
.orElse(null))
|
.orElse(null))
|
||||||
.withProp(p -> ofNullable(p.getPartnerRel())
|
.withProp(p -> ofNullable(p.getPartnerRel())
|
||||||
.map(HsOfficeRelation::getContact)
|
.map(HsOfficeRelation::getContact)
|
||||||
|
@ -20,7 +20,7 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
|
|||||||
SELECT partner FROM HsOfficePartnerEntity partner
|
SELECT partner FROM HsOfficePartnerEntity partner
|
||||||
JOIN HsOfficeRelationRealEntity rel ON rel.uuid = partner.partnerRel.uuid
|
JOIN HsOfficeRelationRealEntity rel ON rel.uuid = partner.partnerRel.uuid
|
||||||
JOIN HsOfficeContactRealEntity contact ON contact.uuid = rel.contact.uuid
|
JOIN HsOfficeContactRealEntity contact ON contact.uuid = rel.contact.uuid
|
||||||
JOIN HsOfficePersonEntity person ON person.uuid = rel.holder.uuid
|
JOIN HsOfficePersonRealEntity person ON person.uuid = rel.holder.uuid
|
||||||
WHERE :name is null
|
WHERE :name is null
|
||||||
OR partner.details.birthName like concat(cast(:name as text), '%')
|
OR partner.details.birthName like concat(cast(:name as text), '%')
|
||||||
OR contact.caption like concat(cast(:name as text), '%')
|
OR contact.caption like concat(cast(:name as text), '%')
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.FieldNameConstants;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||||
|
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
||||||
|
import net.hostsharing.hsadminng.repr.Stringify;
|
||||||
|
import net.hostsharing.hsadminng.repr.Stringifyable;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import jakarta.persistence.Version;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static net.hostsharing.hsadminng.repr.Stringify.stringify;
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
|
@SuperBuilder(toBuilder = true)
|
||||||
|
@FieldNameConstants
|
||||||
|
@DisplayAs("Person")
|
||||||
|
public class HsOfficePerson<T extends HsOfficePerson<?> & BaseEntity<?>> implements BaseEntity<T>, Stringifyable {
|
||||||
|
|
||||||
|
private static Stringify<HsOfficePerson> toString = stringify(HsOfficePerson.class, "person")
|
||||||
|
.withProp(Fields.personType, HsOfficePerson::getPersonType)
|
||||||
|
.withProp(Fields.tradeName, HsOfficePerson::getTradeName)
|
||||||
|
.withProp(Fields.salutation, HsOfficePerson::getSalutation)
|
||||||
|
.withProp(Fields.title, HsOfficePerson::getTitle)
|
||||||
|
.withProp(Fields.familyName, HsOfficePerson::getFamilyName)
|
||||||
|
.withProp(Fields.givenName, HsOfficePerson::getGivenName);
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
@Version
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
@Column(name = "persontype")
|
||||||
|
private HsOfficePersonType personType;
|
||||||
|
|
||||||
|
@Column(name = "tradename")
|
||||||
|
private String tradeName;
|
||||||
|
|
||||||
|
@Column(name = "salutation")
|
||||||
|
private String salutation;
|
||||||
|
|
||||||
|
@Column(name = "title")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(name = "familyname")
|
||||||
|
private String familyName;
|
||||||
|
|
||||||
|
@Column(name = "givenname")
|
||||||
|
private String givenName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return toString.apply(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toShortString() {
|
||||||
|
return personType + " " +
|
||||||
|
(!StringUtils.isEmpty(tradeName) ? tradeName : (familyName + ", " + givenName));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -27,7 +27,7 @@ public class HsOfficePersonController implements HsOfficePersonsApi {
|
|||||||
private StandardMapper mapper;
|
private StandardMapper mapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HsOfficePersonRepository personRepo;
|
private HsOfficePersonRbacRepository personRepo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
@ -54,7 +54,7 @@ public class HsOfficePersonController implements HsOfficePersonsApi {
|
|||||||
|
|
||||||
context.define(currentSubject, assumedRoles);
|
context.define(currentSubject, assumedRoles);
|
||||||
|
|
||||||
final var entityToSave = mapper.map(body, HsOfficePersonEntity.class);
|
final var entityToSave = mapper.map(body, HsOfficePersonRbacEntity.class);
|
||||||
|
|
||||||
final var saved = personRepo.save(entityToSave);
|
final var saved = personRepo.save(entityToSave);
|
||||||
|
|
||||||
|
@ -1,103 +0,0 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.person;
|
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
import lombok.experimental.FieldNameConstants;
|
|
||||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
|
||||||
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
|
||||||
import net.hostsharing.hsadminng.rbac.generator.RbacView;
|
|
||||||
import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL;
|
|
||||||
import net.hostsharing.hsadminng.repr.Stringify;
|
|
||||||
import net.hostsharing.hsadminng.repr.Stringifyable;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.rbac.generator.RbacView.GLOBAL;
|
|
||||||
import static net.hostsharing.hsadminng.rbac.generator.RbacView.Permission.*;
|
|
||||||
import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectReference.UserRole.CREATOR;
|
|
||||||
import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*;
|
|
||||||
import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor;
|
|
||||||
import static net.hostsharing.hsadminng.repr.Stringify.stringify;
|
|
||||||
|
|
||||||
// TODO.refa: split HsOfficePersonEntity into Real+Rbac-Entity
|
|
||||||
@Entity
|
|
||||||
@Table(schema = "hs_office", name = "person_rv")
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@FieldNameConstants
|
|
||||||
@DisplayAs("Person")
|
|
||||||
public class HsOfficePersonEntity implements BaseEntity<HsOfficePersonEntity>, Stringifyable {
|
|
||||||
|
|
||||||
private static Stringify<HsOfficePersonEntity> toString = stringify(HsOfficePersonEntity.class, "person")
|
|
||||||
.withProp(Fields.personType, HsOfficePersonEntity::getPersonType)
|
|
||||||
.withProp(Fields.tradeName, HsOfficePersonEntity::getTradeName)
|
|
||||||
.withProp(Fields.salutation, HsOfficePersonEntity::getSalutation)
|
|
||||||
.withProp(Fields.title, HsOfficePersonEntity::getTitle)
|
|
||||||
.withProp(Fields.familyName, HsOfficePersonEntity::getFamilyName)
|
|
||||||
.withProp(Fields.givenName, HsOfficePersonEntity::getGivenName);
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private UUID uuid;
|
|
||||||
|
|
||||||
@Version
|
|
||||||
private int version;
|
|
||||||
|
|
||||||
@Column(name = "persontype")
|
|
||||||
private HsOfficePersonType personType;
|
|
||||||
|
|
||||||
@Column(name = "tradename")
|
|
||||||
private String tradeName;
|
|
||||||
|
|
||||||
@Column(name = "salutation")
|
|
||||||
private String salutation;
|
|
||||||
|
|
||||||
@Column(name = "title")
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
@Column(name = "familyname")
|
|
||||||
private String familyName;
|
|
||||||
|
|
||||||
@Column(name = "givenname")
|
|
||||||
private String givenName;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return toString.apply(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toShortString() {
|
|
||||||
return personType + " " +
|
|
||||||
(!StringUtils.isEmpty(tradeName) ? tradeName : (familyName + ", " + givenName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RbacView rbac() {
|
|
||||||
return rbacViewFor("person", HsOfficePersonEntity.class)
|
|
||||||
.withIdentityView(SQL.projection("concat(tradeName, familyName, givenName)"))
|
|
||||||
.withUpdatableColumns("personType", "title", "salutation", "tradeName", "givenName", "familyName")
|
|
||||||
.toRole(GLOBAL, GUEST).grantPermission(INSERT)
|
|
||||||
|
|
||||||
.createRole(OWNER, (with) -> {
|
|
||||||
with.permission(DELETE);
|
|
||||||
with.owningUser(CREATOR);
|
|
||||||
with.incomingSuperRole(GLOBAL, ADMIN);
|
|
||||||
})
|
|
||||||
.createSubRole(ADMIN, (with) -> {
|
|
||||||
with.permission(UPDATE);
|
|
||||||
})
|
|
||||||
.createSubRole(REFERRER, (with) -> {
|
|
||||||
with.permission(SELECT);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
rbac().generateWithBaseFileName("5-hs-office/502-person/5023-hs-office-person-rbac");
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,9 +9,9 @@ import java.util.Optional;
|
|||||||
|
|
||||||
class HsOfficePersonEntityPatcher implements EntityPatcher<HsOfficePersonPatchResource> {
|
class HsOfficePersonEntityPatcher implements EntityPatcher<HsOfficePersonPatchResource> {
|
||||||
|
|
||||||
private final HsOfficePersonEntity entity;
|
private final HsOfficePersonRbacEntity entity;
|
||||||
|
|
||||||
HsOfficePersonEntityPatcher(final HsOfficePersonEntity entity) {
|
HsOfficePersonEntityPatcher(final HsOfficePersonRbacEntity entity) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import lombok.experimental.FieldNameConstants;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||||
|
import net.hostsharing.hsadminng.rbac.generator.RbacView;
|
||||||
|
import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static net.hostsharing.hsadminng.rbac.generator.RbacView.GLOBAL;
|
||||||
|
import static net.hostsharing.hsadminng.rbac.generator.RbacView.Permission.*;
|
||||||
|
import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectReference.UserRole.CREATOR;
|
||||||
|
import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*;
|
||||||
|
import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(schema = "hs_office", name = "person_rv")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder(toBuilder = true)
|
||||||
|
@FieldNameConstants
|
||||||
|
@DisplayAs("RbacPerson")
|
||||||
|
public class HsOfficePersonRbacEntity extends HsOfficePerson<HsOfficePersonRbacEntity> {
|
||||||
|
|
||||||
|
public static RbacView rbac() {
|
||||||
|
return rbacViewFor("person", HsOfficePersonRbacEntity.class)
|
||||||
|
.withIdentityView(SQL.projection("concat(tradeName, familyName, givenName)"))
|
||||||
|
.withUpdatableColumns("personType", "title", "salutation", "tradeName", "givenName", "familyName")
|
||||||
|
.toRole(GLOBAL, GUEST).grantPermission(INSERT)
|
||||||
|
|
||||||
|
.createRole(OWNER, (with) -> {
|
||||||
|
with.permission(DELETE);
|
||||||
|
with.owningUser(CREATOR);
|
||||||
|
with.incomingSuperRole(GLOBAL, ADMIN);
|
||||||
|
})
|
||||||
|
.createSubRole(ADMIN, (with) -> {
|
||||||
|
with.permission(UPDATE);
|
||||||
|
})
|
||||||
|
.createSubRole(REFERRER, (with) -> {
|
||||||
|
with.permission(SELECT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
rbac().generateWithBaseFileName("5-hs-office/502-person/5023-hs-office-person-rbac");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
import io.micrometer.core.annotation.Timed;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface HsOfficePersonRbacRepository extends Repository<HsOfficePersonRbacEntity, UUID> {
|
||||||
|
|
||||||
|
@Timed("app.office.persons.repo.findByUuid.rbac")
|
||||||
|
Optional<HsOfficePersonRbacEntity> findByUuid(UUID personUuid);
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
SELECT p FROM HsOfficePersonRbacEntity p
|
||||||
|
WHERE :name is null
|
||||||
|
OR p.tradeName like concat(cast(:name as text), '%')
|
||||||
|
OR p.givenName like concat(cast(:name as text), '%')
|
||||||
|
OR p.familyName like concat(cast(:name as text), '%')
|
||||||
|
""")
|
||||||
|
@Timed("app.office.persons.repo.findPersonByOptionalNameLike.rbac")
|
||||||
|
List<HsOfficePersonRbacEntity> findPersonByOptionalNameLike(String name);
|
||||||
|
|
||||||
|
@Timed("app.office.persons.repo.save.rbac")
|
||||||
|
HsOfficePersonRbacEntity save(final HsOfficePersonRbacEntity entity);
|
||||||
|
|
||||||
|
@Timed("app.office.persons.repo.deleteByUuid.rbac")
|
||||||
|
int deleteByUuid(final UUID personUuid);
|
||||||
|
|
||||||
|
@Timed("app.office.persons.repo.count.rbac")
|
||||||
|
long count();
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.FieldNameConstants;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(schema = "hs_office", name = "person")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder(toBuilder = true)
|
||||||
|
@FieldNameConstants
|
||||||
|
@DisplayAs("RealPerson")
|
||||||
|
public class HsOfficePersonRealEntity extends HsOfficePerson<HsOfficePersonRealEntity> {
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
import io.micrometer.core.annotation.Timed;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface HsOfficePersonRealRepository extends Repository<HsOfficePersonRealEntity, UUID> {
|
||||||
|
|
||||||
|
@Timed("app.office.persons.repo.findByUuid.real")
|
||||||
|
Optional<HsOfficePersonRealEntity> findByUuid(UUID personUuid);
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
SELECT p FROM HsOfficePersonRealEntity p
|
||||||
|
WHERE :name is null
|
||||||
|
OR p.tradeName like concat(cast(:name as text), '%')
|
||||||
|
OR p.givenName like concat(cast(:name as text), '%')
|
||||||
|
OR p.familyName like concat(cast(:name as text), '%')
|
||||||
|
""")
|
||||||
|
@Timed("app.office.persons.repo.findPersonByOptionalNameLike.real")
|
||||||
|
List<HsOfficePersonRealEntity> findPersonByOptionalNameLike(String name);
|
||||||
|
|
||||||
|
@Timed("app.office.persons.repo.save.real")
|
||||||
|
HsOfficePersonRealEntity save(final HsOfficePersonRealEntity entity);
|
||||||
|
|
||||||
|
@Timed("app.office.persons.repo.count.real")
|
||||||
|
long count();
|
||||||
|
}
|
@ -1,34 +0,0 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.person;
|
|
||||||
|
|
||||||
import io.micrometer.core.annotation.Timed;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.data.repository.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface HsOfficePersonRepository extends Repository<HsOfficePersonEntity, UUID> {
|
|
||||||
|
|
||||||
@Timed("app.office.persons.repo.findByUuid.rbac")
|
|
||||||
Optional<HsOfficePersonEntity> findByUuid(UUID personUuid);
|
|
||||||
|
|
||||||
@Query("""
|
|
||||||
SELECT p FROM HsOfficePersonEntity p
|
|
||||||
WHERE :name is null
|
|
||||||
OR p.tradeName like concat(cast(:name as text), '%')
|
|
||||||
OR p.givenName like concat(cast(:name as text), '%')
|
|
||||||
OR p.familyName like concat(cast(:name as text), '%')
|
|
||||||
""")
|
|
||||||
@Timed("app.office.persons.repo.findPersonByOptionalNameLike.rbac")
|
|
||||||
List<HsOfficePersonEntity> findPersonByOptionalNameLike(String name);
|
|
||||||
|
|
||||||
@Timed("app.office.persons.repo.save.rbac")
|
|
||||||
HsOfficePersonEntity save(final HsOfficePersonEntity entity);
|
|
||||||
|
|
||||||
@Timed("app.office.persons.repo.deleteByUuid.rbac")
|
|
||||||
int deleteByUuid(final UUID personUuid);
|
|
||||||
|
|
||||||
@Timed("app.office.persons.repo.count.rbac")
|
|
||||||
long count();
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ import lombok.*;
|
|||||||
import lombok.experimental.FieldNameConstants;
|
import lombok.experimental.FieldNameConstants;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
||||||
import net.hostsharing.hsadminng.repr.Stringify;
|
import net.hostsharing.hsadminng.repr.Stringify;
|
||||||
import net.hostsharing.hsadminng.repr.Stringifyable;
|
import net.hostsharing.hsadminng.repr.Stringifyable;
|
||||||
@ -45,11 +45,11 @@ public class HsOfficeRelation implements BaseEntity<HsOfficeRelation>, Stringify
|
|||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "anchoruuid")
|
@JoinColumn(name = "anchoruuid")
|
||||||
private HsOfficePersonEntity anchor;
|
private HsOfficePersonRealEntity anchor;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "holderuuid")
|
@JoinColumn(name = "holderuuid")
|
||||||
private HsOfficePersonEntity holder;
|
private HsOfficePersonRealEntity holder;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "contactuuid")
|
@JoinColumn(name = "contactuuid")
|
||||||
|
@ -5,7 +5,7 @@ import net.hostsharing.hsadminng.context.Context;
|
|||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeRelationsApi;
|
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeRelationsApi;
|
||||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*;
|
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||||
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -34,7 +34,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
|
|||||||
private HsOfficeRelationRbacRepository relationRbacRepo;
|
private HsOfficeRelationRbacRepository relationRbacRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HsOfficePersonRepository holderRepo;
|
private HsOfficePersonRealRepository personRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HsOfficeContactRealRepository realContactRepo;
|
private HsOfficeContactRealRepository realContactRepo;
|
||||||
@ -78,10 +78,10 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
|
|||||||
final var entityToSave = new HsOfficeRelationRbacEntity();
|
final var entityToSave = new HsOfficeRelationRbacEntity();
|
||||||
entityToSave.setType(HsOfficeRelationType.valueOf(body.getType()));
|
entityToSave.setType(HsOfficeRelationType.valueOf(body.getType()));
|
||||||
entityToSave.setMark(body.getMark());
|
entityToSave.setMark(body.getMark());
|
||||||
entityToSave.setAnchor(holderRepo.findByUuid(body.getAnchorUuid()).orElseThrow(
|
entityToSave.setAnchor(personRepo.findByUuid(body.getAnchorUuid()).orElseThrow(
|
||||||
() -> new NoSuchElementException("cannot find Person by anchorUuid: " + body.getAnchorUuid())
|
() -> new NoSuchElementException("cannot find Person by anchorUuid: " + body.getAnchorUuid())
|
||||||
));
|
));
|
||||||
entityToSave.setHolder(holderRepo.findByUuid(body.getHolderUuid()).orElseThrow(
|
entityToSave.setHolder(personRepo.findByUuid(body.getHolderUuid()).orElseThrow(
|
||||||
() -> new NoSuchElementException("cannot find Person by holderUuid: " + body.getHolderUuid())
|
() -> new NoSuchElementException("cannot find Person by holderUuid: " + body.getHolderUuid())
|
||||||
));
|
));
|
||||||
entityToSave.setContact(realContactRepo.findByUuid(body.getContactUuid()).orElseThrow(
|
entityToSave.setContact(realContactRepo.findByUuid(body.getContactUuid()).orElseThrow(
|
||||||
|
@ -6,7 +6,7 @@ import lombok.Setter;
|
|||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||||
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.HsOfficePersonRbacEntity;
|
||||||
import net.hostsharing.hsadminng.rbac.generator.RbacView;
|
import net.hostsharing.hsadminng.rbac.generator.RbacView;
|
||||||
import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL;
|
import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL;
|
||||||
|
|
||||||
@ -52,11 +52,11 @@ public class HsOfficeRelationRbacEntity extends HsOfficeRelation {
|
|||||||
.withRestrictedViewOrderBy(SQL.expression(
|
.withRestrictedViewOrderBy(SQL.expression(
|
||||||
"(select idName from hs_office.person_iv p where p.uuid = target.holderUuid)"))
|
"(select idName from hs_office.person_iv p where p.uuid = target.holderUuid)"))
|
||||||
.withUpdatableColumns("contactUuid")
|
.withUpdatableColumns("contactUuid")
|
||||||
.importEntityAlias("anchorPerson", HsOfficePersonEntity.class, usingDefaultCase(),
|
.importEntityAlias("anchorPerson", HsOfficePersonRbacEntity.class, usingDefaultCase(),
|
||||||
dependsOnColumn("anchorUuid"),
|
dependsOnColumn("anchorUuid"),
|
||||||
directlyFetchedByDependsOnColumn(),
|
directlyFetchedByDependsOnColumn(),
|
||||||
NOT_NULL)
|
NOT_NULL)
|
||||||
.importEntityAlias("holderPerson", HsOfficePersonEntity.class, usingDefaultCase(),
|
.importEntityAlias("holderPerson", HsOfficePersonRbacEntity.class, usingDefaultCase(),
|
||||||
dependsOnColumn("holderUuid"),
|
dependsOnColumn("holderUuid"),
|
||||||
directlyFetchedByDependsOnColumn(),
|
directlyFetchedByDependsOnColumn(),
|
||||||
NOT_NULL)
|
NOT_NULL)
|
||||||
|
@ -11,7 +11,7 @@ import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
|||||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipStatus;
|
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipStatus;
|
||||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerDetailsEntity;
|
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.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
@ -81,7 +81,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static Map<Integer, HsOfficeContactRealEntity> contacts = new WriteOnceMap<>();
|
static Map<Integer, HsOfficeContactRealEntity> contacts = new WriteOnceMap<>();
|
||||||
static Map<Integer, HsOfficePersonEntity> persons = new WriteOnceMap<>();
|
static Map<Integer, HsOfficePersonRealEntity> persons = new WriteOnceMap<>();
|
||||||
static Map<Integer, HsOfficePartnerEntity> partners = new WriteOnceMap<>();
|
static Map<Integer, HsOfficePartnerEntity> partners = new WriteOnceMap<>();
|
||||||
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<>();
|
||||||
@ -731,7 +731,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final var person = HsOfficePersonEntity.builder().build();
|
final var person = HsOfficePersonRealEntity.builder().build();
|
||||||
|
|
||||||
final var partnerRel = addRelation(
|
final var partnerRel = addRelation(
|
||||||
HsOfficeRelationType.PARTNER,
|
HsOfficeRelationType.PARTNER,
|
||||||
@ -880,6 +880,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
coopAssets.entrySet().forEach(entry -> {
|
coopAssets.entrySet().forEach(entry -> {
|
||||||
final var legacyId = entry.getKey();
|
final var legacyId = entry.getKey();
|
||||||
final var assetTransaction = entry.getValue();
|
final var assetTransaction = entry.getValue();
|
||||||
@ -995,14 +996,14 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
addPerson(partnerPerson, rec);
|
addPerson(partnerPerson, rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
HsOfficePersonEntity contactPerson = partnerPerson;
|
HsOfficePersonRealEntity contactPerson = partnerPerson;
|
||||||
if (!StringUtils.equals(rec.getString("firma"), partnerPerson.getTradeName()) ||
|
if (!StringUtils.equals(rec.getString("firma"), partnerPerson.getTradeName()) ||
|
||||||
partnerPerson.getPersonType() != determinePersonType(rec) ||
|
partnerPerson.getPersonType() != determinePersonType(rec) ||
|
||||||
!StringUtils.equals(rec.getString("title"), partnerPerson.getTitle()) ||
|
!StringUtils.equals(rec.getString("title"), partnerPerson.getTitle()) ||
|
||||||
!StringUtils.equals(rec.getString("salut"), partnerPerson.getSalutation()) ||
|
!StringUtils.equals(rec.getString("salut"), partnerPerson.getSalutation()) ||
|
||||||
!StringUtils.equals(rec.getString("first_name"), partnerPerson.getGivenName()) ||
|
!StringUtils.equals(rec.getString("first_name"), partnerPerson.getGivenName()) ||
|
||||||
!StringUtils.equals(rec.getString("last_name"), partnerPerson.getFamilyName())) {
|
!StringUtils.equals(rec.getString("last_name"), partnerPerson.getFamilyName())) {
|
||||||
contactPerson = addPerson(HsOfficePersonEntity.builder().build(), rec);
|
contactPerson = addPerson(HsOfficePersonRealEntity.builder().build(), rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
final var contact = HsOfficeContactRealEntity.builder().build();
|
final var contact = HsOfficeContactRealEntity.builder().build();
|
||||||
@ -1085,8 +1086,8 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
|
|
||||||
private static HsOfficeRelationRealEntity addRelation(
|
private static HsOfficeRelationRealEntity addRelation(
|
||||||
final HsOfficeRelationType type,
|
final HsOfficeRelationType type,
|
||||||
final HsOfficePersonEntity anchor,
|
final HsOfficePersonRealEntity anchor,
|
||||||
final HsOfficePersonEntity holder,
|
final HsOfficePersonRealEntity holder,
|
||||||
final HsOfficeContactRealEntity contact) {
|
final HsOfficeContactRealEntity contact) {
|
||||||
final var rel = HsOfficeRelationRealEntity.builder()
|
final var rel = HsOfficeRelationRealEntity.builder()
|
||||||
.anchor(anchor)
|
.anchor(anchor)
|
||||||
@ -1098,7 +1099,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
return rel;
|
return rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HsOfficePersonEntity addPerson(final HsOfficePersonEntity person, final Record contactRecord) {
|
private HsOfficePersonRealEntity addPerson(final HsOfficePersonRealEntity person, final Record contactRecord) {
|
||||||
person.setSalutation(contactRecord.getString("salut"));
|
person.setSalutation(contactRecord.getString("salut"));
|
||||||
person.setTitle(contactRecord.getString("title"));
|
person.setTitle(contactRecord.getString("title"));
|
||||||
person.setGivenName(contactRecord.getString("first_name"));
|
person.setGivenName(contactRecord.getString("first_name"));
|
||||||
|
@ -7,7 +7,7 @@ import net.hostsharing.hsadminng.context.Context;
|
|||||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||||
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.HsOfficePersonRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||||
@ -57,16 +57,16 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
HsOfficePartnerRepository partnerRepo;
|
HsOfficePartnerRepository partnerRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeContactRealRepository contactrealRepo;
|
HsOfficeContactRealRepository contactRealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeBankAccountRepository bankAccountRepo;
|
HsOfficeBankAccountRepository bankAccountRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRealRepository personRealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeRelationRealRepository relrealRepo;
|
HsOfficeRelationRealRepository relationRealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
JpaAttempt jpaAttempt;
|
JpaAttempt jpaAttempt;
|
||||||
@ -270,13 +270,13 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
|
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
|
||||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
||||||
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0);
|
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0);
|
||||||
final var givenBillingPerson = personRepo.findPersonByOptionalNameLike("Fourth").get(0);
|
final var givenBillingPerson = personRealRepo.findPersonByOptionalNameLike("Fourth").get(0);
|
||||||
|
|
||||||
final var givenDebitorRelUUid = jpaAttempt.transacted(() -> {
|
final var givenDebitorRelUUid = jpaAttempt.transacted(() -> {
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
return relrealRepo.save(HsOfficeRelationRealEntity.builder()
|
return relationRealRepo.save(HsOfficeRelationRealEntity.builder()
|
||||||
.type(DEBITOR)
|
.type(DEBITOR)
|
||||||
.anchor(givenPartner.getPartnerRel().getHolder())
|
.anchor(givenPartner.getPartnerRel().getHolder())
|
||||||
.holder(givenBillingPerson)
|
.holder(givenBillingPerson)
|
||||||
@ -327,7 +327,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
|
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
|
||||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
||||||
|
|
||||||
final var location = RestAssured // @formatter:off
|
final var location = RestAssured // @formatter:off
|
||||||
.given()
|
.given()
|
||||||
@ -554,7 +554,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenDebitor = givenSomeTemporaryDebitor();
|
final var givenDebitor = givenSomeTemporaryDebitor();
|
||||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
||||||
|
|
||||||
final var location = RestAssured // @formatter:off
|
final var location = RestAssured // @formatter:off
|
||||||
.given()
|
.given()
|
||||||
@ -724,7 +724,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
return jpaAttempt.transacted(() -> {
|
return jpaAttempt.transacted(() -> {
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0).load();
|
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0).load();
|
||||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
|
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
|
||||||
final var newDebitor = HsOfficeDebitorEntity.builder()
|
final var newDebitor = HsOfficeDebitorEntity.builder()
|
||||||
.debitorNumberSuffix(nextDebitorSuffix())
|
.debitorNumberSuffix(nextDebitorSuffix())
|
||||||
.billable(true)
|
.billable(true)
|
||||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor;
|
|||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
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.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.rbac.generator.RbacViewMermaidFlowchartGenerator;
|
import net.hostsharing.hsadminng.rbac.generator.RbacViewMermaidFlowchartGenerator;
|
||||||
@ -13,11 +13,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
class HsOfficeDebitorEntityUnitTest {
|
class HsOfficeDebitorEntityUnitTest {
|
||||||
|
|
||||||
private final HsOfficeRelationRealEntity givenDebitorRel = HsOfficeRelationRealEntity.builder()
|
private final HsOfficeRelationRealEntity givenDebitorRel = HsOfficeRelationRealEntity.builder()
|
||||||
.anchor(HsOfficePersonEntity.builder()
|
.anchor(HsOfficePersonRealEntity.builder()
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("some partner trade name")
|
.tradeName("some partner trade name")
|
||||||
.build())
|
.build())
|
||||||
.holder(HsOfficePersonEntity.builder()
|
.holder(HsOfficePersonRealEntity.builder()
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("some billing trade name")
|
.tradeName("some billing trade name")
|
||||||
.build())
|
.build())
|
||||||
|
@ -4,7 +4,7 @@ import net.hostsharing.hsadminng.context.Context;
|
|||||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||||
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.HsOfficePersonRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||||
@ -53,7 +53,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
|||||||
HsOfficeContactRealRepository contactrealRepo;
|
HsOfficeContactRealRepository contactrealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRealRepository personRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeBankAccountRepository bankAccountRepo;
|
HsOfficeBankAccountRepository bankAccountRepo;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.debitor;
|
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.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealTestEntity.TEST_REAL_CONTACT;
|
import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealTestEntity.TEST_REAL_CONTACT;
|
||||||
@ -15,8 +15,8 @@ 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(HsOfficeRelationRealEntity.builder()
|
.debitorRel(HsOfficeRelationRealEntity.builder()
|
||||||
.holder(HsOfficePersonEntity.builder().build())
|
.holder(HsOfficePersonRealEntity.builder().build())
|
||||||
.anchor(HsOfficePersonEntity.builder().build())
|
.anchor(HsOfficePersonRealEntity.builder().build())
|
||||||
.contact(TEST_REAL_CONTACT)
|
.contact(TEST_REAL_CONTACT)
|
||||||
.build())
|
.build())
|
||||||
.partner(TEST_PARTNER)
|
.partner(TEST_PARTNER)
|
||||||
|
@ -5,8 +5,8 @@ import io.restassured.http.ContentType;
|
|||||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||||
@ -48,10 +48,10 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
HsOfficeRelationRealRepository relationRepo;
|
HsOfficeRelationRealRepository relationRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRealRepository personRealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeContactRealRepository contactrealRepo;
|
HsOfficeContactRealRepository contactRealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
JpaAttempt jpaAttempt;
|
JpaAttempt jpaAttempt;
|
||||||
@ -93,9 +93,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
void globalAdmin_withoutAssumedRole_canPostNewPartner() {
|
void globalAdmin_withoutAssumedRole_canPostNewPartner() {
|
||||||
|
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
|
final var givenMandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
|
||||||
final var givenPerson = personRepo.findPersonByOptionalNameLike("Third").stream().findFirst().orElseThrow();
|
final var givenPerson = personRealRepo.findPersonByOptionalNameLike("Third").stream().findFirst().orElseThrow();
|
||||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth").stream().findFirst().orElseThrow();
|
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth").stream().findFirst().orElseThrow();
|
||||||
|
|
||||||
final var location = RestAssured // @formatter:off
|
final var location = RestAssured // @formatter:off
|
||||||
.given()
|
.given()
|
||||||
@ -153,8 +153,8 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
void globalAdmin_canNotPostNewPartner_ifContactDoesNotExist() {
|
void globalAdmin_canNotPostNewPartner_ifContactDoesNotExist() {
|
||||||
|
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
final var givenMandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||||
final var givenPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
|
final var givenPerson = personRealRepo.findPersonByOptionalNameLike("Third").get(0);
|
||||||
|
|
||||||
final var location = RestAssured // @formatter:off
|
final var location = RestAssured // @formatter:off
|
||||||
.given()
|
.given()
|
||||||
@ -191,8 +191,8 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
void globalAdmin_canNotPostNewPartner_ifPersonDoesNotExist() {
|
void globalAdmin_canNotPostNewPartner_ifPersonDoesNotExist() {
|
||||||
|
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var mandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
final var mandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth").get(0);
|
||||||
|
|
||||||
final var location = RestAssured // @formatter:off
|
final var location = RestAssured // @formatter:off
|
||||||
.given()
|
.given()
|
||||||
@ -224,7 +224,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
// TODO.impl: we want this error message:
|
// TODO.impl: we want this error message:
|
||||||
// .body("message", is("ERROR: [400] Unable to find Person by uuid: " + GIVEN_NON_EXISTING_UUID));
|
// .body("message", is("ERROR: [400] Unable to find Person by uuid: " + GIVEN_NON_EXISTING_UUID));
|
||||||
// but ModelMapper creates this error message:
|
// but ModelMapper creates this error message:
|
||||||
.body("message", is("ERROR: [400] Unable to find " + HsOfficePersonEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
|
.body("message", is("ERROR: [400] Unable to find " + HsOfficePersonRealEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID));
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -528,9 +528,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
final String contactName) {
|
final String contactName) {
|
||||||
return jpaAttempt.transacted(() -> {
|
return jpaAttempt.transacted(() -> {
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
|
final var givenMandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
|
||||||
final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow();
|
final var givenPerson = personRealRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow();
|
||||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow();
|
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow();
|
||||||
|
|
||||||
final var partnerRel = new HsOfficeRelationRealEntity();
|
final var partnerRel = new HsOfficeRelationRealEntity();
|
||||||
partnerRel.setType(HsOfficeRelationType.PARTNER);
|
partnerRel.setType(HsOfficeRelationType.PARTNER);
|
||||||
|
@ -2,7 +2,7 @@ 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.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||||
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
||||||
@ -66,10 +66,10 @@ class HsOfficePartnerControllerRestTest {
|
|||||||
EntityManagerFactory emf;
|
EntityManagerFactory emf;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
HsOfficePersonEntity mandateMock;
|
HsOfficePersonRealEntity mandateMock;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
HsOfficePersonEntity personMock;
|
HsOfficePersonRealEntity personMock;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
HsOfficeContactRbacEntity contactMock;
|
HsOfficeContactRbacEntity contactMock;
|
||||||
@ -84,8 +84,8 @@ class HsOfficePartnerControllerRestTest {
|
|||||||
when(emf.createEntityManager(any(SynchronizationType.class))).thenReturn(em);
|
when(emf.createEntityManager(any(SynchronizationType.class))).thenReturn(em);
|
||||||
when(emf.createEntityManager(any(SynchronizationType.class), any(Map.class))).thenReturn(em);
|
when(emf.createEntityManager(any(SynchronizationType.class), any(Map.class))).thenReturn(em);
|
||||||
|
|
||||||
lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_MANDANTE_UUID)).thenReturn(mandateMock);
|
lenient().when(em.getReference(HsOfficePersonRealEntity.class, GIVEN_MANDANTE_UUID)).thenReturn(mandateMock);
|
||||||
lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_PERSON_UUID)).thenReturn(personMock);
|
lenient().when(em.getReference(HsOfficePersonRealEntity.class, GIVEN_PERSON_UUID)).thenReturn(personMock);
|
||||||
lenient().when(em.getReference(HsOfficeContactRbacEntity.class, GIVEN_CONTACT_UUID)).thenReturn(contactMock);
|
lenient().when(em.getReference(HsOfficeContactRbacEntity.class, GIVEN_CONTACT_UUID)).thenReturn(contactMock);
|
||||||
lenient().when(em.getReference(any(), eq(GIVEN_INVALID_UUID))).thenThrow(EntityNotFoundException.class);
|
lenient().when(em.getReference(any(), eq(GIVEN_INVALID_UUID))).thenThrow(EntityNotFoundException.class);
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ class HsOfficePartnerControllerRestTest {
|
|||||||
.andExpect(status().is4xxClientError())
|
.andExpect(status().is4xxClientError())
|
||||||
.andExpect(jsonPath("statusCode", is(400)))
|
.andExpect(jsonPath("statusCode", is(400)))
|
||||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||||
.andExpect(jsonPath("message", startsWith("ERROR: [400] Cannot resolve HsOfficePersonEntity with uuid ")));
|
.andExpect(jsonPath("message", startsWith("ERROR: [400] Cannot resolve HsOfficePersonRealEntity with uuid ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
|
|||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerDetailsPatchResource;
|
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerDetailsPatchResource;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacEntity;
|
||||||
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;
|
||||||
@ -45,8 +45,8 @@ class HsOfficePartnerDetailsEntityPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
void initMocks() {
|
void initMocks() {
|
||||||
lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation ->
|
lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation ->
|
||||||
HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build());
|
HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||||
lenient().when(em.getReference(eq(HsOfficePersonEntity.class), any())).thenAnswer(invocation ->
|
lenient().when(em.getReference(eq(HsOfficePersonRbacEntity.class), any())).thenAnswer(invocation ->
|
||||||
HsOfficePersonEntity.builder().uuid(invocation.getArgument(1)).build());
|
HsOfficePersonRbacEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
|
|||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
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.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
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;
|
||||||
@ -33,7 +33,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
private static final UUID INITIAL_DETAILS_UUID = UUID.randomUUID();
|
private static final UUID INITIAL_DETAILS_UUID = UUID.randomUUID();
|
||||||
private static final UUID PATCHED_PARTNER_ROLE_UUID = UUID.randomUUID();
|
private static final UUID PATCHED_PARTNER_ROLE_UUID = UUID.randomUUID();
|
||||||
|
|
||||||
private final HsOfficePersonEntity givenInitialPerson = HsOfficePersonEntity.builder()
|
private final HsOfficePersonRealEntity givenInitialPerson = HsOfficePersonRealEntity.builder()
|
||||||
.uuid(INITIAL_PERSON_UUID)
|
.uuid(INITIAL_PERSON_UUID)
|
||||||
.build();
|
.build();
|
||||||
private final HsOfficeContactRealEntity givenInitialContact = HsOfficeContactRealEntity.builder()
|
private final HsOfficeContactRealEntity givenInitialContact = HsOfficeContactRealEntity.builder()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.partner;
|
package net.hostsharing.hsadminng.hs.office.partner;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||||
@ -15,12 +15,12 @@ class HsOfficePartnerEntityUnitTest {
|
|||||||
private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder()
|
private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder()
|
||||||
.partnerNumber(12345)
|
.partnerNumber(12345)
|
||||||
.partnerRel(HsOfficeRelationRealEntity.builder()
|
.partnerRel(HsOfficeRelationRealEntity.builder()
|
||||||
.anchor(HsOfficePersonEntity.builder()
|
.anchor(HsOfficePersonRealEntity.builder()
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("Hostsharing eG")
|
.tradeName("Hostsharing eG")
|
||||||
.build())
|
.build())
|
||||||
.type(HsOfficeRelationType.PARTNER)
|
.type(HsOfficeRelationType.PARTNER)
|
||||||
.holder(HsOfficePersonEntity.builder()
|
.holder(HsOfficePersonRealEntity.builder()
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("some trade name")
|
.tradeName("some trade name")
|
||||||
.build())
|
.build())
|
||||||
|
@ -2,7 +2,7 @@ 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.HsOfficeContactRealRepository;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||||
@ -45,7 +45,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
|||||||
HsOfficeRelationRealRepository relationRepo;
|
HsOfficeRelationRealRepository relationRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRealRepository personRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeContactRealRepository contactrealRepo;
|
HsOfficeContactRealRepository contactrealRepo;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.partner;
|
package net.hostsharing.hsadminng.hs.office.partner;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||||
|
|
||||||
@ -16,12 +16,12 @@ public class TestHsOfficePartner {
|
|||||||
.partnerNumber(10001)
|
.partnerNumber(10001)
|
||||||
.partnerRel(
|
.partnerRel(
|
||||||
HsOfficeRelationRealEntity.builder()
|
HsOfficeRelationRealEntity.builder()
|
||||||
.holder(HsOfficePersonEntity.builder()
|
.holder(HsOfficePersonRealEntity.builder()
|
||||||
.personType(LEGAL_PERSON)
|
.personType(LEGAL_PERSON)
|
||||||
.tradeName("Hostsharing eG")
|
.tradeName("Hostsharing eG")
|
||||||
.build())
|
.build())
|
||||||
.type(HsOfficeRelationType.PARTNER)
|
.type(HsOfficeRelationType.PARTNER)
|
||||||
.holder(HsOfficePersonEntity.builder()
|
.holder(HsOfficePersonRealEntity.builder()
|
||||||
.personType(LEGAL_PERSON)
|
.personType(LEGAL_PERSON)
|
||||||
.tradeName(tradeName)
|
.tradeName(tradeName)
|
||||||
.build())
|
.build())
|
||||||
|
@ -43,7 +43,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
|||||||
Context contextMock;
|
Context contextMock;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRealRepository personRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
JpaAttempt jpaAttempt;
|
JpaAttempt jpaAttempt;
|
||||||
@ -327,10 +327,10 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HsOfficePersonEntity givenSomeTemporaryPersonCreatedBy(final String creatingUser) {
|
private HsOfficePersonRealEntity givenSomeTemporaryPersonCreatedBy(final String creatingUser) {
|
||||||
return jpaAttempt.transacted(() -> {
|
return jpaAttempt.transacted(() -> {
|
||||||
context.define(creatingUser);
|
context.define(creatingUser);
|
||||||
final var newPerson = HsOfficePersonEntity.builder()
|
final var newPerson = HsOfficePersonRealEntity.builder()
|
||||||
.uuid(UUID.randomUUID())
|
.uuid(UUID.randomUUID())
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("Temp " + Context.getCallerMethodNameFromStackFrame(2))
|
.tradeName("Temp " + Context.getCallerMethodNameFromStackFrame(2))
|
||||||
@ -347,7 +347,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
|||||||
jpaAttempt.transacted(() -> {
|
jpaAttempt.transacted(() -> {
|
||||||
context.define("superuser-alex@hostsharing.net", null);
|
context.define("superuser-alex@hostsharing.net", null);
|
||||||
em.createQuery("""
|
em.createQuery("""
|
||||||
DELETE FROM HsOfficePersonEntity p
|
DELETE FROM HsOfficePersonRealEntity p
|
||||||
WHERE p.tradeName LIKE 'Temp %' OR p.givenName LIKE 'Temp %'
|
WHERE p.tradeName LIKE 'Temp %' OR p.givenName LIKE 'Temp %'
|
||||||
""").executeUpdate();
|
""").executeUpdate();
|
||||||
}).assertSuccessful();
|
}).assertSuccessful();
|
||||||
|
@ -13,14 +13,14 @@ import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
|
|||||||
@TestInstance(PER_CLASS)
|
@TestInstance(PER_CLASS)
|
||||||
class HsOfficePersonEntityPatcherUnitTest extends PatchUnitTestBase<
|
class HsOfficePersonEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||||
HsOfficePersonPatchResource,
|
HsOfficePersonPatchResource,
|
||||||
HsOfficePersonEntity
|
HsOfficePersonRbacEntity
|
||||||
> {
|
> {
|
||||||
|
|
||||||
private static final UUID INITIAL_PERSON_UUID = UUID.randomUUID();
|
private static final UUID INITIAL_PERSON_UUID = UUID.randomUUID();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected HsOfficePersonEntity newInitialEntity() {
|
protected HsOfficePersonRbacEntity newInitialEntity() {
|
||||||
final var entity = new HsOfficePersonEntity();
|
final var entity = new HsOfficePersonRbacEntity();
|
||||||
entity.setUuid(INITIAL_PERSON_UUID);
|
entity.setUuid(INITIAL_PERSON_UUID);
|
||||||
entity.setPersonType(HsOfficePersonType.LEGAL_PERSON);
|
entity.setPersonType(HsOfficePersonType.LEGAL_PERSON);
|
||||||
entity.setTradeName("initial trade name");
|
entity.setTradeName("initial trade name");
|
||||||
@ -37,7 +37,7 @@ class HsOfficePersonEntityPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected HsOfficePersonEntityPatcher createPatcher(final HsOfficePersonEntity entity) {
|
protected HsOfficePersonEntityPatcher createPatcher(final HsOfficePersonRbacEntity entity) {
|
||||||
return new HsOfficePersonEntityPatcher(entity);
|
return new HsOfficePersonEntityPatcher(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,34 +48,34 @@ class HsOfficePersonEntityPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
"personType",
|
"personType",
|
||||||
HsOfficePersonPatchResource::setPersonType,
|
HsOfficePersonPatchResource::setPersonType,
|
||||||
HsOfficePersonTypeResource.INCORPORATED_FIRM,
|
HsOfficePersonTypeResource.INCORPORATED_FIRM,
|
||||||
HsOfficePersonEntity::setPersonType,
|
HsOfficePersonRbacEntity::setPersonType,
|
||||||
HsOfficePersonType.INCORPORATED_FIRM)
|
HsOfficePersonType.INCORPORATED_FIRM)
|
||||||
.notNullable(),
|
.notNullable(),
|
||||||
new JsonNullableProperty<>(
|
new JsonNullableProperty<>(
|
||||||
"tradeName",
|
"tradeName",
|
||||||
HsOfficePersonPatchResource::setTradeName,
|
HsOfficePersonPatchResource::setTradeName,
|
||||||
"patched trade name",
|
"patched trade name",
|
||||||
HsOfficePersonEntity::setTradeName),
|
HsOfficePersonRbacEntity::setTradeName),
|
||||||
new JsonNullableProperty<>(
|
new JsonNullableProperty<>(
|
||||||
"title",
|
"title",
|
||||||
HsOfficePersonPatchResource::setTitle,
|
HsOfficePersonPatchResource::setTitle,
|
||||||
"Dr. Patch.",
|
"Dr. Patch.",
|
||||||
HsOfficePersonEntity::setTitle),
|
HsOfficePersonRbacEntity::setTitle),
|
||||||
new JsonNullableProperty<>(
|
new JsonNullableProperty<>(
|
||||||
"salutation",
|
"salutation",
|
||||||
HsOfficePersonPatchResource::setSalutation,
|
HsOfficePersonPatchResource::setSalutation,
|
||||||
"Hallo Ini",
|
"Hallo Ini",
|
||||||
HsOfficePersonEntity::setSalutation),
|
HsOfficePersonRbacEntity::setSalutation),
|
||||||
new JsonNullableProperty<>(
|
new JsonNullableProperty<>(
|
||||||
"familyName",
|
"familyName",
|
||||||
HsOfficePersonPatchResource::setFamilyName,
|
HsOfficePersonPatchResource::setFamilyName,
|
||||||
"patched family name",
|
"patched family name",
|
||||||
HsOfficePersonEntity::setFamilyName),
|
HsOfficePersonRbacEntity::setFamilyName),
|
||||||
new JsonNullableProperty<>(
|
new JsonNullableProperty<>(
|
||||||
"patched given name",
|
"patched given name",
|
||||||
HsOfficePersonPatchResource::setGivenName,
|
HsOfficePersonPatchResource::setGivenName,
|
||||||
"patched given name",
|
"patched given name",
|
||||||
HsOfficePersonEntity::setGivenName)
|
HsOfficePersonRbacEntity::setGivenName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getDisplayReturnsTradeNameIfAvailable() {
|
void getDisplayReturnsTradeNameIfAvailable() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("some trade name")
|
.tradeName("some trade name")
|
||||||
.build();
|
.build();
|
||||||
@ -23,7 +23,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getDisplayReturnsFamilyAndGivenNameIfNoTradeNameAvailable() {
|
void getDisplayReturnsFamilyAndGivenNameIfNoTradeNameAvailable() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
.givenName("some given name")
|
.givenName("some given name")
|
||||||
@ -36,7 +36,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toShortStringWithTradeNameReturnsTradeName() {
|
void toShortStringWithTradeNameReturnsTradeName() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("some trade name")
|
.tradeName("some trade name")
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
@ -50,7 +50,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toShortStringWithoutTradeNameReturnsFamilyAndGivenName() {
|
void toShortStringWithoutTradeNameReturnsFamilyAndGivenName() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
.givenName("some given name")
|
.givenName("some given name")
|
||||||
@ -63,7 +63,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toShortStringWithSalutationAndTitleReturnsSalutationAndTitle() {
|
void toShortStringWithSalutationAndTitleReturnsSalutationAndTitle() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
.salutation("Frau")
|
.salutation("Frau")
|
||||||
.title("Dr.")
|
.title("Dr.")
|
||||||
@ -78,7 +78,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toShortStringWithSalutationAndWithoutTitleReturnsSalutation() {
|
void toShortStringWithSalutationAndWithoutTitleReturnsSalutation() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
.salutation("Frau")
|
.salutation("Frau")
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
@ -92,7 +92,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toShortStringWithoutSalutationAndWithTitleReturnsTitle() {
|
void toShortStringWithoutSalutationAndWithTitleReturnsTitle() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
.title("Dr. Dr.")
|
.title("Dr. Dr.")
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
@ -106,7 +106,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toStringWithAllFieldsReturnsAllButUuid() {
|
void toStringWithAllFieldsReturnsAllButUuid() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.uuid(UUID.randomUUID())
|
.uuid(UUID.randomUUID())
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
.tradeName("some trade name")
|
.tradeName("some trade name")
|
||||||
@ -122,7 +122,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toStringSkipsNullFields() {
|
void toStringSkipsNullFields() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
.givenName("some given name")
|
.givenName("some given name")
|
||||||
.build();
|
.build();
|
||||||
@ -133,7 +133,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
void toStringWithSalutationAndTitleRetursSalutationAndTitle() {
|
void toStringWithSalutationAndTitleRetursSalutationAndTitle() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.salutation("Herr")
|
.salutation("Herr")
|
||||||
.title("Prof. Dr.")
|
.title("Prof. Dr.")
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
@ -146,7 +146,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
void toStringWithSalutationAndWithoutTitleSkipsTitle() {
|
void toStringWithSalutationAndWithoutTitleSkipsTitle() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.salutation("Herr")
|
.salutation("Herr")
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
.givenName("some given name")
|
.givenName("some given name")
|
||||||
@ -159,7 +159,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toStringWithoutSalutationAndWithTitleSkipsSalutation() {
|
void toStringWithoutSalutationAndWithTitleSkipsSalutation() {
|
||||||
final var givenPersonEntity = HsOfficePersonEntity.builder()
|
final var givenPersonEntity = HsOfficePersonRbacEntity.builder()
|
||||||
.title("some title")
|
.title("some title")
|
||||||
.familyName("some family name")
|
.familyName("some family name")
|
||||||
.givenName("some given name")
|
.givenName("some given name")
|
||||||
@ -172,7 +172,7 @@ class HsOfficePersonEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void definesRbac() {
|
void definesRbac() {
|
||||||
final var rbacFlowchart = new RbacViewMermaidFlowchartGenerator(HsOfficePersonEntity.rbac()).toString();
|
final var rbacFlowchart = new RbacViewMermaidFlowchartGenerator(HsOfficePersonRbacEntity.rbac()).toString();
|
||||||
assertThat(rbacFlowchart).isEqualTo("""
|
assertThat(rbacFlowchart).isEqualTo("""
|
||||||
%%{init:{'flowchart':{'htmlLabels':false}}}%%
|
%%{init:{'flowchart':{'htmlLabels':false}}}%%
|
||||||
flowchart TB
|
flowchart TB
|
||||||
|
@ -21,7 +21,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.hs.office.person.TestHsOfficePerson.hsOfficePerson;
|
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacTestEntity.hsOfficePersonRbacEntity;
|
||||||
import static net.hostsharing.hsadminng.rbac.grant.RawRbacGrantEntity.distinctGrantDisplaysOf;
|
import static net.hostsharing.hsadminng.rbac.grant.RawRbacGrantEntity.distinctGrantDisplaysOf;
|
||||||
import static net.hostsharing.hsadminng.rbac.role.RawRbacRoleEntity.distinctRoleNamesOf;
|
import static net.hostsharing.hsadminng.rbac.role.RawRbacRoleEntity.distinctRoleNamesOf;
|
||||||
import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt;
|
import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt;
|
||||||
@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
@DataJpaTest
|
@DataJpaTest
|
||||||
@Import( { Context.class, JpaAttempt.class })
|
@Import( { Context.class, JpaAttempt.class })
|
||||||
class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
class HsOfficePersonRbacRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRbacRepository personRbacRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RawRbacRoleRepository rawRoleRepo;
|
RawRbacRoleRepository rawRoleRepo;
|
||||||
@ -56,34 +56,34 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
public void globalAdmin_withoutAssumedRole_canCreateNewPerson() {
|
public void globalAdmin_withoutAssumedRole_canCreateNewPerson() {
|
||||||
// given
|
// given
|
||||||
context("superuser-alex@hostsharing.net");
|
context("superuser-alex@hostsharing.net");
|
||||||
final var count = personRepo.count();
|
final var count = personRbacRepo.count();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var result = attempt(em, () -> toCleanup(personRepo.save(
|
final var result = attempt(em, () -> toCleanup(personRbacRepo.save(
|
||||||
hsOfficePerson("a new person"))));
|
hsOfficePersonRbacEntity("a new person"))));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
result.assertSuccessful();
|
result.assertSuccessful();
|
||||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePersonEntity::getUuid).isNotNull();
|
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePersonRbacEntity::getUuid).isNotNull();
|
||||||
assertThatPersonIsPersisted(result.returnedValue());
|
assertThatPersonIsPersisted(result.returnedValue());
|
||||||
assertThat(personRepo.count()).isEqualTo(count + 1);
|
assertThat(personRbacRepo.count()).isEqualTo(count + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void arbitraryUser_canCreateNewPerson() {
|
public void arbitraryUser_canCreateNewPerson() {
|
||||||
// given
|
// given
|
||||||
context("selfregistered-user-drew@hostsharing.org");
|
context("selfregistered-user-drew@hostsharing.org");
|
||||||
final var count = personRepo.count();
|
final var count = personRbacRepo.count();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var result = attempt(em, () -> toCleanup(personRepo.save(
|
final var result = attempt(em, () -> toCleanup(personRbacRepo.save(
|
||||||
hsOfficePerson("another new person"))));
|
hsOfficePersonRbacEntity("another new person"))));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
result.assertSuccessful();
|
result.assertSuccessful();
|
||||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePersonEntity::getUuid).isNotNull();
|
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePersonRbacEntity::getUuid).isNotNull();
|
||||||
assertThatPersonIsPersisted(result.returnedValue());
|
assertThatPersonIsPersisted(result.returnedValue());
|
||||||
assertThat(personRepo.count()).isEqualTo(count + 1);
|
assertThat(personRbacRepo.count()).isEqualTo(count + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -95,7 +95,7 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
attempt(em, () -> toCleanup(
|
attempt(em, () -> toCleanup(
|
||||||
personRepo.save(hsOfficePerson("another new person"))
|
personRbacRepo.save(hsOfficePersonRbacEntity("another new person"))
|
||||||
)).assumeSuccessful();
|
)).assumeSuccessful();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -122,8 +122,8 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertThatPersonIsPersisted(final HsOfficePersonEntity saved) {
|
private void assertThatPersonIsPersisted(final HsOfficePersonRbacEntity saved) {
|
||||||
final var found = personRepo.findByUuid(saved.getUuid());
|
final var found = personRbacRepo.findByUuid(saved.getUuid());
|
||||||
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
|
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
context("superuser-alex@hostsharing.net");
|
context("superuser-alex@hostsharing.net");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var result = personRepo.findPersonByOptionalNameLike(null);
|
final var result = personRbacRepo.findPersonByOptionalNameLike(null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
allThesePersonsAreReturned(
|
allThesePersonsAreReturned(
|
||||||
@ -155,7 +155,7 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
// when:
|
// when:
|
||||||
context("pac-admin-zzz00@zzz.example.com");
|
context("pac-admin-zzz00@zzz.example.com");
|
||||||
final var result = personRepo.findPersonByOptionalNameLike(null);
|
final var result = personRbacRepo.findPersonByOptionalNameLike(null);
|
||||||
|
|
||||||
// then:
|
// then:
|
||||||
exactlyThesePersonsAreReturned(result, givenPerson.getTradeName());
|
exactlyThesePersonsAreReturned(result, givenPerson.getTradeName());
|
||||||
@ -171,7 +171,7 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
context("superuser-alex@hostsharing.net", null);
|
context("superuser-alex@hostsharing.net", null);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final var result = personRepo.findPersonByOptionalNameLike("Second");
|
final var result = personRbacRepo.findPersonByOptionalNameLike("Second");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
exactlyThesePersonsAreReturned(result, "Second e.K.");
|
exactlyThesePersonsAreReturned(result, "Second e.K.");
|
||||||
@ -184,7 +184,7 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
// when:
|
// when:
|
||||||
context("selfregistered-user-drew@hostsharing.org");
|
context("selfregistered-user-drew@hostsharing.org");
|
||||||
final var result = personRepo.findPersonByOptionalNameLike(givenPerson.getTradeName());
|
final var result = personRbacRepo.findPersonByOptionalNameLike(givenPerson.getTradeName());
|
||||||
|
|
||||||
// then:
|
// then:
|
||||||
exactlyThesePersonsAreReturned(result, givenPerson.getTradeName());
|
exactlyThesePersonsAreReturned(result, givenPerson.getTradeName());
|
||||||
@ -202,14 +202,14 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
// when
|
// when
|
||||||
final var result = jpaAttempt.transacted(() -> {
|
final var result = jpaAttempt.transacted(() -> {
|
||||||
context("superuser-alex@hostsharing.net", null);
|
context("superuser-alex@hostsharing.net", null);
|
||||||
personRepo.deleteByUuid(givenPerson.getUuid());
|
personRbacRepo.deleteByUuid(givenPerson.getUuid());
|
||||||
});
|
});
|
||||||
|
|
||||||
// then
|
// then
|
||||||
result.assertSuccessful();
|
result.assertSuccessful();
|
||||||
assertThat(jpaAttempt.transacted(() -> {
|
assertThat(jpaAttempt.transacted(() -> {
|
||||||
context("superuser-alex@hostsharing.net", null);
|
context("superuser-alex@hostsharing.net", null);
|
||||||
return personRepo.findPersonByOptionalNameLike(givenPerson.getTradeName());
|
return personRbacRepo.findPersonByOptionalNameLike(givenPerson.getTradeName());
|
||||||
}).assertSuccessful().returnedValue()).hasSize(0);
|
}).assertSuccessful().returnedValue()).hasSize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,14 +221,14 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
// when
|
// when
|
||||||
final var result = jpaAttempt.transacted(() -> {
|
final var result = jpaAttempt.transacted(() -> {
|
||||||
context("selfregistered-user-drew@hostsharing.org", null);
|
context("selfregistered-user-drew@hostsharing.org", null);
|
||||||
personRepo.deleteByUuid(givenPerson.getUuid());
|
personRbacRepo.deleteByUuid(givenPerson.getUuid());
|
||||||
});
|
});
|
||||||
|
|
||||||
// then
|
// then
|
||||||
result.assertSuccessful();
|
result.assertSuccessful();
|
||||||
assertThat(jpaAttempt.transacted(() -> {
|
assertThat(jpaAttempt.transacted(() -> {
|
||||||
context("superuser-alex@hostsharing.net", null);
|
context("superuser-alex@hostsharing.net", null);
|
||||||
return personRepo.findPersonByOptionalNameLike(givenPerson.getTradeName());
|
return personRbacRepo.findPersonByOptionalNameLike(givenPerson.getTradeName());
|
||||||
}).assertSuccessful().returnedValue()).hasSize(0);
|
}).assertSuccessful().returnedValue()).hasSize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
// when
|
// when
|
||||||
final var result = jpaAttempt.transacted(() -> {
|
final var result = jpaAttempt.transacted(() -> {
|
||||||
context("selfregistered-user-drew@hostsharing.org", null);
|
context("selfregistered-user-drew@hostsharing.org", null);
|
||||||
return personRepo.deleteByUuid(givenPerson.getUuid());
|
return personRbacRepo.deleteByUuid(givenPerson.getUuid());
|
||||||
});
|
});
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -276,29 +276,29 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
"[creating person test-data, hs_office.person, INSERT, Third OHG, null]");
|
"[creating person test-data, hs_office.person, INSERT, Third OHG, null]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private HsOfficePersonEntity givenSomeTemporaryPerson(
|
private HsOfficePersonRbacEntity givenSomeTemporaryPerson(
|
||||||
final String createdByUser,
|
final String createdByUser,
|
||||||
Supplier<HsOfficePersonEntity> entitySupplier) {
|
Supplier<HsOfficePersonRbacEntity> entitySupplier) {
|
||||||
return jpaAttempt.transacted(() -> {
|
return jpaAttempt.transacted(() -> {
|
||||||
context(createdByUser);
|
context(createdByUser);
|
||||||
return toCleanup(personRepo.save(entitySupplier.get()));
|
return toCleanup(personRbacRepo.save(entitySupplier.get()));
|
||||||
}).assumeSuccessful().returnedValue();
|
}).assumeSuccessful().returnedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private HsOfficePersonEntity givenSomeTemporaryPerson(final String createdByUser) {
|
private HsOfficePersonRbacEntity givenSomeTemporaryPerson(final String createdByUser) {
|
||||||
return givenSomeTemporaryPerson(createdByUser, () ->
|
return givenSomeTemporaryPerson(createdByUser, () ->
|
||||||
hsOfficePerson("some temporary person #" + RandomStringUtils.random(12)));
|
hsOfficePersonRbacEntity("some temporary person #" + RandomStringUtils.random(12)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void exactlyThesePersonsAreReturned(final List<HsOfficePersonEntity> actualResult, final String... personCaptions) {
|
void exactlyThesePersonsAreReturned(final List<HsOfficePersonRbacEntity> actualResult, final String... personCaptions) {
|
||||||
assertThat(actualResult)
|
assertThat(actualResult)
|
||||||
.extracting(HsOfficePersonEntity::getTradeName)
|
.extracting(HsOfficePersonRbacEntity::getTradeName)
|
||||||
.containsExactlyInAnyOrder(personCaptions);
|
.containsExactlyInAnyOrder(personCaptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void allThesePersonsAreReturned(final List<HsOfficePersonEntity> actualResult, final String... personCaptions) {
|
void allThesePersonsAreReturned(final List<HsOfficePersonRbacEntity> actualResult, final String... personCaptions) {
|
||||||
assertThat(actualResult)
|
assertThat(actualResult)
|
||||||
.extracting(hsOfficePersonEntity -> hsOfficePersonEntity.toShortString())
|
.extracting(HsOfficePerson::toShortString)
|
||||||
.contains(personCaptions);
|
.contains(personCaptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
|
||||||
|
public class HsOfficePersonRbacTestEntity {
|
||||||
|
|
||||||
|
public static final HsOfficePersonRbacEntity somePerson = hsOfficePersonRbacEntity("some person");
|
||||||
|
|
||||||
|
public static HsOfficePersonRbacEntity hsOfficePersonRbacEntity(final String tradeName) {
|
||||||
|
return HsOfficePersonRbacEntity.builder()
|
||||||
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
|
.tradeName(tradeName)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,182 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
|
import net.hostsharing.hsadminng.mapper.Array;
|
||||||
|
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||||
|
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||||
|
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||||
|
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.PersistenceContext;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealTestEntity.hsOfficePersonRealEntity;
|
||||||
|
import static net.hostsharing.hsadminng.rbac.grant.RawRbacGrantEntity.distinctGrantDisplaysOf;
|
||||||
|
import static net.hostsharing.hsadminng.rbac.role.RawRbacRoleEntity.distinctRoleNamesOf;
|
||||||
|
import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@DataJpaTest
|
||||||
|
@Import( { Context.class, JpaAttempt.class })
|
||||||
|
class HsOfficePersonRealRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
HsOfficePersonRealRepository personRealRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RawRbacRoleRepository rawRoleRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RawRbacGrantRepository rawGrantRepo;
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
EntityManager em;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
JpaAttempt jpaAttempt;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
HttpServletRequest request;
|
||||||
|
@Autowired
|
||||||
|
private HsOfficePersonRealRepository hsOfficePersonRealRepository;
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class CreatePerson {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void arbitraryUser_canCreateNewPerson() {
|
||||||
|
// given
|
||||||
|
context("selfregistered-user-drew@hostsharing.org");
|
||||||
|
final var count = personRealRepo.count();
|
||||||
|
|
||||||
|
// when
|
||||||
|
final var result = attempt(em, () -> toCleanup(personRealRepo.save(
|
||||||
|
hsOfficePersonRealEntity("another new person"))));
|
||||||
|
|
||||||
|
// then
|
||||||
|
result.assertSuccessful();
|
||||||
|
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePersonRealEntity::getUuid).isNotNull();
|
||||||
|
assertThatPersonIsPersisted(result.returnedValue());
|
||||||
|
assertThat(personRealRepo.count()).isEqualTo(count + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createsAndGrantsRoles() {
|
||||||
|
// given
|
||||||
|
context("selfregistered-user-drew@hostsharing.org");
|
||||||
|
final var initialRoleNames = distinctRoleNamesOf(rawRoleRepo.findAll());
|
||||||
|
final var initialGrantNames = distinctGrantDisplaysOf(rawGrantRepo.findAll());
|
||||||
|
|
||||||
|
// when
|
||||||
|
attempt(em, () -> toCleanup(
|
||||||
|
personRealRepo.save(hsOfficePersonRealEntity("another new person"))
|
||||||
|
)).assumeSuccessful();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(
|
||||||
|
Array.from(
|
||||||
|
initialRoleNames,
|
||||||
|
"hs_office.person#anothernewperson:OWNER",
|
||||||
|
"hs_office.person#anothernewperson:ADMIN",
|
||||||
|
"hs_office.person#anothernewperson:REFERRER"
|
||||||
|
));
|
||||||
|
assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder(
|
||||||
|
Array.fromFormatted(
|
||||||
|
initialGrantNames,
|
||||||
|
"{ grant perm:hs_office.person#anothernewperson:INSERT>hs_office.relation to role:hs_office.person#anothernewperson:ADMIN by system and assume }",
|
||||||
|
|
||||||
|
"{ grant role:hs_office.person#anothernewperson:OWNER to user:selfregistered-user-drew@hostsharing.org by hs_office.person#anothernewperson:OWNER and assume }",
|
||||||
|
"{ grant role:hs_office.person#anothernewperson:OWNER to role:rbac.global#global:ADMIN by system and assume }",
|
||||||
|
"{ grant perm:hs_office.person#anothernewperson:UPDATE to role:hs_office.person#anothernewperson:ADMIN by system and assume }",
|
||||||
|
"{ grant perm:hs_office.person#anothernewperson:DELETE to role:hs_office.person#anothernewperson:OWNER by system and assume }",
|
||||||
|
"{ grant role:hs_office.person#anothernewperson:ADMIN to role:hs_office.person#anothernewperson:OWNER by system and assume }",
|
||||||
|
|
||||||
|
"{ grant perm:hs_office.person#anothernewperson:SELECT to role:hs_office.person#anothernewperson:REFERRER by system and assume }",
|
||||||
|
"{ grant role:hs_office.person#anothernewperson:REFERRER to role:hs_office.person#anothernewperson:ADMIN by system and assume }"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertThatPersonIsPersisted(final HsOfficePersonRealEntity saved) {
|
||||||
|
final var found = personRealRepo.findByUuid(saved.getUuid());
|
||||||
|
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class FindAllPersons {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void arbitraryUser_canViewAllPersons() {
|
||||||
|
// given
|
||||||
|
context("selfregistered-user-drew@hostsharing.org");
|
||||||
|
|
||||||
|
// when
|
||||||
|
final var result = personRealRepo.findPersonByOptionalNameLike(null);
|
||||||
|
|
||||||
|
// then
|
||||||
|
allThesePersonsAreReturned(
|
||||||
|
result,
|
||||||
|
"NP Smith, Peter",
|
||||||
|
"LP Second e.K.",
|
||||||
|
"IF Third OHG",
|
||||||
|
"UF Erben Bessler");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class FindByCaptionLike {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void arbitraryUser_canViewAllPersons() {
|
||||||
|
// given
|
||||||
|
context("selfregistered-user-drew@hostsharing.org");
|
||||||
|
|
||||||
|
// when
|
||||||
|
final var result = personRealRepo.findPersonByOptionalNameLike("Second");
|
||||||
|
|
||||||
|
// then
|
||||||
|
exactlyThesePersonsAreReturned(result, "Second e.K.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void auditJournalLogIsAvailable() {
|
||||||
|
// given
|
||||||
|
final var query = em.createNativeQuery("""
|
||||||
|
select currentTask, targetTable, targetOp, targetdelta->>'tradename', targetdelta->>'lastname'
|
||||||
|
from base.tx_journal_v
|
||||||
|
where targettable = 'hs_office.person';
|
||||||
|
""");
|
||||||
|
|
||||||
|
// when
|
||||||
|
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(customerLogEntries).map(Arrays::toString).contains(
|
||||||
|
"[creating person test-data, hs_office.person, INSERT, Hostsharing eG, null]",
|
||||||
|
"[creating person test-data, hs_office.person, INSERT, First GmbH, null]",
|
||||||
|
"[creating person test-data, hs_office.person, INSERT, Second e.K., null]",
|
||||||
|
"[creating person test-data, hs_office.person, INSERT, Third OHG, null]");
|
||||||
|
}
|
||||||
|
|
||||||
|
void exactlyThesePersonsAreReturned(final List<HsOfficePersonRealEntity> actualResult, final String... personCaptions) {
|
||||||
|
assertThat(actualResult)
|
||||||
|
.extracting(HsOfficePersonRealEntity::getTradeName)
|
||||||
|
.containsExactlyInAnyOrder(personCaptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void allThesePersonsAreReturned(final List<HsOfficePersonRealEntity> actualResult, final String... personCaptions) {
|
||||||
|
assertThat(actualResult)
|
||||||
|
.extracting(HsOfficePerson::toShortString)
|
||||||
|
.contains(personCaptions);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.hostsharing.hsadminng.hs.office.person;
|
||||||
|
|
||||||
|
|
||||||
|
public class HsOfficePersonRealTestEntity {
|
||||||
|
|
||||||
|
public static final HsOfficePersonRealEntity somePerson = hsOfficePersonRealEntity("some person");
|
||||||
|
|
||||||
|
public static HsOfficePersonRealEntity hsOfficePersonRealEntity(final String tradeName) {
|
||||||
|
return HsOfficePersonRealEntity.builder()
|
||||||
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
|
.tradeName(tradeName)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.person;
|
|
||||||
|
|
||||||
|
|
||||||
public class TestHsOfficePerson {
|
|
||||||
|
|
||||||
public static final HsOfficePersonEntity somePerson = hsOfficePerson("some person");
|
|
||||||
|
|
||||||
static public HsOfficePersonEntity hsOfficePerson(final String tradeName) {
|
|
||||||
return HsOfficePersonEntity.builder()
|
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
|
||||||
.tradeName(tradeName)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.relation;
|
package net.hostsharing.hsadminng.hs.office.relation;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||||
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;
|
||||||
@ -30,7 +30,7 @@ class HsOfficeRealRelationRepositoryIntegrationTest extends ContextBasedTestWith
|
|||||||
HsOfficeRelationRealRepository relationRealRepo;
|
HsOfficeRelationRealRepository relationRealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRbacRepository personRepo;
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
@ -3,11 +3,11 @@ package net.hostsharing.hsadminng.hs.office.relation;
|
|||||||
import io.restassured.RestAssured;
|
import io.restassured.RestAssured;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource;
|
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
|
||||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||||
import net.hostsharing.hsadminng.test.DisableSecurityConfig;
|
import net.hostsharing.hsadminng.test.DisableSecurityConfig;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
@ -45,7 +45,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
|||||||
HsOfficeRelationRealRepository relationrealRepo;
|
HsOfficeRelationRealRepository relationrealRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRealRepository personRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeContactRealRepository contactrealRepo;
|
HsOfficeContactRealRepository contactrealRepo;
|
||||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.relation;
|
|||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
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.HsOfficePersonRealEntity;
|
||||||
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;
|
||||||
@ -38,10 +38,10 @@ class HsOfficeRelationPatcherUnitTest extends PatchUnitTestBase<
|
|||||||
HsOfficeContactRealEntity.builder().uuid(invocation.getArgument(1)).build());
|
HsOfficeContactRealEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
final HsOfficePersonEntity givenInitialAnchorPerson = HsOfficePersonEntity.builder()
|
final HsOfficePersonRealEntity givenInitialAnchorPerson = HsOfficePersonRealEntity.builder()
|
||||||
.uuid(UUID.randomUUID())
|
.uuid(UUID.randomUUID())
|
||||||
.build();
|
.build();
|
||||||
final HsOfficePersonEntity givenInitialHolderPerson = HsOfficePersonEntity.builder()
|
final HsOfficePersonRealEntity givenInitialHolderPerson = HsOfficePersonRealEntity.builder()
|
||||||
.uuid(UUID.randomUUID())
|
.uuid(UUID.randomUUID())
|
||||||
.build();
|
.build();
|
||||||
final HsOfficeContactRealEntity givenInitialContact = HsOfficeContactRealEntity.builder()
|
final HsOfficeContactRealEntity givenInitialContact = HsOfficeContactRealEntity.builder()
|
||||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.relation;
|
|||||||
|
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||||
@ -37,7 +37,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
|
|||||||
HsOfficeRelationRbacRepository relationRbacRepo;
|
HsOfficeRelationRbacRepository relationRbacRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRealRepository personRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficeContactRealRepository contactrealRepo;
|
HsOfficeContactRealRepository contactrealRepo;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.relation;
|
package net.hostsharing.hsadminng.hs.office.relation;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||||
import net.hostsharing.hsadminng.rbac.generator.RbacViewMermaidFlowchartGenerator;
|
import net.hostsharing.hsadminng.rbac.generator.RbacViewMermaidFlowchartGenerator;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -9,11 +9,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
class HsOfficeRelationUnitTest {
|
class HsOfficeRelationUnitTest {
|
||||||
|
|
||||||
private HsOfficePersonEntity anchor = HsOfficePersonEntity.builder()
|
private HsOfficePersonRealEntity anchor = HsOfficePersonRealEntity.builder()
|
||||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||||
.tradeName("some trade name")
|
.tradeName("some trade name")
|
||||||
.build();
|
.build();
|
||||||
private HsOfficePersonEntity holder = HsOfficePersonEntity.builder()
|
private HsOfficePersonRealEntity holder = HsOfficePersonRealEntity.builder()
|
||||||
.personType(HsOfficePersonType.NATURAL_PERSON)
|
.personType(HsOfficePersonType.NATURAL_PERSON)
|
||||||
.familyName("Meier")
|
.familyName("Meier")
|
||||||
.givenName("Mellie")
|
.givenName("Mellie")
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.hostsharing.hsadminng.hs.scenarios;
|
package net.hostsharing.hsadminng.hs.scenarios;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacEntity;
|
||||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacRepository;
|
||||||
import net.hostsharing.hsadminng.lambda.Reducer;
|
import net.hostsharing.hsadminng.lambda.Reducer;
|
||||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||||
@ -68,7 +68,7 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
|||||||
Integer port;
|
Integer port;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
HsOfficePersonRepository personRepo;
|
HsOfficePersonRbacRepository personRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
JpaAttempt jpaAttempt;
|
JpaAttempt jpaAttempt;
|
||||||
@ -117,7 +117,7 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
|||||||
null,
|
null,
|
||||||
personRepo.findPersonByOptionalNameLike("Hostsharing eG")
|
personRepo.findPersonByOptionalNameLike("Hostsharing eG")
|
||||||
.stream()
|
.stream()
|
||||||
.map(HsOfficePersonEntity::getUuid)
|
.map(HsOfficePersonRbacEntity::getUuid)
|
||||||
.reduce(Reducer::toSingleElement).orElseThrow())
|
.reduce(Reducer::toSingleElement).orElseThrow())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user