Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades spring to 3.4.0 #2154

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -184,13 +185,15 @@ 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);
obj.put("type", type.getName());
return obj;
}

@SneakyThrows
protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type, final int weight) {
return getAssignmentObject(id, type).put("weight", weight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,4 @@ MetaData generateTargetMetadata(@Size(min = 1, max = MetaData.KEY_MAX_SIZE) @Not
* @return {@link TargetFilterQueryBuilder} object
*/
TargetFilterQueryBuilder targetFilterQuery();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public interface Artifact extends TenantAwareBaseEntity {
* @return size of the artifact in bytes.
*/
long getSize();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,21 @@ public class JpaEntityFactory implements EntityFactory {

@Autowired
private DistributionSetBuilder distributionSetBuilder;

@Autowired
private TargetBuilder targetBuilder;

@Autowired
private DistributionSetTypeBuilder distributionSetTypeBuilder;

@Autowired
private SoftwareModuleBuilder softwareModuleBuilder;

@Autowired
private RolloutBuilder rolloutBuilder;

@Autowired
private TargetFilterQueryBuilder targetFilterQueryBuilder;

@Autowired
private SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder;

@Autowired
private TargetTypeBuilder targetTypeBuilder;

@Override
public ActionStatusBuilder actionStatus() {
return new JpaActionStatusBuilder();
Expand Down Expand Up @@ -132,5 +125,4 @@ public TargetTypeBuilder targetType() {
public TargetFilterQueryBuilder targetFilterQuery() {
return targetFilterQueryBuilder;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Size;

Expand All @@ -33,7 +33,8 @@
@Table(name = "sp_target_conf_status")
public class JpaAutoConfirmationStatus extends AbstractJpaTenantAwareBaseEntity implements AutoConfirmationStatus {

@OneToOne(optional = false, fetch = FetchType.LAZY)
// actually it is OneToOne - but lazy loading is not supported for OneToOne (at least for hibernate 6.6.2)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "target_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_auto_conf"))
private JpaTarget target;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapKeyColumn;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.PrimaryKeyJoinColumn;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
Expand Down Expand Up @@ -65,6 +64,7 @@
import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.springframework.util.ObjectUtils;

/**
* JPA implementation of {@link Target}.
Expand Down Expand Up @@ -140,11 +140,10 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
// set default request controller attributes to true, because we want to request them the first time
private boolean requestControllerAttributes = true;

@Setter
@Getter
@OneToOne(fetch = FetchType.LAZY, mappedBy = "target", cascade = { CascadeType.ALL }, orphanRemoval = true)
// actually it is OneToOne - but lazy loading is not supported for OneToOne (at least for hibernate 6.6.2)
@OneToMany(fetch = FetchType.LAZY, mappedBy = "target", cascade = { CascadeType.ALL }, orphanRemoval = true)
@PrimaryKeyJoinColumn
private JpaAutoConfirmationStatus autoConfirmationStatus;
private List<JpaAutoConfirmationStatus> autoConfirmationStatus;

@Setter
@Getter
Expand Down Expand Up @@ -242,6 +241,19 @@ public PollStatus getPollStatus() {
.apply(this);
}

public JpaAutoConfirmationStatus getAutoConfirmationStatus() {
return ObjectUtils.isEmpty(autoConfirmationStatus) ? null : autoConfirmationStatus.get(0);
}

public void setAutoConfirmationStatus(final JpaAutoConfirmationStatus autoConfirmationStatus) {
if (this.autoConfirmationStatus == null) {
this.autoConfirmationStatus = new ArrayList<>();
} else {
this.autoConfirmationStatus.clear();
}
this.autoConfirmationStatus.add(autoConfirmationStatus);
}

public void addTag(final TargetTag tag) {
if (tags == null) {
tags = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction> {
* @return the found {@link Action}
*/
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
Optional<Action> findWithDetailsById(Long actionId);
Optional<Action> findWithDetailsById(@Param("id") Long actionId);

/**
* Retrieves the latest finished {@link Action} for given target and {@link DistributionSet}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifac
*
* @return sum of artifacts size in bytes
*/
@Query("SELECT SUM(la.size) FROM JpaArtifact la WHERE la.softwareModule.deleted = false")
@Query("SELECT SUM(a.fileSize) FROM JpaArtifact a WHERE a.softwareModule.deleted = false")
Optional<Long> sumOfNonDeletedArtifactSize();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> 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<Long> targets);

// TODO AC - remove it and use specification

Expand All @@ -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<Long> targets);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void canceledAndFailedActionsAreCleanedUp() {
autoActionCleanup.run();

assertThat(actionRepository.count()).isEqualTo(1);
assertThat(actionRepository.findWithDetailsById(action3)).isPresent();
assertThat(actionRepository.findById(action3)).isPresent();
}

@Test
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ private void assertInstalledDistributionSetId(final String controllerId, final L
}

private void assertLastActionStatusCodeInAction(final Long actionId, final Integer expectedLastActionStatusCode) {
final Optional<Action> action = actionRepository.findWithDetailsById(actionId);
final Optional<Action> action = actionRepository.findById(actionId).map(Action.class::cast);
assertThat(action).isPresent();
assertThat(action.get().getLastActionStatusCode()).isEqualTo(Optional.ofNullable(expectedLastActionStatusCode));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading