final AsyncCallback<AccountProjectWatchInfo> callback) {
run(callback, new Action<AccountProjectWatchInfo>() {
public AccountProjectWatchInfo run(ReviewDb db) throws OrmException,
NoSuchProjectException, InvalidQueryException {
final Project.NameKey nameKey = new Project.NameKey(projectName);
final ProjectControl ctl = projectControlFactory.validateFor(nameKey);
if (filter != null) {
try {
ChangeQueryBuilder builder = queryBuilder.create(currentUser.get());
builder.setAllowFile(true);
builder.parse(filter);
} catch (QueryParseException badFilter) {
throw new InvalidQueryException(badFilter.getMessage(), filter);
}
}
AccountProjectWatch watch =
new AccountProjectWatch(new AccountProjectWatch.Key(
((IdentifiedUser) ctl.getCurrentUser()).getAccountId(),
nameKey, filter));
try {
db.accountProjectWatches().insert(Collections.singleton(watch));
} catch (OrmDuplicateKeyException alreadyHave) {
watch = db.accountProjectWatches().get(watch.getKey());
}
return new AccountProjectWatchInfo(watch, ctl.getProject());
}
});
}