Remove not needed JpaDistributionSetType.compatibleToTargetTypes (#2193)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-10 12:58:26 +02:00
committed by GitHub
parent e1f43c8705
commit 0e4efe0987
5 changed files with 15 additions and 70 deletions

View File

@@ -10,7 +10,6 @@
package org.eclipse.hawkbit.mgmt.rest.resource; package org.eclipse.hawkbit.mgmt.rest.resource;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.PagedList;
@@ -119,7 +118,7 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
public ResponseEntity<Void> addCompatibleDistributionSets( public ResponseEntity<Void> addCompatibleDistributionSets(
final Long targetTypeId, final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds) { final Long targetTypeId, final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds) {
targetTypeManagement.assignCompatibleDistributionSetTypes( targetTypeManagement.assignCompatibleDistributionSetTypes(
targetTypeId, distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList())); targetTypeId, distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).toList());
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
} }

View File

@@ -99,15 +99,6 @@ public interface DistributionSetType extends Type {
return getOptionalModuleTypes().stream().anyMatch(element -> element.getId().equals(softwareModuleTypeId)); return getOptionalModuleTypes().stream().anyMatch(element -> element.getId().equals(softwareModuleTypeId));
} }
/**
* Compares the modules of this {@link DistributionSetType} and the given
* one.
*
* @param dsType to compare with
* @return <code>true</code> if the lists are identical.
*/
boolean areModuleEntriesIdentical(DistributionSetType dsType);
/** /**
* @param distributionSet to check for completeness * @param distributionSet to check for completeness
* @return <code>true</code> if the all mandatory software module types are * @return <code>true</code> if the all mandatory software module types are

View File

@@ -13,6 +13,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.ToLongFunction;
import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.TargetTypeFields; import org.eclipse.hawkbit.repository.TargetTypeFields;
@@ -197,7 +198,7 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
} }
final JpaTargetType type = getByIdAndThrowIfNotFound(id); final JpaTargetType type = getByIdAndThrowIfNotFound(id);
assertDistributionSetTypeQuota(id, distributionSetTypeIds.size()); assertDistributionSetTypeQuota(id, distributionSetTypeIds.size(), typeId -> type.getCompatibleDistributionSetTypes().size());
dsTypes.forEach(type::addCompatibleDistributionSetType); dsTypes.forEach(type::addCompatibleDistributionSetType);
return targetTypeRepository.save(type); return targetTypeRepository.save(type);
@@ -224,7 +225,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
private JpaTargetType getByIdAndThrowIfNotFound(final Long id) { private JpaTargetType getByIdAndThrowIfNotFound(final Long id) {
return targetTypeRepository return targetTypeRepository
.findById(id).orElseThrow(() -> new EntityNotFoundException(TargetType.class, id)); .findById(id)
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, id));
} }
/** /**
@@ -235,8 +237,9 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
* @param requested number of distribution set types to check * @param requested number of distribution set types to check
* @throws AssignmentQuotaExceededException if the software module type quota is exceeded * @throws AssignmentQuotaExceededException if the software module type quota is exceeded
*/ */
private void assertDistributionSetTypeQuota(final long id, final int requested) { private void assertDistributionSetTypeQuota(final long id, final int requested, final ToLongFunction<Long> countFct) {
QuotaHelper.assertAssignmentQuota(id, requested, quotaManagement.getMaxDistributionSetTypesPerTargetType(), QuotaHelper.assertAssignmentQuota(
DistributionSetType.class, TargetType.class, targetTypeRepository::countDsSetTypesById); id, requested, quotaManagement.getMaxDistributionSetTypesPerTargetType(),
DistributionSetType.class, TargetType.class, countFct);
} }
} }

View File

@@ -60,7 +60,7 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis
@OneToMany( @OneToMany(
mappedBy = "dsType", targetEntity = DistributionSetTypeElement.class, mappedBy = "dsType", targetEntity = DistributionSetTypeElement.class,
fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE }, orphanRemoval = true) cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE }, orphanRemoval = true)
private Set<DistributionSetTypeElement> elements = new HashSet<>(); private Set<DistributionSetTypeElement> elements = new HashSet<>();
@Setter @Setter
@@ -68,9 +68,6 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis
@Column(name = "deleted") @Column(name = "deleted")
private boolean deleted; private boolean deleted;
@ManyToMany(mappedBy = "distributionSetTypes", targetEntity = JpaTargetType.class, fetch = FetchType.LAZY)
private List<TargetType> compatibleToTargetTypes;
public JpaDistributionSetType(final String key, final String name, final String description) { public JpaDistributionSetType(final String key, final String name, final String description) {
this(key, name, description, null); this(key, name, description, null);
} }
@@ -95,21 +92,6 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@Override
public boolean areModuleEntriesIdentical(final DistributionSetType dsType) {
if (dsType instanceof JpaDistributionSetType jpaDsType) {
if (isOneModuleListEmpty(jpaDsType)) {
return false;
} else if (areBothModuleListsEmpty(jpaDsType)) {
return true;
} else {
return new HashSet<>(jpaDsType.elements).equals(elements);
}
} else {
return false;
}
}
@Override @Override
public boolean checkComplete(final DistributionSet distributionSet) { public boolean checkComplete(final DistributionSet distributionSet) {
final List<SoftwareModuleType> smTypes = distributionSet.getModules().stream() final List<SoftwareModuleType> smTypes = distributionSet.getModules().stream()
@@ -163,15 +145,6 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis
getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId())); getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
} }
private boolean isOneModuleListEmpty(final JpaDistributionSetType dsType) {
return (!CollectionUtils.isEmpty(dsType.elements) && CollectionUtils.isEmpty(elements)) ||
(CollectionUtils.isEmpty(dsType.elements) && !CollectionUtils.isEmpty(elements));
}
private boolean areBothModuleListsEmpty(final JpaDistributionSetType dsType) {
return CollectionUtils.isEmpty(dsType.elements) && CollectionUtils.isEmpty(elements);
}
private JpaDistributionSetType setModuleType(final SoftwareModuleType smType, final boolean mandatory) { private JpaDistributionSetType setModuleType(final SoftwareModuleType smType, final boolean mandatory) {
if (elements.isEmpty()) { if (elements.isEmpty()) {
elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, mandatory)); elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, mandatory));

View File

@@ -22,36 +22,15 @@ import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* {@link PagingAndSortingRepository} and {@link org.springframework.data.repository.CrudRepository} for * {@link PagingAndSortingRepository} and {@link org.springframework.data.repository.CrudRepository} for {@link JpaTargetType}.
* {@link JpaTargetType}.
*/ */
@Transactional(readOnly = true) @Transactional(readOnly = true)
public interface TargetTypeRepository public interface TargetTypeRepository extends BaseEntityRepository<JpaTargetType> {
extends BaseEntityRepository<JpaTargetType> {
/**
* Counts the distributions set types compatible with that type
* <p/>
* No access control applied.
*
* @param id target type id
* @return the count
*/
@Query(value = "SELECT COUNT (t.id) FROM JpaDistributionSetType t JOIN t.compatibleToTargetTypes tt WHERE tt.id = :id")
long countDsSetTypesById(@Param("id") Long id);
/**
* @param dsTypeId to search for
* @return all {@link TargetType}s in the repository with given
* {@link TargetType#getName()}
*/
default List<JpaTargetType> findByDsType(@Param("id") final Long dsTypeId) { default List<JpaTargetType> findByDsType(@Param("id") final Long dsTypeId) {
return findAll(Specification.where(TargetTypeSpecification.hasDsSetType(dsTypeId))); return findAll(Specification.where(TargetTypeSpecification.hasDsSetType(dsTypeId)));
} }
/**
* @param tenant Tenant
*/
@Modifying @Modifying
@Transactional @Transactional
@Query("DELETE FROM JpaTargetType t WHERE t.tenant = :tenant") @Query("DELETE FROM JpaTargetType t WHERE t.tenant = :tenant")