diff --git a/hawkbit-core/pom.xml b/hawkbit-core/pom.xml index 514ded4ba..74b532cfe 100644 --- a/hawkbit-core/pom.xml +++ b/hawkbit-core/pom.xml @@ -9,52 +9,52 @@ SPDX-License-Identifier: EPL-2.0 --> - - 4.0.0 - - org.eclipse.hawkbit - hawkbit-parent - ${revision} - - hawkbit-core - hawkBit :: Core + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-parent + ${revision} + + hawkbit-core + hawkBit :: Core - - - org.springframework.boot - spring-boot - - - org.slf4j - slf4j-api - - - jakarta.validation - jakarta.validation-api - - - commons-io - commons-io - ${commons-io.version} - - - - - io.github.classgraph - classgraph - test - - - org.springframework.boot - spring-boot-starter-test - test - - - io.qameta.allure - allure-junit5 - test - - + + + org.springframework.boot + spring-boot + + + org.slf4j + slf4j-api + + + jakarta.validation + jakarta.validation-api + + + commons-io + commons-io + ${commons-io.version} + + + + + io.github.classgraph + classgraph + test + + + org.springframework.boot + spring-boot-starter-test + test + + + io.qameta.allure + allure-junit5 + test + + \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/ContextAware.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/ContextAware.java index 9fb9d3303..c81d267a5 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/ContextAware.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/ContextAware.java @@ -9,12 +9,12 @@ */ package org.eclipse.hawkbit; -import org.eclipse.hawkbit.tenancy.TenantAware; - import java.util.Objects; import java.util.Optional; import java.util.function.Function; +import org.eclipse.hawkbit.tenancy.TenantAware; + /** * {@link ContextAware} provides means for getting the current context (via {@link #getCurrentContext()}) and then * to execute a {@link Runnable} or a {@link Function} in the same context using {@link #runInContext(String, Runnable)} @@ -28,7 +28,7 @@ public interface ContextAware extends TenantAware { /** * Return the current context encoded as a {@link String}. Depending on the implementation it could, * for instance, be a serialized context or a reference to such. - * + * * @return could be empty if there is nothing to serialize or context aware is not supported. */ Optional getCurrentContext(); @@ -38,7 +38,6 @@ public interface ContextAware extends TenantAware { * * @param the type of the input to the function * @param the type of the result of the function - * * @param serializedContext created by {@link #getCurrentContext()}. Must be non-null. * @param function function to call in the reconstructed context. Must be non-null. * @param t the argument that will be passed to the function diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java index ada7ace88..f3a13e8cd 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/ControllerPollProperties.java @@ -12,19 +12,19 @@ package org.eclipse.hawkbit; import java.io.Serializable; import lombok.Data; - import org.springframework.boot.context.properties.ConfigurationProperties; /** * Defines global configuration for the controllers/clients on the provisioning * targets/devices. - * + * * Note: many of the controller related properties can be overridden on tenant * level. */ @Data @ConfigurationProperties(prefix = "hawkbit.controller") public class ControllerPollProperties implements Serializable { + private static final long serialVersionUID = 1L; /** diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/DistributedResourceBundleMessageSource.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/DistributedResourceBundleMessageSource.java index 9066abf2d..f4e69fc65 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/DistributedResourceBundleMessageSource.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/DistributedResourceBundleMessageSource.java @@ -39,6 +39,12 @@ public class DistributedResourceBundleMessageSource extends ReloadableResourceBu setUseCodeAsDefaultMessage(true); } + @Override + public void setResourceLoader(final ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + super.setResourceLoader(resourceLoader); + } + @Override protected PropertiesHolder refreshProperties(final String filename, final PropertiesHolder propHolder) { final Properties properties = new Properties(); @@ -66,10 +72,4 @@ public class DistributedResourceBundleMessageSource extends ReloadableResourceBu } return new PropertiesHolder(properties, lastModified); } - - @Override - public void setResourceLoader(final ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - super.setResourceLoader(resourceLoader); - } } \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/HawkbitServerProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/HawkbitServerProperties.java index 3d8d75348..b2701ea69 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/HawkbitServerProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/HawkbitServerProperties.java @@ -11,25 +11,26 @@ package org.eclipse.hawkbit; import lombok.Data; import lombok.Getter; - import org.springframework.boot.context.properties.ConfigurationProperties; /** * Properties for the server e.g. the server's URL which must be configured. - * */ @Getter @ConfigurationProperties("hawkbit.server") public class HawkbitServerProperties { + + private final Anonymous anonymous = new Anonymous(); + private final Build build = new Build(); /** * Defines under which URI the update server can be reached. Used to * calculate download URLs for DMF transmitted update actions. */ private String url = "http://localhost:8080"; - private final Anonymous anonymous = new Anonymous(); - - private final Build build = new Build(); + public void setUrl(final String url) { + this.url = url; + } /** * Properties for anonymous API access by Devices/Controllers. @@ -42,7 +43,6 @@ public class HawkbitServerProperties { /** * Properties for artifact download under anonymous API access by * Devices/Controllers. - * */ @Data public static class Download { @@ -56,7 +56,6 @@ public class HawkbitServerProperties { /** * Build information of the hawkBit instance. Influenced by maven. - * */ public static class Build { @@ -74,8 +73,4 @@ public class HawkbitServerProperties { } } - - public void setUrl(final String url) { - this.url = url; - } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrl.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrl.java index edddf0404..2b5303444 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrl.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrl.java @@ -13,7 +13,6 @@ import lombok.Data; /** * Container for a generated Artifact URL. - * */ @Data public class ArtifactUrl { @@ -24,13 +23,10 @@ public class ArtifactUrl { /** * Constructor. - * - * @param protocol - * string, e.g. ftp, http, https - * @param rel - * hypermedia value - * @param ref - * hypermedia value + * + * @param protocol string, e.g. ftp, http, https + * @param rel hypermedia value + * @param ref hypermedia value */ public ArtifactUrl(final String protocol, final String rel, final String ref) { this.protocol = protocol; diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java index 20c002a48..8d55149fb 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java @@ -15,7 +15,6 @@ import java.util.List; /** * Interface declaration of the {@link ArtifactUrlHandler} which generates the * URLs to specific artifacts. - * */ public interface ArtifactUrlHandler { @@ -23,11 +22,8 @@ public interface ArtifactUrlHandler { * Returns a generated download URL for a given artifact parameters for a * specific protocol. * - * @param placeholder - * data for URL generation - * @param api - * given protocol that URL needs to support - * + * @param placeholder data for URL generation + * @param api given protocol that URL needs to support * @return an URL for the given artifact parameters in a given protocol */ List getUrls(URLPlaceholder placeholder, ApiType api); @@ -36,14 +32,10 @@ public interface ArtifactUrlHandler { * Returns a generated download URL for a given artifact parameters for a * specific protocol. * - * @param placeholder - * data for URL generation - * @param api - * given protocol that URL needs to support - * @param requestUri - * of the request that allows the handler to align the generated - * URL to the original request. - * + * @param placeholder data for URL generation + * @param api given protocol that URL needs to support + * @param requestUri of the request that allows the handler to align the generated + * URL to the original request. * @return an URL for the given artifact parameters in a given protocol */ List getUrls(URLPlaceholder placeholder, ApiType api, URI requestUri); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java index 5a673ddcd..239359936 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java @@ -21,7 +21,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; /** * Artifact handler properties class for holding all supported protocols with * host, ip, port and download pattern. - * + * * @see PropertyBasedArtifactUrlHandler */ @Data diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/Base62Util.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/Base62Util.java index da07f10cd..7d7722bd4 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/Base62Util.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/Base62Util.java @@ -23,8 +23,7 @@ public final class Base62Util { private static final int BASE62_BASE = BASE62_ALPHABET.length(); /** - * @param base10 - * number + * @param base10 number * @return converted number into Base62 ASCII string */ public static String fromBase10(final long base10) { @@ -42,8 +41,7 @@ public final class Base62Util { } /** - * @param base62 - * number + * @param base62 number * @return converted number into Base10 */ public static Long toBase10(final String base62) { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/HostnameResolver.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/HostnameResolver.java index 05c0fdcc2..bf4e63152 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/HostnameResolver.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/HostnameResolver.java @@ -13,7 +13,6 @@ import java.net.URL; /** * Resolve to reach the server url. - * */ @FunctionalInterface public interface HostnameResolver { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java index be04d9b9a..e7b7f4359 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java @@ -28,19 +28,18 @@ import org.springframework.util.StringUtils; /** * Implementation for ArtifactUrlHandler for creating urls to download resource * based on patterns configured by {@link ArtifactUrlHandlerProperties}. - * + * * This mechanism can be used to generate links to arbitrary file hosting * infrastructure. However, the hawkBit update server supports hosting files as * well in the following {@link UrlProtocol#getRef()} patterns: - * + * * Default: * {protocol}://{hostname}:{port}{contextPath}/{tenant}/controller/v1/{controllerId}/ * softwaremodules/{softwareModuleId}/artifacts/{artifactFileName} - * + * * Default (MD5SUM files): * {protocol}://{hostname}:{port}{contextPath}/{tenant}/controller/v1/{controllerId}/ * softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}.MD5SUM - * */ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { @@ -64,16 +63,13 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { private static final String TENANT_ID_BASE10_PLACEHOLDER = "tenantId"; private static final String TENANT_ID_BASE62_PLACEHOLDER = "tenantIdBase62"; private static final String SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER = "softwareModuleId"; - private static final String SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER = "softwareModuleIdBase62"; - final static String DEFAULT_URL_PROTOCOL_REF = "{" + PROTOCOL_PLACEHOLDER + "}://{" + HOSTNAME_PLACEHOLDER + "}:{" + PORT_PLACEHOLDER + "}{" + CONTEXT_PATH + "}/{" + TENANT_PLACEHOLDER + "}/controller/v1/{" + CONTROLLER_ID_PLACEHOLDER + "}/softwaremodules/{" + SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER + "}/artifacts/{" + ARTIFACT_FILENAME_PLACEHOLDER + "}"; - + private static final String SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER = "softwareModuleIdBase62"; private final ArtifactUrlHandlerProperties urlHandlerProperties; private final String contextPath; /** - * @param urlHandlerProperties - * for URL generation configuration + * @param urlHandlerProperties for URL generation configuration */ public PropertyBasedArtifactUrlHandler(final ArtifactUrlHandlerProperties urlHandlerProperties, final String contextPath) { this.urlHandlerProperties = urlHandlerProperties; @@ -95,64 +91,6 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { } - private String generateUrl(final UrlProtocol protocol, final URLPlaceholder placeholder, - final URI requestUri) { - final Set> entrySet = getReplaceMap(protocol, placeholder, requestUri).entrySet(); - - String urlPattern = protocol.getRef(); - - for (final Entry entry : entrySet) { - if (List.of(PORT_PLACEHOLDER,PORT_REQUEST_PLACEHOLDER).contains(entry.getKey())) { - urlPattern = urlPattern.replace(":{" + entry.getKey() + "}", - ObjectUtils.isEmpty(entry.getValue()) ? "" : (":" + entry.getValue())); - } else { - if(entry.getValue() != null) { - urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue()); - } - } - } - - return urlPattern; - } - - private Map getReplaceMap(final UrlProtocol protocol, final URLPlaceholder placeholder, - final URI requestUri) { - final Map replaceMap = new HashMap<>(); - replaceMap.put(IP_PLACEHOLDER, protocol.getIp()); - - replaceMap.put(HOSTNAME_PLACEHOLDER, protocol.getHostname()); - - replaceMap.put(HOSTNAME_REQUEST_PLACEHOLDER, getRequestHost(protocol, requestUri)); - replaceMap.put(PORT_REQUEST_PLACEHOLDER, getRequestPort(protocol, requestUri)); - replaceMap.put(HOSTNAME_WITH_DOMAIN_REQUEST_PLACEHOLDER, computeHostWithRequestDomain(protocol, requestUri)); - replaceMap.put(PROTOCOL_REQUEST_PLACEHOLDER, getRequestProtocol(protocol, requestUri)); - - replaceMap.put(CONTEXT_PATH, contextPath); - - replaceMap.put(ARTIFACT_FILENAME_PLACEHOLDER, - URLEncoder.encode(placeholder.getSoftwareData().getFilename(), StandardCharsets.UTF_8)); - - replaceMap.put(ARTIFACT_SHA1_PLACEHOLDER, placeholder.getSoftwareData().getSha1Hash()); - replaceMap.put(PROTOCOL_PLACEHOLDER, protocol.getProtocol()); - replaceMap.put(PORT_PLACEHOLDER, getPort(protocol)); - replaceMap.put(TENANT_PLACEHOLDER, placeholder.getTenant()); - replaceMap.put(TENANT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTenantId())); - replaceMap.put(TENANT_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTenantId())); - replaceMap.put(CONTROLLER_ID_PLACEHOLDER, placeholder.getControllerId()); - replaceMap.put(TARGET_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTargetId())); - if (placeholder.getTargetId() != null) { - replaceMap.put(TARGET_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTargetId())); - } - replaceMap.put(ARTIFACT_ID_BASE62_PLACEHOLDER, - Base62Util.fromBase10(placeholder.getSoftwareData().getArtifactId())); - replaceMap.put(ARTIFACT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getSoftwareData().getArtifactId())); - replaceMap.put(SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER, - String.valueOf(placeholder.getSoftwareData().getSoftwareModuleId())); - replaceMap.put(SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER, - Base62Util.fromBase10(placeholder.getSoftwareData().getSoftwareModuleId())); - return replaceMap; - } - private static String getRequestPort(final UrlProtocol protocol, final URI requestUri) { if (requestUri == null) { return getPort(protocol); @@ -205,4 +143,62 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { return host + "." + domain; } + private String generateUrl(final UrlProtocol protocol, final URLPlaceholder placeholder, + final URI requestUri) { + final Set> entrySet = getReplaceMap(protocol, placeholder, requestUri).entrySet(); + + String urlPattern = protocol.getRef(); + + for (final Entry entry : entrySet) { + if (List.of(PORT_PLACEHOLDER, PORT_REQUEST_PLACEHOLDER).contains(entry.getKey())) { + urlPattern = urlPattern.replace(":{" + entry.getKey() + "}", + ObjectUtils.isEmpty(entry.getValue()) ? "" : (":" + entry.getValue())); + } else { + if (entry.getValue() != null) { + urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue()); + } + } + } + + return urlPattern; + } + + private Map getReplaceMap(final UrlProtocol protocol, final URLPlaceholder placeholder, + final URI requestUri) { + final Map replaceMap = new HashMap<>(); + replaceMap.put(IP_PLACEHOLDER, protocol.getIp()); + + replaceMap.put(HOSTNAME_PLACEHOLDER, protocol.getHostname()); + + replaceMap.put(HOSTNAME_REQUEST_PLACEHOLDER, getRequestHost(protocol, requestUri)); + replaceMap.put(PORT_REQUEST_PLACEHOLDER, getRequestPort(protocol, requestUri)); + replaceMap.put(HOSTNAME_WITH_DOMAIN_REQUEST_PLACEHOLDER, computeHostWithRequestDomain(protocol, requestUri)); + replaceMap.put(PROTOCOL_REQUEST_PLACEHOLDER, getRequestProtocol(protocol, requestUri)); + + replaceMap.put(CONTEXT_PATH, contextPath); + + replaceMap.put(ARTIFACT_FILENAME_PLACEHOLDER, + URLEncoder.encode(placeholder.getSoftwareData().getFilename(), StandardCharsets.UTF_8)); + + replaceMap.put(ARTIFACT_SHA1_PLACEHOLDER, placeholder.getSoftwareData().getSha1Hash()); + replaceMap.put(PROTOCOL_PLACEHOLDER, protocol.getProtocol()); + replaceMap.put(PORT_PLACEHOLDER, getPort(protocol)); + replaceMap.put(TENANT_PLACEHOLDER, placeholder.getTenant()); + replaceMap.put(TENANT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTenantId())); + replaceMap.put(TENANT_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTenantId())); + replaceMap.put(CONTROLLER_ID_PLACEHOLDER, placeholder.getControllerId()); + replaceMap.put(TARGET_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTargetId())); + if (placeholder.getTargetId() != null) { + replaceMap.put(TARGET_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTargetId())); + } + replaceMap.put(ARTIFACT_ID_BASE62_PLACEHOLDER, + Base62Util.fromBase10(placeholder.getSoftwareData().getArtifactId())); + replaceMap.put(ARTIFACT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getSoftwareData().getArtifactId())); + replaceMap.put(SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER, + String.valueOf(placeholder.getSoftwareData().getSoftwareModuleId())); + replaceMap.put(SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER, + Base62Util.fromBase10(placeholder.getSoftwareData().getSoftwareModuleId())); + return replaceMap; + } + } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/URLPlaceholder.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/URLPlaceholder.java index d6fe0c319..b56926423 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/URLPlaceholder.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/URLPlaceholder.java @@ -11,8 +11,6 @@ package org.eclipse.hawkbit.api; import lombok.Data; -import java.util.Objects; - /** * Container for variables available to the {@link ArtifactUrlHandler}. */ @@ -27,18 +25,13 @@ public class URLPlaceholder { /** * Constructor. - * - * @param tenant - * of the client - * @param tenantId - * of teh tenant - * @param controllerId - * of the target - * @param targetId - * of the target - * @param softwareData - * information about the artifact and software module that can be - * accessed by the URL. + * + * @param tenant of the client + * @param tenantId of teh tenant + * @param controllerId of the target + * @param targetId of the target + * @param softwareData information about the artifact and software module that can be + * accessed by the URL. */ public URLPlaceholder(final String tenant, final Long tenantId, final String controllerId, final Long targetId, final SoftwareData softwareData) { @@ -64,14 +57,10 @@ public class URLPlaceholder { /** * Constructor. * - * @param softwareModuleId - * of the module the artifact belongs to - * @param filename - * of the artifact - * @param artifactId - * of the artifact - * @param sha1Hash - * of the artifact + * @param softwareModuleId of the module the artifact belongs to + * @param filename of the artifact + * @param artifactId of the artifact + * @param sha1Hash of the artifact */ public SoftwareData(final Long softwareModuleId, final String filename, final Long artifactId, final String sha1Hash) { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java index e171b250d..f72cd670f 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java @@ -83,19 +83,8 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository { } } - private AbstractDbArtifact addMissingHashes(final AbstractDbArtifact existing, final String calculatedSha1, - final String calculatedMd5, final String calculatedSha256) { - - final String sha1 = checkEmpty(existing.getHashes().getSha1(), calculatedSha1); - final String md5 = checkEmpty(existing.getHashes().getMd5(), calculatedMd5); - final String sha256 = checkEmpty(existing.getHashes().getSha256(), calculatedSha256); - - existing.setHashes(new DbArtifactHash(sha1, md5, sha256)); - return existing; - } - - private String checkEmpty(final String value, final String fallback) { - return StringUtils.isEmpty(value) ? fallback : value; + protected static String sanitizeTenant(final String tenant) { + return tenant.trim().toUpperCase(); } protected void deleteTempFile(final String tempFile) { @@ -116,6 +105,9 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository { return file.getPath(); } + protected abstract AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, + final String contentType, final String tempFile) throws IOException; + private static File createTempFile() { try { return Files.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX).toFile(); @@ -149,15 +141,23 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository { return providedHashValue != null && !hashValue.equals(providedHashValue); } - protected abstract AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, - final String contentType, final String tempFile) throws IOException; - private static DigestInputStream wrapInDigestInputStream(final InputStream input, final MessageDigest mdSHA1, final MessageDigest mdMD5, final MessageDigest mdSHA256) { return new DigestInputStream(new DigestInputStream(new DigestInputStream(input, mdSHA256), mdMD5), mdSHA1); } - protected static String sanitizeTenant(final String tenant) { - return tenant.trim().toUpperCase(); + private AbstractDbArtifact addMissingHashes(final AbstractDbArtifact existing, final String calculatedSha1, + final String calculatedMd5, final String calculatedSha256) { + + final String sha1 = checkEmpty(existing.getHashes().getSha1(), calculatedSha1); + final String md5 = checkEmpty(existing.getHashes().getMd5(), calculatedMd5); + final String sha256 = checkEmpty(existing.getHashes().getSha256(), calculatedSha256); + + existing.setHashes(new DbArtifactHash(sha1, md5, sha256)); + return existing; + } + + private String checkEmpty(final String value, final String fallback) { + return StringUtils.isEmpty(value) ? fallback : value; } } \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactRepository.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactRepository.java index 4ba47b0ab..2934df0d5 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactRepository.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactRepository.java @@ -19,81 +19,58 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; /** * ArtifactRepository service interface. - * - * - * */ public interface ArtifactRepository { + /** * Stores an artifact into the repository. - * - * @param tenant - * the tenant to store the artifact - * @param content - * the content to store - * @param filename - * the filename of the artifact - * @param contentType - * the content type of the artifact - * @param hash - * the hashes of the artifact to do hash-checks after storing the - * artifact, might be {@code null} + * + * @param tenant the tenant to store the artifact + * @param content the content to store + * @param filename the filename of the artifact + * @param contentType the content type of the artifact + * @param hash the hashes of the artifact to do hash-checks after storing the + * artifact, might be {@code null} * @return the stored artifact - * - * @throws MethodNotSupportedException - * if implementation does not support the operation - * @throws ArtifactStoreException - * in case storing of the artifact was not successful - * @throws HashNotMatchException - * in case {@code hash} is provided and not matching to the - * calculated hashes during storing + * @throws MethodNotSupportedException if implementation does not support the operation + * @throws ArtifactStoreException in case storing of the artifact was not successful + * @throws HashNotMatchException in case {@code hash} is provided and not matching to the + * calculated hashes during storing */ AbstractDbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename, String contentType, DbArtifactHash hash); /** * Deletes an artifact by its SHA1 hash. - * - * @param tenant - * the tenant to store the artifact - * @param sha1Hash - * the sha1-hash of the artifact to delete - * - * @throws MethodNotSupportedException - * if implementation does not support the operation + * + * @param tenant the tenant to store the artifact + * @param sha1Hash the sha1-hash of the artifact to delete + * @throws MethodNotSupportedException if implementation does not support the operation */ void deleteBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash); /** * Retrieves a {@link AbstractDbArtifact} from the store by its SHA1 hash. - * - * @param tenant - * the tenant to store the artifact - * @param sha1Hash - * the sha1-hash of the file to lookup. + * + * @param tenant the tenant to store the artifact + * @param sha1Hash the sha1-hash of the file to lookup. * @return The artifact file object or {@code null} if no file exists. - * - * @throws MethodNotSupportedException - * if implementation does not support the operation + * @throws MethodNotSupportedException if implementation does not support the operation */ AbstractDbArtifact getArtifactBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash); /** * Deletes all artifacts of given tenant. - * - * @param tenant - * to erase + * + * @param tenant to erase */ void deleteByTenant(@NotEmpty String tenant); /** * Checks if an artifact exists for a given tenant by its sha1 hash * - * @param tenant - * the tenant - * @param sha1Hash - * the sha1-hash of the file to lookup. - * + * @param tenant the tenant + * @param sha1Hash the sha1-hash of the file to lookup. * @return the boolean whether the artifact exists or not */ boolean existsByTenantAndSha1(@NotEmpty String tenant, @NotEmpty String sha1Hash); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreException.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreException.java index ea26ceab8..64f584662 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreException.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreException.java @@ -19,11 +19,9 @@ public class ArtifactStoreException extends RuntimeException { /** * Constructs a ArtifactStoreException with message and cause. - * - * @param message - * the message of the exception - * @param cause - * of the exception + * + * @param message the message of the exception + * @param cause of the exception */ public ArtifactStoreException(final String message, final Throwable cause) { super(message, cause); @@ -31,9 +29,8 @@ public class ArtifactStoreException extends RuntimeException { /** * Constructs a ArtifactStoreException with message. - * - * @param message - * the message of the exception + * + * @param message the message of the exception */ public ArtifactStoreException(final String message) { super(message); @@ -41,9 +38,8 @@ public class ArtifactStoreException extends RuntimeException { /** * Constructs a ArtifactStoreException with cause. - * - * @param cause - * of the exception + * + * @param cause of the exception */ public ArtifactStoreException(final Throwable cause) { super(cause); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/HashNotMatchException.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/HashNotMatchException.java index e455b03f8..f2985c0db 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/HashNotMatchException.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/HashNotMatchException.java @@ -12,29 +12,21 @@ package org.eclipse.hawkbit.artifact.repository; /** * Thrown when provided hashes and hashes caluclated during storing are not * matching. - * - * - * */ public class HashNotMatchException extends RuntimeException { - private static final long serialVersionUID = 1L; - public static final String SHA1 = "SHA-1"; public static final String MD5 = "MD5"; public static final String SHA256 = "SHA-256"; - + private static final long serialVersionUID = 1L; private final String hashFunction; /** * Constructs a HashNotMatchException with message and cause. - * - * @param message - * the message of the exception - * @param cause - * the cause of the exception - * @param hashFunction - * the hash function which caused this exception + * + * @param message the message of the exception + * @param cause the cause of the exception + * @param hashFunction the hash function which caused this exception */ public HashNotMatchException(final String message, final Throwable cause, final String hashFunction) { super(message, cause); @@ -43,11 +35,9 @@ public class HashNotMatchException extends RuntimeException { /** * Constructs a HashNotMatchException with message. - * - * @param message - * the message of the exception - * @param hashFunction - * the hash function which caused this exception + * + * @param message the message of the exception + * @param hashFunction the hash function which caused this exception */ public HashNotMatchException(final String message, final String hashFunction) { super(message); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java index b6318dfbf..076c5d446 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifact.java @@ -39,7 +39,7 @@ public interface DbArtifact { /** * Creates an {@link InputStream} on this artifact. Caller has to take care of * closing the stream. Repeatable calls open a new {@link InputStream}. - * + * * @return {@link InputStream} to read from artifact. */ InputStream getFileInputStream(); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java index 59d9e0272..ff3336081 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/DbArtifactHash.java @@ -23,7 +23,7 @@ public class DbArtifactHash { /** * Constructor. - * + * * @param sha1 the sha1 hash * @param md5 the md5 hash * @param sha256 the sha256 hash diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java index 4ccdf06cc..38b79b9ce 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java @@ -22,8 +22,7 @@ public interface TenancyCacheManager extends CacheManager { * tenant key. This is necessary e.g. for retrieving caches not for the * current tenant. * - * @param name - * the name of the cache to retrieve directly + * @param name the name of the cache to retrieve directly * @return the cache associated with the name without tenancy separation */ Cache getDirectCache(String name); @@ -32,8 +31,7 @@ public interface TenancyCacheManager extends CacheManager { * Evicts all caches for a given tenant. All caches under a certain tenant * gets evicted. * - * @param tenant - * the tenant to evict caches + * @param tenant the tenant to evict caches */ void evictCaches(final String tenant); } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java index dcf81f576..89ab0014f 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java @@ -38,10 +38,8 @@ public class TenantAwareCacheManager implements TenancyCacheManager { /** * Constructor. * - * @param delegate - * the {@link CacheManager} to delegate to. - * @param tenantAware - * the tenant aware to retrieve the current tenant + * @param delegate the {@link CacheManager} to delegate to. + * @param tenantAware the tenant aware to retrieve the current tenant */ public TenantAwareCacheManager(final CacheManager delegate, final TenantAware tenantAware) { this.tenantAware = tenantAware; diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/AbstractServerRtException.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/AbstractServerRtException.java index b86cf567f..9506bc50e 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/AbstractServerRtException.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/AbstractServerRtException.java @@ -9,12 +9,12 @@ */ package org.eclipse.hawkbit.exception; -import lombok.Data; -import lombok.EqualsAndHashCode; - import java.io.Serial; import java.util.Map; +import lombok.Data; +import lombok.EqualsAndHashCode; + /** * Generic Custom Exception to wrap the Runtime and checked exception */ @@ -30,7 +30,7 @@ public abstract class AbstractServerRtException extends RuntimeException { /** * Parameterized constructor. - * + * * @param error detail */ protected AbstractServerRtException(final SpServerError error) { @@ -41,7 +41,7 @@ public abstract class AbstractServerRtException extends RuntimeException { /** * Parameterized constructor. - * + * * @param message custom error message * @param error detail */ @@ -63,7 +63,7 @@ public abstract class AbstractServerRtException extends RuntimeException { /** * Parameterized constructor. - * + * * @param message custom error message * @param error detail * @param cause of the exception @@ -76,7 +76,7 @@ public abstract class AbstractServerRtException extends RuntimeException { /** * Parameterized constructor. - * + * * @param error detail * @param cause of the exception */ @@ -93,7 +93,8 @@ public abstract class AbstractServerRtException extends RuntimeException { * @param error detail * @param cause of the exception */ - protected AbstractServerRtException(final String message, final SpServerError error, final Throwable cause, final Map info) { + protected AbstractServerRtException(final String message, final SpServerError error, final Throwable cause, + final Map info) { super(message, cause); this.error = error; this.info = info; diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/GenericSpServerException.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/GenericSpServerException.java index 50123cec2..a5d5f3b9d 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/GenericSpServerException.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/GenericSpServerException.java @@ -13,11 +13,9 @@ package org.eclipse.hawkbit.exception; * {@link GenericSpServerException} is thrown when a given entity in's actual * and cannot be stored within the current session. Reason could be that it has * been changed within another session. - * - * - * */ public class GenericSpServerException extends AbstractServerRtException { + private static final long serialVersionUID = 1L; private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_GENERIC_ERROR; @@ -30,9 +28,8 @@ public class GenericSpServerException extends AbstractServerRtException { /** * Parameterized constructor. - * - * @param cause - * of the exception + * + * @param cause of the exception */ public GenericSpServerException(final Throwable cause) { super(THIS_ERROR, cause); @@ -40,11 +37,9 @@ public class GenericSpServerException extends AbstractServerRtException { /** * Parameterized constructor. - * - * @param message - * custom error message - * @param cause - * of the exception + * + * @param message custom error message + * @param cause of the exception */ public GenericSpServerException(final String message, final Throwable cause) { super(message, THIS_ERROR, cause); @@ -52,9 +47,8 @@ public class GenericSpServerException extends AbstractServerRtException { /** * Parameterized constructor. - * - * @param message - * custom error message + * + * @param message custom error message */ public GenericSpServerException(final String message) { super(message, THIS_ERROR); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java index 66b93219a..83cbd7273 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java @@ -15,14 +15,13 @@ package org.eclipse.hawkbit.exception; public enum SpServerError { - SP_REPO_GENERIC_ERROR("hawkbit.server.error.repo.genericError", "unknown error occurred"), SP_REPO_ENTITY_ALREADY_EXISTS("hawkbit.server.error.repo.entitiyAlreayExists", - "The given entity already exists in database"), + "The given entity already exists in database"), SP_REPO_AUTO_CONFIRMATION_ALREADY_ACTIVE("hawkbit.server.error.repo.autoConfAlreadyActive", - "Auto confirmation is already active"), + "Auto confirmation is already active"), SP_CONFIRMATION_FEEDBACK_INVALID("hawkbit.server.confirmation.feedback.invalid", - "Confirmation feedback is not valid"), + "Confirmation feedback is not valid"), SP_REPO_CONSTRAINT_VIOLATION("hawkbit.server.error.repo.constraintViolation", "The given entity cannot be saved due to Constraint Violation"), SP_REPO_INVALID_TARGET_ADDRESS("hawkbit.server.error.repo.invalidTargetAddress", diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java index 58f1682e4..3dfabb53b 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java @@ -9,11 +9,11 @@ */ package org.eclipse.hawkbit.repository; -import lombok.Getter; - import java.util.Collections; import java.util.List; +import lombok.Getter; + /** * Sort and search fields for actions. */ diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java index b1a403587..7259c3a03 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java @@ -9,14 +9,14 @@ */ package org.eclipse.hawkbit.repository; -import lombok.Getter; - import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Collections; import java.util.List; import java.util.Map.Entry; import java.util.Optional; +import lombok.Getter; + /** * Describing the fields of the DistributionSet model which can be used in the * REST API e.g. for sorting etc. diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java index c40321666..ab936e920 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java @@ -9,11 +9,11 @@ */ package org.eclipse.hawkbit.repository; -import lombok.Getter; - import java.util.Collections; import java.util.List; +import lombok.Getter; + /** * Describing the fields of the Tag model which can be used in the REST API e.g. * for sorting etc. @@ -23,23 +23,23 @@ import java.util.List; @Getter public enum DistributionSetTagFields implements RsqlQueryField { - ID(TagFields.ID.getJpaEntityFieldName()), - NAME(TagFields.NAME.getJpaEntityFieldName()), - DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()), - COLOUR(TagFields.COLOUR.getJpaEntityFieldName()), - DISTRIBUTIONSET("assignedToDistributionSet", - DistributionSetFields.ID.getJpaEntityFieldName(), DistributionSetFields.NAME.getJpaEntityFieldName()); + ID(TagFields.ID.getJpaEntityFieldName()), + NAME(TagFields.NAME.getJpaEntityFieldName()), + DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()), + COLOUR(TagFields.COLOUR.getJpaEntityFieldName()), + DISTRIBUTIONSET("assignedToDistributionSet", + DistributionSetFields.ID.getJpaEntityFieldName(), DistributionSetFields.NAME.getJpaEntityFieldName()); - private final String jpaEntityFieldName; - private final List subEntityAttributes; + private final String jpaEntityFieldName; + private final List subEntityAttributes; - DistributionSetTagFields(final String jpaEntityFieldName) { - this.jpaEntityFieldName = jpaEntityFieldName; - this.subEntityAttributes = Collections.emptyList(); - } + DistributionSetTagFields(final String jpaEntityFieldName) { + this.jpaEntityFieldName = jpaEntityFieldName; + this.subEntityAttributes = Collections.emptyList(); + } - DistributionSetTagFields(final String jpaEntityFieldName, final String... subEntityAttributes) { - this.jpaEntityFieldName = jpaEntityFieldName; - this.subEntityAttributes = List.of(subEntityAttributes); - } + DistributionSetTagFields(final String jpaEntityFieldName, final String... subEntityAttributes) { + this.jpaEntityFieldName = jpaEntityFieldName; + this.subEntityAttributes = List.of(subEntityAttributes); + } } \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java index f45850b4c..13ac58a94 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java @@ -23,7 +23,7 @@ public interface FieldValueConverter> { /** * Converts the given {@code value} into the representation to build a * generic query. - * + * * @param e the enum to build the value for * @param value the value in string representation * @return the converted object or {@code null} if conversation fails, if @@ -34,7 +34,7 @@ public interface FieldValueConverter> { /** * returns the possible values associated with the given enum type. - * + * * @param e the enum type to retrieve the possible values * @return the possible values for a specific enum or {@code null} */ diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java index 4c5157e29..d13676a71 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java @@ -9,11 +9,11 @@ */ package org.eclipse.hawkbit.repository; -import lombok.Getter; - import java.util.Collections; import java.util.List; +import lombok.Getter; + /** * Describing the fields of the Rollout model which can be used in the REST API e.g. for sorting etc. */ diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RsqlQueryField.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RsqlQueryField.java index 6d9d972d1..031e375c2 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RsqlQueryField.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RsqlQueryField.java @@ -16,7 +16,6 @@ import java.util.Map.Entry; import java.util.Optional; import jakarta.validation.constraints.NotNull; -import org.springframework.util.ObjectUtils; /** * An RSQL query field interface extended by all the fields that could be used in RSQL queries. diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java index 437979404..ed73a50cb 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java @@ -9,14 +9,14 @@ */ package org.eclipse.hawkbit.repository; -import lombok.Getter; - import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Collections; import java.util.List; import java.util.Map.Entry; import java.util.Optional; +import lombok.Getter; + /** * Describing the fields of the SoftwareModule model which can be used in the REST API e.g. for sorting etc. */ @@ -41,6 +41,7 @@ public enum SoftwareModuleFields implements RsqlQueryField { SoftwareModuleFields(final String jpaEntityFieldName, final String... subEntityAttributes) { this(jpaEntityFieldName, List.of(subEntityAttributes), null); } + SoftwareModuleFields(final String jpaEntityFieldName, final Entry subEntityMapTuple) { this(jpaEntityFieldName, Collections.emptyList(), subEntityMapTuple); } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java index 1a24f838f..2489117ac 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java @@ -9,14 +9,14 @@ */ package org.eclipse.hawkbit.repository; -import lombok.Getter; - import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Collections; import java.util.List; import java.util.Map.Entry; import java.util.Optional; +import lombok.Getter; + /** * Describing the fields of the Target model which can be used in the REST API * e.g. for sorting etc. diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java index c07d81dab..64a1a9257 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java @@ -9,11 +9,11 @@ */ package org.eclipse.hawkbit.repository; -import lombok.Getter; - import java.util.Collections; import java.util.List; +import lombok.Getter; + /** * Describing the fields of the Target model which can be used in the REST API e.g. for sorting etc. */ diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java index efc3887e3..b2ac7b1c9 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java @@ -18,14 +18,14 @@ import lombok.Getter; @Getter public enum TargetTagFields implements RsqlQueryField { - ID(TagFields.ID.getJpaEntityFieldName()), - NAME(TagFields.NAME.getJpaEntityFieldName()), - DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()), - COLOUR(TagFields.COLOUR.getJpaEntityFieldName()); + ID(TagFields.ID.getJpaEntityFieldName()), + NAME(TagFields.NAME.getJpaEntityFieldName()), + DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()), + COLOUR(TagFields.COLOUR.getJpaEntityFieldName()); - private final String jpaEntityFieldName; + private final String jpaEntityFieldName; - TargetTagFields(final String jpaEntityFieldName) { - this.jpaEntityFieldName = jpaEntityFieldName; - } + TargetTagFields(final String jpaEntityFieldName) { + this.jpaEntityFieldName = jpaEntityFieldName; + } } \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAware.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAware.java index ca4246266..80278be96 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAware.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAware.java @@ -34,11 +34,9 @@ public interface TenantAware { * {@link TenantRunner} it must be ensured that the original tenant before * this invocation is reset. * - * @param tenant - * the tenant which the specific code should run - * @param tenantRunner - * the runner which is implemented to run this specific code - * under the given tenant + * @param tenant the tenant which the specific code should run + * @param tenantRunner the runner which is implemented to run this specific code + * under the given tenant * @return the return type of the {@link TenantRunner} */ T runAsTenant(String tenant, TenantRunner tenantRunner); @@ -50,13 +48,10 @@ public interface TenantAware { * {@link TenantRunner} it must be ensured that the original tenant before * this invocation is reset. * - * @param tenant - * the tenant which the specific code should run with - * @param username - * the username which the specific code should run with - * @param tenantRunner - * the runner which is implemented to run this specific code - * under the given tenant + * @param tenant the tenant which the specific code should run with + * @param username the username which the specific code should run with + * @param tenantRunner the runner which is implemented to run this specific code + * under the given tenant * @return the return type of the {@link TenantRunner} */ T runAsTenantAsUser(String tenant, String username, TenantRunner tenantRunner); @@ -66,14 +61,11 @@ public interface TenantAware { * a given tenant by using the * {@link TenantAware#runAsTenant(String, TenantRunner)}. * - * - * - * - * @param - * the return type of the runner + * @param the return type of the runner */ @FunctionalInterface interface TenantRunner { + /** * Called to run specific code and a given tenant. * diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/UserAuthoritiesResolver.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/UserAuthoritiesResolver.java index 55a2bd564..cbd335383 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/UserAuthoritiesResolver.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/UserAuthoritiesResolver.java @@ -21,10 +21,8 @@ public interface UserAuthoritiesResolver { /** * User authorities/roles lookup based on the tenant and the username * - * @param tenant - * The tenant that this user belongs to - * @param username - * The username of the user + * @param tenant The tenant that this user belongs to + * @param username The username of the user * @return a {@link Collection} of authorities/roles for this user */ Collection getUserAuthorities(String tenant, String username); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/InvalidTenantConfigurationKeyException.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/InvalidTenantConfigurationKeyException.java index 05a40f3fa..735f46150 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/InvalidTenantConfigurationKeyException.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/InvalidTenantConfigurationKeyException.java @@ -15,7 +15,6 @@ import org.eclipse.hawkbit.exception.SpServerError; /** * The {@link #InvalidTenantConfigurationKeyException} is thrown when an invalid * configuration key is used. - * */ public class InvalidTenantConfigurationKeyException extends AbstractServerRtException { @@ -31,9 +30,8 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce /** * Parameterized constructor. - * - * @param cause - * of the exception + * + * @param cause of the exception */ public InvalidTenantConfigurationKeyException(final Throwable cause) { super(THIS_ERROR, cause); @@ -41,11 +39,9 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce /** * Parameterized constructor. - * - * @param message - * of the exception - * @param cause - * of the exception + * + * @param message of the exception + * @param cause of the exception */ public InvalidTenantConfigurationKeyException(final String message, final Throwable cause) { super(message, THIS_ERROR, cause); @@ -53,9 +49,8 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce /** * Parameterized constructor. - * - * @param message - * of the exception + * + * @param message of the exception */ public InvalidTenantConfigurationKeyException(final String message) { super(message, THIS_ERROR); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/validator/TenantConfigurationValidatorException.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/validator/TenantConfigurationValidatorException.java index 7ecd18adf..a43bc4d8c 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/validator/TenantConfigurationValidatorException.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/validator/TenantConfigurationValidatorException.java @@ -15,7 +15,6 @@ import org.eclipse.hawkbit.exception.SpServerError; /** * Exception which is thrown, when the validation of the configuration value has * not been successful. - * */ public class TenantConfigurationValidatorException extends AbstractServerRtException { @@ -31,9 +30,8 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep /** * Parameterized constructor. - * - * @param cause - * of the exception + * + * @param cause of the exception */ public TenantConfigurationValidatorException(final Throwable cause) { super(THIS_ERROR, cause); @@ -41,11 +39,9 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep /** * Parameterized constructor. - * - * @param message - * of the exception - * @param cause - * of the exception + * + * @param message of the exception + * @param cause of the exception */ public TenantConfigurationValidatorException(final String message, final Throwable cause) { super(message, THIS_ERROR, cause); @@ -53,9 +49,8 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep /** * Parameterized constructor. - * - * @param message - * of the exception + * + * @param message of the exception */ public TenantConfigurationValidatorException(final String message) { super(message, THIS_ERROR); diff --git a/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/Base62UtilTest.java b/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/Base62UtilTest.java index 174a5c8eb..eff988944 100644 --- a/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/Base62UtilTest.java +++ b/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/Base62UtilTest.java @@ -11,11 +11,10 @@ package org.eclipse.hawkbit.api; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.Test; - import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; +import org.junit.jupiter.api.Test; @Feature("Unit Tests - Artifact URL Handler") @Story("Base62 Utility tests") diff --git a/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandlerTest.java index 9c76e4b29..26cdbe93c 100644 --- a/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandlerTest.java @@ -13,18 +13,16 @@ import static org.assertj.core.api.Assertions.assertThat; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.List; +import io.qameta.allure.Description; +import io.qameta.allure.Feature; +import io.qameta.allure.Story; import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties.UrlProtocol; import org.eclipse.hawkbit.api.URLPlaceholder.SoftwareData; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - -import io.qameta.allure.Description; -import io.qameta.allure.Feature; -import io.qameta.allure.Story; import org.mockito.junit.jupiter.MockitoExtension; /** @@ -51,13 +49,10 @@ public class PropertyBasedArtifactUrlHandlerTest { private static final String TENANT = "TEST_TENANT"; private static final String HTTP_LOCALHOST = "http://localhost:8080/"; - - private ArtifactUrlHandler urlHandlerUnderTest; - - private ArtifactUrlHandlerProperties properties; - private static URLPlaceholder placeholder = new URLPlaceholder(TENANT, TENANT_ID, CONTROLLER_ID, TARGETID, new SoftwareData(SOFTWAREMODULEID, FILENAME_DECODE, ARTIFACTID, SHA1HASH)); + private ArtifactUrlHandler urlHandlerUnderTest; + private ArtifactUrlHandlerProperties properties; @BeforeEach public void setup() { @@ -142,6 +137,7 @@ public class PropertyBasedArtifactUrlHandlerTest { assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, TEST_PROTO + "://" + testHost + ":5683/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62)); } + @Test @Description("Verfies that the protocol of the statically defined hostname is replaced with the protocol of the request.") public void urlGenerationWithProtocolFromRequest() throws URISyntaxException { @@ -191,10 +187,10 @@ public class PropertyBasedArtifactUrlHandlerTest { proto.setProtocol(protocol); properties.getProtocols().put("download-http", proto); - URI uri = new URI(protocol+"://anotherHost.com"); + URI uri = new URI(protocol + "://anotherHost.com"); final List urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI, uri); assertThat(urls).containsExactly(new ArtifactUrl(protocol.toUpperCase(), "download-http", - uri +"/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/" + uri + "/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/" + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE)); } diff --git a/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/URLPlaceholderTest.java b/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/URLPlaceholderTest.java index c64c60be2..227539434 100644 --- a/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/URLPlaceholderTest.java +++ b/hawkbit-core/src/test/java/org/eclipse/hawkbit/api/URLPlaceholderTest.java @@ -11,11 +11,10 @@ package org.eclipse.hawkbit.api; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.Test; - import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; +import org.junit.jupiter.api.Test; @Feature("Unit Tests - Artifact URL Handler") @Story("URL placeholder tests") diff --git a/hawkbit-core/src/test/java/org/eclipse/hawkbit/repository/FileNameFieldsTest.java b/hawkbit-core/src/test/java/org/eclipse/hawkbit/repository/FileNameFieldsTest.java index bc48eed88..defbe68c2 100644 --- a/hawkbit-core/src/test/java/org/eclipse/hawkbit/repository/FileNameFieldsTest.java +++ b/hawkbit-core/src/test/java/org/eclipse/hawkbit/repository/FileNameFieldsTest.java @@ -9,16 +9,16 @@ */ package org.eclipse.hawkbit.repository; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + import io.github.classgraph.ClassGraph; import io.github.classgraph.ClassInfo; import io.github.classgraph.ScanResult; import io.qameta.allure.Description; import org.junit.jupiter.api.Test; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - public class FileNameFieldsTest { @Test