Rev 1780 | 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; |
||
1782 | jmachado | 4 | import com.owlike.genson.GensonBuilder; |
5 | import jomm.dao.impl.AbstractDao; |
||
1728 | jmachado | 6 | import org.json.JSONException; |
7 | import org.json.JSONObject; |
||
1782 | jmachado | 8 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
1728 | jmachado | 9 | |
10 | import java.io.IOException; |
||
11 | import java.io.Serializable; |
||
12 | import java.util.ArrayList; |
||
1729 | jmachado | 13 | import java.util.HashSet; |
1782 | jmachado | 14 | import java.util.List; |
1728 | jmachado | 15 | |
16 | /** |
||
17 | * Created by jorgemachado on 13/04/17. |
||
18 | */ |
||
19 | public class ConfigurationSeparatorImpl extends ConfigurationSeparator { |
||
1729 | jmachado | 20 | |
1728 | jmachado | 21 | @1.5.0/docs/api/java/lang/Override.html">Override |
22 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() |
||
23 | { |
||
24 | return getId(); |
||
25 | } |
||
26 | |||
1782 | jmachado | 27 | |
28 | |||
29 | |||
1729 | jmachado | 30 | public ArrayList<Long> getSchoolsIds() |
31 | { |
||
32 | ArrayList<Long> schoolsIds = new ArrayList<Long>(); |
||
33 | for(CourseSchool school: getSchools()) |
||
34 | schoolsIds.add(school.getId()); |
||
35 | return schoolsIds; |
||
36 | } |
||
37 | |||
38 | public void setSchoolsIds(ArrayList<Long> ids) |
||
39 | { |
||
40 | setSchools(new HashSet<CourseSchool>()); |
||
41 | for(1.5.0/docs/api/java/lang/Long.html">Long id: ids) |
||
42 | { |
||
43 | CourseSchool school = new CourseSchoolImpl(); |
||
44 | school.setId(id); |
||
45 | getSchools().add(school); |
||
46 | } |
||
47 | } |
||
48 | |||
1737 | jmachado | 49 | public ArrayList<String> getAllowedRoles() |
50 | { |
||
51 | ArrayList<String> roles = new ArrayList<String>(); |
||
52 | if(getSchools() != null) |
||
53 | { |
||
54 | for(CourseSchool sc : getSchools()) |
||
55 | { |
||
56 | if(isShowStudents()) |
||
57 | roles.add(sc.getStudentRole()); |
||
58 | if(isShowTeachers()) |
||
59 | roles.add(sc.getTeacherRole()); |
||
60 | if(isShowWorkers()) |
||
61 | roles.add(sc.getFuncionarioRole()); |
||
62 | } |
||
63 | } |
||
64 | return roles; |
||
65 | } |
||
66 | |||
67 | public 1.5.0/docs/api/java/lang/String.html">String getSeparatorKey() |
||
68 | { |
||
69 | return "ConfigSeparator" + getId(); |
||
70 | } |
||
71 | |||
1782 | jmachado | 72 | static Genson confGenson = new GensonBuilder() |
1728 | jmachado | 73 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
1782 | jmachado | 74 | .useRuntimeType(true) |
75 | .useMethods(true) |
||
76 | .useFields(false) |
||
77 | .useClassMetadata(true) |
||
78 | .include(ConfigurationSeparator.class) |
||
79 | .include(ConfigurationSeparatorImpl.class) |
||
80 | .include("id", ConfigurationSeparator.class) |
||
81 | .include("name", ConfigurationSeparator.class) |
||
82 | .include("nameEn",ConfigurationSeparator.class) |
||
83 | .include("nameEs",ConfigurationSeparator.class) |
||
84 | .include("nameFr", ConfigurationSeparator.class) |
||
85 | .include("description", ConfigurationSeparator.class) |
||
86 | |||
87 | .include("active", ConfigurationSeparator.class) |
||
88 | .include("position", ConfigurationSeparator.class) |
||
89 | |||
90 | .include("showInBaco", ConfigurationSeparator.class) |
||
91 | .include("showInPae", ConfigurationSeparator.class) |
||
92 | |||
93 | .include("showStudents", ConfigurationSeparator.class) |
||
94 | .include("showTeachers", ConfigurationSeparator.class) |
||
95 | .include("showWorkers", ConfigurationSeparator.class) |
||
96 | |||
1731 | jmachado | 97 | //Evita fazer o parse a todas as escolas, o set Ids vai colocar escolas na classe só com id |
1737 | jmachado | 98 | .include("schoolsIds", ConfigurationSeparatorImpl.class) |
1782 | jmachado | 99 | .include("pageSection", ConfigurationSeparator.class) |
1731 | jmachado | 100 | .include("id", PageContent.class) |
1782 | jmachado | 101 | .include("path", PageContent.class) |
102 | .include("slug", PageContent.class) |
||
1728 | jmachado | 103 | .create(); |
104 | |||
1780 | jmachado | 105 | public 1.5.0/docs/api/java/lang/String.html">String toJson() { |
1728 | jmachado | 106 | return confGenson.serialize(this); |
107 | } |
||
108 | |||
1782 | jmachado | 109 | public static 1.5.0/docs/api/java/lang/String.html">String toJson(List<ConfigurationSeparator> seps) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1728 | jmachado | 110 | { |
111 | return confGenson.serialize(seps); |
||
112 | } |
||
113 | |||
1776 | jmachado | 114 | 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 { |
1728 | jmachado | 115 | return confGenson.deserialize(json, ConfigurationSeparatorImpl.class); |
116 | } |
||
117 | |||
1780 | jmachado | 118 | public JSONObject toJsonObject() throws JSONException { |
1779 | jmachado | 119 | return new JSONObject(toJson()); |
1728 | jmachado | 120 | } |
1778 | jmachado | 121 | |
122 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
1779 | jmachado | 123 | |
1782 | jmachado | 124 | AbstractDao.getCurrentSession().beginTransaction(); |
125 | List<ConfigurationSeparator> seps = DaoFactory.getConfigurationSeparatorDaoImpl().findAll(); |
||
1779 | jmachado | 126 | |
1782 | jmachado | 127 | /*List<ConfigurationSeparatorImpl> seps2 = new ArrayList<ConfigurationSeparatorImpl>(); |
128 | for(ConfigurationSeparator s : seps) |
||
129 | { |
||
130 | seps2.add((ConfigurationSeparatorImpl) s); |
||
131 | |||
132 | }*/ |
||
133 | 1.5.0/docs/api/java/lang/String.html">String jsonArraySeps = ConfigurationSeparatorImpl.toJson(seps); |
||
134 | |||
135 | 1.5.0/docs/api/java/lang/System.html">System.out.println(jsonArraySeps); |
||
136 | |||
137 | |||
138 | |||
139 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
140 | |||
141 | |||
1778 | jmachado | 142 | } |
1728 | jmachado | 143 | } |