Rev 1675 | Rev 1732 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1670 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
3 | import com.owlike.genson.Genson; |
||
4 | import com.owlike.genson.TransformationException; |
||
1675 | jmachado | 5 | import org.json.JSONArray; |
1670 | jmachado | 6 | import org.json.JSONException; |
7 | import org.json.JSONObject; |
||
8 | |||
9 | import java.io.IOException; |
||
10 | import java.io.Serializable; |
||
1675 | jmachado | 11 | import java.util.ArrayList; |
1670 | jmachado | 12 | import java.util.List; |
1675 | jmachado | 13 | import java.util.Set; |
1670 | jmachado | 14 | |
15 | /** |
||
16 | * Created by jorgemachado on 23/02/17. |
||
17 | */ |
||
18 | public class RepositoryDocumentCollectionImpl extends RepositoryDocumentCollection { |
||
19 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
20 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() { |
||
21 | return getId(); |
||
22 | } |
||
23 | |||
24 | |||
1692 | jmachado | 25 | |
26 | |||
1675 | jmachado | 27 | static Genson genson; |
28 | |||
29 | static { |
||
30 | Genson.Builder gensonBuilder = new Genson.Builder() |
||
1670 | jmachado | 31 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
32 | .include(RepositoryDocumentCollectionImpl.class) |
||
33 | .include(1.5.0/docs/api/java/lang/String.html">String.class) |
||
1675 | jmachado | 34 | .exclude("parent", RepositoryDocumentCollection.class); |
35 | genson = gensonBuilder.create(); |
||
1670 | jmachado | 36 | |
1675 | jmachado | 37 | } |
1670 | jmachado | 38 | public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException |
39 | { |
||
40 | return genson.serialize(this); |
||
41 | } |
||
42 | |||
43 | public static 1.5.0/docs/api/java/lang/String.html">String toJson(List<RepositoryDocumentCollection> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException |
||
44 | { |
||
45 | return genson.serialize(collections); |
||
46 | } |
||
1675 | jmachado | 47 | public static JSONArray toJsonArray(Set<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException { |
48 | ArrayList<RepositoryDocumentCollectionImpl> collectionsList = new ArrayList<RepositoryDocumentCollectionImpl>(collections); |
||
49 | return toJsonArray(collectionsList); |
||
50 | } |
||
1670 | jmachado | 51 | |
1675 | jmachado | 52 | public static JSONArray toJsonArray(List<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException { |
53 | return new JSONArray(genson.serialize(collections)); |
||
54 | } |
||
55 | |||
1670 | jmachado | 56 | public static RepositoryDocumentCollectionImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException { |
57 | return genson.deserialize(json, RepositoryDocumentCollectionImpl.class); |
||
58 | } |
||
59 | |||
60 | public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException { |
||
61 | return new JSONObject(toJson()); |
||
62 | } |
||
1675 | jmachado | 63 | |
64 | public 1.5.0/docs/api/java/lang/String.html">String getPathName() |
||
65 | { |
||
66 | if(getParent()==null) |
||
67 | return getName(); |
||
68 | else |
||
69 | return getParent().getPathName() + " - " + getName(); |
||
70 | } |
||
1692 | jmachado | 71 | |
72 | private 1.5.0/docs/api/java/lang/String.html">String getTreeHiffens() |
||
73 | { |
||
74 | if(getParent() == null) |
||
75 | return "-"; |
||
76 | else |
||
77 | return getParent().getTreeHiffens(); |
||
78 | } |
||
79 | |||
80 | public 1.5.0/docs/api/java/lang/String.html">String getTreeName() |
||
81 | { |
||
82 | if(getParent() == null) |
||
83 | return getName(); |
||
84 | else |
||
85 | return getParent().getTreeHiffens() + getName(); |
||
86 | } |
||
87 | public void setTreeName(1.5.0/docs/api/java/lang/String.html">String name) |
||
88 | {} |
||
1670 | jmachado | 89 | } |
90 |