From 3851a6c1dfae45511d407ec03efdcfea55da99cb Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Wed, 27 Apr 2016 16:47:14 +0200 Subject: [PATCH] Fixed sonar issues and added javadoc Signed-off-by: Jonathan Philip Knoblauch --- examples/hawkbit-example-ddi-client/pom.xml | 18 +++++----- .../client/DdiAcceptedRequestInterceptor.java | 27 --------------- .../hawkbit/ddi/client/DdiDecoder.java | 11 +++--- .../ddi/client/DdiDefaultFeignClient.java | 26 ++++++++++---- .../hawkbit/ddi/client/DdiExampleClient.java | 34 +++++++++++-------- .../RootControllerResourceClient.java | 5 +-- ...RootControllerResourceClientConstants.java | 21 ++++++++++++ .../ArtifactsPersistenceStrategy.java | 1 + 8 files changed, 75 insertions(+), 68 deletions(-) delete mode 100644 examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java create mode 100644 examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClientConstants.java diff --git a/examples/hawkbit-example-ddi-client/pom.xml b/examples/hawkbit-example-ddi-client/pom.xml index c6acefb00..661d59f8f 100644 --- a/examples/hawkbit-example-ddi-client/pom.xml +++ b/examples/hawkbit-example-ddi-client/pom.xml @@ -73,16 +73,14 @@ 2.5 - com.google.guava - guava - - - commons-lang - commons-lang - 2.3 - - - + com.google.guava + guava + + + commons-lang + commons-lang + 2.3 + diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java deleted file mode 100644 index 3e82618c0..000000000 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH 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 - */ -package org.eclipse.hawkbit.ddi.client; - -import org.springframework.http.MediaType; - -import feign.RequestInterceptor; -import feign.RequestTemplate; - -/** - * - * - */ -public class DdiAcceptedRequestInterceptor implements RequestInterceptor { - - @Override - public void apply(final RequestTemplate template) { - template.header("Accept", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE, - MediaType.TEXT_PLAIN_VALUE); - } -} diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDecoder.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDecoder.java index 47a59a667..79f0758e0 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDecoder.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDecoder.java @@ -20,9 +20,7 @@ import org.springframework.http.ResponseEntity; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import feign.FeignException; import feign.Response; -import feign.codec.DecodeException; import feign.codec.Decoder; import feign.jackson.JacksonDecoder; @@ -32,8 +30,9 @@ import feign.jackson.JacksonDecoder; */ public class DdiDecoder implements Decoder { - ObjectMapper mapper; - private final String octentTypeOctetStream = "[application/octet-stream]"; + private static final String OCTET_STREAM = "[application/octet-stream]"; + + private final ObjectMapper mapper; public DdiDecoder() { mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) @@ -41,11 +40,11 @@ public class DdiDecoder implements Decoder { } @Override - public Object decode(final Response response, final Type type) throws IOException, DecodeException, FeignException { + public Object decode(final Response response, final Type type) throws IOException { final Map> header = response.headers(); final String contentType = String.valueOf(header.get("Content-Type")); - if (contentType.equals(octentTypeOctetStream)) { + if (contentType.equals(OCTET_STREAM)) { return ResponseEntity.ok(response.body().asInputStream()); } final ResponseEntityDecoder responseEntityDecoder = new ResponseEntityDecoder(new JacksonDecoder(mapper)); diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java index d156e8eb5..e579c07b5 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ddi.client; import org.apache.commons.lang.Validate; import org.eclipse.hawkbit.ddi.client.authenctication.AuthenticationInterceptor; import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient; +import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClientConstants; import org.eclipse.hawkbit.feign.core.client.ApplicationJsonRequestHeaderInterceptor; import org.eclipse.hawkbit.feign.core.client.IgnoreMultipleConsumersProducersSpringMvcContract; @@ -26,26 +27,39 @@ import feign.jackson.JacksonEncoder; public class DdiDefaultFeignClient { private RootControllerResourceClient rootControllerResourceClient; - private final Builder feignBuilder; private final String baseUrl; private final String tenant; + /** + * Constructor for default DDI feign client with no authentication. + * + * @param baseUrl + * the base url of the client + * @param tenant + * the tenant + */ public DdiDefaultFeignClient(final String baseUrl, final String tenant) { this(baseUrl, tenant, null); } + /** + * Constructor for default DDI feign client with authentication. + * + * @param baseUrl + * the base url of the client + * @param tenant + * the tenant + * @param authenticationInterceptor + */ public DdiDefaultFeignClient(final String baseUrl, final String tenant, final AuthenticationInterceptor authenticationInterceptor) { feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract()) - .requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()) - .requestInterceptor(new DdiAcceptedRequestInterceptor()).logLevel(Level.FULL) + .requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()).logLevel(Level.FULL) .logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder()).decoder(new DdiDecoder()); - if (authenticationInterceptor != null) { feignBuilder.requestInterceptor(authenticationInterceptor); } - Validate.notNull(baseUrl, "A baseUrl has to be set"); Validate.notNull(tenant, "A tenant has to be set"); this.baseUrl = baseUrl; @@ -69,7 +83,7 @@ public class DdiDefaultFeignClient { public RootControllerResourceClient getRootControllerResourceClient() { if (rootControllerResourceClient == null) { - String rootControllerResourcePath = this.baseUrl + RootControllerResourceClient.PATH; + String rootControllerResourcePath = this.baseUrl + RootControllerResourceClientConstants.PATH; rootControllerResourcePath = rootControllerResourcePath.replace("{tenant}", tenant); rootControllerResourceClient = feignBuilder.target(RootControllerResourceClient.class, rootControllerResourcePath); diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java index 5945fef5d..2c0421067 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java @@ -47,7 +47,6 @@ public class DdiExampleClient implements Runnable { private final RootControllerResourceClient rootControllerResourceClient; private final ArtifactsPersistenceStrategy persistenceStrategy; private DdiClientStatus clientStatus; - private FinalResult finalResultOfCurrentUpdate; /** @@ -83,7 +82,8 @@ public class DdiExampleClient implements Runnable { * might be {@code null} */ public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant, - final ArtifactsPersistenceStrategy persistenceStrategy, final AuthenticationInterceptor authenticationInterceptor) { + final ArtifactsPersistenceStrategy persistenceStrategy, + final AuthenticationInterceptor authenticationInterceptor) { this.controllerId = controllerId; this.rootControllerResourceClient = new DdiDefaultFeignClient(baseUrl, tenant, authenticationInterceptor) .getRootControllerResourceClient(); @@ -130,22 +130,25 @@ public class DdiExampleClient implements Runnable { private void startDownload(final Long actionId, final Integer resource) { final ResponseEntity respone = rootControllerResourceClient - .getControllerBasedeploymentAction(controllerId, Long.valueOf(actionId), Integer.valueOf(resource)); + .getControllerBasedeploymentAction(controllerId, actionId, resource); final DdiDeploymentBase ddiDeploymentBase = respone.getBody(); final List chunks = ddiDeploymentBase.getDeployment().getChunks(); for (final DdiChunk chunk : chunks) { - final List artifactList = chunk.getArtifacts(); - if (artifactList.isEmpty()) { - sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, - "No artifacts to download for softwaremodule " + chunk.getName()); - } else { - for (final DdiArtifact ddiArtifact : artifactList) { - if (finalResultOfCurrentUpdate != FinalResult.FAILURE) { - downloadArtifact(actionId, ddiArtifact); - } - } - } + downloadArtifacts(chunk, actionId); + } + } + private void downloadArtifacts(final DdiChunk chunk, final Long actionId) { + final List artifactList = chunk.getArtifacts(); + if (artifactList.isEmpty()) { + sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, + "No artifacts to download for softwaremodule " + chunk.getName()); + return; + } + for (final DdiArtifact ddiArtifact : artifactList) { + if (finalResultOfCurrentUpdate != FinalResult.FAILURE) { + downloadArtifact(actionId, ddiArtifact); + } } } @@ -170,8 +173,9 @@ public class DdiExampleClient implements Runnable { sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, "Downloaded artifact " + artifact); } catch (final IOException e) { + LOGGER.error("Download of artifact failed", e); sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, - "Downloaded of artifact " + artifact + "failed"); + "Download of artifact " + artifact + "failed"); finalResultOfCurrentUpdate = FinalResult.FAILURE; } diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClient.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClient.java index 76867af98..db41a6e86 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClient.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClient.java @@ -14,10 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the Rootcontroller resource of the DDI API. */ - -@FeignClient(url = "${hawkbit.url:localhost:8080}/" + RootControllerResourceClient.PATH) +@FeignClient(url = "${hawkbit.url:localhost:8080}/" + RootControllerResourceClientConstants.PATH) public interface RootControllerResourceClient extends DdiRootControllerRestApi { - static String PATH = "{tenant}/controller/v1"; - } diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClientConstants.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClientConstants.java new file mode 100644 index 000000000..d902c2da0 --- /dev/null +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/resource/RootControllerResourceClientConstants.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved. + */ +package org.eclipse.hawkbit.ddi.client.resource; + +/** + * + * Constants for RootController resource client. + */ +public class RootControllerResourceClientConstants { + + public static final String PATH = "{tenant}/controller/v1"; + + /** + * Default constructor. + */ + private RootControllerResourceClientConstants() { + + } + +} diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java index 347b01bcc..d7e99522e 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java @@ -14,6 +14,7 @@ import java.io.InputStream; /** * Interface of persistence strategy. */ +@FunctionalInterface public interface ArtifactsPersistenceStrategy { /**