Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.cosmos.implementation.Paths;
import com.azure.cosmos.models.CosmosAsyncContainerResponse;
import com.azure.cosmos.models.CosmosAsyncDatabaseResponse;
import com.azure.cosmos.models.CosmosAsyncUserResponse;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosContainerRequestOptions;
import com.azure.cosmos.models.CosmosDatabaseRequestOptions;
Expand Down Expand Up @@ -542,9 +542,9 @@ public CosmosAsyncContainer getContainer(String id) {
* @return an {@link Mono} containing the single resource response with the
* created cosmos user or an error.
*/
public Mono<CosmosAsyncUserResponse> createUser(CosmosUserProperties userProperties) {
public Mono<CosmosUserResponse> createUser(CosmosUserProperties userProperties) {
return getDocClientWrapper().createUser(this.getLink(), ModelBridgeInternal.getV2User(userProperties), null)
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response, this)).single();
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response)).single();
}


Expand All @@ -559,9 +559,9 @@ public Mono<CosmosAsyncUserResponse> createUser(CosmosUserProperties userPropert
* @return an {@link Mono} containing the single resource response with the
* upserted user or an error.
*/
public Mono<CosmosAsyncUserResponse> upsertUser(CosmosUserProperties userProperties) {
public Mono<CosmosUserResponse> upsertUser(CosmosUserProperties userProperties) {
return getDocClientWrapper().upsertUser(this.getLink(), ModelBridgeInternal.getV2User(userProperties), null)
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response, this)).single();
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response)).single();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.cosmos.implementation.Paths;
import com.azure.cosmos.models.CosmosAsyncPermissionResponse;
import com.azure.cosmos.models.CosmosAsyncUserResponse;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.CosmosPermissionProperties;
import com.azure.cosmos.models.CosmosPermissionRequestOptions;
import com.azure.cosmos.models.CosmosUserProperties;
Expand Down Expand Up @@ -55,10 +55,10 @@ CosmosAsyncUser setId(String id) {
*
* @return a {@link Mono} containing the single resource response with the read user or an error.
*/
public Mono<CosmosAsyncUserResponse> read() {
public Mono<CosmosUserResponse> read() {
return this.database.getDocClientWrapper()
.readUser(getLink(), null)
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response, database)).single();
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response)).single();
}

/**
Expand All @@ -67,21 +67,21 @@ public Mono<CosmosAsyncUserResponse> read() {
* @param userSettings the user properties to use
* @return a {@link Mono} containing the single resource response with the replaced user or an error.
*/
public Mono<CosmosAsyncUserResponse> replace(CosmosUserProperties userSettings) {
public Mono<CosmosUserResponse> replace(CosmosUserProperties userSettings) {
return this.database.getDocClientWrapper()
.replaceUser(ModelBridgeInternal.getV2User(userSettings), null)
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response, database)).single();
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response)).single();
}

/**
* Delete a cosmos user
*
* @return a {@link Mono} containing the single resource response with the deleted user or an error.
*/
public Mono<CosmosAsyncUserResponse> delete() {
public Mono<CosmosUserResponse> delete() {
return this.database.getDocClientWrapper()
.deleteUser(getLink(), null)
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response, database)).single();
.map(response -> ModelBridgeInternal.createCosmosAsyncUserResponse(response)).single();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
package com.azure.cosmos;

import com.azure.cosmos.models.CosmosAsyncContainerResponse;
import com.azure.cosmos.models.CosmosAsyncUserResponse;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosContainerRequestOptions;
import com.azure.cosmos.models.CosmosContainerResponse;
import com.azure.cosmos.models.CosmosDatabaseRequestOptions;
import com.azure.cosmos.models.CosmosDatabaseResponse;
import com.azure.cosmos.models.CosmosUserProperties;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.FeedOptions;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.SqlQuerySpec;
Expand Down Expand Up @@ -477,9 +476,9 @@ public CosmosUser getUser(String id) {
return new CosmosUser(databaseWrapper.getUser(id), this, id);
}

CosmosUserResponse mapUserResponseAndBlock(Mono<CosmosAsyncUserResponse> containerMono) {
CosmosUserResponse mapUserResponseAndBlock(Mono<CosmosUserResponse> containerMono) {
try {
return containerMono.map(this::convertUserResponse).block();
return containerMono.block();
} catch (Exception ex) {
final Throwable throwable = Exceptions.unwrap(ex);
if (throwable instanceof CosmosException) {
Expand All @@ -490,10 +489,6 @@ CosmosUserResponse mapUserResponseAndBlock(Mono<CosmosAsyncUserResponse> contain
}
}

private CosmosUserResponse convertUserResponse(CosmosAsyncUserResponse response) {
return ModelBridgeInternal.createCosmosUserResponse(response, this);
}

/**
* Sets the throughput.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

package com.azure.cosmos;

import com.azure.cosmos.models.CosmosUserProperties;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.CosmosUserProperties;

/**
* The type Cosmos sync user.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,32 @@

package com.azure.cosmos.models;

import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.CosmosDatabase;
import com.azure.cosmos.CosmosUser;
import com.azure.cosmos.implementation.ResourceResponse;
import com.azure.cosmos.implementation.User;
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;

/**
* The type Cosmos sync user response.
* The type Cosmos user response. Contains methods to get properties
*/
public class CosmosUserResponse extends CosmosResponse<CosmosUserProperties> {
private final CosmosAsyncUserResponse asyncResponse;
private final CosmosUser user;

/**
* Instantiates a new Cosmos sync user response.
*
* @param response the response
* @param database the database
*/
CosmosUserResponse(CosmosAsyncUserResponse response, CosmosDatabase database) {
super(response.resourceResponseWrapper, response.getProperties());
this.asyncResponse = response;
if (response.getUser() != null) {
this.user = BridgeInternal.createCosmosUser(response.getUser(), database, response.getUser().getId());
CosmosUserResponse(ResourceResponse<User> response) {
super(response);
String bodyAsString = response.getBodyAsString();
if (StringUtils.isEmpty(bodyAsString)) {
super.setProperties(null);
} else {
// delete has null user client
this.user = null;
CosmosUserProperties props = new CosmosUserProperties(bodyAsString);
super.setProperties(props);
}
}

/**
* Gets cosmos sync user.
*
* @return the cosmos sync user
*/
public CosmosUser getUser() {
return this.user;
}

/**
* Gets cosmos user properties.
* Gets the cosmos user properties
*
* @return the cosmos user properties
* @return {@link CosmosUserProperties}
*/
public CosmosUserProperties getProperties() {
return asyncResponse.getProperties();
return super.getProperties();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public static CosmosAsyncUserDefinedFunctionResponse createCosmosAsyncUserDefine
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static CosmosAsyncUserResponse createCosmosAsyncUserResponse(ResourceResponse<User> response, CosmosAsyncDatabase database) {
return new CosmosAsyncUserResponse(response, database);
public static CosmosUserResponse createCosmosAsyncUserResponse(ResourceResponse<User> response) {
return new CosmosUserResponse(response);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
Expand All @@ -145,11 +145,6 @@ public static CosmosContainerResponse createCosmosContainerResponse(CosmosAsyncC
return new CosmosContainerResponse(response, database, client);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static CosmosUserResponse createCosmosUserResponse(CosmosAsyncUserResponse response, CosmosDatabase database) {
return new CosmosUserResponse(response, database);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static <T> CosmosItemResponse<T> createCosmosItemResponse(CosmosAsyncItemResponse<T> response) {
return new CosmosItemResponse<>(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.azure.cosmos.models.CosmosStoredProcedureResponse;
import com.azure.cosmos.models.CosmosAsyncTriggerResponse;
import com.azure.cosmos.models.CosmosAsyncUserDefinedFunctionResponse;
import com.azure.cosmos.models.CosmosAsyncUserResponse;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.CosmosConflictProperties;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosDatabaseProperties;
Expand Down Expand Up @@ -80,8 +80,8 @@ private Resource getResource(T resourceResponse) {
return ModelBridgeInternal.getResource(((CosmosAsyncTriggerResponse)resourceResponse).getProperties());
} else if (resourceResponse instanceof CosmosAsyncUserDefinedFunctionResponse) {
return ModelBridgeInternal.getResource(((CosmosAsyncUserDefinedFunctionResponse)resourceResponse).getProperties());
} else if (resourceResponse instanceof CosmosAsyncUserResponse) {
return ModelBridgeInternal.getResource(((CosmosAsyncUserResponse)resourceResponse).getProperties());
} else if (resourceResponse instanceof CosmosUserResponse) {
return ModelBridgeInternal.getResource(((CosmosUserResponse)resourceResponse).getProperties());
} else if (resourceResponse instanceof CosmosAsyncPermissionResponse) {
return ModelBridgeInternal.getResource(((CosmosAsyncPermissionResponse) resourceResponse).getProperties());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

package com.azure.cosmos;

import com.azure.cosmos.models.CosmosUserProperties;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.CosmosUserProperties;
import com.azure.cosmos.models.FeedOptions;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.cosmos.rx.TestSuiteBase;
import com.azure.cosmos.util.CosmosPagedIterable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.azure.cosmos.models.CosmosResponse;
import com.azure.cosmos.models.CosmosStoredProcedureRequestOptions;
import com.azure.cosmos.models.CosmosUserProperties;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.DataType;
import com.azure.cosmos.models.FeedOptions;
import com.azure.cosmos.models.FeedResponse;
Expand Down Expand Up @@ -499,7 +500,9 @@ public void voidBulkInsertBlocking(CosmosAsyncContainer cosmosContainer,
}

public static CosmosAsyncUser createUser(CosmosAsyncClient client, String databaseId, CosmosUserProperties userSettings) {
return client.getDatabase(databaseId).read().block().getDatabase().createUser(userSettings).block().getUser();
CosmosAsyncDatabase database = client.getDatabase(databaseId);
CosmosUserResponse userResponse = database.createUser(userSettings).block();
return database.getUser(userResponse.getProperties().getId());
}

public static CosmosAsyncUser safeCreateUser(CosmosAsyncClient client, String databaseId, CosmosUserProperties user) {
Expand Down Expand Up @@ -614,7 +617,7 @@ public static void deleteUserIfExists(CosmosAsyncClient client, String databaseI
}

public static void deleteUser(CosmosAsyncDatabase database, String userId) {
database.getUser(userId).read().block().getUser().delete().block();
database.getUser(userId).delete().block();
}

static private CosmosAsyncDatabase safeCreateDatabase(CosmosAsyncClient client, CosmosDatabaseProperties databaseSettings) {
Expand Down
Loading