diff --git a/sample-extension-plugin/src/integrationTest/java/org/opensearch/security/sampleextension/SampleExtensionPluginTests.java b/sample-extension-plugin/src/integrationTest/java/org/opensearch/security/sampleextension/SampleExtensionPluginTests.java index 22bc4d1973..8a7b106a1c 100644 --- a/sample-extension-plugin/src/integrationTest/java/org/opensearch/security/sampleextension/SampleExtensionPluginTests.java +++ b/sample-extension-plugin/src/integrationTest/java/org/opensearch/security/sampleextension/SampleExtensionPluginTests.java @@ -68,7 +68,10 @@ public void testCreateAndUpdateOwnSampleResource() throws Exception { System.out.println("resourceId: " + resourceId); String sampleResourceUpdated = "{\"name\":\"sampleUpdated\"}"; - HttpResponse updateResponse = client.putJson("_plugins/resource_sharing_example/resource/update/" + resourceId, sampleResourceUpdated); + HttpResponse updateResponse = client.putJson( + "_plugins/resource_sharing_example/resource/update/" + resourceId, + sampleResourceUpdated + ); updateResponse.assertStatusCode(HttpStatus.SC_OK); System.out.println("Update Response: " + updateResponse.getBody()); } diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/SampleExtensionPlugin.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/SampleExtensionPlugin.java index e028be9a01..f014e39980 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/SampleExtensionPlugin.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/SampleExtensionPlugin.java @@ -45,12 +45,12 @@ import org.opensearch.security.sampleextension.actions.ListSampleResourceRestAction; import org.opensearch.security.sampleextension.actions.ListSampleResourceTransportAction; import org.opensearch.security.sampleextension.actions.SampleResource; -import org.opensearch.security.sampleextension.actions.UpdateSampleResourceAction; -import org.opensearch.security.sampleextension.actions.UpdateSampleResourceRestAction; import org.opensearch.security.sampleextension.actions.UpdateSampleResourceSharingAction; import org.opensearch.security.sampleextension.actions.UpdateSampleResourceSharingRestAction; import org.opensearch.security.sampleextension.actions.UpdateSampleResourceSharingTransportAction; -import org.opensearch.security.sampleextension.actions.UpdateSampleResourceTransportAction; +import org.opensearch.security.sampleextension.actions.update.UpdateSampleResourceAction; +import org.opensearch.security.sampleextension.actions.update.UpdateSampleResourceRestAction; +import org.opensearch.security.sampleextension.actions.update.UpdateSampleResourceTransportAction; import org.opensearch.security.sampleextension.resource.SampleResourceSharingService; import org.opensearch.security.spi.DefaultResourceSharingService; import org.opensearch.security.spi.ResourceSharingService; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceAction.java similarity index 92% rename from sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceAction.java rename to sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceAction.java index c3037a03cf..18f8f1d3fe 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceAction.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.security.sampleextension.actions; +package org.opensearch.security.sampleextension.actions.update; import org.opensearch.action.ActionType; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceRequest.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceRequest.java similarity index 95% rename from sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceRequest.java rename to sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceRequest.java index 8dd86933a4..ad3118e577 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceRequest.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceRequest.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.security.sampleextension.actions; +package org.opensearch.security.sampleextension.actions.update; import java.io.IOException; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceResponse.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceResponse.java similarity index 69% rename from sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceResponse.java rename to sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceResponse.java index aa103d1440..dcd996db9b 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceResponse.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceResponse.java @@ -6,36 +6,34 @@ * compatible open source license. */ -package org.opensearch.security.sampleextension.actions; +package org.opensearch.security.sampleextension.actions.update; import java.io.IOException; -import java.util.List; import org.opensearch.core.action.ActionResponse; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; -import org.opensearch.security.spi.AbstractResource; /** * Response to a ListSampleResourceRequest */ public class UpdateSampleResourceResponse extends ActionResponse implements ToXContentObject { - private final List resources; + private final String resourceId; /** * Default constructor * - * @param resources The resources + * @param resourceId The resourceId */ - public UpdateSampleResourceResponse(List resources) { - this.resources = resources; + public UpdateSampleResourceResponse(String resourceId) { + this.resourceId = resourceId; } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeList(resources); + out.writeString(resourceId); } /** @@ -44,13 +42,13 @@ public void writeTo(StreamOutput out) throws IOException { * @param in the stream input */ public UpdateSampleResourceResponse(final StreamInput in) throws IOException { - resources = in.readList(SampleResource::new); + resourceId = in.readString(); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.array("resources", (Object[]) resources.toArray(new AbstractResource[0])); + builder.field("resourceId", resourceId); builder.endObject(); return builder; } diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceRestAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceRestAction.java similarity index 96% rename from sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceRestAction.java rename to sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceRestAction.java index 01c0dc3aa7..8658193c9b 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceRestAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceRestAction.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.security.sampleextension.actions; +package org.opensearch.security.sampleextension.actions.update; import java.io.IOException; import java.util.List; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceTransportAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceTransportAction.java similarity index 90% rename from sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceTransportAction.java rename to sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceTransportAction.java index dd00625bc5..443fa01728 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/UpdateSampleResourceTransportAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/update/UpdateSampleResourceTransportAction.java @@ -6,10 +6,9 @@ * compatible open source license. */ -package org.opensearch.security.sampleextension.actions; +package org.opensearch.security.sampleextension.actions.update; import java.io.IOException; -import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -23,6 +22,7 @@ import org.opensearch.common.inject.Inject; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.ToXContent; +import org.opensearch.security.sampleextension.actions.SampleResource; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; @@ -38,11 +38,7 @@ public class UpdateSampleResourceTransportAction extends HandledTransportAction< private final Client nodeClient; @Inject - public UpdateSampleResourceTransportAction( - TransportService transportService, - ActionFilters actionFilters, - Client nodeClient - ) { + public UpdateSampleResourceTransportAction(TransportService transportService, ActionFilters actionFilters, Client nodeClient) { super(UpdateSampleResourceAction.NAME, transportService, actionFilters, UpdateSampleResourceRequest::new); this.nodeClient = nodeClient; } @@ -68,7 +64,7 @@ private void indexResource(UpdateSampleResourceRequest request, ActionListener irListener = ActionListener.wrap(idxResponse -> { log.info("Updated resource: " + idxResponse.toString()); - listener.onResponse(new UpdateSampleResourceResponse(List.of(updatedResource))); + listener.onResponse(new UpdateSampleResourceResponse(updatedResource.getResourceId())); }, listener::onFailure); nodeClient.index(ir, irListener); } catch (IOException e) {