1 /* 2 * Copyright (c) 2002-2018, 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.appointment.modules.resource.business; 35 36 import fr.paris.lutece.plugins.appointment.modules.resource.service.AppointmentResourcePlugin; 37 import fr.paris.lutece.portal.service.plugin.Plugin; 38 import fr.paris.lutece.portal.service.plugin.PluginService; 39 import fr.paris.lutece.portal.service.spring.SpringContextService; 40 41 import java.sql.Date; 42 import java.sql.Timestamp; 43 import java.util.List; 44 45 /** 46 * Home for appointment resource 47 */ 48 public final class AppointmentResourceHome 49 { 50 private static IAppointmentResourceDAO _dao = SpringContextService.getBean( IAppointmentResourceDAO.BEAN_NAME ); 51 private static Plugin _plugin = PluginService.getPlugin( AppointmentResourcePlugin.PLUGIN_NAME ); 52 53 /** 54 * Default constructor 55 */ 56 private AppointmentResourceHome( ) 57 { 58 // Do nothing 59 } 60 61 /** 62 * Insert a new appointment resource 63 * 64 * @param resource 65 * The appointment resource to insert 66 */ 67 public static void insert( AppointmentResource resource ) 68 { 69 _dao.insert( resource, _plugin ); 70 } 71 72 /** 73 * Find an appointment resource from its primary key 74 * 75 * @param nIdAppointment 76 * The id of the appointment 77 * @param nIdAppointmentFormResourceType 78 * the id of the appointment form resource type 79 * @return The appointment resource, or null if no appointment resource has the given id 80 */ 81 public static AppointmentResource findByPrimaryKey( int nIdAppointment, int nIdAppointmentFormResourceType ) 82 { 83 return _dao.findByPrimaryKey( nIdAppointment, nIdAppointmentFormResourceType, _plugin ); 84 } 85 86 /** 87 * Find appointment resource associated with a given appointment 88 * 89 * @param nIdAppointment 90 * the id of the appointment 91 * @return The list of appointment resource associated with the given appointment, or an empty list if no appointment resource is associated with the 92 * appointment 93 */ 94 public static List<AppointmentResource> findByIdAppointment( int nIdAppointment ) 95 { 96 return _dao.findByIdAppointment( nIdAppointment, _plugin ); 97 } 98 99 /** 100 * Update an appointment resource 101 * 102 * @param resource 103 * The appointment resource to update 104 */ 105 public static void update( AppointmentResource resource ) 106 { 107 _dao.update( resource, _plugin ); 108 } 109 110 /** 111 * Delete an appointment resource 112 * 113 * @param nIdAppointment 114 * The id of the appointment of the appointment resource 115 * @param nIdAppointmentFormResourceType 116 * The id of the appointment form resource type of the appointment resource 117 */ 118 public static void delete( int nIdAppointment, int nIdAppointmentFormResourceType ) 119 { 120 _dao.delete( nIdAppointment, nIdAppointmentFormResourceType, _plugin ); 121 } 122 123 /** 124 * Delete appointment resource associated with a given appointment 125 * 126 * @param nIdAppointment 127 * The id of the appointment 128 */ 129 public static void deleteByIdAppointment( int nIdAppointment ) 130 { 131 _dao.deleteByIdAppointment( nIdAppointment, _plugin ); 132 } 133 134 /** 135 * Delete appointment resource associated with a given appointment form resource type 136 * 137 * @param nIdAppointmentFormResourceType 138 * The id of the appointment form resource type 139 */ 140 public static void deleteByIdAppointmentFormResourceType( int nIdAppointmentFormResourceType ) 141 { 142 _dao.deleteByIdAppointmentFormResourceType( nIdAppointmentFormResourceType, _plugin ); 143 } 144 145 /** 146 * Check if a resource is available for a given period, or if it has already been associated with an appointment 147 * 148 * @param strIdResource 149 * The id of the resource 150 * @param strResourceTypeName 151 * The type of the resource 152 * @param nStartingTime 153 * The beginning time 154 * @param nEndingTime 155 * the ending time 156 * @return True if the resource is available, false otherwise 157 */ 158 public static boolean isResourceAvailable( String strIdResource, String strResourceTypeName, Timestamp nStartingTime, Timestamp nEndingTime ) 159 { 160 return _dao.isResourceAvailable( strIdResource, strResourceTypeName, nStartingTime, nEndingTime, _plugin ); 161 } 162 163 /** 164 * Get the list of id of appointments a resource is associated to between two given dates 165 * 166 * @param strIdResource 167 * The id of the resource 168 * @param strResourceType 169 * The resource type 170 * @param dateMin 171 * The minimum date 172 * @param dateMax 173 * the maximum date 174 * @return The list of ids of appointments 175 */ 176 public static List<Integer> findIdAppointmentsByResourceAndDate( String strIdResource, String strResourceType, Date dateMin, Date dateMax ) 177 { 178 return _dao.findIdAppointmentsByResourceAndDate( strIdResource, strResourceType, dateMin, dateMax, _plugin ); 179 } 180 }