Access LabelTypes through ProjectState rather than globally

We want to allow projects to define their own labels, so we can't
assume the label list is global. In typical cases, we can access it
through a ProjectControl, ChangeControl, or related factory. This does
result in a few more places where we propagate
NoSuchProject/ChangeExceptions where there were none before. This is
intended: operations that query/modify labels on, say, a bare
Change.Id now do need to verify that the project/change exists.

For now, leave code in LabelTypesProvider, but try not to inject
LabelTypes where at all possible.

Change-Id: I4936ccafdb41848aaac3e335adf4648369d6abbc
This commit is contained in:
Dave Borowitz
2013-02-14 17:11:25 -08:00
parent 742a046fd0
commit 6cae753a4c
32 changed files with 212 additions and 156 deletions

View File

@@ -43,17 +43,14 @@ import java.util.TreeMap;
public class ReviewerJson {
private final Provider<ReviewDb> db;
private final LabelTypes labelTypes;
private final FunctionState.Factory functionState;
private final AccountInfo.Loader.Factory accountLoaderFactory;
@Inject
ReviewerJson(Provider<ReviewDb> db,
LabelTypes labelTypes,
FunctionState.Factory functionState,
AccountInfo.Loader.Factory accountLoaderFactory) {
this.db = db;
this.labelTypes = labelTypes;
this.functionState = functionState;
this.accountLoaderFactory = accountLoaderFactory;
}
@@ -84,6 +81,7 @@ public class ReviewerJson {
.byPatchSetUser(psId, out._id));
}
LabelTypes labelTypes = ctl.getLabelTypes();
FunctionState fs = functionState.create(ctl, psId, approvals);
for (LabelType at : labelTypes.getLabelTypes()) {
CategoryFunction.forType(at).run(at, fs);