diff --git a/.gitignore b/.gitignore index 40f7468..ce60458 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,75 @@ .idea target/ -*.iml \ No newline at end of file +*.iml +.classpath +.project +.vscode/ +.settings/ + +# APPLE +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +#WINDOWS +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# LINUX +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* diff --git a/README.md b/README.md index 95e4d04..366aa0c 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,38 @@ UsergridResponse response = Usergrid.GET(query); List entities = response.getEntities(); ``` +- To get list of counter IDs: + +```java +List counteridslist = Usergrid.GETcounters(); + +Example: + + "data": [ + "application.collection.roles", + "application.collection.tblmformmanagements", + "application.collection.tblmforms", + "application.collection.tblmmodules", + "application.collection.tblmscreens", + "application.collection.users", + "application.collection.xmenus", + "application.entities", + "application.requests.delete", + "application.requests.get", + "application.requests.post", + "application.requests.put" + ] + +``` + +- To get value of a specific counter by ID: + +```java +long countervalue = Usergrid.GETcounterbyid("counterid"); + +Example: 12345 +``` + ### POST and PUT POST and PUT requests both require a JSON body payload. You can pass either a Java object or a `UsergridEntity` instance. While the former works in principle, best practise is to use a `UsergridEntity` wherever practical. When an entity has a uuid or name property and already exists on the server, use a PUT request to update it. If it does not, use POST to create it. diff --git a/pom.xml b/pom.xml index a4bb6dc..a2deaaf 100644 --- a/pom.xml +++ b/pom.xml @@ -13,11 +13,11 @@ 4.0.0 org.apache.usergrid usergrid-java-client - 2.2.0-SNAPSHOT + 2.2.2 jar A Java client for Usergrid http://usergrid.apache.org - + The Apache Software License, Version 2.0 @@ -51,6 +51,10 @@ rwalsh Robert Walsh + + alaksmana + Andre Laksmana + diff --git a/src/main/java/org/apache/usergrid/java/client/UsergridClient.java b/src/main/java/org/apache/usergrid/java/client/UsergridClient.java index a317d07..0d9f079 100644 --- a/src/main/java/org/apache/usergrid/java/client/UsergridClient.java +++ b/src/main/java/org/apache/usergrid/java/client/UsergridClient.java @@ -26,10 +26,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.fasterxml.jackson.databind.JsonNode; + @SuppressWarnings("unused") public class UsergridClient { @@ -215,6 +218,64 @@ public UsergridResponse sendRequest(@NotNull final UsergridRequest request) { return this.requestManager.performRequest(request); } + @NotNull + public long GETcounterbyid(@NotNull final String counterid) { + String[] pathSegments = {"counters"}; + UsergridRequest request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests(), pathSegments); + + Map parameters = new HashMap(); + parameters.put("counter", counterid); + request.setParameters(parameters); + + UsergridResponse ugResponse = this.sendRequest(request); + + long counter = -1; + if(ugResponse.ok()){ + try{ + JsonNode ugJsonResponse = ugResponse.getResponseJson(); + JsonNode ugCounterArray = ugJsonResponse.get("counters"); + JsonNode ugCounter = ugCounterArray.get(0); + JsonNode ugCounterValuesArray = ugCounter.get("values"); + JsonNode ugCounterValueObj = ugCounterValuesArray.get(0); + JsonNode ugCounterValue = ugCounterValueObj.get("value"); + return ugCounterValue.asLong(counter); + } + catch(Exception e){ + return counter; + } + } + else{ + return counter; + } + } + + @NotNull + public List GETcounters() { + String[] pathSegments = {"counters"}; + UsergridRequest request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, this.clientAppUrl(), this.authForRequests(), pathSegments); + UsergridResponse ugResponse = this.sendRequest(request); + + List counterids = new ArrayList(); + + if(ugResponse.ok()){ + try{ + JsonNode ugJsonResponse = ugResponse.getResponseJson(); + JsonNode ugCounterIdList = ugJsonResponse.get("data"); + + for(JsonNode ugCounterId : ugCounterIdList){ + counterids.add(ugCounterId.asText()); + } + } + catch(Exception e){ + return counterids; + } + return counterids; + } + else{ + return counterids; + } + } + @NotNull public UsergridResponse GET(@NotNull final String type, @NotNull final String uuidOrName) { String[] pathSegments = {type, uuidOrName}; diff --git a/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java b/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java index 1ed61da..dab4b25 100644 --- a/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java +++ b/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java @@ -28,7 +28,7 @@ public class UsergridAuth { @Nullable private String accessToken = null; @Nullable private Long expiry = null; private boolean usingToken = false; - private boolean isAdminUser = false; + boolean isAdminUser = false; public UsergridAuth() { } diff --git a/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java b/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java index 7cb42ad..2ab5739 100644 --- a/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java +++ b/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java @@ -26,8 +26,7 @@ public class UsergridUserAuth extends UsergridAuth { @NotNull private String username; @NotNull private String password; - private boolean isAdminUser = false; - + @NotNull public String getUsername() { return username; } public void setUsername(@NotNull final String username) { this.username = username; }