Search in sources :

Example 61 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class Discovery method deleteConfiguration.

/**
 * Delete a configuration.
 *
 * <p>The deletion is performed unconditionally. A configuration deletion request succeeds even if
 * the configuration is referenced by a collection or document ingestion. However, documents that
 * have already been submitted for processing continue to use the deleted configuration. Documents
 * are always processed with a snapshot of the configuration as it existed at the time the
 * document was submitted.
 *
 * @param deleteConfigurationOptions the {@link DeleteConfigurationOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link DeleteConfigurationResponse}
 */
public ServiceCall<DeleteConfigurationResponse> deleteConfiguration(DeleteConfigurationOptions deleteConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteConfigurationOptions, "deleteConfigurationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", deleteConfigurationOptions.environmentId());
    pathParamsMap.put("configuration_id", deleteConfigurationOptions.configurationId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/configurations/{configuration_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteConfiguration");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<DeleteConfigurationResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteConfigurationResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DeleteConfigurationResponse(com.ibm.watson.discovery.v1.model.DeleteConfigurationResponse)

Example 62 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project bgg-api by tnaskali.

the class ThingsService method getPrivateThings.

public Mono<Collection> getPrivateThings(String username, String cookie, CollectionParams params) {
    BggCollectionQueryParams queryParams = collectionParamsMapper.toBggModel(params);
    queryParams.setUsername(username);
    // handle subtype bug in the BBG XML API
    if (queryParams.getSubtype() == null || queryParams.getSubtype().equals(CollectionItemSubtype.boardgame.value())) {
        queryParams.setExcludesubtype(CollectionItemSubtype.boardgameexpansion.value());
    }
    queryParams.setShowprivate(1);
    return collectionRepository.getCollection(cookie, queryParams).map(xml -> xmlProcessor.toJavaObject(xml, com.boardgamegeek.collection.Collection.class)).map(collectionMapper::fromBggModel);
}
Also used : ThingsParamsMapper(li.naska.bgg.mapper.ThingsParamsMapper) CollectionParams(li.naska.bgg.resource.v3.model.CollectionParams) Version(li.naska.bgg.resource.v3.model.Thing.Version) ThingsParams(li.naska.bgg.resource.v3.model.ThingsParams) PagingHelper(li.naska.bgg.util.PagingHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) Page(li.naska.bgg.util.Page) CollectionMapper(li.naska.bgg.mapper.CollectionMapper) BggCollectionRepository(li.naska.bgg.repository.BggCollectionRepository) Service(org.springframework.stereotype.Service) Things(com.boardgamegeek.thing.Things) BggCollectionQueryParams(li.naska.bgg.repository.model.BggCollectionQueryParams) Thing(li.naska.bgg.resource.v3.model.Thing) XmlProcessor(li.naska.bgg.util.XmlProcessor) BggThingsRepository(li.naska.bgg.repository.BggThingsRepository) Video(li.naska.bgg.resource.v3.model.Thing.Video) ResponseStatusException(org.springframework.web.server.ResponseStatusException) BggThingsQueryParams(li.naska.bgg.repository.model.BggThingsQueryParams) CollectionItemSubtype(com.boardgamegeek.enums.CollectionItemSubtype) Mono(reactor.core.publisher.Mono) MarketplaceListing(li.naska.bgg.resource.v3.model.Thing.MarketplaceListing) Collectors(java.util.stream.Collectors) Comment(li.naska.bgg.resource.v3.model.Thing.Comment) PagingParams(li.naska.bgg.util.PagingParams) CollectionParamsMapper(li.naska.bgg.mapper.CollectionParamsMapper) ThingMapper(li.naska.bgg.mapper.ThingMapper) HttpStatus(org.springframework.http.HttpStatus) Flux(reactor.core.publisher.Flux) List(java.util.List) Collection(li.naska.bgg.resource.v3.model.Collection) BggCollectionQueryParams(li.naska.bgg.repository.model.BggCollectionQueryParams)

Example 63 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project bgg-api by tnaskali.

the class ThingsService method getThings.

public Mono<Collection> getThings(String username, CollectionParams params) {
    BggCollectionQueryParams queryParams = collectionParamsMapper.toBggModel(params);
    queryParams.setUsername(username);
    // handle subtype bug in the BBG XML API
    if (queryParams.getSubtype() == null || queryParams.getSubtype().equals(CollectionItemSubtype.boardgame.value())) {
        queryParams.setExcludesubtype(CollectionItemSubtype.boardgameexpansion.value());
    }
    return collectionRepository.getCollection(null, queryParams).map(xml -> xmlProcessor.toJavaObject(xml, com.boardgamegeek.collection.Collection.class)).map(collectionMapper::fromBggModel);
}
Also used : ThingsParamsMapper(li.naska.bgg.mapper.ThingsParamsMapper) CollectionParams(li.naska.bgg.resource.v3.model.CollectionParams) Version(li.naska.bgg.resource.v3.model.Thing.Version) ThingsParams(li.naska.bgg.resource.v3.model.ThingsParams) PagingHelper(li.naska.bgg.util.PagingHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) Page(li.naska.bgg.util.Page) CollectionMapper(li.naska.bgg.mapper.CollectionMapper) BggCollectionRepository(li.naska.bgg.repository.BggCollectionRepository) Service(org.springframework.stereotype.Service) Things(com.boardgamegeek.thing.Things) BggCollectionQueryParams(li.naska.bgg.repository.model.BggCollectionQueryParams) Thing(li.naska.bgg.resource.v3.model.Thing) XmlProcessor(li.naska.bgg.util.XmlProcessor) BggThingsRepository(li.naska.bgg.repository.BggThingsRepository) Video(li.naska.bgg.resource.v3.model.Thing.Video) ResponseStatusException(org.springframework.web.server.ResponseStatusException) BggThingsQueryParams(li.naska.bgg.repository.model.BggThingsQueryParams) CollectionItemSubtype(com.boardgamegeek.enums.CollectionItemSubtype) Mono(reactor.core.publisher.Mono) MarketplaceListing(li.naska.bgg.resource.v3.model.Thing.MarketplaceListing) Collectors(java.util.stream.Collectors) Comment(li.naska.bgg.resource.v3.model.Thing.Comment) PagingParams(li.naska.bgg.util.PagingParams) CollectionParamsMapper(li.naska.bgg.mapper.CollectionParamsMapper) ThingMapper(li.naska.bgg.mapper.ThingMapper) HttpStatus(org.springframework.http.HttpStatus) Flux(reactor.core.publisher.Flux) List(java.util.List) Collection(li.naska.bgg.resource.v3.model.Collection) BggCollectionQueryParams(li.naska.bgg.repository.model.BggCollectionQueryParams)

Example 64 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testCreateCollectionWOptions.

@Test
public void testCreateCollectionWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"image_count\": 10, \"training_status\": {\"objects\": {\"ready\": false, \"in_progress\": true, \"data_changed\": false, \"latest_failed\": true, \"rscnn_ready\": true, \"description\": \"description\"}}}";
    String createCollectionPath = "/v4/collections";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the CreateCollectionOptions model
    CreateCollectionOptions createCollectionOptionsModel = new CreateCollectionOptions.Builder().name("testString").description("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Collection> response = visualRecognitionService.createCollection(createCollectionOptionsModel).execute();
    assertNotNull(response);
    Collection responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateCollectionOptions(com.ibm.watson.visual_recognition.v4.model.CreateCollectionOptions) Collection(com.ibm.watson.visual_recognition.v4.model.Collection) Test(org.testng.annotations.Test)

Example 65 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testTrainWOptions.

@Test
public void testTrainWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"image_count\": 10, \"training_status\": {\"objects\": {\"ready\": false, \"in_progress\": true, \"data_changed\": false, \"latest_failed\": true, \"rscnn_ready\": true, \"description\": \"description\"}}}";
    String trainPath = "/v4/collections/testString/train";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(202).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the TrainOptions model
    TrainOptions trainOptionsModel = new TrainOptions.Builder().collectionId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Collection> response = visualRecognitionService.train(trainOptionsModel).execute();
    assertNotNull(response);
    Collection responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, trainPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) TrainOptions(com.ibm.watson.visual_recognition.v4.model.TrainOptions) Collection(com.ibm.watson.visual_recognition.v4.model.Collection) Test(org.testng.annotations.Test)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)23 HashMap (java.util.HashMap)22 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 JsonObject (com.google.gson.JsonObject)15 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)9 Collection (com.ibm.watson.discovery.v1.model.Collection)9 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 MockResponse (okhttp3.mockwebserver.MockResponse)8 Test (org.testng.annotations.Test)7 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5