list hosting-assets with debitor, parent and type query-parameters (#52)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/52 Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
@@ -6,6 +6,7 @@ import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetTypeResource;
|
||||
import net.hostsharing.hsadminng.mapper.KeyValueMap;
|
||||
import net.hostsharing.hsadminng.mapper.Mapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -33,13 +34,15 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<HsHostingAssetResource>> listAssetsByDebitorUuid(
|
||||
public ResponseEntity<List<HsHostingAssetResource>> listAssets(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID debitorUuid) {
|
||||
final UUID debitorUuid,
|
||||
final UUID parentAssetUuid,
|
||||
final HsHostingAssetTypeResource type) {
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var entities = assetRepo.findAllByDebitorUuid(debitorUuid);
|
||||
final var entities = assetRepo.findAllByCriteria(debitorUuid, parentAssetUuid, HsHostingAssetType.of(type));
|
||||
|
||||
final var resources = mapper.mapList(entities, HsHostingAssetResource.class);
|
||||
return ResponseEntity.ok(resources);
|
||||
|
@@ -32,7 +32,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
|
||||
@@ -65,11 +64,11 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
||||
|
||||
private static Stringify<HsHostingAssetEntity> stringify = stringify(HsHostingAssetEntity.class)
|
||||
.withProp(HsHostingAssetEntity::getBookingItem)
|
||||
.withProp(HsHostingAssetEntity::getType)
|
||||
.withProp(HsHostingAssetEntity::getParentAsset)
|
||||
.withProp(HsHostingAssetEntity::getIdentifier)
|
||||
.withProp(HsHostingAssetEntity::getCaption)
|
||||
.withProp(HsHostingAssetEntity::getParentAsset)
|
||||
.withProp(HsHostingAssetEntity::getBookingItem)
|
||||
.withProp(HsHostingAssetEntity::getConfig)
|
||||
.quotedValues(false);
|
||||
|
||||
@@ -122,8 +121,7 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
||||
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return ofNullable(bookingItem).map(HsBookingItemEntity::toShortString).orElse("D-???????:?") +
|
||||
":" + identifier;
|
||||
return type + ":" + identifier;
|
||||
}
|
||||
|
||||
public static RbacView rbac() {
|
||||
|
@@ -7,16 +7,22 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public interface HsHostingAssetRepository extends Repository<HsHostingAssetEntity, UUID> {
|
||||
|
||||
List<HsHostingAssetEntity> findAll();
|
||||
Optional<HsHostingAssetEntity> findByUuid(final UUID serverUuid);
|
||||
|
||||
@Query("""
|
||||
SELECT s FROM HsHostingAssetEntity s
|
||||
WHERE s.bookingItem.debitor.uuid = :debitorUuid
|
||||
SELECT asset FROM HsHostingAssetEntity asset
|
||||
WHERE (:debitorUuid IS NULL OR asset.bookingItem.debitor.uuid = :debitorUuid)
|
||||
AND (:parentAssetUuid IS NULL OR asset.parentAsset.uuid = :parentAssetUuid)
|
||||
AND (:type IS NULL OR :type = CAST(asset.type AS String))
|
||||
""")
|
||||
List<HsHostingAssetEntity> findAllByDebitorUuid(final UUID debitorUuid);
|
||||
List<HsHostingAssetEntity> findAllByCriteriaImpl(UUID debitorUuid, UUID parentAssetUuid, String type);
|
||||
default List<HsHostingAssetEntity> findAllByCriteria(final UUID debitorUuid, final UUID parentAssetUuid, final HsHostingAssetType type) {
|
||||
return findAllByCriteriaImpl(debitorUuid, parentAssetUuid, HsHostingAssetType.asString(type));
|
||||
}
|
||||
|
||||
HsHostingAssetEntity save(HsHostingAssetEntity current);
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
|
||||
public enum HsHostingAssetType {
|
||||
CLOUD_SERVER, // named e.g. vm1234
|
||||
MANAGED_SERVER, // named e.g. vm1234
|
||||
@@ -25,4 +26,12 @@ public enum HsHostingAssetType {
|
||||
HsHostingAssetType() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> HsHostingAssetType of(final T value) {
|
||||
return value == null ? null : valueOf(value.name());
|
||||
}
|
||||
|
||||
static String asString(final HsHostingAssetType type) {
|
||||
return type == null ? null : type.name();
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,29 @@
|
||||
get:
|
||||
summary: Returns a list of all hosting assets for a specified debitor.
|
||||
description: Returns the list of all hosting assets for a debitor which are visible to the current user or any of it's assumed roles.
|
||||
summary: Returns a filtered list of all hosting assets.
|
||||
description: Returns the list of all hosting assets which match the given filters and are visible to the current user or any of it's assumed roles.
|
||||
tags:
|
||||
- hs-hosting-assets
|
||||
operationId: listAssetsByDebitorUuid
|
||||
operationId: listAssets
|
||||
parameters:
|
||||
- $ref: 'auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: debitorUuid
|
||||
in: query
|
||||
required: true
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
- name: parentAssetUuid
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
- name: type
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
$ref: 'hs-hosting-asset-schemas.yaml#/components/schemas/HsHostingAssetType'
|
||||
description: The UUID of the debitor, whose hosting assets are to be listed.
|
||||
responses:
|
||||
"200":
|
||||
|
@@ -97,7 +97,7 @@ $$;
|
||||
create table RbacObject
|
||||
(
|
||||
uuid uuid primary key default uuid_generate_v4(),
|
||||
serialId serial, -- TODO: we might want to remove this once test data deletion works properly
|
||||
serialId serial, -- TODO.perf: only needed for reverse deletion of temp test data
|
||||
objectTable varchar(64) not null,
|
||||
unique (objectTable, uuid)
|
||||
);
|
||||
|
Reference in New Issue
Block a user