Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2cc2f6fedb8878adaa06ccc5774cc36b0c01184e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
 * Copyright (c) 2013 Tasktop Technologies and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.gerrit.core.client.rest;

import java.util.Map;
import java.util.Map.Entry;

import com.google.gerrit.common.data.ApprovalDetail;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.ApprovalCategory;
import com.google.gerrit.reviewdb.PatchSet;
import com.google.gerrit.reviewdb.PatchSetApproval;

/**
 * Data model object for <a
 * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#reviewer-info">ReviewerInfo</a>.
 */
public class ReviewerInfo extends AccountInfo {

	private final String kind = "gerritcodereview#reviewer"; //$NON-NLS-1$

	private Map<String/*label name*/, String/*approval value*/> approvals;

	public String getKind() {
		return kind;
	}

	public Map<String, String> getApprovals() {
		return approvals;
	}

	public ApprovalDetail toApprovalDetail(PatchSet currentPatchSet) {
		Account.Id accountId = new Account.Id(getId());
		ApprovalDetail approvalDetail = new ApprovalDetail(accountId);
		Map<String, String> map = getApprovals();
		if (map != null) {
			for (Entry<String, String> entry : map.entrySet()) {
				ApprovalCategory.Id categoryId = ApprovalUtil.findCategoryIdByName(entry.getKey().replace('-', ' '));
				if (categoryId != null) {
					PatchSetApproval patchSetApproval = new PatchSetApproval(new PatchSetApproval.Key(
							currentPatchSet.getId(), accountId, categoryId), ApprovalUtil.parseShort(entry.getValue()));
					approvalDetail.add(patchSetApproval);
				}
			}
		}
		return approvalDetail;
	}

	public com.google.gerrit.common.data.AccountInfo toAccountInfo() {
		Account.Id accountId = new Account.Id(getId());
		Account account = new Account(accountId);
		account.setFullName(getName());
		account.setPreferredEmail(getEmail());
		com.google.gerrit.common.data.AccountInfo accountInfo = new com.google.gerrit.common.data.AccountInfo(account);
		return accountInfo;
	}
}

Back to the top