diff --git a/cosmosdb/Ballerina.toml b/cosmosdb/Ballerina.toml index 05128dbc..3374fc23 100644 --- a/cosmosdb/Ballerina.toml +++ b/cosmosdb/Ballerina.toml @@ -1,10 +1,10 @@ [package] -distribution = "slbeta6" org= "ballerinax" name= "azure_cosmosdb" version= "2.1.0" authors = ["Ballerina"] keywords = ["IT Operations/Databases", "Cost/Paid", "Vendor/Microsoft"] +distribution = "slbeta6" icon = "icon.png" repository = "https://github.com/ballerina-platform/module-ballerinax-azure-cosmosdb" license = ["Apache-2.0"] diff --git a/cosmosdb/management_endpoint.bal b/cosmosdb/management_endpoint.bal index 12fa790c..2ed53d03 100644 --- a/cosmosdb/management_endpoint.bal +++ b/cosmosdb/management_endpoint.bal @@ -117,7 +117,6 @@ public isolated client class ManagementClient { remote isolated function listDatabases() returns @tainted @display {label: "Stream of Databases"} stream|Error { - http:Request request = new; string requestPath = prepareUrl([RESOURCE_TYPE_DATABASES]); map headerMap = check setMandatoryGetHeaders(self.host, self.primaryKeyOrResourceToken, http:HTTP_GET, @@ -247,7 +246,6 @@ public isolated client class ManagementClient { remote isolated function listContainers(@display {label: "Database ID"} string databaseId) returns @tainted @display {label: "Stream of Containers"} stream|Error { - http:Request request = new; string requestPath = prepareUrl([RESOURCE_TYPE_DATABASES, databaseId, RESOURCE_TYPE_COLLECTIONS]); map headerMap = check setMandatoryGetHeaders(self.host, self.primaryKeyOrResourceToken, http:HTTP_GET, @@ -291,7 +289,6 @@ public isolated client class ManagementClient { @display {label: "Container ID"} string containerId) returns @tainted @display {label: "Stream of Partition Key Ranges"} stream|Error { - http:Request request = new; string requestPath = prepareUrl([RESOURCE_TYPE_DATABASES, databaseId, RESOURCE_TYPE_COLLECTIONS, containerId, RESOURCE_TYPE_PK_RANGES]); map headerMap = check setMandatoryGetHeaders(self.host, self.primaryKeyOrResourceToken, http:HTTP_GET, @@ -793,7 +790,6 @@ public isolated client class ManagementClient { setOptionalHeaders(request, resourceDeleteOptions); http:Response response = check self.httpClient->delete(requestPath, request); - json|error value = handleResponse(response); check handleHeaderOnlyResponse(response); return mapHeadersToResultType(response); } diff --git a/cosmosdb/samples/admin-operations/container/container_operations.bal b/cosmosdb/samples/admin-operations/container/container_operations.bal index 80d9331f..3261e3cd 100644 --- a/cosmosdb/samples/admin-operations/container/container_operations.bal +++ b/cosmosdb/samples/admin-operations/container/container_operations.bal @@ -151,9 +151,9 @@ public function main() { } log:printInfo("Getting list of containers"); - stream|error containerList = managementClient->listContainers(databaseId); + stream|error containerList = managementClient->listContainers(databaseId); - if (containerList is stream) { + if (containerList is stream) { error? e = containerList.forEach(function (cosmosdb:Container container) { log:printInfo(container.toString()); }); diff --git a/cosmosdb/samples/admin-operations/database/database_operations.bal b/cosmosdb/samples/admin-operations/database/database_operations.bal index 68b63020..48e2ed56 100644 --- a/cosmosdb/samples/admin-operations/database/database_operations.bal +++ b/cosmosdb/samples/admin-operations/database/database_operations.bal @@ -102,9 +102,9 @@ public function main() { } log:printInfo("Getting list of databases"); - stream|error databaseList = managementClient->listDatabases(); + stream|error databaseList = managementClient->listDatabases(); - if (databaseList is stream) { + if (databaseList is stream) { error? e = databaseList.forEach(function (cosmosdb:Database database) { log:printInfo(database.toString()); }); diff --git a/cosmosdb/samples/admin-operations/offers/offer_operations.bal b/cosmosdb/samples/admin-operations/offers/offer_operations.bal index 87ac8f7a..ee975436 100644 --- a/cosmosdb/samples/admin-operations/offers/offer_operations.bal +++ b/cosmosdb/samples/admin-operations/offers/offer_operations.bal @@ -75,7 +75,7 @@ public function main() { string offersInContainerQuery = string `SELECT * FROM ${containerId} f WHERE (f["_self"]) = "${container?.selfReference.toString()}"`; int maximumItemCount = 20; - stream|error result = checkpanic managementClient-> + stream|error result = checkpanic managementClient-> queryOffer(<@untainted>offersInContainerQuery); log:printInfo("Success!"); } diff --git a/cosmosdb/samples/admin-operations/users-permissions/users_access_control.bal b/cosmosdb/samples/admin-operations/users-permissions/users_access_control.bal index a770c199..78d41f86 100644 --- a/cosmosdb/samples/admin-operations/users-permissions/users_access_control.bal +++ b/cosmosdb/samples/admin-operations/users-permissions/users_access_control.bal @@ -130,8 +130,8 @@ public function main() { } log:printInfo("List permissions"); - stream|error permissionList = managementClient->listPermissions(databaseId, userId); - if (permissionList is stream) { + stream|error permissionList = managementClient->listPermissions(databaseId, userId); + if (permissionList is stream) { error? e = permissionList.forEach(function (cosmosdb:Permission storedPrcedure) { log:printInfo(storedPrcedure.toString()); }); diff --git a/cosmosdb/samples/data-operations/documents/document_operations.bal b/cosmosdb/samples/data-operations/documents/document_operations.bal index eba530a4..c49c333c 100644 --- a/cosmosdb/samples/data-operations/documents/document_operations.bal +++ b/cosmosdb/samples/data-operations/documents/document_operations.bal @@ -173,9 +173,9 @@ public function main() { } log:printInfo("Getting list of documents"); - stream|error documentList = azureCosmosClient->getDocumentList(databaseId, containerId); + stream|error documentList = azureCosmosClient->getDocumentList(databaseId, containerId); - if (documentList is stream) { + if (documentList is stream) { error? e = documentList.forEach(function (cosmosdb:Document document) { log:printInfo(document.toString()); }); diff --git a/cosmosdb/stream_implementer.bal b/cosmosdb/stream_implementer.bal index 254d3bef..2c1a8577 100644 --- a/cosmosdb/stream_implementer.bal +++ b/cosmosdb/stream_implementer.bal @@ -47,6 +47,7 @@ class DatabaseStream { self.index += 1; return singleRecord; } + return; } isolated function fetchDatabases() returns @tainted Database[]|Error { @@ -97,6 +98,7 @@ class ContainerStream { self.index += 1; return singleRecord; } + return; } isolated function fetchContainers() returns @tainted Container[]|Error { @@ -147,6 +149,7 @@ class DocumentStream { self.index += 1; return singleRecord; } + return; } isolated function fetchDocuments() returns @tainted Document[]|Error { @@ -196,6 +199,7 @@ class StoredProcedureStream { self.index += 1; return singleRecord; } + return; } isolated function fetchStoredProcedures() returns @tainted StoredProcedure[]|Error { @@ -245,6 +249,7 @@ class UserDefiinedFunctionStream { self.index += 1; return singleRecord; } + return; } isolated function fetchUserDefinedFunctions() returns @tainted UserDefinedFunction[]|Error { @@ -295,6 +300,7 @@ class TriggerStream { self.index += 1; return singleRecord; } + return; } isolated function fetchTriggers() returns @tainted Trigger[]|Error { @@ -345,6 +351,7 @@ class UserStream { self.index += 1; return singleRecord; } + return; } isolated function fetchUsers() returns @tainted User[]|Error { @@ -396,6 +403,7 @@ class PermissionStream { self.index += 1; return singleRecord; } + return; } isolated function fetchPermission() returns @tainted Permission[]|Error { @@ -446,6 +454,7 @@ class OfferStream { self.index += 1; return singleRecord; } + return; } isolated function fetchOffers() returns @tainted Offer[]|Error { @@ -495,6 +504,7 @@ class PartitionKeyRangeStream { self.index += 1; return singleRecord; } + return; } isolated function fetchPKRanges() returns @tainted PartitionKeyRange[]|Error { @@ -545,6 +555,7 @@ class DocumentQueryResultStream { self.index += 1; return singleRecord; } + return; } isolated function fetchQueryResults() returns @tainted Document[]|Error { @@ -594,6 +605,7 @@ class OfferQueryResultStream { self.index += 1; return singleRecord; } + return; } isolated function fetchOfferQueryResults() returns @tainted Offer[]|Error { diff --git a/cosmosdb/tests/test.bal b/cosmosdb/tests/test.bal index d45583a4..1b2df355 100644 --- a/cosmosdb/tests/test.bal +++ b/cosmosdb/tests/test.bal @@ -170,6 +170,9 @@ function testListAllDatabases() { error? e = result.forEach(isolated function (Database queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -290,6 +293,9 @@ function testGetAllContainers() { error? e = result.forEach(isolated function (Container queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -439,6 +445,9 @@ function testGetDocumentList() { error? e = result.forEach(isolated function (Document queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -462,6 +471,9 @@ function testGetDocumentListWithRequestOptions() { error? e = result.forEach(isolated function (Document queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -520,6 +532,9 @@ function testQueryDocuments() { error? e = result.forEach(isolated function (Document queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -543,6 +558,9 @@ function testQueryDocumentsWithRequestOptions() { error? e = result.forEach(isolated function (Document queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -642,6 +660,9 @@ function testGetAllStoredProcedures() { error? e = result.forEach(isolated function (StoredProcedure queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -730,6 +751,9 @@ function testListAllUDF() { error? e = result.forEach(isolated function (UserDefinedFunction queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -855,6 +879,9 @@ function testListTriggers() { error? e = result.forEach(isolated function (Trigger queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -943,6 +970,9 @@ function testListUsers() { error? e = result.forEach(isolated function (User queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -1050,6 +1080,9 @@ function testListPermissions() { error? e = result.forEach(isolated function (Permission queryResult) { log:printInfo(queryResult.toString()); }); + if (e is error) { + log:printInfo(msg = e.message()); + } } else { test:assertFail(msg = result.message()); } @@ -1210,7 +1243,6 @@ function testQueryOffer() { function testGetContainerWithResourceToken() { log:printInfo("ACTION : createCollection_Resource_Token()"); - string permissionDatabaseId = databaseId; string permissionUserId = newUserId; string userPermissionId = permissionId; @@ -1243,7 +1275,7 @@ function afterFunc() { var result2 = azureCosmosManagementClient->deleteDatabase(createDatabaseExistId); if (result1 is DeleteResponse && result2 is DeleteResponse) { - var output = ""; + log:printInfo("Success"); } else { test:assertFail(msg = "Failed to delete one of the databases"); } diff --git a/cosmosdb/utils.bal b/cosmosdb/utils.bal index 64530794..00932c66 100644 --- a/cosmosdb/utils.bal +++ b/cosmosdb/utils.bal @@ -59,7 +59,7 @@ isolated function getResourceType(string url) returns string { if (count % 2 != 0) { resourceType = urlParts[count]; if (count > 1) { - int? lastIndex = url.lastIndexOf(FORWARD_SLASH); + _ = url.lastIndexOf(FORWARD_SLASH); } } else { resourceType = urlParts[count - 1]; @@ -318,7 +318,7 @@ isolated function setExpiryHeader(http:Request request, int validityPeriodInSeco # (in `HTTP-date` format as defined by RFC 1123 Date/Time Formats). Else returns `Error`. isolated function getDateTime() returns string|Error { [int, decimal] & readonly currentTime = time:utcNow(); - string time = check utcToString(currentTime, TIME_ZONE_FORMAT); + _ = check utcToString(currentTime, TIME_ZONE_FORMAT); return check utcToString(currentTime, TIME_ZONE_FORMAT) + " GMT"; }