diff --git a/README.md b/README.md index 75c2bfc..c830eed 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ In it's current form, it doesn't provide any html/javascript scaffolding, only s ## Icons -The main mechanism to use icons is to have a spring bean named "leaflet-icon-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.service.IIconProvider. The implementor must return an icon name. The Java code for pages displaying the map can then call fr.paris.lutece.plugins.leaflet.service.IconService.getIcon() to retrieve the icon name from the resource. +The main mechanism to use icons is to have a CDI bean named "leaflet-icon-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.service.IIconProvider. The implementor must return an icon name. The Java code for pages displaying the map can then call fr.paris.lutece.plugins.leaflet.service.IconService.getIcon() to retrieve the icon name from the resource. fr.paris.lutece.plugins.leaflet.service.IconService.getList() can be used to get a List of available icons, for example to build GUIs for users to choose an icon. To add icons to this list, add an entry in the datastore in the form ('leaflet.icon.icons.ICON_NAME.installed', 'true'). ## Popups -The main mechanism to use popups is to have a spring bean named "leaflet-rest-popup-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.rest.service.IPopupContentProvider. The implementor must produce html snippets. They will be automatically accessible at the URL rest/leaflet/popup/{XXX}/{docid}/{code} and can be loaded when the user clicks a marker with AJAX. +The main mechanism to use popups is to have a CDI bean named "leaflet-rest-popup-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.rest.service.IPopupContentProvider. The implementor must produce html snippets. They will be automatically accessible at the URL rest/leaflet/popup/{XXX}/{docid}/{code} and can be loaded when the user clicks a marker with AJAX. CORS headers can be enabled with the following properties: diff --git a/pom.xml b/pom.xml index 285114d..ffc2870 100644 --- a/pom.xml +++ b/pom.xml @@ -3,14 +3,14 @@ lutece-global-pom fr.paris.lutece.tools - 7.0.2 + 8.0.0-SNAPSHOT 4.0.0 fr.paris.lutece.plugins plugin-leaflet lutece-plugin - 1.0.5-SNAPSHOT + 2.0.0-SNAPSHOT Lutece leaflet plugin @@ -20,27 +20,42 @@ https://dev.lutece.paris.fr/maven_repository default + + luteceSnapshot + luteceSnapshot + https://dev.lutece.paris.fr/snapshot_repository + + true + + + false + + fr.paris.lutece lutece-core - [7.0.0,7.9.9) + [8.0.0-SNAPSHOT,) lutece-core fr.paris.lutece.plugins plugin-rest - [3.1.1,3.9.9) + [4.0.0-SNAPSHOT,) lutece-plugin + + fr.paris.lutece.plugins + library-lutece-unit-testing + jar + test + leaflet - LEAFLET - diff --git a/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItem.java b/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItem.java index 77ab532..9fa19da 100644 --- a/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItem.java +++ b/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItem.java @@ -44,8 +44,6 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -143,7 +141,7 @@ public String getType( ) @JsonProperty( PATH_PROPERTIES ) public Map getProperties( ) { - HashMap properties = new HashMap( ); + Map properties = new HashMap<>( ); if ( _address != null ) { @@ -171,7 +169,7 @@ public Map getProperties( ) @JsonProperty( PATH_GEOMETRY ) public Map getGeometry( ) { - HashMap geometry = new HashMap( ); + Map geometry = new HashMap<>( ); geometry.put( PATH_GEOMETRY_TYPE, _typegeometry ); if ( _typegeometry.equals( VALUE_GEOMETRY_TYPE ) ) { @@ -311,7 +309,7 @@ public String toXML( ) * @return The geolocItem object */ public static GeolocItem fromJSON( String strJson ) - throws JsonParseException, JsonMappingException, IOException + throws IOException { return _objectMapper.readValue( strJson, GeolocItem.class ); } diff --git a/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemPolygon.java b/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemPolygon.java index fb648dc..e2d88f9 100644 --- a/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemPolygon.java +++ b/src/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemPolygon.java @@ -35,21 +35,10 @@ import fr.paris.lutece.util.xml.XmlUtil; -/* -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.annotate.JsonAutoDetect; -import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -*/ import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -86,7 +75,6 @@ public class GeolocItemPolygon static { _objectMapper = new ObjectMapper( ); - //_objectMapper.configure( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false ); _objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false ); } @@ -144,7 +132,7 @@ public String getType( ) @JsonProperty( PATH_PROPERTIES ) public Map getProperties( ) { - HashMap properties = new HashMap( ); + Map properties = new HashMap<>( ); if ( _icon != null ) { @@ -167,7 +155,7 @@ public Map getProperties( ) @JsonProperty( PATH_GEOMETRY ) public Map getGeometry( ) { - HashMap geometry = new HashMap( ); + Map geometry = new HashMap<>( ); //geometry.put( PATH_GEOMETRY_TYPE, VALUE_GEOMETRY_TYPE_POLYGON ); geometry.put( PATH_GEOMETRY_TYPE, _typegeometry ); //geometry.put( PATH_GEOMETRY_COORDINATES, _lonlat ); @@ -287,7 +275,7 @@ public String toXML( ) * @return The geolocItem object */ public static GeolocItemPolygon fromJSON( String strJson ) - throws JsonParseException, JsonMappingException, IOException + throws IOException { return _objectMapper.readValue( strJson, GeolocItemPolygon.class ); } diff --git a/src/java/fr/paris/lutece/plugins/leaflet/rest/rs/LeafletRest.java b/src/java/fr/paris/lutece/plugins/leaflet/rest/rs/LeafletRest.java index 3a76a50..2fae01c 100644 --- a/src/java/fr/paris/lutece/plugins/leaflet/rest/rs/LeafletRest.java +++ b/src/java/fr/paris/lutece/plugins/leaflet/rest/rs/LeafletRest.java @@ -33,22 +33,24 @@ */ package fr.paris.lutece.plugins.leaflet.rest.rs; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Instance; +import jakarta.enterprise.inject.literal.NamedLiteral; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.ResponseBuilder; import fr.paris.lutece.plugins.leaflet.rest.service.IPopupContentProvider; import fr.paris.lutece.plugins.leaflet.service.CorsUtils; import fr.paris.lutece.plugins.rest.service.RestConstants; import fr.paris.lutece.portal.service.i18n.I18nService; -import fr.paris.lutece.portal.service.spring.SpringContextService; import fr.paris.lutece.portal.service.util.AppLogService; import fr.paris.lutece.portal.service.util.AppPropertiesService; @@ -56,6 +58,8 @@ /** * LeafletRest */ +@ApplicationScoped +@Named( "leaflet-rest.leafletRest" ) @Path( RestConstants.BASE_PATH + "leaflet" ) public class LeafletRest { @@ -69,12 +73,14 @@ public class LeafletRest private static final String PROPERTY_CORS_ENABLED_KEY = "leaflet.cors.enabled"; private static final boolean PROPERTY_CORS_ENABLED_DEFAULT = false; - private static final String HEADER_ORIGIN = "origin"; private static final String PROPERTY_CORS_METHODS_KEY = "leaflet.cors.methods"; private static final String PROPERTY_CORS_METHODS_DEFAULT = "GET, POST, DELETE, PUT"; + @Inject + private Instance _popupContentProviderInstance; + /** * Get an html snippet representing a leaflet popup * @param request the httpServletRequest @@ -85,47 +91,65 @@ public class LeafletRest */ @GET @Path( PATH_POPUP ) - public Response getDocument( @Context - HttpServletRequest request, @PathParam( PARAMETER_PROVIDER ) - String strProvider, @PathParam( PARAMETER_ID_DOCUMENT ) - String strIdDocument, @PathParam( PARAMETER_CODE ) - String strCode ) + public Response getDocument( @Context HttpServletRequest request, + @PathParam( PARAMETER_PROVIDER ) String strProvider, + @PathParam( PARAMETER_ID_DOCUMENT ) String strIdDocument, + @PathParam( PARAMETER_CODE ) String strCode ) { - try + Instance selectedProviderInstance = _popupContentProviderInstance.select( NamedLiteral.of( BEAN_PREFIX + strProvider ) ); + + String popup = getPopupContentProvider( selectedProviderInstance, strProvider, strIdDocument ).getPopup( request, strIdDocument, strCode ); + + if ( popup != null ) { - - IPopupContentProvider popupContentProvider = (IPopupContentProvider) SpringContextService.getBean( BEAN_PREFIX + - strProvider ); - - String popup = popupContentProvider.getPopup( request, strIdDocument, strCode ); - - if ( popup != null ) - { - String popupLocalized = I18nService.localize( popup, request.getLocale( ) ); - - ResponseBuilder responseBuilder = Response.ok(); - if ( AppPropertiesService.getPropertyBoolean( PROPERTY_CORS_ENABLED_KEY, PROPERTY_CORS_ENABLED_DEFAULT ) ) { - - String strHeaderOrigin = request.getHeader( HEADER_ORIGIN ); - String strAccessControlAllowOrigin = CorsUtils.isValidOrigin( strHeaderOrigin ) ? strHeaderOrigin : ""; - String strCorsMethods = AppPropertiesService.getProperty( PROPERTY_CORS_METHODS_KEY, PROPERTY_CORS_METHODS_DEFAULT); - responseBuilder .header("Access-Control-Allow-Methods", strCorsMethods).header("Access-Control-Allow-Origin", strAccessControlAllowOrigin); - - } - return responseBuilder - .entity(popupLocalized) - .build(); + String popupLocalized = I18nService.localize( popup, request.getLocale( ) ); + + ResponseBuilder responseBuilder = Response.ok(); + if ( AppPropertiesService.getPropertyBoolean( PROPERTY_CORS_ENABLED_KEY, PROPERTY_CORS_ENABLED_DEFAULT ) ) { + + String strHeaderOrigin = request.getHeader( HEADER_ORIGIN ); + String strAccessControlAllowOrigin = CorsUtils.isValidOrigin( strHeaderOrigin ) ? strHeaderOrigin : ""; + String strCorsMethods = AppPropertiesService.getProperty( PROPERTY_CORS_METHODS_KEY, PROPERTY_CORS_METHODS_DEFAULT); + responseBuilder .header("Access-Control-Allow-Methods", strCorsMethods).header("Access-Control-Allow-Origin", strAccessControlAllowOrigin); + } + return responseBuilder + .entity(popupLocalized) + .build(); + } + + AppLogService.debug( "Leaflet popup rest API: icon was null" ); + throw new WebApplicationException( 404 ); + } - AppLogService.debug( "Leaflet popup rest API: icon was null" ); + /** + * Get the popup provider from a provider instance + * + * @param popupContentProviderInstance the provider instance + * @param strProvider the provider + * @param strIdDocument the id document + * @return the provider + * @throws WebApplicationException if the provider cannot be resolved + */ + private IPopupContentProvider getPopupContentProvider( Instance popupContentProviderInstance, + String strProvider, String strIdDocument ) + { + if ( popupContentProviderInstance.isUnsatisfied( ) ) + { + AppLogService.error( + "Leaflet popup rest API: No provider found for provider '{}' , document ID '{}'", strProvider, strIdDocument + ); throw new WebApplicationException( 404 ); } - catch ( NoSuchBeanDefinitionException e ) + + if ( popupContentProviderInstance.isAmbiguous( ) ) { - AppLogService.error( "Leaflet popup rest API: Missing strProvider " + strProvider + " , strDocId " + - strIdDocument + ", exception " + e ); + AppLogService.error( + "Leaflet popup rest API: Multiple providers found for provider '{}' , document ID '{}'", strProvider, strIdDocument + ); throw new WebApplicationException( 404 ); } + + return popupContentProviderInstance.get( ); } - } diff --git a/src/java/fr/paris/lutece/plugins/leaflet/rest/service/IPopupContentProvider.java b/src/java/fr/paris/lutece/plugins/leaflet/rest/service/IPopupContentProvider.java index 6affd2d..8a3d36b 100644 --- a/src/java/fr/paris/lutece/plugins/leaflet/rest/service/IPopupContentProvider.java +++ b/src/java/fr/paris/lutece/plugins/leaflet/rest/service/IPopupContentProvider.java @@ -33,7 +33,7 @@ */ package fr.paris.lutece.plugins.leaflet.rest.service; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; /** diff --git a/src/java/fr/paris/lutece/plugins/leaflet/service/CorsUtils.java b/src/java/fr/paris/lutece/plugins/leaflet/service/CorsUtils.java index 806f6b5..dee5224 100644 --- a/src/java/fr/paris/lutece/plugins/leaflet/service/CorsUtils.java +++ b/src/java/fr/paris/lutece/plugins/leaflet/service/CorsUtils.java @@ -34,9 +34,8 @@ package fr.paris.lutece.plugins.leaflet.service; +import fr.paris.lutece.util.http.AntPathMatcher; import org.apache.commons.lang3.StringUtils; -import org.springframework.util.AntPathMatcher; -import org.springframework.util.PathMatcher; import fr.paris.lutece.portal.service.util.AppPropertiesService; @@ -49,7 +48,7 @@ public final class CorsUtils { /** The Constant PATH_MATCHER. */ - private final static PathMatcher PATH_MATCHER = new AntPathMatcher( ); + private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher( ); /** The Constant PROPERTY_CORS_ORIGIN_KEY. */ private static final String PROPERTY_CORS_ORIGIN_KEY = "leaflet.cors.origin"; diff --git a/src/java/fr/paris/lutece/plugins/leaflet/service/IconService.java b/src/java/fr/paris/lutece/plugins/leaflet/service/IconService.java index e91afc3..92d0519 100644 --- a/src/java/fr/paris/lutece/plugins/leaflet/service/IconService.java +++ b/src/java/fr/paris/lutece/plugins/leaflet/service/IconService.java @@ -34,12 +34,13 @@ package fr.paris.lutece.plugins.leaflet.service; import fr.paris.lutece.portal.service.datastore.DatastoreService; -import fr.paris.lutece.portal.service.spring.SpringContextService; import fr.paris.lutece.portal.service.util.AppLogService; import fr.paris.lutece.util.ReferenceItem; import fr.paris.lutece.util.ReferenceList; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import jakarta.enterprise.inject.Instance; +import jakarta.enterprise.inject.literal.NamedLiteral; +import jakarta.enterprise.inject.spi.CDI; import java.util.ArrayList; import java.util.Collection; @@ -54,6 +55,7 @@ public class IconService private static final String BEAN_PREFIX = "leaflet-icon-provider-"; private static final String DATASTORE_PREFIX = "leaflet.icon."; private static final String DATASTORE_ICONS_PREFIX = DATASTORE_PREFIX + "icons."; + private static final String DEFAULT_ICON = "default"; /** Private constructor */ @@ -69,7 +71,7 @@ private IconService( ) public static Collection getList( ) { ReferenceList referenceList = DatastoreService.getDataByPrefix( DATASTORE_ICONS_PREFIX ); - HashSet hashSet = new HashSet( ); + HashSet hashSet = new HashSet<>( ); for ( ReferenceItem referenceItem : referenceList ) { @@ -78,9 +80,7 @@ public static Collection getList( ) hashSet.add( code ); } - ArrayList result = new ArrayList( hashSet ); - - return result; + return new ArrayList<>( hashSet ); } /** @@ -92,19 +92,34 @@ public static Collection getList( ) */ public static String getIcon( String strProvider, String strIconKey ) { - try + Instance iconProviderInstance = CDI.current( ).select( IIconProvider.class, NamedLiteral.of( BEAN_PREFIX + strProvider ) ); + + if ( iconProviderInstance.isResolvable( ) ) { - IIconProvider iconProvider = (IIconProvider) SpringContextService.getBean( BEAN_PREFIX + strProvider ); - String icon = iconProvider.getIcon( strIconKey ); + String icon = iconProviderInstance.get( ).getIcon( strIconKey ); + return ( icon == null ) ? DEFAULT_ICON : icon; + } - return ( icon == null ) ? "default" : icon; + logProviderError( iconProviderInstance, strProvider, strIconKey ); + return DEFAULT_ICON; + } + + /** + * Logs an error message when the icon provider cannot be resolved. + * + * @param instance the CDI instance that failed to resolve + * @param strProvider the name of the provider + * @param strIconKey the key of the icon + */ + private static void logProviderError(Instance instance, String strProvider, String strIconKey) + { + if ( instance.isAmbiguous( ) ) + { + AppLogService.error( "icon API: Multiple providers found for '{}', iconKey '{}'", strProvider, strIconKey ); } - catch ( NoSuchBeanDefinitionException e ) + else { - AppLogService.error( "icon API: Missing strProvider " + strProvider + " , strIconKey " + strIconKey + - ", exception " + e ); - - return "default"; + AppLogService.error( "icon API: Provider '{}' not found, iconKey '{}'", strProvider, strIconKey ); } } } diff --git a/src/site/fr/xdoc/index.xml b/src/site/fr/xdoc/index.xml index 9e66e18..1d45b20 100644 --- a/src/site/fr/xdoc/index.xml +++ b/src/site/fr/xdoc/index.xml @@ -18,11 +18,11 @@

Dans sa version actuelle, il n'intervient pas dans l'écriture du HTML/javascript, il fournit seulement des fonctionnalités coté serveur. L'utilisateur doit intégrer la carte dans sa page lui-même.

-

Le mécanisme principal pour choisir des icône est de créer un bean spring "leaflet-icon-provider-XXX" qui implémente l'interface fr.paris.lutece.plugins.leaflet.service.IIconProvider. L'implémentation doit retourner un nom d'icône. Le code java générant la page peut alors appeler la fonction fr.paris.lutece.plugins.leaflet.service.IconService.getIcon() pour obtenir un nom d'icône pour la ressource.

+

Le mécanisme principal pour choisir des icône est de créer un bean CDI "leaflet-icon-provider-XXX" qui implémente l'interface fr.paris.lutece.plugins.leaflet.service.IIconProvider. L'implémentation doit retourner un nom d'icône. Le code java générant la page peut alors appeler la fonction fr.paris.lutece.plugins.leaflet.service.IconService.getIcon() pour obtenir un nom d'icône pour la ressource.

fr.paris.lutece.plugins.leaflet.service.IconService.getList() renvoie la liste des icônes disponibles, ce qui permet de faire des interfaces utilisateur permettant de choisir l'icône. Pour ajouter des icônes à cette liste, il faut insérer une valeur dans le datastore de la forme ('leaflet.icon.icons.ICON_NAME.installed', 'true').

-

Le mécanisme principal pour obtenir des popups est de créer un bean spring "leaflet-rest-popup-provider-XXX" qui implémente l'interface fr.paris.lutece.plugins.leaflet.rest.service.IPopupContentProvider. L'implémentation doit produire des fragment d'html. Ils seront accessibles automatiquement à l'URL rest/leaflet/popup/{XXX}/{docid}/{code} et peuvent être chargés dynamiquement quand l'utilisateur clique sur le marqueur en AJAX.

+

Le mécanisme principal pour obtenir des popups est de créer un bean CDI "leaflet-rest-popup-provider-XXX" qui implémente l'interface fr.paris.lutece.plugins.leaflet.rest.service.IPopupContentProvider. L'implémentation doit produire des fragment d'html. Ils seront accessibles automatiquement à l'URL rest/leaflet/popup/{XXX}/{docid}/{code} et peuvent être chargés dynamiquement quand l'utilisateur clique sur le marqueur en AJAX.

Les headers CORS peuvent être activés avec les propriétés suivantes:

  • leaflet.cors.enabled (default false)
  • diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index e455624..e86169c 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -18,11 +18,11 @@

    In it's current form, it doesn't provide any html/javascript scaffolding, only server-side features. The user must integrate the map in a page itself.

    -

    The main mechanism to use icons is to have a spring bean named "leaflet-icon-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.service.IIconProvider. The implementor must return an icon name. The Java code for pages displaying the map can then call fr.paris.lutece.plugins.leaflet.service.IconService.getIcon() to retrieve the icon name from the resource.

    +

    The main mechanism to use icons is to have a CDI bean named "leaflet-icon-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.service.IIconProvider. The implementor must return an icon name. The Java code for pages displaying the map can then call fr.paris.lutece.plugins.leaflet.service.IconService.getIcon() to retrieve the icon name from the resource.

    fr.paris.lutece.plugins.leaflet.service.IconService.getList() can be used to get a List of available icons, for example to build GUIs for users to choose an icon. To add icons to this list, add an entry in the datastore in the form ('leaflet.icon.icons.ICON_NAME.installed', 'true').

    -

    The main mechanism to use popups is to have a spring bean named "leaflet-rest-popup-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.rest.service.IPopupContentProvider. The implementor must produce html snippets. They will be automatically accessible at the URL rest/leaflet/popup/{XXX}/{docid}/{code} and can be loaded when the user clicks a marker with AJAX.

    +

    The main mechanism to use popups is to have a CDI bean named "leaflet-rest-popup-provider-XXX" implement the interface fr.paris.lutece.plugins.leaflet.rest.service.IPopupContentProvider. The implementor must produce html snippets. They will be automatically accessible at the URL rest/leaflet/popup/{XXX}/{docid}/{code} and can be loaded when the user clicks a marker with AJAX.

    CORS headers can be enabled with the following properties:

    • leaflet.cors.enabled (default false)
    • diff --git a/src/test/java/fr/paris/lutece/plugins/leaflet/AllTests.java b/src/test/java/fr/paris/lutece/plugins/leaflet/AllTests.java deleted file mode 100644 index 08cce68..0000000 --- a/src/test/java/fr/paris/lutece/plugins/leaflet/AllTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2002-2015, Mairie de Paris - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright notice - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice - * and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * License 1.0 - */ -package fr.paris.lutece.plugins.leaflet; - -import fr.paris.lutece.plugins.leaflet.business.GeolocItemTest; - -import junit.framework.Test; -import junit.framework.TestSuite; - - -public final class AllTests -{ - /** - * Constructor (private) - */ - private AllTests( ) - { - } - - /** - * A set of tests - * @return Test the tests - */ - public static Test suite( ) - { - TestSuite suite = new TestSuite( "Test of the package fr.paris.lutece.plugins.leaflet" ); - - //$JUnit-BEGIN$ - // Add tests of the current package - suite.addTest( new TestSuite( GeolocItemTest.class ) ); - - // Add tests of sublevel packages - //suite.addTest( fr.paris.lutece.plugins.myplugin.business.AllTests.suite( ) ); - //suite.addTest( fr.paris.lutece.plugins.myplugin.web.AllTests.suite( ) ); - - //$JUnit-END$ - return suite; - } -} diff --git a/src/test/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemTest.java b/src/test/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemTest.java index de7f365..17af913 100644 --- a/src/test/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemTest.java +++ b/src/test/java/fr/paris/lutece/plugins/leaflet/business/GeolocItemTest.java @@ -33,30 +33,34 @@ */ package fr.paris.lutece.plugins.leaflet.business; -import junit.framework.TestCase; - import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; -public class GeolocItemTest extends TestCase +public class GeolocItemTest { - public void testSerialize( ) throws JsonParseException, JsonMappingException, IOException + @Test + void testSerialize( ) throws JsonParseException, JsonMappingException, IOException { GeolocItem ref = new GeolocItem( ); - HashMap pref = new HashMap( ); + Map pref = new HashMap<>(); pref.put( "layer", "aco" ); pref.put( "icon", "ico" ); pref.put( "address", "addo" ); - HashMap gref = new HashMap( ); + Map gref = new HashMap<>(); + gref.put( "type", "Point" ); gref.put( "coordinates", Arrays.asList( new Double[] { 2.31272, 48.83632 } ) ); ref.setGeometry( gref ); ref.setProperties( pref ); @@ -70,27 +74,28 @@ public void testSerialize( ) throws JsonParseException, JsonMappingException, I assert a.equals( b ) : "Parsing ref string and ref.toJSON should produce equal objects"; GeolocItem g = GeolocItem.fromJSON( s ); - assert g.getLonLat( ).equals( ref.getLonLat( ) ) : "Check serialized field"; - assert g.getAddress( ).equals( ref.getAddress( ) ) : "Check serialized field"; - assert g.getIcon( ).equals( ref.getIcon( ) ) : "Check serialized field"; - assert g.getLayer( ).equals( ref.getLayer( ) ) : "Check serialized field"; + assertEquals( g.getLonLat( ), ref.getLonLat( ), "Check serialized field" ); + assertEquals( g.getAddress( ), ref.getAddress( ), "Check serialized field" ); + assertEquals( g.getIcon( ), ref.getIcon( ), "Check serialized field" ); + assertEquals( g.getLayer( ), ref.getLayer( ), "Check serialized field" ); GeolocItem g2 = GeolocItem.fromJSON( g.toJSON( ) ); - assert g2.getLonLat( ).equals( ref.getLonLat( ) ) : "Check serialized field"; - assert g2.getAddress( ).equals( ref.getAddress( ) ) : "Check serialized field"; - assert g2.getIcon( ).equals( ref.getIcon( ) ) : "Check serialized field"; - assert g2.getLayer( ).equals( ref.getLayer( ) ) : "Check serialized field"; + assertEquals( g2.getLonLat( ), ref.getLonLat( ), "Check serialized field" ); + assertEquals( g2.getAddress( ), ref.getAddress( ), "Check serialized field" ); + assertEquals( g2.getIcon( ), ref.getIcon( ), "Check serialized field" ); + assertEquals( g2.getLayer( ), ref.getLayer( ), "Check serialized field" ); String strRefXML = "\r\n" + "2.31272\r\n" + "48.83632\r\n" + "
      \r\n" + "ico\r\n" + "aco\r\n" + "
      \r\n"; String strXML = ref.toXML( ); - assert strRefXML.equals( strXML ) : "Test xml marshalling: ref:\n" + strRefXML + "\n; got:\n" + strXML; + assertEquals( strRefXML, strXML, "Test xml marshalling: ref:\n" + strRefXML + "\n; got:\n" + strXML ); GeolocItem missingref = new GeolocItem( ); - HashMap missingpref = new HashMap( ); - HashMap missinggref = new HashMap( ); + Map missingpref = new HashMap<>( ); + Map missinggref = new HashMap<>( ); + missinggref.put( "type", "Point" ); missinggref.put( "coordinates", Arrays.asList( new Double[] { 2.31272, 48.83632 } ) ); missingref.setGeometry( missinggref ); missingref.setProperties( missingpref ); @@ -99,14 +104,14 @@ public void testSerialize( ) throws JsonParseException, JsonMappingException, I "\r\n"; String strMissingXML = missingref.toXML( ); - assert strMissingRefXML.equals( strMissingXML ) : "Test missing xml marshalling: ref:\n" + strRefXML + - "\n; got:\n" + strXML; + assertEquals( strMissingRefXML, strMissingXML, "Test missing xml marshalling: ref:\n" + strRefXML + + "\n; got:\n" + strXML); String smissing = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[2.31272,48.83632]},\"properties\":{}}"; JsonNode bmissing = objectMapper.readTree( smissing ); String jsonmissing = missingref.toJSON( ); JsonNode bmissingref = objectMapper.readTree( jsonmissing ); - assert bmissingref.equals( bmissing ) : "Parsing,for missing fields, ref string and ref.toJSON should produce equal objects. strings are: \n" + - smissing + "\n and \n" + jsonmissing; + assertEquals( bmissingref, bmissing, "Parsing,for missing fields, ref string and ref.toJSON should produce equal objects. strings are: \n" + + smissing + "\n and \n" + jsonmissing ); } } diff --git a/src/test/java/fr/paris/lutece/plugins/leaflet/service/CorsUtilTest.java b/src/test/java/fr/paris/lutece/plugins/leaflet/service/CorsUtilTest.java index 5638c83..7791e7f 100644 --- a/src/test/java/fr/paris/lutece/plugins/leaflet/service/CorsUtilTest.java +++ b/src/test/java/fr/paris/lutece/plugins/leaflet/service/CorsUtilTest.java @@ -33,22 +33,23 @@ */ package fr.paris.lutece.plugins.leaflet.service; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * The Class CorsUtilTest. */ -public class CorsUtilTest { +public class CorsUtilTest +{ + - /** * Checks if is valid origin test. */ @Test - public void isValidOriginTest() + void isValidOriginTest() { String strPattern="https://*.paris.mdp:443/*,https://*.paris.mdp/*,https://*.paris.fr:443/*,https://*.paris.fr/*,https://*.paris.mdp:443,https://*.paris.mdp"; diff --git a/webapp/WEB-INF/conf/plugins/leaflet_context.xml b/webapp/WEB-INF/conf/plugins/leaflet_context.xml deleted file mode 100644 index 62ac817..0000000 --- a/webapp/WEB-INF/conf/plugins/leaflet_context.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - diff --git a/webapp/WEB-INF/plugins/leaflet.xml b/webapp/WEB-INF/plugins/leaflet.xml index 4b84d79..383aa21 100644 --- a/webapp/WEB-INF/plugins/leaflet.xml +++ b/webapp/WEB-INF/plugins/leaflet.xml @@ -1,7 +1,7 @@ leaflet fr.paris.lutece.portal.service.plugin.PluginDefaultImplementation - 1.0.5-SNAPSHOT + 2.0.0-SNAPSHOT @@ -10,11 +10,11 @@ leaflet.plugin.provider http://dev.lutece.paris.fr images/admin/skin/feature_default_icon.png - Copyright (c) 2015 Mairie de Paris + Copyright (c) 2025 Ville de Paris 0 - 4.1.0 + 8.0.0