ec.gob.senescyt.sniese.commons.resources.CatalogoResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sniese-commons Show documentation
Show all versions of sniese-commons Show documentation
Librería que contiene clases de uso comun para sniese hechos en dropwizard
package ec.gob.senescyt.sniese.commons.resources;
import ec.gob.senescyt.sniese.commons.core.EntidadBase;
import ec.gob.senescyt.sniese.commons.core.Lista;
import ec.gob.senescyt.sniese.commons.dao.AbstractServicioDAO;
import io.dropwizard.hibernate.UnitOfWork;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.eclipse.jetty.http.HttpStatus.NOT_FOUND_404;
import static org.eclipse.jetty.http.HttpStatus.OK_200;
@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
@Produces(MediaType.APPLICATION_JSON)
public abstract class CatalogoResource> {
protected final D dao;
public CatalogoResource(D dao) {
this.dao = dao;
}
@GET
@UnitOfWork(readOnly = true)
public Response obtenerTodos() {
return Response.ok(new Lista<>(dao.obtenerTodos())).build();
}
@GET
@Path("{entidadId}")
@UnitOfWork(readOnly = true)
public Response obtener(@PathParam("entidadId") long entidadId) {
EntidadBase entity = dao.obtenerPorId(entidadId);
if (entity == null) {
return noEncontrado();
}
return Response.status(OK_200).entity(entity).build();
}
protected Response noEncontrado() {
return Response.status(NOT_FOUND_404).build();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy