class 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);
			}
		});

		// Sort by count
		List<Entry<ResultModel, Long>> collect = models //
				.entrySet() //
				.stream() //
				.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) //
				// .limit(5) //
				.collect(Collectors.toList()); //
		collect.forEach(entry -> {
			result.addInfo(entry.getKey());
		});

		return result;
	}

}