Sonar Fixes (6) (#2214)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -11,12 +11,14 @@ package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import static org.eclipse.hawkbit.repository.SizeConversionHelper.byteValueToReadableString;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* Thrown if file size quota is exceeded
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class FileSizeQuotaExceededException extends AbstractServerRtException {
|
||||
|
||||
private static final String MAX_ARTIFACT_SIZE_EXCEEDED = "Maximum artifact size (%s) exceeded.";
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.io.Serial;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -20,9 +21,9 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
|
||||
/**
|
||||
* Thrown if user tries to assign a {@link DistributionSet} to a {@link Target}
|
||||
* that has an incompatible {@link TargetType}
|
||||
* Thrown if user tries to assign a {@link DistributionSet} to a {@link Target} that has an incompatible {@link TargetType}
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class IncompatibleTargetTypeException extends AbstractServerRtException {
|
||||
|
||||
@Serial
|
||||
|
||||
@@ -11,14 +11,15 @@ package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* This exception is indicating that the confirmation feedback cannot be
|
||||
* processed for a specific actions for different reasons which are listed as
|
||||
* enum {@link Reason}.
|
||||
* This exception is indicating that the confirmation feedback cannot be processed for a specific actions for different reasons which are
|
||||
* listed as enum {@link Reason}.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class InvalidConfirmationFeedbackException extends AbstractServerRtException {
|
||||
|
||||
@Serial
|
||||
|
||||
@@ -11,15 +11,16 @@ package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* This exception is thrown if trying to set a maintenance schedule that is
|
||||
* invalid. A maintenance schedule is considered to be valid only if schedule,
|
||||
* duration and timezone are all null, or are all valid; in which case there
|
||||
* should be at least one valid window after the current time.
|
||||
* This exception is thrown if trying to set a maintenance schedule that is invalid. A maintenance schedule is considered to be valid only if
|
||||
* schedule, duration and timezone are all null, or are all valid; in which case there should be at least one valid window after the current
|
||||
* time.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class InvalidMaintenanceScheduleException extends AbstractServerRtException {
|
||||
|
||||
@Serial
|
||||
|
||||
@@ -91,8 +91,8 @@ class HawkbitEclipseLinkJpaDialect extends EclipseLinkJpaDialect {
|
||||
Throwable exception = jpaSystemException;
|
||||
do {
|
||||
final Throwable cause = exception.getCause();
|
||||
if (cause instanceof SQLException) {
|
||||
return (SQLException) cause;
|
||||
if (cause instanceof SQLException sqlException) {
|
||||
return sqlException;
|
||||
}
|
||||
exception = cause;
|
||||
} while (exception != null);
|
||||
|
||||
@@ -31,7 +31,7 @@ public class EntityPropertyChangeListener extends DescriptorEventAdapter {
|
||||
final Object object = event.getObject();
|
||||
if (((UpdateObjectQuery) event.getQuery()).getObjectChangeSet().getChangedAttributeNames().stream()
|
||||
.anyMatch(field -> !TARGET_UPDATE_EVENT_IGNORE_FIELDS.contains(field))) {
|
||||
AbstractJpaBaseEntity.doNotify(() -> ((EventAwareEntity) object).fireUpdateEvent());
|
||||
AbstractBaseEntity.doNotify(((EventAwareEntity) object)::fireUpdateEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class EntityPropertyChangeListener implements PostUpdateEventListener {
|
||||
}
|
||||
|
||||
if (hasNonIgnoredChanges || !lastTargetQueryChanged) {
|
||||
AbstractJpaBaseEntity.doNotify(() -> ((EventAwareEntity) event.getEntity()).fireUpdateEvent());
|
||||
AbstractBaseEntity.doNotify(((EventAwareEntity) event.getEntity())::fireUpdateEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
|
||||
private List<Action> giveConfirmationForActiveActions(final AutoConfirmationStatus autoConfirmationStatus) {
|
||||
return findActiveActionsHavingStatus(autoConfirmationStatus.getTarget().getControllerId(), Status.WAIT_FOR_CONFIRMATION).stream()
|
||||
.map(action -> autoConfirmAction(action, autoConfirmationStatus))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Action autoConfirmAction(final JpaAction action, final AutoConfirmationStatus autoConfirmationStatus) {
|
||||
|
||||
@@ -321,13 +321,16 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
@Retryable(retryFor = ConcurrencyFailureException.class, noRetryFor = EntityAlreadyExistsException.class, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Target findOrRegisterTargetIfItDoesNotExist(final String controllerId, final URI address) {
|
||||
return findOrRegisterTargetIfItDoesNotExist(controllerId, address, null, null);
|
||||
return findOrRegisterTargetIfItDoesNotExist0(controllerId, address, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
@Retryable(retryFor = ConcurrencyFailureException.class, noRetryFor = EntityAlreadyExistsException.class, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Target findOrRegisterTargetIfItDoesNotExist(final String controllerId, final URI address, final String name, final String type) {
|
||||
return findOrRegisterTargetIfItDoesNotExist0(controllerId, address, name, type);
|
||||
}
|
||||
private Target findOrRegisterTargetIfItDoesNotExist0(final String controllerId, final URI address, final String name, final String type) {
|
||||
final Specification<JpaTarget> spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTarget_.controllerId), controllerId);
|
||||
return targetRepository.findOne(spec).map(target -> updateTarget(target, address, name, type))
|
||||
.orElseGet(() -> createTarget(controllerId, address, name, type));
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -375,7 +376,7 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
||||
public static class StatusConverter extends MapAttributeConverter<Status, Integer> {
|
||||
|
||||
public StatusConverter() {
|
||||
super(new HashMap<>() {{
|
||||
super(new EnumMap<>(new HashMap<>() {{
|
||||
put(Status.FINISHED, 0);
|
||||
put(Status.ERROR, 1);
|
||||
put(Status.WARNING, 2);
|
||||
@@ -388,7 +389,7 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
||||
put(Status.CANCEL_REJECTED, 9);
|
||||
put(Status.DOWNLOADED, 10);
|
||||
put(Status.WAIT_FOR_CONFIRMATION, 11);
|
||||
}}, null);
|
||||
}}), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,15 +19,17 @@ import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.model.AutoConfirmationStatus;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@NoArgsConstructor // Default constructor needed for JPA entities.
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "sp_target_conf_status")
|
||||
@@ -48,8 +50,8 @@ public class JpaAutoConfirmationStatus extends AbstractJpaTenantAwareBaseEntity
|
||||
|
||||
public JpaAutoConfirmationStatus(final String initiator, final String remark, final Target target) {
|
||||
this.target = (JpaTarget) target;
|
||||
this.initiator = StringUtils.isEmpty(initiator) ? null : initiator;
|
||||
this.remark = StringUtils.isEmpty(remark) ? null : remark;
|
||||
this.initiator = ObjectUtils.isEmpty(initiator) ? null : initiator;
|
||||
this.remark = ObjectUtils.isEmpty(remark) ? null : remark;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,28 +27,28 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
@Feature("Component Tests - Repository")
|
||||
@Story("Entity Listener Interceptor")
|
||||
public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the pre persist is called after a entity creation.")
|
||||
public void prePersistIsCalledWhenPersistingATarget() {
|
||||
void prePersistIsCalledWhenPersistingATarget() {
|
||||
executePersistAndAssertCallbackResult(new PrePersistEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the post persist is called after a entity creation.")
|
||||
public void postPersistIsCalledWhenPersistingATarget() {
|
||||
void postPersistIsCalledWhenPersistingATarget() {
|
||||
executePersistAndAssertCallbackResult(new PostPersistEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the post load is called after a entity is loaded.")
|
||||
public void postLoadIsCalledWhenLoadATarget() {
|
||||
void postLoadIsCalledWhenLoadATarget() {
|
||||
final PostLoadEntityListener postLoadEntityListener = new PostLoadEntityListener();
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(postLoadEntityListener);
|
||||
|
||||
@@ -61,25 +61,25 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the pre update is called after a entity update.")
|
||||
public void preUpdateIsCalledWhenUpdateATarget() {
|
||||
void preUpdateIsCalledWhenUpdateATarget() {
|
||||
executeUpdateAndAssertCallbackResult(new PreUpdateEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the post update is called after a entity update.")
|
||||
public void postUpdateIsCalledWhenUpdateATarget() {
|
||||
void postUpdateIsCalledWhenUpdateATarget() {
|
||||
executeUpdateAndAssertCallbackResult(new PostUpdateEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the pre remove is called after a entity deletion.")
|
||||
public void preRemoveIsCalledWhenDeletingATarget() {
|
||||
void preRemoveIsCalledWhenDeletingATarget() {
|
||||
executeDeleteAndAssertCallbackResult(new PreRemoveEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the post remove is called after a entity deletion.")
|
||||
public void postRemoveIsCalledWhenDeletingATarget() {
|
||||
void postRemoveIsCalledWhenDeletingATarget() {
|
||||
executeDeleteAndAssertCallbackResult(new PostRemoveEntityListener());
|
||||
}
|
||||
|
||||
@@ -91,10 +91,10 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void executeUpdateAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
Target updateTarget = addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated");
|
||||
|
||||
updateTarget = targetManagement
|
||||
.update(entityFactory.target().update(updateTarget.getControllerId()).name("New"));
|
||||
final Target updateTarget = targetManagement.update(
|
||||
entityFactory.target()
|
||||
.update(addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated").getControllerId())
|
||||
.name("New"));
|
||||
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(updateTarget);
|
||||
|
||||
@@ -144,17 +144,17 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof RemoteTenantAwareEvent) {
|
||||
assertThat(((RemoteTenantAwareEvent) event).getTenant()).isNotEmpty();
|
||||
if (event instanceof RemoteTenantAwareEvent remoteTenantAwareEvent) {
|
||||
assertThat(remoteTenantAwareEvent.getTenant()).isNotEmpty();
|
||||
}
|
||||
|
||||
if (event instanceof RemoteIdEvent) {
|
||||
assertThat(((RemoteIdEvent) event).getEntityId()).isNotNull();
|
||||
if (event instanceof RemoteIdEvent remoteIdEvent) {
|
||||
assertThat(remoteIdEvent.getEntityId()).isNotNull();
|
||||
}
|
||||
|
||||
if (event instanceof TargetAssignDistributionSetEvent) {
|
||||
assertThat(((TargetAssignDistributionSetEvent) event).getActions()).isNotEmpty();
|
||||
assertThat(((TargetAssignDistributionSetEvent) event).getDistributionSetId()).isNotNull();
|
||||
if (event instanceof TargetAssignDistributionSetEvent targetAssignDistributionSetEvent) {
|
||||
assertThat(targetAssignDistributionSetEvent.getActions()).isNotEmpty();
|
||||
assertThat(targetAssignDistributionSetEvent.getDistributionSetId()).isNotNull();
|
||||
}
|
||||
|
||||
capturedEvents.compute(event.getClass(), (k, v) -> v == null ? 1 : v + 1);
|
||||
@@ -177,7 +177,7 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ResetCounterMarkerEvent() {
|
||||
super(new Object(), "resetcounter");
|
||||
super(new Object(), "resetcounter", DEFAULT_DESTINATION_FACTORY.getDestination(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user