use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class NoSQLTest method test_20_InsertRecord.
/**
*
*/
@Test
public void test_20_InsertRecord() {
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, guid2, valuesMap);
try {
instance.insert(collection, guid2, nameRecord.toJSONObject());
} catch (FailedDBOperationException | JSONException | RecordExistsException e) {
fail("Problem during insert " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class NoSQLTest method test_24_LookupEntireRecordGuid2Again.
/**
*
*/
@Test
public void test_24_LookupEntireRecordGuid2Again() {
JSONObject json = new JSONObject();
try {
JSONObject innerJson = new JSONObject();
innerJson.put("key", "value");
json.put("map", innerJson);
json.put("new", "newValue");
} catch (JSONException e) {
fail("Problem creating json " + e);
}
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.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class Select method aclCheckFilterFields.
/**
* This filters individual fields if the cannot be accessed by the reader.
*
* @param packet
* @param records
* @param reader
* @param app
* @return
*/
private static JSONArray aclCheckFilterFields(SelectRequestPacket packet, JSONArray records, String reader, GNSApplicationInterface<String> app) {
for (int i = 0; i < records.length(); i++) {
try {
JSONObject record = records.getJSONObject(i);
String guid = record.getString(NameRecord.NAME.getName());
// Look at the keys in the values map
JSONObject valuesMap = record.getJSONObject(NameRecord.VALUES_MAP.getName());
Iterator<?> keys = valuesMap.keys();
while (keys.hasNext()) {
String field = (String) keys.next();
if (!InternalField.isInternalField(field)) {
LOGGER.log(Level.FINE, "{0} Checking: {1}", new Object[] { app.getNodeID(), field });
ResponseCode responseCode = NSAuthentication.signatureAndACLCheck(null, guid, field, null, reader, null, null, MetaDataTypeName.READ_WHITELIST, app, true);
if (!responseCode.isOKResult()) {
LOGGER.log(Level.FINE, "{0} Removing: {1}", new Object[] { app.getNodeID(), field });
// removing the offending field
keys.remove();
}
}
}
} catch (JSONException | InvalidKeyException | InvalidKeySpecException | SignatureException | NoSuchAlgorithmException | FailedDBOperationException | UnsupportedEncodingException e) {
// ignore json errros
LOGGER.log(Level.FINE, "{0} Problem getting guid from json: {1}", new Object[] { app.getNodeID(), e.getMessage() });
}
}
return records;
}
use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class Select method aclCheckFilterForRecordsArray.
/**
* This filters entire records if the query uses fields that cannot be accessed in the
* returned record by the reader. Otherwise the user would be able to determine that
* some GUIDS contain specific values for fields they can't access.
*
* @param packet
* @param records
* @param reader
* @param app
* @return
*/
private static JSONArray aclCheckFilterForRecordsArray(SelectRequestPacket packet, JSONArray records, String reader, GNSApplicationInterface<String> app) {
JSONArray result = new JSONArray();
for (int i = 0; i < records.length(); i++) {
try {
JSONObject record = records.getJSONObject(i);
String guid = record.getString(NameRecord.NAME.getName());
List<String> queryFields = getFieldsForQueryType(packet);
ResponseCode responseCode = NSAuthentication.signatureAndACLCheck(null, guid, null, queryFields, reader, null, null, MetaDataTypeName.READ_WHITELIST, app, true);
LOGGER.log(Level.FINE, "{0} ACL check for select: guid={0} queryFields={1} responsecode={2}", new Object[] { app.getNodeID(), guid, queryFields, responseCode });
if (responseCode.isOKResult()) {
result.put(record);
}
} catch (JSONException | InvalidKeyException | InvalidKeySpecException | SignatureException | NoSuchAlgorithmException | FailedDBOperationException | UnsupportedEncodingException e) {
// ignore json errros
LOGGER.log(Level.FINE, "{0} Problem getting guid from json: {1}", new Object[] { app.getNodeID(), e.getMessage() });
}
}
return result;
}
use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class Select method handleSelectRequestFromNS.
/**
* Handle a select request from the collecting NS. This is what other NSs do when they
* get a SelectRequestPacket from the NS that originally received the packet (the one that is collecting
* all the records).
* This NS looks up the records and returns them.
*
* @param incomingJSON
* @param app
* @throws JSONException
*/
@SuppressWarnings("unchecked")
private static void handleSelectRequestFromNS(SelectRequestPacket request, GNSApplicationInterface<String> app) throws JSONException {
LOGGER.log(Level.FINE, "NS {0} {1} received query {2}", new Object[] { Select.class.getSimpleName(), app.getNodeID(), request.getSummary() });
try {
// grab the records
JSONArray jsonRecords = getJSONRecordsForSelect(request, app);
jsonRecords = aclCheckFilterReturnedRecord(request, jsonRecords, request.getReader(), app);
@SuppressWarnings("unchecked") SelectResponsePacket response = SelectResponsePacket.makeSuccessPacketForFullRecords(request.getId(), request.getClientAddress(), request.getCcpQueryId(), request.getNsQueryId(), app.getNodeAddress(), jsonRecords);
LOGGER.log(Level.FINE, "NS {0} sending back {1} record(s) in response to {2}", new Object[] { app.getNodeID(), jsonRecords.length(), request.getSummary() });
// and send them back to the originating NS
app.sendToAddress(request.getNSReturnAddress(), response.toJSONObject());
} catch (FailedDBOperationException | JSONException | IOException e) {
LOGGER.log(Level.SEVERE, "Exception while handling select request: {0}", e);
SelectResponsePacket failResponse = SelectResponsePacket.makeFailPacket(request.getId(), request.getClientAddress(), request.getNsQueryId(), app.getNodeAddress(), e.getMessage());
try {
app.sendToAddress(request.getNSReturnAddress(), failResponse.toJSONObject());
} catch (IOException f) {
LOGGER.log(Level.SEVERE, "Unable to send Failure SelectResponsePacket: {0}", f);
}
}
}
Aggregations