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 propertiesById = new LinkedHashMap<String, PropertyData<?>>();
56 propertiesByQueryName = new LinkedHashMap<String, PropertyData<?>>();
57
58 if (objectData != null) {
59
60 ObjectFactory of = session.getObjectFactory();
61
62
63 if (objectData.getProperties() != null) {
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 @Override
99 public List<PropertyData<?>> getProperties() {
100 return new ArrayList<PropertyData<?>>(propertiesByQueryName.values());
101 }
102
103 @Override
104 @SuppressWarnings("unchecked")
105 public <T> PropertyData<T> getPropertyById(String id) {
106 return (PropertyData<T>) propertiesById.get(id);
107 }
108
109 @Override
110 @SuppressWarnings("unchecked")
111 public <T> PropertyData<T> getPropertyByQueryName(String queryName) {
112 return (PropertyData<T>) propertiesByQueryName.get(queryName);
113 }
114
115 @Override
116 public <T> T getPropertyValueById(String id) {
117 PropertyData<T> property = getPropertyById(id);
118 if (property == null) {
119 return null;
120 }
121
122 return property.getFirstValue();
123 }
124
125 @Override
126 public <T> T getPropertyValueByQueryName(String queryName) {
127 PropertyData<T> property = getPropertyByQueryName(queryName);
128 if (property == null) {
129 return null;
130 }
131
132 return property.getFirstValue();
133 }
134
135 @Override
136 public <T> List<T> getPropertyMultivalueById(String id) {
137 PropertyData<T> property = getPropertyById(id);
138 if (property == null) {
139 return null;
140 }
141
142 return property.getValues();
143 }
144
145 @Override
146 public <T> List<T> getPropertyMultivalueByQueryName(String queryName) {
147 PropertyData<T> property = getPropertyByQueryName(queryName);
148 if (property == null) {
149 return null;
150 }
151
152 return property.getValues();
153 }
154
155 @Override
156 public AllowableActions getAllowableActions() {
157 return allowableActions;
158 }
159
160 @Override
161 public List<Relationship> getRelationships() {
162 return relationships;
163 }
164
165 @Override
166 public List<Rendition> getRenditions() {
167 return renditions;
168 }
169 }