All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tteky.xenonext.client.QueryContract Maven / Gradle / Ivy

Go to download

JAX-RS annotation processing capability for Xenon Stateless services and Service client.

The newest version!
package com.tteky.xenonext.client;

import com.tteky.xenonext.jaxrs.annotation.OperationBody;
import com.vmware.xenon.common.Utils;
import com.vmware.xenon.services.common.QueryTask;

import javax.ws.rs.*;
import java.util.Map;
import java.util.concurrent.CompletableFuture;


/**
 * Contract for Xenon core query tasks and odata query
 */
@Path("/core")
public interface QueryContract {

    String LE = " le ", OR = " or ", ANY = " any ", ALL = " all ", AND = " and ";
    String GT = " gt ", GE = " ge ", lt = " lt ", EQ = " eq ", NE = " ne ";

    @Path("/odata-queries")
    @GET
    CompletableFuture oDataQuery(@QueryParam("$filter") String filterCriteria);

    @Path("/query-tasks/{id}")
    @GET
    CompletableFuture getQueryResults(@PathParam("id") String id);

    @Path("/query-tasks")
    @POST
    CompletableFuture query(@OperationBody QueryTask filterCriteria);

    /**
     * TO be used only with queries returning homogeneous results of a single type
     * @param filterCriteria the actual criteria
     * @param clazz the return type, usually it will be an array type
     * @param 
     * @return
     */
    default  CompletableFuture typedODataQuery(String filterCriteria, Class clazz) {
        return oDataQuery(filterCriteria)
                .thenApply(task -> {
                    Map documents = task.results.documents;
                    return Utils.fromJson(documents.values(), clazz);
                });
    }

    /**
     * To be used only with direct task queries returning homogeneous results of a single type
     * @param filterCriteria the actual criteria
     * @param clazz the return type, usually it will be an array type
     * @param 
     * @return
     */
    default  CompletableFuture typedQuery(QueryTask filterCriteria, Class clazz) {
        return query(filterCriteria)
                .thenApply(task -> {
                    Map documents = task.results.documents;
                    return Utils.fromJson(documents.values(), clazz);
                });
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy