use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class CreateMergePatchSet method findBasePatchSet.
private PatchSet findBasePatchSet(String baseChange) throws PermissionBackendException, UnprocessableEntityException {
List<ChangeNotes> notes = changeFinder.find(baseChange);
if (notes.size() != 1) {
throw new UnprocessableEntityException("Base change not found: " + baseChange);
}
ChangeNotes change = Iterables.getOnlyElement(notes);
try {
permissionBackend.currentUser().change(change).check(ChangePermission.READ);
} catch (AuthException e) {
throw new UnprocessableEntityException("Read not permitted for " + baseChange, e);
}
return psUtil.current(change);
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ChangesCollection method parse.
public ChangeResource parse(Change.Id id) throws ResourceConflictException, ResourceNotFoundException, PermissionBackendException {
List<ChangeNotes> notes = changeFinder.find(id);
if (notes.isEmpty()) {
throw new ResourceNotFoundException(toIdString(id));
} else if (notes.size() != 1) {
throw new ResourceNotFoundException("Multiple changes found for " + id);
}
ChangeNotes change = notes.get(0);
if (!canRead(change)) {
throw new ResourceNotFoundException(toIdString(id));
}
checkProjectStatePermitsRead(change.getProjectName());
return changeResourceFactory.create(change, user.get());
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ChangeFinder method find.
/**
* Find at most N changes matching the given identifier.
*
* @param id change identifier.
* @param queryLimit maximum number of changes to be returned
* @return possibly-empty list of notes for all matching changes; may or may not be visible.
*/
public List<ChangeNotes> find(String id, int queryLimit) {
if (id.isEmpty()) {
return Collections.emptyList();
}
int z = id.lastIndexOf('~');
int y = id.lastIndexOf('~', z - 1);
if (y < 0 && z > 0) {
// Try project~numericChangeId
Integer n = Ints.tryParse(id.substring(z + 1));
if (n != null) {
changeIdCounter.increment(ChangeIdType.PROJECT_NUMERIC_ID);
return fromProjectNumber(id.substring(0, z), n.intValue());
}
}
if (y < 0 && z < 0) {
// Try numeric changeId
Integer n = Ints.tryParse(id);
if (n != null) {
changeIdCounter.increment(ChangeIdType.NUMERIC_ID);
return find(Change.id(n));
}
}
// Use the index to search for changes, but don't return any stored fields,
// to force rereading in case the index is stale.
InternalChangeQuery query = queryProvider.get().noFields();
if (queryLimit > 0) {
query.setLimit(queryLimit);
}
// Try commit hash
if (id.matches("^([0-9a-fA-F]{" + ObjectIds.ABBREV_STR_LEN + "," + ObjectIds.STR_LEN + "})$")) {
changeIdCounter.increment(ChangeIdType.COMMIT_HASH);
return asChangeNotes(query.byCommit(id));
}
if (y > 0 && z > 0) {
// Try change triplet (project~branch~Ihash...)
Optional<ChangeTriplet> triplet = ChangeTriplet.parse(id, y, z);
if (triplet.isPresent()) {
ChangeTriplet t = triplet.get();
changeIdCounter.increment(ChangeIdType.TRIPLET);
return asChangeNotes(query.byBranchKey(t.branch(), t.id()));
}
}
// Try isolated Ihash... format ("Change-Id: Ihash").
List<ChangeNotes> notes = asChangeNotes(query.byKeyPrefix(id));
if (!notes.isEmpty()) {
changeIdCounter.increment(ChangeIdType.I_HASH);
}
return notes;
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ChangeJson method checkOnly.
private ChangeInfo checkOnly(ChangeData cd) {
ChangeNotes notes;
try {
notes = cd.notes();
} catch (StorageException e) {
String msg = "Error loading change";
logger.atWarning().withCause(e).log(msg + " %s", cd.getId());
ChangeInfo info = new ChangeInfo();
info._number = cd.getId().get();
ProblemInfo p = new ProblemInfo();
p.message = msg;
info.problems = Lists.newArrayList(p);
return info;
}
ConsistencyChecker.Result result = checkerProvider.get().check(notes, fix);
ChangeInfo info = new ChangeInfo();
Change c = result.change();
if (c != null) {
info.project = c.getProject().get();
info.branch = c.getDest().shortName();
info.topic = c.getTopic();
info.changeId = c.getKey().get();
info.subject = c.getSubject();
info.status = c.getStatus().asChangeStatus();
info.owner = new AccountInfo(c.getOwner().get());
info.setCreated(c.getCreatedOn());
info.setUpdated(c.getLastUpdatedOn());
info._number = c.getId().get();
info.problems = result.problems();
info.isPrivate = c.isPrivate() ? true : null;
info.workInProgress = c.isWorkInProgress() ? true : null;
info.hasReviewStarted = c.hasReviewStarted();
finish(info);
} else {
info._number = result.id().get();
info.problems = result.problems();
}
return info;
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onCommentAdded.
@Override
public void onCommentAdded(CommentAddedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
PatchSet ps = getPatchSet(notes, ev.getRevision());
CommentAddedEvent event = new CommentAddedEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.author = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, ps);
event.comment = ev.getComment();
event.approvals = approvalsAttributeSupplier(change, ev.getApprovals(), ev.getOldApprovals());
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
Aggregations