package org.gcube.application.geoportal.service.rest; import java.util.Collection; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.managers.ConcessioneManager; import org.gcube.application.geoportal.managers.ManagerFactory; import org.gcube.application.geoportal.model.concessioni.Concessione; import lombok.extern.slf4j.Slf4j; @Path(InterfaceConstants.Methods.CONCESSIONI) @Slf4j public class Concessioni { @GET @Produces(MediaType.APPLICATION_JSON) @Path("{"+InterfaceConstants.Parameters.PROJECT_ID+"}") public Concessione getById(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) { try { log.info("Loading Concessione by id {} ",id); return (Concessione) ManagerFactory.getByRecordID(Long.parseLong(id)).getRecord(); }catch(WebApplicationException e){ log.warn("Unable to serve request",e); throw e; }catch(Throwable e){ log.warn("Unable to serve request",e); throw new WebApplicationException("Unable to serve request", e); } } @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Concessione registerNew(Concessione toRegister) { try { log.info("Registering new Concessione "+toRegister); ConcessioneManager manager=ManagerFactory.registerNew(toRegister); manager.commitSafely(false); return manager.getRecord(); }catch(WebApplicationException e){ log.warn("Unable to serve request",e); throw e; }catch(Throwable e){ log.warn("Unable to serve request",e); throw new WebApplicationException("Unable to serve request", e); } } public Concessione addSection() { try { log.info("Loading all projects.."); throw new RuntimeException("Feature not yet available"); }catch(WebApplicationException e){ log.warn("Unable to serve request",e); throw e; }catch(Throwable e){ log.warn("Unable to serve request",e); throw new WebApplicationException("Unable to serve request", e); } } @GET @Produces(MediaType.APPLICATION_JSON) public Collection getList(){ try { return ManagerFactory.getList(Concessione.class); }catch(WebApplicationException e){ log.warn("Unable to serve request",e); throw e; }catch(Throwable e){ log.warn("Unable to serve request",e); throw new WebApplicationException("Unable to serve request", e); } } }