This repository has been archived on 2021-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/Concessioni.java

89 lines
2.6 KiB
Java
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<Concessione> 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);
}
}
}