View Javadoc
1   /*
2    * Copyright (c) 2002-2024, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the 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.grubusiness.business.mock;
35  
36  import java.util.ArrayList;
37  import java.util.Collection;
38  import java.util.HashMap;
39  import java.util.Map;
40  
41  import fr.paris.lutece.plugins.grubusiness.business.demand.Demand;
42  import fr.paris.lutece.plugins.grubusiness.business.demand.IDemandDAO;
43  import fr.paris.lutece.plugins.grubusiness.business.notification.NotificationFilter;
44  
45  import java.util.List;
46  
47  /**
48   * This class is a mock implementation of {@link IDemandDAO}
49   */
50  public class MockDemandDAO implements IDemandDAO
51  {
52      private final Map<String, Demand> _mapMockDemand = new HashMap<String, Demand>( );
53  
54      /**
55       * {@inheritDoc}
56       */
57      @Override
58      public Collection<Demand> loadByCustomerId( String strCustomerId )
59      {
60          Collection<Demand> listResult = new ArrayList<Demand>( );
61          for ( Demand demand : _mapMockDemand.values( ) )
62          {
63              if ( demand.getCustomer( ) != null && demand.getCustomer( ).getId( ).equals( strCustomerId ) )
64              {
65                  listResult.add( demand );
66              }
67          }
68          return listResult;
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      @Override
75      public Collection<Demand> loadByReference( String strReference )
76      {
77          Collection<Demand> listResult = new ArrayList<Demand>( );
78          for ( Demand demand : _mapMockDemand.values( ) )
79          {
80              if ( demand.getReference( ).equals( strReference ) )
81              {
82                  listResult.add( demand );
83              }
84          }
85          return listResult;
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public Demand load( int nId )
93      {
94         //TODO:
95          
96          return null;
97      }
98  
99      
100     /**
101      * {@inheritDoc}
102      */
103     @Override
104     public Demand loadByDemandIdAndTypeId( String strDemandId, String strDemandTypeId )
105     {
106         return _mapMockDemand.get( strDemandTypeId + "|" + strDemandId );
107     }
108 
109     /**
110      * {@inheritDoc}
111      */
112     @Override
113     public Demand insert( Demand demand )
114     {
115         _mapMockDemand.put( demand.getTypeId( ) + "|" + demand.getId( ), demand );
116         return demand;
117     }
118 
119     /**
120      * {@inheritDoc}
121      */
122     @Override
123     public Demand store( Demand demand )
124     {
125         _mapMockDemand.put( demand.getTypeId( ) + "|" + demand.getId( ), demand );
126         return demand;
127     }
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public void delete( String strDemandId, String strDemandTypeId )
134     {
135         _mapMockDemand.remove( strDemandTypeId + "|" + strDemandId );
136     }
137 
138     /**
139      * {@inheritDoc}
140      */
141     @Override
142     public List<String> loadAllIds( )
143     {
144         return new ArrayList<>( _mapMockDemand.keySet( ) );
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     @Override
151     public Demand loadByDemandId( String strId )
152     {
153         return null;
154     }
155 
156     @Override
157     public Collection<Demand> loadByFilter( NotificationFilter filter )
158     {
159         return _mapMockDemand.values( );
160     }
161 
162     @Override
163     public List<Integer> loadIdsByFilter( NotificationFilter filter )
164     {
165         // TODO Auto-generated method stub
166         return null;
167     }
168 
169     @Override
170     public List<Demand> loadByIds( List<Integer> listIds )
171     {
172         List<Demand> listDemands = new ArrayList<>( );
173         listDemands.addAll( _mapMockDemand.values( ) );
174 
175         return listDemands;
176     }
177 
178     @Override
179     public List<Integer> loadIdsByCustomerIdAndIdDemandType( String strCustomerId, String strNotificationType, String strIdDemandType )
180     {
181         return null;
182     }
183 
184     @Override
185     public List<Integer> loadIdsByStatus( String strCustomerId, List<String> listStatus, String strNotificationType, String strIdDemandType )
186     {
187         return null;
188     }
189 
190 }