Skip to content

Commit

Permalink
Merge pull request #49 from sachinira/slbeta6-release
Browse files Browse the repository at this point in the history
Fix warnings for slbeta6 release
  • Loading branch information
RolandHewage authored Dec 14, 2021
2 parents 6087ff5 + 13c2ae4 commit 28a681b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cosmosdb/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
4 changes: 0 additions & 4 deletions cosmosdb/management_endpoint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public isolated client class ManagementClient {
remote isolated function listDatabases() returns
@tainted @display {label: "Stream of Databases"}
stream<Database, error?>|Error {
http:Request request = new;
string requestPath = prepareUrl([RESOURCE_TYPE_DATABASES]);

map<string> headerMap = check setMandatoryGetHeaders(self.host, self.primaryKeyOrResourceToken, http:HTTP_GET,
Expand Down Expand Up @@ -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<Container, error?>|Error {
http:Request request = new;
string requestPath = prepareUrl([RESOURCE_TYPE_DATABASES, databaseId, RESOURCE_TYPE_COLLECTIONS]);

map<string> headerMap = check setMandatoryGetHeaders(self.host, self.primaryKeyOrResourceToken, http:HTTP_GET,
Expand Down Expand Up @@ -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<PartitionKeyRange, error?>|Error {
http:Request request = new;
string requestPath = prepareUrl([RESOURCE_TYPE_DATABASES, databaseId, RESOURCE_TYPE_COLLECTIONS, containerId,
RESOURCE_TYPE_PK_RANGES]);
map<string> headerMap = check setMandatoryGetHeaders(self.host, self.primaryKeyOrResourceToken, http:HTTP_GET,
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public function main() {
}

log:printInfo("Getting list of containers");
stream<cosmosdb:Container,error>|error containerList = managementClient->listContainers(databaseId);
stream<cosmosdb:Container,error?>|error containerList = managementClient->listContainers(databaseId);

if (containerList is stream<cosmosdb:Container,error>) {
if (containerList is stream<cosmosdb:Container,error?>) {
error? e = containerList.forEach(function (cosmosdb:Container container) {
log:printInfo(container.toString());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public function main() {
}

log:printInfo("Getting list of databases");
stream<cosmosdb:Database,error>|error databaseList = managementClient->listDatabases();
stream<cosmosdb:Database,error?>|error databaseList = managementClient->listDatabases();

if (databaseList is stream<cosmosdb:Database,error>) {
if (databaseList is stream<cosmosdb:Database,error?>) {
error? e = databaseList.forEach(function (cosmosdb:Database database) {
log:printInfo(database.toString());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function main() {
string offersInContainerQuery =
string `SELECT * FROM ${containerId} f WHERE (f["_self"]) = "${container?.selfReference.toString()}"`;
int maximumItemCount = 20;
stream<cosmosdb:QueryResult, error>|error result = checkpanic managementClient->
stream<cosmosdb:QueryResult, error?>|error result = checkpanic managementClient->
queryOffer(<@untainted>offersInContainerQuery);
log:printInfo("Success!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public function main() {
}

log:printInfo("List permissions");
stream<cosmosdb:Permission, error>|error permissionList = managementClient->listPermissions(databaseId, userId);
if (permissionList is stream<cosmosdb:Permission, error>) {
stream<cosmosdb:Permission, error?>|error permissionList = managementClient->listPermissions(databaseId, userId);
if (permissionList is stream<cosmosdb:Permission, error?>) {
error? e = permissionList.forEach(function (cosmosdb:Permission storedPrcedure) {
log:printInfo(storedPrcedure.toString());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ public function main() {
}

log:printInfo("Getting list of documents");
stream<cosmosdb:Document, error>|error documentList = azureCosmosClient->getDocumentList(databaseId, containerId);
stream<cosmosdb:Document, error?>|error documentList = azureCosmosClient->getDocumentList(databaseId, containerId);

if (documentList is stream<cosmosdb:Document, error>) {
if (documentList is stream<cosmosdb:Document, error?>) {
error? e = documentList.forEach(function (cosmosdb:Document document) {
log:printInfo(document.toString());
});
Expand Down
12 changes: 12 additions & 0 deletions cosmosdb/stream_implementer.bal
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DatabaseStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchDatabases() returns @tainted Database[]|Error {
Expand Down Expand Up @@ -97,6 +98,7 @@ class ContainerStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchContainers() returns @tainted Container[]|Error {
Expand Down Expand Up @@ -147,6 +149,7 @@ class DocumentStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchDocuments() returns @tainted Document[]|Error {
Expand Down Expand Up @@ -196,6 +199,7 @@ class StoredProcedureStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchStoredProcedures() returns @tainted StoredProcedure[]|Error {
Expand Down Expand Up @@ -245,6 +249,7 @@ class UserDefiinedFunctionStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchUserDefinedFunctions() returns @tainted UserDefinedFunction[]|Error {
Expand Down Expand Up @@ -295,6 +300,7 @@ class TriggerStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchTriggers() returns @tainted Trigger[]|Error {
Expand Down Expand Up @@ -345,6 +351,7 @@ class UserStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchUsers() returns @tainted User[]|Error {
Expand Down Expand Up @@ -396,6 +403,7 @@ class PermissionStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchPermission() returns @tainted Permission[]|Error {
Expand Down Expand Up @@ -446,6 +454,7 @@ class OfferStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchOffers() returns @tainted Offer[]|Error {
Expand Down Expand Up @@ -495,6 +504,7 @@ class PartitionKeyRangeStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchPKRanges() returns @tainted PartitionKeyRange[]|Error {
Expand Down Expand Up @@ -545,6 +555,7 @@ class DocumentQueryResultStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchQueryResults() returns @tainted Document[]|Error {
Expand Down Expand Up @@ -594,6 +605,7 @@ class OfferQueryResultStream {
self.index += 1;
return singleRecord;
}
return;
}

isolated function fetchOfferQueryResults() returns @tainted Offer[]|Error {
Expand Down
36 changes: 34 additions & 2 deletions cosmosdb/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -1210,7 +1243,6 @@ function testQueryOffer() {
function testGetContainerWithResourceToken() {
log:printInfo("ACTION : createCollection_Resource_Token()");

string permissionDatabaseId = databaseId;
string permissionUserId = newUserId;
string userPermissionId = permissionId;

Expand Down Expand Up @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions cosmosdb/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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";
}

Expand Down

0 comments on commit 28a681b

Please sign in to comment.