use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.
the class DatabaseNigoriProtocol method getRevisions.
@Override
public GetRevisionsResponse getRevisions(GetRevisionsRequest request) throws IOException, NotFoundException, UnauthorisedException {
byte[] index = request.getKey().toByteArray();
AuthenticateRequest auth = request.getAuth();
User user = authenticateUser(auth, MessageLibrary.REQUEST_GET_REVISIONS, index);
Collection<byte[]> value = database.getRevisions(user, index);
if (value == null) {
throw new NotFoundException("Cannot find requested key");
}
return MessageLibrary.getRevisionsResponseAsProtobuf(value);
}
use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.
the class DatabaseNigoriProtocol method get.
@Override
public GetResponse get(GetRequest request) throws IOException, NotFoundException, UnauthorisedException {
byte[] index = request.getKey().toByteArray();
AuthenticateRequest auth = request.getAuth();
User user;
byte[] revision = null;
if (request.hasRevision()) {
revision = request.getRevision().toByteArray();
user = authenticateUser(auth, MessageLibrary.REQUEST_GET, index, revision);
} else {
user = authenticateUser(auth, MessageLibrary.REQUEST_GET, index);
}
Collection<RevValue> value;
if (request.hasRevision()) {
value = new ArrayList<RevValue>(1);
RevValue revVal = database.getRevision(user, index, revision);
if (revVal == null) {
throw new NotFoundException("Cannot find requested index with revision");
}
value.add(revVal);
} else {
value = database.getRecord(user, index);
}
if (value == null) {
throw new NotFoundException("No value for that index");
}
return MessageLibrary.getResponseAsProtobuf(value);
}
Aggregations