use of com.emc.storageos.db.client.constraint.ConstraintDescriptor in project coprhd-controller by CoprHD.
the class GeoServiceClient method queryByConstraint.
/**
* Query the GeoVisible resources by conditions
*
* @param constraint the query condition
* @param result the query result
* @return list of resources
* @throws Exception
*/
@SuppressWarnings("unchecked")
public <T> void queryByConstraint(Constraint constraint, QueryResultList<T> result) throws Exception {
ConstraintDescriptor constrainDescriptor = constraint.toConstraintDescriptor();
WebResource rRoot = createRequest(GEOVISIBLE_URI + "constraint/" + result.getClass().getName());
rRoot.accept(MediaType.APPLICATION_OCTET_STREAM);
ClientResponse resp = addSignature(rRoot).post(ClientResponse.class, constrainDescriptor);
InputStream input = resp.getEntityInputStream();
ObjectInputStream objInputStream = new ObjectInputStream(input);
ResourcesResponse<?> resources = (ResourcesResponse<?>) objInputStream.readObject();
List<Object> queryResult = (List<Object>) resources.getObjects();
List<T> ret = new ArrayList<T>();
for (Object obj : queryResult) {
ret.add((T) obj);
}
result.setResult(ret.iterator());
}
use of com.emc.storageos.db.client.constraint.ConstraintDescriptor in project coprhd-controller by CoprHD.
the class GeoServiceClient method queryByConstraint.
/**
* Query the GeoVisible resources by conditions
*
* @param constraint the query condition
* @param result the query result
* @param startId where the query starts, if it's null, query starts at the beginning
* @param maxCount the max number of resources returned
* @throws Exception
*/
@SuppressWarnings("unchecked")
public <T> void queryByConstraint(Constraint constraint, QueryResultList<T> result, URI startId, int maxCount) throws Exception {
ConstraintDescriptor constrainDescriptor = constraint.toConstraintDescriptor();
WebResource rRoot = createRequest(GEOVISIBLE_URI + "constraint/" + result.getClass().getName());
if (startId != null) {
rRoot = rRoot.queryParam("start_id", startId.toString());
}
if (maxCount > 0) {
rRoot = rRoot.queryParam("max_count", Integer.toString(maxCount));
}
rRoot.accept(MediaType.APPLICATION_OCTET_STREAM);
ClientResponse resp = addSignature(rRoot).post(ClientResponse.class, constrainDescriptor);
InputStream input = resp.getEntityInputStream();
ObjectInputStream objInputStream = new ObjectInputStream(input);
ResourcesResponse<?> resources = (ResourcesResponse<?>) objInputStream.readObject();
List<Object> queryResult = (List<Object>) resources.getObjects();
List<T> ret = new ArrayList<T>();
for (Object obj : queryResult) {
ret.add((T) obj);
}
result.setResult(ret.iterator());
}
Aggregations