Passed
Pull Request — dev (#364)
by
unknown
05:28
created

QuizzesMapper()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.95
cc 1
1
package easytests.api.v1.mappers;
2
3
import easytests.api.v1.models.Quiz;
4
import easytests.api.v1.models.Testee;
0 ignored issues
show
Unused Code introduced by
Remove this unused import 'easytests.api.v1.models.Testee'.
Loading history...
5
import easytests.core.models.QuizModel;
6
import easytests.core.models.TesteeModel;
0 ignored issues
show
Unused Code introduced by
Remove this unused import 'easytests.core.models.TesteeModel'.
Loading history...
7
import easytests.core.models.TesteeModelInterface;
0 ignored issues
show
Unused Code introduced by
Remove this unused import 'easytests.core.models.TesteeModelInterface'.
Loading history...
8
import easytests.core.models.empty.ModelsListEmpty;
9
import easytests.core.models.empty.TesteeModelEmpty;
0 ignored issues
show
Unused Code introduced by
Remove this unused import 'easytests.core.models.empty.TesteeModelEmpty'.
Loading history...
10
import org.modelmapper.ModelMapper;
11
import org.springframework.stereotype.Service;
12
13
import javax.print.attribute.standard.Destination;
0 ignored issues
show
Unused Code introduced by
Remove this unused import 'javax.print.attribute.standard.Destination'.
Loading history...
14
import java.time.LocalDateTime;
15
import java.time.format.DateTimeFormatter;
16
17
18
/**
19
 * @author miron97
20
 */
21
@Service("QuizzesMapperV1")
22
public class QuizzesMapper extends ModelMapper {
23
    public QuizzesMapper() {
24
        super();
25
        this.createTypeMap(QuizModel.class, Quiz.class)
26
                .addMappings(mapper -> mapper.when(context -> !(context.getSource() instanceof ModelsListEmpty))
27
                        .<Integer>map(quizModel -> quizModel.getTestee().getId(), (quiz, id) -> quiz.getTestee().setId(id)))
28
                .addMappings(mapper -> mapper.using(src -> ((LocalDateTime)src.getSource()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "Z")
29
                        .<String>map(QuizModel::getStartedAt, (quiz, startedAt) -> quiz.setStartedAt(startedAt)))
30
                .addMappings(mapper -> mapper.using(src -> ((LocalDateTime)src.getSource()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "Z")
31
                        .<String>map(QuizModel::getFinishedAt, (quiz, finishedAt) -> quiz.setFinishedAt(finishedAt)));
32
    }
33
}
34