Fix SonarQube issues (2) (#2205)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -11,18 +11,21 @@ package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* Exception being thrown in case of error while generating encryption secrets,
|
||||
* encrypting or decrypting artifacts.
|
||||
* Exception being thrown in case of error while generating encryption secrets, encrypting or decrypting artifacts.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class ArtifactEncryptionFailedException extends AbstractServerRtException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final EncryptionOperation encryptionOperation;
|
||||
|
||||
public ArtifactEncryptionFailedException(final EncryptionOperation encryptionOperation) {
|
||||
@@ -33,21 +36,15 @@ public final class ArtifactEncryptionFailedException extends AbstractServerRtExc
|
||||
this(encryptionOperation, message, null);
|
||||
}
|
||||
|
||||
public ArtifactEncryptionFailedException(final EncryptionOperation encryptionOperation, final String message,
|
||||
final Throwable cause) {
|
||||
public ArtifactEncryptionFailedException(final EncryptionOperation encryptionOperation, final String message, final Throwable cause) {
|
||||
super(message, SpServerError.SP_ARTIFACT_ENCRYPTION_FAILED, cause);
|
||||
this.encryptionOperation = encryptionOperation;
|
||||
}
|
||||
|
||||
public EncryptionOperation getEncryptionOperation() {
|
||||
return encryptionOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encryption operation that caused the exception.
|
||||
*/
|
||||
public enum EncryptionOperation {
|
||||
GENERATE_SECRETS, ENCRYPT, DECRYPT;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,8 @@ public abstract class AbstractBaseEntityBuilder implements Identifiable<Long> {
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
static String strip(final String value) {
|
||||
return value == null ? null : value.strip();
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
@@ -25,6 +25,7 @@ public abstract class AbstractDistributionSetUpdateCreate<T> extends AbstractNam
|
||||
@ValidString
|
||||
protected String version;
|
||||
protected Boolean requiredMigrationStep;
|
||||
@Getter
|
||||
protected Collection<Long> modules;
|
||||
|
||||
public T modules(final Collection<Long> modules) {
|
||||
@@ -32,10 +33,6 @@ public abstract class AbstractDistributionSetUpdateCreate<T> extends AbstractNam
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Collection<Long> getModules() {
|
||||
return modules;
|
||||
}
|
||||
|
||||
public T requiredMigrationStep(final Boolean requiredMigrationStep) {
|
||||
this.requiredMigrationStep = requiredMigrationStep;
|
||||
return (T) this;
|
||||
@@ -46,7 +43,7 @@ public abstract class AbstractDistributionSetUpdateCreate<T> extends AbstractNam
|
||||
}
|
||||
|
||||
public T version(final String version) {
|
||||
this.version = StringUtils.trimWhitespace(version);
|
||||
this.version = strip(version);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
@@ -29,12 +28,12 @@ public abstract class AbstractMetadataUpdateCreate<T> {
|
||||
protected String value;
|
||||
|
||||
public T key(final String key) {
|
||||
this.key = StringUtils.trimWhitespace(key);
|
||||
this.key = AbstractBaseEntityBuilder.strip(key);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T value(final String value) {
|
||||
this.value = StringUtils.trimWhitespace(value);
|
||||
this.value = AbstractBaseEntityBuilder.strip(value);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public abstract class AbstractNamedEntityBuilder<T> extends AbstractBaseEntityBuilder {
|
||||
|
||||
@@ -22,12 +21,12 @@ public abstract class AbstractNamedEntityBuilder<T> extends AbstractBaseEntityBu
|
||||
protected String description;
|
||||
|
||||
public T name(final String name) {
|
||||
this.name = StringUtils.trimWhitespace(name);
|
||||
this.name = AbstractBaseEntityBuilder.strip(name);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T description(final String description) {
|
||||
this.description = StringUtils.trimWhitespace(description);
|
||||
this.description = AbstractBaseEntityBuilder.strip(description);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create builder DTO.
|
||||
@@ -27,7 +26,7 @@ public abstract class AbstractRolloutGroupCreate<T> extends AbstractNamedEntityB
|
||||
protected boolean confirmationRequired;
|
||||
|
||||
public T targetFilterQuery(final String targetFilterQuery) {
|
||||
this.targetFilterQuery = StringUtils.trimWhitespace(targetFilterQuery);
|
||||
this.targetFilterQuery = AbstractBaseEntityBuilder.strip(targetFilterQuery);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
@@ -29,7 +28,7 @@ public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractName
|
||||
protected String type;
|
||||
|
||||
public T type(final String type) {
|
||||
this.type = StringUtils.trimWhitespace(type);
|
||||
this.type = AbstractBaseEntityBuilder.strip(type);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -38,7 +37,7 @@ public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractName
|
||||
}
|
||||
|
||||
public T vendor(final String vendor) {
|
||||
this.vendor = StringUtils.trimWhitespace(vendor);
|
||||
this.vendor = AbstractBaseEntityBuilder.strip(vendor);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractName
|
||||
}
|
||||
|
||||
public T version(final String version) {
|
||||
this.version = StringUtils.trimWhitespace(version);
|
||||
this.version = AbstractBaseEntityBuilder.strip(version);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class AbstractTagUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
protected String colour;
|
||||
|
||||
public T colour(final String colour) {
|
||||
this.colour = StringUtils.trimWhitespace(colour);
|
||||
this.colour = AbstractBaseEntityBuilder.strip(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
@@ -91,7 +90,7 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
|
||||
* @return this builder
|
||||
*/
|
||||
public T name(final String name) {
|
||||
this.name = StringUtils.trimWhitespace(name);
|
||||
this.name = AbstractBaseEntityBuilder.strip(name);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -106,7 +105,7 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
|
||||
* @return this builder
|
||||
*/
|
||||
public T query(final String query) {
|
||||
this.query = StringUtils.trimWhitespace(query);
|
||||
this.query = AbstractBaseEntityBuilder.strip(query);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import lombok.ToString;
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
@@ -37,7 +36,7 @@ public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T>
|
||||
protected Long targetTypeId;
|
||||
|
||||
protected AbstractTargetUpdateCreate(final String controllerId) {
|
||||
this.controllerId = StringUtils.trimWhitespace(controllerId);
|
||||
this.controllerId = AbstractBaseEntityBuilder.strip(controllerId);
|
||||
}
|
||||
|
||||
public T status(final TargetUpdateStatus status) {
|
||||
@@ -49,7 +48,7 @@ public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T>
|
||||
// check if this is a real URI
|
||||
if (address != null) {
|
||||
try {
|
||||
URI.create(StringUtils.trimWhitespace(address));
|
||||
URI.create(AbstractBaseEntityBuilder.strip(address));
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw new InvalidTargetAddressException(
|
||||
"The given address " + address + " violates the RFC-2396 specification", e);
|
||||
@@ -60,7 +59,7 @@ public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T>
|
||||
}
|
||||
|
||||
public T securityToken(final String securityToken) {
|
||||
this.securityToken = StringUtils.trimWhitespace(securityToken);
|
||||
this.securityToken = AbstractBaseEntityBuilder.strip(securityToken);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T>
|
||||
}
|
||||
|
||||
public TargetCreate controllerId(final String controllerId) {
|
||||
this.controllerId = StringUtils.trimWhitespace(controllerId);
|
||||
this.controllerId = AbstractBaseEntityBuilder.strip(controllerId);
|
||||
return (TargetCreate) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
@@ -27,7 +26,7 @@ public abstract class AbstractTypeUpdateCreate<T> extends AbstractNamedEntityBui
|
||||
protected String key;
|
||||
|
||||
public T colour(final String colour) {
|
||||
this.colour = StringUtils.trimWhitespace(colour);
|
||||
this.colour = AbstractBaseEntityBuilder.strip(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ public abstract class AbstractTypeUpdateCreate<T> extends AbstractNamedEntityBui
|
||||
}
|
||||
|
||||
public T key(final String key) {
|
||||
this.key = StringUtils.trimWhitespace(key);
|
||||
this.key = AbstractBaseEntityBuilder.strip(key);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
protected static final String NOT_EXIST_ID = "12345678990";
|
||||
protected static final long NOT_EXIST_IDL = Long.parseLong(NOT_EXIST_ID);
|
||||
|
||||
protected static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.insecure();
|
||||
|
||||
private static final List<String> REPOSITORY_AND_TARGET_PERMISSIONS = List.of(SpPermission.READ_REPOSITORY, SpPermission.CREATE_REPOSITORY, SpPermission.UPDATE_REPOSITORY, SpPermission.DELETE_REPOSITORY, SpPermission.READ_TARGET, SpPermission.CREATE_TARGET, SpPermission.UPDATE_TARGET, SpPermission.DELETE_TARGET);
|
||||
|
||||
@PersistenceContext
|
||||
@@ -177,14 +175,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
((JpaSoftwareModule) module).setOptLockRevision(module.getOptLockRevision() + 1);
|
||||
}
|
||||
|
||||
protected static String randomString(final int len) {
|
||||
return RANDOM_STRING_UTILS.next(len, true, false);
|
||||
}
|
||||
|
||||
protected static byte[] randomBytes(final int len) {
|
||||
return randomString(len).getBytes();
|
||||
}
|
||||
|
||||
protected Database getDatabase() {
|
||||
return jpaProperties.getDatabase();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.AutoAssignDistributionSetUpdate;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
@@ -248,15 +249,13 @@ class AutoAssignCheckerIntTest extends AbstractJpaIntegrationTest {
|
||||
final String targetDsAIdPref = "targA";
|
||||
final String targetDsFIdPref = "targB";
|
||||
|
||||
// target filter query that matches first bunch of targets, that should
|
||||
// fail
|
||||
assertThatExceptionOfType(IncompleteDistributionSetException.class).isThrownBy(() -> {
|
||||
final Long filterId = targetFilterQueryManagement.create(
|
||||
entityFactory.targetFilterQuery().create().name("filterA").query("id==" + targetDsFIdPref + "*"))
|
||||
.getId();
|
||||
targetFilterQueryManagement
|
||||
.updateAutoAssignDS(entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(setF.getId()));
|
||||
});
|
||||
final Long filterId = targetFilterQueryManagement.create(
|
||||
entityFactory.targetFilterQuery().create().name("filterA").query("id==" + targetDsFIdPref + "*"))
|
||||
.getId();
|
||||
final AutoAssignDistributionSetUpdate targetFilterQuery = entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(setF.getId());
|
||||
// target filter query that matches first bunch of targets, that should fail
|
||||
assertThatExceptionOfType(IncompleteDistributionSetException.class).isThrownBy(
|
||||
() -> targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery));
|
||||
// target filter query that matches failed bunch of targets
|
||||
targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("filterB")
|
||||
.query("id==" + targetDsAIdPref + "*").autoAssignDistributionSet(setA.getId()));
|
||||
|
||||
@@ -30,7 +30,6 @@ import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
|
||||
@@ -116,6 +116,8 @@ public abstract class AbstractIntegrationTest {
|
||||
protected static final URI LOCALHOST = URI.create("http://127.0.0.1");
|
||||
protected static final int DEFAULT_TEST_WEIGHT = 500;
|
||||
|
||||
protected static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure();
|
||||
|
||||
/**
|
||||
* Number of {@link DistributionSetType}s that exist in every test case. One
|
||||
* generated by using
|
||||
@@ -292,6 +294,14 @@ public abstract class AbstractIntegrationTest {
|
||||
return Comparator.comparing(Target::getControllerId);
|
||||
}
|
||||
|
||||
protected static String randomString(final int len) {
|
||||
return RANDOM_STRING_UTILS.next(len, true, false);
|
||||
}
|
||||
|
||||
protected static byte[] randomBytes(final int len) {
|
||||
return randomString(len).getBytes();
|
||||
}
|
||||
|
||||
protected DistributionSetAssignmentResult assignDistributionSet(final long dsID, final String controllerId) {
|
||||
return assignDistributionSet(dsID, controllerId, ActionType.FORCED);
|
||||
}
|
||||
@@ -477,7 +487,7 @@ public abstract class AbstractIntegrationTest {
|
||||
|
||||
private static String createTempDir() {
|
||||
try {
|
||||
return Files.createTempDirectory(null).toString() + "/" + RandomStringUtils.randomAlphanumeric(20);
|
||||
return Files.createTempDirectory(null).toString() + "/" + randomString(20);
|
||||
} catch (final IOException e) {
|
||||
throw new IllegalStateException("Failed to create temp directory");
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class AbstractSqlTestDatabase extends AbstractTestExecutionListe
|
||||
|
||||
protected final DatasourceContext context;
|
||||
|
||||
public AbstractSqlTestDatabase(final DatasourceContext context) {
|
||||
protected AbstractSqlTestDatabase(final DatasourceContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user