View Javadoc

1   package org.gnomekr.potron.service;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.gnomekr.potron.data.Project;
7   import org.gnomekr.potron.data.Template;
8   import org.gnomekr.potron.data.Translation;
9   import org.gnomekr.potron.data.User;
10  import org.gnomekr.potron.statistics.StatusOverview;
11  import org.gnomekr.potron.statistics.TranslationStatus;
12  import org.gnomekr.potron.statistics.TranslatorStatus;
13  import org.gnomekr.potron.statistics.UserStatus;
14  import org.hibernate.Hibernate;
15  import org.hibernate.Query;
16  import org.hibernate.SQLQuery;
17  import org.hibernate.Session;
18  import org.springframework.orm.hibernate3.SessionFactoryUtils;
19  import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
20  
21  /***
22   * StatisticsManager.java
23   * @author Xavier Cho
24   * @version $Revision 1.1 $ $Date: 2005/09/11 05:49:44 $
25   * FIXME Finish the implementation.
26   */
27  public class StatisticsManager extends HibernateDaoSupport implements
28          IStatisticsManager {
29  
30      /***
31       * @see org.gnomekr.potron.service.IStatisticsManager#getTopTranslators(int)
32       */
33      public List<TranslatorStatus> getTopTranslators(int count) {
34          List<TranslatorStatus> topTranslators = new ArrayList<TranslatorStatus>(
35                  count);
36  
37          Session session = SessionFactoryUtils.getSession(
38                  getSessionFactory(),
39                  false);
40  
41          SQLQuery query = session
42                  .createSQLQuery("select count(e.trans_entry_id) as cnt, {user.*} from POTRON_TRANS_ENTRY as e, POTRON_USER user where e.translator = user.user_name and e.fuzzy = 0 group by user.user_name order by cnt desc");
43  
44          query.addScalar("cnt", Hibernate.LONG);
45          query.addEntity("user", User.class);
46  
47          query.setMaxResults(count);
48  
49          for (Object o : query.list()) {
50              Object[] values = (Object[]) o;
51  
52              long translatedEntries = (Long) values[0];
53              User user = (User) values[1];
54  
55              topTranslators.add(new TranslatorStatus(user, translatedEntries));
56          }
57  
58          return topTranslators;
59      }
60  
61      /* (non-Javadoc)
62       * @see org.gnomekr.potron.service.IStatisticsManager#getFastestTranslators(int, int)
63       */
64      public List<User> getFastestTranslators(int count, int minimumEntries) {
65          // TODO Auto-generated method stub
66          return null;
67      }
68  
69      /* (non-Javadoc)
70       * @see org.gnomekr.potron.service.IStatisticsManager#getSlowestTranslators(int, int)
71       */
72      public List<User> getSlowestTranslators(int count, int minimumEntries) {
73          // TODO Auto-generated method stub
74          return null;
75      }
76  
77      /* (non-Javadoc)
78       * @see org.gnomekr.potron.service.IStatisticsManager#getMostCompleteProjects(int)
79       */
80      public List<Project> getMostCompleteProjects(int count) {
81          // TODO Auto-generated method stub
82          return null;
83      }
84  
85      /* (non-Javadoc)
86       * @see org.gnomekr.potron.service.IStatisticsManager#getLeastCompleteProjects(int)
87       */
88      public List<Project> getLeastCompleteProjects(int count) {
89          // TODO Auto-generated method stub
90          return null;
91      }
92  
93      /* (non-Javadoc)
94       * @see org.gnomekr.potron.service.IStatisticsManager#getMostWorkedOnProjects(int)
95       */
96      public List<Project> getMostWorkedOnProjects(int count) {
97          // TODO Auto-generated method stub
98          return null;
99      }
100 
101     /* (non-Javadoc)
102      * @see org.gnomekr.potron.service.IStatisticsManager#getLeastWorkedOnProjects(int)
103      */
104     public List<Project> getLeastWorkedOnProjects(int count) {
105         // TODO Auto-generated method stub
106         return null;
107     }
108 
109     /* (non-Javadoc)
110      * @see org.gnomekr.potron.service.IStatisticsManager#getMostCompleteTemplates(int, java.lang.String)
111      */
112     public List<Template> getMostCompleteTemplates(int count, String projectId) {
113         // TODO Auto-generated method stub
114         return null;
115     }
116 
117     /* (non-Javadoc)
118      * @see org.gnomekr.potron.service.IStatisticsManager#getLeastCompleteTemplates(int, java.lang.String)
119      */
120     public List<Template> getLeastCompleteTemplates(int count, String projectId) {
121         // TODO Auto-generated method stub
122         return null;
123     }
124 
125     /* (non-Javadoc)
126      * @see org.gnomekr.potron.service.IStatisticsManager#getMostWorkedOnTemplates(int, java.lang.String)
127      */
128     public List<Template> getMostWorkedOnTemplates(int count, String projectId) {
129         // TODO Auto-generated method stub
130         return null;
131     }
132 
133     /* (non-Javadoc)
134      * @see org.gnomekr.potron.service.IStatisticsManager#getLeastWorkedOnTemplates(int, java.lang.String)
135      */
136     public List<Template> getLeastWorkedOnTemplates(int count, String projectId) {
137         // TODO Auto-generated method stub
138         return null;
139     }
140 
141     /* (non-Javadoc)
142      * @see org.gnomekr.potron.service.IStatisticsManager#getMostCompleteTranslations(int, java.lang.String)
143      */
144     public List<Translation> getMostCompleteTranslations(
145             int count,
146             String projectId) {
147         // TODO Auto-generated method stub
148         return null;
149     }
150 
151     /* (non-Javadoc)
152      * @see org.gnomekr.potron.service.IStatisticsManager#getLeastCompleteTranslations(int, java.lang.String)
153      */
154     public List<Translation> getLeastCompleteTranslations(
155             int count,
156             String projectId) {
157         // TODO Auto-generated method stub
158         return null;
159     }
160 
161     /* (non-Javadoc)
162      * @see org.gnomekr.potron.service.IStatisticsManager#getMostWorkedOnTranslations(int, java.lang.String)
163      */
164     public List<Translation> getMostWorkedOnTranslations(
165             int count,
166             String projectId) {
167         // TODO Auto-generated method stub
168         return null;
169     }
170 
171     /* (non-Javadoc)
172      * @see org.gnomekr.potron.service.IStatisticsManager#getLeastWorkedOnTranslations(int, java.lang.String)
173      */
174     public List<Translation> getLeastWorkedOnTranslations(
175             int count,
176             String projectId) {
177         // TODO Auto-generated method stub
178         return null;
179     }
180 
181     /***
182      * @see org.gnomekr.potron.service.IStatisticsManager#getProjectStatus(java.lang.String)
183      */
184     public TranslationStatus getProjectStatus(String projectId) {
185         Session session = SessionFactoryUtils.getSession(
186                 getSessionFactory(),
187                 false);
188 
189         long entries;
190         long translatedEntries;
191         long checkedOutEntries;
192         long fuzzyEntries;
193         long workingTimeInMillis = 0;
194 
195         Query query = session
196                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.project.id = :id");
197         query.setString("id", projectId);
198         entries = (Integer) query.iterate().next();
199 
200         query = session
201                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.project.id = :id and e.translatedString is not null and e.fuzzy = :fuzzy and e.lock.owner is null");
202         query.setString("id", projectId);
203         query.setBoolean("fuzzy", false);
204         translatedEntries = (Integer) query.iterate().next();
205 
206         query = session
207                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.project.id = :id and e.lock.owner is not null");
208         query.setString("id", projectId);
209         checkedOutEntries = (Integer) query.iterate().next();
210 
211         query = session
212                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.project.id = :id and e.fuzzy = :fuzzy and e.lock.owner is null");
213         query.setString("id", projectId);
214         query.setBoolean("fuzzy", true);
215 
216         fuzzyEntries = (Integer) query.iterate().next();
217 
218         TranslationStatus status = new TranslationStatus(entries,
219                 checkedOutEntries, translatedEntries, fuzzyEntries,
220                 workingTimeInMillis);
221         return status;
222     }
223 
224     /***
225      * @see org.gnomekr.potron.service.IStatisticsManager#getTemplateStatus(long)
226      */
227     public TranslationStatus getTemplateStatus(long templateId) {
228         long entries;
229         long translatedEntries;
230         long checkedOutEntries;
231         long fuzzyEntries;
232         long workingTimeInMillis = 0;
233         Session session = SessionFactoryUtils.getSession(
234                 getSessionFactory(),
235                 false);
236 
237         Query query = session
238                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.id = :id");
239         query.setLong("id", templateId);
240         entries = (Integer) query.iterate().next();
241 
242         query = session
243                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.id = :id and e.translatedString is not null and e.fuzzy = :fuzzy and e.lock.owner is null");
244         query.setLong("id", templateId);
245         query.setBoolean("fuzzy", false);
246         translatedEntries = (Integer) query.iterate().next();
247 
248         query = session
249                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.id = :id and e.lock.owner is not null");
250         query.setLong("id", templateId);
251         checkedOutEntries = (Integer) query.iterate().next();
252 
253         query = session
254                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.template.id = :id and e.fuzzy = :fuzzy and e.lock.owner is null");
255         query.setLong("id", templateId);
256         query.setBoolean("fuzzy", true);
257 
258         fuzzyEntries = (Integer) query.iterate().next();
259 
260         TranslationStatus status = new TranslationStatus(entries,
261                 checkedOutEntries, translatedEntries, fuzzyEntries,
262                 workingTimeInMillis);
263         return status;
264     }
265 
266     /***
267      * @see org.gnomekr.potron.service.IStatisticsManager#getStatusOverview()
268      * TODO Reformat the source and externalize the SQL query string.
269      */
270     public StatusOverview getStatusOverview() {
271         Session session = SessionFactoryUtils.getSession(
272                 getSessionFactory(),
273                 false);
274 
275         long users;
276         long projects;
277         long entries;
278         long translatedEntries;
279         long checkedOutEntries;
280         long fuzzyEntries;
281         long workingTimeInMillis = 0;
282 
283         Query query = session
284                 .createQuery("select count(u.userName) from User u");
285         users = (Integer) query.iterate().next();
286 
287         query = session.createQuery("select count(p.id) from Project p");
288         projects = (Integer) query.iterate().next();
289 
290         query = session
291                 .createQuery("select count(e.id) from TranslatedEntry as e");
292         entries = (Integer) query.iterate().next();
293 
294         query = session
295                 .createQuery("select count(e.id) from TranslatedEntry as e where e.translatedString is not null and e.fuzzy = :fuzzy and e.lock.owner is null");
296         query.setBoolean("fuzzy", false);
297         translatedEntries = (Integer) query.iterate().next();
298 
299         query = session
300                 .createQuery("select count(e.id) from TranslatedEntry as e where e.lock.owner.userName is not null");
301         checkedOutEntries = (Integer) query.iterate().next();
302 
303         query = session
304                 .createQuery("select count(e.id) from TranslatedEntry as e where e.fuzzy = :fuzzy and e.lock.owner is null");
305         query.setBoolean("fuzzy", true);
306 
307         fuzzyEntries = (Integer) query.iterate().next();
308 
309         StatusOverview status = new StatusOverview(users, projects, entries,
310                 checkedOutEntries, translatedEntries, fuzzyEntries,
311                 workingTimeInMillis);
312         return status;
313     }
314 
315     /***
316      * @see org.gnomekr.potron.service.IStatisticsManager#getTranslationStatus(long)
317      * TODO Reformat the source and externalize the SQL query string.
318      */
319     public TranslationStatus getTranslationStatus(long translationId) {
320         Session session = SessionFactoryUtils.getSession(
321                 getSessionFactory(),
322                 false);
323 
324         long entries;
325         long translatedEntries;
326         long checkedOutEntries;
327         long fuzzyEntries;
328         long workingTimeInMillis = 0;
329 
330         Query query = session
331                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.id = :id");
332         query.setLong("id", translationId);
333         entries = (Integer) query.iterate().next();
334 
335         query = session
336                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.id = :id and e.translatedString is not null and e.fuzzy = :fuzzy and e.lock.owner is null");
337         query.setLong("id", translationId);
338         query.setBoolean("fuzzy", false);
339         translatedEntries = (Integer) query.iterate().next();
340 
341         query = session
342                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.id = :id and e.lock.owner is not null");
343         query.setLong("id", translationId);
344         checkedOutEntries = (Integer) query.iterate().next();
345 
346         query = session
347                 .createQuery("select count(e.id) from Translation as t join t.entries as e where t.id = :id and e.translatedString is not null and e.fuzzy = :fuzzy and e.lock.owner is null");
348         query.setLong("id", translationId);
349         query.setBoolean("fuzzy", true);
350 
351         fuzzyEntries = (Integer) query.iterate().next();
352 
353         TranslationStatus status = new TranslationStatus(entries,
354                 checkedOutEntries, translatedEntries, fuzzyEntries,
355                 workingTimeInMillis);
356         return status;
357     }
358 
359     /* (non-Javadoc)
360      * @see org.gnomekr.potron.service.IStatisticsManager#getUserStatus(java.lang.String)
361      */
362     public UserStatus getUserStatus(String userName) {
363         // TODO Auto-generated method stub
364         return null;
365     }
366 }