From 5e480535db9e3d81193e7bf2b10b12774428946c Mon Sep 17 00:00:00 2001 From: francesco Date: Tue, 20 Oct 2020 15:25:26 +0200 Subject: [PATCH] integration with service completed --- .../ConstantsGeoPortalDataEntryApp.java | 2 + .../client/GeoPortalDataEntryApp.java | 24 +++--- .../client/ui/GeonaDataEntryMainForm.java | 3 +- .../server/ConvertToServiceModel.java | 51 +++++++++++-- .../server/GreetingServiceImpl.java | 4 +- .../client/GwtTestGeoPortalDataEntryApp.java | 75 ------------------- .../geoportaldataentry/client/TestClass.java | 21 ++++++ 7 files changed, 87 insertions(+), 93 deletions(-) delete mode 100644 src/test/java/org/gcube/portlets/user/geoportaldataentry/client/GwtTestGeoPortalDataEntryApp.java create mode 100644 src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index a9ca6d9..d110dbc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -7,4 +7,6 @@ public class ConstantsGeoPortalDataEntryApp { public static final String DATE_FORMAT = ConstantsMPFormBuilder.DATE_FORMAT; public static final String TIME_FORMAT = ConstantsMPFormBuilder.TIME_FORMAT; + + public static final String HOURS_MINUTES_SEPARATOR = ConstantsMPFormBuilder.HOURS_MINUTES_SEPARATOR; } 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 2963f3c..33d1c8f 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 @@ -109,14 +109,20 @@ public class GeoPortalDataEntryApp implements EntryPoint { resetUI(); //ordered values for (GeoNaFormCardModel geonaForm : orderedCards) { - CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(geonaForm.getMetadataProfileBean()),appManagerBus); - geonaForm.setMetadataForm(baseForm); - String key = geonaForm.getMetadataProfileBean().getType(); - if(geonaForm.getFormCardTitle()!=null) { - key = geonaForm.getFormCardTitle().getTitle(); - } - geoNaMainForm.addForm(key, geonaForm); - mapForms.put(key, geonaForm); + + //TODO TO TEST + //if(geonaForm.getFormCardTitle().equals(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO)){ + + CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(geonaForm.getMetadataProfileBean()),appManagerBus); + geonaForm.setMetadataForm(baseForm); + String key = geonaForm.getMetadataProfileBean().getType(); + if(geonaForm.getFormCardTitle()!=null) { + key = geonaForm.getFormCardTitle().getTitle(); + } + geoNaMainForm.addForm(key, geonaForm); + mapForms.put(key, geonaForm); + + //} } mainPanel.setLoaderVisible("", false); } @@ -224,7 +230,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { //means the form was not submitted if(mapForms.size()>0) { - boolean confirm = Window.confirm("The data are not saved and will be lost, Confirm?"); + boolean confirm = Window.confirm("Creating a new project, the current project (is not saved) and will be lost, Confirm?"); if(confirm) buildNewCards(orderedCards); }else diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java index ba91b57..4ef2610 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java @@ -22,7 +22,6 @@ import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; @@ -126,7 +125,7 @@ public class GeonaDataEntryMainForm extends Composite { } - Window.alert("I can save: "+listGeonaFormObjects); + //Window.alert("I can save: "+listGeonaFormObjects); } 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 7ed0bef..a058694 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 @@ -1,6 +1,5 @@ package org.gcube.portlets.user.geoportaldataentry.server; -import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; @@ -8,6 +7,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import org.gcube.application.geoportal.model.AccessPolicy; import org.gcube.application.geoportal.model.concessioni.Concessione; import org.gcube.application.geoportal.model.concessioni.LayerConcessione; import org.gcube.application.geoportal.model.concessioni.RelazioneScavo; @@ -29,9 +29,10 @@ import org.slf4j.LoggerFactory; */ public class ConvertToServiceModel { - public static final DateFormat dateFormat = new SimpleDateFormat(ConstantsGeoPortalDataEntryApp.DATE_FORMAT+" "+ConstantsGeoPortalDataEntryApp.TIME_FORMAT); + /** The Constant LOG. */ private static final Logger LOG = LoggerFactory.getLogger(ConvertToServiceModel.class); + /** * To concessione. * @@ -155,6 +156,12 @@ public class ConvertToServiceModel { } + /** + * To relazione scavo. + * + * @param gdb the gdb + * @return the relazione scavo + */ public static RelazioneScavo toRelazioneScavo(GenericDatasetBean gdb){ Map> mapFields = gdb.getFormDataEntryFields(); @@ -187,6 +194,12 @@ public class ConvertToServiceModel { return relazioneScavo; } + /** + * To immagini rappresentative. + * + * @param gdb the gdb + * @return the uploaded image + */ public static UploadedImage toImmaginiRappresentative(GenericDatasetBean gdb){ Map> mapFields = gdb.getFormDataEntryFields(); @@ -223,6 +236,12 @@ public class ConvertToServiceModel { return uplaodedImage; } + /** + * To layer concessione. + * + * @param gdb the gdb + * @return the layer concessione + */ public static LayerConcessione toLayerConcessione(GenericDatasetBean gdb){ Map> mapFields = gdb.getFormDataEntryFields(); @@ -234,6 +253,16 @@ public class ConvertToServiceModel { layerConcessione.setTitolo(titoloLst.get(0)); } + List politicaDiAccessoLst = mapFields.get("Politica di accesso"); + if(politicaDiAccessoLst!=null && politicaDiAccessoLst.size()>0) { + try { + AccessPolicy ap = AccessPolicy.valueOf(politicaDiAccessoLst.get(0)); + layerConcessione.setPolicy(ap); + }catch (Exception e) { + LOG.warn("I cannot cast "+politicaDiAccessoLst.get(0) +" to "+AccessPolicy.values(),e); + } + } + List valutazioneQualitaLst = mapFields.get("Valutazione della qualità"); if(valutazioneQualitaLst!=null && valutazioneQualitaLst.size()>0) { layerConcessione.setValutazioneQualita(valutazioneQualitaLst.get(0)); @@ -256,13 +285,23 @@ public class ConvertToServiceModel { return layerConcessione; } - - - - + + /** + * To instant. + * + * @param date the date + * @return the instant + */ public static Instant toInstant(String date) { Instant theInst = null; try { + date = date.trim(); + SimpleDateFormat dateFormat = null; + if(date.contains(ConstantsGeoPortalDataEntryApp.HOURS_MINUTES_SEPARATOR)) { + dateFormat = new SimpleDateFormat(ConstantsGeoPortalDataEntryApp.DATE_FORMAT+" "+ConstantsGeoPortalDataEntryApp.TIME_FORMAT); + }else + dateFormat = new SimpleDateFormat(ConstantsGeoPortalDataEntryApp.DATE_FORMAT); + Date theDate = dateFormat.parse(date); theInst = theDate.toInstant(); } catch (ParseException e) { 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 9cfc345..2af34fe 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 @@ -55,6 +55,7 @@ public class GreetingServiceImpl extends RemoteServiceServlet implements Greetin prettyPrintClientDataEntryMap(toMap); LOG.debug("Built map with form data: "+toMap); + GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest()); //Saving Data @@ -179,7 +180,8 @@ public class GreetingServiceImpl extends RemoteServiceServlet implements Greetin private void prettyPrintClientDataEntryMap(HashMap> toMap) { for (ConcessioniFormCardTitle theType : toMap.keySet()) { - LOG.debug("\n\n"+theType); + LOG.debug("\n\n"); + LOG.debug(theType.toString()); List list = toMap.get(theType); for (GeoNaFormDataObject geoNaFormDataObject : list) { LOG.debug("\t has "+geoNaFormDataObject.getListGDB().size() +" data bean/s"); diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/GwtTestGeoPortalDataEntryApp.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/GwtTestGeoPortalDataEntryApp.java deleted file mode 100644 index fdded9b..0000000 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/GwtTestGeoPortalDataEntryApp.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.client; - -import org.gcube.portlets.user.geoportaldataentry.shared.FieldVerifier; -import com.google.gwt.core.client.GWT; -import com.google.gwt.junit.client.GWTTestCase; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.rpc.ServiceDefTarget; - -/** - * GWT JUnit integration tests must extend GWTTestCase. - * Using "GwtTest*" naming pattern exclude them from running with - * surefire during the test phase. - * - * If you run the tests using the Maven command line, you will have to - * navigate with your browser to a specific url given by Maven. - * See https://gwt-maven-plugin.github.io/gwt-maven-plugin/user-guide/testing.html - * for details. - */ -public class GwtTestGeoPortalDataEntryApp extends GWTTestCase { - - /** - * Must refer to a valid module that sources this class. - */ - public String getModuleName() { - return "org.gcube.portlets.user.geoportaldataentry.GeoPortalDataEntryAppJUnit"; - } - - /** - * Tests the FieldVerifier. - */ - public void testFieldVerifier() { - assertFalse(FieldVerifier.isValidName(null)); - assertFalse(FieldVerifier.isValidName("")); - assertFalse(FieldVerifier.isValidName("a")); - assertFalse(FieldVerifier.isValidName("ab")); - assertFalse(FieldVerifier.isValidName("abc")); - assertTrue(FieldVerifier.isValidName("abcd")); - } - - /** - * This test will send a request to the server using the greetServer method in - * GreetingService and verify the response. - */ - public void testGreetingService() { - // Create the service that we will test. - GreetingServiceAsync greetingService = GWT.create(GreetingService.class); - ServiceDefTarget target = (ServiceDefTarget) greetingService; - target.setServiceEntryPoint(GWT.getModuleBaseURL() + "GeoPortalDataEntryApp/greet"); - - // Since RPC calls are asynchronous, we will need to wait for a response - // after this test method returns. This line tells the test runner to wait - // up to 10 seconds before timing out. - delayTestFinish(10000); - - // Send a request to the server. - greetingService.greetServer("GWT User", new AsyncCallback() { - public void onFailure(Throwable caught) { - // The request resulted in an unexpected error. - fail("Request failure: " + caught.getMessage()); - } - - public void onSuccess(String result) { - // Verify that the response is correct. - assertTrue(result.startsWith("Hello, GWT User!")); - - // Now that we have received a response, we need to tell the test runner - // that the test is complete. You must call finishTest() after an - // asynchronous test finishes successfully, or the test will time out. - finishTest(); - } - }); - } - - -} diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java new file mode 100644 index 0000000..a669fe5 --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.user.geoportaldataentry.client; + +import java.time.Instant; + +import org.gcube.portlets.user.geoportaldataentry.server.ConvertToServiceModel; + +public class TestClass { + + + public static void main(String[] args) { + + Instant instant = ConvertToServiceModel.toInstant("2020-10-01 10:20"); + System.out.println(instant.toString()); + + String latitudine = "-899.2986"; + System.out.println(latitudine.matches("^[-]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); + + } + + +}