@Timed for partners and debitors and Controller method name refactoring
This commit is contained in:
parent
2adfc490ad
commit
0559c8de97
@ -1,5 +1,6 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.debitor;
|
package net.hostsharing.hsadminng.hs.office.debitor;
|
||||||
|
|
||||||
|
import io.micrometer.core.annotation.Timed;
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeDebitorsApi;
|
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeDebitorsApi;
|
||||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorInsertResource;
|
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorInsertResource;
|
||||||
@ -51,6 +52,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
@Timed("app.debitors.api.getListOfDebitors")
|
||||||
public ResponseEntity<List<HsOfficeDebitorResource>> getListOfDebitors(
|
public ResponseEntity<List<HsOfficeDebitorResource>> getListOfDebitors(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
@ -68,6 +70,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@Timed("app.debitors.api.postNewDebitor")
|
||||||
public ResponseEntity<HsOfficeDebitorResource> postNewDebitor(
|
public ResponseEntity<HsOfficeDebitorResource> postNewDebitor(
|
||||||
String currentSubject,
|
String currentSubject,
|
||||||
String assumedRoles,
|
String assumedRoles,
|
||||||
@ -115,6 +118,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
@Timed("app.debitors.api.getSingleDebitorByUuid")
|
||||||
public ResponseEntity<HsOfficeDebitorResource> getSingleDebitorByUuid(
|
public ResponseEntity<HsOfficeDebitorResource> getSingleDebitorByUuid(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
@ -131,6 +135,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@Timed("app.debitors.api.deleteDebitorByUuid")
|
||||||
public ResponseEntity<Void> deleteDebitorByUuid(
|
public ResponseEntity<Void> deleteDebitorByUuid(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
@ -147,6 +152,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@Timed("app.debitors.api.patchDebitor")
|
||||||
public ResponseEntity<HsOfficeDebitorResource> patchDebitor(
|
public ResponseEntity<HsOfficeDebitorResource> patchDebitor(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.debitor;
|
package net.hostsharing.hsadminng.hs.office.debitor;
|
||||||
|
|
||||||
|
import io.micrometer.core.annotation.Timed;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEntity, UUID> {
|
public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEntity, UUID> {
|
||||||
|
|
||||||
|
@Timed("app.debitors.repo.findByUuid")
|
||||||
Optional<HsOfficeDebitorEntity> findByUuid(UUID id);
|
Optional<HsOfficeDebitorEntity> findByUuid(UUID id);
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
@ -19,7 +21,8 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
|
|||||||
WHERE partner.partnerNumber = :partnerNumber
|
WHERE partner.partnerNumber = :partnerNumber
|
||||||
AND debitor.debitorNumberSuffix = :debitorNumberSuffix
|
AND debitor.debitorNumberSuffix = :debitorNumberSuffix
|
||||||
""")
|
""")
|
||||||
List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int partnerNumber, String debitorNumberSuffix);
|
@Timed("app.debitors.repo.findDebitorByDebitorNumber")
|
||||||
|
List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int partnerNumber, String debitorNumberSuffix);
|
||||||
|
|
||||||
default List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int debitorNumber) {
|
default List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int debitorNumber) {
|
||||||
final var partnerNumber = debitorNumber / 100;
|
final var partnerNumber = debitorNumber / 100;
|
||||||
@ -46,11 +49,15 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
|
|||||||
OR person.givenName like concat(cast(:name as text), '%')
|
OR person.givenName like concat(cast(:name as text), '%')
|
||||||
OR contact.caption like concat(cast(:name as text), '%')
|
OR contact.caption like concat(cast(:name as text), '%')
|
||||||
""")
|
""")
|
||||||
|
@Timed("app.debitors.repo.findDebitorByOptionalNameLike")
|
||||||
List<HsOfficeDebitorEntity> findDebitorByOptionalNameLike(String name);
|
List<HsOfficeDebitorEntity> findDebitorByOptionalNameLike(String name);
|
||||||
|
|
||||||
|
@Timed("app.debitors.repo.save")
|
||||||
HsOfficeDebitorEntity save(final HsOfficeDebitorEntity entity);
|
HsOfficeDebitorEntity save(final HsOfficeDebitorEntity entity);
|
||||||
|
|
||||||
|
@Timed("app.debitors.repo.count")
|
||||||
long count();
|
long count();
|
||||||
|
|
||||||
|
@Timed("app.debitors.repo.deleteByUuid")
|
||||||
int deleteByUuid(UUID uuid);
|
int deleteByUuid(UUID uuid);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.partner;
|
package net.hostsharing.hsadminng.hs.office.partner;
|
||||||
|
|
||||||
|
import io.micrometer.core.annotation.Timed;
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
import net.hostsharing.hsadminng.errors.ReferenceNotFoundException;
|
import net.hostsharing.hsadminng.errors.ReferenceNotFoundException;
|
||||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||||
@ -50,7 +51,8 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public ResponseEntity<List<HsOfficePartnerResource>> listPartners(
|
@Timed("app.partners.api.getListOfPartners")
|
||||||
|
public ResponseEntity<List<HsOfficePartnerResource>> getListOfPartners(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final String name) {
|
final String name) {
|
||||||
@ -64,7 +66,8 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<HsOfficePartnerResource> addPartner(
|
@Timed("app.partners.api.postNewPartner")
|
||||||
|
public ResponseEntity<HsOfficePartnerResource> postNewPartner(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final HsOfficePartnerInsertResource body) {
|
final HsOfficePartnerInsertResource body) {
|
||||||
@ -86,7 +89,8 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public ResponseEntity<HsOfficePartnerResource> getPartnerByUuid(
|
@Timed("app.partners.api.getSinglePartnerByUuid")
|
||||||
|
public ResponseEntity<HsOfficePartnerResource> getSinglePartnerByUuid(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
final UUID partnerUuid) {
|
final UUID partnerUuid) {
|
||||||
@ -102,6 +106,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@Timed("app.partners.api.deletePartnerByUuid")
|
||||||
public ResponseEntity<Void> deletePartnerByUuid(
|
public ResponseEntity<Void> deletePartnerByUuid(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
@ -122,6 +127,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@Timed("app.partners.api.patchPartner")
|
||||||
public ResponseEntity<HsOfficePartnerResource> patchPartner(
|
public ResponseEntity<HsOfficePartnerResource> patchPartner(
|
||||||
final String currentSubject,
|
final String currentSubject,
|
||||||
final String assumedRoles,
|
final String assumedRoles,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.partner;
|
package net.hostsharing.hsadminng.hs.office.partner;
|
||||||
|
|
||||||
|
import io.micrometer.core.annotation.Timed;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
@ -9,9 +10,11 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEntity, UUID> {
|
public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEntity, UUID> {
|
||||||
|
|
||||||
|
@Timed("app.partners.repo.findByUuid")
|
||||||
Optional<HsOfficePartnerEntity> findByUuid(UUID id);
|
Optional<HsOfficePartnerEntity> findByUuid(UUID id);
|
||||||
|
|
||||||
List<HsOfficePartnerEntity> findAll(); // TODO.impl: move to a repo in test sources
|
@Timed("app.partners.repo.findAll")
|
||||||
|
List<HsOfficePartnerEntity> findAll(); // TODO.refa: move to a repo in test sources
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
SELECT partner FROM HsOfficePartnerEntity partner
|
SELECT partner FROM HsOfficePartnerEntity partner
|
||||||
@ -25,12 +28,18 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
|
|||||||
OR person.givenName like concat(cast(:name as text), '%')
|
OR person.givenName like concat(cast(:name as text), '%')
|
||||||
OR person.familyName like concat(cast(:name as text), '%')
|
OR person.familyName like concat(cast(:name as text), '%')
|
||||||
""")
|
""")
|
||||||
|
@Timed("app.partners.repo.findPartnerByOptionalNameLike")
|
||||||
List<HsOfficePartnerEntity> findPartnerByOptionalNameLike(String name);
|
List<HsOfficePartnerEntity> findPartnerByOptionalNameLike(String name);
|
||||||
|
|
||||||
|
@Timed("app.partners.repo.findPartnerByPartnerNumber")
|
||||||
HsOfficePartnerEntity findPartnerByPartnerNumber(Integer partnerNumber);
|
HsOfficePartnerEntity findPartnerByPartnerNumber(Integer partnerNumber);
|
||||||
|
|
||||||
|
@Timed("app.partners.repo.save")
|
||||||
HsOfficePartnerEntity save(final HsOfficePartnerEntity entity);
|
HsOfficePartnerEntity save(final HsOfficePartnerEntity entity);
|
||||||
|
|
||||||
|
@Timed("app.partners.repo.count")
|
||||||
long count();
|
long count();
|
||||||
|
|
||||||
|
@Timed("app.partners.repo.deleteByUuid")
|
||||||
int deleteByUuid(UUID uuid);
|
int deleteByUuid(UUID uuid);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ get:
|
|||||||
tags:
|
tags:
|
||||||
- hs-office-partners
|
- hs-office-partners
|
||||||
description: 'Fetch a single business partner by its uuid, if visible for the current subject.'
|
description: 'Fetch a single business partner by its uuid, if visible for the current subject.'
|
||||||
operationId: getPartnerByUuid
|
operationId: getSinglePartnerByUuid
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: 'auth.yaml#/components/parameters/currentSubject'
|
- $ref: 'auth.yaml#/components/parameters/currentSubject'
|
||||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||||
|
@ -3,7 +3,7 @@ get:
|
|||||||
description: Returns the list of (optionally filtered) business partners which are visible to the current subject or any of it's assumed roles.
|
description: Returns the list of (optionally filtered) business partners which are visible to the current subject or any of it's assumed roles.
|
||||||
tags:
|
tags:
|
||||||
- hs-office-partners
|
- hs-office-partners
|
||||||
operationId: listPartners
|
operationId: getListOfPartners
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: 'auth.yaml#/components/parameters/currentSubject'
|
- $ref: 'auth.yaml#/components/parameters/currentSubject'
|
||||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||||
@ -31,7 +31,7 @@ post:
|
|||||||
summary: Adds a new business partner.
|
summary: Adds a new business partner.
|
||||||
tags:
|
tags:
|
||||||
- hs-office-partners
|
- hs-office-partners
|
||||||
operationId: addPartner
|
operationId: postNewPartner
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: 'auth.yaml#/components/parameters/currentSubject'
|
- $ref: 'auth.yaml#/components/parameters/currentSubject'
|
||||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||||
|
@ -58,7 +58,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@Transactional
|
@Transactional
|
||||||
class ListPartners {
|
class GetListOfPartners {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void globalAdmin_withoutAssumedRoles_canViewAllPartners_ifNoCriteriaGiven() {
|
void globalAdmin_withoutAssumedRoles_canViewAllPartners_ifNoCriteriaGiven() {
|
||||||
@ -87,10 +87,10 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@Transactional
|
@Transactional
|
||||||
class AddPartner {
|
class PostNewPartner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void globalAdmin_withoutAssumedRole_canAddPartner() {
|
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 = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
|
||||||
@ -150,7 +150,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void globalAdmin_canNotAddPartner_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 = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||||
@ -188,7 +188,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void globalAdmin_canNotAddPartner_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 = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||||
|
@ -91,7 +91,7 @@ class HsOfficePartnerControllerRestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class AddPartner {
|
class PostNewPartner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void respondBadRequest_ifPersonUuidIsInvalid() throws Exception {
|
void respondBadRequest_ifPersonUuidIsInvalid() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user