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 0000000000..4ae7315517 --- /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 0000000000..e739820e27 --- /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 0000000000..2c3a152f28 --- /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( ); +} 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 0000000000..b1ad5eb718 --- /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 6b59b8a74c..e1384ecc43 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 0000000000..3e4b0e6edf --- /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 31516528f7..14e3ad2250 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