1 /* 2 * Copyright (c) 2002-2020, 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 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.participatorybudget.business.campaign; 35 36 import java.util.Collection; 37 import java.util.List; 38 import java.util.Map; 39 40 import fr.paris.lutece.portal.service.plugin.Plugin; 41 import fr.paris.lutece.portal.service.plugin.PluginService; 42 import fr.paris.lutece.portal.service.spring.SpringContextService; 43 44 /** 45 * This class provides instances management methods (create, find, ...) for CampaignArea objects 46 */ 47 48 public final class CampaignAreaHome 49 { 50 // Static variable pointed at the DAO instance 51 52 private static ICampaignAreaDAO _dao = SpringContextService.getBean( "participatorybudget.campaignAreaDAO" ); 53 private static Plugin _plugin = PluginService.getPlugin( "participatorybudget" ); 54 55 /** 56 * Private constructor - this class need not be instantiated 57 */ 58 private CampaignAreaHome( ) 59 { 60 } 61 62 /** 63 * Create an instance of the campaignArea class 64 * 65 * @param campaignArea 66 * The instance of the CampaignArea which contains the informations to store 67 * @return The instance of campaignArea which has been created with its primary key. 68 */ 69 public static CampaignArea./../../../../../fr/paris/lutece/plugins/participatorybudget/business/campaign/CampaignArea.html#CampaignArea">CampaignArea create( CampaignArea campaignArea ) 70 { 71 _dao.insert( campaignArea, _plugin ); 72 73 return campaignArea; 74 } 75 76 /** 77 * Update of the campaignAre which is specified in parameter 78 * 79 * @param campaignArea 80 * The instance of the CampaignArea which contains the data to store 81 * @return The instance of the campaignArea which has been updated 82 */ 83 public static CampaignArea./../../../../../fr/paris/lutece/plugins/participatorybudget/business/campaign/CampaignArea.html#CampaignArea">CampaignArea update( CampaignArea campaignArea ) 84 { 85 _dao.store( campaignArea, _plugin ); 86 87 return campaignArea; 88 } 89 90 /** 91 * Change a campaign code 92 * 93 * @param oldCampaignCode 94 * The campaign code to change 95 * @param newCampaignCode 96 * The new campaign code 97 */ 98 public static void changeCampainCode( String oldCampaignCode, String newCampaignCode ) 99 { 100 _dao.changeCampainCode( oldCampaignCode, newCampaignCode, _plugin ); 101 } 102 103 /** 104 * Remove the campaignArea whose identifier is specified in parameter 105 * 106 * @param nKey 107 * The campaignArea Id 108 */ 109 public static void remove( int nKey ) 110 { 111 _dao.delete( nKey, _plugin ); 112 } 113 114 // ///////////////////////////////////////////////////////////////////////// 115 // Finders 116 117 /** 118 * Returns an instance of a campaignArea whose identifier is specified in parameter 119 * 120 * @param nKey 121 * The campaignArea primary key 122 * @return an instance of CampaignArea 123 */ 124 public static CampaignArea findByPrimaryKey( int nKey ) 125 { 126 return _dao.load( nKey, _plugin ); 127 } 128 129 /** 130 * Load the data of all the campaignArea objects and returns them in form of a collection 131 * 132 * @return the collection which contains the data of all the campaignArea objects 133 */ 134 public static Collection<CampaignArea> getCampaignAreasList( ) 135 { 136 return _dao.selectCampaignAreasList( _plugin ); 137 } 138 139 /** 140 * Load the id of all the campaignArea objects and returns them in form of a collection 141 * 142 * @return the collection which contains the id of all the campaignArea objects 143 */ 144 public static Collection<Integer> getIdCampaignAreasList( ) 145 { 146 return _dao.selectIdCampaignAreasList( _plugin ); 147 } 148 149 /** 150 * Load the data of all the campaignArea objects for a campaign and returns them in form of a collection 151 * 152 * @return the collection which contains the data of all the campaignArea objects 153 */ 154 public static Collection<CampaignArea> getCampaignAreasListByCampaign( String codeCampaign ) 155 { 156 return _dao.selectCampaignAreasListByCampaign( codeCampaign, _plugin ); 157 } 158 159 /** 160 * Load the data of all the campaignArea objects mapped from campaign code and returns them in form of a map 161 * 162 * @return the collection which contains the data of all the campaignArea objects 163 */ 164 public static Map<String, List<CampaignArea>> getCampaignAreasMapByCampaign( ) 165 { 166 return _dao.selectCampaignAreasMapByCampaign( _plugin ); 167 } 168 }