Search in sources :

Example 1 with ConstraintDescriptor

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) ResourcesResponse(com.emc.storageos.geomodel.ResourcesResponse) ConstraintDescriptor(com.emc.storageos.db.client.constraint.ConstraintDescriptor) DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) QueryResultList(com.emc.storageos.db.client.constraint.QueryResultList) List(java.util.List) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with ConstraintDescriptor

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) ResourcesResponse(com.emc.storageos.geomodel.ResourcesResponse) ConstraintDescriptor(com.emc.storageos.db.client.constraint.ConstraintDescriptor) DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) QueryResultList(com.emc.storageos.db.client.constraint.QueryResultList) List(java.util.List) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ConstraintDescriptor (com.emc.storageos.db.client.constraint.ConstraintDescriptor)2 QueryResultList (com.emc.storageos.db.client.constraint.QueryResultList)2 DataObject (com.emc.storageos.db.client.model.DataObject)2 ResourcesResponse (com.emc.storageos.geomodel.ResourcesResponse)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 InputStream (java.io.InputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2