This project has retired. For details please refer to its
Attic page.
QueryResultImpl xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.runtime;
20
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.chemistry.opencmis.client.api.CmisObject;
28 import org.apache.chemistry.opencmis.client.api.ObjectFactory;
29 import org.apache.chemistry.opencmis.client.api.QueryResult;
30 import org.apache.chemistry.opencmis.client.api.Relationship;
31 import org.apache.chemistry.opencmis.client.api.Rendition;
32 import org.apache.chemistry.opencmis.client.api.Session;
33 import org.apache.chemistry.opencmis.commons.data.AllowableActions;
34 import org.apache.chemistry.opencmis.commons.data.ObjectData;
35 import org.apache.chemistry.opencmis.commons.data.PropertyData;
36 import org.apache.chemistry.opencmis.commons.data.RenditionData;
37
38
39
40
41 public class QueryResultImpl implements QueryResult, Serializable {
42
43 private static final long serialVersionUID = 1L;
44
45 private Map<String, PropertyData<?>> propertiesById;
46 private Map<String, PropertyData<?>> propertiesByQueryName;
47 private AllowableActions allowableActions;
48 private List<Relationship> relationships;
49 private List<Rendition> renditions;
50
51
52
53
54 public QueryResultImpl(Session session, ObjectData objectData) {
55 if (objectData != null) {
56
57 ObjectFactory of = session.getObjectFactory();
58
59
60 if (objectData.getProperties() != null) {
61 propertiesById = new LinkedHashMap<String, PropertyData<?>>();
62 propertiesByQueryName = new LinkedHashMap<String, PropertyData<?>>();
63
64 List<PropertyData<?>> queryProperties = of.convertQueryProperties(objectData.getProperties());
65
66 for (PropertyData<?> property : queryProperties) {
67 propertiesById.put(property.getId(), property);
68 propertiesByQueryName.put(property.getQueryName(), property);
69 }
70 }
71
72
73 if (objectData.getAllowableActions() != null) {
74 this.allowableActions = objectData.getAllowableActions();
75 }
76
77
78 if (objectData.getRelationships() != null) {
79 relationships = new ArrayList<Relationship>();
80 for (ObjectData rod : objectData.getRelationships()) {
81 CmisObject relationship = of.convertObject(rod, session.getDefaultContext());
82 if (relationship instanceof Relationship) {
83 relationships.add((Relationship) relationship);
84 }
85 }
86 }
87
88
89 if (objectData.getRenditions() != null) {
90 this.renditions = new ArrayList<Rendition>();
91 for (RenditionData rd : objectData.getRenditions()) {
92 this.renditions.add(of.convertRendition(null, rd));
93 }
94 }
95 }
96 }
97
98
99
100
101
102
103 public List<PropertyData<?>> getProperties() {
104 return new ArrayList<PropertyData<?>>(propertiesByQueryName.values());
105 }
106
107
108
109
110
111
112
113
114 @SuppressWarnings("unchecked")
115 public <T> PropertyData<T> getPropertyById(String id) {
116 return (PropertyData<T>) propertiesById.get(id);
117 }
118
119
120
121
122
123
124
125
126 @SuppressWarnings("unchecked")
127 public <T> PropertyData<T> getPropertyByQueryName(String queryName) {
128 return (PropertyData<T>) propertiesByQueryName.get(queryName);
129 }
130
131
132
133
134
135
136
137
138 public <T> T getPropertyValueById(String id) {
139 PropertyData<T> property = getPropertyById(id);
140 if (property == null) {
141 return null;
142 }
143
144 return property.getFirstValue();
145 }
146
147
148
149
150
151
152
153
154 public <T> T getPropertyValueByQueryName(String queryName) {
155 PropertyData<T> property = getPropertyByQueryName(queryName);
156 if (property == null) {
157 return null;
158 }
159
160 return property.getFirstValue();
161 }
162
163
164
165
166
167
168
169
170 public <T> List<T> getPropertyMultivalueById(String id) {
171 PropertyData<T> property = getPropertyById(id);
172 if (property == null) {
173 return null;
174 }
175
176 return property.getValues();
177 }
178
179
180
181
182
183
184
185
186 public <T> List<T> getPropertyMultivalueByQueryName(String queryName) {
187 PropertyData<T> property = getPropertyByQueryName(queryName);
188 if (property == null) {
189 return null;
190 }
191
192 return property.getValues();
193 }
194
195
196
197
198
199
200 public AllowableActions getAllowableActions() {
201 return allowableActions;
202 }
203
204
205
206
207
208
209 public List<Relationship> getRelationships() {
210 return relationships;
211 }
212
213
214
215
216
217
218 public List<Rendition> getRenditions() {
219 return renditions;
220 }
221 }