@QueryParam("sortBy") final String sortBy,
@QueryParam("connectionId") final String connectionId,
@Context final HttpServletRequest request) {
String response = new ResponseTemplate().execute(logger, connectionId, request, new ResponseCallback() {
public Object execute() throws Exception {
GridFSService gridFSService = new GridFSServiceImpl(connectionId);
int startIndex = query.indexOf("("), endIndex = query.lastIndexOf(")");
String cmdStr = query.substring(0, startIndex);
int lastIndexOfDot = cmdStr.lastIndexOf(".");
if (lastIndexOfDot + 1 == cmdStr.length()) {
// In this case the cmsStr = db.gridFSName.
throw new InvalidMongoCommandException(ErrorCodes.COMMAND_EMPTY, "Command is empty");
}
int firstIndexOfDot = cmdStr.indexOf(".");
int indexOfDotAtCollectionName = cmdStr.lastIndexOf(".", lastIndexOfDot - 1);
String bucket = cmdStr.substring(firstIndexOfDot + 1, indexOfDotAtCollectionName);
String collectionName = cmdStr.substring(indexOfDotAtCollectionName + 1, lastIndexOfDot);
String command = cmdStr.substring(lastIndexOfDot + 1, cmdStr.length());
if (firstIndexOfDot != lastIndexOfDot) {
// when commands are of the form db.bucketName.find
} else {
throw new InvalidMongoCommandException(ErrorCodes.INVALID_COMMAND, "Invalid command");
}
String jsonStr = query.substring(startIndex + 1, endIndex);
return gridFSService.executeQuery(dbName, bucket, collectionName, command, jsonStr, skip, limit, sortBy);
}
});
return response.replace("\\", "").replace("\"{", "{").replace("}\"", "}");
}