Rev 1728 | Rev 1731 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1728 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
3 | import com.owlike.genson.Genson; |
||
4 | import com.owlike.genson.TransformationException; |
||
5 | import org.json.JSONException; |
||
6 | import org.json.JSONObject; |
||
7 | |||
8 | import java.io.IOException; |
||
9 | import java.io.Serializable; |
||
10 | import java.util.ArrayList; |
||
1729 | jmachado | 11 | import java.util.HashSet; |
1728 | jmachado | 12 | |
13 | /** |
||
14 | * Created by jorgemachado on 13/04/17. |
||
15 | */ |
||
16 | public class ConfigurationSeparatorImpl extends ConfigurationSeparator { |
||
1729 | jmachado | 17 | |
1728 | jmachado | 18 | @1.5.0/docs/api/java/lang/Override.html">Override |
19 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() |
||
20 | { |
||
21 | return getId(); |
||
22 | } |
||
23 | |||
1729 | jmachado | 24 | public ArrayList<Long> getSchoolsIds() |
25 | { |
||
26 | ArrayList<Long> schoolsIds = new ArrayList<Long>(); |
||
27 | for(CourseSchool school: getSchools()) |
||
28 | schoolsIds.add(school.getId()); |
||
29 | return schoolsIds; |
||
30 | } |
||
31 | |||
32 | public void setSchoolsIds(ArrayList<Long> ids) |
||
33 | { |
||
34 | setSchools(new HashSet<CourseSchool>()); |
||
35 | for(1.5.0/docs/api/java/lang/Long.html">Long id: ids) |
||
36 | { |
||
37 | CourseSchool school = new CourseSchoolImpl(); |
||
38 | school.setId(id); |
||
39 | getSchools().add(school); |
||
40 | } |
||
41 | } |
||
42 | |||
1728 | jmachado | 43 | static Genson confGenson = new Genson.Builder() |
44 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
1729 | jmachado | 45 | |
46 | .include("name", ConfigurationSeparatorImpl.class) |
||
47 | .include("nameEn",ConfigurationSeparatorImpl.class) |
||
48 | .include("nameEs",ConfigurationSeparatorImpl.class) |
||
49 | .include("nameFr",ConfigurationSeparatorImpl.class) |
||
50 | .include("description",ConfigurationSeparatorImpl.class) |
||
51 | .include("schoolsIds",ConfigurationSeparatorImpl.class) |
||
52 | .include(1.5.0/docs/api/java/util/ArrayList.html">ArrayList.class) |
||
1728 | jmachado | 53 | .create(); |
54 | |||
55 | public 1.5.0/docs/api/java/lang/String.html">String getJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException |
||
56 | { |
||
57 | return confGenson.serialize(this); |
||
58 | } |
||
59 | |||
1729 | jmachado | 60 | public static 1.5.0/docs/api/java/lang/String.html">String getJson(ArrayList<ConfigurationSeparator> seps) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException |
1728 | jmachado | 61 | { |
62 | return confGenson.serialize(seps); |
||
63 | } |
||
64 | |||
65 | public static ConfigurationSeparatorImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException { |
||
66 | return confGenson.deserialize(json, ConfigurationSeparatorImpl.class); |
||
67 | } |
||
68 | |||
69 | public JSONObject getJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException { |
||
70 | return new JSONObject(getJson()); |
||
71 | } |
||
72 | } |