diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java index 267bcbb02d..b5192619c0 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import java.util.List; -import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.mgmt.json.model.PagedList; @@ -119,7 +118,7 @@ public ResponseEntity removeCompatibleDistributionSet(final Long targetTyp public ResponseEntity addCompatibleDistributionSets( final Long targetTypeId, final List distributionSetTypeIds) { targetTypeManagement.assignCompatibleDistributionSetTypes( - targetTypeId, distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList())); + targetTypeId, distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).toList()); return ResponseEntity.ok().build(); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index d8673a288f..7ab6edf7c4 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -99,19 +99,10 @@ default boolean containsOptionalModuleType(final Long 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 true if the lists are identical. - */ - boolean areModuleEntriesIdentical(DistributionSetType dsType); - /** * @param distributionSet to check for completeness * @return true if the all mandatory software module types are * in the system. */ boolean checkComplete(DistributionSet distributionSet); -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java index 94a70ad6e0..0ce1e8b600 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java @@ -13,6 +13,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.function.ToLongFunction; import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.TargetTypeFields; @@ -197,7 +198,7 @@ public TargetType assignCompatibleDistributionSetTypes(final long id, } final JpaTargetType type = getByIdAndThrowIfNotFound(id); - assertDistributionSetTypeQuota(id, distributionSetTypeIds.size()); + assertDistributionSetTypeQuota(id, distributionSetTypeIds.size(), typeId -> type.getCompatibleDistributionSetTypes().size()); dsTypes.forEach(type::addCompatibleDistributionSetType); return targetTypeRepository.save(type); @@ -224,7 +225,8 @@ private void assertDistributionSetTypeExists(final Long typeId) { private JpaTargetType getByIdAndThrowIfNotFound(final Long id) { return targetTypeRepository - .findById(id).orElseThrow(() -> new EntityNotFoundException(TargetType.class, id)); + .findById(id) + .orElseThrow(() -> new EntityNotFoundException(TargetType.class, id)); } /** @@ -235,8 +237,9 @@ private JpaTargetType getByIdAndThrowIfNotFound(final Long id) { * @param requested number of distribution set types to check * @throws AssignmentQuotaExceededException if the software module type quota is exceeded */ - private void assertDistributionSetTypeQuota(final long id, final int requested) { - QuotaHelper.assertAssignmentQuota(id, requested, quotaManagement.getMaxDistributionSetTypesPerTargetType(), - DistributionSetType.class, TargetType.class, targetTypeRepository::countDsSetTypesById); + private void assertDistributionSetTypeQuota(final long id, final int requested, final ToLongFunction countFct) { + QuotaHelper.assertAssignmentQuota( + id, requested, quotaManagement.getMaxDistributionSetTypesPerTargetType(), + DistributionSetType.class, TargetType.class, countFct); } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java index 9a885b127f..5964b1a4fc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java @@ -60,7 +60,7 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis @OneToMany( 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 elements = new HashSet<>(); @Setter @@ -68,9 +68,6 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis @Column(name = "deleted") private boolean deleted; - @ManyToMany(mappedBy = "distributionSetTypes", targetEntity = JpaTargetType.class, fetch = FetchType.LAZY) - private List compatibleToTargetTypes; - public JpaDistributionSetType(final String key, final String name, final String description) { this(key, name, description, null); } @@ -95,21 +92,6 @@ public Set getOptionalModuleTypes() { .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 public boolean checkComplete(final DistributionSet distributionSet) { final List smTypes = distributionSet.getModules().stream() @@ -163,15 +145,6 @@ public void fireDeleteEvent() { 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) { if (elements.isEmpty()) { elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, mandatory)); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetTypeRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetTypeRepository.java index edced60d51..52ccd9de0b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetTypeRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetTypeRepository.java @@ -22,38 +22,17 @@ import org.springframework.transaction.annotation.Transactional; /** - * {@link PagingAndSortingRepository} and {@link org.springframework.data.repository.CrudRepository} for - * {@link JpaTargetType}. + * {@link PagingAndSortingRepository} and {@link org.springframework.data.repository.CrudRepository} for {@link JpaTargetType}. */ @Transactional(readOnly = true) -public interface TargetTypeRepository - extends BaseEntityRepository { +public interface TargetTypeRepository extends BaseEntityRepository { - /** - * Counts the distributions set types compatible with that type - *

- * 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 findByDsType(@Param("id") final Long dsTypeId) { return findAll(Specification.where(TargetTypeSpecification.hasDsSetType(dsTypeId))); } - /** - * @param tenant Tenant - */ @Modifying @Transactional @Query("DELETE FROM JpaTargetType t WHERE t.tenant = :tenant") void deleteByTenant(@Param("tenant") String tenant); -} +} \ No newline at end of file