23
23
import ch .xxx .maps .domain .model .dto .LocationDto ;
24
24
import ch .xxx .maps .domain .model .dto .PolygonDto ;
25
25
import ch .xxx .maps .domain .model .dto .RingDto ;
26
- import ch .xxx .maps .domain .model .dto .Tuple ;
27
26
import ch .xxx .maps .domain .model .entity .CompanySite ;
28
27
import ch .xxx .maps .domain .model .entity .Location ;
29
28
import ch .xxx .maps .domain .model .entity .Polygon ;
33
32
public class EntityDtoMapper {
34
33
35
34
public CompanySite mapToEntity (CompanySiteDto dto , CompanySite entity ) {
35
+ record Polygons (PolygonDto dto , Polygon entity ) {};
36
36
entity .setAtDate (dto .getAtDate () == null ? LocalDate .now () : dto .getAtDate ());
37
37
entity .setTitle (dto .getTitle ());
38
- entity .setPolygons (dto .getPolygons ().stream ().flatMap (myPolygonDto -> Stream .of (new Tuple < PolygonDto , Polygon > (
38
+ entity .setPolygons (dto .getPolygons ().stream ().flatMap (myPolygonDto -> Stream .of (new Polygons (
39
39
myPolygonDto ,
40
40
entity .getPolygons ().stream ()
41
41
.filter (myPolygon -> myPolygon .getId () != null && entity .getId () != null
42
42
&& myPolygon .getId ().equals (myPolygonDto .getId ()))
43
43
.findFirst ().orElse (new Polygon ()))))
44
- .flatMap (tuple -> Stream .of (this .mapToEntity (tuple . getA (), tuple . getB (), entity )))
44
+ .flatMap (myRecord -> Stream .of (this .mapToEntity (myRecord . dto (), myRecord . entity (), entity )))
45
45
.collect (Collectors .toSet ()));
46
46
return entity ;
47
47
}
48
48
49
49
public Polygon mapToEntity (PolygonDto dto , Polygon entity , CompanySite companySite ) {
50
+ record Rings (RingDto dto , Ring entity ) {};
50
51
entity .setBorderColor (dto .getBorderColor ());
51
52
entity .setLatitude (dto .getLatitude ());
52
53
entity .setLongitude (dto .getLongitude ());
@@ -55,28 +56,29 @@ public Polygon mapToEntity(PolygonDto dto, Polygon entity, CompanySite companySi
55
56
entity .setTitle (dto .getTitle ());
56
57
entity .setRings (
57
58
dto .getRings ().stream ()
58
- .flatMap (myRingDto -> Stream .of (new Tuple < RingDto , Ring > (myRingDto , entity .getRings ().stream ()
59
+ .flatMap (myRingDto -> Stream .of (new Rings (myRingDto , entity .getRings ().stream ()
59
60
.filter (myRing -> myRing .getId () != null && myRingDto .getId () != null
60
61
&& myRing .getId ().equals (myRingDto .getId ()))
61
62
.findFirst ().orElse (new Ring ()))))
62
- .flatMap (myTuple -> Stream .of (this .mapToEntity (myTuple .getA (), myTuple .getB (), entity )))
63
+ .flatMap (myTuple -> Stream .of (this .mapToEntity (myTuple .dto (), myTuple .entity (), entity )))
63
64
.collect (Collectors .toSet ()));
64
65
return entity ;
65
66
}
66
67
67
68
public Ring mapToEntity (RingDto dto , Ring entity , Polygon polygon ) {
69
+ record Locations (LocationDto dto , Location entity ) { };
68
70
for (int i = 0 ; i < dto .getLocations ().size (); i ++) {
69
71
dto .getLocations ().get (i ).setOrderId (i + 1 );
70
72
}
71
73
entity .setPolygon (polygon );
72
74
entity .setPrimaryRing (dto .isPrimaryRing ());
73
75
entity .setLocations (dto .getLocations ().stream ()
74
- .flatMap (myLocationDto -> Stream .of (new Tuple < LocationDto , Location > (myLocationDto ,
76
+ .flatMap (myLocationDto -> Stream .of (new Locations (myLocationDto ,
75
77
entity .getLocations ().stream ()
76
78
.filter (myLocation -> myLocation .getId () != null && myLocationDto .getId () != null
77
79
&& myLocation .getId ().equals (myLocationDto .getId ()))
78
80
.findFirst ().orElse (new Location ()))))
79
- .flatMap (tuple -> Stream .of (this .mapToEntity (tuple .getA (), tuple .getB (), null , entity )))
81
+ .flatMap (tuple -> Stream .of (this .mapToEntity (tuple .dto (), tuple .entity (), null , entity )))
80
82
.collect (Collectors .toSet ()));
81
83
return entity ;
82
84
}
0 commit comments