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

ec.gob.senescyt.sniese.commons.resources.CatalogoResource Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
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