From ac4dcc327db6673222f3b46cb877f85aada795fb Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 19 Dec 2024 11:19:20 +0200 Subject: [PATCH] Upgrades spring to 3.4.0 Signed-off-by: Avgustin Marinov --- .../RequestOnHawkbitDefaultPortPostProcessor.java | 2 -- .../AbstractManagementApiIntegrationTest.java | 3 +++ .../rest/resource/MgmtBasicAuthResourceTest.java | 5 +++-- .../hawkbit/repository/model/Artifact.java | 3 +-- .../jpa/management/JpaArtifactManagement.java | 2 +- .../management/OnlineDsAssignmentStrategy.java | 3 +-- .../hawkbit/repository/jpa/model/JpaAction.java | 8 +++++--- .../hawkbit/repository/jpa/model/JpaArtifact.java | 7 ++++++- .../jpa/repository/ActionRepository.java | 2 +- .../jpa/repository/LocalArtifactRepository.java | 2 +- .../jpa/repository/TargetRepository.java | 15 ++++++++------- .../jpa/autocleanup/AutoActionCleanupTest.java | 8 ++++---- .../jpa/management/ControllerManagementTest.java | 2 +- .../jpa/management/DeploymentManagementTest.java | 4 ++-- .../repository/jpa/rsql/RSQLActionFieldsTest.java | 3 +-- pom.xml | 8 ++++---- 16 files changed, 42 insertions(+), 35 deletions(-) diff --git a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java index 2c495902e0..dfd50e781e 100644 --- a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java +++ b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java @@ -11,13 +11,11 @@ import static org.eclipse.hawkbit.ddi.rest.resource.AbstractDDiApiIntegrationTest.HTTP_PORT; -import org.jetbrains.annotations.NotNull; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.web.servlet.request.RequestPostProcessor; public class RequestOnHawkbitDefaultPortPostProcessor implements RequestPostProcessor { - @NotNull @Override public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setRemotePort(HTTP_PORT); diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java index fc56227f73..c23ae29e90 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java @@ -13,6 +13,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import lombok.SneakyThrows; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; import org.eclipse.hawkbit.repository.jpa.Jpa; import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration; @@ -184,6 +185,7 @@ protected static ResultMatcher applySelfLinkMatcherOnSingleResult(final String l return mvcResult -> jsonPath("_links.self.href", equalTo(link)).match(mvcResult); } + @SneakyThrows protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type) { final JSONObject obj = new JSONObject(); obj.put("id", id); @@ -191,6 +193,7 @@ protected static JSONObject getAssignmentObject(final Object id, final MgmtActio return obj; } + @SneakyThrows protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type, final int weight) { return getAssignmentObject(id, type).put("weight", weight); } diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java index 87876627ef..0a7d7602cd 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java @@ -15,6 +15,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.Base64; + import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; @@ -46,7 +48,6 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.util.Base64Utils; import org.springframework.web.context.WebApplicationContext; /** @@ -105,7 +106,7 @@ public void validateBasicAuthFailsWithInvalidCredentials() throws Exception { } private String getBasicAuth(final String username, final String password) { - return "Basic " + Base64Utils.encodeToString((username + ":" + password).getBytes()); + return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); } private MockMvc withSecurityMock() throws Exception { diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index 1dc2b6fd28..91c40ec816 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -48,5 +48,4 @@ public interface Artifact extends TenantAwareBaseEntity { * @return size of the artifact in bytes. */ long getSize(); - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java index c4c7f3653f..ba8fd54942 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java @@ -317,7 +317,7 @@ private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, fina } artifact.setMd5Hash(result.getHashes().getMd5()); artifact.setSha256Hash(result.getHashes().getSha256()); - artifact.setSize(result.getSize()); + artifact.setFileSize(result.getSize()); log.debug("storing new artifact into repository {}", artifact); return localArtifactRepository.save(AccessController.Operation.CREATE, artifact); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java index 81d87cac43..bf89264826 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java @@ -132,8 +132,7 @@ public void setAssignedDistributionSetAndTargetStatus(final JpaDistributionSet s targetRepository.byIdsSpec(targetIdsChunk)) != targetIdsChunk.size()) { throw new InsufficientPermissionException("No update access to all targets!"); } - targetRepository.setAssignedDistributionSetAndUpdateStatus(TargetUpdateStatus.PENDING, - set, now, currentUser, targetIdsChunk); + targetRepository.setAssignedDistributionSetAndUpdateStatus(set, now, currentUser, TargetUpdateStatus.PENDING, targetIdsChunk); // TODO AC - current problem with this approach is that the caller detach the targets and seems doesn't save them // targetRepository.saveAll( // targetRepository diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java index e1e75585d3..cfb9f605dd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -67,9 +67,11 @@ @NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), @NamedEntityGraph(name = "Action.all", attributeNodes = { - @NamedAttributeNode("distributionSet"), - @NamedAttributeNode(value = "target", subgraph = "target.ds") }, - subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) + @NamedAttributeNode(value = "target", subgraph = "target.ds"), + @NamedAttributeNode("distributionSet") }, + subgraphs = @NamedSubgraph( + name = "target.ds", + attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) @Entity // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java index 33df233d5b..2854560c97 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java @@ -75,7 +75,7 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art private String sha256Hash; @Column(name = "file_size", updatable = false) - private long size; + private long fileSize; /** * Constructs artifact. @@ -90,4 +90,9 @@ public JpaArtifact(@NotEmpty final String sha1Hash, @NotNull final String filena this.softwareModule = (JpaSoftwareModule) softwareModule; this.softwareModule.addArtifact(this); } + + @Override + public long getSize() { + return getFileSize(); + } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java index 827f3a0647..c0dc2a4cef 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java @@ -44,7 +44,7 @@ public interface ActionRepository extends BaseEntityRepository { * @return the found {@link Action} */ @EntityGraph(value = "Action.all", type = EntityGraphType.LOAD) - Optional findWithDetailsById(Long actionId); + Optional findWithDetailsById(@Param("id") Long actionId); /** * Retrieves the latest finished {@link Action} for given target and {@link DistributionSet}. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java index 5ab376ac8c..e5b973508e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java @@ -31,7 +31,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository sumOfNonDeletedArtifactSize(); /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java index a731eea796..009c143afa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java @@ -50,10 +50,10 @@ default JpaTarget getByControllerId(final String controllerId) { @Deprecated(forRemoval = true) @Modifying @Transactional - @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :set, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") - void setAssignedDistributionSetAndUpdateStatus(@Param("status") TargetUpdateStatus status, - @Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt, - @Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection targets); + @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :dSet, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") + void setAssignedDistributionSetAndUpdateStatus( + @Param("dSet") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt, @Param("lastModifiedBy") String modifiedBy, @Param("status") TargetUpdateStatus status, + @Param("targets") Collection targets); // TODO AC - remove it and use specification @@ -64,9 +64,10 @@ void setAssignedDistributionSetAndUpdateStatus(@Param("status") TargetUpdateStat @Deprecated(forRemoval = true) @Modifying @Transactional - @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :set, t.installedDistributionSet = :set, t.installationDate = :lastModifiedAt, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") - void setAssignedAndInstalledDistributionSetAndUpdateStatus(@Param("status") TargetUpdateStatus status, - @Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt, + @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :dSet, t.installedDistributionSet = :dSet, t.installationDate = :lastModifiedAt, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") + void setAssignedAndInstalledDistributionSetAndUpdateStatus( + @Param("status") TargetUpdateStatus status, + @Param("dSet") JpaDistributionSet distributionSet, @Param("lastModifiedAt") Long modifiedAt, @Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection targets); /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java index 40fb9fac70..8f5148a95e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java @@ -114,7 +114,7 @@ void canceledAndFailedActionsAreCleanedUp() { autoActionCleanup.run(); assertThat(actionRepository.count()).isEqualTo(1); - assertThat(actionRepository.findWithDetailsById(action3)).isPresent(); + assertThat(actionRepository.findById(action3)).isPresent(); } @Test @@ -145,8 +145,8 @@ void canceledActionsAreCleanedUp() { autoActionCleanup.run(); assertThat(actionRepository.count()).isEqualTo(2); - assertThat(actionRepository.findWithDetailsById(action2)).isPresent(); - assertThat(actionRepository.findWithDetailsById(action3)).isPresent(); + assertThat(actionRepository.findById(action2)).isPresent(); + assertThat(actionRepository.findById(action3)).isPresent(); } @Test @@ -184,7 +184,7 @@ void canceledAndFailedActionsAreCleanedUpWhenExpired() throws InterruptedExcepti autoActionCleanup.run(); assertThat(actionRepository.count()).isEqualTo(1); - assertThat(actionRepository.findWithDetailsById(action3)).isPresent(); + assertThat(actionRepository.findById(action3)).isPresent(); } private void setActionToCanceled(final Long id) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java index ee26b51a97..09500c163e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java @@ -1879,7 +1879,7 @@ private void assertInstalledDistributionSetId(final String controllerId, final L } private void assertLastActionStatusCodeInAction(final Long actionId, final Integer expectedLastActionStatusCode) { - final Optional action = actionRepository.findWithDetailsById(actionId); + final Optional action = actionRepository.findById(actionId).map(Action.class::cast); assertThat(action).isPresent(); assertThat(action.get().getLastActionStatusCode()).isEqualTo(Optional.ofNullable(expectedLastActionStatusCode)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java index c18b42d964..8c7c85e3dc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java @@ -996,8 +996,8 @@ void weightValidatedAndSaved() { deploymentManagement.assignDistributionSets(Collections.singletonList(valideRequest1)).get(0)).getId(); final Long valideActionId2 = getFirstAssignedAction( deploymentManagement.assignDistributionSets(Collections.singletonList(valideRequest2)).get(0)).getId(); - assertThat(actionRepository.findWithDetailsById(valideActionId1).get().getWeight()).get().isEqualTo(Action.WEIGHT_MAX); - assertThat(actionRepository.findWithDetailsById(valideActionId2).get().getWeight()).get().isEqualTo(Action.WEIGHT_MIN); + assertThat(actionRepository.findById(valideActionId1).get().getWeight()).get().isEqualTo(Action.WEIGHT_MAX); + assertThat(actionRepository.findById(valideActionId2).get().getWeight()).get().isEqualTo(Action.WEIGHT_MIN); } /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java index d2f0e05d7a..dc2234dd83 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java @@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.data.domain.PageRequest; @@ -91,7 +90,7 @@ public void testFilterByParameterExtRef() { assertRSQLQuery(ActionFields.EXTERNALREF.name() + "==extRef*", 10); } - private @NotNull JpaAction newJpaAction(final DistributionSet dsA, final boolean active, final String extRef) { + private JpaAction newJpaAction(final DistributionSet dsA, final boolean active, final String extRef) { final JpaAction newAction = new JpaAction(); newAction.setActionType(ActionType.SOFT); newAction.setDistributionSet(dsA); diff --git a/pom.xml b/pom.xml index 5ac40120fa..e93d62511b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.5 + 3.4.0 org.eclipse.hawkbit @@ -40,9 +40,9 @@ true - 3.3.5 - 2023.0.2 - 2.6.0 + 3.4.0 + 2024.0.0 + 2.7.0 3.0.0