View Javadoc
1   /*
2    * Copyright (C) 2003-2013 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.commons.search.service;
18  
19  import java.util.Arrays;
20  import java.util.Comparator;
21  import java.util.HashMap;
22  import java.util.List;
23  
24  import org.exoplatform.commons.utils.LazyPageList;
25  import org.exoplatform.commons.utils.ListAccess;
26  import org.exoplatform.portal.application.PortletPreferences;
27  import org.exoplatform.portal.config.DataStorage;
28  import org.exoplatform.portal.config.Query;
29  import org.exoplatform.portal.config.model.Application;
30  import org.exoplatform.portal.config.model.ApplicationState;
31  import org.exoplatform.portal.config.model.ApplicationType;
32  import org.exoplatform.portal.config.model.Container;
33  import org.exoplatform.portal.config.model.Dashboard;
34  import org.exoplatform.portal.config.model.ModelObject;
35  import org.exoplatform.portal.config.model.Page;
36  import org.exoplatform.portal.config.model.PortalConfig;
37  import org.exoplatform.portal.pom.data.ModelChange;
38  import org.exoplatform.services.log.ExoLogger;
39  import org.exoplatform.services.log.Log;
40  import org.mockito.Mockito;
41  import org.picocontainer.Startable;
42  
43  /**
44   * Created by The eXo Platform SAS
45   * Author : Canh Pham Van
46   *          canhpv@exoplatform.com
47   * Mar 29, 2013  
48   */
49  public class MockDataStorage implements DataStorage,Startable {
50  
51    private static final Log      LOG                  = ExoLogger.getLogger(MockDataStorage.class);
52  
53    static private HashMap<String, Page> pageCollections      = new HashMap<String, Page>();
54  
55    public static final String[]  PORTAL_CLASSIC__WIKI = new String[] { "portal::classic::wiki", PortalConfig.PORTAL_TYPE, "classic" };
56  
57    public static final String[]  USER_MARY_WIKI       = new String[] { "user::mary::wiki", PortalConfig.USER_TYPE, "mary" };
58  
59    public static final String[]  GROUP_USER_WIKI      = new String[] { "group::/platform/users::wiki", PortalConfig.GROUP_TYPE,
60        "/platform/users"                             };
61  
62    public static final String[]  SPACE_EXO_WIKI       = new String[] { "group::/space/exo::wiki", PortalConfig.GROUP_TYPE, "/space/exo" };
63  
64    private List<String[]>        pageDatas            = Arrays.asList(new String[][] { PORTAL_CLASSIC__WIKI, USER_MARY_WIKI,
65        GROUP_USER_WIKI, SPACE_EXO_WIKI               });
66  
67    /* (non-Javadoc)
68     * @see org.exoplatform.portal.config.DataStorage#create(org.exoplatform.portal.config.model.PortalConfig)
69     */
70    @Override
71    public void create(PortalConfig config) throws Exception {
72  
73    }
74  
75    /* (non-Javadoc)
76     * @see org.exoplatform.portal.config.DataStorage#save(org.exoplatform.portal.config.model.PortalConfig)
77     */
78    @Override
79    public void save(PortalConfig config) throws Exception {
80  
81    }
82  
83    /* (non-Javadoc)
84     * @see org.exoplatform.portal.config.DataStorage#getPortalConfig(java.lang.String)
85     */
86    @Override
87    public PortalConfig getPortalConfig(String portalName) throws Exception {
88      return null;
89    }
90  
91    /* (non-Javadoc)
92     * @see org.exoplatform.portal.config.DataStorage#getPortalConfig(java.lang.String, java.lang.String)
93     */
94    @Override
95    public PortalConfig getPortalConfig(String ownerType, String portalName) throws Exception {
96      return null;
97    }
98  
99    /* (non-Javadoc)
100    * @see org.exoplatform.portal.config.DataStorage#remove(org.exoplatform.portal.config.model.PortalConfig)
101    */
102   @Override
103   public void remove(PortalConfig config) throws Exception {
104 
105   }
106 
107   /* (non-Javadoc)
108    * @see org.exoplatform.portal.config.DataStorage#getPage(java.lang.String)
109    */
110   @Override
111   public Page getPage(String pageId) throws Exception {
112     return pageCollections.get(pageId);
113   }
114 
115   /* (non-Javadoc)
116    * @see org.exoplatform.portal.config.DataStorage#clonePage(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
117    */
118   @Override
119   public Page clonePage(String pageId, String clonedOwnerType, String clonedOwnerId, String clonedName) {
120     return null;
121   }
122 
123   /* (non-Javadoc)
124    * @see org.exoplatform.portal.config.DataStorage#remove(org.exoplatform.portal.config.model.Page)
125    */
126   @Override
127   public void remove(Page page) {
128 
129   }
130 
131   /* (non-Javadoc)
132    * @see org.exoplatform.portal.config.DataStorage#create(org.exoplatform.portal.config.model.Page)
133    */
134   @Override
135   public void create(Page page) {
136     pageCollections.put(page.getId(), page);
137   }
138 
139   /* (non-Javadoc)
140    * @see org.exoplatform.portal.config.DataStorage#save(org.exoplatform.portal.config.model.Page)
141    */
142   @Override
143   public List<ModelChange> save(Page page) throws Exception {
144     return null;
145   }
146 
147   /* (non-Javadoc)
148    * @see org.exoplatform.portal.config.DataStorage#save(org.exoplatform.portal.application.PortletPreferences)
149    */
150   public void save(PortletPreferences portletPreferences) throws Exception {
151 
152   }
153 
154   /* (non-Javadoc)
155    * @see org.exoplatform.portal.config.DataStorage#getId(org.exoplatform.portal.config.model.ApplicationState)
156    */
157   @Override
158   public <S> String getId(ApplicationState<S> state) throws Exception {
159     return null;
160   }
161 
162   /* (non-Javadoc)
163    * @see org.exoplatform.portal.config.DataStorage#load(org.exoplatform.portal.config.model.ApplicationState, org.exoplatform.portal.config.model.ApplicationType)
164    */
165   @Override
166   public <S> S load(ApplicationState<S> state, ApplicationType<S> type) throws Exception {
167     return null;
168   }
169 
170   /* (non-Javadoc)
171    * @see org.exoplatform.portal.config.DataStorage#save(org.exoplatform.portal.config.model.ApplicationState, java.lang.Object)
172    */
173   @Override
174   public <S> ApplicationState<S> save(ApplicationState<S> state, S preferences) throws Exception {
175     return null;
176   }
177 
178   /* (non-Javadoc)
179    * @see org.exoplatform.portal.config.DataStorage#getPortletPreferences(java.lang.String)
180    */
181   public PortletPreferences getPortletPreferences(String windowID) throws Exception {
182     return null;
183   }
184 
185   /* (non-Javadoc)
186    * @see org.exoplatform.portal.config.DataStorage#find(org.exoplatform.portal.config.Query)
187    */
188   @Override
189   public <T> LazyPageList<T> find(Query<T> q) throws Exception {
190     return null;
191   }
192 
193   /* (non-Javadoc)
194    * @see org.exoplatform.portal.config.DataStorage#find(org.exoplatform.portal.config.Query, java.util.Comparator)
195    */
196   @Override
197   public <T> LazyPageList<T> find(Query<T> q, Comparator<T> sortComparator) throws Exception {
198     return null;
199   }
200 
201   /* (non-Javadoc)
202    * @see org.exoplatform.portal.config.DataStorage#find2(org.exoplatform.portal.config.Query)
203    */
204   @Override
205   public <T> ListAccess<T> find2(Query<T> q) throws Exception {
206     return null;
207   }
208 
209   /* (non-Javadoc)
210    * @see org.exoplatform.portal.config.DataStorage#find2(org.exoplatform.portal.config.Query, java.util.Comparator)
211    */
212   @Override
213   public <T> ListAccess<T> find2(Query<T> q, Comparator<T> sortComparator) throws Exception {
214     return null;
215   }
216 
217   /* (non-Javadoc)
218    * @see org.exoplatform.portal.config.DataStorage#getSharedLayout()
219    */
220   @Override
221   public Container getSharedLayout() throws Exception {
222     return null;
223   }
224 
225   /* (non-Javadoc)
226    * @see org.exoplatform.portal.config.DataStorage#loadDashboard(java.lang.String)
227    */
228   @Override
229   public Dashboard loadDashboard(String dashboardId) throws Exception {
230     return null;
231   }
232 
233   /* (non-Javadoc)
234    * @see org.exoplatform.portal.config.DataStorage#saveDashboard(org.exoplatform.portal.config.model.Dashboard)
235    */
236   @Override
237   public void saveDashboard(Dashboard dashboard) throws Exception {
238 
239   }
240 
241   /* (non-Javadoc)
242    * @see org.exoplatform.portal.config.DataStorage#getAllPortalNames()
243    */
244   @Override
245   public List<String> getAllPortalNames() throws Exception {
246     return Arrays.asList("intranet", "acme");
247   }
248 
249   /* (non-Javadoc)
250    * @see org.exoplatform.portal.config.DataStorage#getAllGroupNames()
251    */
252   @Override
253   public List<String> getAllGroupNames() throws Exception {
254     return null;
255   }
256 
257   /* (non-Javadoc)
258    * @see org.exoplatform.portal.config.DataStorage#adapt(org.exoplatform.portal.config.model.ModelObject, java.lang.Class)
259    */
260   @Override
261   public <A> A adapt(ModelObject modelObject, Class<A> type) {
262     return null;
263   }
264 
265   /* (non-Javadoc)
266    * @see org.exoplatform.portal.config.DataStorage#adapt(org.exoplatform.portal.config.model.ModelObject, java.lang.Class, boolean)
267    */
268   @Override
269   public <A> A adapt(ModelObject modelObject, Class<A> type, boolean create) {
270     return null;
271   }
272 
273   /* (non-Javadoc)
274    * @see org.picocontainer.Startable#start()
275    */
276   @Override
277   public void start() {
278     try {
279       for (String[] item : pageDatas) {
280         Page page = Mockito.mock(Page.class);
281         Mockito.when(page.getId()).thenReturn(item[0]);
282         Mockito.when(page.getOwnerType()).thenReturn(item[1]);
283         Mockito.when(page.getOwnerId()).thenReturn(item[2]);
284         create(page);
285       }
286     } catch (Exception e) {
287       LOG.warn("Could not create default page data for test", e);
288     }
289   }
290 
291   /* (non-Javadoc)
292    * @see org.picocontainer.Startable#stop()
293    */
294   @Override
295   public void stop() {
296   }
297 
298   /* (non-Javadoc)
299    * @see org.exoplatform.portal.config.DataStorage#save()
300    */
301   @Override
302   public void save() throws Exception {
303     // TODO Auto-generated method stub
304     
305   }
306 
307   @Override
308   public String[] getSiteInfo(String applicationStorageId) throws Exception {
309     // TODO Auto-generated method stub
310     return null;
311   }
312 
313   @Override
314   public <S> Application<S> getApplicationModel(String applicationStorageId)
315       throws Exception {
316     // TODO Auto-generated method stub
317     return null;
318   }
319 
320 }