use of edu.umass.cs.gnsserver.utils.ValuesMap in project GNS by MobilityFirst.
the class AccountAccess method lookupPrimaryGuid.
/**
* If this is a subguid associated with an account, returns the guid of that
* account, otherwise returns null.
* <p>
* guid = Globally Unique Identifier
*
* @param header
* @param guid
* @param handler
* @param allowRemoteLookup
* @return a guid
*/
public static String lookupPrimaryGuid(InternalRequestHeader header, String guid, ClientRequestHandlerInterface handler, boolean allowRemoteLookup) {
try {
ValuesMap result = NSFieldAccess.lookupJSONFieldLocalNoAuth(null, guid, PRIMARY_GUID, handler.getApp(), false);
GNSConfig.getLogger().log(Level.FINE, "ValuesMap for {0} / {1}: {2}", new Object[] { guid, PRIMARY_GUID, result });
if (result != null) {
return result.getString(PRIMARY_GUID);
}
} catch (FailedDBOperationException | JSONException e) {
GNSConfig.getLogger().log(Level.SEVERE, "Problem extracting PRIMARY_GUID from {0} :{1}", new Object[] { guid, e });
}
String value = null;
GNSConfig.getLogger().log(Level.FINE, "PRIMARY_GUID NOT FOUND LOCALLY for {0}", guid);
if (allowRemoteLookup) {
GNSConfig.getLogger().log(Level.FINE, "LOOKING REMOTELY for PRIMARY_GUID for {0}", guid);
try {
value = handler.getInternalClient().execute(GNSCommandInternal.fieldRead(guid, PRIMARY_GUID, header)).getResultString();
if (!FieldAccess.SINGLE_FIELD_VALUE_ONLY && value != null) {
value = new JSONObject(value).getString(PRIMARY_GUID);
}
} catch (IOException | JSONException | ClientException | InternalRequestException e) {
GNSConfig.getLogger().log(Level.SEVERE, "Problem getting HRN_GUID for {0} from remote server: {1}", new Object[] { guid, e });
}
}
return value;
}
use of edu.umass.cs.gnsserver.utils.ValuesMap in project GNS by MobilityFirst.
the class NoSQLTest method test_21_UpdateEntireRecord.
/**
*
*/
@Test
public void test_21_UpdateEntireRecord() {
JSONObject json = new JSONObject();
try {
JSONObject innerJson = new JSONObject();
innerJson.put("key", "value");
json.put("map", innerJson);
} catch (JSONException e) {
fail("Problem creating json " + e);
}
ValuesMap valuesMap = new ValuesMap(json);
NameRecord nameRecord = new NameRecord(recordMap, guid2, valuesMap);
try {
instance.updateEntireRecord(collection, guid2, nameRecord.getValuesMap());
} catch (FailedDBOperationException | FieldNotFoundException e) {
fail("Problem during insert " + e);
}
}
use of edu.umass.cs.gnsserver.utils.ValuesMap in project GNS by MobilityFirst.
the class NoSQLTest method test_03_LookupEntireRecord.
/**
*
*/
@Test
public void test_03_LookupEntireRecord() {
JSONObject json = new JSONObject();
try {
json.put(field, "some value");
} catch (JSONException e) {
fail("Problem creating json: " + e);
}
ValuesMap valuesMap = new ValuesMap(json);
JSONObject expected = new JSONObject();
try {
expected.put(NameRecord.NAME.getName(), guid);
expected.put(NameRecord.VALUES_MAP.getName(), valuesMap);
} catch (JSONException e) {
fail("Problem creating json expected value: " + e);
}
try {
JSONAssert.assertEquals(expected, instance.lookupEntireRecord(collection, guid), JSONCompareMode.STRICT);
} catch (RecordNotFoundException | FailedDBOperationException | JSONException e) {
fail("Problem during LookupEntireRecord: " + e);
}
}
use of edu.umass.cs.gnsserver.utils.ValuesMap in project GNS by MobilityFirst.
the class NoSQLTest method test_31_LookupEntireRecordGuid2YetAgain.
/**
*
*/
@Test
public void test_31_LookupEntireRecordGuid2YetAgain() {
JSONObject json = new JSONObject();
ValuesMap valuesMap = new ValuesMap(json);
JSONObject expected = new JSONObject();
try {
expected.put(NameRecord.NAME.getName(), guid2);
expected.put(NameRecord.VALUES_MAP.getName(), valuesMap);
} catch (JSONException e) {
fail("Problem creating json expected value: " + e);
}
try {
JSONAssert.assertEquals(expected, instance.lookupEntireRecord(collection, guid2), JSONCompareMode.STRICT);
} catch (RecordNotFoundException | FailedDBOperationException | JSONException e) {
fail("Problem during LookupEntireRecord: " + e);
}
}
use of edu.umass.cs.gnsserver.utils.ValuesMap in project GNS by MobilityFirst.
the class NoSQLTest method test_01_Insert.
/**
*
*/
@Test
public void test_01_Insert() {
JSONObject json = new JSONObject();
try {
json.put(field, "some value");
} catch (JSONException e) {
fail("Problem creating json " + e);
}
ValuesMap valuesMap = new ValuesMap(json);
NameRecord nameRecord = new NameRecord(recordMap, guid, valuesMap);
try {
instance.insert(collection, guid, nameRecord.toJSONObject());
} catch (FailedDBOperationException | JSONException | RecordExistsException e) {
fail("Problem during insert " + e);
}
}
Aggregations