From f69d3866132cf79350b4de689c16a5caa75c82da Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Sat, 3 Feb 2024 04:46:24 +0200 Subject: [PATCH] Lombok/apply to security repo3 (#1594) * Improve Security Core with lombok (#1592) Add lombok to repository modules Signed-off-by: Marinov Avgustin * Improve Security Core with lombok 3 Signed-off-by: Marinov Avgustin --------- Signed-off-by: Marinov Avgustin --- .../org/eclipse/hawkbit/api/ArtifactUrl.java | 78 +-------------- .../api/ArtifactUrlHandlerProperties.java | 67 +------------ .../eclipse/hawkbit/api/URLPlaceholder.java | 96 ++----------------- .../AbstractArtifactRepository.java | 2 +- .../repository/model/AbstractDbArtifact.java | 35 +------ .../repository/model/DbArtifactHash.java | 27 ++---- .../hawkbit/cache/DefaultDownloadIdCache.java | 3 +- .../event/remote/MultiActionAssignEvent.java | 10 +- .../event/remote/MultiActionEvent.java | 14 ++- .../remote/RemoteTenantAwareEventTest.java | 17 ++-- 10 files changed, 42 insertions(+), 307 deletions(-) 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 5d73afa9c..edddf0404 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 @@ -9,10 +9,13 @@ */ package org.eclipse.hawkbit.api; +import lombok.Data; + /** * Container for a generated Artifact URL. * */ +@Data public class ArtifactUrl { private final String protocol; @@ -34,77 +37,4 @@ public class ArtifactUrl { this.rel = rel; this.ref = ref; } - - /** - * @return protocol name used in DMF API messages. - */ - public String getProtocol() { - return protocol; - } - - /** - * @return rel links value useful in hypermedia. - */ - public String getRel() { - return rel; - } - - /** - * @return generated artifact download URL - */ - public String getRef() { - return ref; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); - result = prime * result + ((ref == null) ? 0 : ref.hashCode()); - result = prime * result + ((rel == null) ? 0 : rel.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final ArtifactUrl other = (ArtifactUrl) obj; - if (protocol == null) { - if (other.protocol != null) { - return false; - } - } else if (!protocol.equals(other.protocol)) { - return false; - } - if (ref == null) { - if (other.ref != null) { - return false; - } - } else if (!ref.equals(other.ref)) { - return false; - } - if (rel == null) { - if (other.rel != null) { - return false; - } - } else if (!rel.equals(other.rel)) { - return false; - } - return true; - } - - @Override - public String toString() { - return "ArtifactUrl [protocol=" + protocol + ", rel=" + rel + ", ref=" + ref + "]"; - } - -} +} \ No newline at end of file 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 5a57e0970..2ca104cbf 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 @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -23,6 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * * @see PropertyBasedArtifactUrlHandler */ +@Data @ConfigurationProperties("hawkbit.artifact.url") public class ArtifactUrlHandlerProperties { @@ -31,13 +33,10 @@ public class ArtifactUrlHandlerProperties { */ private final Map protocols = new HashMap<>(); - public Map getProtocols() { - return protocols; - } - /** * Protocol specific properties to generate URLs accordingly. */ + @Data public static class UrlProtocol { private static final int DEFAULT_HTTP_PORT = 8080; @@ -85,68 +84,8 @@ public class ArtifactUrlHandlerProperties { */ private List supports = Arrays.asList(ApiType.DDI, ApiType.DMF, ApiType.MGMT); - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(final boolean enabled) { - this.enabled = enabled; - } - - public String getRel() { - return rel; - } - - public void setRel(final String rel) { - this.rel = rel; - } - - public String getRef() { - return ref; - } - - public void setRef(final String ref) { - this.ref = ref; - } - - public String getHostname() { - return hostname; - } - - public void setHostname(final String hostname) { - this.hostname = hostname; - } - - public String getIp() { - return ip; - } - - public void setIp(final String ip) { - this.ip = ip; - } - - public Integer getPort() { - return port; - } - - public void setPort(final Integer port) { - this.port = port; - } - - public List getSupports() { - return Collections.unmodifiableList(supports); - } - public void setSupports(final List supports) { this.supports = Collections.unmodifiableList(supports); } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(final String protocol) { - this.protocol = protocol; - } } } 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 be82ee715..56ad590bb 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 @@ -9,13 +9,16 @@ */ package org.eclipse.hawkbit.api; +import lombok.Data; + import java.util.Objects; /** * Container for variables available to the {@link ArtifactUrlHandler}. - * */ +@Data public class URLPlaceholder { + private final String tenant; private final Long tenantId; private final String controllerId; @@ -49,9 +52,10 @@ public class URLPlaceholder { /** * Information about the artifact and software module that can be accessed * by the URL. - * */ + @Data public static class SoftwareData { + private Long softwareModuleId; private String filename; private Long artifactId; @@ -59,7 +63,7 @@ public class URLPlaceholder { /** * Constructor. - * + * * @param softwareModuleId * of the module the artifact belongs to * @param filename @@ -76,91 +80,5 @@ public class URLPlaceholder { this.artifactId = artifactId; this.sha1Hash = sha1Hash; } - - public Long getSoftwareModuleId() { - return softwareModuleId; - } - - public void setSoftwareModuleId(final Long softwareModuleId) { - this.softwareModuleId = softwareModuleId; - } - - public String getFilename() { - return filename; - } - - public void setFilename(final String filename) { - this.filename = filename; - } - - public Long getArtifactId() { - return artifactId; - } - - public void setArtifactId(final Long artifactId) { - this.artifactId = artifactId; - } - - public String getSha1Hash() { - return sha1Hash; - } - - public void setSha1Hash(final String sha1Hash) { - this.sha1Hash = sha1Hash; - } - - @Override - public boolean equals(final Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - final SoftwareData that = (SoftwareData) o; - return Objects.equals(softwareModuleId, that.softwareModuleId) - && Objects.equals(filename, that.filename) - && Objects.equals(artifactId, that.artifactId) - && Objects.equals(sha1Hash, that.sha1Hash); - } - - @Override - public int hashCode() { - return Objects.hash(softwareModuleId, filename, artifactId, sha1Hash); - } - } - - public String getTenant() { - return tenant; - } - - public Long getTenantId() { - return tenantId; - } - - public String getControllerId() { - return controllerId; - } - - public Long getTargetId() { - return targetId; - } - - public SoftwareData getSoftwareData() { - return softwareData; - } - - @Override - public boolean equals(final Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - final URLPlaceholder that = (URLPlaceholder) o; - return tenantId.equals(that.tenantId) && Objects.equals(controllerId, that.controllerId) && Objects.equals( - targetId, that.targetId) && Objects.equals(softwareData, that.softwareData); - } - - @Override - public int hashCode() { - return Objects.hash(tenantId, controllerId, targetId, softwareData); } } 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 8ecc7890f..099ee6ad6 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 @@ -162,4 +162,4 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository { protected static String sanitizeTenant(final String tenant) { return tenant.trim().toUpperCase(); } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/AbstractDbArtifact.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/AbstractDbArtifact.java index e16730c16..61c474df2 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/AbstractDbArtifact.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/artifact/repository/model/AbstractDbArtifact.java @@ -9,12 +9,13 @@ */ package org.eclipse.hawkbit.artifact.repository.model; +import lombok.Data; import org.springframework.util.Assert; /** * Database representation of artifact. - * */ +@Data public abstract class AbstractDbArtifact implements DbArtifact { private final String artifactId; @@ -32,34 +33,4 @@ public abstract class AbstractDbArtifact implements DbArtifact { this.size = size; this.contentType = contentType; } - - @Override - public String getArtifactId() { - return artifactId; - } - - @Override - public DbArtifactHash getHashes() { - return hashes; - } - - /** - * Set hashes of the artifact - * - * @param hashes - * artifact hashes - */ - public void setHashes(final DbArtifactHash hashes) { - this.hashes = hashes; - } - - @Override - public long getSize() { - return size; - } - - @Override - public String getContentType() { - return contentType; - } -} +} \ No newline at end of file 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 70195649b..6f13d9213 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 @@ -9,43 +9,28 @@ */ package org.eclipse.hawkbit.artifact.repository.model; +import lombok.Data; + /** * Database representation of artifact hash. - * */ +@Data public class DbArtifactHash { private final String sha1; - private final String md5; - private final String sha256; /** * Constructor. * - * @param sha1 - * the sha1 hash - * @param md5 - * the md5 hash - * @param sha256 - * the sha256 hash + * @param sha1 the sha1 hash + * @param md5 the md5 hash + * @param sha256 the sha256 hash */ public DbArtifactHash(final String sha1, final String md5, final String sha256) { this.sha1 = sha1; this.md5 = md5; this.sha256 = sha256; } - - public String getSha1() { - return sha1; - } - - public String getMd5() { - return md5; - } - - public String getSha256() { - return sha256; - } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java index f08b09897..62e123ac4 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java @@ -26,8 +26,7 @@ public class DefaultDownloadIdCache implements DownloadIdCache { private final CacheManager cacheManager; /** - * @param cacheManager - * the underlying cache-manager to store the download-ids + * @param cacheManager the underlying cache-manager to store the download-ids */ public DefaultDownloadIdCache(final CacheManager cacheManager) { this.cacheManager = cacheManager; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionAssignEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionAssignEvent.java index a2affee83..d1d744c0c 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionAssignEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionAssignEvent.java @@ -9,6 +9,8 @@ */ package org.eclipse.hawkbit.repository.event.remote; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.eclipse.hawkbit.repository.model.Action; import java.util.List; @@ -20,17 +22,11 @@ import java.util.List; * actionIds containing the identifiers of the affected actions * as payload. This event is only published in case of an assignment. */ +@NoArgsConstructor(access = AccessLevel.PUBLIC) public class MultiActionAssignEvent extends MultiActionEvent { private static final long serialVersionUID = 1L; - /** - * Default constructor. - */ - public MultiActionAssignEvent() { - // for serialization libs like jackson - } - /** * Constructor. * diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionEvent.java index 5f45e969a..e5b98a696 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/MultiActionEvent.java @@ -1,11 +1,10 @@ /** - * Copyright (c) 2019 Bosch Software Innovations GmbH and others + * Copyright (c) 2019 Bosch Software Innovations GmbH and others. * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 + * 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.repository.event.remote; @@ -50,8 +49,7 @@ public abstract class MultiActionEvent extends RemoteTenantAwareEvent implements * @param actions * the actions involved */ - protected MultiActionEvent(String tenant, String applicationId, List actions) { - super(applicationId, tenant, applicationId); + protected MultiActionEvent(String tenant, String applicationId, List actions) {super(applicationId, tenant, applicationId); this.controllerIds.addAll(getControllerIdsFromActions(actions)); this.actionIds.addAll(getIdsFromActions(actions)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java index eaa3a7494..5229751bf 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java @@ -32,17 +32,8 @@ import io.qameta.allure.Story; public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest { private static final String TENANT_DEFAULT = "DEFAULT"; - private static final String APPLICATION_ID_DEFAULT = "Node"; - private Action createAction(final String controllerId) { - final JpaAction generateAction = new JpaAction(); - generateAction.setActionType(ActionType.FORCED); - generateAction.setTarget(testdataFactory.createTarget(controllerId)); - generateAction.setStatus(Status.RUNNING); - return generateAction; - } - @Test @Description("Verifies that a testMultiActionAssignEvent can be properly serialized and deserialized") public void testMultiActionAssignEvent() { @@ -62,6 +53,14 @@ public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest { assertThat(remoteAssignEventJackson.getControllerIds()).containsExactlyElementsOf(controllerIds); } + private Action createAction(final String controllerId) { + final JpaAction generateAction = new JpaAction(); + generateAction.setActionType(ActionType.FORCED); + generateAction.setTarget(testdataFactory.createTarget(controllerId)); + generateAction.setStatus(Status.RUNNING); + return generateAction; + } + @Test @Description("Verifies that a MultiActionCancelEvent can be properly serialized and deserialized") public void testMultiActionCancelEvent() {