From 4e08ef7d7cdd59607ba97092fc11644721b6d839 Mon Sep 17 00:00:00 2001 From: evdngsl <158455076+evdngsl@users.noreply.github.com> Date: Tue, 22 Jul 2025 14:37:02 +0200 Subject: [PATCH 1/2] LUT-30399 : Repository pattern implementation --- .../fr/paris/lutece/data/dao/IGenericDAO.java | 89 +++++++++++++ .../lutece/data/repository/DAORepository.java | 120 ++++++++++++++++++ .../lutece/data/repository/IRepository.java | 92 ++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 src/java/fr/paris/lutece/data/dao/IGenericDAO.java create mode 100644 src/java/fr/paris/lutece/data/repository/DAORepository.java create mode 100644 src/java/fr/paris/lutece/data/repository/IRepository.java diff --git a/src/java/fr/paris/lutece/data/dao/IGenericDAO.java b/src/java/fr/paris/lutece/data/dao/IGenericDAO.java new file mode 100644 index 000000000..4ae731551 --- /dev/null +++ b/src/java/fr/paris/lutece/data/dao/IGenericDAO.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2002-2025, City of 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.data.dao; + +import java.util.Collection; + +/** + * Generic Data Access Object (DAO) interface for CRUD operations on entities. + *

+ * Provides methods to insert, update, delete, load, and select all entities of type {@code T} identified by {@code ID}. + * + * @param + * the entity type + * @param + * the type of the entity's identifier + */ +public interface IGenericDAO +{ + /** + * Inserts a new entity into the data store. + * + * @param paramT + * the entity to insert + */ + void insert( T paramT ); + + /** + * Updates an existing entity in the data store. + * + * @param paramT + * the entity to update + */ + void store( T paramT ); + + /** + * Deletes an entity by its identifier. + * + * @param paramID + * the identifier of the entity to delete + */ + void delete( ID paramID ); + + /** + * Loads an entity by its identifier. + * + * @param paramID + * the identifier of the entity to load + * @return the entity if found, or {@code null} if not found + */ + T load( ID paramID ); + + /** + * Selects all entities from the data store. + * + * @return a collection of all entities + */ + Collection selectAll( ); +} diff --git a/src/java/fr/paris/lutece/data/repository/DAORepository.java b/src/java/fr/paris/lutece/data/repository/DAORepository.java new file mode 100644 index 000000000..e739820e2 --- /dev/null +++ b/src/java/fr/paris/lutece/data/repository/DAORepository.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2002-2025, City of 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.data.repository; + +import java.util.Collection; +import java.util.Optional; + +import fr.paris.lutece.data.dao.IGenericDAO; + +/** + * Abstract base repository providing CRUD operations using a generic DAO. + *

+ * This class implements common repository methods and delegates persistence operations to an underlying {@link IGenericDAO} implementation. + * + * @param + * the entity type + * @param + * the type of the entity's identifier + */ +public abstract class DAORepository implements IRepository +{ + + /** + * Gets the DAO instance used for persistence operations. + * + * @return the generic DAO + */ + protected abstract IGenericDAO getDAO( ); + + /** + * Creates a new entity in the data store. + * + * @param paramT + * the entity to create + * @return the created entity + */ + public T create( T paramT ) + { + getDAO( ).insert( paramT ); + return paramT; + } + + /** + * Updates an existing entity in the data store. + * + * @param paramT + * the entity to update + * @return the updated entity + */ + public T update( T paramT ) + { + getDAO( ).store( paramT ); + return paramT; + } + + /** + * Removes an entity by its identifier. + * + * @param paramID + * the identifier of the entity to remove + */ + public void remove( ID paramID ) + { + getDAO( ).delete( paramID ); + } + + /** + * Loads an entity by its identifier. + * + * @param paramID + * the identifier of the entity to load + * @return an {@link Optional} containing the entity if found, or empty if not found + */ + public Optional load( ID paramID ) + { + return Optional.ofNullable( getDAO( ).load( paramID ) ); + } + + /** + * Finds all entities in the data store. + * + * @return a collection of all entities + */ + public Collection findAll( ) + { + return getDAO( ).selectAll( ); + } + +} diff --git a/src/java/fr/paris/lutece/data/repository/IRepository.java b/src/java/fr/paris/lutece/data/repository/IRepository.java new file mode 100644 index 000000000..2c3a152f2 --- /dev/null +++ b/src/java/fr/paris/lutece/data/repository/IRepository.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2002-2025, City of 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.data.repository; + +import java.util.Collection; +import java.util.Optional; + +/** + * Generic repository interface for CRUD operations on entities. + *

+ * Provides methods to create, update, remove, load, and list all entities of type {@code T} identified by {@code ID}. + * + * @param + * the entity type + * @param + * the type of the entity's identifier + */ +public interface IRepository +{ + /** + * Creates a new entity in the data store. + * + * @param paramT + * the entity to create + * @return the created entity + */ + T create( T paramT ); + + /** + * Updates an existing entity in the data store. + * + * @param paramT + * the entity to update + * @return the updated entity + */ + T update( T paramT ); + + /** + * Removes an entity by its identifier. + * + * @param paramID + * the identifier of the entity to remove + */ + void remove( ID paramID ); + + /** + * Loads an entity by its identifier. + * + * @param paramID + * the identifier of the entity to load + * @return an {@link Optional} containing the entity if found, or empty if not found + */ + Optional load( ID paramID ); + + /** + * Finds all entities in the data store. + * + * @return a collection of all entities + */ + Collection findAll( ); +} From a1f865877c775749a36eb5782d0d5d18a8b49878 Mon Sep 17 00:00:00 2001 From: evdngsl <158455076+evdngsl@users.noreply.github.com> Date: Tue, 22 Jul 2025 14:38:05 +0200 Subject: [PATCH 2/2] LUT-30399 : Repository pattern applied to Style features (mode, style, stylesheet, pagetemplate) --- .../business/style/IModeRepository.java | 47 +++++ .../business/style/IPageTemplateDAO.java | 46 +---- .../style/IPageTemplateRepository.java | 41 +++++ .../portal/business/style/IStyleDAO.java | 42 +---- .../business/style/IStyleRepository.java | 51 +++++ .../portal/business/style/ModeHome.java | 134 +++----------- .../portal/business/style/ModeRepository.java | 174 ++++++++++++++++++ .../business/style/PageTemplateDAO.java | 9 +- .../business/style/PageTemplateHome.java | 82 ++------- .../style/PageTemplateRepository.java | 60 ++++++ .../portal/business/style/StyleDAO.java | 7 +- .../portal/business/style/StyleHome.java | 89 ++------- .../business/style/StyleRepository.java | 76 ++++++++ .../business/stylesheet/IStyleSheetDAO.java | 19 +- .../stylesheet/IStyleSheetRepository.java | 47 +++++ .../business/stylesheet/StyleSheetDAO.java | 37 +--- .../business/stylesheet/StyleSheetHome.java | 76 ++------ .../stylesheet/StyleSheetRepository.java | 84 +++++++++ .../portal/service/page/PageService.java | 7 +- .../service/portal/PortalMenuService.java | 6 +- .../portal/service/portal/PortalService.java | 10 +- .../portal/service/style/IStyleService.java | 33 ++++ .../portal/service/style/StyleService.java | 86 +++++++++ .../portal/web/admin/AdminMapJspBean.java | 8 +- .../portal/web/admin/AdminPageJspBean.java | 10 +- .../portal/web/includes/TreeMenuInclude.java | 8 +- .../web/style/PageTemplatesJspBean.java | 20 +- .../portal/web/style/StylesJspBean.java | 30 +-- .../web/stylesheet/StyleSheetFileServlet.java | 14 +- .../web/stylesheet/StyleSheetJspBean.java | 36 ++-- .../lutece/portal/web/xpages/SiteMapApp.java | 8 +- .../portal/business/page/PageDAOTest.java | 6 +- .../business/style/PageTemplateTest.java | 22 ++- .../portal/business/style/StyleTest.java | 28 +-- .../business/stylesheet/StyleSheetTest.java | 22 ++- .../web/admin/AdminPageJspBeanTest.java | 8 +- .../web/style/PageTemplatesJspBeanTest.java | 54 +++--- .../portal/web/style/StylesJspBeanTest.java | 59 +++--- .../web/stylesheet/StyleSheetJspBeanTest.java | 51 ++--- .../web/xpages/SiteMapAppCycleTest.java | 6 +- .../portal/web/xpages/SiteMapAppTest.java | 18 +- 41 files changed, 1036 insertions(+), 635 deletions(-) create mode 100644 src/java/fr/paris/lutece/portal/business/style/IModeRepository.java create mode 100644 src/java/fr/paris/lutece/portal/business/style/IPageTemplateRepository.java create mode 100644 src/java/fr/paris/lutece/portal/business/style/IStyleRepository.java create mode 100644 src/java/fr/paris/lutece/portal/business/style/ModeRepository.java create mode 100644 src/java/fr/paris/lutece/portal/business/style/PageTemplateRepository.java create mode 100644 src/java/fr/paris/lutece/portal/business/style/StyleRepository.java create mode 100644 src/java/fr/paris/lutece/portal/business/stylesheet/IStyleSheetRepository.java create mode 100644 src/java/fr/paris/lutece/portal/business/stylesheet/StyleSheetRepository.java create mode 100644 src/java/fr/paris/lutece/portal/service/style/IStyleService.java create mode 100644 src/java/fr/paris/lutece/portal/service/style/StyleService.java diff --git a/src/java/fr/paris/lutece/portal/business/style/IModeRepository.java b/src/java/fr/paris/lutece/portal/business/style/IModeRepository.java new file mode 100644 index 000000000..b1ad5eb71 --- /dev/null +++ b/src/java/fr/paris/lutece/portal/business/style/IModeRepository.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2002-2025, City of 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.portal.business.style; + +import java.util.Properties; + +import fr.paris.lutece.util.ReferenceList; + +public interface IModeRepository +{ + Mode load( int nId ); + + ReferenceList findAllToReferenceList( ); + + Properties findOuputXslProperties( int nId ); +} diff --git a/src/java/fr/paris/lutece/portal/business/style/IPageTemplateDAO.java b/src/java/fr/paris/lutece/portal/business/style/IPageTemplateDAO.java index 6b59b8a74..e1384ecc4 100644 --- a/src/java/fr/paris/lutece/portal/business/style/IPageTemplateDAO.java +++ b/src/java/fr/paris/lutece/portal/business/style/IPageTemplateDAO.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2022, City of Paris + * Copyright (c) 2002-2025, City of Paris * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,54 +33,14 @@ */ package fr.paris.lutece.portal.business.style; -import java.util.List; +import fr.paris.lutece.data.dao.IGenericDAO; /** * * @author LEVY */ -public interface IPageTemplateDAO +public interface IPageTemplateDAO extends IGenericDAO { - /** - * Delete a record from the table - * - * @param nPageTemplateId - * The indentifier of the object PageTemplate - */ - void delete( int nPageTemplateId ); - - /** - * Insert a new record in the table. - * - * @param pageTemplate - * The Instance of the object PageTemplate - */ - void insert( PageTemplate pageTemplate ); - - /** - * load the data of PageTemplate from the table - * - * - * @param nPageTemplateId - * The indentifier of the object PageTemplate - * @return The Instance of the object PageTemplate - */ - PageTemplate load( int nPageTemplateId ); - - /** - * Returns a list of all the page templates - * - * @return A list of PageTemplates objects - */ - List selectPageTemplatesList( ); - - /** - * Update the record in the table - * - * @param pageTemplate - * The instance of the PageTemplate to update - */ - void store( PageTemplate pageTemplate ); /** * Checks if a page template has been used by a page diff --git a/src/java/fr/paris/lutece/portal/business/style/IPageTemplateRepository.java b/src/java/fr/paris/lutece/portal/business/style/IPageTemplateRepository.java new file mode 100644 index 000000000..3e4b0e6ed --- /dev/null +++ b/src/java/fr/paris/lutece/portal/business/style/IPageTemplateRepository.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2002-2025, City of 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.portal.business.style; + +import fr.paris.lutece.data.repository.IRepository; + +public interface IPageTemplateRepository extends IRepository +{ + boolean isUsedByPage( int nPageTemplateId ); +} diff --git a/src/java/fr/paris/lutece/portal/business/style/IStyleDAO.java b/src/java/fr/paris/lutece/portal/business/style/IStyleDAO.java index 31516528f..14e3ad225 100644 --- a/src/java/fr/paris/lutece/portal/business/style/IStyleDAO.java +++ b/src/java/fr/paris/lutece/portal/business/style/IStyleDAO.java @@ -33,6 +33,7 @@ */ package fr.paris.lutece.portal.business.style; +import fr.paris.lutece.data.dao.IGenericDAO; import fr.paris.lutece.portal.business.stylesheet.StyleSheet; import fr.paris.lutece.util.ReferenceList; @@ -42,7 +43,7 @@ * * @author LEVY */ -public interface IStyleDAO +public interface IStyleDAO extends IGenericDAO { /** * Checks if a style has been created in the database with the given portal componenet @@ -53,31 +54,6 @@ public interface IStyleDAO */ boolean checkStylePortalComponent( int nPortalComponentId ); - /** - * Delete a record from the table - * - * @param nStyleId - * the identifier of the style to delete - */ - void delete( int nStyleId ); - - /** - * Insert a new record in the table. - * - * @param style - * The Instance of the object Style - */ - void insert( Style style ); - - /** - * load the data of the Style whose identifier is specified in parameter from the table - * - * @param nStyleId - * The identifier of the Style - * @return an instance of the Style which has been created - */ - Style load( int nStyleId ); - /** * Returns the list of the portal component in form of a ReferenceList * @@ -95,18 +71,4 @@ public interface IStyleDAO */ Collection selectStyleSheetList( int nStyleId ); - /** - * Load the list of styles stored in the database - * - * @return The styles list in form of a Collection object - */ - Collection