Search in sources :

Example 1 with BasicGuidEntry

use of edu.umass.cs.gnsclient.client.util.BasicGuidEntry in project GNS by MobilityFirst.

the class ContextAwareGroupGuidExample method showFieldValuesInGuids.

//
// private helper methods
//
/**
   * Prints out the values of fields name field in the guids given in the guids list.
   *
   * @param guids
   * @param field
   * @throws Exception
   */
private static void showFieldValuesInGuids(JSONArray guids, String field) throws Exception {
    for (int i = 0; i < guids.length(); i++) {
        BasicGuidEntry guidInfo = new BasicGuidEntry(client.lookupGuidRecord(guids.getString(i)));
        GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(client, guidInfo.getEntityName());
        String value = client.fieldRead(entry, field);
        System.out.println(guids.get(i).toString() + ": " + field + " -> " + value);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry)

Example 2 with BasicGuidEntry

use of edu.umass.cs.gnsclient.client.util.BasicGuidEntry in project GNS by MobilityFirst.

the class ContextAwareGroupGuidExample method cleanupAllGuids.

/**
   * Removes all the sub guids we use in this example.
   *
   * @throws Exception
   */
private static void cleanupAllGuids() throws Exception {
    // Remove the two group guids
    client.guidRemove(masterGuid, groupOneGuidEntry.getGuid());
    client.guidRemove(masterGuid, groupTwoGuidEntry.getGuid());
    // Remove all the value holding guids
    String query = "~" + fieldName + " : {$exists: true}";
    JSONArray result = client.selectQuery(query);
    for (int i = 0; i < result.length(); i++) {
        BasicGuidEntry guidInfo = new BasicGuidEntry(client.lookupGuidRecord(result.getString(i)));
        GuidEntry guidEntry = GuidUtils.lookupGuidEntryFromDatabase(client, guidInfo.getEntityName());
        client.guidRemove(masterGuid, guidEntry.getGuid());
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry)

Example 3 with BasicGuidEntry

use of edu.umass.cs.gnsclient.client.util.BasicGuidEntry in project GNS by MobilityFirst.

the class ServerIntegrationTest method test_561_QueryLookupSecondGroup.

/**
   * Check to see if the second group has members now... it should.
   *
   * @param groupTestFieldName
   * @param groupTwoGuid
   */
public void test_561_QueryLookupSecondGroup(String groupTestFieldName, GuidEntry groupTwoGuid) {
    if (!enable552) {
        return;
    }
    try {
        JSONArray result = clientCommands.selectLookupGroupQuery(groupTwoGuid.getGuid());
        // should be 4 now
        Assert.assertThat(result.length(), Matchers.equalTo(4));
        // look up the individual values
        for (int i = 0; i < result.length(); i++) {
            BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
            GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
            String value = clientCommands.fieldReadArrayFirstElement(entry, groupTestFieldName);
            Assert.assertEquals("0", value);
        }
    } catch (Exception e) {
        failWithStackTrace("Exception executing selectLookupGroupQuery: ", e);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 4 with BasicGuidEntry

use of edu.umass.cs.gnsclient.client.util.BasicGuidEntry in project GNS by MobilityFirst.

the class ServerIntegrationTest method test_560_QueryLookupGroupAfterAlterations.

/**
   * Lookup the group members again after the change.
   *
   * @param groupTestFieldName
   * @param groupOneGuid
   */
public void test_560_QueryLookupGroupAfterAlterations(String groupTestFieldName, GuidEntry groupOneGuid) {
    if (!enable552) {
        return;
    }
    try {
        JSONArray result = clientCommands.selectLookupGroupQuery(groupOneGuid.getGuid());
        // should only be one
        Assert.assertThat(result.length(), Matchers.equalTo(1));
        // look up the individual values
        for (int i = 0; i < result.length(); i++) {
            BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
            GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
            String value = clientCommands.fieldReadArrayFirstElement(entry, groupTestFieldName);
            Assert.assertEquals(TEST_HIGH_VALUE, value);
        }
    } catch (Exception e) {
        failWithStackTrace("Exception executing selectLookupGroupQuery: ", e);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 5 with BasicGuidEntry

use of edu.umass.cs.gnsclient.client.util.BasicGuidEntry in project GNS by MobilityFirst.

the class ServerIntegrationTest method test_559_QueryAlterGroup.

/**
   * Change the value that the group is triggered on.
   *
   * @param groupTestFieldName
   * @param groupOneGuid
   */
// Change all the testQuery fields except 1 to be equal to zero
public void test_559_QueryAlterGroup(String groupTestFieldName, GuidEntry groupOneGuid) {
    if (!enable552) {
        return;
    }
    try {
        JSONArray result = clientCommands.selectLookupGroupQuery(groupOneGuid.getGuid());
        // change ALL BUT ONE to be ZERO
        for (int i = 0; i < result.length() - 1; i++) {
            BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
            GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
            JSONArray array = new JSONArray(Arrays.asList(0));
            clientCommands.fieldReplaceOrCreateList(entry, groupTestFieldName, array);
        }
    } catch (Exception e) {
        failWithStackTrace("Exception while trying to alter the fields: ", e);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Aggregations

BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)13 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)13 JSONArray (org.json.JSONArray)10 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)9 IOException (java.io.IOException)9 RandomString (edu.umass.cs.gnscommon.utils.RandomString)8 JSONException (org.json.JSONException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)4 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)4 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)4 FileNotFoundException (java.io.FileNotFoundException)4 Test (org.junit.Test)4 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)1 InvalidKeyException (java.security.InvalidKeyException)1 SignatureException (java.security.SignatureException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1