Skip to content

Commit

Permalink
Separate package
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Dec 12, 2024
1 parent 47a1921 commit f091617
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SampleResource> resources;
private final String resourceId;

/**
* Default constructor
*
* @param resources The resources
* @param resourceId The resourceId
*/
public UpdateSampleResourceResponse(List<SampleResource> 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);
}

/**
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -68,7 +64,7 @@ private void indexResource(UpdateSampleResourceRequest request, ActionListener<U

ActionListener<IndexResponse> 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) {
Expand Down

0 comments on commit f091617

Please sign in to comment.