summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-30 07:11:59 (EDT)
committer Tomasz Zarna2013-07-30 07:16:02 (EDT)
commitbc7f37b72de00c7063556ce7285919c77ec59850 (patch)
treebffafed7187a43149495f8626c1ac8893ec007d2
parent530437d1830fded3816c4b45a1e6684d5d78a90e (diff)
downloadorg.eclipse.mylyn.reviews-bc7f37b72de00c7063556ce7285919c77ec59850.zip
org.eclipse.mylyn.reviews-bc7f37b72de00c7063556ce7285919c77ec59850.tar.gz
org.eclipse.mylyn.reviews-bc7f37b72de00c7063556ce7285919c77ec59850.tar.bz2
add a method for finding ApprovalCategory by name with dashrefs/changes/57/14957/1
Change-Id: I27ced746cbac4fa89153a4649809ef3a345306e8 Signed-off-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/PermissionLabel.java4
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java27
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java13
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java3
4 files changed, 36 insertions, 11 deletions
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/PermissionLabel.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/PermissionLabel.java
index 80d6c85..94fc87f 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/PermissionLabel.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/PermissionLabel.java
@@ -11,6 +11,8 @@
package org.eclipse.mylyn.internal.gerrit.core.client.compat;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil;
+
import com.google.gerrit.reviewdb.ApprovalCategory;
import com.google.gerrit.reviewdb.ApprovalCategoryValue;
@@ -40,7 +42,7 @@ public class PermissionLabel {
}
public String toLabelName(String identifier) {
- return "label-" + identifier.replace(" ", "-"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ return "label-" + ApprovalUtil.toNameWithDash(identifier); //$NON-NLS-1$
}
public boolean matches(ApprovalCategoryValue value) {
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
index 9db7ebf..f82d576 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
@@ -84,13 +84,32 @@ public final class ApprovalUtil {
BY_ID.put(IPCL.getCategory().getId().get(), IPCL);
}
- static ApprovalCategory.Id findCategoryIdByName(String name) {
+ static ApprovalCategory findCategoryByName(String name) {
+ name = name.replace('-', ' ');
if (BY_NAME.containsKey(name)) {
- return BY_NAME.get(name).getCategory().getId();
+ return BY_NAME.get(name).getCategory();
+ }
+ return null;
+ }
+
+ static ApprovalCategory findCategoryByNameWithDash(String name) {
+ name = name.replace('-', ' ');
+ return findCategoryByName(name);
+ }
+
+ static ApprovalCategory.Id findCategoryIdByName(String name) {
+ ApprovalCategory cat = findCategoryByName(name);
+ if (cat != null) {
+ return cat.getId();
}
return null;
}
+ static ApprovalCategory.Id findCategoryIdByNameWithDash(String name) {
+ name = name.replace('-', ' ');
+ return findCategoryIdByName(name);
+ }
+
public static String findCategoryNameById(String id) {
if (BY_ID.containsKey(id)) {
return BY_ID.get(id).getCategory().getName();
@@ -98,6 +117,10 @@ public final class ApprovalUtil {
return null;
}
+ public static String toNameWithDash(String name) {
+ return name.replace(' ', '-');
+ }
+
public static short parseShort(String s) {
s = s.trim();
// only Java7 handles a plus sign as indication of a positive value
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java
index 47935f6..e856435 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java
@@ -72,7 +72,6 @@ public class ChangeInfo {
private String _sortkey;
// e.g. 3965
- @SuppressWarnings("unused")
private int _number;
public String getKind() {
@@ -155,8 +154,10 @@ public class ChangeInfo {
for (Entry<String, LabelInfo> entry : labels.entrySet()) {
List<ApprovalInfo> all = entry.getValue().getAll();
if (all != null) {
- String name = entry.getKey().replace('-', ' ');
- ApprovalCategory.Id approvalCategoryId = ApprovalUtil.findCategoryIdByName(name);
+ ApprovalCategory.Id approvalCategoryId = ApprovalUtil.findCategoryIdByNameWithDash(entry.getKey());
+ if (approvalCategoryId == null) {
+ continue;
+ }
for (ApprovalInfo approvalInfo : all) {
Account.Id accountId = new Account.Id(approvalInfo.getId());
ApprovalDetail approvalDetail = new ApprovalDetail(accountId);
@@ -175,12 +176,10 @@ public class ChangeInfo {
}
Set<ApprovalType> result = new HashSet<ApprovalType>();
for (Entry<String, LabelInfo> entry : labels.entrySet()) {
- String name = entry.getKey().replace('-', ' ');
- ApprovalCategory.Id approvalCategoryId = ApprovalUtil.findCategoryIdByName(name);
- ApprovalCategory approvalCategory = new ApprovalCategory(approvalCategoryId, name);
+ ApprovalCategory approvalCategory = ApprovalUtil.findCategoryByNameWithDash(entry.getKey());
List<ApprovalCategoryValue> valueList = new ArrayList<ApprovalCategoryValue>();
for (Entry<String, String> valueEntry : entry.getValue().getValues().entrySet()) {
- valueList.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(approvalCategoryId,
+ valueList.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(approvalCategory.getId(),
ApprovalUtil.parseShort(valueEntry.getKey())), valueEntry.getValue()));
}
ApprovalType approvalType = new ApprovalType(approvalCategory, valueList);
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java
index 29557e5..7952bb5 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java
@@ -31,6 +31,7 @@ import org.eclipse.mylyn.internal.gerrit.core.client.GerritException;
import org.eclipse.mylyn.internal.gerrit.core.client.compat.ChangeDetailX;
import org.eclipse.mylyn.internal.gerrit.core.client.compat.SubmitRecord;
import org.eclipse.mylyn.internal.gerrit.core.client.compat.SubmitRecord.Label;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil;
import org.eclipse.mylyn.reviews.core.model.IApprovalType;
import org.eclipse.mylyn.reviews.core.model.IChange;
import org.eclipse.mylyn.reviews.core.model.IComment;
@@ -320,7 +321,7 @@ public class GerritReviewRemoteFactory extends ReviewRemoteFactory<GerritChange,
}
String approvalName = remoteType.getCategory().getName();
//Special case so we can match different label name for status records. (?!)
- approvalName = approvalName.replace(" ", "-"); //$NON-NLS-1$ //$NON-NLS-2$
+ approvalName = ApprovalUtil.toNameWithDash(approvalName);
typeForName.put(approvalName, localApprovalType);
}
}