merging aftermaths
This commit is contained in:
parent
98504f7495
commit
3022473c11
@ -45,35 +45,31 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public ResponseEntity<List<HsOfficeRelationResource>> listRelations(
|
public ResponseEntity<List<HsOfficeRelationResource>> listRelations(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final UUID personUuid,
|
final UUID personUuid,
|
||||||
final HsOfficeRelationTypeResource relationType,
|
final HsOfficeRelationTypeResource relationType,
|
||||||
final String personData,
|
final String personData,
|
||||||
final String contactData) {
|
final String contactData) {
|
||||||
context.define(currentSubject, assumedRoles);
|
context.define(currentSubject, assumedRoles);
|
||||||
|
|
||||||
final List<HsOfficeRelationRbacEntity> entities =
|
final List<HsOfficeRelationRbacEntity> entities =
|
||||||
( personData == null && contactData == null )
|
relationRbacRepo.findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
|
||||||
? relationRbacRepo.findRelationRelatedToPersonUuidRelationTypePersonAndContactData(personUuid,
|
personUuid,
|
||||||
relationType == null ? null : HsOfficeRelationType.valueOf(relationType.name()),
|
relationType == null ? null : HsOfficeRelationType.valueOf(relationType.name()),
|
||||||
personData, contactData)
|
personData, contactData);
|
||||||
: relationRbacRepo.findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
|
|
||||||
personUuid,
|
|
||||||
relationType == null ? null : HsOfficeRelationType.valueOf(relationType.name()),
|
|
||||||
forLike(personData), forLike(contactData));
|
|
||||||
|
|
||||||
final var resources = mapper.mapList(entities, HsOfficeRelationResource.class,
|
final var resources = mapper.mapList(entities, HsOfficeRelationResource.class,
|
||||||
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
|
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
|
||||||
return ResponseEntity.ok(resources);
|
return ResponseEntity.ok(resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<HsOfficeRelationResource> addRelation(
|
public ResponseEntity<HsOfficeRelationResource> addRelation(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final HsOfficeRelationInsertResource body) {
|
final HsOfficeRelationInsertResource body) {
|
||||||
|
|
||||||
context.define(currentSubject, assumedRoles);
|
context.define(currentSubject, assumedRoles);
|
||||||
|
|
||||||
@ -81,33 +77,33 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
|
|||||||
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(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(
|
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(
|
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 saved = relationRbacRepo.save(entityToSave);
|
||||||
|
|
||||||
final var uri =
|
final var uri =
|
||||||
MvcUriComponentsBuilder.fromController(getClass())
|
MvcUriComponentsBuilder.fromController(getClass())
|
||||||
.path("/api/hs/office/relations/{id}")
|
.path("/api/hs/office/relations/{id}")
|
||||||
.buildAndExpand(saved.getUuid())
|
.buildAndExpand(saved.getUuid())
|
||||||
.toUri();
|
.toUri();
|
||||||
final var mapped = mapper.map(saved, HsOfficeRelationResource.class,
|
final var mapped = mapper.map(saved, HsOfficeRelationResource.class,
|
||||||
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
|
RELATION_ENTITY_TO_RESOURCE_POSTMAPPER);
|
||||||
return ResponseEntity.created(uri).body(mapped);
|
return ResponseEntity.created(uri).body(mapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public ResponseEntity<HsOfficeRelationResource> getRelationByUuid(
|
public ResponseEntity<HsOfficeRelationResource> getRelationByUuid(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final UUID relationUuid) {
|
final UUID relationUuid) {
|
||||||
|
|
||||||
context.define(currentSubject, assumedRoles);
|
context.define(currentSubject, assumedRoles);
|
||||||
|
|
||||||
@ -121,9 +117,9 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<Void> deleteRelationByUuid(
|
public ResponseEntity<Void> deleteRelationByUuid(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final UUID relationUuid) {
|
final UUID relationUuid) {
|
||||||
context.define(currentSubject, assumedRoles);
|
context.define(currentSubject, assumedRoles);
|
||||||
|
|
||||||
final var result = relationRbacRepo.deleteByUuid(relationUuid);
|
final var result = relationRbacRepo.deleteByUuid(relationUuid);
|
||||||
@ -137,10 +133,10 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<HsOfficeRelationResource> patchRelation(
|
public ResponseEntity<HsOfficeRelationResource> patchRelation(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final UUID relationUuid,
|
final UUID relationUuid,
|
||||||
final HsOfficeRelationPatchResource body) {
|
final HsOfficeRelationPatchResource body) {
|
||||||
|
|
||||||
context.define(currentSubject, assumedRoles);
|
context.define(currentSubject, assumedRoles);
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ public interface HsOfficeRelationRbacRepository extends Repository<HsOfficeRelat
|
|||||||
* @return a list of (accessible) relations which match all given criteria
|
* @return a list of (accessible) relations which match all given criteria
|
||||||
*/
|
*/
|
||||||
default List<HsOfficeRelationRbacEntity> findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
|
default List<HsOfficeRelationRbacEntity> findRelationRelatedToPersonUuidRelationTypePersonAndContactData(
|
||||||
UUID personUuid,
|
final UUID personUuid,
|
||||||
HsOfficeRelationType relationType,
|
final HsOfficeRelationType relationType,
|
||||||
String personData,
|
final String personData,
|
||||||
String contactData) {
|
final String contactData) {
|
||||||
return findRelationRelatedToPersonUuidRelationTypePersonAndContactDataImpl(
|
return findRelationRelatedToPersonUuidRelationTypePersonAndContactDataImpl(
|
||||||
personUuid, toStringOrNull(relationType), toSqlLikeOperand(personData), toSqlLikeOperand(contactData));
|
personUuid, toStringOrNull(relationType), toSqlLikeOperand(personData), toSqlLikeOperand(contactData));
|
||||||
}
|
}
|
||||||
@ -57,36 +57,6 @@ public interface HsOfficeRelationRbacRepository extends Repository<HsOfficeRelat
|
|||||||
final String personData,
|
final String personData,
|
||||||
final String contactData);
|
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);
|
HsOfficeRelationRbacEntity save(final HsOfficeRelationRbacEntity entity);
|
||||||
|
|
||||||
long count();
|
long count();
|
||||||
|
Loading…
Reference in New Issue
Block a user