611e4c1520
In order to better support non-relational DBs that do not support sorting in a descending order, I have removed the DESC keyword from several of the ORM queries in which is was present. Change-Id: Iac9cbc43a62e7e652f721cacf223e8161eb4a280
89 lines
2.9 KiB
Java
89 lines
2.9 KiB
Java
// Copyright (C) 2009 The Android Open Source Project
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package com.google.gerrit.httpd.rpc.account;
|
|
|
|
import com.google.gerrit.common.data.AgreementInfo;
|
|
import com.google.gerrit.httpd.rpc.Handler;
|
|
import com.google.gerrit.reviewdb.AccountAgreement;
|
|
import com.google.gerrit.reviewdb.AccountGroup;
|
|
import com.google.gerrit.reviewdb.AccountGroupAgreement;
|
|
import com.google.gerrit.reviewdb.ContributorAgreement;
|
|
import com.google.gerrit.reviewdb.ReviewDb;
|
|
import com.google.gerrit.server.IdentifiedUser;
|
|
import com.google.inject.Inject;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
class AgreementInfoFactory extends Handler<AgreementInfo> {
|
|
interface Factory {
|
|
AgreementInfoFactory create();
|
|
}
|
|
|
|
private final ReviewDb db;
|
|
private final IdentifiedUser user;
|
|
|
|
private AgreementInfo info;
|
|
|
|
@Inject
|
|
AgreementInfoFactory(final ReviewDb db, final IdentifiedUser user) {
|
|
this.db = db;
|
|
this.user = user;
|
|
}
|
|
|
|
@Override
|
|
public AgreementInfo call() throws Exception {
|
|
final List<AccountAgreement> userAccepted =
|
|
db.accountAgreements().byAccount(user.getAccountId()).toList();
|
|
|
|
Collections.reverse(userAccepted);
|
|
|
|
final List<AccountGroupAgreement> groupAccepted =
|
|
new ArrayList<AccountGroupAgreement>();
|
|
for (final AccountGroup.Id groupId : user.getEffectiveGroups()) {
|
|
final List<AccountGroupAgreement> temp =
|
|
db.accountGroupAgreements().byGroup(groupId).toList();
|
|
|
|
Collections.reverse(temp);
|
|
|
|
groupAccepted.addAll(temp);
|
|
}
|
|
|
|
final Map<ContributorAgreement.Id, ContributorAgreement> agreements =
|
|
new HashMap<ContributorAgreement.Id, ContributorAgreement>();
|
|
for (final AccountAgreement a : userAccepted) {
|
|
final ContributorAgreement.Id id = a.getAgreementId();
|
|
if (!agreements.containsKey(id)) {
|
|
agreements.put(id, db.contributorAgreements().get(id));
|
|
}
|
|
}
|
|
for (final AccountGroupAgreement a : groupAccepted) {
|
|
final ContributorAgreement.Id id = a.getAgreementId();
|
|
if (!agreements.containsKey(id)) {
|
|
agreements.put(id, db.contributorAgreements().get(id));
|
|
}
|
|
}
|
|
|
|
info = new AgreementInfo();
|
|
info.setUserAccepted(userAccepted);
|
|
info.setGroupAccepted(groupAccepted);
|
|
info.setAgreements(agreements);
|
|
return info;
|
|
}
|
|
}
|