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

104 lines
3.2 KiB
Java
Raw Normal View History

2020-11-11 18:17:06 +01:00
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;
2020-11-17 17:34:42 +01:00
import org.gcube.application.geoportal.model.report.PublicationReport;
import org.gcube.application.geoportal.utils.Serialization;
import org.json.JSONArray;
import org.json.JSONObject;
2020-11-11 18:17:06 +01:00
import lombok.extern.slf4j.Slf4j;
@Path(InterfaceConstants.Methods.CONCESSIONI)
@Slf4j
public class Concessioni {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{"+InterfaceConstants.Parameters.PROJECT_ID+"}")
2020-11-17 17:34:42 +01:00
public String getById(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) {
2020-11-11 18:17:06 +01:00
try {
log.info("Loading Concessione by id {} ",id);
2020-11-17 17:34:42 +01:00
Concessione toReturn=(Concessione) ManagerFactory.getByRecordID(Long.parseLong(id)).getRecord();
log.debug("Loaded object {} ",toReturn);
return toReturn.asJson();
2020-11-11 18:17:06 +01:00
}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)
2020-11-17 17:34:42 +01:00
public String registerNew(Concessione toRegister) {
2020-11-11 18:17:06 +01:00
try {
log.info("Registering new Concessione "+toRegister);
ConcessioneManager manager=ManagerFactory.registerNew(toRegister);
2020-11-17 17:34:42 +01:00
PublicationReport report=manager.commitSafely(false);
return report.prettyPrint();
2020-11-11 18:17:06 +01:00
}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);
}
}
2020-11-18 15:16:08 +01:00
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("{"+InterfaceConstants.Parameters.PROJECT_ID+"}")
public String modify(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) {
2020-11-11 18:17:06 +01:00
try {
2020-11-18 15:16:08 +01:00
log.info("Add Section");
2020-11-11 18:17:06 +01:00
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)
2020-11-17 17:34:42 +01:00
public String getList(){
2020-11-11 18:17:06 +01:00
try {
2020-11-17 17:34:42 +01:00
Collection<Concessione> toReturn=ManagerFactory.getList(Concessione.class);
log.debug("Found "+toReturn.size()+" elements..");
JSONArray array=new JSONArray();
for(Concessione found:toReturn) {
array.put(found.asJson());
}
return array.toString();
2020-11-11 18:17:06 +01:00
}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);
}
}
}