Fix Sonar Findings (#2584)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -121,6 +121,7 @@ public interface TargetTypeManagement<T extends TargetType>
|
||||
|
||||
private Set<DistributionSetType> distributionSetTypes;
|
||||
|
||||
@SuppressWarnings("java:S1144") // java:S1144 - constructor is actually used by SuperBuilder's build() method
|
||||
private Create(final CreateBuilder<?, ?> builder) {
|
||||
super(builder);
|
||||
if (builder.key == null && builder.name == null) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.PropertiesQuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
@@ -99,7 +98,6 @@ import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGrou
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RsqlUtility;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -305,7 +303,7 @@ public class JpaRepositoryConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
TargetBuilder targetBuilder(final TargetTypeManagement targetTypeManagement) {
|
||||
TargetBuilder targetBuilder(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
return new JpaTargetBuilder(targetTypeManagement);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,16 @@ import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
|
||||
/**
|
||||
* Builder implementation for {@link Target}.
|
||||
*/
|
||||
public class JpaTargetBuilder implements TargetBuilder {
|
||||
|
||||
private final TargetTypeManagement targetTypeManagement;
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
|
||||
public JpaTargetBuilder(TargetTypeManagement targetTypeManagement) {
|
||||
public JpaTargetBuilder(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
|
||||
// TODO - make it final
|
||||
private TargetRepository targetRepository;
|
||||
private final TargetTypeManagement targetTypeManagement;
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
private final ConfirmationManagement confirmationManagement;
|
||||
private final SoftwareModuleRepository softwareModuleRepository;
|
||||
@@ -159,7 +159,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
protected JpaControllerManagement(
|
||||
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement,
|
||||
final RepositoryProperties repositoryProperties,
|
||||
final TargetRepository targetRepository, final TargetTypeManagement targetTypeManagement,
|
||||
final TargetRepository targetRepository, final TargetTypeManagement<? extends TargetType> targetTypeManagement,
|
||||
final DeploymentManagement deploymentManagement, final ConfirmationManagement confirmationManagement,
|
||||
final SoftwareModuleRepository softwareModuleRepository,
|
||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
||||
@@ -764,10 +764,10 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores target directly to DB in case either {@link Target#getAddress()}
|
||||
* or {@link Target#getUpdateStatus()} or {@link Target#getName()} changes
|
||||
* or the buffer queue is full.
|
||||
* Stores target directly to DB in case either {@link Target#getAddress()} or {@link Target#getUpdateStatus()} or {@link Target#getName()}
|
||||
* changes or the buffer queue is full.
|
||||
*/
|
||||
@SuppressWarnings("java:S3776") // it's just complex
|
||||
private Target updateTarget(final JpaTarget toUpdate, final URI address, final String name, final String type) {
|
||||
if (isStoreEager(toUpdate, address, name, type) || !queue.offer(new TargetPoll(toUpdate))) {
|
||||
if (isAddressChanged(toUpdate.getAddress(), address)) {
|
||||
@@ -779,13 +779,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
|
||||
if (isTypeChanged(toUpdate.getTargetType(), type)) {
|
||||
if (StringUtils.hasText(type)) {
|
||||
var targetTypeOptional = getTargetType(type);
|
||||
final Optional<TargetType> targetTypeOptional = getTargetType(type);
|
||||
if (targetTypeOptional.isPresent()) {
|
||||
log.debug("Updating target type for thing ID \"{}\" to \"{}\".", toUpdate.getControllerId(), type);
|
||||
toUpdate.setTargetType(targetTypeOptional.get());
|
||||
} else {
|
||||
log.error("Target type with the provided name \"{}\" was not found. Target type for thing ID" +
|
||||
" \"{}\" will not be updated", type, toUpdate.getControllerId());
|
||||
log.error(
|
||||
"Target type with the provided name \"{}\" was not found. Target type for thing ID \"{}\" will not be updated",
|
||||
type, toUpdate.getControllerId());
|
||||
}
|
||||
} else {
|
||||
log.debug("Removing target type assignment for thing ID \"{}\".", toUpdate.getControllerId());
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -27,11 +26,6 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.MapJoin;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.persistence.metamodel.MapAttribute;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
@@ -42,14 +36,12 @@ import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.DeletedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
@@ -506,24 +498,6 @@ public class JpaDistributionSetManagement
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getMap(final long id, final MapAttribute<JpaDistributionSet, String, String> mapAttribute) {
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
|
||||
|
||||
final Root<JpaDistributionSet> targetRoot = query.from(JpaDistributionSet.class);
|
||||
query.where(cb.equal(targetRoot.get(AbstractJpaBaseEntity_.ID), id));
|
||||
|
||||
final MapJoin<JpaDistributionSet, String, String> mapJoin = targetRoot.join(mapAttribute);
|
||||
query.multiselect(mapJoin.key(), mapJoin.value());
|
||||
query.orderBy(cb.asc(mapJoin.key()));
|
||||
|
||||
return entityManager
|
||||
.createQuery(query)
|
||||
.getResultList()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(entry -> (String) entry[0], entry -> (String) entry[1], (v1, v2) -> v1, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
private JpaSoftwareModule findSoftwareModuleAndThrowExceptionIfNotFound(final Long softwareModuleId) {
|
||||
return softwareModuleRepository.findById(softwareModuleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
|
||||
Reference in New Issue
Block a user