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

Sonar Fixes #2240

Merged
merged 1 commit into from
Jan 27, 2025
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 @@ -79,6 +79,7 @@ public TargetWithActionType(
* cron expression is relative to this time zone.
* @throws InvalidMaintenanceScheduleException if the parameters do not define a valid maintenance schedule.
*/
@SuppressWarnings("java:S107")
public TargetWithActionType(
final String controllerId, final ActionType actionType, final long forceTime, final Integer weight,
final String maintenanceSchedule, final String maintenanceWindowDuration, final String maintenanceWindowTimeZone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ private Status convertStatus(final Action.Status status) {
return Status.FINISHED;
case CANCELED:
return Status.CANCELLED;
case RETRIEVED:
case RUNNING:
case WARNING:
case DOWNLOAD:
case WAIT_FOR_CONFIRMATION:
case CANCELING:
case RETRIEVED, RUNNING, WARNING, DOWNLOAD, WAIT_FOR_CONFIRMATION, CANCELING:
return Status.RUNNING;
case DOWNLOADED:
return Action.ActionType.DOWNLOAD_ONLY == rolloutType ? Status.FINISHED : Status.RUNNING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.eclipse.hawkbit.tenancy.configuration.ControllerPollProperties;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.springframework.beans.factory.annotation.Autowired;

/**
* This class is used to validate, that the property is a String and that it is in the correct duration format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@Feature("Component Tests - TotalTargetCountStatus")
@Story("TotalTargetCountStatus should correctly present finished DOWNLOAD_ONLY actions")
public class TotalTargetCountStatusTest {
class TotalTargetCountStatusTest {

private final List<TotalTargetCountActionStatus> targetCountActionStatuses = Arrays.asList(
new TotalTargetCountActionStatus(Action.Status.SCHEDULED, 1L),
Expand All @@ -39,44 +39,44 @@ public class TotalTargetCountStatusTest {
@Test
@Description("Different Action Statuses should be correctly mapped to the corresponding " +
"TotalTargetCountStatus.Status")
public void shouldCorrectlyMapActionStatuses() {
void shouldCorrectlyMapActionStatuses() {
TotalTargetCountStatus status = new TotalTargetCountStatus(targetCountActionStatuses, 55L,
Action.ActionType.FORCED);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)).isEqualTo(1L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)).isEqualTo(2L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)).isEqualTo(3L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)).isEqualTo(4L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)).isEqualTo(45L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)).isEqualTo(0L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)).isZero();
assertThat(status.getFinishedPercent()).isEqualTo((float) 100 * 3 / 55);
}

@Test
@Description("When an empty list is passed to the TotalTargetCountStatus, all actions should be displayed as " +
"NOTSTARTED")
public void shouldCorrectlyMapActionStatusesToNotStarted() {
void shouldCorrectlyMapActionStatusesToNotStarted() {
TotalTargetCountStatus status = new TotalTargetCountStatus(Collections.emptyList(), 55L,
Action.ActionType.FORCED);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)).isEqualTo(0L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)).isEqualTo(0L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)).isEqualTo(0L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)).isEqualTo(0L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)).isEqualTo(0L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)).isZero();
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)).isZero();
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)).isZero();
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)).isZero();
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)).isZero();
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)).isEqualTo(55L);
assertThat(status.getFinishedPercent()).isEqualTo(0);
assertThat(status.getFinishedPercent()).isZero();
}

@Test
@Description("DownloadOnly actions should be displayed as FINISHED when they have ActionStatus.DOWNLOADED")
public void shouldCorrectlyMapActionStatusesInDownloadOnlyCase() {
void shouldCorrectlyMapActionStatusesInDownloadOnlyCase() {
TotalTargetCountStatus status = new TotalTargetCountStatus(targetCountActionStatuses, 55L,
Action.ActionType.DOWNLOAD_ONLY);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)).isEqualTo(1L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)).isEqualTo(2L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)).isEqualTo(13L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)).isEqualTo(4L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)).isEqualTo(35L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)).isEqualTo(0L);
assertThat(status.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)).isZero();
assertThat(status.getFinishedPercent()).isEqualTo((float) 100 * 13 / 55);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.lang.reflect.Method;

import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Service;

Expand All @@ -22,12 +21,14 @@
@Service
public class TenantKeyGenerator implements KeyGenerator {

@Autowired
private TenantAware tenantAware;
private final TenantAware tenantAware;

public TenantKeyGenerator(final TenantAware tenantAware) {
this.tenantAware = tenantAware;
}

@Override
public Object generate(final Object target, final Method method, final Object... params) {
return tenantAware.getCurrentTenant().toUpperCase();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
import org.eclipse.hawkbit.repository.jpa.specifications.TargetTypeSpecification;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTypeEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType_;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
Expand All @@ -36,7 +38,7 @@ public final class TargetTypeSpecification {
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> hasIdIn(final Collection<Long> ids) {
return (targetRoot, query, cb) -> targetRoot.get(JpaTargetType_.id).in(ids);
return (targetRoot, query, cb) -> targetRoot.get(AbstractJpaBaseEntity_.id).in(ids);
}

/**
Expand All @@ -48,32 +50,28 @@ public static Specification<JpaTargetType> hasIdIn(final Collection<Long> ids) {
public static Specification<JpaTargetType> hasDsSetType(final Long dsTypeId) {
return (targetRoot, query, cb) -> {
final SetJoin<JpaTargetType, JpaDistributionSetType> join = targetRoot.join(JpaTargetType_.distributionSetTypes);
return cb.equal(join.get(JpaDistributionSetType_.id), dsTypeId);
return cb.equal(join.get(AbstractJpaBaseEntity_.id), dsTypeId);
};
}

/**
* {@link Specification} for retrieving {@link TargetType} with
* given {@link TargetType#getKey()} including fetching the
* elements list.
* {@link Specification} for retrieving {@link TargetType} with given {@link TargetType#getKey()} including fetching the elements list.
*
* @param key to search
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> hasKey(final String key) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTargetType_.key), key);
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(AbstractJpaTypeEntity_.key), key);
}

/**
* {@link Specification} for retrieving {@link TargetType} with
* given {@link TargetType#getName()} including fetching the
* elements list.
* {@link Specification} for retrieving {@link TargetType} with given {@link TargetType#getName()} including fetching the elements list.
*
* @param name to search
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> hasName(final String name) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTargetType_.name), name);
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(AbstractJpaNamedEntity_.name), name);
}

/**
Expand All @@ -83,6 +81,6 @@ public static Specification<JpaTargetType> hasName(final String name) {
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> likeName(final String name) {
return (targetRoot, query, cb) -> cb.like(cb.lower(targetRoot.get(JpaTargetType_.name)), name.toLowerCase());
return (targetRoot, query, cb) -> cb.like(cb.lower(targetRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public void validateWeight(final Integer weight) {
* @param hasNoWeight indicator of the weight if it doesn't have a numerical value
*/
public void validateWeight(final boolean hasWeight, final boolean hasNoWeight) {
// remove bypassing the weight enforcement as soon as weight can be set
// via UI
// remove bypassing the weight enforcement as soon as weight can be set via UI
final boolean bypassWeightEnforcement = true;
final boolean multiAssignmentsEnabled = TenantConfigHelper
.usingContext(systemSecurityContext, tenantConfigurationManagement).isMultiAssignmentsEnabled();
.usingContext(systemSecurityContext, tenantConfigurationManagement)
.isMultiAssignmentsEnabled();
if (bypassWeightEnforcement) {
return;
} else if (multiAssignmentsEnabled && hasNoWeight) {
Expand Down
Loading
Loading