|
11 | 11 | import java.io.IOException; |
12 | 12 | import java.util.List; |
13 | 13 | import java.util.Objects; |
| 14 | +import java.util.Set; |
14 | 15 |
|
15 | 16 | import com.google.common.collect.ImmutableList; |
16 | 17 | import org.apache.logging.log4j.LogManager; |
@@ -66,21 +67,27 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli |
66 | 67 |
|
67 | 68 | final String resourceIndex = resourcePluginInfo.indexByType(resourceType); |
68 | 69 |
|
| 70 | + if (resourceIndex == null) { |
| 71 | + return channel -> { handleResponse(channel, Set.of()); }; |
| 72 | + } |
69 | 73 | return channel -> resourceAccessHandler.getResourceSharingInfoForCurrentUser(resourceIndex, ActionListener.wrap(rows -> { |
| 74 | + handleResponse(channel, rows); |
| 75 | + }, e -> handleError(channel, e))); |
| 76 | + } |
70 | 77 |
|
71 | | - try (XContentBuilder b = channel.newBuilder()) { |
72 | | - b.startObject(); |
73 | | - b.startArray("resources"); |
74 | | - for (SharingRecord row : rows) { |
75 | | - row.toXContent(b, ToXContent.EMPTY_PARAMS); |
76 | | - } |
77 | | - b.endArray(); |
78 | | - b.endObject(); |
79 | | - channel.sendResponse(new BytesRestResponse(RestStatus.OK, b)); |
80 | | - } catch (IOException ioe) { |
81 | | - handleError(channel, ioe); |
| 78 | + private void handleResponse(RestChannel channel, Set<SharingRecord> records) throws IOException { |
| 79 | + try (XContentBuilder b = channel.newBuilder()) { |
| 80 | + b.startObject(); |
| 81 | + b.startArray("resources"); |
| 82 | + for (SharingRecord row : records) { |
| 83 | + row.toXContent(b, ToXContent.EMPTY_PARAMS); |
82 | 84 | } |
83 | | - }, e -> handleError(channel, e))); |
| 85 | + b.endArray(); |
| 86 | + b.endObject(); |
| 87 | + channel.sendResponse(new BytesRestResponse(RestStatus.OK, b)); |
| 88 | + } catch (IOException ioe) { |
| 89 | + handleError(channel, ioe); |
| 90 | + } |
84 | 91 | } |
85 | 92 |
|
86 | 93 | private void handleError(RestChannel channel, Exception e) { |
|
0 commit comments