Remove Deprecations - SoftwareModuleMangement (#1870)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-10-04 15:29:58 +03:00
committed by GitHub
parent d953ec5c7d
commit 56139fea12
3 changed files with 0 additions and 271 deletions

View File

@@ -44,23 +44,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
public interface SoftwareModuleManagement
extends RepositoryManagement<SoftwareModule, SoftwareModuleCreate, SoftwareModuleUpdate> {
/**
* Counts {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* and {@link SoftwareModule#getType()} that are not marked as deleted.
*
* @param searchText
* to search for in name and version
* @param typeId
* to filter the result by type
* @return number of found {@link SoftwareModule}s
*
* @throws EntityNotFoundException
* if software module type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countByTextAndType(String searchText, Long typeId);
/**
* Creates a list of software module meta data entries.
*
@@ -281,37 +264,6 @@ public interface SoftwareModuleManagement
Page<SoftwareModuleMetadata> findMetaDataByRsql(@NotNull Pageable pageable, long id,
@NotNull String rsqlParam);
/**
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* search text and {@link SoftwareModule#getType()} that are not marked as
* deleted and sort them by means of given distribution set related modules
* on top of the list.
*
* After that the modules are sorted by by default by
* {@link SoftwareModule#getName()} and {@link SoftwareModule#getVersion()}
* in ascending order if no other sorting is provided in {@link Pageable}.
* If sorting is provided in {@link Pageable} parameter the provided sorting
* is used.
*
* @param pageable
* page parameter
* @param orderByDistributionSetId
* the ID of distribution set to be ordered on top
* @param searchText
* filtered as "like" on {@link SoftwareModule#getName()}
* @param typeId
* filtered as "equal" on {@link SoftwareModule#getType()}
*
* @return the page of found {@link SoftwareModule}
*
* @throws EntityNotFoundException
* if given software module type does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<AssignedSoftwareModule> findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
@NotNull Pageable pageable, long orderByDistributionSetId, String searchText, Long typeId);
/**
* Retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType}
* .

View File

@@ -93,7 +93,6 @@ import org.springframework.validation.annotation.Validated;
/**
* JPA implementation of {@link SoftwareModuleManagement}.
*
*/
@Transactional(readOnly = true)
@Validated
@@ -332,129 +331,6 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
smFilterNameAndVersionEntries[1]);
}
/**
* @deprecated Used only in UI which is to be removed
*/
@Deprecated(forRemoval = true)
@Override
// In the interface org.springframework.data.domain.Pageable.getSort the
// return value is not guaranteed to be non-null, therefore a null check is
// necessary otherwise we rely on the implementation but this could change.
@SuppressWarnings({ "squid:S2583", "squid:S2589" })
public Slice<AssignedSoftwareModule> findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
final Pageable pageable, final long orderByDistributionSetId, final String searchText, final Long typeId) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Tuple> query = cb.createTupleQuery();
final Root<JpaSoftwareModule> smRoot = query.from(JpaSoftwareModule.class);
final ListJoin<JpaSoftwareModule, JpaDistributionSet> assignedDsList = smRoot
.join(JpaSoftwareModule_.assignedTo, JoinType.LEFT);
final Expression<Integer> assignedCaseMax = cb.max(
cb.<Long, Integer> selectCase(assignedDsList.get(JpaDistributionSet_.id)).when(orderByDistributionSetId, 1).otherwise(0));
query.multiselect(smRoot.alias("sm"), assignedCaseMax.alias("assigned"));
final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, typeId),
smRoot, query, cb);
if (specPredicate.length > 0) {
query.where(specPredicate);
}
query.groupBy(smRoot);
final Sort sort = pageable.getSort();
final List<Order> orders = new ArrayList<>();
orders.add(cb.desc(assignedCaseMax));
if (sort == null || sort.isEmpty()) {
orders.add(cb.asc(smRoot.get(JpaSoftwareModule_.name)));
orders.add(cb.asc(smRoot.get(JpaSoftwareModule_.version)));
} else {
orders.addAll(QueryUtils.toOrders(sort, smRoot, cb));
}
query.orderBy(orders);
final int pageSize = pageable.getPageSize();
final List<Tuple> smWithAssignedFlagList = entityManager.createQuery(query)
.setFirstResult((int) pageable.getOffset()).setMaxResults(pageSize).getResultList();
final boolean hasNext = smWithAssignedFlagList.size() > pageSize;
final List<AssignedSoftwareModule> resultList = new ArrayList<>();
smWithAssignedFlagList.forEach(smWithAssignedFlag -> {
final JpaSoftwareModule softwareModule = smWithAssignedFlag.get("sm", JpaSoftwareModule.class);
try {
// check read access
if (softwareModuleRepository.getAccessController().map(accessController -> {
try {
accessController.assertOperationAllowed(AccessController.Operation.READ, softwareModule);
return true;
} catch (final InsufficientPermissionException e) {
return false;
}
}).orElse(true)) {
resultList.add(new AssignedSoftwareModule(softwareModule,
smWithAssignedFlag.get("assigned", Number.class).longValue() == 1));
}
} catch (final InsufficientPermissionException e) {
// skip the entry
}
});
return new SliceImpl<>(Collections.unmodifiableList(resultList), pageable, hasNext);
}
private List<Specification<JpaSoftwareModule>> buildSpecificationList(final String searchText, final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
if (!ObjectUtils.isEmpty(searchText)) {
specList.add(buildSmSearchQuerySpec(searchText));
}
if (typeId != null) {
assertSoftwareModuleTypeExists(typeId);
specList.add(SoftwareModuleSpecification.equalType(typeId));
}
specList.add(SoftwareModuleSpecification.isNotDeleted());
return specList;
}
private Predicate[] specificationsToPredicate(final List<Specification<JpaSoftwareModule>> specifications,
final Root<JpaSoftwareModule> root, final CriteriaQuery<?> query, final CriteriaBuilder cb,
final Predicate... additionalPredicates) {
return Stream.concat(specifications.stream().map(spec -> spec.toPredicate(root, query, cb)),
Arrays.stream(additionalPredicates)).toArray(Predicate[]::new);
}
/**
* No access control applied
*
* @deprecated Used only in UI which is to be removed
*/
@Deprecated(forRemoval = true)
@Override
public long countByTextAndType(final String searchText, final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.isNotDeleted();
specList.add(spec);
if (!ObjectUtils.isEmpty(searchText)) {
specList.add(buildSmSearchQuerySpec(searchText));
}
if (null != typeId) {
assertSoftwareModuleTypeExists(typeId);
spec = SoftwareModuleSpecification.equalType(typeId);
specList.add(spec);
}
return JpaManagementHelper.countBySpec(softwareModuleRepository, specList);
}
@Override
public Page<SoftwareModule> findByAssignedTo(final Pageable pageable, final long distributionSetId) {
assertDistributionSetExists(distributionSetId);

View File

@@ -528,105 +528,6 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
}
}
@Test
@Description("Test verifies that results are returned based on given filter parameters and in the specified order.")
public void findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc() {
// test meta data
final SoftwareModuleType testType = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100));
DistributionSetType testDsType = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("key").name("name"));
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(),
Collections.singletonList(osType.getId()));
testDsType = distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(testDsType.getId(),
Collections.singletonList(testType.getId()));
// found in test
final SoftwareModule unassigned = testdataFactory.createSoftwareModule("thetype", "unassignedfound", false);
final SoftwareModule one = testdataFactory.createSoftwareModule("thetype", "bfound", false);
final SoftwareModule two = testdataFactory.createSoftwareModule("thetype", "cfound", false);
final SoftwareModule differentName = testdataFactory.createSoftwareModule("thetype", "a", false);
// ignored
final SoftwareModule deleted = testdataFactory.createSoftwareModule("thetype", "deleted", false);
final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e");
final DistributionSet set = distributionSetManagement
.create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(
List.of(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
softwareModuleManagement.delete(deleted.getId());
// with filter on name, version and module type
assertThat(softwareModuleManagement.findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
set.getId(), "%found%", testType.getId()).getContent())
.as("Found modules with given name, given module type and the assigned ones first")
.containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true),
new AssignedSoftwareModule(unassigned, false));
// with filter on name, version and module type, sorting defined by
// Pagerequest
assertThat(softwareModuleManagement.findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
PageRequest.of(0, 500, Sort.by(Direction.DESC, "name")), set.getId(), "%found%", testType.getId())
.getContent())
.as("Found modules with given name, given module type, the assigned ones first, ordered by name DESC")
.containsExactly(new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(one, true),
new AssignedSoftwareModule(unassigned, false));
// with filter on module type only
assertThat(softwareModuleManagement
.findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, testType.getId())
.getContent()).as("Found modules with given module type and the assigned ones first")
.containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true),
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(unassigned, false));
// without any filter
assertThat(softwareModuleManagement
.findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, null)
.getContent()).as("Found modules with the assigned ones first")
.containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true),
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(four, true),
new AssignedSoftwareModule(unassigned, false));
}
@Test
@Description("Checks that number of modules is returned as expected based on given filters.")
public void countSoftwareModuleByFilters() {
// test meta data
final SoftwareModuleType testType = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100));
DistributionSetType testDsType = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("key").name("name"));
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(),
Collections.singletonList(osType.getId()));
testDsType = distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(testDsType.getId(),
Collections.singletonList(testType.getId()));
// found in test
testdataFactory.createSoftwareModule("thetype", "unassignedfound", false);
final SoftwareModule one = testdataFactory.createSoftwareModule("thetype", "bfound", false);
final SoftwareModule two = testdataFactory.createSoftwareModule("thetype", "cfound", false);
final SoftwareModule differentName = testdataFactory.createSoftwareModule("thetype", "d", false);
// ignored
final SoftwareModule deleted = testdataFactory.createSoftwareModule("thetype", "deleted", false);
final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e");
distributionSetManagement
.create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(
List.of(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
softwareModuleManagement.delete(deleted.getId());
// test
assertThat(softwareModuleManagement.countByTextAndType("%found%", testType.getId()))
.as("Number of modules with given name or version and type").isEqualTo(3);
assertThat(softwareModuleManagement.countByTextAndType(null, testType.getId()))
.as("Number of modules with given type").isEqualTo(4);
assertThat(softwareModuleManagement.countByTextAndType(null, null)).as("Number of modules overall")
.isEqualTo(5);
}
@Test
@Description("Verfies that all undeleted software modules are found in the repository.")
public void countSoftwareModuleTypesAll() {