From 303396b2cce6515aa152d07c4347b3c61e6aef93 Mon Sep 17 00:00:00 2001 From: Artsiom Korzun Date: Wed, 6 Mar 2024 14:05:13 +0100 Subject: [PATCH] merge development --- src/main/java/com/epam/aidial/core/Proxy.java | 2 +- .../core/controller/ControllerSelector.java | 6 +++--- .../aidial/core/service/PublicationService.java | 3 +-- .../aidial/core/storage/ResourceDescription.java | 16 ++++++++-------- .../com/epam/aidial/core/PublicationApiTest.java | 12 ++++++------ .../com/epam/aidial/core/ResourceBaseTest.java | 5 ----- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/epam/aidial/core/Proxy.java b/src/main/java/com/epam/aidial/core/Proxy.java index a5912a268..cf3e646a5 100644 --- a/src/main/java/com/epam/aidial/core/Proxy.java +++ b/src/main/java/com/epam/aidial/core/Proxy.java @@ -13,8 +13,8 @@ import com.epam.aidial.core.security.EncryptionService; import com.epam.aidial.core.security.ExtractedClaims; import com.epam.aidial.core.service.InvitationService; -import com.epam.aidial.core.service.PublicationService; import com.epam.aidial.core.service.LockService; +import com.epam.aidial.core.service.PublicationService; import com.epam.aidial.core.service.ResourceService; import com.epam.aidial.core.service.ShareService; import com.epam.aidial.core.storage.BlobStorage; diff --git a/src/main/java/com/epam/aidial/core/controller/ControllerSelector.java b/src/main/java/com/epam/aidial/core/controller/ControllerSelector.java index ae4784f59..926852e9d 100644 --- a/src/main/java/com/epam/aidial/core/controller/ControllerSelector.java +++ b/src/main/java/com/epam/aidial/core/controller/ControllerSelector.java @@ -265,9 +265,9 @@ private static Controller selectPost(Proxy proxy, ProxyContext context, String p return switch (operation) { case "list" -> controller::listPublications; - case "get"-> controller::getPublication; - case "create"-> controller::createPublication; - case "delete"-> controller::deletePublication; + case "get" -> controller::getPublication; + case "create" -> controller::createPublication; + case "delete" -> controller::deletePublication; default -> null; }; } diff --git a/src/main/java/com/epam/aidial/core/service/PublicationService.java b/src/main/java/com/epam/aidial/core/service/PublicationService.java index 083a5e4db..5a4c58eb1 100644 --- a/src/main/java/com/epam/aidial/core/service/PublicationService.java +++ b/src/main/java/com/epam/aidial/core/service/PublicationService.java @@ -12,7 +12,6 @@ import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.mutable.MutableObject; -import javax.annotation.Nullable; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; @@ -21,6 +20,7 @@ import java.util.Set; import java.util.function.LongSupplier; import java.util.function.Supplier; +import javax.annotation.Nullable; import static com.epam.aidial.core.storage.BlobStorageUtil.PATH_SEPARATOR; import static com.epam.aidial.core.storage.ResourceDescription.PUBLIC_BUCKET; @@ -36,7 +36,6 @@ public class PublicationService { ResourceType.PUBLICATION, PUBLIC_BUCKET, ResourceDescription.PUBLIC_LOCATION, PUBLICATIONS_NAME); - private final EncryptionService encryption; private final ResourceService resources; private final BlobStorage files; diff --git a/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java b/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java index e358a457e..2d059eea1 100644 --- a/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java +++ b/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java @@ -167,14 +167,6 @@ public static ResourceDescription fromLink(String link, EncryptionService encryp return fromEncoded(resourceType, bucket, location, resourcePath); } - public static ResourceDescription fromBucketLink(String link, ResourceDescription bucket) { - return fromLink(link, bucket.getBucketName(), bucket.getBucketLocation()); - } - - public static ResourceDescription fromPublicLink(String link) { - return fromLink(link, PUBLIC_BUCKET, PUBLIC_LOCATION); - } - private static ResourceDescription fromLink(String link, String bucketEncoded, String bucketDecoded) { String[] parts = link.split(BlobStorageUtil.PATH_SEPARATOR); if (parts.length < 2) { @@ -191,6 +183,14 @@ private static ResourceDescription fromLink(String link, String bucketEncoded, S return fromEncoded(resourceType, bucketEncoded, bucketDecoded, relativePath); } + public static ResourceDescription fromBucketLink(String link, ResourceDescription bucket) { + return fromLink(link, bucket.getBucketName(), bucket.getBucketLocation()); + } + + public static ResourceDescription fromPublicLink(String link) { + return fromLink(link, PUBLIC_BUCKET, PUBLIC_LOCATION); + } + private static ResourceDescription from(ResourceType type, String bucketName, String bucketLocation, String originalPath, List paths, boolean isFolder) { boolean isEmptyElements = paths.isEmpty(); diff --git a/src/test/java/com/epam/aidial/core/PublicationApiTest.java b/src/test/java/com/epam/aidial/core/PublicationApiTest.java index 506856d0c..cd17cfb4d 100644 --- a/src/test/java/com/epam/aidial/core/PublicationApiTest.java +++ b/src/test/java/com/epam/aidial/core/PublicationApiTest.java @@ -7,7 +7,7 @@ class PublicationApiTest extends ResourceBaseTest { @Test void testPublicationCreation() { - Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", "12345"); + Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1); verify(response, 200); response = operationRequest("/v1/ops/publications/create", """ @@ -24,7 +24,7 @@ void testPublicationCreation() { } """.formatted(bucket, bucket, bucket)); - verifyPretty(response, 200, """ + verifyJson(response, 200, """ { "url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123", "sourceUrl" : "3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/my/folder/", @@ -40,7 +40,7 @@ void testPublicationCreation() { } """); - verifyPretty(response, 200, """ + verifyJson(response, 200, """ { "url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123", "sourceUrl" : "3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/my/folder/", @@ -62,7 +62,7 @@ void testPublicationCreation() { } """); - verifyPretty(response, 200, """ + verifyJson(response, 200, """ { "publications" : [ { "url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123", @@ -75,7 +75,7 @@ void testPublicationCreation() { """); response = send(HttpMethod.GET, "/v1/conversations/2CZ9i2bcBACFts8JbBu3MdTHfU5imDZBmDVomBuDCkbhEstv1KXNzCiw693js8BLmo/conversation"); - verify(response, 200, "12345"); + verifyJson(response, 200, CONVERSATION_BODY_1); response = send(HttpMethod.PUT, "/v1/conversations/2CZ9i2bcBACFts8JbBu3MdTHfU5imDZBmDVomBuDCkbhEstv1KXNzCiw693js8BLmo/conversation"); verify(response, 403); @@ -86,7 +86,7 @@ void testPublicationCreation() { @Test void testPublicationDeletion() { - Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", "12345"); + Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1); verify(response, 200); response = operationRequest("/v1/ops/publications/create", """ diff --git a/src/test/java/com/epam/aidial/core/ResourceBaseTest.java b/src/test/java/com/epam/aidial/core/ResourceBaseTest.java index a36e9f004..c5848fe39 100644 --- a/src/test/java/com/epam/aidial/core/ResourceBaseTest.java +++ b/src/test/java/com/epam/aidial/core/ResourceBaseTest.java @@ -159,11 +159,6 @@ static void verify(Response response, int status) { assertEquals(status, response.status()); } - static void verifyPretty(Response response, int status, String body) { - assertEquals(status, response.status()); - assertEquals(body.trim(), pretty(response.body())); - } - static void verify(Response response, int status, String body) { assertEquals(status, response.status()); assertEquals(body, response.body());