Search in sources :

Example 6 with CosmosStoredProcedureResponse

use of com.azure.cosmos.models.CosmosStoredProcedureResponse in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosTransferProcessStoreIntegrationTest method uploadStoredProcedure.

private static void uploadStoredProcedure(CosmosContainer container, String name) {
    var is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name + ".js");
    if (is == null) {
        throw new AssertionError("The input stream referring to the " + name + " file cannot be null!");
    }
    Scanner s = new Scanner(is).useDelimiter("\\A");
    String body = s.hasNext() ? s.next() : "";
    CosmosStoredProcedureProperties props = new CosmosStoredProcedureProperties(name, body);
    CosmosScripts scripts = container.getScripts();
    if (scripts.readAllStoredProcedures().stream().noneMatch(sp -> sp.getId().equals(name))) {
        CosmosStoredProcedureResponse storedProcedure = scripts.createStoredProcedure(props);
    }
}
Also used : Scanner(java.util.Scanner) CosmosStoredProcedureProperties(com.azure.cosmos.models.CosmosStoredProcedureProperties) CosmosStoredProcedureResponse(com.azure.cosmos.models.CosmosStoredProcedureResponse) CosmosScripts(com.azure.cosmos.CosmosScripts)

Aggregations

CosmosStoredProcedureResponse (com.azure.cosmos.models.CosmosStoredProcedureResponse)6 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)5 PartitionKey (com.azure.cosmos.models.PartitionKey)5 CosmosContainer (com.azure.cosmos.CosmosContainer)2 CosmosDatabase (com.azure.cosmos.CosmosDatabase)2 CosmosScripts (com.azure.cosmos.CosmosScripts)2 BadRequestException (com.azure.cosmos.implementation.BadRequestException)2 CosmosItemResponse (com.azure.cosmos.models.CosmosItemResponse)2 CosmosStoredProcedureProperties (com.azure.cosmos.models.CosmosStoredProcedureProperties)2 CosmosPagedIterable (com.azure.cosmos.util.CosmosPagedIterable)2 ChronoUnit (java.time.temporal.ChronoUnit)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Scanner (java.util.Scanner)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 RetryPolicy (net.jodah.failsafe.RetryPolicy)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 CosmosDbApiImpl (org.eclipse.dataspaceconnector.azure.cosmos.CosmosDbApiImpl)2