final String fetchPlan = urlParts.length > 3 ? urlParts[3] : null;
iRequest.data.commandInfo = "Load document";
final ORecord rec;
final int parametersPos = urlParts[2].indexOf('?');
final String rid = parametersPos > -1 ? urlParts[2].substring(0, parametersPos) : urlParts[2];
try {
db = getProfiledDatabaseInstance(iRequest);
rec = db.load(new ORecordId(rid), fetchPlan);
if (rec == null)
iResponse.send(OHttpUtils.STATUS_NOTFOUND_CODE, "Not Found", OHttpUtils.CONTENT_JSON, "Record with id '" + urlParts[2]
+ "' was not found.", null);
else if (iRequest.httpMethod.equals("HEAD"))
// JUST SEND HTTP CODE 200
iResponse.send(OHttpUtils.STATUS_OK_CODE, OHttpUtils.STATUS_OK_DESCRIPTION, null, null,
OHttpUtils.HEADER_ETAG + rec.getVersion());
else {
final String ifNoneMatch = iRequest.getHeader("If-None-Match");
if (ifNoneMatch != null && rec.getRecordVersion().toString().equals(ifNoneMatch)) {
// SAME CONTENT, DON'T SEND BACK RECORD
iResponse.send(OHttpUtils.STATUS_OK_NOMODIFIED_CODE, OHttpUtils.STATUS_OK_NOMODIFIED_DESCRIPTION, null, null,
OHttpUtils.HEADER_ETAG + rec.getVersion());
}
// SEND THE DOCUMENT BACK
iResponse.writeRecord(rec, fetchPlan, null);
}