Skip to content
This repository was archived by the owner on Jan 5, 2022. It is now read-only.
Open
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
74 changes: 73 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,75 @@
.idea
target/
*.iml
*.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*
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ UsergridResponse response = Usergrid.GET(query);
List<UsergridEntity> entities = response.getEntities();
```

- To get list of counter IDs:

```java
List<String> 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.
Expand Down
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.usergrid</groupId>
<artifactId>usergrid-java-client</artifactId>
<version>2.2.0-SNAPSHOT</version>
<version>2.2.2</version>
<packaging>jar</packaging>
<description>A Java client for Usergrid</description>
<url>http://usergrid.apache.org</url>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand Down Expand Up @@ -51,6 +51,10 @@
<id>rwalsh</id>
<name>Robert Walsh</name>
</developer>
<developer>
<id>alaksmana</id>
<name>Andre Laksmana</name>
</developer>
</developers>

<build>
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/org/apache/usergrid/java/client/UsergridClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<String, Object> parameters = new HashMap<String, Object>();
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<String> 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<String> counterids = new ArrayList<String>();

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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down