Skip to content

Commit 27590cf

Browse files
committed
try to modernize docs
1 parent c041014 commit 27590cf

4 files changed

Lines changed: 40 additions & 50 deletions

File tree

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@
1919

2020
package org.elasticsearch.client.documentation;
2121

22-
import org.apache.http.client.methods.HttpPost;
23-
import org.apache.http.entity.ContentType;
24-
import org.apache.http.nio.entity.NStringEntity;
2522
import org.apache.http.client.methods.HttpPost;
2623
import org.apache.http.entity.ContentType;
2724
import org.apache.http.nio.entity.NStringEntity;
2825
import org.elasticsearch.action.ActionListener;
2926
import org.elasticsearch.action.LatchedActionListener;
3027
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
3128
import org.elasticsearch.client.Request;
32-
import org.elasticsearch.client.Request;
3329
import org.elasticsearch.client.RequestOptions;
3430
import org.elasticsearch.client.RestHighLevelClient;
3531
import org.elasticsearch.client.security.ChangePasswordRequest;
3632
import org.elasticsearch.client.security.DeleteRoleMappingRequest;
3733
import org.elasticsearch.client.security.DeleteRoleMappingResponse;
3834
import org.elasticsearch.client.security.DeleteRoleRequest;
3935
import org.elasticsearch.client.security.DeleteRoleResponse;
40-
import org.elasticsearch.client.security.DeleteRoleRequest;
41-
import org.elasticsearch.client.security.DeleteRoleResponse;
4236
import org.elasticsearch.client.security.DisableUserRequest;
4337
import org.elasticsearch.client.security.EmptyResponse;
4438
import org.elasticsearch.client.security.EnableUserRequest;
@@ -48,18 +42,14 @@
4842
import org.elasticsearch.client.security.PutUserRequest;
4943
import org.elasticsearch.client.security.PutUserResponse;
5044
import org.elasticsearch.client.security.RefreshPolicy;
51-
import org.elasticsearch.client.security.support.expressiondsl.RoleMapperExpression;
52-
import org.elasticsearch.client.security.support.expressiondsl.fields.FieldRoleMapperExpression;
5345
import org.elasticsearch.client.security.support.CertificateInfo;
46+
import org.elasticsearch.client.security.support.expressiondsl.RoleMapperExpression;
5447
import org.elasticsearch.client.security.support.expressiondsl.expressions.AnyRoleMapperExpression;
5548
import org.elasticsearch.client.security.support.expressiondsl.fields.FieldRoleMapperExpression;
5649
import org.elasticsearch.common.Strings;
5750
import org.elasticsearch.common.xcontent.XContentBuilder;
58-
import org.elasticsearch.common.Strings;
59-
import org.elasticsearch.common.xcontent.XContentBuilder;
6051
import org.hamcrest.Matchers;
6152

62-
import java.io.IOException;
6353
import java.io.IOException;
6454
import java.util.Collections;
6555
import java.util.Iterator;
@@ -443,21 +433,31 @@ public void testDeleteRole() throws Exception {
443433
addRole("testrole");
444434

445435
{
446-
//tag::delete-role-execute
447-
DeleteRoleRequest deleteRoleRequest = new DeleteRoleRequest("testrole");
436+
// tag::delete-role-request
437+
DeleteRoleRequest deleteRoleRequest = new DeleteRoleRequest(
438+
"testrole"); // <1>
439+
// end::delete-role-request
440+
441+
// tag::delete-role-execute
448442
DeleteRoleResponse deleteRoleResponse = client.security().deleteRole(deleteRoleRequest, RequestOptions.DEFAULT);
449-
//end::delete-role-execute
450-
assertTrue(deleteRoleResponse.isFound());
443+
// end::delete-role-execute
444+
445+
// tag::delete-role-response
446+
boolean found = deleteRoleResponse.isFound(); // <1>
447+
// end::delete-role-response
448+
assertTrue(found);
451449

452450
// check if deleting the already deleted role again will give us a different response
453451
deleteRoleResponse = client.security().deleteRole(deleteRoleRequest, RequestOptions.DEFAULT);
454452
assertFalse(deleteRoleResponse.isFound());
455453
}
456454

457455
{
458-
//tag::delete-role-execute-listener
459456
DeleteRoleRequest deleteRoleRequest = new DeleteRoleRequest("testrole");
460-
ActionListener<DeleteRoleResponse> listener = new ActionListener<DeleteRoleResponse>() {
457+
458+
ActionListener<DeleteRoleResponse> listener;
459+
//tag::delete-role-execute-listener
460+
listener = new ActionListener<DeleteRoleResponse>() {
461461
@Override
462462
public void onResponse(DeleteRoleResponse deleteRoleResponse) {
463463
// <1>

docs/java-rest/high-level/document/delete.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[id="{upid}-{api}-request"]
1111
==== Delete Request
1212

13-
A +{request}+ requires the following arguments:
13+
A +{request}+ has no arguments
1414

1515
["source","java",subs="attributes,callouts,macros"]
1616
--------------------------------------------------
Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,33 @@
1-
[[java-rest-high-security-delete-role]]
1+
--
2+
:api: delete-role
3+
:request: DeleteRoleRequest
4+
:response: DeleteRoleResponse
5+
--
6+
7+
[id="{upid}-{api}"]
28
=== Delete Role API
39

4-
[[java-rest-high-security-delete-role-execution]]
5-
==== Execution
10+
[id="{upid}-{api}-request"]
11+
==== Delete Role Request
612

7-
Deleting a role can be performed using the `security().deleteRole()`
8-
method:
13+
A +{request}+ has a single argument
914

1015
["source","java",subs="attributes,callouts,macros"]
1116
--------------------------------------------------
12-
include-tagged::{doc-tests}/SecurityDocumentationIT.java[delete-role-execute]
17+
include-tagged::{doc-tests-file}[{api}-request]
1318
--------------------------------------------------
19+
<1> role to delete
1420

15-
[[java-rest-high-security-delete-role-response]]
16-
==== Response
17-
18-
The returned `DeleteRoleResponse` contains information about whether the specified role
19-
was found or not.
20-
21-
[[java-rest-high-security-delete-role-async]]
22-
==== Asynchronous Execution
23-
24-
This request can be executed asynchronously:
25-
26-
["source","java",subs="attributes,callouts,macros"]
27-
--------------------------------------------------
28-
include-tagged::{doc-tests}/SecurityDocumentationIT.java[delete-role-execute-async]
29-
--------------------------------------------------
30-
<1> The `DeleteRoleRequest` to execute and the `ActionListener` to use when
31-
the execution completes.
21+
include::../execution.asciidoc[]
3222

33-
The asynchronous method does not block and returns immediately. Once the request
34-
has completed the `ActionListener` is called back using the `onResponse` method
35-
if the execution successfully completed or using the `onFailure` method if
36-
it failed.
23+
[id="{upid}-{api}-response"]
24+
==== Delete Response
3725

38-
A typical listener for a `DeleteRoleResponse` looks like:
26+
The returned +{response}+ allows to retrieve information about the executed
27+
operation as follows:
3928

4029
["source","java",subs="attributes,callouts,macros"]
4130
--------------------------------------------------
42-
include-tagged::{doc-tests}/SecurityDocumentationIT.java[delete-role-execute-listener]
31+
include-tagged::{doc-tests-file}[{api}-response]
4332
--------------------------------------------------
44-
<1> Called when the execution is successfully completed. The response is
45-
provided as an argument.
46-
<2> Called in case of failure. The raised exception is provided as an argument.
33+
<1> whether the given role was found

docs/java-rest/high-level/supported-apis.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ include::rollup/get_rollup_caps.asciidoc[]
310310

311311
== Security APIs
312312

313+
:upid: {mainid}-security
314+
:doc-tests-file: {doc-tests}/SecurityDocumentationIT.java
315+
313316
The Java High Level REST Client supports the following Security APIs:
314317

315318
* <<java-rest-high-security-put-user>>

0 commit comments

Comments
 (0)