use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SingleRemoveGuidTest method test_01_RemoveGuidUsingAccount.
/**
*
*/
@Test
public void test_01_RemoveGuidUsingAccount() {
String testGuidName = "testGUID" + RandomString.randomString(12);
GuidEntry testGuid = null;
try {
testGuid = clientCommands.guidCreate(masterGuid, testGuidName);
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception while creating testGuid: " + e);
}
if (testGuid != null) {
try {
clientCommands.guidRemove(masterGuid, testGuid.getGuid());
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception while removing testGuid: " + e);
}
try {
clientCommands.lookupGuidRecord(testGuid.getGuid());
Utils.failWithStackTrace("Lookup testGuid should have throw an exception.");
} catch (ClientException e) {
} catch (IOException e) {
Utils.failWithStackTrace("Exception while doing Lookup testGuid: " + e);
}
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SecureCommandTest method test_15_SecureRead.
/**
* Remove the account.
*/
@Test
public void test_15_SecureRead() {
GuidEntry masterGuid = GuidUtils.getGUIDKeys(globalAccountName);
try {
client.execute(GNSCommand.guidCreate(masterGuid, "whatever"));
GuidEntry testGuid = GuidUtils.lookupGuidEntryFromDatabase(client, "whatever");
client.execute(GNSCommand.fieldUpdate(testGuid, "fred", "value"));
JSONObject actual = client.execute(GNSCommand.readSecure(testGuid.getGuid())).getResultJSONObject();
JSONAssert.assertEquals(new JSONObject().put("fred", "value"), actual, JSONCompareMode.STRICT);
client.execute(GNSCommand.guidRemove(masterGuid, testGuid.getGuid()));
} catch (ClientException | IOException | JSONException e) {
Utils.failWithStackTrace("Exception while removing account record: ", e);
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SelectRecordsExample method createUserRecords.
/**
* Create some example user records.
*/
private static void createUserRecords() {
Random random = new Random();
for (int i = 0; i < 30; i++) {
try {
client.execute(GNSCommand.createGUID(accountGuidEntry, "user-" + i));
GuidEntry userGuid = GuidUtils.getGUIDKeys("user-" + i);
System.out.print("+");
// Randomly place the in the region
double lon = LEFT_LON + (RIGHT_LON - LEFT_LON) * random.nextDouble();
double lat = BOTTOM_LAT + (TOP_LAT - BOTTOM_LAT) * random.nextDouble();
client.execute(GNSCommand.setLocation(userGuid, lon, lat));
// Add some additional random attributes
client.execute(GNSCommand.fieldUpdate(userGuid, "age", random.nextInt(40) + 20));
client.execute(GNSCommand.fieldUpdate(userGuid, "preference", random.nextInt(2) == 0 ? "Long" : "Short"));
} catch (ClientException e) {
// Catch the normal case where the records already exist
if (ResponseCode.CONFLICTING_GUID_EXCEPTION.equals(e.getCode())) {
System.out.print(".");
} else {
System.out.println("Problem creating user: " + e.getMessage());
}
} catch (IOException e) {
System.out.println("Problem creating user: " + e.getMessage());
}
}
System.out.println();
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class Select method parse.
@Override
public void parse(String commandText) throws Exception {
try {
GNSClientCommands gnsClient = module.getGnsClient();
StringTokenizer st = new StringTokenizer(commandText.trim());
GuidEntry guidEntry;
switch(st.countTokens()) {
case 2:
guidEntry = null;
break;
case 3:
String alias = st.nextToken();
guidEntry = KeyPairUtils.getGuidEntry(module.getGnsInstance(), alias);
if (guidEntry == null) {
console.printString("Unknown alias " + alias);
console.printNewline();
return;
}
break;
default:
wrongArguments();
return;
}
String field = st.nextToken();
String value = st.nextToken();
JSONArray result;
if (guidEntry != null) {
result = gnsClient.select(guidEntry, field, value);
} else {
result = gnsClient.select(field, value);
}
console.printString(result.toString());
console.printNewline();
} catch (IOException | ClientException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SetDefaultGuid method parse.
@Override
public void parse(String commandText) throws Exception {
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 1) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
GNSClientCommands gnsClient = module.getGnsClient();
try {
try {
gnsClient.lookupGuid(aliasName);
} catch (ClientException e) {
console.printString("Alias " + aliasName + " is not registered in the GNS\n");
return;
}
if (!module.isSilent()) {
console.printString("Looking up alias " + aliasName + " GUID and certificates...\n");
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid == null) {
console.printString("You do not have the private key for alias " + aliasName);
console.printNewline();
return;
}
// Success, let's update the console prompt with the new alias name
// module.setCurrentGuid(myGuid);
module.setDefaultGuidAndCheckForVerified(myGuid);
if (!module.isSilent()) {
console.printString("Default GUID set to " + aliasName + "\n");
}
} catch (IOException e) {
console.printString("Failed to access the GNS ( " + e + ")\n");
}
}
Aggregations