class ErrorTransformer {

    ErrorWithProblemsDTO toDto(Error error) {
        ErrorWithProblemsDTO result = new ErrorWithProblemsDTO();
        result.setId(0L);
        if (null != error) {
            result.setId(error.getId());
            result.setStep(error.getStep());
            result.setStepDefinition(error.getStepDefinition());
            result.setStepLine(error.getStepLine());
            result.setException(error.getException());

            List<Problem> problems = error.getProblemPatterns().stream()
                    .map(ProblemPattern::getProblem)
                    .sorted(Comparator.nullsLast(Problem::compareTo))
                    .distinct()
                    .collect(Collectors.toList());
            result.setProblems(problemTransformer.toDtos(problems));
        }
        return result;
    }

}