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

com.adaptrex.sandbox.rest.SandboxRestBase Maven / Gradle / Ivy

package com.adaptrex.sandbox.rest;

import javax.servlet.ServletContext;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

import com.adaptrex.core.Adaptrex;
import com.adaptrex.core.rest.RequestBody;
import com.adaptrex.core.rest.RestModel;
import com.adaptrex.core.rest.RestService;
import com.adaptrex.core.rest.RestStore;

public class SandboxRestBase {

	Class clazz;
	
	@Context UriInfo uriInfo;
	RestService rest;
	@Context ServletContext servletContext;
	
	RestService getRest() {
		if (this.rest == null) {
			this.rest = Adaptrex.get(servletContext).getRestService();
		}
		return this.rest;
	}
	
	@GET
	public RestStore getStore() {
		return getRest().getStore(clazz, uriInfo);
	}
	
	@GET
	@Path("{id}")
	public RestModel readModel(@PathParam("id") String id) {
		return getRest().getModel(clazz, id, uriInfo);
	}
	
	@POST
    public RestModel createModel(RequestBody modelUpdate) {
    	return getRest().createModel(clazz, modelUpdate, uriInfo);
    }
	
	@PUT
	@Path("{id}")
    public RestModel updateModel(@PathParam("id") String id, RequestBody modelUpdate) {
    	return getRest().updateModel(clazz, id, modelUpdate, uriInfo);
    }
	
	@DELETE
	@Path("{id}")
	public RestModel deleteRecord(@PathParam("id") String id) {
		return getRest().deleteModel(clazz, id);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy