@Override public List<Record> apply(RevisionResource rsrc, Input input) throws AuthException, OrmException { if (input == null) { input = new Input(); } if (input.rule != null && !rules.isProjectRulesEnabled()) { throw new AuthException("project rules are disabled"); } input.filters = MoreObjects.firstNonNull(input.filters, filters); SubmitRuleEvaluator evaluator = new SubmitRuleEvaluator(changeDataFactory.create(db.get(), rsrc.getControl())); List<SubmitRecord> records = evaluator .setPatchSet(rsrc.getPatchSet()) .setLogErrors(false) .setSkipSubmitFilters(input.filters == Filters.SKIP) .setRule(input.rule) .evaluate(); List<Record> out = Lists.newArrayListWithCapacity(records.size()); AccountLoader accounts = accountInfoFactory.create(true); for (SubmitRecord r : records) { out.add(new Record(r, accounts)); } if (!out.isEmpty()) { out.get(0).prologReductionCount = evaluator.getReductionsConsumed(); } accounts.fill(); return out; }
Record(SubmitRecord r, AccountLoader accounts) { this.status = r.status; this.errorMessage = r.errorMessage; if (r.labels != null) { for (SubmitRecord.Label n : r.labels) { AccountInfo who = n.appliedBy != null ? accounts.get(n.appliedBy) : new AccountInfo(null); label(n, who); } } }
@Override public ServiceUserInfo apply(ServiceUserResource rsrc) throws ResourceNotFoundException, OrmException { ProjectLevelConfig storage = projectCache.getAllProjects().getConfig(pluginName + ".db"); String username = rsrc.getUser().getUserName(); Config db = storage.get(); if (!db.getSubsections(USER).contains(username)) { throw new ResourceNotFoundException(username); } ServiceUserInfo info = new ServiceUserInfo(getAccount.get().apply(rsrc)); AccountLoader al = accountLoader.create(true); info.createdBy = al.get(new Account.Id(db.getInt(USER, username, KEY_CREATOR_ID, -1))); al.fill(); info.createdAt = db.getString(USER, username, KEY_CREATED_AT); info.inactive = !rsrc.getUser().getAccount().isActive() ? true : null; Response<GroupInfo> response = getOwner.apply(rsrc); if (response.statusCode() == SC_OK) { info.owner = response.value(); } return info; }