diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java index 0826c9f188..f03fd41e17 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java @@ -29,7 +29,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata; import org.eclipse.hawkbit.repository.model.MetaData; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; /** @@ -38,23 +37,31 @@ @Validated 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; - + private final TargetBuilder targetBuilder; + private final TargetTypeBuilder targetTypeBuilder; + private final TargetFilterQueryBuilder targetFilterQueryBuilder; + private final SoftwareModuleBuilder softwareModuleBuilder; + private final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder; + private final DistributionSetBuilder distributionSetBuilder; + private final DistributionSetTypeBuilder distributionSetTypeBuilder; + private final RolloutBuilder rolloutBuilder; + + @SuppressWarnings("java:S107") + public JpaEntityFactory( + final TargetBuilder targetBuilder, final TargetTypeBuilder targetTypeBuilder, + final TargetFilterQueryBuilder targetFilterQueryBuilder, + final SoftwareModuleBuilder softwareModuleBuilder, final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder, + final DistributionSetBuilder distributionSetBuilder, final DistributionSetTypeBuilder distributionSetTypeBuilder, + final RolloutBuilder rolloutBuilder) { + this.targetBuilder = targetBuilder; + this.targetTypeBuilder = targetTypeBuilder; + this.targetFilterQueryBuilder = targetFilterQueryBuilder; + this.softwareModuleBuilder = softwareModuleBuilder; + this.softwareModuleMetadataBuilder = softwareModuleMetadataBuilder; + this.distributionSetBuilder = distributionSetBuilder; + this.distributionSetTypeBuilder = distributionSetTypeBuilder; + this.rolloutBuilder = rolloutBuilder; + } @Override public ActionStatusBuilder actionStatus() { return new JpaActionStatusBuilder(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java index 8aa9663b29..fc1e4bd574 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java @@ -29,7 +29,6 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; /** * A collection of static helper methods for the management classes diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java index 929634e314..6984a869a8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java @@ -121,6 +121,7 @@ public class JpaRolloutExecutor implements RolloutExecutor { private final RepositoryProperties repositoryProperties; private final Map lastDynamicGroupFill = new ConcurrentHashMap<>(); + @SuppressWarnings("java:S107") public JpaRolloutExecutor( final ActionRepository actionRepository, final RolloutGroupRepository rolloutGroupRepository, final RolloutTargetGroupRepository rolloutTargetGroupRepository, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java index f86a4cdbeb..19701d113e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java @@ -181,6 +181,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.integration.support.locks.LockRegistry; import org.springframework.lang.NonNull; +import org.springframework.orm.jpa.vendor.Database; import org.springframework.retry.annotation.EnableRetry; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.transaction.PlatformTransactionManager; @@ -702,16 +703,26 @@ RolloutExecutor rolloutExecutor( @Bean @ConditionalOnMissingBean - RolloutManagement rolloutManagement(final TargetManagement targetManagement, - final DistributionSetManagement distributionSetManagement, final EventPublisherHolder eventPublisherHolder, - final VirtualPropertyReplacer virtualPropertyReplacer, final JpaProperties properties, + RolloutManagement rolloutManagement( + final RolloutRepository rolloutRepository, + final RolloutGroupRepository rolloutGroupRepository, final RolloutApprovalStrategy rolloutApprovalStrategy, + final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction, + final RolloutStatusCache rolloutStatusCache, + final ActionRepository actionRepository, + final TargetManagement targetManagement, + final DistributionSetManagement distributionSetManagement, final TenantConfigurationManagement tenantConfigurationManagement, - final SystemSecurityContext systemSecurityContext, - final ContextAware contextAware) { - return new JpaRolloutManagement(targetManagement, distributionSetManagement, eventPublisherHolder, - virtualPropertyReplacer, properties.getDatabase(), rolloutApprovalStrategy, - tenantConfigurationManagement, systemSecurityContext, contextAware); + final QuotaManagement quotaManagement, + final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder, + final VirtualPropertyReplacer virtualPropertyReplacer, + final SystemSecurityContext systemSecurityContext, final ContextAware contextAware, final JpaProperties properties, + final RepositoryProperties repositoryProperties) { + return new JpaRolloutManagement(rolloutRepository, rolloutGroupRepository, rolloutApprovalStrategy, + startNextRolloutGroupAction, rolloutStatusCache, actionRepository, targetManagement, + distributionSetManagement, tenantConfigurationManagement, quotaManagement, afterCommit, + eventPublisherHolder, virtualPropertyReplacer, systemSecurityContext, contextAware, properties.getDatabase(), + repositoryProperties); } /** @@ -809,8 +820,14 @@ ArtifactManagement artifactManagement( */ @Bean @ConditionalOnMissingBean - EntityFactory entityFactory() { - return new JpaEntityFactory(); + EntityFactory entityFactory( + final TargetBuilder targetBuilder, final TargetTypeBuilder targetTypeBuilder, + final TargetFilterQueryBuilder targetFilterQueryBuilder, + final SoftwareModuleBuilder softwareModuleBuilder, final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder, + final DistributionSetBuilder distributionSetBuilder, final DistributionSetTypeBuilder distributionSetTypeBuilder, + final RolloutBuilder rolloutBuilder) { + return new JpaEntityFactory(targetBuilder, targetTypeBuilder, targetFilterQueryBuilder, softwareModuleBuilder, + softwareModuleMetadataBuilder, distributionSetBuilder, distributionSetTypeBuilder, rolloutBuilder); } /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java index 8780478e8f..9bb8436575 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java @@ -21,7 +21,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.springframework.util.StringUtils; public class JpaRolloutCreate extends AbstractNamedEntityBuilder implements RolloutCreate { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java index 829ad7f13e..107f696ab0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java @@ -33,17 +33,8 @@ public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup /** * Set the Success And Error conditions for the rollout group - * - * @param group The Rollout group - * @param successCondition The Rollout group success condition - * @param successConditionExp The Rollout group success expression - * @param successAction The Rollout group success action - * @param successActionExp The Rollout group success action expression - * @param errorCondition The Rollout group error condition - * @param errorConditionExp The Rollout group error expression - * @param errorAction The Rollout group error action - * @param errorActionExp The Rollout group error action expression */ + @SuppressWarnings("java:S107") public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup group, final RolloutGroup.RolloutGroupSuccessCondition successCondition, final String successConditionExp, final RolloutGroup.RolloutGroupSuccessAction successAction, final String successActionExp, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java index 6c37bebc4b..f4cc9dc88c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java @@ -29,9 +29,9 @@ import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; @@ -66,21 +66,15 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { private final RolloutGroupRepository rolloutGroupRepository; - private final RolloutRepository rolloutRepository; - private final ActionRepository actionRepository; - private final TargetRepository targetRepository; - private final EntityManager entityManager; - private final VirtualPropertyReplacer virtualPropertyReplacer; - private final RolloutStatusCache rolloutStatusCache; - private final Database database; + @SuppressWarnings("java:S107") public JpaRolloutGroupManagement(final RolloutGroupRepository rolloutGroupRepository, final RolloutRepository rolloutRepository, final ActionRepository actionRepository, final TargetRepository targetRepository, final EntityManager entityManager, @@ -130,7 +124,7 @@ public Page findByRolloutAndRsql(final long rolloutId, final Strin final List> specList = Arrays.asList( RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutGroupFields.class, virtualPropertyReplacer, database), - (root, query, cb) -> cb.equal(root.get(JpaRolloutGroup_.rollout).get(JpaRollout_.id), rolloutId)); + (root, query, cb) -> cb.equal(root.get(JpaRolloutGroup_.rollout).get(AbstractJpaBaseEntity_.id), rolloutId)); return JpaManagementHelper.findAllWithCountBySpec(rolloutGroupRepository, specList, pageable); } @@ -180,7 +174,8 @@ public Page findTargetsOfRolloutGroup(final long rolloutGroupId, final P // in case of status ready the action has not been created yet and // the relation information between target and rollout-group is // stored in the #TargetRolloutGroup. - return JpaManagementHelper.findAllWithCountBySpec(targetRepository, + return JpaManagementHelper.findAllWithCountBySpec( + targetRepository, Collections.singletonList(TargetSpecifications.isInRolloutGroup(rolloutGroupId)), page ); } @@ -190,17 +185,14 @@ public Page findTargetsOfRolloutGroup(final long rolloutGroupId, final P } @Override - public Page findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId, - final String rsqlParam) { + public Page findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId, final String rsqlParam) { throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); final List> specList = Arrays.asList( RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database), (root, query, cb) -> { - final ListJoin rolloutTargetJoin = root - .join(JpaTarget_.rolloutTargetGroup); - return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), - rolloutGroupId); + final ListJoin rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup); + return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), rolloutGroupId); }); return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable); @@ -273,8 +265,7 @@ private Map> getStatusCountItemForRollo private Predicate getRolloutGroupTargetWithRolloutGroupJoinCondition(final long rolloutGroupId, final CriteriaBuilder cb, final Root targetRoot) { - return cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), // - rolloutGroupId); + return cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), rolloutGroupId); } private void throwExceptionIfRolloutGroupDoesNotExist(final Long rolloutGroupId) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java index b70871e671..d5d7f686e4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java @@ -52,6 +52,7 @@ import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; @@ -109,48 +110,57 @@ public class JpaRolloutManagement implements RolloutManagement { RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING, RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.APPROVAL_DENIED); + private final RolloutRepository rolloutRepository; + private final RolloutGroupRepository rolloutGroupRepository; + private final RolloutApprovalStrategy rolloutApprovalStrategy; + private final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction; + private final RolloutStatusCache rolloutStatusCache; + private final ActionRepository actionRepository; private final TargetManagement targetManagement; private final DistributionSetManagement distributionSetManagement; - private final VirtualPropertyReplacer virtualPropertyReplacer; - private final RolloutApprovalStrategy rolloutApprovalStrategy; private final TenantConfigurationManagement tenantConfigurationManagement; - private final SystemSecurityContext systemSecurityContext; + private final QuotaManagement quotaManagement; + private final AfterTransactionCommitExecutor afterCommit; private final EventPublisherHolder eventPublisherHolder; + private final VirtualPropertyReplacer virtualPropertyReplacer; + private final SystemSecurityContext systemSecurityContext; private final ContextAware contextAware; private final Database database; - @Autowired - private RepositoryProperties repositoryProperties; - @Autowired - private RolloutRepository rolloutRepository; - @Autowired - private RolloutGroupRepository rolloutGroupRepository; - @Autowired - private ActionRepository actionRepository; - @Autowired - private AfterTransactionCommitExecutor afterCommit; - @Autowired - private QuotaManagement quotaManagement; - @Autowired - private RolloutStatusCache rolloutStatusCache; - @Autowired - private StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction; - - public JpaRolloutManagement(final TargetManagement targetManagement, - final DistributionSetManagement distributionSetManagement, final EventPublisherHolder eventPublisherHolder, - final VirtualPropertyReplacer virtualPropertyReplacer, final Database database, + private final RepositoryProperties repositoryProperties; + + @SuppressWarnings("java:S107") + public JpaRolloutManagement( + final RolloutRepository rolloutRepository, + final RolloutGroupRepository rolloutGroupRepository, final RolloutApprovalStrategy rolloutApprovalStrategy, + final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction, + final RolloutStatusCache rolloutStatusCache, + final ActionRepository actionRepository, + final TargetManagement targetManagement, + final DistributionSetManagement distributionSetManagement, final TenantConfigurationManagement tenantConfigurationManagement, - final SystemSecurityContext systemSecurityContext, - final ContextAware contextAware) { + final QuotaManagement quotaManagement, + final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder, + final VirtualPropertyReplacer virtualPropertyReplacer, + final SystemSecurityContext systemSecurityContext, final ContextAware contextAware, final Database database, + final RepositoryProperties repositoryProperties) { + this.rolloutRepository = rolloutRepository; + this.rolloutGroupRepository = rolloutGroupRepository; + this.rolloutApprovalStrategy = rolloutApprovalStrategy; + this.startNextRolloutGroupAction = startNextRolloutGroupAction; + this.rolloutStatusCache = rolloutStatusCache; + this.actionRepository = actionRepository; this.targetManagement = targetManagement; this.distributionSetManagement = distributionSetManagement; - this.virtualPropertyReplacer = virtualPropertyReplacer; - this.database = database; - this.rolloutApprovalStrategy = rolloutApprovalStrategy; this.tenantConfigurationManagement = tenantConfigurationManagement; - this.systemSecurityContext = systemSecurityContext; + this.quotaManagement = quotaManagement; + this.afterCommit = afterCommit; this.eventPublisherHolder = eventPublisherHolder; + this.virtualPropertyReplacer = virtualPropertyReplacer; + this.systemSecurityContext = systemSecurityContext; this.contextAware = contextAware; + this.database = database; + this.repositoryProperties = repositoryProperties; } public static String createRolloutLockKey(final String tenant) { @@ -164,7 +174,7 @@ public void publishRolloutGroupCreatedEventAfterCommit(final RolloutGroup group, @Override public long count() { - return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, JpaRollout_.ID))); + return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, AbstractJpaBaseEntity_.ID))); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index b0bbe657da..dce785e94e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -12,7 +12,7 @@ import java.io.Serial; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; +import java.util.EnumMap; import java.util.List; import java.util.Optional; @@ -61,8 +61,9 @@ @Entity @Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout")) @NamedEntityGraphs({ @NamedEntityGraph(name = "Rollout.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }) }) -// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities -@SuppressWarnings("squid:S2160") +// squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities +// java:S1710 - not possible to use without group annotation +@SuppressWarnings({ "squid:S2160", "java:S1710", "java:S1171", "java:S3599" }) public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, EventAwareEntity { @Serial @@ -226,7 +227,7 @@ public void fireDeleteEvent() { public static class RolloutStatusConverter extends MapAttributeConverter { public RolloutStatusConverter() { - super(new HashMap<>() {{ + super(new EnumMap<>(RolloutStatus.class) {{ put(RolloutStatus.CREATING, 0); put(RolloutStatus.READY, 1); put(RolloutStatus.PAUSED, 2); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java index 824b87ef56..0b7ae41408 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java @@ -567,6 +567,7 @@ private List acceptChildren(final LogicalNode node) { return childs; } + @SuppressWarnings("java:S1221") // java:S1221 - intentionally to match the SQL wording private Predicate equal(final Expression expressionToCompare, final String sqlValue) { return cb.equal(caseWise(cb, expressionToCompare), caseWise(sqlValue)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java index 692fc233d6..86b483fa72 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java @@ -288,13 +288,12 @@ private Path getFieldPath(final Root root, final QuertPath queryField) { return fieldPath; } - // if root.get creates a join we call join directly in order to specify LEFT JOIN type, - // to include rows for missing in particular table / criteria (root.get creates INNER JOIN) - // (see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details) - // otherwise delegate to root.get + // if root.get creates a join we call join directly in order to specify LEFT JOIN type, to include rows for missing in particular + // table / criteria (root.get creates INNER JOIN) (see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation + // for more details) otherwise delegate to root.get + @SuppressWarnings("java:S1066") // java:S1066 - better reading this way private Path getPath(final Root root, final String fieldNameSplit) { - // see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details - // when root.get creates a join + // see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details when root.get creates a join final Attribute attribute = root.getModel().getAttribute(fieldNameSplit); if (!attribute.isCollection()) { // it is a SingularAttribute and not join if it is of basic persistent type @@ -393,7 +392,7 @@ private Path getExpressionToCompare(final A enumField, final Path fieldP } return enumField.getSubEntityMapTuple() .map(Entry::getValue) - .map(valueFieldName -> fieldPath. get(valueFieldName)) + .map(fieldPath::get) .orElseThrow(() -> new UnsupportedOperationException( "For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed." + @@ -434,6 +433,7 @@ private List acceptChildren(final LogicalNode node) { return children; } + @SuppressWarnings("java:S1221") // java:S1221 - intentionally to match the SQL wording private Predicate equal(final Path expressionToCompare, final String sqlValue) { if (caseWise(expressionToCompare)) { return cb.equal(cb.upper(expressionToCompare), sqlValue.toUpperCase()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java index 38bd7544e2..201154cacc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java @@ -38,11 +38,11 @@ @Feature("Component Tests - Repository") @Story("Multi Tenancy") @ExtendWith(DisposableSqlTestDatabaseExtension.class) -public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { +class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { @Test @Description(value = "Ensures that multiple targets with same controller-ID can be created for different tenants.") - public void createMultipleTargetsWithSameIdForDifferentTenant() throws Exception { + void createMultipleTargetsWithSameIdForDifferentTenant() throws Exception { // known controller ID for overall tenants same final String knownControllerId = "controllerId"; @@ -64,9 +64,9 @@ public void createMultipleTargetsWithSameIdForDifferentTenant() throws Exception } @Test - @Description(value = "Ensures that targtes created by a tenant are not visible by another tenant.") + @Description(value = "Ensures that targets created by a tenant are not visible by another tenant.") @WithUser(tenantId = "mytenant", allSpPermissions = true) - public void queryTargetFromDifferentTenantIsNotVisible() throws Exception { + void queryTargetFromDifferentTenantIsNotVisible() throws Exception { // create target for another tenant final String anotherTenant = "anotherTenant"; final String controllerAnotherTenant = "anotherController"; @@ -86,7 +86,7 @@ public void queryTargetFromDifferentTenantIsNotVisible() throws Exception { @Test @Description(value = "Ensures that tenant with proper permissions can read and delete other tenants.") @WithUser(tenantId = "mytenant", allSpPermissions = true) - public void deleteAnotherTenantPossible() throws Exception { + void deleteAnotherTenantPossible() throws Exception { // create target for another tenant final String anotherTenant = "anotherTenant"; final String controllerAnotherTenant = "anotherController"; @@ -102,7 +102,7 @@ public void deleteAnotherTenantPossible() throws Exception { @Test @Description(value = "Ensures that tenant metadata is retrieved for the current tenant.") @WithUser(tenantId = "mytenant", autoCreateTenant = false, allSpPermissions = true) - public void getTenanatMetdata() throws Exception { + void getTenanatMetdata() throws Exception { // logged in tenant mytenant - check if tenant default data is // autogenerated @@ -122,7 +122,7 @@ public void getTenanatMetdata() throws Exception { @Test @Description(value = "Ensures that targets created from a different tenant cannot be deleted from other tenants") @WithUser(tenantId = "mytenant", allSpPermissions = true) - public void deleteTargetFromOtherTenantIsNotPossible() throws Exception { + void deleteTargetFromOtherTenantIsNotPossible() throws Exception { // create target for another tenant final String anotherTenant = "anotherTenant"; final String controllerAnotherTenant = "anotherController"; @@ -147,7 +147,7 @@ public void deleteTargetFromOtherTenantIsNotPossible() throws Exception { @Test @Description(value = "Ensures that multiple distribution sets with same name and version can be created for different tenants.") - public void createMultipleDistributionSetsWithSameNameForDifferentTenants() throws Exception { + void createMultipleDistributionSetsWithSameNameForDifferentTenants() throws Exception { // known tenant names final String tenant = "aTenant";