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
101
102
103
104
105
106
107
108
109
110
111
112
|
/*******************************************************************************
* Copyright (c) 2013, 2014 Ericsson 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:
* Miles Parker, Tasktop Technologies - initial API and implementation
* Steffen Pingel, Tasktop Technologies - original GerritUtil implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.gerrit.core.remote;
import java.util.Date;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.gerrit.core.client.GerritChange;
import org.eclipse.mylyn.reviews.core.model.IRepository;
import org.eclipse.mylyn.reviews.core.model.IReview;
import org.eclipse.mylyn.reviews.core.model.IReviewItemSet;
import org.eclipse.mylyn.reviews.core.model.IReviewsFactory;
import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfConsumer;
import org.eclipse.mylyn.reviews.core.spi.remote.review.ReviewItemSetRemoteFactory;
import org.eclipse.osgi.util.NLS;
import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.reviewdb.PatchSet;
/**
* Converts patch set details to review sets. Does not retrive actual patch set content. Does not require a remote
* invocation, as the neccesary data is collected as part of {@link GerritReviewRemoteFactory} API call.
*
* @author Miles Parker
* @author Steffen Pingel
*/
public class PatchSetDetailRemoteFactory extends ReviewItemSetRemoteFactory<PatchSetDetail, PatchSetDetail> {
public PatchSetDetailRemoteFactory(GerritRemoteFactoryProvider gerritRemoteFactoryProvider) {
super(gerritRemoteFactoryProvider);
}
@Override
public PatchSetDetail pull(IReview parent, PatchSetDetail remoteKey, IProgressMonitor monitor) throws CoreException {
return remoteKey;
}
@Override
public boolean isAsynchronous() {
return false;
}
@Override
public boolean isPullNeeded(IReview parent, IReviewItemSet object, PatchSetDetail remote) {
return object == null || remote == null;
}
@Override
public IReviewItemSet createModel(IReview review, PatchSetDetail patchSetDetail) {
PatchSet patchSet = patchSetDetail.getPatchSet();
IReviewItemSet itemSet = IReviewsFactory.INSTANCE.createReviewItemSet();
itemSet.setName(NLS.bind(Messages.PatchSetContentRemoteFactory_Patch_Set, patchSet.getPatchSetId()));
itemSet.setCreationDate(patchSet.getCreatedOn());
itemSet.setId(Integer.toString(patchSet.getPatchSetId()));
itemSet.setReference(patchSet.getRefName());
itemSet.setRevision(patchSet.getRevision().get());
review.getSets().add(itemSet);
return itemSet;
}
@Override
public PatchSetDetail getRemoteKey(PatchSetDetail remoteObject) {
return remoteObject;
}
@Override
public String getLocalKeyForRemoteObject(PatchSetDetail remoteObject) {
return Integer.toString(remoteObject.getPatchSet().getPatchSetId());
}
@Override
public String getLocalKeyForRemoteKey(PatchSetDetail remoteKey) {
return getLocalKeyForRemoteObject(remoteKey);
}
@Override
public PatchSetDetail getRemoteObjectForLocalKey(IReview parentObject, String localKey) {
GerritReviewRemoteFactory reviewFactory = ((GerritRemoteFactoryProvider) getFactoryProvider()).getReviewFactory();
RemoteEmfConsumer<IRepository, IReview, String, GerritChange, String, Date> reviewConsumer = reviewFactory.getConsumerForModel(
parentObject.getRepository(), parentObject);
try {
if (reviewConsumer != null) {
GerritChange change = reviewConsumer.getRemoteObject();
if (change != null) {
for (PatchSetDetail patchSetDetail : change.getPatchSetDetails()) {
if (patchSetDetail.getPatchSet().getPatchSetId() == Integer.parseInt(localKey)) {
return patchSetDetail;
}
}
}
}
} catch (NumberFormatException e) {
//ignore;
} finally {
if (reviewConsumer != null) {
reviewConsumer.release();
}
}
return null;
}
}
|