revisited the business logic to publish on (mongo) server by
geoportal-client
This commit is contained in:
parent
b1696fd356
commit
77968d2835
|
@ -74,7 +74,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
LOG.debug("Built map with form data: " + toMap);
|
LOG.debug("Built map with form data: " + toMap);
|
||||||
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
|
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
|
||||||
|
|
||||||
Concessione concessioneService = null;
|
Concessione concessioneNew;
|
||||||
String mongoId = null;
|
String mongoId = null;
|
||||||
ServiceUtil serviceUtil = new ServiceUtil();
|
ServiceUtil serviceUtil = new ServiceUtil();
|
||||||
MongoConcessioni clientMongo = null;
|
MongoConcessioni clientMongo = null;
|
||||||
|
@ -97,11 +97,11 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
LOG.debug(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " building with client obj: " + idp);
|
LOG.debug(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " building with client obj: " + idp);
|
||||||
Concessione concessione = ConvertToServiceModel.toConcessione(idp, user);
|
Concessione concessione = ConvertToServiceModel.toConcessione(idp, user);
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " as server obj: " + concessione);
|
LOG.debug("Built " + ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " as server obj: " + concessione);
|
||||||
|
|
||||||
//Register New Concessione
|
|
||||||
concessioneService=clientMongo.createNew(concessione);
|
|
||||||
mongoId = concessioneService.getMongo_id();
|
|
||||||
|
|
||||||
|
//Register New Concessione
|
||||||
|
concessioneNew=clientMongo.createNew(concessione);
|
||||||
|
|
||||||
|
|
||||||
// ABSTRACT_RELAZIONE_DI_SCAVO
|
// ABSTRACT_RELAZIONE_DI_SCAVO
|
||||||
list = toMap.get(ConcessioniFormCardTitle.ABSTRACT_RELAZIONE_DI_SCAVO);
|
list = toMap.get(ConcessioniFormCardTitle.ABSTRACT_RELAZIONE_DI_SCAVO);
|
||||||
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
|
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
|
||||||
|
@ -126,18 +126,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
LOG.debug(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " building with client obj: " + rds);
|
LOG.debug(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " building with client obj: " + rds);
|
||||||
RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(abstractRelazioneDiScavo, rds);
|
RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(abstractRelazioneDiScavo, rds);
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " as server obj: " + relazioneDiScavo);
|
LOG.debug("Built " + ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " as server obj: " + relazioneDiScavo);
|
||||||
//Setting Relazione
|
|
||||||
concessioneService.setRelazioneScavo(relazioneDiScavo);
|
|
||||||
|
|
||||||
// Building TempFile for Relazione
|
//Setting Relazione
|
||||||
List<TempFile> files = serviceUtil.toTemFiles(rds.getFilesUploaded());
|
concessioneNew.setRelazioneScavo(relazioneDiScavo);
|
||||||
// Upload file to Concessione
|
|
||||||
if (files!=null && files.size() > 0) {
|
|
||||||
// saving into back-end
|
|
||||||
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.RELAZIONE, files);
|
|
||||||
clientMongo.registerFile(mongoId, request);
|
|
||||||
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.RELAZIONE + "with "+files.size()+" file/s");
|
|
||||||
}
|
|
||||||
|
|
||||||
// IMMAGINI_RAPPRESENTATIVE
|
// IMMAGINI_RAPPRESENTATIVE
|
||||||
list = toMap.get(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE);
|
list = toMap.get(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE);
|
||||||
|
@ -146,22 +138,22 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
"Error: no data found for " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getTitle());
|
"Error: no data found for " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getTitle());
|
||||||
|
|
||||||
List<GenericDatasetBean> imgRaprsLst = list.get(0).getListGDB();
|
List<GenericDatasetBean> imgRaprsLst = list.get(0).getListGDB();
|
||||||
for (GenericDatasetBean imgRapr : imgRaprsLst) {
|
List<UploadedImage> immaginiRappresentativeService = null;
|
||||||
LOG.debug("\n\n");
|
if(imgRaprsLst.size()>0) {
|
||||||
LOG.debug(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " building with client obj: " + imgRapr);
|
immaginiRappresentativeService = new ArrayList<UploadedImage>(imgRaprsLst.size());
|
||||||
UploadedImage img = ConvertToServiceModel.toImmaginiRappresentative(imgRapr);
|
for (GenericDatasetBean imgRapr : imgRaprsLst) {
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " as server obj: " + img);
|
LOG.debug("\n\n");
|
||||||
|
LOG.debug(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " building with client obj: " + imgRapr);
|
||||||
// Building TempFile for Immagini
|
UploadedImage img = ConvertToServiceModel.toImmaginiRappresentative(imgRapr);
|
||||||
files = serviceUtil.toTemFiles(imgRapr.getFilesUploaded());
|
LOG.debug("Built " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " as server obj: " + img);
|
||||||
// Upload file to Concessione
|
immaginiRappresentativeService.add(img);
|
||||||
if (files!=null && files.size() > 0) {
|
|
||||||
// saving into back-end
|
|
||||||
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.IMMAGINI, files);
|
|
||||||
clientMongo.registerFile(mongoId, request);
|
|
||||||
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.IMMAGINI + "with "+files.size()+" file/s");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Setting Immagini Rappresentative
|
||||||
|
if(immaginiRappresentativeService!=null) {
|
||||||
|
concessioneNew.setImmaginiRappresentative(immaginiRappresentativeService);
|
||||||
|
}
|
||||||
|
|
||||||
// POSIZIONAMENTO_DELL_AREA_DI_INDAGINE
|
// POSIZIONAMENTO_DELL_AREA_DI_INDAGINE
|
||||||
list = toMap.get(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE);
|
list = toMap.get(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE);
|
||||||
|
@ -171,21 +163,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
|
|
||||||
listGDB = list.get(0).getListGDB();
|
listGDB = list.get(0).getListGDB();
|
||||||
GenericDatasetBean pad = listGDB.get(0);
|
GenericDatasetBean pad = listGDB.get(0);
|
||||||
LOG.debug("\n\n");
|
LayerConcessione layerPad = null;
|
||||||
LOG.debug(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " building with client obj: "
|
if(pad!=null) {
|
||||||
+ pad);
|
LOG.debug("\n\n");
|
||||||
LayerConcessione layerPad = ConvertToServiceModel.toLayerConcessione(pad);
|
LOG.debug(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " building with client obj: "
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " as server obj: "
|
+ pad);
|
||||||
+ layerPad);
|
layerPad = ConvertToServiceModel.toLayerConcessione(pad);
|
||||||
|
LOG.debug("Built " + ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " as server obj: "
|
||||||
|
+ layerPad);
|
||||||
|
}
|
||||||
|
|
||||||
// Building TempFile for POSIZIONAMENTO
|
//Setting Posizionamento Di Scavo
|
||||||
files = serviceUtil.toTemFiles(pad.getFilesUploaded());
|
if(layerPad!=null) {
|
||||||
// Upload file to Concessione
|
concessioneNew.setPosizionamentoScavo(layerPad);
|
||||||
if (files!=null && files.size() > 0) {
|
|
||||||
// saving into back-end
|
|
||||||
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.POSIZIONAMENTO, files);
|
|
||||||
clientMongo.registerFile(mongoId, request);
|
|
||||||
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.POSIZIONAMENTO + "with "+files.size()+" file/s");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PIANTA_DI_FINE_SCAVO
|
// PIANTA_DI_FINE_SCAVO
|
||||||
|
@ -195,25 +185,91 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
"Error: no data found for " + ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO.getTitle());
|
"Error: no data found for " + ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO.getTitle());
|
||||||
|
|
||||||
listGDB = list.get(0).getListGDB();
|
listGDB = list.get(0).getListGDB();
|
||||||
|
List<GenericDatasetBean> listPfs = listGDB;
|
||||||
//Managing N:N
|
//Managing N:N
|
||||||
for (GenericDatasetBean pfs : listGDB) {
|
List<LayerConcessione> pianteFineScavo = null;
|
||||||
LOG.debug("\n\n");
|
if(listPfs.size()>0) {
|
||||||
LOG.debug(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " building with client obj: " + pfs);
|
pianteFineScavo = new ArrayList<LayerConcessione>(listPfs.size());
|
||||||
LayerConcessione layerPfs = ConvertToServiceModel.toLayerConcessione(pfs);
|
for (GenericDatasetBean pfs : listPfs) {
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " as server obj: " + layerPfs);
|
LOG.debug("\n\n");
|
||||||
|
LOG.debug(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " building with client obj: " + pfs);
|
||||||
|
LayerConcessione layerPfs = ConvertToServiceModel.toLayerConcessione(pfs);
|
||||||
|
LOG.debug("Built " + ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " as server obj: " + layerPfs);
|
||||||
|
pianteFineScavo.add(layerPfs);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Setting Piante fine Scavo
|
||||||
|
if(pianteFineScavo!=null) {
|
||||||
|
concessioneNew.setPianteFineScavo(pianteFineScavo);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Registering Meta
|
||||||
|
clientMongo.replace(concessioneNew);
|
||||||
|
mongoId = concessioneNew.getMongo_id();
|
||||||
|
LOG.info("Registered the meta. Called mongo.replace for: "+concessioneNew);
|
||||||
|
|
||||||
|
//UPLOADING FILES
|
||||||
|
LOG.info("Now uploading the files...");
|
||||||
|
// Building TempFile for Relazione
|
||||||
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
||||||
|
List<TempFile> files = serviceUtil.toTemFiles(rds.getFilesUploaded());
|
||||||
|
// Upload file to Concessione. Should be one file.
|
||||||
|
if (files!=null && files.size() > 0) {
|
||||||
|
// saving into back-end
|
||||||
|
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.RELAZIONE, files);
|
||||||
|
clientMongo.registerFile(mongoId, request);
|
||||||
|
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.RELAZIONE + "with "+files.size()+" file/s");
|
||||||
|
}
|
||||||
|
|
||||||
// Building TempFile for PIANTA_DI_FINE_SCAVO
|
//IMMAGINI RAPPRESENTATIVE
|
||||||
files = serviceUtil.toTemFiles(pfs.getFilesUploaded());
|
for (int i=0; i<imgRaprsLst.size(); i++) {
|
||||||
// Upload file to Concessione Section by Path 'Relazione'
|
LOG.debug("\n\n");
|
||||||
|
GenericDatasetBean imgRapr = imgRaprsLst.get(i);
|
||||||
|
// Building TempFile for Immagini
|
||||||
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
||||||
|
files = serviceUtil.toTemFiles(imgRapr.getFilesUploaded());
|
||||||
|
// Upload file to Concessione. The size is always 1 so it is consistent with the 'for' index
|
||||||
if (files!=null && files.size() > 0) {
|
if (files!=null && files.size() > 0) {
|
||||||
// saving into back-end
|
// saving into back-end
|
||||||
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.PIANTE, files);
|
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.imgByIndex(i), files);
|
||||||
clientMongo.registerFile(mongoId, request);
|
clientMongo.registerFile(mongoId, request);
|
||||||
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.PIANTE + "with "+files.size()+" file/s");
|
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.IMMAGINI + "with "+files.size()+" file/s");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//POSIZIONAMENTO
|
||||||
|
// Building TempFile for POSIZIONAMENTO
|
||||||
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
||||||
|
files = serviceUtil.toTemFiles(pad.getFilesUploaded());
|
||||||
|
// Upload file to Concessione
|
||||||
|
if (files!=null && files.size() > 0) {
|
||||||
|
// saving into back-end
|
||||||
|
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.POSIZIONAMENTO, files);
|
||||||
|
clientMongo.registerFile(mongoId, request);
|
||||||
|
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.POSIZIONAMENTO + "with "+files.size()+" file/s");
|
||||||
|
}
|
||||||
|
|
||||||
|
//PIANTE FINE SCAVO
|
||||||
|
if(listPfs.size()>0) {
|
||||||
|
for (int i=0; i<listPfs.size(); i++) {
|
||||||
|
// Building TempFile for PIANTA_DI_FINE_SCAVO
|
||||||
|
GenericDatasetBean pfs = listPfs.get(i);
|
||||||
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
||||||
|
files = serviceUtil.toTemFiles(pfs.getFilesUploaded());
|
||||||
|
// Upload file to Concessione Section by Path 'Relazione'
|
||||||
|
if (files!=null && files.size() > 0) {
|
||||||
|
// saving into back-end
|
||||||
|
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.piantaByIndex(i), files);
|
||||||
|
clientMongo.registerFile(mongoId, request);
|
||||||
|
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.PIANTE + "with "+files.size()+" file/s");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error on converting form data: ", e);
|
LOG.error("Error on converting form data: ", e);
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
@ -224,6 +280,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
|
|
||||||
Concessione concessione;
|
Concessione concessione;
|
||||||
if(clientMongo!=null && mongoId!=null) {
|
if(clientMongo!=null && mongoId!=null) {
|
||||||
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
||||||
concessione = clientMongo.publish(mongoId);
|
concessione = clientMongo.publish(mongoId);
|
||||||
//server report
|
//server report
|
||||||
ValidationReport report = concessione.getReport();
|
ValidationReport report = concessione.getReport();
|
||||||
|
|
|
@ -5,6 +5,7 @@ package org.gcube.portlets.user.geoportaldataentry.server;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
@ -67,20 +68,27 @@ public class SessionUtil {
|
||||||
* Retrieve the current scope by using the portal manager.
|
* Retrieve the current scope by using the portal manager.
|
||||||
*
|
*
|
||||||
* @param request the request
|
* @param request the request
|
||||||
* @param setInThread the set in thread
|
* @param setContextsInThread set the scope and the security token into current thread
|
||||||
* @return a GcubeUser object
|
* @return a GcubeUser object
|
||||||
*/
|
*/
|
||||||
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
|
public static String getCurrentContext(HttpServletRequest request, boolean setContextsInThread){
|
||||||
|
|
||||||
if(request == null)
|
if(request == null)
|
||||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||||
|
|
||||||
PortalContext pContext = PortalContext.getConfiguration();
|
PortalContext pContext = PortalContext.getConfiguration();
|
||||||
String context = pContext.getCurrentScope(request);
|
String context = pContext.getCurrentScope(request);
|
||||||
LOG.debug("Returning context " + context);
|
|
||||||
|
if(setContextsInThread) {
|
||||||
if(context != null && setInThread)
|
GCubeUser user = getCurrentUser(request);
|
||||||
ScopeProvider.instance.set(context);
|
String token = pContext.getCurrentUserToken(context, user.getUsername());
|
||||||
|
|
||||||
|
if(context!=null)
|
||||||
|
ScopeProvider.instance.set(context);
|
||||||
|
|
||||||
|
if(token!=null)
|
||||||
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue