Skip to main content
summaryrefslogtreecommitdiffstats
blob: aeff052a276dee33afff7c4ccecd6c73f47add64 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*******************************************************************************
 * 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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gerrit.common.data.ApprovalType;
import com.google.gerrit.reviewdb.ApprovalCategory;
import com.google.gerrit.reviewdb.ApprovalCategoryValue;

public abstract class ApprovalUtil {

	public static final ApprovalType VRIF;

	public static final ApprovalType CRVW;

	public static final ApprovalType IPCL;

	private static final Map<String, ApprovalType> BY_NAME;

	private static final Map<String, ApprovalType> BY_ID;

	static {
		ApprovalCategory vrifCategory = new ApprovalCategory(new ApprovalCategory.Id("VRIF"), "Verified"); //$NON-NLS-1$ //$NON-NLS-2$
		vrifCategory.setAbbreviatedName("V"); //$NON-NLS-1$
		vrifCategory.setPosition((short) 0);
		List<ApprovalCategoryValue> vrifValues = new ArrayList<ApprovalCategoryValue>(3);
		vrifValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(vrifCategory.getId(), (short) -1),
				"Fails")); //$NON-NLS-1$
		vrifValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(vrifCategory.getId(), (short) 0),
				"No score")); //$NON-NLS-1$
		vrifValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(vrifCategory.getId(), (short) 1),
				"Verified")); //$NON-NLS-1$
		VRIF = new ApprovalType(vrifCategory, vrifValues);

		ApprovalCategory crvwCategory = new ApprovalCategory(new ApprovalCategory.Id("CRVW"), "Code Review"); //$NON-NLS-1$ //$NON-NLS-2$
		crvwCategory.setAbbreviatedName("R"); //$NON-NLS-1$
		crvwCategory.setPosition((short) 1);
		List<ApprovalCategoryValue> crvwValues = new ArrayList<ApprovalCategoryValue>(5);
		crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) -2),
				"Do not submit")); //$NON-NLS-1$
		crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) -1),
				"I would prefer that you didn\u0027t submit this")); //$NON-NLS-1$
		crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) 0),
				"No score")); //$NON-NLS-1$
		crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) 1),
				"Looks good to me, but someone else must approve")); //$NON-NLS-1$
		crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) 2),
				"Looks good to me, approved")); //$NON-NLS-1$
		CRVW = new ApprovalType(crvwCategory, crvwValues);

		ApprovalCategory ipclCategory = new ApprovalCategory(new ApprovalCategory.Id("IPCL"), "IP Clean"); //$NON-NLS-1$ //$NON-NLS-2$
		ipclCategory.setAbbreviatedName("I"); //$NON-NLS-1$
		ipclCategory.setPosition((short) 2);
		List<ApprovalCategoryValue> ipclValues = new ArrayList<ApprovalCategoryValue>(3);
		ipclValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(ipclCategory.getId(), (short) -1),
				"Unclean IP, do not check in")); //$NON-NLS-1$
		ipclValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(ipclCategory.getId(), (short) 0),
				"No score")); //$NON-NLS-1$
		ipclValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(ipclCategory.getId(), (short) 1),
				"IP review completed")); //$NON-NLS-1$
		IPCL = new ApprovalType(ipclCategory, ipclValues);

		BY_NAME = new HashMap<String, ApprovalType>(3);
		BY_NAME.put(VRIF.getCategory().getName(), VRIF);
		BY_NAME.put(CRVW.getCategory().getName(), CRVW);
		BY_NAME.put(IPCL.getCategory().getName(), IPCL);

		BY_ID = new HashMap<String, ApprovalType>(3);
		BY_ID.put(VRIF.getCategory().getId().get(), VRIF);
		BY_ID.put(CRVW.getCategory().getId().get(), CRVW);
		BY_ID.put(IPCL.getCategory().getId().get(), IPCL);
	}

	static ApprovalCategory.Id findCategoryIdByName(String name) {
		if (BY_NAME.containsKey(name)) {
			return BY_NAME.get(name).getCategory().getId();
		}
		return null;
	}

	public static String findCategoryNameById(String id) {
		if (BY_ID.containsKey(id)) {
			return BY_ID.get(id).getCategory().getName();
		}
		return null;
	}
}

Back to the top