Coverage Report - fr.paris.lutece.plugins.dbpage.business.section.DbPageSectionTable
 
Classes in this File Line Coverage Branch Coverage Complexity
DbPageSectionTable
0 %
0/32
0 %
0/6
1,556
 
 1  
 /*
 2  
  * Copyright (c) 2002-2014, 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.dbpage.business.section;
 35  
 
 36  
 import fr.paris.lutece.plugins.dbpage.business.DbPageHome;
 37  
 import fr.paris.lutece.portal.service.template.AppTemplateService;
 38  
 import fr.paris.lutece.portal.service.util.AppLogService;
 39  
 import fr.paris.lutece.portal.service.util.AppPropertiesService;
 40  
 import fr.paris.lutece.util.html.HtmlTemplate;
 41  
 
 42  
 import java.sql.SQLException;
 43  
 
 44  
 import java.util.ArrayList;
 45  
 import java.util.HashMap;
 46  
 import java.util.List;
 47  
 import java.util.Map;
 48  
 
 49  
 import javax.servlet.http.HttpServletRequest;
 50  
 
 51  
 
 52  
 /**
 53  
  * This class represents business object DbPageSectionTable
 54  
  */
 55  
 public class DbPageSectionTable extends DbPageSection
 56  
 {
 57  
     private static final long serialVersionUID = 3589380186475889829L;
 58  
     private static final String MARK_RESULT_DATASET = "result_dataset";
 59  
     private static final String MARK_SECTION_TITLE = "section_title";
 60  
     private static final String MARK_COLUMN_NAMES = "column_names";
 61  
     private static final String PROPERTY_FILES_PATH = "dbpage.files.path";
 62  
     private static final String TEMPLATE_DEFAULT_TABLE = "skin/plugins/dbpage/default_table.html";
 63  
     private static final String TEMPLATE_CREATION_TABLE = "admin/plugins/dbpage/create_section_table.html";
 64  
     private static final String TEMPLATE_MODIFICATION_TABLE = "admin/plugins/dbpage/modify_section_table.html";
 65  
 
 66  
     /**
 67  
      * Creates a section which of type table
 68  
      * @param strDescType The description of the type of the section
 69  
      */
 70  
     public DbPageSectionTable( String strDescType )
 71  0
     {
 72  0
         this.setIdTypeSignature( serialVersionUID );
 73  0
         this.setDescType( strDescType );
 74  0
     }
 75  
 
 76  
     /**
 77  
      * Returns the Html Section Table form
 78  
      * @return the html code of the html Section Table form
 79  
      * @param request The request
 80  
      * @param listValues the list of id values substitute in the SQL request
 81  
      */
 82  
     public String getHtmlSection( List listValues, HttpServletRequest request )
 83  
     {
 84  0
         HashMap rootModel = new HashMap(  );
 85  
 
 86  0
         rootModel.put( MARK_SECTION_TITLE, getTitle(  ) );
 87  0
         rootModel.put( MARK_COLUMN_NAMES, getTableHeader(  ) );
 88  0
         rootModel.put( MARK_RESULT_DATASET, getTableDataset( getValuatedQuery( listValues ) ) );
 89  
 
 90  0
         if ( getTemplatePath(  ).equals( "" ) )
 91  
         {
 92  0
             HtmlTemplate tTable = AppTemplateService.getTemplate( TEMPLATE_DEFAULT_TABLE, request.getLocale(  ),
 93  
                     rootModel );
 94  
 
 95  0
             return tTable.getHtml(  );
 96  
         }
 97  
         else
 98  
         {
 99  0
             String strFilePath = AppPropertiesService.getProperty( PROPERTY_FILES_PATH );
 100  0
             HtmlTemplate tSelect = AppTemplateService.getTemplate( getTemplatePath(  ), strFilePath,
 101  0
                     ( request == null ) ? null : request.getLocale(  ), rootModel );
 102  
 
 103  0
             return tSelect.getHtml(  );
 104  
         }
 105  
     }
 106  
 
 107  
     /**
 108  
      *  Returns the table headers as a list of string values
 109  
      * @return The table headers
 110  
      */
 111  
     private List<String> getTableHeader(  )
 112  
     {
 113  0
         List<String> listColumnNames = new ArrayList<String>(  );
 114  
 
 115  0
         for ( String strColumnName : getColumnNames(  ) )
 116  
         {
 117  0
             listColumnNames.add( strColumnName );
 118  0
         }
 119  
 
 120  0
         return listColumnNames;
 121  
     }
 122  
 
 123  
     /**
 124  
      * Returns the table dataset
 125  
      * @param strRequest The request
 126  
      * @return A list of list of string values
 127  
      */
 128  
     private List<List<String>> getTableDataset( String strRequest )
 129  
     {
 130  0
         List<List<String>> listDataset = null;
 131  
 
 132  
         try
 133  
         {
 134  0
             listDataset = DbPageHome.selectRows( strRequest, getConnectionService( getDbPool(  ) ) );
 135  
         }
 136  0
         catch ( SQLException e )
 137  
         {
 138  0
             AppLogService.error( e );
 139  0
         }
 140  
 
 141  0
         return listDataset;
 142  
     }
 143  
 
 144  
     /**
 145  
      * The type of the section
 146  
      * @return The type of the section
 147  
      */
 148  
     public long getIdType(  )
 149  
     {
 150  0
         return getIdTypeSignature(  );
 151  
     }
 152  
 
 153  
     /**
 154  
      * The description of the section type
 155  
      * @return The description of the section type
 156  
      */
 157  
     public String getTypeDescription(  )
 158  
     {
 159  0
         return getDescType(  );
 160  
     }
 161  
 
 162  
     /**
 163  
      * The path of the template for creation
 164  
      * @return the path of the creation template
 165  
      */
 166  
     public String getCreationTemplate(  )
 167  
     {
 168  0
         return TEMPLATE_CREATION_TABLE;
 169  
     }
 170  
 
 171  
     /**
 172  
      * The path of the template for modification
 173  
      * @return the path of the modification template
 174  
      */
 175  
     public String getModificationTemplate(  )
 176  
     {
 177  0
         return TEMPLATE_MODIFICATION_TABLE;
 178  
     }
 179  
 
 180  
     /**
 181  
      * Returns a map with additional markers
 182  
      */
 183  
     public Map<String, Object> getMarkMap(  )
 184  
     {
 185  0
         Map map = new HashMap(  );
 186  
 
 187  0
         return map;
 188  
     }
 189  
 }