Skip to content

Commit

Permalink
Add public APIs for listing skillsets (Azure#254)
Browse files Browse the repository at this point in the history
* Add public APIs for listing skillsets
  • Loading branch information
sakintoye authored Nov 13, 2019
1 parent ef7d3ca commit 2be2ce7
Show file tree
Hide file tree
Showing 28 changed files with 581 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.azure.search.models.IndexerExecutionInfo;
import com.azure.search.models.RequestOptions;
import com.azure.search.models.Skillset;
import com.azure.search.models.SkillsetListResult;
import com.azure.search.models.SynonymMap;
import com.azure.search.models.TokenInfo;
import org.apache.commons.lang3.NotImplementedException;
Expand Down Expand Up @@ -1097,19 +1096,57 @@ Mono<Response<Skillset>> getSkillsetWithResponse(String skillsetName,
}

/**
* @return all Skillsets in the Search service.
* @throws NotImplementedException not implemented
* Lists all skillsets available for an Azure Cognitive Search service.
*
* @return a reactive response emitting the list of skillsets.
*/
public Mono<SkillsetListResult> listSkillsets() {
throw logger.logExceptionAsError(new NotImplementedException("not implemented."));
public PagedFlux<Skillset> listSkillsets() {
return this.listSkillsets(null, null);
}

/**
* @return a response containing all Skillsets in the Search service.
* @throws NotImplementedException not implemented
* Lists all skillsets available for an Azure Cognitive Search service.
*
* @param select selects which top-level properties of the skillset definitions to retrieve.
* Specified as a comma-separated list of JSON property names, or '*' for all properties.
* The default is all properties
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @return a reactive response emitting the list of skillsets.
*/
public Mono<Response<SkillsetListResult>> listSkillsetsWithResponse() {
throw logger.logExceptionAsError(new NotImplementedException("not implemented."));
public PagedFlux<Skillset> listSkillsets(String select, RequestOptions requestOptions) {
return new PagedFlux<>(
() -> this.listSkillsetsWithResponse(select, requestOptions),
nextLink -> Mono.empty());
}

/**
* Lists all skillsets available for an Azure Cognitive Search service.
*
* @param select selects which top-level properties of the skillset definitions to retrieve.
* Specified as a comma-separated list of JSON property names, or '*' for all properties.
* The default is all properties
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @return a response emitting the list of skillsets.
*/
public Mono<PagedResponse<Skillset>> listSkillsetsWithResponse(String select, RequestOptions requestOptions) {
return withContext(context -> this.listSkillsetsWithResponse(select, requestOptions, context));
}

Mono<PagedResponse<Skillset>> listSkillsetsWithResponse(String select,
RequestOptions requestOptions,
Context context) {
return this.restClient.skillsets()
.listWithRestResponseAsync(select, requestOptions, context)
.map(response -> new PagedResponseBase<>(
response.getRequest(),
response.getStatusCode(),
response.getHeaders(),
response.getValue().getSkillsets(),
null,
deserializeHeaders(response.getHeaders()))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.azure.search.models.IndexerExecutionInfo;
import com.azure.search.models.RequestOptions;
import com.azure.search.models.Skillset;
import com.azure.search.models.SkillsetListResult;
import com.azure.search.models.SynonymMap;

import com.azure.search.models.TokenInfo;
Expand Down Expand Up @@ -981,19 +980,43 @@ public Response<Skillset> getSkillsetWithResponse(String skillsetName,
}

/**
* @return all Skillsets in the Search service.
* @throws NotImplementedException not implemented
* Lists all skillsets available for an Azure Cognitive Search service.
*
* @return the list of skillsets.
*/
public SkillsetListResult listSkillsets() {
throw logger.logExceptionAsError(new NotImplementedException("not implemented."));
public PagedIterable<Skillset> listSkillsets() {
return new PagedIterable<>(asyncClient.listSkillsets());
}

/**
* @return a response containing all Skillsets in the Search service.
* @throws NotImplementedException not implemented
* Lists all skillsets available for an Azure Cognitive Search service.
*
* @param select selects which top-level properties of the skillset definitions to retrieve.
* Specified as a comma-separated list of JSON property names, or '*' for all properties.
* The default is all properties
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @return the list of skillsets.
*/
public Response<SkillsetListResult> listSkillsetsWithResponse() {
throw logger.logExceptionAsError(new NotImplementedException("not implemented."));
public PagedIterable<Skillset> listSkillsets(String select, RequestOptions requestOptions) {
return new PagedIterable<>(asyncClient.listSkillsets(select, requestOptions));
}

/**
* Lists all skillsets available for an Azure Cognitive Search service.
*
* @param select selects which top-level properties of the skillset definitions to retrieve.
* Specified as a comma-separated list of JSON property names, or '*' for all properties.
* The default is all properties
* @param requestOptions additional parameters for the operation.
* Contains the tracking ID sent with the request to help with debugging
* @param context Additional context that is passed through the HTTP pipeline during the service call.
* @return a response emitting the list of skillsets.
*/
public PagedResponse<Skillset> listSkillsetsWithResponse(String select,
RequestOptions requestOptions,
Context context) {
return asyncClient.listSkillsetsWithResponse(select, requestOptions, context).block();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
package com.azure.search;

import com.azure.core.exception.HttpResponseException;

import com.azure.core.http.rest.PagedFlux;
import com.azure.search.models.EntityCategory;
import com.azure.search.models.KeyPhraseExtractionSkillLanguage;
import com.azure.search.models.OcrSkillLanguage;
import com.azure.search.models.RequestOptions;
import com.azure.search.models.SentimentSkillLanguage;
import com.azure.search.models.Skillset;
import com.azure.search.models.SplitSkillLanguage;
Expand Down Expand Up @@ -280,6 +283,46 @@ public void getSkillsetThrowsOnNotFound() {
});
}

@Override
public void canCreateAndListSkillsets() {
Skillset skillset1 = createSkillsetWithCognitiveServicesKey();
Skillset skillset2 = createSkillsetWithEntityRecognitionDefaultSettings();

client.createSkillset(skillset1).block();
client.createSkillset(skillset2).block();

PagedFlux<Skillset> listResponse = client.listSkillsets();

StepVerifier
.create(listResponse.collectList())
.assertNext(result -> {
Assert.assertEquals(2, result.size());
Assert.assertEquals(skillset1.getName(), result.get(0).getName());
Assert.assertEquals(skillset2.getName(), result.get(1).getName());
})
.verifyComplete();
}

@Override
public void canListSkillsetsWithSelectedField() {
Skillset skillset1 = createSkillsetWithCognitiveServicesKey();
Skillset skillset2 = createSkillsetWithEntityRecognitionDefaultSettings();

client.createSkillset(skillset1).block();
client.createSkillset(skillset2).block();

PagedFlux<Skillset> listResponse = client.listSkillsets("name", new RequestOptions());

StepVerifier
.create(listResponse.collectList())
.assertNext(result -> {
Assert.assertEquals(2, result.size());
Assert.assertEquals(skillset1.getName(), result.get(0).getName());
Assert.assertEquals(skillset2.getName(), result.get(1).getName());
})
.verifyComplete();
}

@Override
public void deleteSkillsetIsIdempotent() {
Skillset skillset = createSkillsetWithOcrDefaultSettings(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
package com.azure.search;

import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.search.models.EntityCategory;
import com.azure.search.models.KeyPhraseExtractionSkillLanguage;
import com.azure.search.models.OcrSkillLanguage;
import com.azure.search.models.RequestOptions;
import com.azure.search.models.SentimentSkillLanguage;
import com.azure.search.models.Skillset;
import com.azure.search.models.SplitSkillLanguage;
Expand All @@ -17,6 +19,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class SkillsetManagementSyncTests extends SkillsetManagementTestBase {
private SearchServiceClient client;
Expand Down Expand Up @@ -235,6 +238,39 @@ public void getSkillsetThrowsOnNotFound() {
}
}

@Override
public void canCreateAndListSkillsets() {
Skillset skillset1 = createSkillsetWithCognitiveServicesKey();
Skillset skillset2 = createSkillsetWithEntityRecognitionDefaultSettings();

client.createSkillset(skillset1);
client.createSkillset(skillset2);

PagedIterable<Skillset> actual = client.listSkillsets();
List<Skillset> result = actual.stream().collect(Collectors.toList());

Assert.assertEquals(2, result.size());
Assert.assertEquals(skillset1.getName(), result.get(0).getName());
Assert.assertEquals(skillset2.getName(), result.get(1).getName());
}

@Override
public void canListSkillsetsWithSelectedField() {
Skillset skillset1 = createSkillsetWithCognitiveServicesKey();
Skillset skillset2 = createSkillsetWithEntityRecognitionDefaultSettings();

client.createSkillset(skillset1);
client.createSkillset(skillset2);

PagedIterable<Skillset> selectedFieldListResponse = client.listSkillsets("name",
new RequestOptions());
List<Skillset> result = selectedFieldListResponse.stream().collect(Collectors.toList());

Assert.assertEquals(2, result.size());
Assert.assertEquals(result.get(0).getName(), skillset1.getName());
Assert.assertEquals(result.get(1).getName(), skillset2.getName());
}

@Override
public void deleteSkillsetIsIdempotent() {
Skillset skillset = createSkillsetWithOcrDefaultSettings(false);
Expand Down
Loading

0 comments on commit 2be2ce7

Please sign in to comment.