add micrometer @Timing annotations to Controllers+Repositories + ArchTest #128

Merged
hsh-michaelhoennig merged 6 commits from feature/add-micrometer-timing-measurements into master 2024-12-05 10:32:34 +01:00
50 changed files with 266 additions and 87 deletions
Showing only changes of commit eb525f34c5 - Show all commits

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.booking.debitor; package net.hostsharing.hsadminng.hs.booking.debitor;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -8,7 +9,9 @@ import java.util.UUID;
public interface HsBookingDebitorRepository extends Repository<HsBookingDebitorEntity, UUID> { public interface HsBookingDebitorRepository extends Repository<HsBookingDebitorEntity, UUID> {
@Timed("app.bookingDebitor.repo.findByUuid")
Optional<HsBookingDebitorEntity> findByUuid(UUID id); Optional<HsBookingDebitorEntity> findByUuid(UUID id);
@Timed("app.bookingDebitor.repo.findByDebitorNumber")
List<HsBookingDebitorEntity> findByDebitorNumber(int debitorNumber); List<HsBookingDebitorEntity> findByDebitorNumber(int debitorNumber);
} }

View File

@ -1,12 +1,15 @@
package net.hostsharing.hsadminng.hs.booking.item; package net.hostsharing.hsadminng.hs.booking.item;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.UUID; import java.util.UUID;
public interface BookingItemCreatedEventRepository extends Repository<BookingItemCreatedEventEntity, UUID> { public interface BookingItemCreatedEventRepository extends Repository<BookingItemCreatedEventEntity, UUID> {
@Timed("app.booking.items.repo.save")
BookingItemCreatedEventEntity save(HsBookingItemRealEntity current); BookingItemCreatedEventEntity save(HsBookingItemRealEntity current);
@Timed("app.booking.items.repo.findByBookingItem")
BookingItemCreatedEventEntity findByBookingItem(HsBookingItemRealEntity newBookingItem); BookingItemCreatedEventEntity findByBookingItem(HsBookingItemRealEntity newBookingItem);
} }

View File

@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.booking.generated.api.v1.api.HsBookingItemsApi; import net.hostsharing.hsadminng.hs.booking.generated.api.v1.api.HsBookingItemsApi;
import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsBookingItemInsertResource; import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsBookingItemInsertResource;
@ -51,7 +52,8 @@ public class HsBookingItemController implements HsBookingItemsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<HsBookingItemResource>> listBookingItemsByProjectUuid( @Timed("app.bookingItems.api.getListOfBookingItemsByProjectUuid")
public ResponseEntity<List<HsBookingItemResource>> getListOfBookingItemsByProjectUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID projectUuid) { final UUID projectUuid) {
@ -65,7 +67,8 @@ public class HsBookingItemController implements HsBookingItemsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<HsBookingItemResource> addBookingItem( @Timed("app.bookingItems.api.postNewBookingItem")
public ResponseEntity<HsBookingItemResource> postNewBookingItem(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final HsBookingItemInsertResource body) { final HsBookingItemInsertResource body) {
@ -94,7 +97,8 @@ public class HsBookingItemController implements HsBookingItemsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<HsBookingItemResource> getBookingItemByUuid( @Timed("app.bookingItems.api.getSingleBookingItemByUuid")
public ResponseEntity<HsBookingItemResource> getSingleBookingItemByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID bookingItemUuid) { final UUID bookingItemUuid) {
@ -111,6 +115,7 @@ public class HsBookingItemController implements HsBookingItemsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.bookingItems.api.deleteBookingIemByUuid")
public ResponseEntity<Void> deleteBookingIemByUuid( public ResponseEntity<Void> deleteBookingIemByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -125,6 +130,7 @@ public class HsBookingItemController implements HsBookingItemsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.bookingItems.api.patchBookingItem")
public ResponseEntity<HsBookingItemResource> patchBookingItem( public ResponseEntity<HsBookingItemResource> patchBookingItem(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.booking.item; package net.hostsharing.hsadminng.hs.booking.item;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -9,15 +10,21 @@ import java.util.UUID;
public interface HsBookingItemRbacRepository extends HsBookingItemRepository<HsBookingItemRbacEntity>, public interface HsBookingItemRbacRepository extends HsBookingItemRepository<HsBookingItemRbacEntity>,
Repository<HsBookingItemRbacEntity, UUID> { Repository<HsBookingItemRbacEntity, UUID> {
@Timed("app.bookingItems.repo.findByUuid.rbac")
Optional<HsBookingItemRbacEntity> findByUuid(final UUID bookingItemUuid); Optional<HsBookingItemRbacEntity> findByUuid(final UUID bookingItemUuid);
@Timed("app.bookingItems.repo.findByCaption.rbac")
List<HsBookingItemRbacEntity> findByCaption(String bookingItemCaption); List<HsBookingItemRbacEntity> findByCaption(String bookingItemCaption);
@Timed("app.bookingItems.repo.findAllByProjectUuid.rbac")
List<HsBookingItemRbacEntity> findAllByProjectUuid(final UUID projectItemUuid); List<HsBookingItemRbacEntity> findAllByProjectUuid(final UUID projectItemUuid);
@Timed("app.bookingItems.repo.save.rbac")
HsBookingItemRbacEntity save(HsBookingItemRbacEntity current); HsBookingItemRbacEntity save(HsBookingItemRbacEntity current);
@Timed("app.bookingItems.repo.deleteByUuid.rbac")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.bookingItems.repo.count.rbac")
long count(); long count();
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.booking.item; package net.hostsharing.hsadminng.hs.booking.item;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -9,15 +10,21 @@ import java.util.UUID;
public interface HsBookingItemRealRepository extends HsBookingItemRepository<HsBookingItemRealEntity>, public interface HsBookingItemRealRepository extends HsBookingItemRepository<HsBookingItemRealEntity>,
Repository<HsBookingItemRealEntity, UUID> { Repository<HsBookingItemRealEntity, UUID> {
@Timed("app.bookingItems.repo.findByUuid.real")
Optional<HsBookingItemRealEntity> findByUuid(final UUID bookingItemUuid); Optional<HsBookingItemRealEntity> findByUuid(final UUID bookingItemUuid);
@Timed("app.bookingItems.repo.findByCaption.real")
List<HsBookingItemRealEntity> findByCaption(String bookingItemCaption); List<HsBookingItemRealEntity> findByCaption(String bookingItemCaption);
@Timed("app.bookingItems.repo.findAllByProjectUuid.real")
List<HsBookingItemRealEntity> findAllByProjectUuid(final UUID projectItemUuid); List<HsBookingItemRealEntity> findAllByProjectUuid(final UUID projectItemUuid);
@Timed("app.bookingItems.repo.save.real")
HsBookingItemRealEntity save(HsBookingItemRealEntity current); HsBookingItemRealEntity save(HsBookingItemRealEntity current);
@Timed("app.bookingItems.repo.deleteByUuid.real")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.bookingItems.repo.count.real")
long count(); long count();
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.booking.item; package net.hostsharing.hsadminng.hs.booking.item;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.booking.project; package net.hostsharing.hsadminng.hs.booking.project;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorRepository; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorRepository;
import net.hostsharing.hsadminng.hs.booking.generated.api.v1.api.HsBookingProjectsApi; import net.hostsharing.hsadminng.hs.booking.generated.api.v1.api.HsBookingProjectsApi;
@ -35,7 +36,8 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<HsBookingProjectResource>> listBookingProjectsByDebitorUuid( @Timed("app.bookingProjects.api.getListOfBookingProjectsByDebitorUuid")
public ResponseEntity<List<HsBookingProjectResource>> getListOfBookingProjectsByDebitorUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID debitorUuid) { final UUID debitorUuid) {
@ -49,7 +51,8 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<HsBookingProjectResource> addBookingProject( @Timed("app.bookingProjects.api.postNewBookingProject")
public ResponseEntity<HsBookingProjectResource> postNewBookingProject(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final HsBookingProjectInsertResource body) { final HsBookingProjectInsertResource body) {
@ -71,6 +74,7 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Timed("app.bookingProjects.api.getBookingProjectByUuid")
public ResponseEntity<HsBookingProjectResource> getBookingProjectByUuid( public ResponseEntity<HsBookingProjectResource> getBookingProjectByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -87,6 +91,7 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.bookingProjects.api.deleteBookingIemByUuid")
public ResponseEntity<Void> deleteBookingIemByUuid( public ResponseEntity<Void> deleteBookingIemByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -101,6 +106,7 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.bookingProjects.api.patchBookingProject")
public ResponseEntity<HsBookingProjectResource> patchBookingProject( public ResponseEntity<HsBookingProjectResource> patchBookingProject(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.booking.project; package net.hostsharing.hsadminng.hs.booking.project;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -9,14 +10,21 @@ import java.util.UUID;
public interface HsBookingProjectRbacRepository extends HsBookingProjectRepository<HsBookingProjectRbacEntity>, public interface HsBookingProjectRbacRepository extends HsBookingProjectRepository<HsBookingProjectRbacEntity>,
Repository<HsBookingProjectRbacEntity, UUID> { Repository<HsBookingProjectRbacEntity, UUID> {
@Timed("app.bookingProjects.repo.findByUuid.rbac")
Optional<HsBookingProjectRbacEntity> findByUuid(final UUID bookingProjectUuid); Optional<HsBookingProjectRbacEntity> findByUuid(final UUID bookingProjectUuid);
@Timed("app.bookingProjects.repo.findByCaption.rbac")
List<HsBookingProjectRbacEntity> findByCaption(final String projectCaption); List<HsBookingProjectRbacEntity> findByCaption(final String projectCaption);
@Timed("app.bookingProjects.repo.findAllByDebitorUuid.rbac")
List<HsBookingProjectRbacEntity> findAllByDebitorUuid(final UUID bookingProjectUuid); List<HsBookingProjectRbacEntity> findAllByDebitorUuid(final UUID bookingProjectUuid);
@Timed("app.bookingProjects.repo.save.rbac")
HsBookingProjectRbacEntity save(HsBookingProjectRbacEntity current); HsBookingProjectRbacEntity save(HsBookingProjectRbacEntity current);
@Timed("app.bookingProjects.repo.deleteByUuid.rbac")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.bookingProjects.repo.count.rbac")
long count(); long count();
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.booking.project; package net.hostsharing.hsadminng.hs.booking.project;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -9,14 +10,21 @@ import java.util.UUID;
public interface HsBookingProjectRealRepository extends HsBookingProjectRepository<HsBookingProjectRealEntity>, public interface HsBookingProjectRealRepository extends HsBookingProjectRepository<HsBookingProjectRealEntity>,
Repository<HsBookingProjectRealEntity, UUID> { Repository<HsBookingProjectRealEntity, UUID> {
@Timed("app.bookingProjects.repo.findByUuid.real")
Optional<HsBookingProjectRealEntity> findByUuid(final UUID bookingProjectUuid); Optional<HsBookingProjectRealEntity> findByUuid(final UUID bookingProjectUuid);
@Timed("app.bookingProjects.repo.findByCaption.real")
List<HsBookingProjectRealEntity> findByCaption(final String projectCaption); List<HsBookingProjectRealEntity> findByCaption(final String projectCaption);
@Timed("app.bookingProjects.repo.findAllByDebitorUuid.real")
List<HsBookingProjectRealEntity> findAllByDebitorUuid(final UUID bookingProjectUuid); List<HsBookingProjectRealEntity> findAllByDebitorUuid(final UUID bookingProjectUuid);
@Timed("app.bookingProjects.repo.save.real")
HsBookingProjectRealEntity save(HsBookingProjectRealEntity current); HsBookingProjectRealEntity save(HsBookingProjectRealEntity current);
@Timed("app.bookingProjects.repo.deleteByUuid.real")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.bookingProjects.repo.count.real")
long count(); long count();
} }

View File

@ -1,19 +1,28 @@
package net.hostsharing.hsadminng.hs.booking.project; package net.hostsharing.hsadminng.hs.booking.project;
import io.micrometer.core.annotation.Timed;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public interface HsBookingProjectRepository<E extends HsBookingProject> { public interface HsBookingProjectRepository<E extends HsBookingProject> {
Optional<E> findByUuid(final UUID bookingProjectUuid); @Timed("app.booking.projects.repo.findByUuid")
Optional<E> findByUuid(final UUID findByUuid);
@Timed("app.booking.projects.repo.findByCaption")
List<E> findByCaption(final String projectCaption); List<E> findByCaption(final String projectCaption);
@Timed("app.booking.projects.repo.findAllByDebitorUuid")
List<E> findAllByDebitorUuid(final UUID bookingProjectUuid); List<E> findAllByDebitorUuid(final UUID bookingProjectUuid);
@Timed("app.booking.projects.repo.save")
E save(E current); E save(E current);
@Timed("app.booking.projects.repo.deleteByUuid")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.booking.projects.repo.count")
long count(); long count();
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealRepository; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealRepository;
import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor; import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor;
import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntityValidatorRegistry;
@ -48,7 +49,8 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<HsHostingAssetResource>> listAssets( @Timed("app.hosting.assets.api.getListOfHostingAssets")
public ResponseEntity<List<HsHostingAssetResource>> getListOfHostingAssets(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID debitorUuid, final UUID debitorUuid,
@ -65,7 +67,8 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<HsHostingAssetResource> addAsset( @Timed("app.hosting.assets.api.postNewHostingAsset")
public ResponseEntity<HsHostingAssetResource> postNewHostingAsset(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final HsHostingAssetInsertResource body) { final HsHostingAssetInsertResource body) {
@ -93,7 +96,8 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<HsHostingAssetResource> getAssetByUuid( @Timed("app.hosting.assets.api.getSingleHostingAssetByUuid")
public ResponseEntity<HsHostingAssetResource> getSingleHostingAssetByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID assetUuid) { final UUID assetUuid) {
@ -109,7 +113,8 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<Void> deleteAssetUuid( @Timed("app.hosting.assets.api.deleteHostingAssetByUuid")
public ResponseEntity<Void> deleteHostingAssetByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID assetUuid) { final UUID assetUuid) {
@ -123,7 +128,8 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<HsHostingAssetResource> patchAsset( @Timed("app.hosting.assets.api.patchHostingAsset")
public ResponseEntity<HsHostingAssetResource> patchHostingAsset(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID assetUuid, final UUID assetUuid,

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntityValidatorRegistry;
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.api.HsHostingAssetPropsApi; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.api.HsHostingAssetPropsApi;
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetTypeResource; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetTypeResource;
@ -14,7 +15,8 @@ import java.util.Map;
public class HsHostingAssetPropsController implements HsHostingAssetPropsApi { public class HsHostingAssetPropsController implements HsHostingAssetPropsApi {
@Override @Override
public ResponseEntity<List<String>> listAssetTypes() { @Timed("app.hosting.assets.api.getListOfHostingAssetTypes")
public ResponseEntity<List<String>> getListOfHostingAssetTypes() {
final var resource = HostingAssetEntityValidatorRegistry.types().stream() final var resource = HostingAssetEntityValidatorRegistry.types().stream()
.map(Enum::name) .map(Enum::name)
.toList(); .toList();
@ -22,7 +24,8 @@ public class HsHostingAssetPropsController implements HsHostingAssetPropsApi {
} }
@Override @Override
public ResponseEntity<List<Object>> listAssetTypeProps( @Timed("app.hosting.assets.api.getListOfHostingAssetTypeProps")
public ResponseEntity<List<Object>> getListOfHostingAssetTypeProps(
final HsHostingAssetTypeResource assetType) { final HsHostingAssetTypeResource assetType) {
final Enum<HsHostingAssetType> type = HsHostingAssetType.of(assetType); final Enum<HsHostingAssetType> type = HsHostingAssetType.of(assetType);

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
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;
@ -10,8 +11,10 @@ import java.util.UUID;
public interface HsHostingAssetRbacRepository extends HsHostingAssetRepository<HsHostingAssetRbacEntity>, Repository<HsHostingAssetRbacEntity, UUID> { public interface HsHostingAssetRbacRepository extends HsHostingAssetRepository<HsHostingAssetRbacEntity>, Repository<HsHostingAssetRbacEntity, UUID> {
@Timed("app.hostingAsset.repo.findByUuid.rbac")
Optional<HsHostingAssetRbacEntity> findByUuid(final UUID serverUuid); Optional<HsHostingAssetRbacEntity> findByUuid(final UUID serverUuid);
@Timed("app.hostingAsset.repo.findByIdentifier.rbac")
List<HsHostingAssetRbacEntity> findByIdentifier(String assetIdentifier); List<HsHostingAssetRbacEntity> findByIdentifier(String assetIdentifier);
@Query(value = """ @Query(value = """
@ -32,16 +35,21 @@ public interface HsHostingAssetRbacRepository extends HsHostingAssetRepository<H
and (:parentAssetUuid is null or pha.uuid=:parentAssetUuid) and (:parentAssetUuid is null or pha.uuid=:parentAssetUuid)
and (:type is null or :type=cast(ha.type as text)) and (:type is null or :type=cast(ha.type as text))
""", nativeQuery = true) """, nativeQuery = true)
@Timed("app.hostingAsset.repo.findAllByCriteriaImpl.rbac")
// The JPQL query did not generate "left join" but just "join". // The JPQL query did not generate "left join" but just "join".
// I also optimized the query by not using the _rv for hs_booking.item and hs_hosting.asset, only for hs_hosting.asset_rv. // I also optimized the query by not using the _rv for hs_booking.item and hs_hosting.asset, only for hs_hosting.asset_rv.
List<HsHostingAssetRbacEntity> findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); List<HsHostingAssetRbacEntity> findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type);
default List<HsHostingAssetRbacEntity> findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { default List<HsHostingAssetRbacEntity> findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) {
return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type));
} }
@Timed("app.hostingAsset.repo.save.rbac")
HsHostingAssetRbacEntity save(HsHostingAsset current); HsHostingAssetRbacEntity save(HsHostingAsset current);
@Timed("app.hostingAsset.repo.deleteByUuid.rbac")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.hostingAsset.repo.count.rbac")
long count(); long count();
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
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;
@ -10,8 +11,10 @@ import java.util.UUID;
public interface HsHostingAssetRealRepository extends HsHostingAssetRepository<HsHostingAssetRealEntity>, Repository<HsHostingAssetRealEntity, UUID> { public interface HsHostingAssetRealRepository extends HsHostingAssetRepository<HsHostingAssetRealEntity>, Repository<HsHostingAssetRealEntity, UUID> {
@Timed("app.hostingAsset.repo.findByUuid.real")
Optional<HsHostingAssetRealEntity> findByUuid(final UUID serverUuid); Optional<HsHostingAssetRealEntity> findByUuid(final UUID serverUuid);
@Timed("app.hostingAsset.repo.findByIdentifier.real")
List<HsHostingAssetRealEntity> findByIdentifier(String assetIdentifier); List<HsHostingAssetRealEntity> findByIdentifier(String assetIdentifier);
default List<HsHostingAssetRealEntity> findByTypeAndIdentifier(@NotNull HsHostingAssetType type, @NotNull String identifier) { default List<HsHostingAssetRealEntity> findByTypeAndIdentifier(@NotNull HsHostingAssetType type, @NotNull String identifier) {
@ -24,6 +27,7 @@ public interface HsHostingAssetRealRepository extends HsHostingAssetRepository<H
where cast(ha.type as String) = :type where cast(ha.type as String) = :type
and ha.identifier = :identifier and ha.identifier = :identifier
""") """)
@Timed("app.hostingAsset.repo.findByTypeAndIdentifierImpl.real")
List<HsHostingAssetRealEntity> findByTypeAndIdentifierImpl(@NotNull String type, @NotNull String identifier); List<HsHostingAssetRealEntity> findByTypeAndIdentifierImpl(@NotNull String type, @NotNull String identifier);
@Query(value = """ @Query(value = """
@ -46,14 +50,19 @@ public interface HsHostingAssetRealRepository extends HsHostingAssetRepository<H
""", nativeQuery = true) """, nativeQuery = true)
// The JPQL query did not generate "left join" but just "join". // The JPQL query did not generate "left join" but just "join".
// I also optimized the query by not using the _rv for hs_booking.item and hs_hosting.asset, only for hs_hosting.asset_rv. // I also optimized the query by not using the _rv for hs_booking.item and hs_hosting.asset, only for hs_hosting.asset_rv.
@Timed("app.hostingAsset.repo.findAllByCriteriaImpl.real")
List<HsHostingAssetRealEntity> findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); List<HsHostingAssetRealEntity> findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type);
default List<HsHostingAssetRealEntity> findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { default List<HsHostingAssetRealEntity> findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) {
return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type));
} }
@Timed("app.hostingAsset.repo.save.real")
HsHostingAssetRealEntity save(HsHostingAssetRealEntity current); HsHostingAssetRealEntity save(HsHostingAssetRealEntity current);
@Timed("app.hostingAsset.repo.deleteByUuid.real")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.hostingAsset.repo.count.real")
long count(); long count();
} }

View File

@ -1,24 +1,32 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
import io.micrometer.core.annotation.Timed;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public interface HsHostingAssetRepository<E extends HsHostingAsset> { public interface HsHostingAssetRepository<E extends HsHostingAsset> {
@Timed("app.hosting.assets.repo.findByUuid")
Optional<E> findByUuid(final UUID serverUuid); Optional<E> findByUuid(final UUID serverUuid);
@Timed("app.hosting.assets.repo.findByIdentifier")
List<E> findByIdentifier(String assetIdentifier); List<E> findByIdentifier(String assetIdentifier);
@Timed("app.hosting.assets.repo.findAllByCriteriaImpl")
List<E> findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); List<E> findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type);
default List<E> findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { default List<E> findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) {
return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type));
} }
@Timed("app.hosting.assets.repo.save")
E save(HsHostingAsset current); E save(HsHostingAsset current);
@Timed("app.hosting.assets.repo.deleteByUuid")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.hosting.assets.repo.count")
long count(); long count();
} }

View File

@ -20,6 +20,7 @@ public interface HsOfficeBankAccountRepository extends Repository<HsOfficeBankAc
""") """)
@Timed("app.bankAccounts.repo.findByOptionalHolderLikeImpl") @Timed("app.bankAccounts.repo.findByOptionalHolderLikeImpl")
List<HsOfficeBankAccountEntity> findByOptionalHolderLikeImpl(String holder); List<HsOfficeBankAccountEntity> findByOptionalHolderLikeImpl(String holder);
default List<HsOfficeBankAccountEntity> findByOptionalHolderLike(String holder) { default List<HsOfficeBankAccountEntity> findByOptionalHolderLike(String holder) {
return findByOptionalHolderLikeImpl(holder == null ? "" : holder); return findByOptionalHolderLikeImpl(holder == null ? "" : holder);
} }

View File

@ -21,13 +21,13 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
WHERE partner.partnerNumber = :partnerNumber WHERE partner.partnerNumber = :partnerNumber
AND debitor.debitorNumberSuffix = :debitorNumberSuffix AND debitor.debitorNumberSuffix = :debitorNumberSuffix
""") """)
@Timed("app.debitors.repo.findDebitorByDebitorNumber") @Timed("app.debitors.repo.findDebitorByPartnerNumberAndDebitorNumberSuffix")
List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int partnerNumber, String debitorNumberSuffix); List<HsOfficeDebitorEntity> findDebitorByPartnerNumberAndDebitorNumberSuffix(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;
final String suffix = String.format("%02d", debitorNumber % 100); final String suffix = String.format("%02d", debitorNumber % 100);
final var result = findDebitorByDebitorNumber(partnerNumber, suffix); final var result = findDebitorByPartnerNumberAndDebitorNumberSuffix(partnerNumber, suffix);
return result; return result;
} }

View File

@ -34,7 +34,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Timed("app.membership.api.getListOfMemberships") @Timed("app.office.membership.api.getListOfMemberships")
public ResponseEntity<List<HsOfficeMembershipResource>> getListOfMemberships( public ResponseEntity<List<HsOfficeMembershipResource>> getListOfMemberships(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -55,7 +55,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.membership.api.postNewMembership") @Timed("app.office.membership.api.postNewMembership")
public ResponseEntity<HsOfficeMembershipResource> postNewMembership( public ResponseEntity<HsOfficeMembershipResource> postNewMembership(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -79,7 +79,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Timed("app.membership.api.getSingleMembershipByUuid") @Timed("app.office.membership.api.getSingleMembershipByUuid")
public ResponseEntity<HsOfficeMembershipResource> getSingleMembershipByUuid( public ResponseEntity<HsOfficeMembershipResource> getSingleMembershipByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -97,7 +97,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.membership.api.deleteMembershipByUuid") @Timed("app.office.membership.api.deleteMembershipByUuid")
public ResponseEntity<Void> deleteMembershipByUuid( public ResponseEntity<Void> deleteMembershipByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -114,7 +114,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.membership.api.patchMembership") @Timed("app.office.membership.api.patchMembership")
public ResponseEntity<HsOfficeMembershipResource> patchMembership( public ResponseEntity<HsOfficeMembershipResource> patchMembership(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,

View File

@ -11,13 +11,13 @@ import java.util.UUID;
public interface HsOfficeMembershipRepository extends Repository<HsOfficeMembershipEntity, UUID> { public interface HsOfficeMembershipRepository extends Repository<HsOfficeMembershipEntity, UUID> {
@Timed("app.membership.repo.findByUuid") @Timed("app.office.membership.repo.findByUuid")
Optional<HsOfficeMembershipEntity> findByUuid(UUID id); Optional<HsOfficeMembershipEntity> findByUuid(UUID id);
@Timed("app.membership.repo.save") @Timed("app.office.membership.repo.save")
HsOfficeMembershipEntity save(final HsOfficeMembershipEntity entity); HsOfficeMembershipEntity save(final HsOfficeMembershipEntity entity);
@Timed("app.membership.repo.findAll") @Timed("app.office.membership.repo.findAll")
List<HsOfficeMembershipEntity> findAll(); List<HsOfficeMembershipEntity> findAll();
@Query(""" @Query("""
@ -26,7 +26,7 @@ public interface HsOfficeMembershipRepository extends Repository<HsOfficeMembers
OR membership.partner.uuid = :partnerUuid ) OR membership.partner.uuid = :partnerUuid )
ORDER BY membership.partner.partnerNumber, membership.memberNumberSuffix ORDER BY membership.partner.partnerNumber, membership.memberNumberSuffix
""") """)
@Timed("app.membership.repo.findMembershipsByOptionalPartnerUuid") @Timed("app.office.membership.repo.findMembershipsByOptionalPartnerUuid")
List<HsOfficeMembershipEntity> findMembershipsByOptionalPartnerUuid(UUID partnerUuid); List<HsOfficeMembershipEntity> findMembershipsByOptionalPartnerUuid(UUID partnerUuid);
@Query(""" @Query("""
@ -35,7 +35,7 @@ public interface HsOfficeMembershipRepository extends Repository<HsOfficeMembers
AND (membership.memberNumberSuffix = :suffix) AND (membership.memberNumberSuffix = :suffix)
ORDER BY membership.memberNumberSuffix ORDER BY membership.memberNumberSuffix
""") """)
@Timed("app.membership.repo.findMembershipByPartnerNumberAndSuffix") @Timed("app.office.membership.repo.findMembershipByPartnerNumberAndSuffix")
HsOfficeMembershipEntity findMembershipByPartnerNumberAndSuffix( HsOfficeMembershipEntity findMembershipByPartnerNumberAndSuffix(
@NotNull Integer partnerNumber, @NotNull Integer partnerNumber,
@NotNull String suffix); @NotNull String suffix);
@ -47,9 +47,9 @@ public interface HsOfficeMembershipRepository extends Repository<HsOfficeMembers
return result; return result;
} }
@Timed("app.membership.repo.count") @Timed("app.office.membership.repo.count")
long count(); long count();
@Timed("app.membership.repo.deleteByUuid") @Timed("app.office.membership.repo.deleteByUuid")
int deleteByUuid(UUID uuid); int deleteByUuid(UUID uuid);
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.grant; package net.hostsharing.hsadminng.rbac.grant;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -7,9 +8,12 @@ import java.util.UUID;
public interface RawRbacGrantRepository extends Repository<RawRbacGrantEntity, UUID> { public interface RawRbacGrantRepository extends Repository<RawRbacGrantEntity, UUID> {
List<RawRbacGrantEntity> findAll(); @Timed("app.rbac.grants.repo.findAll")
List<RawRbacGrantEntity> findAll(); // TODO.refa: move to test repo
@Timed("app.rbac.grants.repo.findByAscendingUuid")
List<RawRbacGrantEntity> findByAscendingUuid(UUID ascendingUuid); List<RawRbacGrantEntity> findByAscendingUuid(UUID ascendingUuid);
@Timed("app.rbac.grants.repo.findByDescendantUuid")
List<RawRbacGrantEntity> findByDescendantUuid(UUID refUuid); List<RawRbacGrantEntity> findByDescendantUuid(UUID refUuid);
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.grant; package net.hostsharing.hsadminng.rbac.grant;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.mapper.StandardMapper; import net.hostsharing.hsadminng.mapper.StandardMapper;
import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacGrantsApi; import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacGrantsApi;
@ -32,7 +33,8 @@ public class RbacGrantController implements RbacGrantsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<RbacGrantResource> getGrantById( @Timed("app.rbac.grants.api.getListOfGrantsByUuid")
public ResponseEntity<RbacGrantResource> getListOfGrantsByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID grantedRoleUuid, final UUID grantedRoleUuid,
@ -50,7 +52,8 @@ public class RbacGrantController implements RbacGrantsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<RbacGrantResource>> listSubjectGrants( @Timed("app.rbac.grants.api.getListOfSubjectGrants")
public ResponseEntity<List<RbacGrantResource>> getListOfSubjectGrants(
final String currentSubject, final String currentSubject,
final String assumedRoles) { final String assumedRoles) {
@ -61,7 +64,8 @@ public class RbacGrantController implements RbacGrantsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<RbacGrantResource> grantRoleToSubject( @Timed("app.rbac.grants.api.postNewRoleGrantToSubject")
public ResponseEntity<RbacGrantResource> postNewRoleGrantToSubject(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final RbacGrantResource body) { final RbacGrantResource body) {
@ -82,7 +86,8 @@ public class RbacGrantController implements RbacGrantsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<Void> revokeRoleFromSubject( @Timed("app.rbac.grants.api.deleteRoleGrantFromSubject")
public ResponseEntity<Void> deleteRoleGrantFromSubject(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID grantedRoleUuid, final UUID grantedRoleUuid,

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.grant; package net.hostsharing.hsadminng.rbac.grant;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
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;
@ -13,12 +14,16 @@ public interface RbacGrantRepository extends Repository<RbacGrantEntity, RbacGra
where g.grantedRoleUuid=:#{#rbacGrantId.grantedRoleUuid} where g.grantedRoleUuid=:#{#rbacGrantId.grantedRoleUuid}
and g.granteeSubjectUuid=:#{#rbacGrantId.granteeSubjectUuid} and g.granteeSubjectUuid=:#{#rbacGrantId.granteeSubjectUuid}
""") """)
@Timed("app.rbac.grants.repo.findById")
RbacGrantEntity findById(RbacGrantId rbacGrantId); RbacGrantEntity findById(RbacGrantId rbacGrantId);
@Timed("app.rbac.grants.repo.count")
long count(); long count();
@Timed("app.rbac.grants.repo.findAll")
List<RbacGrantEntity> findAll(); List<RbacGrantEntity> findAll();
@Timed("app.rbac.grants.repo.save")
RbacGrantEntity save(final RbacGrantEntity grant); RbacGrantEntity save(final RbacGrantEntity grant);
@Modifying @Modifying
@ -27,5 +32,6 @@ public interface RbacGrantRepository extends Repository<RbacGrantEntity, RbacGra
where g.grantedRoleUuid=:#{#rbacGrantId.grantedRoleUuid} where g.grantedRoleUuid=:#{#rbacGrantId.grantedRoleUuid}
and g.granteeSubjectUuid=:#{#rbacGrantId.granteeSubjectUuid} and g.granteeSubjectUuid=:#{#rbacGrantId.granteeSubjectUuid}
""") """)
@Timed("app.rbac.grants.repo.deleteByRbacGrantId")
void deleteByRbacGrantId(RbacGrantId rbacGrantId); void deleteByRbacGrantId(RbacGrantId rbacGrantId);
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.role; package net.hostsharing.hsadminng.rbac.role;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.mapper.StandardMapper; import net.hostsharing.hsadminng.mapper.StandardMapper;
import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacRolesApi; import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacRolesApi;
@ -25,7 +26,8 @@ public class RbacRoleController implements RbacRolesApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<RbacRoleResource>> listRoles( @Timed("app.rbac.roles.api.getListOfRoles")
public ResponseEntity<List<RbacRoleResource>> getListOfRoles(
final String currentSubject, final String currentSubject,
final String assumedRoles) { final String assumedRoles) {

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.role; package net.hostsharing.hsadminng.rbac.role;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -10,12 +11,15 @@ public interface RbacRoleRepository extends Repository<RbacRoleEntity, UUID> {
/** /**
* @return the number of persistent RbacRoleEntity instances, mostly for testing purposes. * @return the number of persistent RbacRoleEntity instances, mostly for testing purposes.
*/ */
long count(); // TODO: move to test sources @Timed("app.rbac.roles.repo.findByUuid")
long count(); // TODO.refa: move to test sources
/** /**
* @return all persistent RbacRoleEntity instances, assigned to the current subject (user or assumed roles) * @return all persistent RbacRoleEntity instances, assigned to the current subject (user or assumed roles)
*/ */
List<RbacRoleEntity> findAll(); @Timed("app.rbac.roles.repo.findAll")
List<RbacRoleEntity> findAll(); // TODO.refa: move to test sources
@Timed("app.rbac.roles.repo.findByRoleName")
RbacRoleEntity findByRoleName(String roleName); RbacRoleEntity findByRoleName(String roleName);
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.subject; package net.hostsharing.hsadminng.rbac.subject;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.mapper.StandardMapper; import net.hostsharing.hsadminng.mapper.StandardMapper;
import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacSubjectsApi; import net.hostsharing.hsadminng.rbac.generated.api.v1.api.RbacSubjectsApi;
@ -28,7 +29,8 @@ public class RbacSubjectController implements RbacSubjectsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<RbacSubjectResource> createSubject( @Timed("app.rbac.subjects.api.postNewSubject")
public ResponseEntity<RbacSubjectResource> postNewSubject(
final RbacSubjectResource body final RbacSubjectResource body
) { ) {
context.define(null); context.define(null);
@ -48,6 +50,7 @@ public class RbacSubjectController implements RbacSubjectsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.rbac.subjects.api.deleteSubjectByUuid")
public ResponseEntity<Void> deleteSubjectByUuid( public ResponseEntity<Void> deleteSubjectByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -62,7 +65,8 @@ public class RbacSubjectController implements RbacSubjectsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<RbacSubjectResource> getSubjectById( @Timed("app.rbac.subjects.api.getSingleSubjectByUuid")
public ResponseEntity<RbacSubjectResource> getSingleSubjectByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID subjectUuid) { final UUID subjectUuid) {
@ -78,7 +82,8 @@ public class RbacSubjectController implements RbacSubjectsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<RbacSubjectResource>> listSubjects( @Timed("app.rbac.subjects.api.getListOfSubjects")
public ResponseEntity<List<RbacSubjectResource>> getListOfSubjects(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final String userName final String userName
@ -90,7 +95,8 @@ public class RbacSubjectController implements RbacSubjectsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<RbacSubjectPermissionResource>> listSubjectPermissions( @Timed("app.rbac.subjects.api.getListOfSubjectPermissions")
public ResponseEntity<List<RbacSubjectPermissionResource>> getListOfSubjectPermissions(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID subjectUuid final UUID subjectUuid

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.subject; package net.hostsharing.hsadminng.rbac.subject;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
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;
@ -14,15 +15,19 @@ public interface RbacSubjectRepository extends Repository<RbacSubjectEntity, UUI
where :userName is null or u.name like concat(cast(:userName as text), '%') where :userName is null or u.name like concat(cast(:userName as text), '%')
order by u.name order by u.name
""") """)
@Timed("app.rbac.subjects.repo.findByOptionalNameLike")
List<RbacSubjectEntity> findByOptionalNameLike(String userName); List<RbacSubjectEntity> findByOptionalNameLike(String userName);
// bypasses the restricted view, to be able to grant rights to arbitrary user // bypasses the restricted view, to be able to grant rights to arbitrary user
@Query(value = "select * from rbac.subject where name=:userName", nativeQuery = true) @Query(value = "select * from rbac.subject where name=:userName", nativeQuery = true)
@Timed("app.rbac.subjects.repo.findByName")
RbacSubjectEntity findByName(String userName); RbacSubjectEntity findByName(String userName);
@Timed("app.rbac.subjects.repo.findByUuid")
RbacSubjectEntity findByUuid(UUID uuid); RbacSubjectEntity findByUuid(UUID uuid);
@Query(value = "select * from rbac.grantedPermissions(:subjectUuid)", nativeQuery = true) @Query(value = "select * from rbac.grantedPermissions(:subjectUuid)", nativeQuery = true)
@Timed("app.rbac.subjects.repo.findPermissionsOfUserByUuid")
List<RbacSubjectPermission> findPermissionsOfUserByUuid(UUID subjectUuid); List<RbacSubjectPermission> findPermissionsOfUserByUuid(UUID subjectUuid);
/* /*
@ -32,6 +37,7 @@ public interface RbacSubjectRepository extends Repository<RbacSubjectEntity, UUI
*/ */
@Modifying @Modifying
@Query(value = "insert into rbac.subject_rv (uuid, name) values( :#{#newUser.uuid}, :#{#newUser.name})", nativeQuery = true) @Query(value = "insert into rbac.subject_rv (uuid, name) values( :#{#newUser.uuid}, :#{#newUser.name})", nativeQuery = true)
@Timed("app.rbac.subjects.repo.insert")
void insert(final RbacSubjectEntity newUser); void insert(final RbacSubjectEntity newUser);
default RbacSubjectEntity create(final RbacSubjectEntity rbacSubjectEntity) { default RbacSubjectEntity create(final RbacSubjectEntity rbacSubjectEntity) {
@ -42,5 +48,6 @@ public interface RbacSubjectRepository extends Repository<RbacSubjectEntity, UUI
return rbacSubjectEntity; return rbacSubjectEntity;
} }
@Timed("app.rbac.subjects.repo.deleteByUuid")
void deleteByUuid(UUID subjectUuid); void deleteByUuid(UUID subjectUuid);
} }

View File

@ -2,7 +2,7 @@ get:
tags: tags:
- hs-booking-items - hs-booking-items
description: 'Fetch a single booking item its uuid, if visible for the current subject.' description: 'Fetch a single booking item its uuid, if visible for the current subject.'
operationId: getBookingItemByUuid operationId: getSingleBookingItemByUuid
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'

View File

@ -3,7 +3,7 @@ get:
description: Returns the list of all booking items for a specified project which are visible to the current subject or any of it's assumed roles. description: Returns the list of all booking items for a specified project which are visible to the current subject or any of it's assumed roles.
tags: tags:
- hs-booking-items - hs-booking-items
operationId: listBookingItemsByProjectUuid operationId: getListOfBookingItemsByProjectUuid
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'
@ -32,7 +32,7 @@ post:
summary: Adds a new booking item. summary: Adds a new booking item.
tags: tags:
- hs-booking-items - hs-booking-items
operationId: addBookingItem operationId: postNewBookingItem
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'

View File

@ -3,7 +3,7 @@ get:
description: Returns the list of all booking projects for a specified debitor which are visible to the current subject or any of it's assumed roles. description: Returns the list of all booking projects for a specified debitor which are visible to the current subject or any of it's assumed roles.
tags: tags:
- hs-booking-projects - hs-booking-projects
operationId: listBookingProjectsByDebitorUuid operationId: getListOfBookingProjectsByDebitorUuid
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'
@ -32,7 +32,7 @@ post:
summary: Adds a new project as a container for booking items. summary: Adds a new project as a container for booking items.
tags: tags:
- hs-booking-projects - hs-booking-projects
operationId: addBookingProject operationId: postNewBookingProject
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'

View File

@ -3,7 +3,7 @@ get:
description: Returns the list of available properties and their validations for a given asset type. description: Returns the list of available properties and their validations for a given asset type.
tags: tags:
- hs-hosting-asset-props - hs-hosting-asset-props
operationId: listAssetTypeProps operationId: getListOfHostingAssetTypeProps
parameters: parameters:
- name: assetType - name: assetType
in: path in: path

View File

@ -3,7 +3,7 @@ get:
description: Returns the list of asset types to enable an adaptive UI. description: Returns the list of asset types to enable an adaptive UI.
tags: tags:
- hs-hosting-asset-props - hs-hosting-asset-props
operationId: listAssetTypes operationId: getListOfHostingAssetTypes
responses: responses:
"200": "200":
description: OK description: OK

View File

@ -2,7 +2,7 @@ get:
tags: tags:
- hs-hosting-assets - hs-hosting-assets
description: 'Fetch a single managed asset by its uuid, if visible for the current subject.' description: 'Fetch a single managed asset by its uuid, if visible for the current subject.'
operationId: getAssetByUuid operationId: getSingleHostingAssetByUuid
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'
@ -30,7 +30,7 @@ patch:
tags: tags:
- hs-hosting-assets - hs-hosting-assets
description: 'Updates a single hosting asset identified by its uuid, if permitted for the current subject.' description: 'Updates a single hosting asset identified by its uuid, if permitted for the current subject.'
operationId: patchAsset operationId: patchHostingAsset
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'
@ -61,7 +61,7 @@ delete:
tags: tags:
- hs-hosting-assets - hs-hosting-assets
description: 'Delete a single hosting asset identified by its uuid, if permitted for the current subject.' description: 'Delete a single hosting asset identified by its uuid, if permitted for the current subject.'
operationId: deleteAssetUuid operationId: deleteHostingAssetByUuid
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'

View File

@ -3,7 +3,7 @@ get:
description: Returns the list of all hosting assets which match the given filters and are visible to the current subject or any of it's assumed roles. description: Returns the list of all hosting assets which match the given filters and are visible to the current subject or any of it's assumed roles.
tags: tags:
- hs-hosting-assets - hs-hosting-assets
operationId: listAssets operationId: getListOfHostingAssets
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'
@ -45,7 +45,7 @@ post:
summary: Adds a new hosting asset. summary: Adds a new hosting asset.
tags: tags:
- hs-hosting-assets - hs-hosting-assets
operationId: addAsset operationId: postNewHostingAsset
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'

View File

@ -1,7 +1,7 @@
get: get:
tags: tags:
- rbac-grants - rbac-grants
operationId: getGrantById operationId: getListOfGrantsByUuid
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'
@ -36,7 +36,7 @@ get:
delete: delete:
tags: tags:
- rbac-grants - rbac-grants
operationId: revokeRoleFromSubject operationId: deleteRoleGrantFromSubject
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'

View File

@ -1,7 +1,7 @@
get: get:
tags: tags:
- rbac-grants - rbac-grants
operationId: listSubjectGrants operationId: getListOfSubjectGrants
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'
@ -18,7 +18,7 @@ get:
post: post:
tags: tags:
- rbac-grants - rbac-grants
operationId: grantRoleToSubject operationId: postNewRoleGrantToSubject
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'

View File

@ -1,7 +1,7 @@
get: get:
tags: tags:
- rbac-roles - rbac-roles
operationId: listRoles operationId: getListOfRoles
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'

View File

@ -2,7 +2,7 @@ get:
tags: tags:
- rbac-subjects - rbac-subjects
description: 'List all visible permissions granted to the given subject; reduced ' description: 'List all visible permissions granted to the given subject; reduced '
operationId: listSubjectPermissions operationId: getListOfSubjectPermissions
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'

View File

@ -2,7 +2,7 @@ get:
tags: tags:
- rbac-subjects - rbac-subjects
description: 'Fetch a single subject by its id, if visible for the current subject.' description: 'Fetch a single subject by its id, if visible for the current subject.'
operationId: getSubjectById operationId: getSingleSubjectByUuid
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'

View File

@ -2,7 +2,7 @@ get:
tags: tags:
- rbac-subjects - rbac-subjects
description: List accessible RBAC subjects with optional filter by name. description: List accessible RBAC subjects with optional filter by name.
operationId: listSubjects operationId: getListOfSubjects
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'
@ -29,7 +29,7 @@ post:
tags: tags:
- rbac-subjects - rbac-subjects
description: Create a new RBAC subject (e.g. user). description: Create a new RBAC subject (e.g. user).
operationId: createSubject operationId: postNewSubject
requestBody: requestBody:
required: true required: true
content: content:

View File

@ -10,6 +10,7 @@ import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule; import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.ConditionEvents; import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent; import com.tngtech.archunit.lang.SimpleConditionEvent;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItem; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItem;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity;
@ -20,7 +21,9 @@ import org.springframework.web.bind.annotation.RestController;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static com.tngtech.archunit.core.domain.JavaModifier.ABSTRACT; import java.lang.annotation.Annotation;
import static com.tngtech.archunit.core.domain.JavaModifier.PUBLIC;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*;
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices; import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
import static java.lang.String.format; import static java.lang.String.format;
@ -98,7 +101,7 @@ public class ArchitectureTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule testClassesAreProperlyNamed = classes() public static final ArchRule testClassesAreProperlyNamed = classes()
.that().haveSimpleNameEndingWith("Test") .that().haveSimpleNameEndingWith("Test")
.and().doNotHaveModifier(ABSTRACT) .and().doNotHaveModifier(JavaModifier.ABSTRACT)
.should().haveNameMatching(".*(UnitTest|RestTest|IntegrationTest|AcceptanceTest|ScenarioTest|ArchitectureTest)$"); .should().haveNameMatching(".*(UnitTest|RestTest|IntegrationTest|AcceptanceTest|ScenarioTest|ArchitectureTest)$");
@ArchTest @ArchTest
@ -346,11 +349,25 @@ public class ArchitectureTest {
static final ArchRule restControllerNaming = static final ArchRule restControllerNaming =
classes().that().areAnnotatedWith(RestController.class).should().haveSimpleNameEndingWith("Controller"); classes().that().areAnnotatedWith(RestController.class).should().haveSimpleNameEndingWith("Controller");
@ArchTest
@SuppressWarnings("unused")
static final ArchRule restControllerMethods = classes()
.that().areAnnotatedWith(RestController.class)
.and().resideOutsideOfPackages("net.hostsharing.hsadminng.rbac.test", "net.hostsharing.hsadminng.rbac.test.*")
.should(haveAllPublicMethodsAnnotatedWith(Timed.class));
@ArchTest @ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
static final ArchRule repositoryNaming = static final ArchRule repositoryNaming =
classes().that().areAssignableTo(Repository.class).should().haveSimpleNameEndingWith("Repository"); classes().that().areAssignableTo(Repository.class).should().haveSimpleNameEndingWith("Repository");
@ArchTest
@SuppressWarnings("unused")
static final ArchRule repositoryMethods = classes()
.that().areAssignableTo(Repository.class)
.and().resideOutsideOfPackages("net.hostsharing.hsadminng.rbac.test", "net.hostsharing.hsadminng.rbac.test.*")
.should(haveAllPublicMethodsAnnotatedWith(Timed.class));
@ArchTest @ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
static final ArchRule tableNamesOfRbacEntitiesShouldEndWith_rv = static final ArchRule tableNamesOfRbacEntitiesShouldEndWith_rv =
@ -389,4 +406,35 @@ public class ArchitectureTest {
} }
}; };
} }
private static ArchCondition<JavaClass> haveAllPublicMethodsAnnotatedWith(Class<? extends Annotation> annotation) {
return new ArchCondition<>("have all public methods annotated with @" + annotation.getSimpleName()) {
@Override
public void check(final JavaClass item, final ConditionEvents events) {
for (JavaMethod method : item.getMethods()) {
if (method.isAnnotatedWith(annotation)) {
continue;
}
if (isGeneratedSpringRepositoryMethod(item, method)) {
continue;
}
if (item.isAnnotatedWith(RestController.class) && !method.getModifiers().contains(PUBLIC)) {
continue;
}
final var message = String.format(
"Method %s in class %s is not annotated with @%s",
method.getName(),
item.getName(),
annotation.getSimpleName()
);
events.add(SimpleConditionEvent.violated(method, message));
}
}
};
}
private static boolean isGeneratedSpringRepositoryMethod(final JavaClass item, final JavaMethod method) {
// this is a heuristic, ideally we can determine all methods with generated database calls
return item.isAssignableTo(Repository.class) && !method.getModifiers().contains(JavaModifier.ABSTRACT);
}
} }

View File

@ -139,10 +139,10 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
@Nested @Nested
@Order(3) @Order(3)
class AddBookingItem { class PostNewBookingItem {
@Test @Test
void globalAdmin_canAddBookingItem() { void globalAdmin_canPostNewBookingItem() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenProject = findDefaultProjectOfDebitorNumber(1000111); final var givenProject = findDefaultProjectOfDebitorNumber(1000111);
@ -349,7 +349,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
} }
@Test @Test
void projectAgent_canAddBookingItemEvenIfHostingAssetCreationFails() { void projectAgent_canPostNewBookingItemEvenIfHostingAssetCreationFails() {
context.define("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); context.define("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT");
final var givenProject = findDefaultProjectOfDebitorNumber(1000111); final var givenProject = findDefaultProjectOfDebitorNumber(1000111);

View File

@ -84,7 +84,7 @@ class HsBookingItemControllerRestTest {
} }
@Nested @Nested
class AddBookingItem { class PostNewBookingItem {
@Test @Test
void globalAdmin_canAddValidBookingItem() throws Exception { void globalAdmin_canAddValidBookingItem() throws Exception {

View File

@ -79,10 +79,10 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
} }
@Nested @Nested
class AddBookingProject { class PostNewBookingProject {
@Test @Test
void globalAdmin_canAddBookingProject() { void globalAdmin_canPostNewBookingProject() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findByDebitorNumber(1000111).stream() final var givenDebitor = debitorRepo.findByDebitorNumber(1000111).stream()

View File

@ -76,7 +76,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
@Nested @Nested
@Order(2) @Order(2)
class ListAssets { class GetListOfHostingAssets {
@Test @Test
void globalAdmin_canViewAllAssetsOfArbitraryDebitor() { void globalAdmin_canViewAllAssetsOfArbitraryDebitor() {
@ -146,7 +146,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
@Nested @Nested
@Order(3) @Order(3)
class AddAsset { class PostNewHostingAsset {
@Test @Test
void globalAdmin_canAddBookedAsset() { void globalAdmin_canAddBookedAsset() {
@ -481,7 +481,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
@Nested @Nested
@Order(4) @Order(4)
class PatchAsset { class PatchHostingAsset {
@Test @Test
void globalAdmin_canPatchAllUpdatablePropertiesOfAsset() { void globalAdmin_canPatchAllUpdatablePropertiesOfAsset() {

View File

@ -583,7 +583,7 @@ public class HsHostingAssetControllerRestTest {
@ParameterizedTest @ParameterizedTest
@EnumSource(HsHostingAssetControllerRestTest.ListTestCases.class) @EnumSource(HsHostingAssetControllerRestTest.ListTestCases.class)
void shouldListAssets(final HsHostingAssetControllerRestTest.ListTestCases testCase) throws Exception { void shouldGetListOfHostingAssets(final HsHostingAssetControllerRestTest.ListTestCases testCase) throws Exception {
// given // given
when(rbacAssetRepo.findAllByCriteria(null, null, testCase.assetType)) when(rbacAssetRepo.findAllByCriteria(null, null, testCase.assetType))
.thenReturn(testCase.givenHostingAssetsOfType); .thenReturn(testCase.givenHostingAssetsOfType);
@ -607,7 +607,7 @@ public class HsHostingAssetControllerRestTest {
} }
@Test @Test
void shouldPatchAsset() throws Exception { void shouldPatchHostingAsset() throws Exception {
// given // given
final var givenDomainSetup = HsHostingAssetRealEntity.builder() final var givenDomainSetup = HsHostingAssetRealEntity.builder()
.type(HsHostingAssetType.DOMAIN_SETUP) .type(HsHostingAssetType.DOMAIN_SETUP)

View File

@ -161,7 +161,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
} }
@Nested @Nested
class GetGrantById { class GetListOfGrantsByUuid {
@Test @Test
void customerAdmin_withAssumedPacketAdminRole_canReadPacketAdminsGrantById() { void customerAdmin_withAssumedPacketAdminRole_canReadPacketAdminsGrantById() {
@ -171,7 +171,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN"); final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN");
// when // when
final var grant = givencurrentSubjectAsPackageAdmin.getGrantById() final var grant = givencurrentSubjectAsPackageAdmin.getListOfGrantsByUuid()
.forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser); .forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser);
// then // then
@ -190,7 +190,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN"); final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN");
// when // when
final var grant = givencurrentSubjectAsPackageAdmin.getGrantById() final var grant = givencurrentSubjectAsPackageAdmin.getListOfGrantsByUuid()
.forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser); .forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser);
// then // then
@ -211,7 +211,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN"); final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN");
// when // when
final var grant = givencurrentSubjectAsPackageAdmin.getGrantById() final var grant = givencurrentSubjectAsPackageAdmin.getListOfGrantsByUuid()
.forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser); .forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser);
// then // then
@ -231,7 +231,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
"rbactest.package#xxx00:TENANT"); "rbactest.package#xxx00:TENANT");
final var givenGranteeUser = findRbacSubjectByName("pac-admin-xxx00@xxx.example.com"); final var givenGranteeUser = findRbacSubjectByName("pac-admin-xxx00@xxx.example.com");
final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN"); final var givenGrantedRole = getRbacRoleByName("rbactest.package#xxx00:ADMIN");
final var grant = givencurrentSubjectAsPackageAdmin.getGrantById() final var grant = givencurrentSubjectAsPackageAdmin.getListOfGrantsByUuid()
.forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser); .forGrantedRole(givenGrantedRole).toGranteeUser(givenGranteeUser);
// then // then
@ -360,8 +360,8 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
return new RevokeFixture(givenOwnPackageAdminRole); return new RevokeFixture(givenOwnPackageAdminRole);
} }
GetGrantByIdFixture getGrantById() { GetListOfGrantsByUuidFixture getListOfGrantsByUuid() {
return new GetGrantByIdFixture(); return new GetListOfGrantsByUuidFixture();
} }
class GrantFixture { class GrantFixture {
@ -443,12 +443,12 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
} }
} }
private class GetGrantByIdFixture { private class GetListOfGrantsByUuidFixture {
private Subject currentSubject = Subject.this; private Subject currentSubject = Subject.this;
private RbacRoleEntity grantedRole; private RbacRoleEntity grantedRole;
GetGrantByIdFixture forGrantedRole(final RbacRoleEntity grantedRole) { GetListOfGrantsByUuidFixture forGrantedRole(final RbacRoleEntity grantedRole) {
this.grantedRole = grantedRole; this.grantedRole = grantedRole;
return this; return this;
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.role; package net.hostsharing.hsadminng.rbac.role;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -7,5 +8,6 @@ import java.util.UUID;
public interface RawRbacObjectRepository extends Repository<RawRbacObjectEntity, UUID> { public interface RawRbacObjectRepository extends Repository<RawRbacObjectEntity, UUID> {
@Timed("app.rbac.objects.repo.findAll.real")
List<RawRbacObjectEntity> findAll(); List<RawRbacObjectEntity> findAll();
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.rbac.role; package net.hostsharing.hsadminng.rbac.role;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import java.util.List; import java.util.List;
@ -7,5 +8,6 @@ import java.util.UUID;
public interface RawRbacRoleRepository extends Repository<RawRbacRoleEntity, UUID> { public interface RawRbacRoleRepository extends Repository<RawRbacRoleEntity, UUID> {
@Timed("app.rbac.roles.repo.findAll.real")
List<RawRbacRoleEntity> findAll(); List<RawRbacRoleEntity> findAll();
} }

View File

@ -45,7 +45,7 @@ class RbacSubjectControllerRestTest {
@Test @Test
void createSubjectUsesGivenUuid() throws Exception { void postNewSubjectUsesGivenUuid() throws Exception {
// given // given
final var givenUuid = UUID.randomUUID(); final var givenUuid = UUID.randomUUID();
@ -69,7 +69,7 @@ class RbacSubjectControllerRestTest {
} }
@Test @Test
void createSubjectGeneratesRandomUuidIfNotGiven() throws Exception { void postNewSubjectGeneratesRandomUuidIfNotGiven() throws Exception {
// when // when
mockMvc.perform(MockMvcRequestBuilders mockMvc.perform(MockMvcRequestBuilders
.post("/api/rbac/subjects") .post("/api/rbac/subjects")

View File

@ -41,7 +41,7 @@ class RbacSubjectRepositoryIntegrationTest extends ContextBasedTest {
HttpServletRequest request; HttpServletRequest request;
@Nested @Nested
class CreateSubject { class PostNewSubject {
@Test @Test
@Transactional(propagation = Propagation.NEVER) @Transactional(propagation = Propagation.NEVER)
@ -178,7 +178,7 @@ class RbacSubjectRepositoryIntegrationTest extends ContextBasedTest {
} }
@Nested @Nested
class ListSubjectPermissions { class GetListOfSubjectPermissions {
private static final String[] ALL_USER_PERMISSIONS = Array.of( private static final String[] ALL_USER_PERMISSIONS = Array.of(
// @formatter:off // @formatter:off