private Map<Integer, ContributorAgreement> getAgreementToAdd(ReviewDb db, ProjectConfig config) throws SQLException { Statement stmt = ((JdbcSchema) db).getConnection().createStatement(); try { ResultSet rs = stmt.executeQuery( "SELECT short_name, id, require_contact_information," + " short_description, agreement_url, auto_verify " + "FROM contributor_agreements WHERE active = 'Y'"); try { Map<Integer, ContributorAgreement> agreements = Maps.newHashMap(); while (rs.next()) { String name = rs.getString(1); if (config.getContributorAgreement(name) != null) { continue; // already exists } ContributorAgreement a = config.getContributorAgreement(name, true); agreements.put(rs.getInt(2), a); a.setRequireContactInformation("Y".equals(rs.getString(3))); a.setDescription(rs.getString(4)); a.setAgreementUrl(rs.getString(5)); if ("Y".equals(rs.getString(6))) { a.setAutoVerify(new GroupReference(null, null)); } } return agreements; } finally { rs.close(); } } finally { stmt.close(); } }
private GroupReference getOrCreateGroupForIndividuals( ReviewDb db, ProjectConfig config, List<AccountGroup.UUID> adminGroupUUIDs, ContributorAgreement agreement) throws OrmException { if (!agreement.getAccepted().isEmpty()) { return agreement.getAccepted().get(0).getGroup(); } String name = "CLA Accepted - " + agreement.getName(); AccountGroupName agn = db.accountGroupNames().get(new AccountGroup.NameKey(name)); AccountGroup ag; if (agn != null) { ag = db.accountGroups().get(agn.getId()); if (ag == null) { throw new IllegalStateException( "account group name exists but account group does not: " + name); } if (!adminGroupUUIDs.contains(ag.getOwnerGroupUUID())) { throw new IllegalStateException( "individual group exists with non admin owner group: " + name); } } else { ag = createGroup( db, name, adminGroupUUIDs.get(0), String.format("Users who have accepted the %s CLA", agreement.getName())); } GroupReference group = config.resolve(ag); agreement.setAccepted(Lists.newArrayList(new PermissionRule(group))); if (agreement.getAutoVerify() != null) { agreement.setAutoVerify(group); } // Don't allow accounts in the same individual CLA group to see each // other in same group visibility mode. List<PermissionRule> sameGroupVisibility = config.getAccountsSection().getSameGroupVisibility(); PermissionRule rule = new PermissionRule(group); rule.setDeny(); if (!sameGroupVisibility.contains(rule)) { sameGroupVisibility.add(rule); } return group; }