Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1505 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
1626 | jmachado | 3 | import com.owlike.genson.Genson; |
1784 | jmachado | 4 | import com.owlike.genson.GensonBuilder; |
1670 | jmachado | 5 | import org.json.JSONException; |
6 | import org.json.JSONObject; |
||
1505 | jmachado | 7 | import pt.estgp.estgweb.utils.ConfigProperties; |
8 | |||
1626 | jmachado | 9 | import java.io.IOException; |
1505 | jmachado | 10 | import java.io.Serializable; |
1626 | jmachado | 11 | import java.util.ArrayList; |
1505 | jmachado | 12 | |
13 | /** |
||
14 | * Created by jorgemachado on 14/09/16. |
||
15 | */ |
||
16 | public class CourseDepartmentImpl extends CourseDepartment { |
||
17 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
18 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() { |
||
19 | return getSigla(); |
||
20 | } |
||
21 | |||
1814 | jmachado | 22 | private 1.5.0/docs/api/java/lang/String.html">String siglaNova; |
23 | |||
24 | public 1.5.0/docs/api/java/lang/String.html">String getSiglaNova() |
||
25 | { |
||
26 | if(siglaNova == null || siglaNova.trim().length() == 0) |
||
27 | siglaNova = getSigla(); |
||
28 | return siglaNova; |
||
29 | } |
||
30 | |||
31 | public void setSiglaNova(1.5.0/docs/api/java/lang/String.html">String siglaNova) { |
||
32 | this.siglaNova = siglaNova; |
||
33 | } |
||
34 | |||
1505 | jmachado | 35 | public 1.5.0/docs/api/java/lang/String.html">String getSchoolFromInstitutionalCode() |
36 | { |
||
1795 | jmachado | 37 | if(getCourseSchool() != null) |
38 | return ConfigProperties.getProperty("institution.code.prefix." + getCourseSchool().getInstitutionalCode()); |
||
39 | return null; |
||
1505 | jmachado | 40 | } |
1626 | jmachado | 41 | |
1782 | jmachado | 42 | public void setSchoolFromInstitutionalCode(1.5.0/docs/api/java/lang/String.html">String garbage) |
43 | { |
||
44 | |||
45 | } |
||
46 | |||
1784 | jmachado | 47 | static Genson courseDepartmentGenson = new GensonBuilder() |
1626 | jmachado | 48 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
1670 | jmachado | 49 | .include(CourseDepartmentImpl.class) |
1782 | jmachado | 50 | .useRuntimeType(true) |
51 | .useMethods(true) |
||
52 | .useFields(false) |
||
53 | .useClassMetadata(true) |
||
54 | .include("sigla", CourseDepartment.class) |
||
1814 | jmachado | 55 | .include("siglaNova", CourseDepartmentImpl.class) |
1782 | jmachado | 56 | .include("active", CourseDepartment.class) |
57 | .include("name", CourseDepartment.class) |
||
58 | .include("nameEn", CourseDepartment.class) |
||
59 | .include("nameEs", CourseDepartment.class) |
||
60 | .include("nameFr",CourseDepartment.class) |
||
61 | .include("directorRole",CourseDepartment.class) |
||
62 | .include("boardRole",CourseDepartment.class) |
||
63 | .include("courseSchool",CourseDepartment.class) |
||
64 | .include("schoolFromInstitutionalCode",CourseDepartmentImpl.class) |
||
65 | |||
66 | .include("id",CourseSchool.class) |
||
67 | |||
1626 | jmachado | 68 | .create(); |
69 | |||
1780 | jmachado | 70 | public 1.5.0/docs/api/java/lang/String.html">String toJson() { |
1626 | jmachado | 71 | return courseDepartmentGenson.serialize(this); |
72 | } |
||
1780 | jmachado | 73 | public JSONObject toJsonObject() throws JSONException |
1670 | jmachado | 74 | { |
75 | return new JSONObject(courseDepartmentGenson.serialize(this)); |
||
76 | } |
||
1626 | jmachado | 77 | |
1779 | jmachado | 78 | public static 1.5.0/docs/api/java/lang/String.html">String toJson(ArrayList<CourseDepartment> departments) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1626 | jmachado | 79 | { |
80 | return courseDepartmentGenson.serialize(departments); |
||
81 | } |
||
1670 | jmachado | 82 | |
1776 | jmachado | 83 | public static CourseDepartmentImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1670 | jmachado | 84 | { |
85 | return courseDepartmentGenson.deserialize(json,CourseDepartmentImpl.class); |
||
86 | } |
||
1778 | jmachado | 87 | |
1782 | jmachado | 88 | |
1505 | jmachado | 89 | } |