Skip to content

Commit

Permalink
merge development
Browse files Browse the repository at this point in the history
  • Loading branch information
artsiomkorzun committed Mar 6, 2024
1 parent a10bade commit 303396b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/epam/aidial/core/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<String> paths, boolean isFolder) {
boolean isEmptyElements = paths.isEmpty();
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/epam/aidial/core/PublicationApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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", """
Expand All @@ -24,7 +24,7 @@ void testPublicationCreation() {
}
""".formatted(bucket, bucket, bucket));

verifyPretty(response, 200, """
verifyJson(response, 200, """
{
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"sourceUrl" : "3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/my/folder/",
Expand All @@ -40,7 +40,7 @@ void testPublicationCreation() {
}
""");

verifyPretty(response, 200, """
verifyJson(response, 200, """
{
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"sourceUrl" : "3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/my/folder/",
Expand All @@ -62,7 +62,7 @@ void testPublicationCreation() {
}
""");

verifyPretty(response, 200, """
verifyJson(response, 200, """
{
"publications" : [ {
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
Expand All @@ -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);
Expand All @@ -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", """
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/com/epam/aidial/core/ResourceBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 303396b

Please sign in to comment.