com.osomapps.pt.goals.GoalService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 33
dl 0
loc 37
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findAll() 0 27 2
A GoalService(GoalRepository,DictionaryService) 0 3 1
1
package com.osomapps.pt.goals;
2
3
import com.osomapps.pt.dictionary.DictionaryName;
4
import com.osomapps.pt.dictionary.DictionaryService;
5
import java.util.List;
6
import java.util.stream.Collectors;
7
import org.springframework.stereotype.Service;
8
9
@Service
10
class GoalService {
11
    private final GoalRepository goalRepository;
12
    private final DictionaryService dictionaryService;
13
14
    GoalService(GoalRepository goalRepository, DictionaryService dictionaryService) {
15
        this.goalRepository = goalRepository;
16
        this.dictionaryService = dictionaryService;
17
    }
18
19
    List<GoalDTO> findAll() {
20
        List<Goal> goals = goalRepository.findAll();
21
        return goals.stream()
22
                .map(
23
                        goal ->
24
                                new GoalDTO()
25
                                        .setId(goal.getId())
26
                                        .setTitle(
27
                                                dictionaryService.getEnValue(
28
                                                        DictionaryName.goal_title,
29
                                                        goal.getDGoalTitle(),
30
                                                        null))
31
                                        .setTitle2(
32
                                                dictionaryService.getEnValue(
33
                                                        DictionaryName.goal_title_2,
34
                                                        goal.getDGoalTitle2(),
35
                                                        null))
36
                                        .setType(
37
                                                goal.getGoalType() == null
38
                                                        ? null
39
                                                        : goal.getGoalType().getName())
40
                                        .setParameters(
41
                                                goal.getGoalParameters().stream()
42
                                                        .map(parameter -> parameter.getName())
43
                                                        .collect(Collectors.toList())))
44
                .sorted((e1, e2) -> Long.compare(e1.getId(), e2.getId()))
45
                .collect(Collectors.toList());
46
    }
47
}
48