Remove not needed JpaDistributionSetType.compatibleToTargetTypes (#2193)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -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 class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
|
||||
public ResponseEntity<Void> addCompatibleDistributionSets(
|
||||
final Long targetTypeId, final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds) {
|
||||
targetTypeManagement.assignCompatibleDistributionSetTypes(
|
||||
targetTypeId, distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()));
|
||||
targetTypeId, distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).toList());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,19 +99,10 @@ public interface DistributionSetType extends Type {
|
||||
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
|
||||
* @return <code>true</code> if the all mandatory software module types are
|
||||
* in the system.
|
||||
*/
|
||||
boolean checkComplete(DistributionSet distributionSet);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import java.util.Collection;
|
||||
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 class JpaTargetTypeManagement implements TargetTypeManagement {
|
||||
}
|
||||
|
||||
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 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
|
||||
|
||||
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 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
|
||||
* @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<Long> countFct) {
|
||||
QuotaHelper.assertAssignmentQuota(
|
||||
id, requested, quotaManagement.getMaxDistributionSetTypesPerTargetType(),
|
||||
DistributionSetType.class, TargetType.class, countFct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<DistributionSetTypeElement> 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<TargetType> compatibleToTargetTypes;
|
||||
|
||||
public JpaDistributionSetType(final String key, final String name, final String description) {
|
||||
this(key, name, description, null);
|
||||
}
|
||||
@@ -95,21 +92,6 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis
|
||||
.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<SoftwareModuleType> smTypes = distributionSet.getModules().stream()
|
||||
@@ -163,15 +145,6 @@ public class JpaDistributionSetType extends AbstractJpaTypeEntity implements Dis
|
||||
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));
|
||||
|
||||
@@ -22,38 +22,17 @@ import org.springframework.data.repository.query.Param;
|
||||
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<JpaTargetType> {
|
||||
public interface TargetTypeRepository 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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user