Fix sonar findings: Type constants access (#1983)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-09 15:11:39 +02:00
committed by GitHub
parent 17fb7efe42
commit cc226eadac
12 changed files with 32 additions and 32 deletions

View File

@@ -26,5 +26,4 @@ public interface DistributionSetBuilder {
* @return builder instance * @return builder instance
*/ */
DistributionSetCreate create(); DistributionSetCreate create();
} }

View File

@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.repository.model.Type;
/** /**
* Builder to create a new {@link DistributionSet} entry. Defines all fields * Builder to create a new {@link DistributionSet} entry. Defines all fields
@@ -50,7 +51,7 @@ public interface DistributionSetCreate {
* @param typeKey for {@link DistributionSet#getType()} * @param typeKey for {@link DistributionSet#getType()}
* @return updated builder instance * @return updated builder instance
*/ */
DistributionSetCreate type(@Size(min = 1, max = DistributionSetType.KEY_MAX_SIZE) @NotNull String typeKey); DistributionSetCreate type(@Size(min = 1, max = Type.KEY_MAX_SIZE) @NotNull String typeKey);
/** /**
* @param type for {@link DistributionSet#getType()} * @param type for {@link DistributionSet#getType()}

View File

@@ -26,5 +26,4 @@ public interface DistributionSetTypeBuilder {
* @return builder instance * @return builder instance
*/ */
DistributionSetTypeCreate create(); DistributionSetTypeCreate create();
} }

View File

@@ -9,8 +9,8 @@
*/ */
package org.eclipse.hawkbit.repository.builder; package org.eclipse.hawkbit.repository.builder;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Optional; import java.util.Optional;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Type;
/** /**
* Builder to create a new {@link DistributionSetType} entry. Defines all fields * Builder to create a new {@link DistributionSetType} entry. Defines all fields
@@ -32,7 +33,7 @@ public interface DistributionSetTypeCreate {
* @param key for {@link DistributionSetType#getKey()} * @param key for {@link DistributionSetType#getKey()}
* @return updated builder instance * @return updated builder instance
*/ */
DistributionSetTypeCreate key(@Size(min = 1, max = DistributionSetType.KEY_MAX_SIZE) @NotNull String key); DistributionSetTypeCreate key(@Size(min = 1, max = Type.KEY_MAX_SIZE) @NotNull String key);
/** /**
* @param name for {@link DistributionSetType#getName()} * @param name for {@link DistributionSetType#getName()}
@@ -50,7 +51,7 @@ public interface DistributionSetTypeCreate {
* @param colour for {@link DistributionSetType#getColour()} * @param colour for {@link DistributionSetType#getColour()}
* @return updated builder instance * @return updated builder instance
*/ */
DistributionSetTypeCreate colour(@Size(max = DistributionSetType.COLOUR_MAX_SIZE) String colour); DistributionSetTypeCreate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
/** /**
* @param mandatory for {@link DistributionSetType#getMandatoryModuleTypes()} * @param mandatory for {@link DistributionSetType#getMandatoryModuleTypes()}
@@ -63,7 +64,7 @@ public interface DistributionSetTypeCreate {
* @return updated builder instance * @return updated builder instance
*/ */
default DistributionSetTypeCreate mandatory(final Long mandatory) { default DistributionSetTypeCreate mandatory(final Long mandatory) {
return mandatory(Arrays.asList(mandatory)); return mandatory(Collections.singletonList(mandatory));
} }
/** /**
@@ -85,7 +86,7 @@ public interface DistributionSetTypeCreate {
* @return updated builder instance * @return updated builder instance
*/ */
default DistributionSetTypeCreate optional(final Long optional) { default DistributionSetTypeCreate optional(final Long optional) {
return optional(Arrays.asList(optional)); return optional(Collections.singletonList(optional));
} }
/** /**
@@ -97,8 +98,7 @@ public interface DistributionSetTypeCreate {
} }
/** /**
* @return peek on current state of {@link DistributionSetType} in the * @return peek on current state of {@link DistributionSetType} in the builder
* builder
*/ */
DistributionSetType build(); DistributionSetType build();
} }

View File

@@ -15,6 +15,7 @@ import jakarta.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.Type;
/** /**
* Builder to update an existing {@link DistributionSetType} entry. Defines all * Builder to update an existing {@link DistributionSetType} entry. Defines all
@@ -32,7 +33,7 @@ public interface DistributionSetTypeUpdate {
* @param colour for {@link DistributionSetType#getColour()} * @param colour for {@link DistributionSetType#getColour()}
* @return updated builder instance * @return updated builder instance
*/ */
DistributionSetTypeUpdate colour(@Size(max = DistributionSetType.COLOUR_MAX_SIZE) String colour); DistributionSetTypeUpdate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
/** /**
* @param mandatory for {@link DistributionSetType#getMandatoryModuleTypes()} * @param mandatory for {@link DistributionSetType#getMandatoryModuleTypes()}

View File

@@ -18,8 +18,7 @@ import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
/** /**
* Builder to update an existing {@link DistributionSet} entry. Defines all * Builder to update an existing {@link DistributionSet} entry. Defines all fields that can be updated.
* fields that can be updated.
*/ */
public interface DistributionSetUpdate { public interface DistributionSetUpdate {

View File

@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Type;
/** /**
* Builder to create a new {@link SoftwareModule} entry. Defines all fields that * Builder to create a new {@link SoftwareModule} entry. Defines all fields that
@@ -55,7 +56,7 @@ public interface SoftwareModuleCreate {
* @param typeKey for {@link SoftwareModule#getType()} * @param typeKey for {@link SoftwareModule#getType()}
* @return updated builder instance * @return updated builder instance
*/ */
SoftwareModuleCreate type(@Size(min = 1, max = SoftwareModuleType.KEY_MAX_SIZE) @NotNull String typeKey); SoftwareModuleCreate type(@Size(min = 1, max = Type.KEY_MAX_SIZE) @NotNull String typeKey);
/** /**
* @param type for {@link SoftwareModule#getType()} * @param type for {@link SoftwareModule#getType()}

View File

@@ -15,6 +15,7 @@ import jakarta.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Type;
/** /**
* Builder to create a new {@link SoftwareModuleType} entry. Defines all fields * Builder to create a new {@link SoftwareModuleType} entry. Defines all fields
@@ -27,7 +28,7 @@ public interface SoftwareModuleTypeCreate {
* @param key for {@link SoftwareModuleType#getKey()} * @param key for {@link SoftwareModuleType#getKey()}
* @return updated builder instance * @return updated builder instance
*/ */
SoftwareModuleTypeCreate key(@Size(min = 1, max = SoftwareModuleType.KEY_MAX_SIZE) @NotNull String key); SoftwareModuleTypeCreate key(@Size(min = 1, max = Type.KEY_MAX_SIZE) @NotNull String key);
/** /**
* @param name for {@link SoftwareModuleType#getName()} * @param name for {@link SoftwareModuleType#getName()}
@@ -45,7 +46,7 @@ public interface SoftwareModuleTypeCreate {
* @param colour for {@link SoftwareModuleType#getColour()} * @param colour for {@link SoftwareModuleType#getColour()}
* @return updated builder instance * @return updated builder instance
*/ */
SoftwareModuleTypeCreate colour(@Size(max = SoftwareModuleType.COLOUR_MAX_SIZE) String colour); SoftwareModuleTypeCreate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
/** /**
* @param maxAssignments for {@link SoftwareModuleType#getMaxAssignments()} * @param maxAssignments for {@link SoftwareModuleType#getMaxAssignments()}

View File

@@ -13,6 +13,7 @@ import jakarta.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Type;
/** /**
* Builder to update an existing {@link SoftwareModuleType} entry. Defines all * Builder to update an existing {@link SoftwareModuleType} entry. Defines all
@@ -30,5 +31,5 @@ public interface SoftwareModuleTypeUpdate {
* @param colour for {@link SoftwareModuleType#getColour()} * @param colour for {@link SoftwareModuleType#getColour()}
* @return updated builder instance * @return updated builder instance
*/ */
SoftwareModuleTypeUpdate colour(@Size(max = SoftwareModuleType.COLOUR_MAX_SIZE) String colour); SoftwareModuleTypeUpdate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
} }

View File

@@ -13,6 +13,7 @@ import jakarta.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TargetType; import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.Type;
/** /**
* Builder to update an existing {@link TargetType} entry. Defines all * Builder to update an existing {@link TargetType} entry. Defines all
@@ -30,7 +31,7 @@ public interface TargetTypeUpdate {
* @param colour for {@link TargetType#getColour()} * @param colour for {@link TargetType#getColour()}
* @return updated builder instance * @return updated builder instance
*/ */
TargetTypeUpdate colour(@Size(max = TargetType.COLOUR_MAX_SIZE) String colour); TargetTypeUpdate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
/** /**
* @param name Name * @param name Name

View File

@@ -10,8 +10,7 @@
package org.eclipse.hawkbit.repository.model; package org.eclipse.hawkbit.repository.model;
/** /**
* {@link Type} is an abstract definition for {@link DistributionSetType}s and * {@link Type} is an abstract definition for {@link DistributionSetType}s and {@link SoftwareModuleType}s
* {@link SoftwareModuleType}s
*/ */
public interface Type extends NamedEntity { public interface Type extends NamedEntity {
@@ -31,8 +30,7 @@ public interface Type extends NamedEntity {
String getKey(); String getKey();
/** /**
* @return <code>true</code> if the type is deleted and only kept for * @return <code>true</code> if the type is deleted and only kept for history purposes.
* history purposes.
*/ */
boolean isDeleted(); boolean isDeleted();
@@ -40,5 +38,4 @@ public interface Type extends NamedEntity {
* @return get color code to be used in management UI views. * @return get color code to be used in management UI views.
*/ */
String getColour(); String getColour();
} }

View File

@@ -214,7 +214,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
.as("targetType with too long colour should not be created") .as("targetType with too long colour should not be created")
.isThrownBy(() -> targetTypeManagement.create( .isThrownBy(() -> targetTypeManagement.create(
entityFactory.targetType().create().name("a") entityFactory.targetType().create().name("a")
.colour(RandomStringUtils.randomAlphanumeric(TargetType.COLOUR_MAX_SIZE + 1)))); .colour(RandomStringUtils.randomAlphanumeric(Type.COLOUR_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid colour should not be created").isThrownBy(() -> targetTypeManagement .as("targetType with invalid colour should not be created").isThrownBy(() -> targetTypeManagement
@@ -224,7 +224,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
.as("targetType with too long colour should not be updated") .as("targetType with too long colour should not be updated")
.isThrownBy(() -> targetTypeManagement.update( .isThrownBy(() -> targetTypeManagement.update(
entityFactory.targetType().update(targetType.getId()) entityFactory.targetType().update(targetType.getId())
.colour(RandomStringUtils.randomAlphanumeric(TargetType.COLOUR_MAX_SIZE + 1)))); .colour(RandomStringUtils.randomAlphanumeric(Type.COLOUR_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class) assertThatExceptionOfType(ConstraintViolationException.class)
.as("targetType with invalid colour should not be updated").isThrownBy(() -> targetTypeManagement .as("targetType with invalid colour should not be updated").isThrownBy(() -> targetTypeManagement