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;
|
2020-11-19 17:38:56 +01:00
|
|
|
|
import org.gcube.application.geoportal.model.InputStreamDescriptor;
|
2020-11-11 18:17:06 +01:00
|
|
|
|
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
2020-11-19 17:38:56 +01:00
|
|
|
|
import org.gcube.application.geoportal.model.concessioni.LayerConcessione;
|
|
|
|
|
import org.gcube.application.geoportal.model.concessioni.RelazioneScavo;
|
|
|
|
|
import org.gcube.application.geoportal.model.content.UploadedImage;
|
2020-11-17 17:34:42 +01:00
|
|
|
|
import org.gcube.application.geoportal.model.report.PublicationReport;
|
2020-11-19 17:38:56 +01:00
|
|
|
|
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
|
|
|
|
|
import org.gcube.application.geoportal.service.engine.StorageClientProvider;
|
|
|
|
|
import org.gcube.application.geoportal.service.model.internal.rest.AddSectionToConcessioneRequest;
|
|
|
|
|
import org.gcube.application.geoportal.service.model.internal.rest.AddSectionToConcessioneRequest.SHUBFileDescriptor;
|
|
|
|
|
import org.gcube.application.geoportal.service.utils.Serialization;
|
2020-11-17 17:34:42 +01:00
|
|
|
|
import org.json.JSONArray;
|
2020-11-11 18:17:06 +01:00
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
@Path(InterfaceConstants.Methods.CONCESSIONI)
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class Concessioni {
|
|
|
|
|
|
2020-11-19 17:38:56 +01:00
|
|
|
|
|
2020-11-19 18:50:20 +01:00
|
|
|
|
|
2020-11-20 17:03:42 +01:00
|
|
|
|
@PUT
|
2020-11-19 18:50:20 +01:00
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Path("publish/{"+InterfaceConstants.Parameters.PROJECT_ID+"}")
|
|
|
|
|
public String publish(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) {
|
|
|
|
|
try {
|
2020-11-20 17:03:42 +01:00
|
|
|
|
log.info("Publishing Concessione by id {} ",id);
|
2020-11-19 18:50:20 +01:00
|
|
|
|
Concessione conc=(Concessione) ConcessioneManager.getByID(Long.parseLong(id));
|
|
|
|
|
ConcessioneManager manager=ManagerFactory.getByRecord(conc);
|
|
|
|
|
log.debug("Loaded object {} ",conc);
|
|
|
|
|
|
|
|
|
|
PublicationReport rep=manager.commitSafely(true);
|
2020-11-20 17:03:42 +01:00
|
|
|
|
String toReturn=rep.prettyPrint();
|
|
|
|
|
log.debug("Publication report to send is "+toReturn);
|
|
|
|
|
return toReturn;
|
2020-11-19 18:50:20 +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-11 18:17:06 +01:00
|
|
|
|
@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-19 17:38:56 +01:00
|
|
|
|
Concessione toReturn=(Concessione) ConcessioneManager.getByID(Long.parseLong(id));
|
2020-11-17 17:34:42 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-19 17:38:56 +01:00
|
|
|
|
|
2020-11-11 18:17:06 +01:00
|
|
|
|
@PUT
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
2020-11-19 17:38:56 +01:00
|
|
|
|
public String registerNew(String toRegister) {
|
2020-11-11 18:17:06 +01:00
|
|
|
|
try {
|
|
|
|
|
log.info("Registering new Concessione "+toRegister);
|
2020-11-19 17:38:56 +01:00
|
|
|
|
Concessione conc=Serialization.read(toRegister, Concessione.class);
|
|
|
|
|
ConcessioneManager manager=ManagerFactory.registerNew(conc);
|
|
|
|
|
manager.commitSafely(false);
|
|
|
|
|
return manager.getRecord().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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-19 17:38:56 +01:00
|
|
|
|
|
2020-11-18 15:16:08 +01:00
|
|
|
|
@PUT
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
2020-11-20 17:03:42 +01:00
|
|
|
|
@Path("section/{"+InterfaceConstants.Parameters.PROJECT_ID+"}")
|
|
|
|
|
public String addSection(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
2020-11-19 17:38:56 +01:00
|
|
|
|
AddSectionToConcessioneRequest request) {
|
2020-11-11 18:17:06 +01:00
|
|
|
|
try {
|
2020-11-19 17:38:56 +01:00
|
|
|
|
log.info("Adding section to Concessione {} ",id);
|
|
|
|
|
Concessione toReturn=(Concessione) ConcessioneManager.getByID(Long.parseLong(id));
|
|
|
|
|
ConcessioneManager manager=ManagerFactory.getByRecord(toReturn);
|
|
|
|
|
log.debug("Loaded object {} ",toReturn);
|
2020-11-20 17:03:42 +01:00
|
|
|
|
log.debug("Request is {}",request);
|
2020-11-19 17:38:56 +01:00
|
|
|
|
|
|
|
|
|
InputStreamDescriptor[] streams=new InputStreamDescriptor[request.getStreams().size()];
|
|
|
|
|
|
|
|
|
|
StorageClientProvider storage=ImplementationProvider.get().getStorageProvider();
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<streams.length;i++) {
|
|
|
|
|
SHUBFileDescriptor sent=request.getStreams().get(i);
|
|
|
|
|
streams[i]=new InputStreamDescriptor(storage.open(sent.getShubID()), sent.getFilename());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(request.getSection()) {
|
|
|
|
|
case PIANTA :manager.addPiantaFineScavo((LayerConcessione) request.getToRegister(),streams);
|
|
|
|
|
break;
|
|
|
|
|
case POSIZIONAMENTO : manager.setPosizionamento((LayerConcessione) request.getToRegister(),streams);
|
|
|
|
|
break;
|
|
|
|
|
case RELAZIONE : manager.setRelazioneScavo((RelazioneScavo)request.getToRegister(), streams[0]);
|
|
|
|
|
break;
|
|
|
|
|
case UPLOADED_IMG : manager.addImmagineRappresentativa((UploadedImage)request.getToRegister(), streams[0]);
|
|
|
|
|
break;
|
|
|
|
|
default : throw new Exception("Unrecognized section");
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 17:03:42 +01:00
|
|
|
|
// PublicationReport report=manager.commitSafely(false);
|
|
|
|
|
Concessione c=manager.commit(false);
|
|
|
|
|
log.debug("Published "+c.asJson());
|
|
|
|
|
return c.validate().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-19 17:38:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-11 18:17:06 +01:00
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-19 17:38:56 +01:00
|
|
|
|
|
2020-11-11 18:17:06 +01:00
|
|
|
|
}
|