Skip to content

Commit 382bab3

Browse files
obfromeviFrancoisEricMerlin
authored andcommitted
LUT-28811 : add a portlet to display a list of forms
1 parent 8d56fd5 commit 382bab3

21 files changed

+877
-0
lines changed
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
* Copyright (c) 2002-2024, City of Paris
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice
10+
* and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice
13+
* and the following disclaimer in the Formsation and/or other materials
14+
* provided with the distribution.
15+
*
16+
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17+
* contributors may be used to endorse or promote products derived from
18+
* this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
* License 1.0
33+
*/
34+
package fr.paris.lutece.plugins.forms.business.portlet;
35+
36+
import java.util.ArrayList;
37+
import java.util.HashMap;
38+
import java.util.Iterator;
39+
import java.util.List;
40+
import java.util.Map;
41+
42+
import javax.servlet.http.HttpServletRequest;
43+
44+
import org.apache.commons.lang3.StringUtils;
45+
46+
import fr.paris.lutece.plugins.forms.business.FormHome;
47+
import fr.paris.lutece.portal.business.portlet.PortletHtmlContent;
48+
import fr.paris.lutece.portal.service.template.AppTemplateService;
49+
import fr.paris.lutece.util.html.HtmlTemplate;
50+
51+
public class FormsListPortlet extends PortletHtmlContent
52+
{
53+
public static final String RESOURCE_ID = "FORMS_LIST_PORTLET";
54+
55+
// TEMPALTES
56+
private static final String TEMPLATE_PORTLET_FORMSLIST = "skin/plugins/forms/portletformslist_content.html";
57+
58+
// MARKS
59+
private static final String MARK_FORMS_LIST = "forms_list";
60+
private static final String MARK_PORTLET_NAME = "portlet_name";
61+
62+
// VARIABLES
63+
private List<Integer> _formsIdList = new ArrayList<>( );
64+
65+
/**
66+
* Sets the identifier of the portlet type to the value specified in the FormsListPortletHome class
67+
*/
68+
public FormsListPortlet( )
69+
{
70+
setPortletTypeId( FormsListPortletHome.getInstance( ).getPortletTypeId( ) );
71+
}
72+
73+
/**
74+
* Returns the HTML code of the FormsListPortlet portlet
75+
*
76+
* @param request
77+
* The HTTP servlet request
78+
* @return the HTML code of the FormsListPortlet portlet
79+
*/
80+
@Override
81+
public String getHtmlContent( HttpServletRequest request )
82+
{
83+
if ( request != null )
84+
{
85+
Map<String, Object> model = new HashMap<>( );
86+
87+
model.put( MARK_FORMS_LIST, FormHome.getFormByPrimaryKeyList( _formsIdList ) );
88+
model.put( MARK_PORTLET_NAME, this.getName( ) );
89+
90+
HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PORTLET_FORMSLIST, getLocale( request ), model );
91+
92+
return template.getHtml( );
93+
}
94+
95+
return StringUtils.EMPTY;
96+
}
97+
98+
/**
99+
* Removes the current instance of the FormsListPortlet object
100+
*/
101+
@Override
102+
public void remove( )
103+
{
104+
FormsListPortletHome.getInstance( ).remove( this );
105+
}
106+
107+
/**
108+
* Updates the current instance of the FormsListPortlet object
109+
*/
110+
public void update( )
111+
{
112+
FormsListPortletHome.getInstance( ).update( this );
113+
}
114+
115+
/**
116+
* get the list of forms identifiers
117+
*
118+
* @return the _formsIdList
119+
*/
120+
public List<Integer> getFormsIdList( )
121+
{
122+
return _formsIdList;
123+
}
124+
125+
/**
126+
* set the list of forms identifiers
127+
*
128+
* @param formsIdList the _formsIdList to set
129+
*/
130+
public void setFormsIdList( List<Integer> formsIdList )
131+
{
132+
this._formsIdList = formsIdList;
133+
}
134+
135+
/**
136+
* add a form id to the list of forms identifiers
137+
*
138+
* @param formId
139+
* The form identifier
140+
*/
141+
public void addFormId( int formId )
142+
{
143+
boolean bFormExists = false;
144+
Iterator<Integer> itr = _formsIdList.iterator( );
145+
while ( itr.hasNext( ) )
146+
{
147+
if ( itr.next( ) == formId )
148+
{
149+
bFormExists = true;
150+
break;
151+
}
152+
}
153+
154+
if ( !bFormExists )
155+
{
156+
_formsIdList.add( formId );
157+
}
158+
}
159+
160+
/**
161+
* Remove a form id to the list of forms identifiers
162+
*
163+
* @param formId
164+
* The form identifier
165+
*/
166+
public void removeFormId( int formId )
167+
{
168+
Iterator<Integer> itr = _formsIdList.iterator( );
169+
while ( itr.hasNext( ) )
170+
{
171+
if ( itr.next( ) == formId )
172+
{
173+
itr.remove( );
174+
break;
175+
}
176+
}
177+
}
178+
179+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 2002-2024, City of Paris
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice
10+
* and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice
13+
* and the following disclaimer in the Formsation and/or other materials
14+
* provided with the distribution.
15+
*
16+
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17+
* contributors may be used to endorse or promote products derived from
18+
* this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
* License 1.0
33+
*/
34+
package fr.paris.lutece.plugins.forms.business.portlet;
35+
36+
import java.util.ArrayList;
37+
import java.util.List;
38+
39+
import org.apache.commons.collections4.CollectionUtils;
40+
41+
import fr.paris.lutece.portal.business.portlet.Portlet;
42+
import fr.paris.lutece.util.sql.DAOUtil;
43+
44+
public class FormsListPortletDAO implements IFormsListPortletDAO
45+
{
46+
private static final String SQL_QUERY_SELECT = "SELECT id_form FROM forms_list_portlet WHERE id_portlet = ? ";
47+
private static final String SQL_QUERY_INSERT = "INSERT INTO forms_list_portlet ( id_portlet, id_form ) VALUES ( ?, ? )";
48+
private static final String SQL_QUERY_DELETE = "DELETE FROM forms_list_portlet WHERE id_portlet = ? ";
49+
50+
/**
51+
* { @inheritDoc }
52+
*/
53+
@Override
54+
public void insert( Portlet portlet )
55+
{
56+
FormsListPortlet formsListPortlet = (FormsListPortlet) portlet;
57+
58+
if ( CollectionUtils.isNotEmpty( formsListPortlet.getFormsIdList( ) ) )
59+
{
60+
for (Integer formId : formsListPortlet.getFormsIdList( ) )
61+
{
62+
try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
63+
{
64+
daoUtil.setInt( 1, formsListPortlet.getId( ) );
65+
daoUtil.setInt( 2, formId );
66+
67+
daoUtil.executeUpdate( );
68+
}
69+
}
70+
}
71+
}
72+
73+
/**
74+
* { @inheritDoc }
75+
*/
76+
@Override
77+
public Portlet load( int nPortletId )
78+
{
79+
try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
80+
{
81+
daoUtil.setInt( 1, nPortletId );
82+
daoUtil.executeQuery( );
83+
84+
FormsListPortlet formsListPortlet = new FormsListPortlet( );
85+
formsListPortlet.setId( nPortletId );
86+
87+
List<Integer> formsIdList = new ArrayList<>( );
88+
while ( daoUtil.next( ) )
89+
{
90+
formsIdList.add( daoUtil.getInt( 1 ) );
91+
}
92+
formsListPortlet.setFormsIdList( formsIdList );
93+
94+
return formsListPortlet;
95+
}
96+
}
97+
98+
/**
99+
* { @inheritDoc }
100+
*/
101+
@Override
102+
public void delete( int nPortletId )
103+
{
104+
try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
105+
{
106+
daoUtil.setInt( 1, nPortletId );
107+
daoUtil.executeUpdate( );
108+
}
109+
}
110+
111+
/**
112+
* { @inheritDoc }
113+
*/
114+
@Override
115+
public void store( Portlet portlet )
116+
{
117+
delete( portlet.getId( ) );
118+
insert( portlet );
119+
}
120+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2002-2024, City of Paris
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice
10+
* and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice
13+
* and the following disclaimer in the Formsation and/or other materials
14+
* provided with the distribution.
15+
*
16+
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17+
* contributors may be used to endorse or promote products derived from
18+
* this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
* License 1.0
33+
*/
34+
package fr.paris.lutece.plugins.forms.business.portlet;
35+
36+
import fr.paris.lutece.portal.business.portlet.IPortletInterfaceDAO;
37+
import fr.paris.lutece.portal.business.portlet.PortletHome;
38+
import fr.paris.lutece.portal.business.portlet.PortletTypeHome;
39+
import fr.paris.lutece.portal.service.spring.SpringContextService;
40+
41+
/**
42+
* This class provides instances management methods for FormsListPortlet objects
43+
*/
44+
public class FormsListPortletHome extends PortletHome
45+
{
46+
private static IFormsListPortletDAO _dao = SpringContextService.getBean( "forms.formsListPortletDAO" );
47+
private static FormsListPortletHome _instance = null;
48+
49+
/**
50+
* Returns the instance of FormsListPortletHome
51+
*
52+
* @return the FormsListPortletHome instance
53+
*/
54+
public static PortletHome getInstance( )
55+
{
56+
if ( _instance == null )
57+
{
58+
_instance = new FormsListPortletHome( );
59+
}
60+
61+
return _instance;
62+
}
63+
64+
/**
65+
* Returns the identifier of the portlet type
66+
*
67+
* @return the portlet type identifier
68+
*/
69+
public String getPortletTypeId( )
70+
{
71+
String strCurrentClassName = this.getClass( ).getName( );
72+
return PortletTypeHome.getPortletTypeId( strCurrentClassName );
73+
}
74+
75+
/**
76+
* Returns the instance of the portlet DAO singleton
77+
*
78+
* @return the instance of the DAO singleton
79+
*/
80+
public IPortletInterfaceDAO getDAO( )
81+
{
82+
return _dao;
83+
}
84+
}
85+

0 commit comments

Comments
 (0)