Some clean code refactorings
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
0
3rd-dependencies/listDeps.sh
Normal file → Executable file
0
3rd-dependencies/listDeps.sh
Normal file → Executable file
@@ -16,8 +16,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
*/
|
||||
@ConfigurationProperties("hawkbit.artifact.url")
|
||||
public class ArtifactUrlHandlerProperties {
|
||||
private static final String DEFAULT_IP_LOCALHOST = "127.0.0.1";
|
||||
private static final String LOCALHOST = "localhost";
|
||||
|
||||
private final Http http = new Http();
|
||||
private final Https https = new Https();
|
||||
@@ -54,227 +52,45 @@ public class ArtifactUrlHandlerProperties {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for declaring common properties through all supported protocols
|
||||
* pattern.
|
||||
*/
|
||||
public interface ProtocolProperties {
|
||||
/**
|
||||
* @return the hostname value to resolve in the pattern.
|
||||
*/
|
||||
String getHostname();
|
||||
|
||||
/**
|
||||
* @return the IP address value to resolve in the pattern.
|
||||
*/
|
||||
String getIp();
|
||||
|
||||
/**
|
||||
* @return the port value to resolve in the pattern.
|
||||
*/
|
||||
String getPort();
|
||||
|
||||
/**
|
||||
* @return the pattern to build the URL.
|
||||
*/
|
||||
String getPattern();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the {@link ProtocolProperties} is
|
||||
* enabled.
|
||||
*/
|
||||
boolean isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Object to hold the properties for the HTTP protocol.
|
||||
*/
|
||||
public static class Http implements ProtocolProperties {
|
||||
private String hostname = LOCALHOST;
|
||||
private String ip = DEFAULT_IP_LOCALHOST;
|
||||
private String port = "";
|
||||
/**
|
||||
* An ant-URL pattern with placeholder to build the URL on. The URL can
|
||||
* have specific artifact placeholder.
|
||||
*/
|
||||
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
|
||||
public static class Http extends DefaultProtocolProperties {
|
||||
|
||||
/**
|
||||
* Enables HTTP URI generation in DDI and DMF.
|
||||
* Constructor.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(final String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(final String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public void setPattern(final String urlPattern) {
|
||||
this.pattern = urlPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(final String port) {
|
||||
this.port = port;
|
||||
public Http() {
|
||||
setPattern(
|
||||
"{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Object to hold the properties for the HTTP protocol.
|
||||
*/
|
||||
public static class Https implements ProtocolProperties {
|
||||
private String hostname = LOCALHOST;
|
||||
private String ip = DEFAULT_IP_LOCALHOST;
|
||||
private String port = "";
|
||||
/**
|
||||
* An ant-URL pattern with placeholder to build the URL on. The URL can
|
||||
* have specific artifact placeholder.
|
||||
*/
|
||||
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
|
||||
public static class Https extends DefaultProtocolProperties {
|
||||
|
||||
/**
|
||||
* Enables HTTPS URI generation in DDI and DMF.
|
||||
* Constructor.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(final String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(final String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public void setPattern(final String urlPattern) {
|
||||
this.pattern = urlPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(final String port) {
|
||||
this.port = port;
|
||||
public Https() {
|
||||
setPattern(
|
||||
"{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Object to hold the properties for the HTTP protocol.
|
||||
*/
|
||||
public static class Coap implements ProtocolProperties {
|
||||
private String hostname = LOCALHOST;
|
||||
private String ip = DEFAULT_IP_LOCALHOST;
|
||||
private String port = "5683";
|
||||
/**
|
||||
* An ant-URL pattern with placeholder to build the URL on. The URL can
|
||||
* have specific artifact placeholder.
|
||||
*/
|
||||
private String pattern = "{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}";
|
||||
public static class Coap extends DefaultProtocolProperties {
|
||||
|
||||
/**
|
||||
* Enables CoAP URI generation in DMF.
|
||||
* Constructor.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(final String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(final String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public void setPattern(final String urlPattern) {
|
||||
this.pattern = urlPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(final String port) {
|
||||
this.port = port;
|
||||
public Coap() {
|
||||
setPattern("{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}");
|
||||
setPort("5683");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 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.api;
|
||||
|
||||
/**
|
||||
* Object to hold the properties for the base protocols.
|
||||
*/
|
||||
public class DefaultProtocolProperties implements ProtocolProperties {
|
||||
// The IP address is not hardcoded. It's the default value, if the IP
|
||||
// address is not configured.
|
||||
@SuppressWarnings("squid:S1313")
|
||||
private static final String DEFAULT_IP_LOCALHOST = "127.0.0.1";
|
||||
private static final String LOCALHOST = "localhost";
|
||||
|
||||
private String hostname = LOCALHOST;
|
||||
private String ip = DEFAULT_IP_LOCALHOST;
|
||||
private String port = "";
|
||||
/**
|
||||
* An ant-URL pattern with placeholder to build the URL on. The URL can have
|
||||
* specific artifact placeholder.
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* Enables protocol.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(final String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(final String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public void setPattern(final String urlPattern) {
|
||||
this.pattern = urlPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(final String port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties.ProtocolProperties;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -61,7 +60,7 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
||||
for (final Entry<String, String> entry : entrySet) {
|
||||
if (entry.getKey().equals(PORT_PLACEHOLDER)) {
|
||||
urlPattern = urlPattern.replace(":{" + entry.getKey() + "}",
|
||||
Strings.isNullOrEmpty(entry.getValue()) ? "" : ":" + entry.getValue());
|
||||
Strings.isNullOrEmpty(entry.getValue()) ? "" : (":" + entry.getValue()));
|
||||
} else {
|
||||
urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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.api;
|
||||
|
||||
/**
|
||||
* Interface for declaring common properties through all supported protocols
|
||||
* pattern.
|
||||
*/
|
||||
public interface ProtocolProperties {
|
||||
/**
|
||||
* @return the hostname value to resolve in the pattern.
|
||||
*/
|
||||
String getHostname();
|
||||
|
||||
/**
|
||||
* @return the IP address value to resolve in the pattern.
|
||||
*/
|
||||
String getIp();
|
||||
|
||||
/**
|
||||
* @return the port value to resolve in the pattern.
|
||||
*/
|
||||
String getPort();
|
||||
|
||||
/**
|
||||
* @return the pattern to build the URL.
|
||||
*/
|
||||
String getPattern();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the {@link ProtocolProperties} is enabled.
|
||||
*/
|
||||
boolean isEnabled();
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import org.springframework.cache.CacheManager;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* A cache interface which handles multi tenancy.
|
||||
*/
|
||||
public interface TenancyCacheManager extends CacheManager {
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class TenantAwareCacheManager implements TenancyCacheManager {
|
||||
public Collection<String> getCacheNames() {
|
||||
String currentTenant = tenantAware.getCurrentTenant();
|
||||
if (currentTenant == null) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
currentTenant = currentTenant.toUpperCase();
|
||||
|
||||
@@ -27,7 +27,7 @@ public final class DurationHelper {
|
||||
* the defined min/max range.
|
||||
*
|
||||
*/
|
||||
public static class DurationRangeValidator {
|
||||
public static final class DurationRangeValidator {
|
||||
final Duration min;
|
||||
final Duration max;
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param messageConverter
|
||||
* message converter
|
||||
* @param rabbitTemplate
|
||||
* the rabbitTemplate
|
||||
*/
|
||||
@Autowired
|
||||
public AmqpMessageDispatcherService(final RabbitTemplate rabbitTemplate) {
|
||||
|
||||
@@ -107,6 +107,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
super(defaultTemplate);
|
||||
}
|
||||
|
||||
// Method is not unused. It is called by the spring rabbit listener.
|
||||
@SuppressWarnings("squid:UnusedPrivateMethod")
|
||||
@RabbitListener(queues = "${hawkbit.dmf.rabbitmq.receiverQueue}", containerFactory = "listenerContainerFactory")
|
||||
private Message onMessage(final Message message, @Header(MessageHeaderKey.TYPE) final String type,
|
||||
@Header(MessageHeaderKey.TENANT) final String tenant) {
|
||||
@@ -417,7 +419,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkContentTypeJson(final Message message) {
|
||||
private static void checkContentTypeJson(final Message message) {
|
||||
final MessageProperties messageProperties = message.getMessageProperties();
|
||||
if (messageProperties.getContentType() != null && messageProperties.getContentType().contains("json")) {
|
||||
return;
|
||||
|
||||
@@ -38,16 +38,6 @@ public class BaseAmqpService {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean message properties before sending a message.
|
||||
*
|
||||
* @param message
|
||||
* the message to cleaned up
|
||||
*/
|
||||
protected void cleanMessageHeaderProperties(final Message message) {
|
||||
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is needed to convert a incoming message to is originally object type.
|
||||
*
|
||||
@@ -67,7 +57,7 @@ public class BaseAmqpService {
|
||||
return (T) rabbitTemplate.getMessageConverter().fromMessage(message);
|
||||
}
|
||||
|
||||
private boolean isMessageBodyEmpty(final Message message) {
|
||||
private static boolean isMessageBodyEmpty(final Message message) {
|
||||
return message == null || message.getBody() == null || message.getBody().length == 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user