Skip to content

Commit

Permalink
feat: extend publications response body with resourceTypes (#318)(#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Gadalov authored Apr 29, 2024
1 parent 625869b commit e6ab09c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/epam/aidial/core/data/Publication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Data
@Accessors(chain = true)
Expand All @@ -21,6 +23,7 @@ public class Publication {
Status status;
Long createdAt;
List<Resource> resources;
Set<ResourceType> resourceTypes;
List<Rule> rules;

public enum Status {
Expand All @@ -42,4 +45,21 @@ public static class Resource {
*/
String reviewUrl;
}

public Set<ResourceType> getResourceTypes() {
if (resourceTypes != null) {
return resourceTypes;
}
if (resources == null) {
return Set.of();
}
Set<ResourceType> resourceTypes = new HashSet<>();
for (Resource resource : resources) {
String sourceUrl = resource.getSourceUrl();
String resourceType = sourceUrl.substring(0, sourceUrl.indexOf('/'));
resourceTypes.add(ResourceType.of(resourceType));
}

return resourceTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ private static Publication newMetadata(Publication publication) {
.setUrl(publication.getUrl())
.setTargetUrl(publication.getTargetUrl())
.setStatus(publication.getStatus())
.setResourceTypes(publication.getResourceTypes())
.setCreatedAt(publication.getCreatedAt());
}

Expand Down
36 changes: 25 additions & 11 deletions src/test/java/com/epam/aidial/core/PublicationApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PublicationApiTest extends ResourceBaseTest {
"targetUrl" : "conversations/public/folder/conversation",
"reviewUrl" : "conversations/2CZ9i2bcBACFts8JbBu3MdTHfU5imDZBmDVomBuDCkbhEstv1KXNzCiw693js8BLmo/conversation"
} ],
"resourceTypes" : [ "CONVERSATION" ],
"rules" : [ {
"function" : "EQUAL",
"source" : "roles",
Expand Down Expand Up @@ -81,7 +82,8 @@ void testPublicationCreation() {
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl" : "public/folder/",
"status" : "PENDING",
"createdAt" : 0
"createdAt" : 0,
"resourceTypes" : [ "CONVERSATION" ]
} ]
}
""");
Expand Down Expand Up @@ -153,6 +155,7 @@ void testDeleteApprovedPublicationWorkflow() {
"targetUrl" : "conversations/public/folder/conversation",
"reviewUrl" : "conversations/2CZ9i2bcBACFts8JbBu3MdTHfU5imDZBmDVomBuDCkbhEstv1KXNzCiw693js8BLmo/conversation"
} ],
"resourceTypes" : [ "CONVERSATION" ],
"rules" : [ {
"function" : "EQUAL",
"source" : "roles",
Expand All @@ -174,7 +177,8 @@ void testDeleteApprovedPublicationWorkflow() {
"url":"publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl":"public/folder/",
"status":"APPROVED",
"createdAt":0
"createdAt":0,
"resourceTypes" : [ "CONVERSATION" ]
}]
}
""");
Expand All @@ -195,7 +199,8 @@ void testDeleteApprovedPublicationWorkflow() {
"url":"publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl":"public/folder/",
"status":"REQUESTED_FOR_DELETION",
"createdAt":0
"createdAt":0,
"resourceTypes" : [ "CONVERSATION" ]
}]
}
""");
Expand All @@ -220,7 +225,8 @@ void testDeleteApprovedPublicationWorkflow() {
"url":"publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl":"public/folder/",
"status":"REQUESTED_FOR_DELETION",
"createdAt":0
"createdAt":0,
"resourceTypes" : [ "CONVERSATION" ]
}]
}
""");
Expand Down Expand Up @@ -270,12 +276,12 @@ void testRejectUserDeletionRequestWorkflow() {
"targetUrl" : "conversations/public/folder/conversation",
"reviewUrl" : "conversations/2CZ9i2bcBACFts8JbBu3MdTHfU5imDZBmDVomBuDCkbhEstv1KXNzCiw693js8BLmo/conversation"
} ],
"resourceTypes" : [ "CONVERSATION" ],
"rules" : [ {
"function" : "EQUAL",
"source" : "roles",
"targets" : [ "user" ]
} ]
}
""");

Expand All @@ -291,7 +297,8 @@ void testRejectUserDeletionRequestWorkflow() {
"url":"publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl":"public/folder/",
"status":"APPROVED",
"createdAt":0
"createdAt":0,
"resourceTypes" : [ "CONVERSATION" ]
}]
}
""");
Expand All @@ -312,7 +319,8 @@ void testRejectUserDeletionRequestWorkflow() {
"url":"publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl":"public/folder/",
"status":"REQUESTED_FOR_DELETION",
"createdAt":0
"createdAt":0,
"resourceTypes" : [ "CONVERSATION" ]
}]
}
""");
Expand All @@ -337,7 +345,8 @@ void testRejectUserDeletionRequestWorkflow() {
"url":"publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl":"public/folder/",
"status":"REQUESTED_FOR_DELETION",
"createdAt":0
"createdAt":0,
"resourceTypes" : [ "CONVERSATION" ]
}]
}
""");
Expand Down Expand Up @@ -368,7 +377,8 @@ void testRejectUserDeletionRequestWorkflow() {
"url":"publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl":"public/folder/",
"status":"APPROVED",
"createdAt":0
"createdAt":0,
"resourceTypes" : [ "CONVERSATION" ]
}]
}
""");
Expand Down Expand Up @@ -411,6 +421,7 @@ void testPublicationApprove() {
"targetUrl" : "conversations/public/folder/conversation",
"reviewUrl" : "conversations/2CZ9i2bcBACFts8JbBu3MdTHfU5imDZBmDVomBuDCkbhEstv1KXNzCiw693js8BLmo/conversation"
} ],
"resourceTypes" : [ "CONVERSATION" ],
"rules" : [ {
"function" : "EQUAL",
"source" : "roles",
Expand Down Expand Up @@ -480,6 +491,7 @@ void testPublicationReject() {
"targetUrl" : "conversations/public/folder/conversation",
"reviewUrl" : "conversations/2CZ9i2bcBACFts8JbBu3MdTHfU5imDZBmDVomBuDCkbhEstv1KXNzCiw693js8BLmo/conversation"
} ],
"resourceTypes" : [ "CONVERSATION" ],
"rules" : [ {
"function" : "EQUAL",
"source" : "roles",
Expand Down Expand Up @@ -750,7 +762,8 @@ void testPublicationList() {
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl" : "public/folder/",
"status" : "PENDING",
"createdAt" : 0
"createdAt" : 0,
"resourceTypes" : [ "CONVERSATION" ]
} ]
}
""");
Expand Down Expand Up @@ -880,7 +893,8 @@ void testPublishedResourceList() {
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
"targetUrl" : "public/folder/",
"status" : "PENDING",
"createdAt" : 0
"createdAt" : 0,
"resourceTypes" : [ "CONVERSATION" ]
} ]
}
""");
Expand Down

0 comments on commit e6ab09c

Please sign in to comment.