SystemDeleteBulkAction extends AbstractRemoveBulkAction<SysSystemDto, SysSystemFilter> { @Override public ResultModels prevalidate() { IdmBulkActionDto action = getAction(); List<UUID> entities = getEntities(action, new StringBuilder()); ResultModels result = new ResultModels(); Map<ResultModel, Long> models = new HashMap<>(); entities.forEach(systemId -> { AccAccountFilter accountFilter = new AccAccountFilter(); accountFilter.setSystemId(systemId); SysSystemDto system = getService().get(systemId); long count = accountService.count(accountFilter); if (count > 0) { models.put(new DefaultResultModel(AccResultCode.SYSTEM_DELETE_BULK_ACTION_NUMBER_OF_ACCOUNTS, ImmutableMap.of("system", system.getCode(), "count", count)), count); } SysProvisioningOperationFilter operationFilter = new SysProvisioningOperationFilter(); operationFilter.setSystemId(system.getId()); long countEntities = provisioningOperationService.count(operationFilter); if (countEntities > 0) { models.put(new DefaultResultModel(AccResultCode.SYSTEM_DELETE_BULK_ACTION_NUMBER_OF_PROVISIONINGS, ImmutableMap.of("system", system.getCode(), "count", countEntities)), countEntities); } }); List<Entry<ResultModel, Long>> collect = models .entrySet() .stream() .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) .collect(Collectors.toList()); collect.forEach(entry -> { result.addInfo(entry.getKey()); }); return result; }  @Override String getName(); @Override ResultModels prevalidate(); @Override ReadWriteDtoService<SysSystemDto, SysSystemFilter> getService(); static final String NAME; }
@Test public void prevalidationBulkActionByIds() { SysSystemDto system = helper.createSystem(getHelper().createName()); IdmBulkActionDto bulkAction = this.findBulkAction(SysSystem.class, SystemDeleteBulkAction.NAME); bulkAction.getIdentifiers().add(system.getId()); ResultModels resultModels = bulkActionManager.prevalidate(bulkAction); assertEquals(0, resultModels.getInfos().size()); helper.createIdentityAccount(system, getHelper().createIdentity()); resultModels = bulkActionManager.prevalidate(bulkAction); assertEquals(1, resultModels.getInfos().size()); }