diff --git a/.classpath b/.classpath index 70ce04a..616c851 100644 --- a/.classpath +++ b/.classpath @@ -27,6 +27,8 @@ + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConcessioniFormCardTitle.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConcessioniFormCardTitle.java index e3ea348..7aa8b67 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConcessioniFormCardTitle.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConcessioniFormCardTitle.java @@ -3,7 +3,7 @@ package org.gcube.portlets.user.geoportaldataentry.client; public enum ConcessioniFormCardTitle { INFORMAZIONI_DI_PROGETTO("Informazioni", "Informazioni di Progetto", 1, false), - RELAZIONI_DI_SCAVO("Relazione di Scavo", "Relazioni di Scavo", 2, false), + RELAZIONE_DI_SCAVO("Relazione di Scavo", "Relazione di Scavo", 2, false), IMMAGINI_RAPPRESENTATIVE("Immagini Rappresentative", "Immagini Rappresentative", 3, true), POSIZIONAMENTO_DELL_AREA_DI_INDAGINE("Posizionamento", "Posizionamento dell'Area di Indagine", 4, false), PIANTA_DI_FINE_SCAVO("Pianta di Fine Scavo", "Pianta di Fine Scavo", 5, true); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 2bac2e5..2963f3c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -140,9 +140,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { if(theMetaType.contains(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO.getKey().toLowerCase())) { geonaForm.setFormCardTitle(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO); treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO.getOrder(), geonaForm); - }else if(theMetaType.contains(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO.getKey().toLowerCase())) { - geonaForm.setFormCardTitle(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO); - treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO.getOrder(), geonaForm); + }else if(theMetaType.contains(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO.getKey().toLowerCase())) { + geonaForm.setFormCardTitle(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO); + treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO.getOrder(), geonaForm); }else if(theMetaType.contains(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getKey().toLowerCase())) { geonaForm.setFormCardTitle(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE); treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getOrder(), geonaForm); @@ -196,7 +196,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { alert.setClose(false); modal.add(alert); modal.setCloseVisible(true); - resetUI(); + //resetUI(); } @Override @@ -207,9 +207,11 @@ public class GeoPortalDataEntryApp implements EntryPoint { alert.setClose(false); modal.add(alert); modal.setCloseVisible(true); - resetUI(); + //resetUI(); } }); + + modal.show(); } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java index 2e6254b..7ed0bef 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java @@ -49,11 +49,6 @@ public class ConvertToServiceModel { if(authors!=null) { concessione.setAuthors(authors); } - - - //TODO - //concessione.setCentroidLat(centroidLat); -// concessione.setCentroidLong(centroidLong); List contributors = mapFields.get("Contributore"); if(contributors!=null) { @@ -65,10 +60,6 @@ public class ConvertToServiceModel { //concessione.setCreationTime(Instant.now()); concessione.setCreationUser(user.getUsername()); - //TODO -// concessione.setDataFineScavo(dataFineScavo); -// concessione.setDataInizioScavo(dataInizioScavo); - List dataInizProgettoList = mapFields.get("Data inizio Progetto"); if(dataInizProgettoList!=null && dataInizProgettoList.size()>0) { String inizioProgetto = dataInizProgettoList.get(0); @@ -103,8 +94,7 @@ public class ConvertToServiceModel { List licenzaLst = mapFields.get("ID Licenza"); if(licenzaLst!=null && licenzaLst.size()>0) { - //TODO FABIO - //concessione.setLicenza() + concessione.setLicenzaID(licenzaLst.get(0)); } List introduzioneLst = mapFields.get("Introduzione"); @@ -181,7 +171,6 @@ public class ConvertToServiceModel { relazioneScavo.setResponsabili(responsabiliLst); } - List licenzaIdList = mapFields.get("ID Licenza"); if(licenzaIdList!=null && licenzaIdList.size()>0) { relazioneScavo.setLicenseID(licenzaIdList.get(0)); @@ -220,6 +209,11 @@ public class ConvertToServiceModel { uplaodedImage.setResponsabili(responsabileLst); } + List licenzaIdList = mapFields.get("ID Licenza"); + if(licenzaIdList!=null && licenzaIdList.size()>0) { + uplaodedImage.setLicenseID(licenzaIdList.get(0)); + } + //TODO??? List autoreLst = mapFields.get("Autore"); if(autoreLst!=null) { @@ -244,8 +238,7 @@ public class ConvertToServiceModel { if(valutazioneQualitaLst!=null && valutazioneQualitaLst.size()>0) { layerConcessione.setValutazioneQualita(valutazioneQualitaLst.get(0)); } - - + List metodoRaccoltaDatiLst = mapFields.get("Metodo di raccolta dei dati"); if(metodoRaccoltaDatiLst!=null && metodoRaccoltaDatiLst.size()>0) { layerConcessione.setMetodoRaccoltaDati(metodoRaccoltaDatiLst.get(0)); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java index b865270..9cfc345 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java @@ -1,10 +1,26 @@ package org.gcube.portlets.user.geoportaldataentry.server; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.gcube.application.geoportal.managers.ConcessioneManager; +import org.gcube.application.geoportal.managers.ManagerFactory; +import org.gcube.application.geoportal.model.InputStreamDescriptor; +import org.gcube.application.geoportal.model.concessioni.Concessione; +import org.gcube.application.geoportal.model.concessioni.LayerConcessione; +import org.gcube.application.geoportal.model.concessioni.RelazioneScavo; +import org.gcube.application.geoportal.model.content.UploadedImage; +import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle; import org.gcube.portlets.user.geoportaldataentry.client.GreetingService; -import org.gcube.portlets.user.geoportaldataentry.shared.FieldVerifier; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; +import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; @@ -12,47 +28,173 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; * The server side implementation of the RPC service. */ @SuppressWarnings("serial") -public class GreetingServiceImpl extends RemoteServiceServlet implements - GreetingService { +public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService { + + private static final Logger LOG = LoggerFactory.getLogger(GreetingServiceImpl.class); - public String greetServer(String input) throws IllegalArgumentException { - // Verify that the input is valid. - if (!FieldVerifier.isValidName(input)) { - // If the input is not valid, throw an IllegalArgumentException back to - // the client. - throw new IllegalArgumentException( - "Name must be at least 4 characters long"); - } + @Override + public String saveGeonaDataForms(List listGeonaFormObjects) throws Exception { + LOG.info("saveGeonaDataForms called"); + + HashMap> toMap = + new HashMap>(); - String serverInfo = getServletContext().getServerInfo(); - String userAgent = getThreadLocalRequest().getHeader("User-Agent"); + for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) { - // Escape data from the client to avoid cross-site script vulnerabilities. - input = escapeHtml(input); - userAgent = escapeHtml(userAgent); + ConcessioniFormCardTitle theType = geoNaFormDataObject.getTheType(); - return "Hello, " + input + "!

I am running " + serverInfo - + ".

It looks like you are using:
" + userAgent; - } + List listForm = toMap.get(theType); + if (listForm == null) { + listForm = new ArrayList(); + } - /** - * Escape an html string. Escaping data received from the client helps to - * prevent cross-site script vulnerabilities. - * - * @param html the html string to escape - * @return the escaped string - */ - private String escapeHtml(String html) { - if (html == null) { - return null; - } - return html.replaceAll("&", "&").replaceAll("<", "<").replaceAll( - ">", ">"); - } - - @Override - public String saveGeonaDataForms(List listGeonaFormObjects) throws Exception{ - - return null; - } + listForm.add(geoNaFormDataObject); + toMap.put(theType, listForm); + } + if(LOG.isDebugEnabled()) + prettyPrintClientDataEntryMap(toMap); + + LOG.debug("Built map with form data: "+toMap); + GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest()); + + //Saving Data + //Informazioni di Progetto + List list = toMap.get(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO); + if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null) + throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO.getTitle()); + + List listGDB = list.get(0).getListGDB(); + GenericDatasetBean idp = listGDB.get(0); + LOG.debug("\n\n"); + LOG.debug(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO+" building with client obj: "+idp); + Concessione concessione = ConvertToServiceModel.toConcessione(idp, user); + LOG.debug("Built "+ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO+" as server obj: "+concessione); + //saving into back-end + ConcessioneManager manager = ManagerFactory.registerNew(concessione); + + //RELAZIONE_DI_SCAVO + list = toMap.get(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO); + if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null) + throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO.getTitle()); + + listGDB = list.get(0).getListGDB(); + GenericDatasetBean rds = listGDB.get(0); + LOG.debug("\n\n"); + LOG.debug(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO+" building with client obj: "+rds); + RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(rds); + LOG.debug("Built "+ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO+" as server obj: "+relazioneDiScavo); + //Should be only one + for (FileUploaded fileUploaded : rds.getFilesUploaded()) { + FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath()); + InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName()); + //saving into back-end + manager.setRelazioneScavo(relazioneDiScavo, isd); + } + + + //IMMAGINI_RAPPRESENTATIVE + list = toMap.get(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE); + if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null) + throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getTitle()); + + List imgRaprsLst = list.get(0).getListGDB(); + for (GenericDatasetBean imgRapr : imgRaprsLst) { + LOG.debug("\n\n"); + LOG.debug(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE+" building with client obj: "+imgRapr); + UploadedImage img = ConvertToServiceModel.toImmaginiRappresentative(imgRapr); + LOG.debug("Built "+ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE+" as server obj: "+img); + for (FileUploaded fileUploaded : imgRapr.getFilesUploaded()) { + LOG.debug("Adding uploaded file: "+fileUploaded.getFileName() + " to "+img); + FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath()); + InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName()); + //saving into back-end + manager.addImmagineRappresentativa(img,isd); + } + } + + //POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + list = toMap.get(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE); + if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null) + throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE.getTitle()); + + listGDB = list.get(0).getListGDB(); + GenericDatasetBean pad = listGDB.get(0); + LOG.debug("\n\n"); + LOG.debug(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE+" building with client obj: "+pad); + LayerConcessione layerPad = ConvertToServiceModel.toLayerConcessione(pad); + LOG.debug("Built "+ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE+" as server obj: "+layerPad); + for (FileUploaded fileUploaded : pad.getFilesUploaded()) { + LOG.debug("Adding uploaded file: "+fileUploaded.getFileName() + " to "+layerPad); + FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath()); + InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName()); + //saving into back-end + manager.setPosizionamento(layerPad, isd); + } + + //PIANTA_DI_FINE_SCAVO + list = toMap.get(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO); + if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null) + throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO.getTitle()); + + listGDB = list.get(0).getListGDB(); + GenericDatasetBean pfs = listGDB.get(0); + 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); + for (FileUploaded fileUploaded : pfs.getFilesUploaded()) { + LOG.debug("Adding uploaded file: "+fileUploaded.getFileName() + " to "+layerPfs); + FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath()); + InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName()); + //saving into back-end + manager.addPiantaFineScavo(layerPfs, isd); + } + + //If true -> data are published into the SDI + Boolean publish=false; + + /*Chiedo al manager di salvare il progetto, causando : + *scrittura sul WS + *pubblicazione sull'SDI (boolean publish) + *scrittura sul DB di applicazione sia dei meta che dei vari link */ +// Concessione registered=manager.commit(publish); +// +// LOG.info("Registered: "+registered); +// String link = null; +// try { +// link = ((WorkspaceContent)registered.getRelazioneScavo().getActualContent().get(0)).getLink(); +// }catch (Exception e) { +// // TODO: handle exception +// } + + String link = "toTest"; + + if(link!=null) + return "Project saved successfully"; + else + return "Project saved with errors"; + } + + + private void prettyPrintClientDataEntryMap(HashMap> toMap) { + + for (ConcessioniFormCardTitle theType : toMap.keySet()) { + LOG.debug("\n\n"+theType); + List list = toMap.get(theType); + for (GeoNaFormDataObject geoNaFormDataObject : list) { + LOG.debug("\t has "+geoNaFormDataObject.getListGDB().size() +" data bean/s"); + int i = 0; + for (GenericDatasetBean gbd : geoNaFormDataObject.getListGDB()) { + LOG.debug("\t "+ ++i +") "+GenericDatasetBean.class.getSimpleName()+" entries:"); + Map> map = gbd.getFormDataEntryFields(); + for (String keyEntry : map.keySet()) { + LOG.debug("\t "+keyEntry + ": "+map.get(keyEntry)); + } + for (FileUploaded fup : gbd.getFilesUploaded()) { + LOG.debug("\t "+fup); + } + } + } + } + } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java new file mode 100644 index 0000000..c393926 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java @@ -0,0 +1,108 @@ +/** + * + */ +package org.gcube.portlets.user.geoportaldataentry.server; + +import javax.servlet.http.HttpServletRequest; + +import org.gcube.common.portal.PortalContext; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.liferay.portal.service.UserLocalServiceUtil; + + + +// TODO: Auto-generated Javadoc +/** + * The Class SessionUtil. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Oct 20, 2020 + */ +public class SessionUtil { + + /** The log. */ + private static Logger LOG = LoggerFactory.getLogger(SessionUtil.class); + + /** + * Checks if is into portal. + * + * @return true, if is into portal + */ + public static boolean isIntoPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + }catch (Exception ex) { + LOG.debug("Development Mode ON"); + return false; + } + } + + /** + * Retrieve the current user by using the portal manager. + * + * @param request the request + * @return a GcubeUser object + */ + public static GCubeUser getCurrentUser(HttpServletRequest request){ + + if(request == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + PortalContext pContext = PortalContext.getConfiguration(); + GCubeUser user = pContext.getCurrentUser(request); + LOG.debug("Returning user " + user); + return user; + } + + /** + * Retrieve the current scope by using the portal manager. + * + * @param request the request + * @param setInThread the set in thread + * @return a GcubeUser object + */ + public static String getCurrentContext(HttpServletRequest request, boolean setInThread){ + + if(request == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + PortalContext pContext = PortalContext.getConfiguration(); + String context = pContext.getCurrentScope(request); + LOG.debug("Returning context " + context); + + if(context != null && setInThread) + ScopeProvider.instance.set(context); + + return context; + } + + /** + * Retrieve the group given the scope. + * + * @param scope the scope + * @return the group from scope + * @throws UserManagementSystemException the user management system exception + * @throws GroupRetrievalFault the group retrieval fault + */ + public static GCubeGroup getGroupFromScope(String scope) throws UserManagementSystemException, GroupRetrievalFault{ + + if(scope == null || scope.isEmpty()) + throw new IllegalArgumentException("Scope is missing here!!"); + + GroupManager gm = new LiferayGroupManager(); + long groupId = gm.getGroupIdFromInfrastructureScope(scope); + return gm.getGroup(groupId); + + } +}