Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1312 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
1814 | jmachado | 3 | import com.owlike.genson.Genson; |
4 | import com.owlike.genson.GensonBuilder; |
||
5 | import org.json.JSONException; |
||
6 | import org.json.JSONObject; |
||
7 | |||
8 | import java.io.IOException; |
||
1312 | jmachado | 9 | import java.io.Serializable; |
10 | import java.util.List; |
||
11 | import java.util.Set; |
||
12 | |||
13 | /** |
||
14 | * Created by jorgemachado on 03/02/16. |
||
15 | */ |
||
16 | public class PageSectionImpl extends PageSection { |
||
17 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
18 | public List<String> getOwnerRoles() { |
||
19 | return null; |
||
20 | } |
||
21 | |||
22 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
23 | public 1.5.0/docs/api/java/lang/String.html">String getChoosedOwnerRole() { |
||
24 | return null; |
||
25 | } |
||
26 | |||
27 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
28 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() { |
||
29 | return getId(); |
||
30 | } |
||
31 | |||
32 | public Set<CourseUnit> courseUnitLookup() |
||
33 | { |
||
34 | if(getCourseUnits() != null && getCourseUnits().size() > 0) |
||
35 | return getCourseUnits(); |
||
36 | if(getParent() != null) |
||
37 | return ((PageSectionImpl)getParent()).courseUnitLookup(); |
||
38 | return null; |
||
39 | } |
||
40 | |||
41 | public Set<Course> coursesLookup() |
||
42 | { |
||
43 | if(getCourses() != null && getCourses().size() > 0) |
||
44 | return getCourses(); |
||
45 | if(getParent() != null) |
||
46 | return ((PageSectionImpl)getParent()).coursesLookup(); |
||
47 | return null; |
||
48 | } |
||
1814 | jmachado | 49 | |
50 | |||
51 | public static Genson genson; |
||
52 | |||
53 | static { |
||
54 | GensonBuilder gensonBuilder = new GensonBuilder() |
||
55 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
56 | .useMethods(true) |
||
57 | .useFields(false) |
||
58 | .useClassMetadata(true) |
||
59 | .useRuntimeType(true) |
||
60 | |||
61 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
||
62 | .exclude("clear") |
||
63 | .exclude("clearanceInitialized") |
||
64 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
65 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
66 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
67 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
68 | //.useFields(false) //COM ISTO A SLUG VAI A NULL E SEM ISTO DÁ NULLPOINTER EXCEPTION. ISTO NO SERVIÇO!!! |
||
69 | .include(PageContentImpl.class) |
||
70 | .include(PageSectionImpl.class) |
||
71 | .include(1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation.class) |
||
72 | .include("title", PageContent.class) |
||
73 | .include("directory",PageContent.class) |
||
74 | .include("file", PageContent.class) |
||
75 | .include("description",PageContent.class) |
||
76 | .include("path",PageContent.class) |
||
77 | .include("acl",PageContent.class) |
||
78 | .include("slug",PageContent.class) |
||
79 | .include("pathForIdHtml",PageContent.class) |
||
80 | .include("html", PageText.class) |
||
81 | .include("url",PageContent.class) |
||
82 | .include("textBox", PageContent.class) |
||
83 | //.include("getAclJson", PageContentImpl.class) |
||
84 | .include("clearances", PageContentImpl.class)//como FUNCIONA PARA PÔR AS ACL'S DIREITINHAS?? |
||
85 | //.include("pageContent", PageContentImpl.class) |
||
86 | //.include("isClear", PageContentImpl.class) |
||
87 | //.include("isDirectory", PageContentImpl.class) |
||
88 | .exclude("childsInitialized", PageContentImpl.class) |
||
89 | .exclude("parentInitialized", PageContentImpl.class) |
||
90 | .exclude("parent", PageContent.class); |
||
91 | |||
92 | |||
93 | genson = gensonBuilder.create(); |
||
94 | } |
||
95 | |||
96 | |||
97 | public static PageSectionImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
98 | return genson.deserialize(json,PageSectionImpl.class); |
||
99 | } |
||
100 | |||
101 | public 1.5.0/docs/api/java/lang/String.html">String toJson() |
||
102 | { |
||
103 | return genson.serialize(this); |
||
104 | } |
||
105 | |||
106 | public static 1.5.0/docs/api/java/lang/String.html">String toJson(List<PageSection> roots) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException{ |
||
107 | return genson.serialize(roots); |
||
108 | } |
||
109 | |||
110 | public JSONObject toJsonObject() throws JSONException { |
||
111 | return new JSONObject(toJson()); |
||
112 | } |
||
113 | |||
1827 | jmachado | 114 | /* |
1814 | jmachado | 115 | public static JSONArray toJsonArray(List<PageSectionImpl> itemGroup) throws IOException, JSONException { |
116 | return new JSONArray(genson.serialize(itemGroup)); |
||
1827 | jmachado | 117 | }*/ |
1814 | jmachado | 118 | |
119 | /*public String getPath(){ |
||
120 | if(getParent()==null) |
||
121 | return getSlug(); |
||
122 | else |
||
123 | return getParent().getSlug() + "/" + getSlug(); |
||
124 | }*/ |
||
1312 | jmachado | 125 | } |