Format all files with google-java-format 1.6 Change-Id: I43cf9e3450c0b4cc02682fb97887568ca487c536
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/InitRTC.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/InitRTC.java index c81e75c..cbc0fa9 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/InitRTC.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/InitRTC.java
@@ -16,20 +16,17 @@ import com.google.gerrit.extensions.annotations.PluginName; import com.google.gerrit.pgm.init.api.AllProjectsConfig; import com.google.gerrit.pgm.init.api.AllProjectsNameOnInitProvider; +import com.google.gerrit.pgm.init.api.ConsoleUI; import com.google.gerrit.pgm.init.api.InitFlags; import com.google.gerrit.pgm.init.api.Section; -import com.google.gerrit.pgm.init.api.ConsoleUI; import com.google.inject.Inject; import com.google.inject.Singleton; - import com.googlesource.gerrit.plugins.its.base.its.InitIts; import com.googlesource.gerrit.plugins.its.base.validation.ItsAssociationPolicy; import com.googlesource.gerrit.plugins.its.rtc.network.RTCClient; - -import org.eclipse.jgit.errors.ConfigInvalidException; - import java.io.IOException; import java.util.Arrays; +import org.eclipse.jgit.errors.ConfigInvalidException; /** Initialize the GitRepositoryManager configuration section. */ @Singleton @@ -44,11 +41,14 @@ private String rtcPassword; @Inject - InitRTC(@PluginName String pluginName, ConsoleUI ui, - Section.Factory sections, AllProjectsConfig allProjectsConfig, - AllProjectsNameOnInitProvider allProjects, InitFlags flags) { - super(pluginName, "IBM Rational Team Concert", ui, - allProjectsConfig, allProjects); + InitRTC( + @PluginName String pluginName, + ConsoleUI ui, + Section.Factory sections, + AllProjectsConfig allProjectsConfig, + AllProjectsNameOnInitProvider allProjects, + InitFlags flags) { + super(pluginName, "IBM Rational Team Concert", ui, allProjectsConfig, allProjects); this.pluginName = pluginName; this.sections = sections; this.flags = flags; @@ -67,11 +67,14 @@ ui.message("A RTC configuration for the 'hooks-rtc' plugin was found.\n"); if (ui.yesno(true, "Copy it for the '%s' plugin?", pluginName)) { for (String n : flags.cfg.getNames("rtc")) { - flags.cfg.setStringList(pluginName, null, n, - Arrays.asList(flags.cfg.getStringList("rtc", null, n))); + flags.cfg.setStringList( + pluginName, null, n, Arrays.asList(flags.cfg.getStringList("rtc", null, n))); } for (String n : flags.cfg.getNames(COMMENT_LINK_SECTION, "rtc")) { - flags.cfg.setStringList(COMMENT_LINK_SECTION, pluginName, n, + flags.cfg.setStringList( + COMMENT_LINK_SECTION, + pluginName, + n, Arrays.asList(flags.cfg.getStringList(COMMENT_LINK_SECTION, "rtc", n))); } @@ -89,13 +92,12 @@ private void init() { this.rtc = sections.get(pluginName, null); - this.rtcComment = - sections.get(COMMENT_LINK_SECTION, pluginName); + this.rtcComment = sections.get(COMMENT_LINK_SECTION, pluginName); boolean sslVerify = true; do { rtcUrl = enterRTCConnectivity(); - if(rtcUrl != null) { + if (rtcUrl != null) { sslVerify = enterSSLVerify(rtc); } } while (rtcUrl != null @@ -108,11 +110,10 @@ ui.header("Rational Team Concert issue-tracking association"); rtcComment.string("RTC Issue-Id regex", "match", "RTC#([0-9]+)"); String workItemLink = "resource/itemName/com.ibm.team.workitem.WorkItem/$1"; - rtcComment.set("html", - String.format("<a href=\"%s/%s\">$1</a>", rtcUrl, workItemLink)); + rtcComment.set("html", String.format("<a href=\"%s/%s\">$1</a>", rtcUrl, workItemLink)); - rtcComment.select("RTC Issue-Id enforced in commit message", "association", - ItsAssociationPolicy.OPTIONAL); + rtcComment.select( + "RTC Issue-Id enforced in commit message", "association", ItsAssociationPolicy.OPTIONAL); } public String enterRTCConnectivity() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCItsFacade.java index e8526a1..b9ab279 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCItsFacade.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCItsFacade.java
@@ -13,23 +13,20 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc; -import java.io.IOException; -import java.net.URL; - -import org.eclipse.jgit.lib.Config; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gerrit.extensions.annotations.PluginName; import com.google.gerrit.server.config.GerritServerConfig; import com.google.inject.Inject; import com.google.inject.Injector; - import com.googlesource.gerrit.plugins.its.base.its.ItsFacade; import com.googlesource.gerrit.plugins.its.rtc.network.RTCClient; import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcComment; import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcRelatedLink; import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkItem; +import java.io.IOException; +import java.net.URL; +import org.eclipse.jgit.lib.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RTCItsFacade implements ItsFacade { @@ -48,15 +45,14 @@ private Injector injector; @Inject - public RTCItsFacade(@PluginName String pluginName, - @GerritServerConfig Config gerritConfig, Injector injector) { + public RTCItsFacade( + @PluginName String pluginName, @GerritServerConfig Config gerritConfig, Injector injector) { this.pluginName = pluginName; try { this.injector = injector; this.gerritConfig = gerritConfig; client().ping(); - log.info("Connected to RTC at " + getRtcUrl() + " as admin user " - + getRtcUser()); + log.info("Connected to RTC at " + getRtcUrl() + " as admin user " + getRtcUser()); } catch (Exception ex) { log.warn("RTC is currently not available", ex); } @@ -66,26 +62,27 @@ public void addComment(String itemId, String comment) throws IOException { long workItem = Long.parseLong(itemId); log.debug("Adding comment " + comment + " to workItem " + workItem); - RtcComment rtcComment = - client().workItemsApi().addComment(workItem, comment); + RtcComment rtcComment = client().workItemsApi().addComment(workItem, comment); log.debug("Comment created: " + rtcComment); } @Override - public void addRelatedLink(String itemId, URL relatedUrl, String description) - throws IOException { + public void addRelatedLink(String itemId, URL relatedUrl, String description) throws IOException { long workItem = Long.parseLong(itemId); - log.debug("Adding related link " + relatedUrl + " to workItem " + workItem - + " with description " + description); + log.debug( + "Adding related link " + + relatedUrl + + " to workItem " + + workItem + + " with description " + + description); RtcRelatedLink relatedLink = client().workItemsApi().addRelated(workItem, relatedUrl, description); - log.debug("Related link " + relatedLink + " to workItem#" + workItem - + " CREATED"); + log.debug("Related link " + relatedLink + " to workItem#" + workItem + " CREATED"); } @Override - public void performAction(String itemId, String actionName) - throws IOException { + public void performAction(String itemId, String actionName) throws IOException { long workItem = Long.parseLong(itemId); log.debug("Executing action " + actionName + " on workItem " + workItem); RtcWorkItem wip = client().workItemsApi().getWorkItem(workItem); @@ -113,13 +110,11 @@ } private String getRtcPassword() { - return gerritConfig.getString(pluginName, null, - GERRIT_CONFIG_RTC_PASSWORD); + return gerritConfig.getString(pluginName, null, GERRIT_CONFIG_RTC_PASSWORD); } private String getRtcUser() { - return gerritConfig.getString(pluginName, null, - GERRIT_CONFIG_RTC_USERNAME); + return gerritConfig.getString(pluginName, null, GERRIT_CONFIG_RTC_USERNAME); } private String getRtcUrl() { @@ -137,5 +132,4 @@ RtcWorkItem item = client().workItemsApi().getWorkItem(workItem); return item != null; } - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCModule.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCModule.java index 8d83bc7..0e031e4 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/RTCModule.java
@@ -13,21 +13,18 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc; -import java.util.Set; - -import org.eclipse.jgit.lib.Config; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gerrit.extensions.annotations.PluginName; import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.PluginConfigFactory; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Scopes; - import com.googlesource.gerrit.plugins.its.base.ItsHookModule; import com.googlesource.gerrit.plugins.its.base.its.ItsFacade; +import java.util.Set; +import org.eclipse.jgit.lib.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RTCModule extends AbstractModule { @@ -38,8 +35,10 @@ private final PluginConfigFactory pluginCfgFactory; @Inject - public RTCModule(@PluginName String pluginName, - @GerritServerConfig Config config, PluginConfigFactory pluginCfgFactory) { + public RTCModule( + @PluginName String pluginName, + @GerritServerConfig Config config, + PluginConfigFactory pluginCfgFactory) { this.pluginName = pluginName; this.gerritConfig = config; this.pluginCfgFactory = pluginCfgFactory;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/AbstractDeserializer.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/AbstractDeserializer.java index e5d340a..ab7ca1a 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/AbstractDeserializer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/AbstractDeserializer.java
@@ -13,14 +13,12 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.api; +import com.google.gson.JsonObject; import java.util.Calendar; - import javax.xml.bind.DatatypeConverter; -import com.google.gson.JsonObject; - public class AbstractDeserializer { - + protected final String extractRdfResourceUrl(JsonObject json, String memberName) { JsonObject rdf = json.getAsJsonObject(memberName); return rdf.get("rdf:resource").getAsString(); @@ -28,10 +26,9 @@ protected final Calendar extractDateTime(JsonObject root, final String memberName) { String txt = extractString(root, memberName); - return DatatypeConverter.parseDateTime(txt); + return DatatypeConverter.parseDateTime(txt); } - protected final String extractString(JsonObject root, final String memberName) { return root.get(memberName).getAsString(); } @@ -43,14 +40,11 @@ protected final String extractIdenFromRdfResource(JsonObject root, final String memberName) { final String rdf = extractRdfResourceUrl(root, memberName); if (rdf != null) { - return rdf.substring(rdf.lastIndexOf('/')+1); - } - else - return null; + return rdf.substring(rdf.lastIndexOf('/') + 1); + } else return null; } protected String extractRdf(JsonObject root) { return extractString(root, "rdf:resource"); } - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceInvalidException.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceInvalidException.java index 958fdaa..42d4ab5 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceInvalidException.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceInvalidException.java
@@ -20,6 +20,6 @@ private static final long serialVersionUID = -2905132705439138798L; public ResourceInvalidException(String name) { - super("Resource name "+name+" is not valid!"); + super("Resource name " + name + " is not valid!"); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceModifiedException.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceModifiedException.java index 1c43c94..d5c4a0e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceModifiedException.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceModifiedException.java
@@ -21,6 +21,6 @@ private static final long serialVersionUID = -2905132705439138798L; public ResourceModifiedException(URI uri) { - super("Resource modified at "+uri.toString()+ " - etag is not matching"); + super("Resource modified at " + uri.toString() + " - etag is not matching"); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceNotFoundException.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceNotFoundException.java index 7463cd8..bfd67e6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceNotFoundException.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/ResourceNotFoundException.java
@@ -21,6 +21,6 @@ private static final long serialVersionUID = -2905132705439138798L; public ResourceNotFoundException(URI uri) { - super("Resource not found at "+uri.toString()); + super("Resource not found at " + uri.toString()); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntity.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntity.java index 6bc1c14..523234d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntity.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntity.java
@@ -13,7 +13,6 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.api; - public class RtcEntity extends RtcObject { String id; @@ -22,7 +21,7 @@ protected RtcEntity(String rdf) { super(rdf); } - + public RtcEntity(String id, String title) { this(null, id, title); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntityDeserializer.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntityDeserializer.java index da73add..38dc311 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntityDeserializer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcEntityDeserializer.java
@@ -13,28 +13,26 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.api; -import java.lang.reflect.Type; - import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; +import java.lang.reflect.Type; -import com.googlesource.gerrit.plugins.its.rtc.api.AbstractDeserializer; - -public class RtcEntityDeserializer extends AbstractDeserializer implements JsonDeserializer<RtcEntity> { +public class RtcEntityDeserializer extends AbstractDeserializer + implements JsonDeserializer<RtcEntity> { @Override - public RtcEntity deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - + public RtcEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + JsonObject root = json.getAsJsonObject(); RtcEntity result = new RtcEntity(extractRdf(root)); result.id = extractString(root, "dc:identifier"); result.title = extractString(root, "dc:title"); - + return result; } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcObject.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcObject.java index 76a90b0..1e4e1ab 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcObject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/api/RtcObject.java
@@ -14,7 +14,6 @@ package com.googlesource.gerrit.plugins.its.rtc.api; import com.google.gson.Gson; - import com.googlesource.gerrit.plugins.its.rtc.network.Transport; public class RtcObject {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/AuthenticationException.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/AuthenticationException.java index e6e74c4..09c18dc 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/AuthenticationException.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/AuthenticationException.java
@@ -17,7 +17,7 @@ public class AuthenticationException extends IOException { private static final long serialVersionUID = -4713503914827418174L; - + public AuthenticationException(String reason) { super(reason); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/CachableResourcesFactory.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/CachableResourcesFactory.java index 3d0229a..58fcde8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/CachableResourcesFactory.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/CachableResourcesFactory.java
@@ -17,7 +17,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - public class CachableResourcesFactory { public final Map<Class<?>, InternalFactory<?>> factories; @@ -65,7 +64,7 @@ } private T streamResourceFrom(final String url, final Class<T> clazz) throws IOException { - return transport.get(url+".json", clazz); + return transport.get(url + ".json", clazz); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/HttpPatch.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/HttpPatch.java index 4f35b3c..7c65997 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/HttpPatch.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/HttpPatch.java
@@ -14,7 +14,6 @@ package com.googlesource.gerrit.plugins.its.rtc.network; import java.net.URI; - import org.apache.http.client.methods.HttpPost; public class HttpPatch extends HttpPost { @@ -31,8 +30,8 @@ super(uri); } - @Override - public String getMethod() { - return "PATCH"; + @Override + public String getMethod() { + return "PATCH"; } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/InvalidContentTypeException.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/InvalidContentTypeException.java index 1a5983b..ccb073f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/InvalidContentTypeException.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/InvalidContentTypeException.java
@@ -17,7 +17,7 @@ public class InvalidContentTypeException extends IOException { private static final long serialVersionUID = -5010337914983644879L; - + public InvalidContentTypeException(String reason) { super(reason); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCClient.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCClient.java index 3dc52ce..b5ba3dc 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCClient.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCClient.java
@@ -13,14 +13,31 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.network; +import com.google.gerrit.extensions.annotations.PluginName; +import com.google.gerrit.server.config.GerritServerConfig; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.inject.Inject; +import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; +import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntityDeserializer; +import com.googlesource.gerrit.plugins.its.rtc.session.SessionApi; +import com.googlesource.gerrit.plugins.its.rtc.session.SessionApiImpl; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcComment; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcCommentDeserializer; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcRelatedLink; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcRelatedLinkDeserializer; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkItem; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkItemDeserializer; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkflowAction; +import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkflowActionDeserializer; +import com.googlesource.gerrit.plugins.its.rtc.workitems.WorkItemsApi; +import com.googlesource.gerrit.plugins.its.rtc.workitems.WorkItemsApiImpl; import java.io.IOException; import java.security.SecureRandom; import java.security.cert.X509Certificate; - import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpResponse; @@ -38,27 +55,6 @@ import org.apache.http.protocol.HttpContext; import org.eclipse.jgit.lib.Config; -import com.google.gerrit.extensions.annotations.PluginName; -import com.google.gerrit.server.config.GerritServerConfig; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.inject.Inject; - -import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; -import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntityDeserializer; -import com.googlesource.gerrit.plugins.its.rtc.session.SessionApi; -import com.googlesource.gerrit.plugins.its.rtc.session.SessionApiImpl; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcComment; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcCommentDeserializer; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcRelatedLink; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcRelatedLinkDeserializer; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkItem; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkItemDeserializer; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkflowAction; -import com.googlesource.gerrit.plugins.its.rtc.workitems.RtcWorkflowActionDeserializer; -import com.googlesource.gerrit.plugins.its.rtc.workitems.WorkItemsApi; -import com.googlesource.gerrit.plugins.its.rtc.workitems.WorkItemsApiImpl; - public class RTCClient { private static Log LOG = LogFactory.getLog(RTCClient.class); @@ -81,16 +77,16 @@ private String rtcPassword; @Inject - public RTCClient(@PluginName String pluginName, - @GerritServerConfig Config config, RTCHttpParams httpParams) + public RTCClient( + @PluginName String pluginName, @GerritServerConfig Config config, RTCHttpParams httpParams) throws IOException { - this(config.getString(pluginName, null, "url"), config - .getBoolean(pluginName, null, "sslVerify", true), + this( + config.getString(pluginName, null, "url"), + config.getBoolean(pluginName, null, "sslVerify", true), httpParams); } - public RTCClient(String url, boolean sslVerify, HttpParams httpParams) - throws IOException { + public RTCClient(String url, boolean sslVerify, HttpParams httpParams) throws IOException { super(); this.baseUrl = (url.endsWith("/") ? url.substring(url.length() - 1) : url); @@ -98,24 +94,20 @@ httpParams = new BasicHttpParams(); } SchemeRegistry schemeRegistry = new SchemeRegistry(); - schemeRegistry.register(new Scheme("http", PlainSocketFactory - .getSocketFactory(), 80)); + schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); this.httpclient = - new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, - schemeRegistry), httpParams); + new DefaultHttpClient( + new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams); this.transport = new Transport(this, baseUrl, httpclient, httpParams); this.factory = new CachableResourcesFactory(transport); GsonBuilder builder = new GsonBuilder(); - builder.registerTypeAdapter(RtcWorkItem.class, new RtcWorkItemDeserializer( - factory)); + builder.registerTypeAdapter(RtcWorkItem.class, new RtcWorkItemDeserializer(factory)); builder.registerTypeAdapter(RtcComment.class, new RtcCommentDeserializer()); builder.registerTypeAdapter(RtcEntity.class, new RtcEntityDeserializer()); - builder.registerTypeAdapter(RtcRelatedLink.class, - new RtcRelatedLinkDeserializer()); - builder.registerTypeAdapter(RtcWorkflowAction.class, - new RtcWorkflowActionDeserializer()); + builder.registerTypeAdapter(RtcRelatedLink.class, new RtcRelatedLinkDeserializer()); + builder.registerTypeAdapter(RtcWorkflowAction.class, new RtcWorkflowActionDeserializer()); gson = builder.create(); transport.setGson(gson); @@ -157,22 +149,20 @@ private void setSSLTrustStrategy(boolean sslVerify) throws IOException { try { TrustManager[] trustAllCerts = - new TrustManager[] {new X509TrustManager() { - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } + new TrustManager[] { + new X509TrustManager() { + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } - @Override - public void checkClientTrusted(X509Certificate[] certs, - String authType) { - } + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) {} - @Override - public void checkServerTrusted(X509Certificate[] certs, - String authType) { + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) {} } - }}; + }; SSLContext sc; if (sslVerify) { @@ -184,8 +174,7 @@ SSLSocketFactory sf = new SSLSocketFactory(sc); sf.setHostnameVerifier(new AllowAllHostnameVerifier()); - SchemeRegistry schemeRegistry = - httpclient.getConnectionManager().getSchemeRegistry(); + SchemeRegistry schemeRegistry = httpclient.getConnectionManager().getSchemeRegistry(); schemeRegistry.register(new Scheme("https", sf, 443)); } catch (Exception any) { throw new IOException(any); @@ -193,20 +182,20 @@ } private void setRedirectStategy() { - httpclient.setRedirectHandler(new DefaultRedirectHandler() { - @Override - public boolean isRedirectRequested(HttpResponse response, - HttpContext context) { - boolean isRedirect = super.isRedirectRequested(response, context); - if (!isRedirect) { - int responseCode = response.getStatusLine().getStatusCode(); - if (responseCode == 301 || responseCode == 302) { - return true; + httpclient.setRedirectHandler( + new DefaultRedirectHandler() { + @Override + public boolean isRedirectRequested(HttpResponse response, HttpContext context) { + boolean isRedirect = super.isRedirectRequested(response, context); + if (!isRedirect) { + int responseCode = response.getStatusLine().getStatusCode(); + if (responseCode == 301 || responseCode == 302) { + return true; + } + } + return isRedirect; } - } - return isRedirect; - } - }); + }); } public Transport getTransportForTest() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCHttpParams.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCHttpParams.java index 1be4750..aa6d219 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCHttpParams.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/RTCHttpParams.java
@@ -13,8 +13,11 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.network; +import com.google.common.base.MoreObjects; +import com.google.gerrit.extensions.annotations.PluginName; +import com.google.gerrit.server.config.GerritServerConfig; +import com.google.inject.Inject; import java.util.HashMap; - import org.apache.http.client.params.ClientPNames; import org.apache.http.conn.params.ConnManagerPNames; import org.apache.http.params.CoreConnectionPNames; @@ -22,61 +25,59 @@ import org.apache.http.params.HttpParams; import org.eclipse.jgit.lib.Config; -import com.google.common.base.MoreObjects; -import com.google.gerrit.extensions.annotations.PluginName; -import com.google.gerrit.server.config.GerritServerConfig; -import com.google.inject.Inject; - @SuppressWarnings("deprecation") public class RTCHttpParams implements HttpParams { private static interface ParameterParser { public Object parse(String value); } - private static final ParameterParser TYPE_STRING = new ParameterParser() { - @Override - public Object parse(String value) { - return value; - } - }; + private static final ParameterParser TYPE_STRING = + new ParameterParser() { + @Override + public Object parse(String value) { + return value; + } + }; - private static final ParameterParser TYPE_LONG = new ParameterParser() { - @Override - public Object parse(String value) { - if (value == null) { - return null; - } else { - return Long.parseLong(value); - } - } - }; + private static final ParameterParser TYPE_LONG = + new ParameterParser() { + @Override + public Object parse(String value) { + if (value == null) { + return null; + } else { + return Long.parseLong(value); + } + } + }; - private static final ParameterParser TYPE_INT = new ParameterParser() { - @Override - public Object parse(String value) { - if (value == null) { - return null; - } else { - return Integer.parseInt(value); - } - } - }; + private static final ParameterParser TYPE_INT = + new ParameterParser() { + @Override + public Object parse(String value) { + if (value == null) { + return null; + } else { + return Integer.parseInt(value); + } + } + }; - private static final ParameterParser TYPE_BOOL = new ParameterParser() { - @Override - public Object parse(String value) { - if (value == null) { - return null; - } else { - return Boolean.parseBoolean(value); - } - } - }; + private static final ParameterParser TYPE_BOOL = + new ParameterParser() { + @Override + public Object parse(String value) { + if (value == null) { + return null; + } else { + return Boolean.parseBoolean(value); + } + } + }; - private static final HashMap<String, ParameterParser> TYPES = - new HashMap<>(); + private static final HashMap<String, ParameterParser> TYPES = new HashMap<>(); + static { - TYPES.put(CoreConnectionPNames.SO_TIMEOUT, TYPE_INT); TYPES.put(CoreConnectionPNames.TCP_NODELAY, TYPE_BOOL); TYPES.put(CoreConnectionPNames.SOCKET_BUFFER_SIZE, TYPE_INT); @@ -103,6 +104,7 @@ TYPES.put(ConnManagerPNames.TIMEOUT, TYPE_LONG); TYPES.put(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, TYPE_INT); } + private final String pluginName; private Config config; @@ -127,8 +129,7 @@ @Override public Object getParameter(String name) { - String value = - config.getString(pluginName, null, getParamName(name)); + String value = config.getString(pluginName, null, getParamName(name)); return getParameterParser(name).parse(value); } @@ -158,8 +159,7 @@ @Override public long getLongParameter(String name, long defaultValue) { - return config.getLong(pluginName, null, getParamName(name), - defaultValue); + return config.getLong(pluginName, null, getParamName(name), defaultValue); } @Override @@ -169,8 +169,7 @@ @Override public int getIntParameter(String name, int defaultValue) { - return config.getInt(pluginName, null, getParamName(name), - defaultValue); + return config.getInt(pluginName, null, getParamName(name), defaultValue); } @Override @@ -190,8 +189,7 @@ @Override public boolean getBooleanParameter(String name, boolean defaultValue) { - return config.getBoolean(pluginName, null, - getParamName(name), defaultValue); + return config.getBoolean(pluginName, null, getParamName(name), defaultValue); } @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/Transport.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/Transport.java index 98abcb6..38e5d1e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/Transport.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/network/Transport.java
@@ -13,6 +13,9 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.network; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.googlesource.gerrit.plugins.its.rtc.api.ResourceNotFoundException; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -23,7 +26,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; - import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -42,17 +44,11 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.HttpParams; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import com.googlesource.gerrit.plugins.its.rtc.api.ResourceNotFoundException; - public class Transport { public static final String APP_JSON = "application/json"; public static final String ANY = "*/*"; - public static final String APP_OSLC = - "application/x-oslc-cm-change-request+json"; + public static final String APP_OSLC = "application/x-oslc-cm-change-request+json"; private static final Log log = LogFactory.getLog(Transport.class); @@ -64,7 +60,8 @@ private HttpParams httpParams; private RTCClient rtcClient; - public Transport(RTCClient rtcClient, String baseUrl, DefaultHttpClient httpclient, HttpParams httpParams) { + public Transport( + RTCClient rtcClient, String baseUrl, DefaultHttpClient httpclient, HttpParams httpParams) { this.rtcClient = rtcClient; this.baseUrl = baseUrl; this.httpclient = httpclient; @@ -75,35 +72,45 @@ this.gson = gson; } - public <T> T put(final String path, final Type typeOrClass, JsonObject data, - String etag) throws IOException { + public <T> T put(final String path, final Type typeOrClass, JsonObject data, String etag) + throws IOException { HttpPut request = new HttpPut(toUri(path)); if (log.isDebugEnabled()) - log.debug("Preparing PUT against " + request.getURI() + " using etag " - + etag + " and data " + data); + log.debug( + "Preparing PUT against " + + request.getURI() + + " using etag " + + etag + + " and data " + + data); request.setEntity(new StringEntity(data.toString(), StandardCharsets.UTF_8)); if (etag != null) request.addHeader("If-Match", etag); return invoke(request, typeOrClass, APP_OSLC, APP_OSLC); } - public <T> T patch(final String path, final Type typeOrClass, - JsonObject data, String etag) throws IOException { + public <T> T patch(final String path, final Type typeOrClass, JsonObject data, String etag) + throws IOException { HttpPatch request = newHttpPatch(path); if (log.isDebugEnabled()) - log.debug("Preparing PATCH against " + request.getURI() + " using etag " - + etag + " and data " + data); + log.debug( + "Preparing PATCH against " + + request.getURI() + + " using etag " + + etag + + " and data " + + data); request.setEntity(new StringEntity(data.toString(), StandardCharsets.UTF_8)); if (etag != null) request.addHeader("If-Match", etag); return invoke(request, typeOrClass, APP_OSLC, APP_OSLC); } - public <T> T post(final String path, final Type typeOrClass, - String contentType, - final NameValuePair... params) throws IOException { + public <T> T post( + final String path, final Type typeOrClass, String contentType, final NameValuePair... params) + throws IOException { HttpPost request = newHttpPost(path); if (log.isDebugEnabled()) - log.debug("Preparing POST against " + request.getURI() + " using params " - + Arrays.asList(params)); + log.debug( + "Preparing POST against " + request.getURI() + " using params " + Arrays.asList(params)); List<NameValuePair> nameValuePairs = Arrays.asList(params); request.setEntity(new UrlEncodedFormEntity(nameValuePairs, StandardCharsets.UTF_8)); return invoke(request, typeOrClass, contentType, null); @@ -112,22 +119,19 @@ public <T> T get(final String path, final Type typeOrClass) throws IOException, MalformedURLException { final HttpGet request = newHttpGet(path); - if (log.isDebugEnabled()) - log.debug("Preparing GET against " + request.getURI()); + if (log.isDebugEnabled()) log.debug("Preparing GET against " + request.getURI()); return invoke(request, typeOrClass, APP_JSON, null); } - public String get(final String path) throws IOException, - MalformedURLException { + public String get(final String path) throws IOException, MalformedURLException { final HttpGet request = newHttpGet(path); - if (log.isDebugEnabled()) - log.debug("Preparing GET against " + request.getURI()); + if (log.isDebugEnabled()) log.debug("Preparing GET against " + request.getURI()); return invoke(request, null, ANY, null); } @SuppressWarnings("unchecked") - private synchronized <T> T invoke(HttpRequestBase request, - Object typeOrClass, String acceptType, String contentType) + private synchronized <T> T invoke( + HttpRequestBase request, Object typeOrClass, String acceptType, String contentType) throws IOException, ClientProtocolException, ResourceNotFoundException { if (contentType != null) { @@ -155,16 +159,22 @@ String entityString = readEntityAsString(response); if (!assertValidContentType(acceptType, responseContentTypeString)) { - log.error("Request to " + request.getURI() - + " failed because of an invalid content returned:\n" - + entityString); + log.error( + "Request to " + + request.getURI() + + " failed because of an invalid content returned:\n" + + entityString); rtcClient.setLoggedIn(false); - throw new InvalidContentTypeException("Wrong content type '" - + responseContentTypeString + "' in HTTP response (Expected: " - + acceptType + ")"); + throw new InvalidContentTypeException( + "Wrong content type '" + + responseContentTypeString + + "' in HTTP response (Expected: " + + acceptType + + ")"); } - if (typeOrClass != null && acceptType.endsWith("json") + if (typeOrClass != null + && acceptType.endsWith("json") && responseContentTypeString.endsWith("json")) { Transport.etag.set(extractEtag(response)); if (typeOrClass instanceof ParameterizedType) { @@ -184,16 +194,14 @@ } } - private boolean assertValidContentType(String acceptType, - String responseContentTypeString) { + private boolean assertValidContentType(String acceptType, String responseContentTypeString) { if (acceptType == null) { return true; } if (acceptType.endsWith("/*")) { return true; } - if (acceptType.split("/")[1].equalsIgnoreCase(responseContentTypeString - .split("/")[1])) { + if (acceptType.split("/")[1].equalsIgnoreCase(responseContentTypeString.split("/")[1])) { return true; } return false; @@ -255,8 +263,9 @@ private String extractEtag(HttpResponse response) { final Header etagHeader = response.getFirstHeader("ETag"); - return etagHeader == null ? null : etagHeader.getValue().substring(1, - etagHeader.getValue().length() - 1); + return etagHeader == null + ? null + : etagHeader.getValue().substring(1, etagHeader.getValue().length() - 1); } private HttpGet newHttpGet(final String path) { @@ -274,9 +283,7 @@ } private String toUri(final String path) { - if (path.startsWith(baseUrl)) - return path; - else - return baseUrl + path; + if (path.startsWith(baseUrl)) return path; + else return baseUrl + path; } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/RtcSession.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/RtcSession.java index 53fa529..e8cb555 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/RtcSession.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/RtcSession.java
@@ -13,17 +13,15 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.session; +import com.googlesource.gerrit.plugins.its.rtc.api.RtcObject; import java.util.Arrays; import java.util.List; -import com.googlesource.gerrit.plugins.its.rtc.api.RtcObject; - - public class RtcSession extends RtcObject { private String userId; private String[] roles; - + private RtcSession() { super(); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApi.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApi.java index 9a87fea..d13b668 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApi.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApi.java
@@ -20,5 +20,4 @@ void login(String username, String password) throws IOException; void ping() throws IOException; - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApiImpl.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApiImpl.java index ee61be9..29a78e2 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApiImpl.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/session/SessionApiImpl.java
@@ -13,14 +13,12 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.session; -import java.io.IOException; - -import org.apache.http.message.BasicNameValuePair; - import com.googlesource.gerrit.plugins.its.rtc.network.AuthenticationException; import com.googlesource.gerrit.plugins.its.rtc.network.RTCClient; import com.googlesource.gerrit.plugins.its.rtc.network.Transport; import com.googlesource.gerrit.plugins.its.rtc.workitems.AbstractApiImpl; +import java.io.IOException; +import org.apache.http.message.BasicNameValuePair; public class SessionApiImpl extends AbstractApiImpl implements SessionApi { @@ -28,18 +26,20 @@ public SessionApiImpl(RTCClient rtcClient, Transport transport) { super(rtcClient); - this.transport=transport; + this.transport = transport; } @Override - public synchronized void login(String username, String password) - throws IOException { - String result = transport.post("/authenticated/j_security_check", String.class, - Transport.ANY, - new BasicNameValuePair("j_username", username), - new BasicNameValuePair("j_password", password)); - - if(result.indexOf("net.jazz.web.app.authfailed") > 0) { + public synchronized void login(String username, String password) throws IOException { + String result = + transport.post( + "/authenticated/j_security_check", + String.class, + Transport.ANY, + new BasicNameValuePair("j_username", username), + new BasicNameValuePair("j_password", password)); + + if (result.indexOf("net.jazz.web.app.authfailed") > 0) { throw new AuthenticationException("User authentication failed"); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/AbstractApiImpl.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/AbstractApiImpl.java index df65d19..ec6b306 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/AbstractApiImpl.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/AbstractApiImpl.java
@@ -13,9 +13,8 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.io.IOException; - import com.googlesource.gerrit.plugins.its.rtc.network.RTCClient; +import java.io.IOException; public class AbstractApiImpl { protected RTCClient client; @@ -23,9 +22,9 @@ public AbstractApiImpl(RTCClient client) { this.client = client; } - + protected void loginIfNeeded() throws IOException { - if(!client.isLoggedIn()) { + if (!client.isLoggedIn()) { client.login(); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcComment.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcComment.java index 821cd48..d97a8c1 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcComment.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcComment.java
@@ -13,16 +13,15 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.util.Calendar; - import com.googlesource.gerrit.plugins.its.rtc.api.RtcObject; +import java.util.Calendar; public class RtcComment extends RtcObject { String creator; String contents; Calendar created; - + RtcComment(String rdf) { super(rdf); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcCommentDeserializer.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcCommentDeserializer.java index aeba152..06a84d6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcCommentDeserializer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcCommentDeserializer.java
@@ -13,28 +13,27 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.lang.reflect.Type; - import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; - import com.googlesource.gerrit.plugins.its.rtc.api.AbstractDeserializer; +import java.lang.reflect.Type; -public class RtcCommentDeserializer extends AbstractDeserializer implements JsonDeserializer<RtcComment> { +public class RtcCommentDeserializer extends AbstractDeserializer + implements JsonDeserializer<RtcComment> { @Override - public RtcComment deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - + public RtcComment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + JsonObject root = json.getAsJsonObject(); RtcComment result = new RtcComment(extractRdf(root)); result.contents = extractString(root, "dc:description"); result.creator = extractIdenFromRdfResource(root, "dc:creator"); - + return result; } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLink.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLink.java index 855f2b9..69b0740 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLink.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLink.java
@@ -13,9 +13,8 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.net.URL; - import com.googlesource.gerrit.plugins.its.rtc.api.RtcObject; +import java.net.URL; public class RtcRelatedLink extends RtcObject { @@ -26,5 +25,4 @@ public URL resource; public String label; - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLinkDeserializer.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLinkDeserializer.java index 40d8b4f..9bcd35c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLinkDeserializer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcRelatedLinkDeserializer.java
@@ -13,36 +13,34 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.lang.reflect.Type; -import java.net.MalformedURLException; -import java.net.URL; - import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; - import com.googlesource.gerrit.plugins.its.rtc.api.AbstractDeserializer; +import java.lang.reflect.Type; +import java.net.MalformedURLException; +import java.net.URL; public class RtcRelatedLinkDeserializer extends AbstractDeserializer implements JsonDeserializer<RtcRelatedLink> { @Override - public RtcRelatedLink deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - + public RtcRelatedLink deserialize( + JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + JsonObject jsonObj = json.getAsJsonObject(); String resourceUrlString = jsonObj.get("rdf:resource").getAsString(); try { URL resourceUrl = new URL(resourceUrlString); String label = jsonObj.get("oslc_cm:label").getAsString(); - + return new RtcRelatedLink(resourceUrl, label); - + } catch (MalformedURLException e) { throw new JsonParseException("Invalid rdf:resource URL '" + resourceUrlString + "'", e); } } - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItem.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItem.java index d9ada02..06dc276 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItem.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItem.java
@@ -13,11 +13,9 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.util.Calendar; - import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; import com.googlesource.gerrit.plugins.its.rtc.api.RtcObject; - +import java.util.Calendar; public class RtcWorkItem extends RtcObject { @@ -32,8 +30,8 @@ RtcEntity severity; RtcEntity priority; RtcEntity type; -// private List<RtcComment> comments; // - + // private List<RtcComment> comments; // + RtcWorkItem(String rdf) { super(rdf); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItemDeserializer.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItemDeserializer.java index cc7e84f..d6d966c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItemDeserializer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkItemDeserializer.java
@@ -13,20 +13,19 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.io.IOException; -import java.lang.reflect.Type; - import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; - import com.googlesource.gerrit.plugins.its.rtc.api.AbstractDeserializer; import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; import com.googlesource.gerrit.plugins.its.rtc.network.CachableResourcesFactory; +import java.io.IOException; +import java.lang.reflect.Type; -public class RtcWorkItemDeserializer extends AbstractDeserializer implements JsonDeserializer<RtcWorkItem> { +public class RtcWorkItemDeserializer extends AbstractDeserializer + implements JsonDeserializer<RtcWorkItem> { private CachableResourcesFactory factory; @@ -35,34 +34,33 @@ } @Override - public RtcWorkItem deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - + public RtcWorkItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + JsonObject root = json.getAsJsonObject(); RtcWorkItem result = new RtcWorkItem(extractRdf(root)); result.id = extractLong(root, "dc:identifier"); - result.title = extractString(root,"dc:title"); - result.subject = extractString(root,"dc:subject"); + result.title = extractString(root, "dc:title"); + result.subject = extractString(root, "dc:subject"); result.creator = extractIdenFromRdfResource(root, "dc:creator"); result.ownedby = extractIdenFromRdfResource(root, "rtc_cm:ownedBy"); result.status = extractResource(root, "rtc_cm:state", RtcEntity.class); result.severity = extractResource(root, "oslc_cm:severity", RtcEntity.class); result.priority = extractResource(root, "oslc_cm:priority", RtcEntity.class); result.type = extractResource(root, "dc:type", RtcEntity.class); - - + return result; } - private RtcEntity extractResource(JsonObject root, final String memberName, - final Class<RtcEntity> clazz) { + private RtcEntity extractResource( + JsonObject root, final String memberName, final Class<RtcEntity> clazz) { String url = extractRdfResourceUrl(root, memberName); try { return factory.get(url, clazz); } catch (IOException e) { - throw new JsonParseException("Unable to parse resource from url "+url+" using class "+clazz, e); + throw new JsonParseException( + "Unable to parse resource from url " + url + " using class " + clazz, e); } } - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowAction.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowAction.java index bf2403a..20f3c01 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowAction.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowAction.java
@@ -18,14 +18,15 @@ public class RtcWorkflowAction extends RtcEntity { String resultStateRdf; - + public RtcWorkflowAction(String id, String title) { super(id, title); } + public RtcWorkflowAction(String rdf, String id, String title) { super(rdf, id, title); } - + public String getResultStateRdf() { return resultStateRdf; }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowActionDeserializer.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowActionDeserializer.java index 79f9f5f..3c9f417 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowActionDeserializer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/RtcWorkflowActionDeserializer.java
@@ -13,22 +13,22 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; -import java.lang.reflect.Type; - import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; - import com.googlesource.gerrit.plugins.its.rtc.api.AbstractDeserializer; +import java.lang.reflect.Type; -public class RtcWorkflowActionDeserializer extends AbstractDeserializer implements JsonDeserializer<RtcWorkflowAction> { +public class RtcWorkflowActionDeserializer extends AbstractDeserializer + implements JsonDeserializer<RtcWorkflowAction> { @Override - public RtcWorkflowAction deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - + public RtcWorkflowAction deserialize( + JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + JsonObject root = json.getAsJsonObject(); final String rdf = extractRdf(root); @@ -36,7 +36,7 @@ final String title = extractString(root, "dc:title"); RtcWorkflowAction result = new RtcWorkflowAction(rdf, id, title); result.resultStateRdf = extractRdf(root.get("rtc_cm:resultState").getAsJsonObject()); - + return result; } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApi.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApi.java index c051a8e..ed625af 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApi.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApi.java
@@ -13,25 +13,22 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; +import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; import java.io.IOException; import java.net.URL; import java.util.List; -import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; - public interface WorkItemsApi { public RtcWorkItem getWorkItem(long id) throws IOException; public RtcComment addComment(long id, String text) throws IOException; - public RtcRelatedLink addRelated(long id, URL relatedUrl, String text) - throws IOException; + public RtcRelatedLink addRelated(long id, URL relatedUrl, String text) throws IOException; public List<RtcEntity> getAvailableStatuses(RtcWorkItem wip) throws IOException; public List<RtcWorkflowAction> getAvailableActions(RtcWorkItem wip) throws IOException; public RtcWorkItem performAction(RtcWorkItem wip, String newStatusTitle) throws IOException; - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApiImpl.java b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApiImpl.java index cb8ae2a..a0ca2cf 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApiImpl.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/rtc/workitems/WorkItemsApiImpl.java
@@ -13,25 +13,23 @@ // limitations under the License. package com.googlesource.gerrit.plugins.its.rtc.workitems; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.googlesource.gerrit.plugins.its.rtc.api.ResourceInvalidException; +import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; +import com.googlesource.gerrit.plugins.its.rtc.network.RTCClient; +import com.googlesource.gerrit.plugins.its.rtc.network.Transport; import java.io.IOException; import java.lang.reflect.Type; import java.net.URL; import java.util.Collection; import java.util.List; - import org.apache.http.message.BasicNameValuePair; -import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; - -import com.googlesource.gerrit.plugins.its.rtc.api.ResourceInvalidException; -import com.googlesource.gerrit.plugins.its.rtc.api.RtcEntity; -import com.googlesource.gerrit.plugins.its.rtc.network.RTCClient; -import com.googlesource.gerrit.plugins.its.rtc.network.Transport; - public class WorkItemsApiImpl extends AbstractApiImpl implements WorkItemsApi { private Transport transport; + public WorkItemsApiImpl(RTCClient rtcClient, Transport transport) { super(rtcClient); this.transport = transport; @@ -44,34 +42,31 @@ } @Override - public synchronized RtcComment addComment(long id, String text) - throws IOException { + public synchronized RtcComment addComment(long id, String text) throws IOException { loginIfNeeded(); - return transport.post("/oslc/workitems/" + id + "/rtc_cm:comments", - RtcComment.class, + return transport.post( + "/oslc/workitems/" + id + "/rtc_cm:comments", + RtcComment.class, Transport.APP_JSON, new BasicNameValuePair("dc:description", text)); } @Override - public synchronized RtcRelatedLink addRelated(long id, URL relatedUrl, - String text) throws IOException { + public synchronized RtcRelatedLink addRelated(long id, URL relatedUrl, String text) + throws IOException { loginIfNeeded(); - return transport - .post( - "/oslc/workitems/" - + id - + "/rtc_cm:com.ibm.team.workitem.linktype.relatedartifact.relatedArtifact", - RtcRelatedLink.class, - Transport.APP_JSON, - new BasicNameValuePair("rdf:resource", - relatedUrl.toExternalForm()), new BasicNameValuePair( - "oslc_cm:label", text)); + return transport.post( + "/oslc/workitems/" + + id + + "/rtc_cm:com.ibm.team.workitem.linktype.relatedartifact.relatedArtifact", + RtcRelatedLink.class, + Transport.APP_JSON, + new BasicNameValuePair("rdf:resource", relatedUrl.toExternalForm()), + new BasicNameValuePair("oslc_cm:label", text)); } @Override - public List<RtcEntity> getAvailableStatuses(RtcWorkItem wip) - throws IOException { + public List<RtcEntity> getAvailableStatuses(RtcWorkItem wip) throws IOException { loginIfNeeded(); final String rdf = wip.getStatus().getRdf(); final String url = rdf.substring(0, rdf.lastIndexOf('/')) + ".json"; @@ -80,18 +75,17 @@ } @Override - public List<RtcWorkflowAction> getAvailableActions(RtcWorkItem wip) - throws IOException { + public List<RtcWorkflowAction> getAvailableActions(RtcWorkItem wip) throws IOException { loginIfNeeded(); final String rdf = wip.getStatus().getRdf(); - final String url = rdf.substring(0, rdf.lastIndexOf('/')).replace("states", "actions")+ ".json"; + final String url = + rdf.substring(0, rdf.lastIndexOf('/')).replace("states", "actions") + ".json"; final Type type = new TypeToken<Collection<RtcWorkflowAction>>() {}.getType(); return transport.get(url, type); } @Override - public RtcWorkItem performAction(RtcWorkItem wip, String actionTitle) - throws IOException { + public RtcWorkItem performAction(RtcWorkItem wip, String actionTitle) throws IOException { loginIfNeeded(); RtcWorkflowAction action = null; List<RtcWorkflowAction> allActions = getAvailableActions(wip); @@ -105,8 +99,8 @@ if (action == null) { throw new ResourceInvalidException(actionTitle); } - - final String url = "/oslc/workitems/" + wip.getId()+"?_action="+action.getId(); + + final String url = "/oslc/workitems/" + wip.getId() + "?_action=" + action.getId(); JsonObject rdf = new JsonObject(); rdf.addProperty("rdf:resource", action.getResultStateRdf()); @@ -115,28 +109,28 @@ return transport.patch(url, RtcWorkItem.class, data, wip.getEtag()); } - -/* - Object foo() - { -// String s = wip.getStatus().getRdf(); -// JsonObject rdf = new JsonObject(); -// rdf.addProperty("rdf:resource", s); -// JsonObject data = new JsonObject(); -// data.add("rtc_cm:state", rdf); - JsonObject rdf = new JsonObject(); - final String url = newStatus.getRdf(); - rdf.addProperty("rdf:resource", url); - JsonObject data = new JsonObject(); - data.add("rtc_cm:state", rdf); + /* + Object foo() + { + // String s = wip.getStatus().getRdf(); + // JsonObject rdf = new JsonObject(); + // rdf.addProperty("rdf:resource", s); + // JsonObject data = new JsonObject(); + // data.add("rtc_cm:state", rdf); -// JsonObject data = new JsonObject(); -// data.addProperty("dc:title", "Hey, wombats! Is this so called 'patch' really working???"); + JsonObject rdf = new JsonObject(); + final String url = newStatus.getRdf(); + rdf.addProperty("rdf:resource", url); + JsonObject data = new JsonObject(); + data.add("rtc_cm:state", rdf); - System.err.println(data); - return transport.patch("/oslc/workitems/" + wip.getId(), RtcWorkItem.class, data, wip.getEtag()); -// return transport.put("/oslc/workitems/" + wip.getId()+"?oslc_cm.properties=rtc_cm:state", RtcWorkItem.class, data, wip.getEtag()); - } -*/ + // JsonObject data = new JsonObject(); + // data.addProperty("dc:title", "Hey, wombats! Is this so called 'patch' really working???"); + + System.err.println(data); + return transport.patch("/oslc/workitems/" + wip.getId(), RtcWorkItem.class, data, wip.getEtag()); + // return transport.put("/oslc/workitems/" + wip.getId()+"?oslc_cm.properties=rtc_cm:state", RtcWorkItem.class, data, wip.getEtag()); + } + */ }