Rev 1779 | Rev 1782 | 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; |
||
1776 | jmachado | 4 | import com.owlike.genson.GensonBuilder; |
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; |
1732 | jmachado | 28 | static Genson gensonSimpleFields; |
1675 | jmachado | 29 | |
30 | static { |
||
1776 | jmachado | 31 | GensonBuilder gensonBuilder = new Genson.Builder() |
1670 | jmachado | 32 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
1778 | jmachado | 33 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
34 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
35 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
36 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
37 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1670 | jmachado | 38 | .include(RepositoryDocumentCollectionImpl.class) |
1732 | jmachado | 39 | .include("name", RepositoryDocumentCollection.class) |
40 | .include("description",RepositoryDocumentCollection.class) |
||
41 | .include("legacyUrl", RepositoryDocumentCollection.class) |
||
42 | .include("treeName", RepositoryDocumentCollection.class) |
||
1755 | jmachado | 43 | .include("sortField", RepositoryDocumentCollection.class) |
1732 | jmachado | 44 | .include("pathName", RepositoryDocumentCollection.class) |
45 | .include("treeHiffens", RepositoryDocumentCollection.class) |
||
46 | .include("collectionManagers", RepositoryDocumentCollection.class) |
||
47 | .include("id",UserImpl.class) |
||
48 | .include("name",UserImpl.class) |
||
49 | .include("sigesCode",SigesUserImpl.class) |
||
1675 | jmachado | 50 | .exclude("parent", RepositoryDocumentCollection.class); |
1732 | jmachado | 51 | |
1675 | jmachado | 52 | genson = gensonBuilder.create(); |
1670 | jmachado | 53 | |
1776 | jmachado | 54 | GensonBuilder gensonBuilderSimpleFields = new Genson.Builder() |
1732 | jmachado | 55 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
1778 | jmachado | 56 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
57 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
58 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
59 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
60 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1732 | jmachado | 61 | .include(RepositoryDocumentCollectionImpl.class) |
62 | .include("name", RepositoryDocumentCollection.class) |
||
63 | .include("description",RepositoryDocumentCollection.class) |
||
64 | .include("legacyUrl", RepositoryDocumentCollection.class) |
||
65 | .include("treeName", RepositoryDocumentCollection.class) |
||
66 | .include("pathName", RepositoryDocumentCollection.class) |
||
67 | .include("treeHiffens", RepositoryDocumentCollection.class) |
||
1755 | jmachado | 68 | .include("sortField", RepositoryDocumentCollection.class) |
1732 | jmachado | 69 | .exclude("parent", RepositoryDocumentCollection.class); |
70 | |||
71 | gensonSimpleFields = gensonBuilderSimpleFields.create(); |
||
72 | |||
1675 | jmachado | 73 | } |
1779 | jmachado | 74 | |
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
1780 | jmachado | 80 | |
81 | public 1.5.0/docs/api/java/lang/String.html">String toJson() { |
||
1670 | jmachado | 82 | return genson.serialize(this); |
83 | } |
||
84 | |||
1776 | jmachado | 85 | 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 |
1670 | jmachado | 86 | { |
87 | return genson.serialize(collections); |
||
88 | } |
||
1776 | jmachado | 89 | public static JSONArray toJsonArray(Set<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1675 | jmachado | 90 | ArrayList<RepositoryDocumentCollectionImpl> collectionsList = new ArrayList<RepositoryDocumentCollectionImpl>(collections); |
91 | return toJsonArray(collectionsList); |
||
92 | } |
||
1670 | jmachado | 93 | |
1776 | jmachado | 94 | public static JSONArray toJsonArray(List<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1675 | jmachado | 95 | return new JSONArray(genson.serialize(collections)); |
96 | } |
||
97 | |||
1776 | jmachado | 98 | public static JSONArray toJsonArraySimpleFields(List<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException , JSONException { |
1732 | jmachado | 99 | return new JSONArray(gensonSimpleFields.serialize(collections)); |
100 | } |
||
101 | |||
1776 | jmachado | 102 | 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 { |
1670 | jmachado | 103 | return genson.deserialize(json, RepositoryDocumentCollectionImpl.class); |
104 | } |
||
105 | |||
1780 | jmachado | 106 | public JSONObject toJsonObject() throws JSONException { |
1670 | jmachado | 107 | return new JSONObject(toJson()); |
108 | } |
||
1675 | jmachado | 109 | |
110 | public 1.5.0/docs/api/java/lang/String.html">String getPathName() |
||
111 | { |
||
112 | if(getParent()==null) |
||
113 | return getName(); |
||
114 | else |
||
115 | return getParent().getPathName() + " - " + getName(); |
||
116 | } |
||
1692 | jmachado | 117 | |
118 | private 1.5.0/docs/api/java/lang/String.html">String getTreeHiffens() |
||
119 | { |
||
120 | if(getParent() == null) |
||
121 | return "-"; |
||
122 | else |
||
123 | return getParent().getTreeHiffens(); |
||
124 | } |
||
125 | |||
126 | public 1.5.0/docs/api/java/lang/String.html">String getTreeName() |
||
127 | { |
||
128 | if(getParent() == null) |
||
129 | return getName(); |
||
130 | else |
||
131 | return getParent().getTreeHiffens() + getName(); |
||
132 | } |
||
133 | public void setTreeName(1.5.0/docs/api/java/lang/String.html">String name) |
||
134 | {} |
||
1732 | jmachado | 135 | |
136 | |||
1779 | jmachado | 137 | public boolean checkManager(UserSession userSession) |
1732 | jmachado | 138 | { |
139 | if(userSession.getUser() == null) |
||
140 | return false; |
||
141 | return checkCollectionManagerInTree(userSession.getUser()); |
||
142 | } |
||
143 | |||
144 | private boolean checkCollectionManagerInTree(User u) |
||
145 | { |
||
146 | if(getCollectionManagers() != null) |
||
147 | { |
||
148 | for(User manager :getCollectionManagers()) |
||
149 | { |
||
150 | if(manager.getId() == u.getId()) |
||
151 | return true; |
||
152 | } |
||
153 | return getParent() != null && getParent().checkCollectionManagerInTree(u); |
||
154 | } |
||
155 | return false; |
||
156 | } |
||
1670 | jmachado | 157 | } |
158 |