PojoUtils.java
4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package fi.codecrew.moya.rest;
import java.util.ArrayList;
import java.util.List;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.rest.pojo.map.v1.MapPojo;
import fi.codecrew.moya.rest.pojo.map.v1.MapRoot;
import fi.codecrew.moya.rest.pojo.map.v1.PlacePojo;
import fi.codecrew.moya.rest.pojo.map.v1.PlaceRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.CardRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.SimpleEventuserRoot;
public class PojoUtils {
public static EventUserRestPojo initEventUserRestPojo(EventUser user)
{
EventUserRestPojo ret = new EventUserRestPojo();
ret.setNick(user.getUser().getNick());
ret.setLogin(user.getUser().getLogin());
ret.setEventuserId(user.getId());
ret.setUserId(user.getUser().getId());
ret.setFirstname(user.getUser().getFirstnames());
ret.setLastname(user.getUser().getLastname());
return ret;
}
public static SimpleEventuserRoot parseEventusers(List<EventUser> users) {
ArrayList<EventUserRestPojo> list = new ArrayList<>();
for (EventUser u : users) {
list.add(initEventUserRestPojo(u));
}
return new SimpleEventuserRoot(list);
}
public static PrintedCardRestPojo initPrintedCardRestPojo(PrintedCard card)
{
PrintedCardRestPojo ret = new PrintedCardRestPojo();
ret.setEventuserId(card.getUser().getId());
ret.setId(card.getId());
if (card.getTemplate() != null)
ret.setTemplate(card.getTemplate().getName());
ret.setUsername(card.getUser().getNick());
ret.setWholeName(card.getUser().getWholeName());
ret.setState(card.getCardState().toString());
if (card.getPrintTime() != null)
ret.setPrintTime(card.getPrintTime().getTime());
return ret;
}
public static CardRoot parsePrintedCards(List<PrintedCard> cards)
{
ArrayList<PrintedCardRestPojo> ret = new ArrayList<PrintedCardRestPojo>();
for (PrintedCard c : cards) {
ret.add(initPrintedCardRestPojo(c));
}
CardRoot root = new CardRoot();
root.setCards(ret);
return root;
}
public static PlacePojo initPlacePojo(Place place) {
PlacePojo ret = new PlacePojo();
if (place.getProduct() != null)
ret.setProductId(place.getProduct().getId());
if (place.getPlaceReserver() != null && place.getPlaceReserver().getPlaceGroup() != null && place.getPlaceReserver().getPlaceGroup().getCreator() != null)
ret.setReserverId(place.getPlaceReserver().getPlaceGroup().getCreator().getId());
ret.setId(place.getId());
ret.setDescription(place.getDescription());
ret.setName(place.getName());
ret.setMapX(place.getMapX());
ret.setMapY(place.getMapY());
ret.setDetails(place.getDetails());
ret.setCode(place.getCode());
ret.setHeight(place.getHeight());
ret.setWidth(place.getWidth());
ret.setTaken(place.isTaken());
ret.setBuyable(place.isBuyable());
ret.setReleaseTime(place.getReleaseTime());
ret.setDisabled(place.isDisabled());
if (place.getMap() != null) {
ret.setMapId(place.getMap().getId());
}
if (place.getPlaceReserver() != null && place.getPlaceReserver().getUser() != null) {
ret.setEventuserId(place.getPlaceReserver().getUser().getId());
}
return ret;
}
public static PlaceRoot initPlaceRoot(EventMap map) {
PlaceRoot ret = new PlaceRoot();
ret.setMap(initMapPojo(map));
ret.setPlaces(parsePlaces(map.getPlaces()));
return ret;
}
private static List<PlacePojo> parsePlaces(List<Place> places) {
ArrayList<PlacePojo> ret = new ArrayList<PlacePojo>();
for (Place place : places) {
ret.add(initPlacePojo(place));
}
return ret;
}
private static MapPojo initMapPojo(EventMap map) {
MapPojo ret = new MapPojo();
ret.setId(map.getId());
ret.setName(map.getName());
ret.setActive(map.isActive());
return ret;
}
public static MapRoot parseMaps(List<EventMap> eventMaps) {
List<MapPojo> ret = new ArrayList<>();
for (EventMap m : eventMaps) {
ret.add(initMapPojo(m));
}
return new MapRoot(ret);
}
}