Coverage Report - fr.paris.lutece.plugins.adminsql.web.AdminSqlJspBean
 
Classes in this File Line Coverage Branch Coverage Complexity
AdminSqlJspBean
0 %
0/581
0 %
0/182
5,143
 
 1  
 /*
 2  
  * Copyright (c) 2002-2017, Mairie de 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 documentation 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.adminsql.web;
 35  
 
 36  
 import java.util.ArrayList;
 37  
 import java.util.HashMap;
 38  
 import java.util.List;
 39  
 import java.util.Map;
 40  
 
 41  
 import javax.servlet.http.HttpServletRequest;
 42  
 
 43  
 import fr.paris.lutece.plugins.adminsql.business.DataHome;
 44  
 import fr.paris.lutece.plugins.adminsql.business.Field;
 45  
 import fr.paris.lutece.plugins.adminsql.business.FieldHome;
 46  
 import fr.paris.lutece.plugins.adminsql.business.FieldValues;
 47  
 import fr.paris.lutece.plugins.adminsql.business.Table;
 48  
 import fr.paris.lutece.plugins.adminsql.business.TableHome;
 49  
 import fr.paris.lutece.plugins.adminsql.service.AdminSqlConnectionService;
 50  
 import fr.paris.lutece.portal.service.database.AppConnectionService;
 51  
 import fr.paris.lutece.portal.service.message.AdminMessage;
 52  
 import fr.paris.lutece.portal.service.message.AdminMessageService;
 53  
 import fr.paris.lutece.portal.service.template.AppTemplateService;
 54  
 import fr.paris.lutece.portal.service.util.AppException;
 55  
 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
 56  
 import fr.paris.lutece.util.ReferenceList;
 57  
 import fr.paris.lutece.util.html.HtmlTemplate;
 58  
 import fr.paris.lutece.util.url.UrlItem;
 59  
 
 60  
 
 61  
 /**
 62  
  * Management of the sql server
 63  
  */
 64  0
 public class AdminSqlJspBean extends PluginAdminPageJspBean
 65  
 {
 66  
     //Rights
 67  
     public static final String RIGHT_MANAGE_ADMIN_SQL = "ADMIN_SQL_MANAGEMENT";
 68  
 
 69  
     //Messages
 70  
     private static final String MESSAGE_TITLE_INVALID_CHARACTERS = "portal.site.message.invalidCharactersInTitleName";
 71  
     private static final String MESSAGE_ERROR_FIELD_NAME = "adminsql.create_field.errorFieldName";
 72  
     private static final String MESSAGE_ERROR_FIELD_TYPE_LENGTH = "adminsql.create_field.errorFieldTypeLength";
 73  
     private static final String MESSAGE_ERROR_TABLE_NAME = "adminsql.create_table.errorTableName";
 74  
     private static final String MESSAGE_ERROR_NULL_AND_PRIMARY_KEY = "adminsql.create_field.errorNullAndPrimaryKey";
 75  
 
 76  
     //Properties
 77  
     private static final String PROPERTY_PAGE_TITLE_POOL_LIST = "adminsql.manage_databases.pageTitle";
 78  
     private static final String PROPERTY_PAGE_TITLE_TABLE_LIST = "adminsql.manage_tables.pageTitle";
 79  
     private static final String PROPERTY_PAGE_TITLE_MANAGE_FIELDS_STRUCTURE = "adminsql.manage_fields_structure.pageTitle";
 80  
     private static final String PROPERTY_PAGE_TITLE_DATA_TABLE = "adminsql.manage_data.pageTitle";
 81  
     private static final String PROPERTY_PAGE_TITLE_CREATE_DATA = "adminsql.create_data.pageTitle";
 82  
     private static final String PROPERTY_PAGE_TITLE_MODIFY_DATA = "adminsql.modify_data.pageTitle";
 83  
     private static final String PROPERTY_PAGE_TITLE_MODIFY_FIELD_STRUCTURE = "adminsql.modify_field_structure.pageTitle";
 84  
     private static final String PROPERTY_PAGE_TITLE_CREATE_FIELD = "adminsql.create_field.pageTitle";
 85  
     private static final String PROPERTY_CONFIRM_DELETE_FIELD = "adminsql.delete_field.confirm_delete_field";
 86  
     private static final String PROPERTY_CONFIRM_MODIFY_FIELD = "adminsql.modify_field.confirm_modify_field";
 87  
     private static final String PROPERTY_PAGE_TITLE_CREATE_TABLE = "adminsql.create_table.pageTitle";
 88  
     private static final String PROPERTY_CONFIRM_DELETE_TABLE = "adminsql.delete_table.confirm_delete_table";
 89  
     private static final String PROPERTY_PAGE_TITLE_MODIFY_TABLE_NAME = "adminsql.modify_table_name.pageTitle";
 90  
     private static final String PROPERTY_PAGE_TITLE_FONCTIONNALITIES_LIST = "adminsql.choose_fonctionnality.pageTitle";
 91  
     private static final String PROPERTY_PAGE_TITLE_USER_REQUEST = "adminsql.user_request.pageTitle";
 92  
     private static final String PROPERTY_CONFIRM_DELETE_DATA = "adminsql.delete_data.confirm_delete_data";
 93  
 
 94  
     //Parameters
 95  
     private static final String PARAMETER_POOL_NAME = "pool_name";
 96  
     private static final String PARAMETER_TABLE_NAME = "table_name";
 97  
     private static final String PARAMETER_TABLE_NAME_TO_MODIFY = "tableNameToModify";
 98  
     private static final String PARAMETER_TABLE_COMMENT = "table_comment";
 99  
     private static final String PARAMETER_DATA_ID = "data_id";
 100  
     private static final String PARAMETER_FIELD_NAME = "field_name";
 101  
     private static final String PARAMETER_LABEL_TYPE_VALUE = "type_value_id";
 102  
     private static final String PARAMETER_NULL_VALUE = "null_value";
 103  
     private static final String PARAMETER_FIELD_LABEL_TYPE = "field_label_type";
 104  
     private static final String PARAMETER_FIELD_LENGTH_TYPE = "field_length_type";
 105  
     private static final String PARAMETER_FIELD_DEFAULT_VALUE = "field_default_value";
 106  
     private static final String PARAMETER_FIELD_NULL = "field_null_value";
 107  
     private static final String PARAMETER_FIELD_COMMENT = "field_comment_value";
 108  
     private static final String PARAMETER_FIELD_KEY = "field_key_value";
 109  
     private static final String PARAMETER_FIELD_TO_MODIFY = "fieldToModify";
 110  
     private static final String PARAMETER_ID_OLD_FIELD_KEY = "idOldFieldKey";
 111  
     private static final String PARAMETER_ID_FIELD_TYPE = "field_type_id";
 112  
     private static final String PARAMETER_ID_FIELD_NULL = "field_null_id";
 113  
     private static final String PARAMETER_ID_FIELD_KEY = "field_key_id";
 114  
     private static final String PARAMETER_FIELDS_NUMBER_ADDING = "fields_number_adding";
 115  
     private static final String PARAMETER_PLACE_OF_FIELD = "place_of_new_field";
 116  
     private static final String PARAMETER_AFTER_THE_FIELD = "choose_fields";
 117  
     private static final String PARAMETER_NUMBER_FIELDS_TABLE = "number_fields_table";
 118  
     private static final String PARAMETER_DATA = "data";
 119  
     private static final String PARAMETER_CONCAT_FIELDNAME_DATA = "concat_fielname_data";
 120  
     private static final String PARAMETER_USER_REQUEST = "user_request";
 121  
     private static final String PARAMETER_DB_TYPE_NAME = "db_type_name";
 122  
     private static final String PARAMETER_IDENTIFIANT_USER = "identifiant";
 123  
     private static final String PARAMETER_PASSWORD_USER = "password";
 124  
     private static final String PARAMETER_ROW_TO_MODIFY = "row_to_modify";
 125  
     private static final String PARAMETER_CHECKBOX_STRUCTURE = "checkbox_structure";
 126  
     private static final String PARAMETER_CHECKBOX_DATA = "checkbox_data";
 127  
     private static final String PARAMETER_CHECKBOX_DATABASE = "checkbox_database";
 128  
     private static final String PARAMETER_ERROR_MESSAGE = "error_mess";
 129  
 
 130  
     //Markers
 131  
     private static final String MARK_POOL_LIST = "pool_list";
 132  
     private static final String MARK_TABLE_LIST = "table_list";
 133  
     private static final String MARK_DATA_LIST = "data_list";
 134  
     private static final String MARK_FIELDS_TABLE = "field_list";
 135  
     private static final String MARK_DATA_LIST_TO_MODIFY = "data_to_modify_list";
 136  
     private static final String MARK_PRIMARY_KEY_LIST = "primary_key_list";
 137  
     private static final String MARK_POOL_NAME = "pool_name";
 138  
     private static final String MARK_TABLE = "table";
 139  
     private static final String MARK_FIELD = "field";
 140  
     private static final String MARK_FIELD_TYPE_REFERENCE_LIST = "field_type_list";
 141  
     private static final String MARK_FIELD_KEY_REFERENCE_LIST = "field_key_list";
 142  
     private static final String MARK_FIELD_NULL_REFERENCE_LIST = "field_null_list";
 143  
     private static final String MARK_FIELD_NAME_REFERENCE_LIST = "field_name_list";
 144  
     private static final String MARK_NEW_FIELD = "place_of_new_field";
 145  
     private static final String MARK_AFTER_THE_FIELD = "choose_fields";
 146  
     private static final String MARK_NUMBER_FIELDS_TABLE = "number_fields_table";
 147  
     private static final String MARK_CONCAT_PRIMARY_KEY_AND_VALUE = "concat_primary_key_and_value";
 148  
     private static final String MARK_CONCAT_FIELDNAME_DATA = "concat_fielname_data";
 149  
     private static final String MARK_USER_REQUEST = "user_request";
 150  
     private static final String MARK_FIELDS_NAMES = "list_fields_names";
 151  
     private static final String MARK_DATABASE_TYPE_LIST = "list_database_type";
 152  
     private static final String MARK_DB_TYPE_NAME = "db_type_name";
 153  
     private static final String MARK_SQL_ERROR = "sql_error";
 154  
     private static final String MARK_DUMP_SCRIPT = "dump_script";
 155  
     private static final String MARK_INPUT_CONCAT_FIELD_NAME_AND_DATA = "input_concat_field_name_data";
 156  
     private static final String MARK_DUMP_COMMANDS = "dump_commands";
 157  
     private static final String MARK_APPEXCEPTION_ERROR = "error_sql";
 158  
 
 159  
     //Error messages
 160  
     private static final String MESSAGE_SQL_ERROR_IN_QUERY = "adminsql.message.sqlErrorInQuery";
 161  
 
 162  
     //Jsps
 163  
     private static final String JSP_URL_MANAGE_FIELDS_STRUCTURES = "ManageFieldsStructure.jsp";
 164  
     private static final String JSP_URL_MANAGE_TABLES = "ManageTables.jsp";
 165  
     private static final String JSP_DO_DELETE_FIELD_STRUCTURE = "jsp/admin/plugins/adminsql/DoDeleteFieldStructure.jsp";
 166  
     private static final String JSP_DO_DELETE_TABLE = "jsp/admin/plugins/adminsql/DoDeleteTable.jsp";
 167  
     private static final String JSP_DO_MODIFY_FIELD_STRUCTURE = "jsp/admin/plugins/adminsql/DoMofifyFieldStructure.jsp";
 168  
     private static final String JSP_URL_MANAGE_DATA_TABLE = "ManageData.jsp";
 169  
     private static final String JSP_URL_MANAGE_DATA_TABLE_AFTER_MODIF = "ManageData.jsp";
 170  
     private static final String JSP_DO_DELETE_DATA = "jsp/admin/plugins/adminsql/DoDeleteData.jsp";
 171  
     private static final String JSP_CREATE_TABLE = "jsp/admin/plugins/adminsql/CreateTable.jsp";
 172  
 
 173  
     // Properties file definition
 174  
     private static final String PROPERTY_DATABASE_TYPE_LIST = "adminsql.type.database.list";
 175  
 
 176  
     //Urls
 177  
     private static final String URL_CREATION_FIELD = "jsp/admin/plugins/adminsql/CreateFieldStructure.jsp";
 178  
     private static final String URL_MODIFY_FIELD = "jsp/admin/plugins/adminsql/ModifyFieldStructure.jsp";
 179  
     private static final String URL_CREATE_DATA = "jsp/admin/plugins/adminsql/CreateData.jsp";
 180  
     private static final String URL_MODIFY_DATA = "jsp/admin/plugins/adminsql/ModifyData.jsp";
 181  
     private static final String URL_USER_REQUEST = "jsp/admin/plugins/adminsql/UserRequest.jsp";
 182  
     private static final String URL_DO_USER_REQUEST_ERROR = "jsp/admin/plugins/adminsql/DoUserRequestError.jsp";
 183  
 
 184  
 
 185  
     //Templates
 186  0
     private String TEMPLATE_MANAGE_POOL_SQL = "admin/plugins/adminsql/manage_databases.html";
 187  0
     private String TEMPLATE_MANAGE_TABLE_SQL = "admin/plugins/adminsql/manage_tables.html";
 188  0
     private String TEMPLATE_MANAGE_DATA_SQL = "admin/plugins/adminsql/manage_data.html";
 189  0
     private String TEMPLATE_CREATE_DATA = "admin/plugins/adminsql/create_data.html";
 190  0
     private String TEMPLATE_MANAGE_STRUCTURE_SQL = "admin/plugins/adminsql/manage_fields_structure.html";
 191  0
     private String TEMPLATE_MODIFY_DATA = "admin/plugins/adminsql/modify_data.html";
 192  0
     private String TEMPLATE_MODIFY_STRUCTURE = "admin/plugins/adminsql/modify_field_structure.html";
 193  0
     private String TEMPLATE_CREATE_STRUCTURE = "admin/plugins/adminsql/create_field.html";
 194  0
     private String TEMPLATE_CREATE_TABLE = "admin/plugins/adminsql/create_table.html";
 195  0
     private String TEMPLATE_MODIFY_TABLE_NAME = "admin/plugins/adminsql/modify_table_name.html";
 196  0
     private String TEMPLATE_CHOOSE_FONCTIONNALITIES_LIST = "admin/plugins/adminsql/fonctionnalities_list_on_database.html";
 197  0
     private String TEMPLATE_USER_REQUEST = "admin/plugins/adminsql/user_request.html";
 198  0
     private String TEMPLATE_RESULT_OF_USER_REQUEST = "admin/plugins/adminsql/result_of_user_request.html";
 199  0
     private String TEMPLATE_EXPORT_DATABASE = "admin/plugins/adminsql/export_database.html";
 200  0
     private String TEMPLATE_SQL_ERROR_PAGE = "admin/plugins/adminsql/sql_error_page.html";
 201  0
     private String TEMPLATE_PARAMETER_TO_EXPORT_DATABASE = "admin/plugins/adminsql/parameter_to_export_db.html";
 202  0
     private String TEMPLATE_DUMP_DATABASE = "admin/plugins/adminsql/dump_database.html";
 203  0
     private String TEMPLATE_USER_REQUEST_ERROR = "admin/plugins/adminsql/error_user_request.html";
 204  
 
 205  
     /**
 206  
      * List of databases
 207  
      * @param request HttpServletRequest
 208  
      * @return the list of databases page
 209  
      */
 210  
     public String getManageDatabases( HttpServletRequest request )
 211  
     {
 212  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_POOL_LIST );
 213  
 
 214  0
         ReferenceList listPools = new ReferenceList(  );
 215  0
         AppConnectionService.getPoolList( listPools );
 216  
 
 217  0
         HashMap model = new HashMap(  );
 218  0
         model.put( MARK_POOL_LIST, listPools );
 219  
 
 220  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_POOL_SQL, getLocale(  ), model );
 221  
 
 222  0
         return getAdminPage( template.getHtml(  ) );
 223  
     }
 224  
 
 225  
     /**
 226  
      * List of fonctionnalities on the pool
 227  
      * @param request HttpServletRequest
 228  
      * @return list of fonctionnalities
 229  
      */
 230  
     public String getManageFonctionnalitiesList( HttpServletRequest request )
 231  
     {
 232  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_FONCTIONNALITIES_LIST );
 233  
 
 234  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 235  0
         HashMap model = new HashMap(  );
 236  0
         model.put( MARK_POOL_NAME, strPoolName );
 237  
 
 238  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CHOOSE_FONCTIONNALITIES_LIST, getLocale(  ),
 239  
                 model );
 240  
 
 241  0
         return getAdminPage( template.getHtml(  ) );
 242  
     }
 243  
 
 244  
     /**
 245  
      * List all tables of a database
 246  
      * @param request HttpServletRequest
 247  
      * @return List of all tables of the databases
 248  
      */
 249  
     public String getManageTables( HttpServletRequest request )
 250  
     {
 251  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_TABLE_LIST );
 252  
 
 253  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 254  
 
 255  0
         List<Table> listTables = TableHome.findAllByPool( strPoolName, getPlugin(  ) );
 256  
 
 257  0
         Map<String, Object> model = new HashMap<String, Object>(  );
 258  0
         model.put( MARK_TABLE_LIST, listTables );
 259  0
         model.put( MARK_POOL_NAME, strPoolName );
 260  
 
 261  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_TABLE_SQL, getLocale(  ), model );
 262  
 
 263  0
         return getAdminPage( template.getHtml(  ) );
 264  
     }
 265  
 
 266  
     /**
 267  
      * User can stamp his request
 268  
      * @param request HttpServletRequest
 269  
      * @return user request page
 270  
      */
 271  
     public String getUserRequest( HttpServletRequest request )
 272  
     {
 273  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_USER_REQUEST );
 274  
 
 275  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 276  
 
 277  0
         Map<String, Object> model = new HashMap<String, Object>(  );
 278  0
         model.put( MARK_POOL_NAME, strPoolName );
 279  
 
 280  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_USER_REQUEST, getLocale(  ), model );
 281  
 
 282  0
         return getAdminPage( template.getHtml(  ) );
 283  
     }
 284  
 
 285  
     /**
 286  
      * User can see the result of his request
 287  
      * @param request HttpServletRequest
 288  
      * @return result of the request
 289  
      */
 290  
     public String doUserRequest( HttpServletRequest request )
 291  
     {
 292  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 293  0
         String strUserRequest = request.getParameter( PARAMETER_USER_REQUEST );
 294  0
         List<List<String>> listData = new ArrayList<List<String>>(  );
 295  0
         List<String> listFieldsNames = new ArrayList<String>(  );
 296  0
         strUserRequest = strUserRequest.trim(  );
 297  
 
 298  0
         String strSqlRequest = strUserRequest;
 299  0
         strSqlRequest = strUserRequest.toLowerCase(  );
 300  
 
 301  0
         if ( strSqlRequest.contains( "select" ) )
 302  
         {
 303  0
             strSqlRequest = strSqlRequest.substring( 0, 6 );
 304  
 
 305  0
             if ( strSqlRequest.contains( "select" ) )
 306  
             {
 307  
                 try
 308  
                 {
 309  0
                     listData = DataHome.findAllInUserRequest( strPoolName, strUserRequest,
 310  0
                             AdminSqlConnectionService.getConnectionService( strPoolName ) );
 311  0
                     listFieldsNames = DataHome.findFieldsNames( strUserRequest,
 312  0
                             AdminSqlConnectionService.getConnectionService( strPoolName ), strPoolName );
 313  
                 }
 314  0
                 catch ( AppException e )
 315  
                 {
 316  0
                     String strErrorMessage = ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "";
 317  0
                     Map<String, Object> model = new HashMap<String, Object>(  );
 318  0
                     model.put( MARK_POOL_NAME, strPoolName );
 319  0
                     model.put( MARK_APPEXCEPTION_ERROR, strErrorMessage );
 320  0
                     model.put( MARK_USER_REQUEST, strUserRequest );
 321  
 
 322  0
                     HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_USER_REQUEST_ERROR, getLocale(  ),
 323  
                             model );
 324  
 
 325  0
                     return getAdminPage( template.getHtml(  ) );
 326  0
                 }
 327  
             }
 328  
         }
 329  
         else
 330  
         {
 331  
             try
 332  
             {
 333  0
                 DataHome.createWithUserRequest( strUserRequest,
 334  0
                     AdminSqlConnectionService.getConnectionService( strPoolName ), strPoolName );
 335  
             }
 336  0
             catch ( AppException e )
 337  
             {
 338  0
                 String strErrorMessage = ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "";
 339  0
                 Map<String, Object> model = new HashMap<String, Object>(  );
 340  0
                 model.put( MARK_POOL_NAME, strPoolName );
 341  0
                 model.put( MARK_APPEXCEPTION_ERROR, strErrorMessage );
 342  0
                 model.put( MARK_USER_REQUEST, strUserRequest );
 343  
 
 344  0
                 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_USER_REQUEST_ERROR, getLocale(  ),
 345  
                         model );
 346  
 
 347  0
                 return getAdminPage( template.getHtml(  ) );
 348  0
             }
 349  
         }
 350  
 
 351  0
         if ( listData.equals( null ) )
 352  
         {
 353  0
             UrlItem url = new UrlItem( JSP_URL_MANAGE_TABLES );
 354  0
             url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 355  
 
 356  0
             return url.getUrl(  );
 357  
         }
 358  
         else
 359  
         {
 360  0
             HashMap<String, Object> model = new HashMap<String, Object>(  );
 361  0
             model.put( MARK_POOL_NAME, strPoolName );
 362  0
             model.put( MARK_USER_REQUEST, strUserRequest );
 363  0
             model.put( MARK_DATA_LIST, listData );
 364  0
             model.put( MARK_FIELDS_NAMES, listFieldsNames );
 365  
 
 366  0
             HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_RESULT_OF_USER_REQUEST, getLocale(  ),
 367  
                     model );
 368  
 
 369  0
             return getAdminPage( template.getHtml(  ) );
 370  
         }
 371  
     }
 372  
 
 373  
     public String getUserRequestError( HttpServletRequest request )
 374  
     {
 375  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 376  0
         String strErrorMessage = request.getParameter( PARAMETER_ERROR_MESSAGE );
 377  
 
 378  0
         UrlItem url = new UrlItem( URL_USER_REQUEST );
 379  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 380  
 
 381  0
         return AdminMessageService.getMessageUrl( request, MESSAGE_SQL_ERROR_IN_QUERY, strErrorMessage, url.getUrl(  ),
 382  
             AdminMessage.TYPE_STOP );
 383  
     }
 384  
 
 385  
     /**
 386  
      * User can choose the options of the dump
 387  
      * @param request HttpServletRequest
 388  
      * @return the dump option page
 389  
      */
 390  
     public String getExportDatabase( HttpServletRequest request )
 391  
     {
 392  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 393  0
         HashMap<String, Object> model = new HashMap<String, Object>(  );
 394  0
         model.put( MARK_POOL_NAME, strPoolName );
 395  
 
 396  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PARAMETER_TO_EXPORT_DATABASE, getLocale(  ),
 397  
                 model );
 398  
 
 399  0
         return getAdminPage( template.getHtml(  ) );
 400  
     }
 401  
 
 402  
     /**
 403  
      * User can see the dump of a database on a page
 404  
      * @param request HttpServletRequest
 405  
      * @return dump database page
 406  
      */
 407  
     public String doExportDatabase( HttpServletRequest request )
 408  
     {
 409  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 410  0
         String strCheckboxStructure = request.getParameter( PARAMETER_CHECKBOX_STRUCTURE );
 411  0
         String strCheckboxData = request.getParameter( PARAMETER_CHECKBOX_DATA );
 412  0
         String strCheckboxDatabase = request.getParameter( PARAMETER_CHECKBOX_DATABASE );
 413  0
         String strFieldNameList = "";
 414  0
         String strPKFieldName = "";
 415  0
         String strKey = "";
 416  0
         List<String> DumpCommandslist = new ArrayList(  );
 417  0
         List<String> listRows = new ArrayList(  );
 418  0
         StringBuffer stDumpCommands = new StringBuffer(  );
 419  0
         List<Table> tableList = new ArrayList<Table>(  );
 420  0
         List<Field> fieldList = new ArrayList<Field>(  );
 421  0
         List<List<String>> listData = new ArrayList<List<String>>(  );
 422  0
         tableList = TableHome.findAllByPool( strPoolName, getPlugin(  ) );
 423  0
         stDumpCommands.append( "--\n-- Base de donn�es : " + "`" + strPoolName + "`" + "\n--\n\n" );
 424  0
         stDumpCommands.append( "-- -------------------------------\n\n" );
 425  
 
 426  0
         if ( ( strCheckboxDatabase != null ) && strCheckboxDatabase.equals( "on" ) )
 427  
         {
 428  0
             stDumpCommands.append( "DROP DATABASE IF EXISTS " + strPoolName + ";\n" + "CREATE DATABASE " + strPoolName +
 429  
                 ";\n" + "USE " + strPoolName + ";\n\n" );
 430  
         }
 431  
 
 432  0
         for ( Table table : tableList )
 433  
         {
 434  0
             String strTableName = table.getTableName(  );
 435  0
             String strDataRow = "";
 436  0
             String strInserDataLine = "";
 437  0
             String strStructureLine = "";
 438  0
             String strFieldsStructuresLines = "";
 439  
 
 440  0
             if ( ( strCheckboxStructure != null ) && strCheckboxStructure.equals( "on" ) )
 441  
             {
 442  0
                 stDumpCommands.append( "--\n-- Structure de la table " + "`" + strTableName + "`" + "\n--\n\n" );
 443  0
                 stDumpCommands.append( "DROP TABLE IF EXISTS " + "`" + strTableName + "`;\n" );
 444  0
                 stDumpCommands.append( "CREATE TABLE " + "`" + strTableName + "`(\n" );
 445  0
                 fieldList = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 446  
 
 447  0
                 for ( Field field : fieldList )
 448  
                 {
 449  0
                     String strFieldName = field.getFieldName(  );
 450  0
                     strFieldNameList += ( "`" + strFieldName + "`," );
 451  
 
 452  0
                     String strType = field.getTypeValue(  );
 453  0
                     String strNull = field.getLabelNullValue(  );
 454  
 
 455  0
                     if ( strNull.equals( "NO" ) )
 456  
                     {
 457  0
                         strNull = "NOT NULL";
 458  
                     }
 459  
                     else
 460  
                     {
 461  0
                         strNull = "";
 462  
                     }
 463  
 
 464  0
                     String strDefault = field.getDefaultValue(  );
 465  
 
 466  0
                     if ( strDefault.equals( "" ) )
 467  
                     {
 468  0
                         strDefault = "";
 469  
                     }
 470  
                     else
 471  
                     {
 472  0
                         if ( field.getTypeValue(  ).equals( "text" ) )
 473  
                         {
 474  0
                             strDefault = "";
 475  
                         }
 476  0
                         else if ( field.getDefaultValue(  ).equals( "NULL" ) ||
 477  0
                                 field.getDefaultValue(  ).equals( "CURRENT_TIMESTAMP" ) )
 478  
                         {
 479  0
                             strDefault = "default " + field.getDefaultValue(  );
 480  
                         }
 481  
                         else
 482  
                         {
 483  0
                             strDefault = "default " + "'" + field.getDefaultValue(  ) + "'";
 484  
                         }
 485  
                     }
 486  
 
 487  0
                     strKey = field.getLabelKeyValue(  );
 488  
 
 489  0
                     if ( strKey.equals( "PRI" ) )
 490  
                     {
 491  0
                         strPKFieldName += ( "`" + field.getFieldName(  ) + "`" + "," );
 492  
                     }
 493  
 
 494  0
                     strStructureLine = "`" + strFieldName + "` " + strType + " " + strNull + " " + strDefault + ",";
 495  0
                     strFieldsStructuresLines += ( strStructureLine + "\n" );
 496  0
                 }
 497  
 
 498  0
                 if ( strPKFieldName != "" )
 499  
                 {
 500  0
                     strPKFieldName = strPKFieldName.substring( 0, strPKFieldName.length(  ) - 1 );
 501  0
                     strFieldsStructuresLines += ( "PRIMARY KEY (" + strPKFieldName + ")\n);" );
 502  
                 }
 503  
                 else
 504  
                 {
 505  0
                     strFieldsStructuresLines = strFieldsStructuresLines.substring( 0,
 506  0
                             strFieldsStructuresLines.length(  ) - 2 ) + ");";
 507  
                 }
 508  
 
 509  0
                 strPKFieldName = "";
 510  0
                 stDumpCommands.append( strFieldsStructuresLines + "\n\n" );
 511  0
                 strFieldNameList = "(" + strFieldNameList.substring( 0, strFieldNameList.length(  ) - 1 ) + ")";
 512  
             }
 513  
 
 514  0
             if ( ( strCheckboxData != null ) && strCheckboxData.equals( "on" ) )
 515  
             {
 516  0
                 if ( !( ( strCheckboxStructure != null ) && strCheckboxStructure.equals( "on" ) ) )
 517  
                 {
 518  0
                     fieldList = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 519  
 
 520  0
                     for ( Field field : fieldList )
 521  
                     {
 522  0
                         String strFieldName = field.getFieldName(  );
 523  0
                         strFieldNameList += ( "`" + strFieldName + "`," );
 524  0
                     }
 525  
 
 526  0
                     strFieldNameList = "(" + strFieldNameList.substring( 0, strFieldNameList.length(  ) - 1 ) + ")";
 527  
                 }
 528  
 
 529  0
                 listData = DataHome.findAll( strTableName, AdminSqlConnectionService.getConnectionService( strPoolName ) );
 530  
 
 531  0
                 if ( listData.isEmpty(  ) )
 532  
                 {
 533  0
                     stDumpCommands.append( "--\n-- Pas de donnees dans " + "`" + strTableName + "`" + "\n--\n\n" ); //
 534  
                 }
 535  
                 else
 536  
                 {
 537  0
                     stDumpCommands.append( "--\n-- Contenu de la table " + "`" + strTableName + "`" + "\n--\n\n" );
 538  
 
 539  0
                     for ( List<String> listRow : listData )
 540  
                     {
 541  0
                         for ( String strData : listRow )
 542  
                         {
 543  0
                             if ( strData.contains( "'" ) )
 544  
                             {
 545  0
                                 strData = strData.replaceAll( "'", "''" );
 546  
                             }
 547  
 
 548  0
                             strDataRow += ( "'" + strData + "'" + "," );
 549  0
                         }
 550  
 
 551  0
                         strInserDataLine = "(" + strDataRow.substring( 0, strDataRow.length(  ) - 1 ) + ");";
 552  0
                         stDumpCommands.append( "INSERT INTO " + "`" + strTableName + "`" + strFieldNameList +
 553  
                             " VALUES " + strInserDataLine + "\n" );
 554  0
                         strDataRow = "";
 555  0
                     }
 556  
 
 557  0
                     stDumpCommands.append( "\n" );
 558  
                 }
 559  
 
 560  0
                 strFieldNameList = "";
 561  
             }
 562  0
         }
 563  
 
 564  0
         HashMap model = new HashMap(  );
 565  0
         model.put( MARK_POOL_NAME, strPoolName );
 566  0
         model.put( MARK_DUMP_COMMANDS, stDumpCommands );
 567  
 
 568  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_DUMP_DATABASE, getLocale(  ), model );
 569  
 
 570  0
         return getAdminPage( template.getHtml(  ) );
 571  
     }
 572  
 
 573  
     /**
 574  
      * Creation of a table in a database
 575  
      * @param request HttpServletRequest
 576  
      * @return table creation page
 577  
      */
 578  
     public String getCreateTable( HttpServletRequest request )
 579  
     {
 580  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_TABLE );
 581  
 
 582  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 583  
 
 584  0
         HashMap model = new HashMap(  );
 585  0
         model.put( MARK_POOL_NAME, strPoolName );
 586  0
         model.put( MARK_FIELD_TYPE_REFERENCE_LIST, FieldHome.findFieldType( strPoolName, getPlugin(  ) ) );
 587  0
         model.put( MARK_FIELD_KEY_REFERENCE_LIST, FieldHome.findFieldKey( strPoolName, getPlugin(  ) ) );
 588  0
         model.put( MARK_FIELD_NULL_REFERENCE_LIST, FieldHome.findFieldNull( strPoolName, getPlugin(  ) ) );
 589  
 
 590  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_TABLE, getLocale(  ), model );
 591  
 
 592  0
         return getAdminPage( template.getHtml(  ) );
 593  
     }
 594  
 
 595  
     /**
 596  
      * Process the creation of the table
 597  
      * @param request HttpServletRequest
 598  
      * @return the manage tables page
 599  
      */
 600  
     public String doCreateTable( HttpServletRequest request )
 601  
     {
 602  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 603  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 604  0
         String strTableComment = request.getParameter( PARAMETER_TABLE_COMMENT );
 605  
 
 606  0
         String strFieldName = request.getParameter( PARAMETER_FIELD_NAME );
 607  0
         String strFieldLengthType = request.getParameter( PARAMETER_FIELD_LENGTH_TYPE );
 608  0
         String strFieldDefault = request.getParameter( PARAMETER_FIELD_DEFAULT_VALUE );
 609  
 
 610  0
         if ( strTableName.equals( null ) || strTableName.equals( "" ) )
 611  
         {
 612  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_TABLE_NAME, AdminMessage.TYPE_STOP );
 613  
         }
 614  
 
 615  0
         if ( strFieldName.equals( null ) || strFieldName.equals( "" ) )
 616  
         {
 617  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_FIELD_NAME, AdminMessage.TYPE_STOP );
 618  
         }
 619  
 
 620  0
         if ( ( strFieldLengthType == null ) || strFieldLengthType.equals( "" ) )
 621  
         {
 622  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_FIELD_TYPE_LENGTH, AdminMessage.TYPE_STOP );
 623  
         }
 624  
 
 625  
         //Combos
 626  0
         int nIdFieldType = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_TYPE ) );
 627  0
         int nIdFieldNull = 1;
 628  0
         int nIdFieldKey = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_KEY ) );
 629  
 
 630  0
         Table table = new Table(  );
 631  0
         table.setTableName( strTableName );
 632  0
         table.setPrimaryKey( strFieldName );
 633  0
         table.setComment( strTableComment );
 634  
 
 635  0
         Field field = new Field(  );
 636  0
         field.setFieldName( strFieldName );
 637  0
         field.setIdTypeValue( nIdFieldType );
 638  0
         field.setLengthTypeValue( strFieldLengthType );
 639  0
         field.setIdNullValue( nIdFieldNull );
 640  0
         field.setIdKeyValue( nIdFieldKey );
 641  0
         field.setDefaultValue( strFieldDefault );
 642  
 
 643  
         try
 644  
         {
 645  0
             TableHome.create( strPoolName, table, field, getPlugin(  ) );
 646  
         }
 647  0
         catch ( AppException e )
 648  
         {
 649  0
             UrlItem url = new UrlItem( JSP_CREATE_TABLE );
 650  
 
 651  0
             url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 652  0
             url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 653  
 
 654  0
             Object[] messageArgs = { ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "" };
 655  
 
 656  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_SQL_ERROR_IN_QUERY, messageArgs, url.getUrl(  ),
 657  
                 AdminMessage.TYPE_STOP );
 658  0
         }
 659  
 
 660  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_FIELDS_STRUCTURES );
 661  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 662  0
         url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 663  
 
 664  0
         return url.getUrl(  );
 665  
     }
 666  
 
 667  
     /**
 668  
      * Modification of a table name of a database
 669  
      * @param request HttpServletRequest
 670  
      * @return the modification of the table name page
 671  
      */
 672  
     public String getModifyTableName( HttpServletRequest request )
 673  
     {
 674  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_TABLE_NAME );
 675  
 
 676  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 677  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 678  
 
 679  0
         Table table = TableHome.findByPrimaryKey( strPoolName, strTableName, getPlugin(  ) );
 680  
 
 681  0
         HashMap model = new HashMap(  );
 682  0
         model.put( MARK_POOL_NAME, strPoolName );
 683  0
         model.put( MARK_TABLE, table );
 684  
 
 685  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_TABLE_NAME, getLocale(  ), model );
 686  
 
 687  0
         return getAdminPage( template.getHtml(  ) );
 688  
     }
 689  
 
 690  
     /**
 691  
      * Process the modification of the table name
 692  
      * @param request HttpServletRequest
 693  
      * @return the manage tables page
 694  
      */
 695  
     public String doModifyTableName( HttpServletRequest request )
 696  
     {
 697  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 698  0
         String strTableNameToModify = request.getParameter( PARAMETER_TABLE_NAME_TO_MODIFY );
 699  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 700  
 
 701  0
         if ( strTableName.equals( null ) || strTableName.equals( "" ) )
 702  
         {
 703  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_TABLE_NAME, AdminMessage.TYPE_STOP );
 704  
         }
 705  
 
 706  0
         Table table = new Table(  );
 707  0
         table.setTableName( strTableName );
 708  
 
 709  0
         TableHome.update( strTableNameToModify, table );
 710  
 
 711  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_TABLES );
 712  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 713  
 
 714  0
         return url.getUrl(  );
 715  
     }
 716  
 
 717  
     /**
 718  
      * Confirmation of the table deleting
 719  
      * @param request HttpServletRequest
 720  
      * @return a confirm message to delete
 721  
      */
 722  
     public String getDeleteTable( HttpServletRequest request )
 723  
     {
 724  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 725  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 726  0
         String strUrl = JSP_DO_DELETE_TABLE + "?" + PARAMETER_POOL_NAME + "=" + strPoolName + "&" +
 727  
             PARAMETER_TABLE_NAME + "=" + strTableName;
 728  0
         String strMessageKey = PROPERTY_CONFIRM_DELETE_TABLE;
 729  0
         String strAdminMessageUrl = AdminMessageService.getMessageUrl( request, strMessageKey, strUrl, "",
 730  
                 AdminMessage.TYPE_CONFIRMATION );
 731  
 
 732  0
         return strAdminMessageUrl;
 733  
     }
 734  
 
 735  
     /**
 736  
      * Process the deleting of the table on a database
 737  
      * @param request HttpServletRequest
 738  
      * @return the management of the tables
 739  
      */
 740  
     public String doDeleteTable( HttpServletRequest request )
 741  
     {
 742  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 743  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 744  
 
 745  0
         TableHome.remove( strTableName, getPlugin(  ) );
 746  
 
 747  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_TABLES );
 748  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 749  
 
 750  0
         return url.getUrl(  );
 751  
     }
 752  
 
 753  
     /**
 754  
      * Management of the fields structure of a table
 755  
      * @param request HttpServletRequest
 756  
      * @return the manage fields structure page
 757  
      */
 758  
     public String getManageFieldsStructure( HttpServletRequest request )
 759  
     {
 760  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_FIELDS_STRUCTURE );
 761  
 
 762  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 763  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 764  0
         String strPlaceOfField = request.getParameter( PARAMETER_PLACE_OF_FIELD );
 765  0
         String strAfterTheField = request.getParameter( PARAMETER_AFTER_THE_FIELD );
 766  
 
 767  0
         Table table = TableHome.findByPrimaryKey( strPoolName, strTableName, getPlugin(  ) ); //TODO COnnection service
 768  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 769  
 
 770  0
         HashMap model = new HashMap(  );
 771  0
         model.put( MARK_FIELDS_TABLE, listFields );
 772  0
         model.put( MARK_POOL_NAME, strPoolName );
 773  0
         model.put( MARK_TABLE, table );
 774  0
         model.put( MARK_NEW_FIELD, strPlaceOfField );
 775  0
         model.put( MARK_AFTER_THE_FIELD, strAfterTheField );
 776  
 
 777  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_STRUCTURE_SQL, getLocale(  ), model );
 778  
 
 779  0
         return getAdminPage( template.getHtml(  ) );
 780  
     }
 781  
 
 782  
     /**
 783  
      * Creation of a field in a table
 784  
      * @param request HttpServletRequest
 785  
      * @return the field creating page
 786  
      */
 787  
     public String getCreateFieldStructure( HttpServletRequest request )
 788  
     {
 789  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_FIELD );
 790  
 
 791  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 792  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 793  0
         String strPlaceOfField = request.getParameter( PARAMETER_PLACE_OF_FIELD );
 794  0
         String strAfterTheField = request.getParameter( PARAMETER_AFTER_THE_FIELD );
 795  0
         Table table = TableHome.findByPrimaryKey( strPoolName, strTableName, getPlugin(  ) );
 796  0
         HashMap model = new HashMap(  );
 797  0
         model.put( MARK_POOL_NAME, strPoolName );
 798  0
         model.put( MARK_TABLE, table );
 799  0
         model.put( MARK_FIELD_TYPE_REFERENCE_LIST, FieldHome.findFieldType( strPoolName, getPlugin(  ) ) );
 800  0
         model.put( MARK_FIELD_KEY_REFERENCE_LIST, FieldHome.findFieldKey( strPoolName, getPlugin(  ) ) );
 801  0
         model.put( MARK_FIELD_NULL_REFERENCE_LIST, FieldHome.findFieldNull( strPoolName, getPlugin(  ) ) );
 802  0
         model.put( MARK_NEW_FIELD, strPlaceOfField );
 803  0
         model.put( MARK_AFTER_THE_FIELD, strAfterTheField );
 804  
 
 805  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_STRUCTURE, getLocale(  ), model );
 806  
 
 807  0
         return getAdminPage( template.getHtml(  ) );
 808  
     }
 809  
 
 810  
     /**
 811  
      * Process the creation of the field
 812  
      * @param request HttpServletRequest
 813  
      * @return the mana
 814  
      */
 815  
     public String doCreateFieldStructure( HttpServletRequest request )
 816  
     {
 817  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 818  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 819  0
         String strFieldName = request.getParameter( PARAMETER_FIELD_NAME );
 820  0
         String strFieldLengthType = request.getParameter( PARAMETER_FIELD_LENGTH_TYPE );
 821  0
         String strFieldDefault = request.getParameter( PARAMETER_FIELD_DEFAULT_VALUE );
 822  0
         String strPlaceOfField = request.getParameter( PARAMETER_PLACE_OF_FIELD );
 823  0
         String strAfterTheField = request.getParameter( PARAMETER_AFTER_THE_FIELD );
 824  
 
 825  0
         if ( strFieldName.equals( null ) || strFieldName.equals( "" ) )
 826  
         {
 827  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_TABLE_NAME, AdminMessage.TYPE_STOP );
 828  
         }
 829  
 
 830  
         //Combos
 831  0
         int nIdFieldType = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_TYPE ) );
 832  0
         int nIdFieldNull = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_NULL ) );
 833  0
         int nIdFieldKey = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_KEY ) );
 834  
 
 835  0
         if ( ( nIdFieldType == 3 ) || ( nIdFieldType == 4 ) || ( nIdFieldType == 12 ) || ( nIdFieldType == 13 ) ||
 836  
                 ( nIdFieldType == 14 ) || ( nIdFieldType == 15 ) || ( nIdFieldType == 17 ) || ( nIdFieldType == 18 ) ||
 837  
                 ( nIdFieldType == 19 ) || ( nIdFieldType == 20 ) || ( nIdFieldType == 21 ) || ( nIdFieldType == 22 ) ||
 838  
                 ( nIdFieldType == 23 ) )
 839  
         {
 840  0
             strFieldLengthType = "";
 841  
         }
 842  0
         else if ( ( strFieldLengthType == null ) || strFieldLengthType.equals( "" ) )
 843  
         {
 844  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_FIELD_TYPE_LENGTH, AdminMessage.TYPE_STOP );
 845  
         }
 846  
 
 847  0
         int nPlaceOfField = Integer.parseInt( strPlaceOfField );
 848  
 
 849  0
         if ( ( nIdFieldNull == 2 ) && ( nIdFieldKey == 2 ) )
 850  
         {
 851  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NULL_AND_PRIMARY_KEY,
 852  
                 AdminMessage.TYPE_STOP );
 853  
         }
 854  
 
 855  0
         Field field = new Field(  );
 856  0
         field.setFieldName( strFieldName );
 857  0
         field.setIdTypeValue( nIdFieldType );
 858  0
         field.setLengthTypeValue( strFieldLengthType );
 859  0
         field.setIdNullValue( nIdFieldNull );
 860  0
         field.setIdKeyValue( nIdFieldKey );
 861  0
         field.setDefaultValue( strFieldDefault );
 862  0
         field.setPlaceOfField( nPlaceOfField );
 863  0
         field.setAfterTheField( strAfterTheField );
 864  
 
 865  
         try
 866  
         {
 867  0
             FieldHome.create( strPoolName, strTableName, field, getPlugin(  ) );
 868  
         }
 869  
 
 870  0
         catch ( AppException e )
 871  
         {
 872  0
             UrlItem url = new UrlItem( URL_CREATION_FIELD );
 873  
 
 874  0
             url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 875  0
             url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 876  0
             url.addParameter( PARAMETER_PLACE_OF_FIELD, strPlaceOfField );
 877  0
             url.addParameter( PARAMETER_AFTER_THE_FIELD, strAfterTheField );
 878  
 
 879  0
             Object[] messageArgs = { ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "" };
 880  
 
 881  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_SQL_ERROR_IN_QUERY, messageArgs, url.getUrl(  ),
 882  
                 AdminMessage.TYPE_STOP );
 883  0
         }
 884  
 
 885  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_FIELDS_STRUCTURES );
 886  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 887  0
         url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 888  
 
 889  0
         return url.getUrl(  );
 890  
     }
 891  
 
 892  
     /**
 893  
      * Modification of a field structure
 894  
      * @param request HttpServletRequest
 895  
      * @return the field modification page
 896  
      */
 897  
     public String getModifyFieldStructure( HttpServletRequest request )
 898  
     {
 899  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_FIELD_STRUCTURE );
 900  
 
 901  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 902  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 903  0
         String strFieldName = request.getParameter( PARAMETER_FIELD_NAME );
 904  0
         Table table = TableHome.findByPrimaryKey( strPoolName, strTableName, getPlugin(  ) );
 905  0
         Field field = FieldHome.findByPrimaryKey( strPoolName, strTableName, strFieldName, getPlugin(  ) );
 906  
 
 907  0
         HashMap model = new HashMap(  );
 908  0
         model.put( MARK_POOL_NAME, strPoolName );
 909  0
         model.put( MARK_TABLE, table );
 910  0
         model.put( MARK_FIELD, field );
 911  0
         model.put( MARK_FIELD_TYPE_REFERENCE_LIST, FieldHome.findFieldType( strPoolName, getPlugin(  ) ) );
 912  0
         model.put( MARK_FIELD_KEY_REFERENCE_LIST, FieldHome.findFieldKey( strPoolName, getPlugin(  ) ) );
 913  0
         model.put( MARK_FIELD_NULL_REFERENCE_LIST, FieldHome.findFieldNull( strPoolName, getPlugin(  ) ) );
 914  
 
 915  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_STRUCTURE, getLocale(  ), model );
 916  
 
 917  0
         return getAdminPage( template.getHtml(  ) );
 918  
     }
 919  
 
 920  
     /**
 921  
      * Process the modification of the field structure
 922  
      * @param request HttpServletRequest
 923  
      * @return the manage fields structure page
 924  
      */
 925  
     public String doModifyFieldStructure( HttpServletRequest request )
 926  
     {
 927  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 928  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 929  0
         String strFieldName = request.getParameter( PARAMETER_FIELD_NAME );
 930  0
         String strFieldLengthType = request.getParameter( PARAMETER_FIELD_LENGTH_TYPE );
 931  0
         String strFieldDefault = request.getParameter( PARAMETER_FIELD_DEFAULT_VALUE );
 932  0
         String strFieldNameToModify = request.getParameter( PARAMETER_FIELD_TO_MODIFY );
 933  0
         String strIdOldFieldKey = request.getParameter( PARAMETER_ID_OLD_FIELD_KEY );
 934  
 
 935  0
         int nIdOldFieldKey = Integer.parseInt( strIdOldFieldKey );
 936  
 
 937  0
         if ( strFieldName.equals( null ) || strFieldName.equals( "" ) )
 938  
         {
 939  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_FIELD_NAME, AdminMessage.TYPE_STOP );
 940  
         }
 941  
 
 942  
         //Combos
 943  0
         int nIdFieldType = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_TYPE ) );
 944  0
         int nIdFieldNull = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_NULL ) );
 945  0
         int nIdFieldKey = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_KEY ) );
 946  
 
 947  0
         if ( ( nIdFieldType == 3 ) || ( nIdFieldType == 4 ) || ( nIdFieldType == 12 ) || ( nIdFieldType == 13 ) ||
 948  
                 ( nIdFieldType == 14 ) || ( nIdFieldType == 15 ) || ( nIdFieldType == 17 ) || ( nIdFieldType == 18 ) ||
 949  
                 ( nIdFieldType == 19 ) || ( nIdFieldType == 20 ) || ( nIdFieldType == 21 ) || ( nIdFieldType == 22 ) ||
 950  
                 ( nIdFieldType == 23 ) )
 951  
         {
 952  0
             strFieldLengthType = "";
 953  
         }
 954  0
         else if ( ( strFieldLengthType == null ) || strFieldLengthType.equals( "" ) )
 955  
         {
 956  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_FIELD_TYPE_LENGTH, AdminMessage.TYPE_STOP );
 957  
         }
 958  
 
 959  0
         if ( strFieldDefault == null )
 960  
         {
 961  0
             strFieldDefault = "";
 962  
         }
 963  
 
 964  0
         if ( ( nIdFieldNull == 2 ) && ( nIdFieldKey == 2 ) )
 965  
         {
 966  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NULL_AND_PRIMARY_KEY,
 967  
                 AdminMessage.TYPE_STOP );
 968  
         }
 969  
 
 970  0
         Field field = new Field(  );
 971  
 
 972  0
         field.setFieldName( strFieldName );
 973  0
         field.setIdTypeValue( nIdFieldType );
 974  0
         field.setLengthTypeValue( strFieldLengthType );
 975  0
         field.setIdKeyValue( nIdFieldKey );
 976  0
         field.setIdNullValue( nIdFieldNull );
 977  0
         field.setDefaultValue( strFieldDefault );
 978  
 
 979  
         try
 980  
         {
 981  0
             FieldHome.update( strPoolName, strTableName, field, strFieldNameToModify, nIdOldFieldKey, getPlugin(  ) );
 982  
         }
 983  
 
 984  0
         catch ( AppException e )
 985  
         {
 986  0
             UrlItem url = new UrlItem( URL_MODIFY_FIELD );
 987  
 
 988  0
             url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 989  0
             url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 990  0
             url.addParameter( PARAMETER_FIELD_NAME, strFieldName );
 991  
 
 992  0
             Object[] messageArgs = { ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "" };
 993  
 
 994  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_SQL_ERROR_IN_QUERY, messageArgs, url.getUrl(  ),
 995  
                 AdminMessage.TYPE_STOP );
 996  0
         }
 997  
 
 998  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_FIELDS_STRUCTURES );
 999  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 1000  0
         url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 1001  
 
 1002  0
         return url.getUrl(  );
 1003  
     }
 1004  
 
 1005  
     /**
 1006  
      * Delete a field structure of a database
 1007  
      * @param request HttpServletRequest
 1008  
      * @return the confirmation message to delete the field
 1009  
      */
 1010  
     public String getDeleteFieldStructure( HttpServletRequest request )
 1011  
     {
 1012  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1013  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1014  0
         String strFieldName = request.getParameter( PARAMETER_FIELD_NAME );
 1015  0
         String strUrl = JSP_DO_DELETE_FIELD_STRUCTURE + "?" + PARAMETER_POOL_NAME + "=" + strPoolName + "&" +
 1016  
             PARAMETER_TABLE_NAME + "=" + strTableName + "&" + PARAMETER_FIELD_NAME + "=" + strFieldName;
 1017  0
         String strMessageKey = PROPERTY_CONFIRM_DELETE_FIELD;
 1018  
 
 1019  0
         String strAdminMessageUrl = AdminMessageService.getMessageUrl( request, strMessageKey, strUrl, "",
 1020  
                 AdminMessage.TYPE_CONFIRMATION );
 1021  
 
 1022  0
         return strAdminMessageUrl;
 1023  
     }
 1024  
 
 1025  
     /**
 1026  
      * Confirmation of a deling field structure
 1027  
      * @param request HttpServletRequest
 1028  
      * @return the manage fields structure page
 1029  
      */
 1030  
     public String doDeleteFieldStructure( HttpServletRequest request )
 1031  
     {
 1032  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1033  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1034  0
         String strFieldName = request.getParameter( PARAMETER_FIELD_NAME );
 1035  0
         FieldHome.remove( strTableName, strFieldName, getPlugin(  ) );
 1036  
 
 1037  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_FIELDS_STRUCTURES );
 1038  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 1039  0
         url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 1040  
 
 1041  0
         return url.getUrl(  );
 1042  
     }
 1043  
 
 1044  
     /**
 1045  
      * List all data's table of a database
 1046  
      * @return List of all data's table of a databases
 1047  
      * @param request HttpServetRequest
 1048  
      */
 1049  
     public String getManageDataTable( HttpServletRequest request )
 1050  
     {
 1051  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_DATA_TABLE );
 1052  
 
 1053  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1054  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1055  0
         Table table = TableHome.findByPrimaryKey( strPoolName, strTableName, getPlugin(  ) );
 1056  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 1057  0
         List<List<String>> listData = DataHome.findAll( strTableName,
 1058  0
                 AdminSqlConnectionService.getConnectionService( strPoolName ) );
 1059  0
         List<List<String>> listNewData = new ArrayList(  );
 1060  0
         List<String> listRows = new ArrayList(  );
 1061  0
         List<String> listInputs = new ArrayList(  );
 1062  
 
 1063  0
         int nNumberLine = listData.size(  );
 1064  0
         String strData = "";
 1065  0
         int nNumberFields = listFields.size(  );
 1066  0
         String strConcatFieldNameAndData = "";
 1067  0
         int nNumberData = 0;
 1068  0
         int nNumberOfRow = 0;
 1069  
         int n;
 1070  0
         String strInputConcatFieldNameAndData = "";
 1071  
 
 1072  0
         for ( n = 0; n < nNumberLine; n++ )
 1073  
         {
 1074  0
             strConcatFieldNameAndData = "";
 1075  0
             listRows = listData.get( n );
 1076  
 
 1077  0
             for ( Field field : listFields )
 1078  
             {
 1079  0
                 String strFieldName = field.getFieldName(  );
 1080  0
                 strData = listRows.get( listFields.indexOf( field ) );
 1081  0
                 strConcatFieldNameAndData = strConcatFieldNameAndData + "&" + strFieldName + "=" + strData;
 1082  0
                 strInputConcatFieldNameAndData = "<input name=" + field.getFieldName(  ) + " type=hidden value=" +
 1083  
                     strData + ">";
 1084  0
             }
 1085  
 
 1086  0
             listInputs.add( strInputConcatFieldNameAndData );
 1087  0
             listRows.add( strConcatFieldNameAndData );
 1088  0
             listNewData.add( listRows );
 1089  
         }
 1090  
 
 1091  0
         HashMap model = new HashMap(  );
 1092  0
         model.put( MARK_FIELDS_TABLE, listFields );
 1093  0
         model.put( MARK_CONCAT_FIELDNAME_DATA, strConcatFieldNameAndData );
 1094  0
         model.put( MARK_INPUT_CONCAT_FIELD_NAME_AND_DATA, strInputConcatFieldNameAndData );
 1095  0
         model.put( MARK_DATA_LIST, listData );
 1096  0
         model.put( MARK_POOL_NAME, strPoolName );
 1097  0
         model.put( MARK_TABLE, table );
 1098  
 
 1099  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DATA_SQL, getLocale(  ), model );
 1100  
 
 1101  0
         return getAdminPage( template.getHtml(  ) );
 1102  
     }
 1103  
 
 1104  
     /**
 1105  
      * Data creation page of a table
 1106  
      * @param request HttpServetRequest
 1107  
      * @return data creation page of a table
 1108  
      */
 1109  
     public String getCreateData( HttpServletRequest request )
 1110  
     {
 1111  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_DATA );
 1112  
 
 1113  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1114  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1115  0
         Table table = TableHome.findByPrimaryKey( strPoolName, strTableName, getPlugin(  ) );
 1116  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 1117  0
         HashMap model = new HashMap(  );
 1118  0
         model.put( MARK_FIELDS_TABLE, listFields );
 1119  0
         model.put( MARK_POOL_NAME, strPoolName );
 1120  0
         model.put( MARK_TABLE, table );
 1121  
 
 1122  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_DATA, getLocale(  ), model );
 1123  
 
 1124  0
         return getAdminPage( template.getHtml(  ) );
 1125  
     }
 1126  
 
 1127  
     /**
 1128  
      * Process the creation of data
 1129  
      * @param request HttpServletRequest
 1130  
      * @return the manage data page
 1131  
      */
 1132  
     public String doCreateData( HttpServletRequest request )
 1133  
     {
 1134  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1135  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1136  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 1137  0
         List<String> listFieldsNames = new ArrayList(  );
 1138  0
         List<String> listData = new ArrayList(  );
 1139  0
         int nIndexOfData=0;
 1140  0
         String strDefaultValue="";
 1141  0
         String strData = "";
 1142  
 
 1143  0
         for ( Field field : listFields )
 1144  
         {
 1145  0
             listFieldsNames.add( field.getFieldName(  ) );
 1146  0
             strData = request.getParameter( field.getFieldName(  ) );
 1147  
 
 1148  0
             if ( strData != null && strData.length( )>0  )
 1149  
                 
 1150  
             {
 1151  0
                 nIndexOfData = listData.indexOf(strData) + 1;
 1152  0
                 Field verifFieldDefault = listFields.get(nIndexOfData);
 1153  0
                 strDefaultValue=verifFieldDefault.getDefaultValue();
 1154  0
                  if ( strDefaultValue != null && strDefaultValue.length( )>0)
 1155  
                  {
 1156  0
                      strData = "";
 1157  
                  }
 1158  
                  else
 1159  
                  {
 1160  0
                     strData = strDefaultValue;
 1161  
                  }
 1162  
             }
 1163  0
             if ( field.getIdTypeValue(  ) == 1 )
 1164  
             {
 1165  0
                 strData = "\"" + strData + "\"";
 1166  
             }
 1167  0
             listData.add( strData );
 1168  0
         }
 1169  
         try
 1170  
         {
 1171  0
             DataHome.create( strPoolName, strTableName, listData, listFieldsNames,
 1172  0
                 AdminSqlConnectionService.getConnectionService( strPoolName ) );
 1173  
         }
 1174  0
         catch ( AppException e )
 1175  
         {
 1176  0
             UrlItem url = new UrlItem( URL_CREATE_DATA );
 1177  
 
 1178  0
             url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 1179  0
             url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 1180  
 
 1181  0
             Object[] messageArgs = { ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "" };
 1182  
 
 1183  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_SQL_ERROR_IN_QUERY, messageArgs, url.getUrl(  ),
 1184  
                 AdminMessage.TYPE_STOP );
 1185  0
         }
 1186  
 
 1187  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_DATA_TABLE );
 1188  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 1189  0
         url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 1190  
 
 1191  0
         return url.getUrl(  );
 1192  
     }
 1193  
 
 1194  
     /**
 1195  
      * Modification of a data in a table
 1196  
      * @param request HttpServletRequest
 1197  
      * @return the modification data page
 1198  
      */
 1199  
     public String getModifyData( HttpServletRequest request )
 1200  
     {
 1201  0
         setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_DATA );
 1202  
 
 1203  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1204  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1205  0
         Table table = TableHome.findByPrimaryKey( strPoolName, strTableName, getPlugin(  ) );
 1206  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 1207  0
         List<String> listData = new ArrayList(  );
 1208  0
         String strData = "";
 1209  
 
 1210  0
         for ( Field field : listFields )
 1211  
         {
 1212  0
             strData = request.getParameter( field.getFieldName(  ) );
 1213  0
             listData.add( strData );
 1214  0
         }
 1215  
 
 1216  0
         HashMap model = new HashMap(  );
 1217  0
         model.put( MARK_DATA_LIST, listData );
 1218  0
         model.put( MARK_FIELDS_TABLE, listFields );
 1219  0
         model.put( MARK_POOL_NAME, strPoolName );
 1220  0
         model.put( MARK_TABLE, table );
 1221  
 
 1222  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_DATA, getLocale(  ), model );
 1223  
 
 1224  0
         return getAdminPage( template.getHtml(  ) );
 1225  
     }
 1226  
 
 1227  
     /**
 1228  
      * Process the modification of a data in a table
 1229  
      * @param request HttpServletRequest
 1230  
      * @return the manage data page
 1231  
      */
 1232  
     public String doModifyData( HttpServletRequest request )
 1233  
     {
 1234  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1235  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1236  
 
 1237  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 1238  0
         List<String> listConcatFieldNameAndData = new ArrayList(  );
 1239  0
         List<String> listConcatFieldNameAndOldData = new ArrayList(  );
 1240  0
         List<FieldValues> listFieldValues = new ArrayList<FieldValues>(  );
 1241  
 
 1242  0
         for ( Field field : listFields )
 1243  
         {
 1244  0
             String strFieldNameUpdate = field.getFieldName(  ) + "_update";
 1245  0
             String strDataUpdate = request.getParameter( strFieldNameUpdate );
 1246  0
             String strFieldName = field.getFieldName(  );
 1247  0
             String strData = request.getParameter( strFieldName );
 1248  
 
 1249  0
             FieldValues fieldValues = new FieldValues(  );
 1250  0
             fieldValues.setFieldName( strFieldName );
 1251  0
             fieldValues.setOldValue( strData );
 1252  0
             fieldValues.setNewValue( strDataUpdate );
 1253  
 
 1254  0
             listFieldValues.add( fieldValues );
 1255  0
         }
 1256  
 
 1257  
         try
 1258  
         {
 1259  0
             DataHome.update( strPoolName, strTableName, listFieldValues,
 1260  0
                 AdminSqlConnectionService.getConnectionService( strPoolName ) );
 1261  
         }
 1262  0
         catch ( AppException e )
 1263  
         {
 1264  0
             UrlItem url = new UrlItem( JSP_URL_MANAGE_DATA_TABLE );
 1265  0
             url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 1266  0
             url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 1267  
 
 1268  0
             Object[] messageArgs = { ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "" };
 1269  
 
 1270  0
             return AdminMessageService.getMessageUrl( request, MESSAGE_SQL_ERROR_IN_QUERY, messageArgs, url.getUrl(  ),
 1271  
                 AdminMessage.TYPE_STOP );
 1272  0
         }
 1273  
 
 1274  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_DATA_TABLE_AFTER_MODIF );
 1275  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 1276  0
         url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 1277  
 
 1278  0
         return url.getUrl(  );
 1279  
     }
 1280  
 
 1281  
     /**
 1282  
      * Delete a data in a table
 1283  
      * @param request HttpServletRequest
 1284  
      * @return the confirmation message to deleting a row
 1285  
      */
 1286  
     public String getDeleteData( HttpServletRequest request )
 1287  
     {
 1288  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1289  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1290  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 1291  0
         String strData = "";
 1292  0
         String strConcatFieldNameAndData = "";
 1293  0
         String strFieldName = "";
 1294  
 
 1295  0
         for ( Field field : listFields )
 1296  
         {
 1297  0
             strFieldName = field.getFieldName(  );
 1298  0
             strData = request.getParameter( field.getFieldName(  ) );
 1299  0
             strConcatFieldNameAndData = strConcatFieldNameAndData + "&" + strFieldName + "=" + strData;
 1300  0
         }
 1301  
 
 1302  0
         strConcatFieldNameAndData = strConcatFieldNameAndData.substring( 1 );
 1303  
 
 1304  0
         String strUrl = JSP_DO_DELETE_DATA + "?" + PARAMETER_POOL_NAME + "=" + strPoolName + "&" +
 1305  
             PARAMETER_TABLE_NAME + "=" + strTableName + "&" + strConcatFieldNameAndData;
 1306  0
         String strMessageKey = PROPERTY_CONFIRM_DELETE_DATA;
 1307  
 
 1308  0
         String strAdminMessageUrl = AdminMessageService.getMessageUrl( request, strMessageKey, strUrl, "",
 1309  
                 AdminMessage.TYPE_CONFIRMATION );
 1310  
 
 1311  0
         return strAdminMessageUrl;
 1312  
     }
 1313  
 
 1314  
     /**
 1315  
      * Process the deleting of a data
 1316  
      * @param request HttpServletRequest
 1317  
      * @return th e manage data page
 1318  
      */
 1319  
     public String doDeleteData( HttpServletRequest request )
 1320  
     {
 1321  0
         String strPoolName = request.getParameter( PARAMETER_POOL_NAME );
 1322  0
         String strTableName = request.getParameter( PARAMETER_TABLE_NAME );
 1323  0
         List<String> listFieldsNames = new ArrayList(  );
 1324  0
         List<String> listConcatFieldNameAndData = new ArrayList(  );
 1325  0
         List<Field> listFields = FieldHome.findAll( strPoolName, strTableName, getPlugin(  ) );
 1326  0
         String strData = "";
 1327  0
         String strConcatFieldNameAndData = "";
 1328  0
         String strFieldName = "";
 1329  
 
 1330  0
         for ( Field field : listFields )
 1331  
         {
 1332  0
             strFieldName = field.getFieldName(  );
 1333  0
             strData = request.getParameter( field.getFieldName(  ) );
 1334  0
             listConcatFieldNameAndData.add( strFieldName + "='" + strData + "'" );
 1335  0
         }
 1336  
 
 1337  0
         DataHome.remove( strPoolName, strTableName, listConcatFieldNameAndData,
 1338  0
             AdminSqlConnectionService.getConnectionService( strPoolName ) );
 1339  
 
 1340  0
         UrlItem url = new UrlItem( JSP_URL_MANAGE_DATA_TABLE );
 1341  0
         url.addParameter( PARAMETER_POOL_NAME, strPoolName );
 1342  0
         url.addParameter( PARAMETER_TABLE_NAME, strTableName );
 1343  
 
 1344  0
         return url.getUrl(  );
 1345  
     }
 1346  
 }