merging aftermaths

This commit is contained in:
Michael Hönnig 2024-10-11 19:08:23 +02:00
parent 98504f7495
commit 3022473c11
2 changed files with 36 additions and 70 deletions

View File

@ -45,35 +45,31 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
@Override
@Transactional(readOnly = true)
public ResponseEntity<List<HsOfficeRelationResource>> listRelations(
final String currentSubject,
final String assumedRoles,
final UUID personUuid,
final HsOfficeRelationTypeResource relationType,
final String personData,
final String contactData) {
final String currentSubject,
final String assumedRoles,
final UUID personUuid,
final HsOfficeRelationTypeResource relationType,
final String personData,
final String contactData) {
context.define(currentSubject, assumedRoles);
final List<HsOfficeRelationRbacEntity> entities =
( personData == null && contactData == null )
? relationRbacRepo.findRelationRelatedToPersonUuidRelationTypePersonAndContactData(personUuid,
relationType == null ? null : HsOfficeRelationType.valueOf(relationType.name()),
personData, contactData)
: relationRbacRepo.findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
personUuid,
relationType == null ? null : HsOfficeRelationType.valueOf(relationType.name()),
forLike(personData), forLike(contactData));
relationRbacRepo.findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
personUuid,
relationType == null ? null : HsOfficeRelationType.valueOf(relationType.name()),
personData, contactData);
final var resources = mapper.mapList(entities, HsOfficeRelationResource.class,
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
return ResponseEntity.ok(resources);
}
@Override
@Transactional
public ResponseEntity<HsOfficeRelationResource> addRelation(
final String currentSubject,
final String assumedRoles,
final HsOfficeRelationInsertResource body) {
final String currentSubject,
final String assumedRoles,
final HsOfficeRelationInsertResource body) {
context.define(currentSubject, assumedRoles);
@ -81,33 +77,33 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
entityToSave.setType(HsOfficeRelationType.valueOf(body.getType()));
entityToSave.setMark(body.getMark());
entityToSave.setAnchor(holderRepo.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(
() -> 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(
() -> new NoSuchElementException("cannot find Contact by contactUuid: " + body.getContactUuid())
() -> new NoSuchElementException("cannot find Contact by contactUuid: " + body.getContactUuid())
));
final var saved = relationRbacRepo.save(entityToSave);
final var uri =
MvcUriComponentsBuilder.fromController(getClass())
.path("/api/hs/office/relations/{id}")
.buildAndExpand(saved.getUuid())
.toUri();
MvcUriComponentsBuilder.fromController(getClass())
.path("/api/hs/office/relations/{id}")
.buildAndExpand(saved.getUuid())
.toUri();
final var mapped = mapper.map(saved, HsOfficeRelationResource.class,
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
return ResponseEntity.created(uri).body(mapped);
}
@Override
@Transactional(readOnly = true)
public ResponseEntity<HsOfficeRelationResource> getRelationByUuid(
final String currentSubject,
final String assumedRoles,
final UUID relationUuid) {
final String currentSubject,
final String assumedRoles,
final UUID relationUuid) {
context.define(currentSubject, assumedRoles);
@ -121,9 +117,9 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
@Override
@Transactional
public ResponseEntity<Void> deleteRelationByUuid(
final String currentSubject,
final String assumedRoles,
final UUID relationUuid) {
final String currentSubject,
final String assumedRoles,
final UUID relationUuid) {
context.define(currentSubject, assumedRoles);
final var result = relationRbacRepo.deleteByUuid(relationUuid);
@ -137,10 +133,10 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
@Override
@Transactional
public ResponseEntity<HsOfficeRelationResource> patchRelation(
final String currentSubject,
final String assumedRoles,
final UUID relationUuid,
final HsOfficeRelationPatchResource body) {
final String currentSubject,
final String assumedRoles,
final UUID relationUuid,
final HsOfficeRelationPatchResource body) {
context.define(currentSubject, assumedRoles);

View File

@ -28,10 +28,10 @@ public interface HsOfficeRelationRbacRepository extends Repository<HsOfficeRelat
* @return a list of (accessible) relations which match all given criteria
*/
default List<HsOfficeRelationRbacEntity> findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
UUID personUuid,
HsOfficeRelationType relationType,
String personData,
String contactData) {
final UUID personUuid,
final HsOfficeRelationType relationType,
final String personData,
final String contactData) {
return findRelationRelatedToPersonUuidRelationTypePersonAndContactDataImpl(
personUuid, toStringOrNull(relationType), toSqlLikeOperand(personData), toSqlLikeOperand(contactData));
}
@ -57,36 +57,6 @@ public interface HsOfficeRelationRbacRepository extends Repository<HsOfficeRelat
final String personData,
final String contactData);
/**
* Finds relations by a conjunction of optional criteria, including anchorPerson, holderPerson and contact data.
*
* @param personUuid the optional UUID of the anchorPerson or holderPerson
* @param relationType the type of the relation
* @param personData a lower-case string to match the persons tradeName, familyName or givenName (use '%' for wildcard)
* @param contactData a lower-case string to match the contacts caption, postalAddress, emailAddresses or phoneNumbers (use '%' for wildcard)
* @return a list of (accessible) relations which match all given criteria
*/
@Query(value = """
SELECT rel FROM HsOfficeRelationRbacEntity AS rel
WHERE (:relationType IS NULL OR CAST(rel.type AS String) = CAST(:relationType AS String))
AND ( :personUuid IS NULL OR
rel.anchor.uuid = :personUuid OR rel.holder.uuid = :personUuid )
AND ( :personData IS NULL OR
lower(rel.anchor.tradeName) LIKE :personData OR lower(rel.holder.tradeName) LIKE :personData OR
lower(rel.anchor.familyName) LIKE :personData OR lower(rel.holder.familyName) LIKE :personData OR
lower(rel.anchor.givenName) LIKE :personData OR lower(rel.holder.givenName) LIKE :personData )
AND ( :contactData IS NULL OR
lower(rel.contact.caption) LIKE :contactData OR
lower(rel.contact.postalAddress) LIKE :contactData OR
lower(CAST(rel.contact.emailAddresses AS String)) LIKE :contactData OR
lower(CAST(rel.contact.phoneNumbers AS String)) LIKE :contactData )
""")
List<HsOfficeRelationRbacEntity> findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
UUID personUuid,
HsOfficeRelationType relationType,
String personData,
String contactData);
HsOfficeRelationRbacEntity save(final HsOfficeRelationRbacEntity entity);
long count();