@@ -33,12 +33,12 @@ public class FirestoreServices {
3333 */
3434 @ CacheInvalidateAll (cacheName = "members-cache" )
3535 public void createMember (ZenikaMember zMember ) throws DatabaseException {
36- createDocument (zMember , FirestoreCollections .MEMBERS .value , zMember .getId ());
36+ createDocument (ZenikaMemberMapper . mapZenikaMemberToMap ( zMember ) , FirestoreCollections .MEMBERS .getValue () , zMember .getId ());
3737 }
3838
3939 @ CacheResult (cacheName = "members-cache" )
4040 public List <ZenikaMember > getAllMembers () throws DatabaseException {
41- CollectionReference zmembers = firestore .collection (FirestoreCollections .MEMBERS .value );
41+ CollectionReference zmembers = firestore .collection (FirestoreCollections .MEMBERS .getValue () );
4242 ApiFuture <QuerySnapshot > querySnapshot = zmembers .get ();
4343 try {
4444 return querySnapshot .get ().getDocuments ().stream ()
@@ -58,7 +58,7 @@ public List<ZenikaMember> getAllMembers() throws DatabaseException {
5858 */
5959 @ CacheInvalidateAll (cacheName = "contributions-cache" )
6060 public void deleteStatsForAGitHubAccountForAYear (String githubMember , int year ) throws DatabaseException {
61- CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
61+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue () );
6262 Query query = zStats .whereEqualTo ("githubHandle" , githubMember ).whereEqualTo ("year" , String .valueOf (year ));
6363 ApiFuture <QuerySnapshot > querySnapshot = query .get ();
6464 try {
@@ -93,7 +93,7 @@ public void saveStats(StatsContribution statsContribution) throws DatabaseExcept
9393 statsContribution .getIdZenikaMember (),
9494 statsContribution .getSource ());
9595
96- firestore .collection (FirestoreCollections .STATS .value )
96+ firestore .collection (FirestoreCollections .STATS .getValue () )
9797 .document (documentId )
9898 .set (statsContribution )
9999 .get ();
@@ -111,7 +111,7 @@ public void saveStats(StatsContribution statsContribution) throws DatabaseExcept
111111 */
112112 @ CacheInvalidateAll (cacheName = "contributions-cache" )
113113 public void deleteStatsBySourceForYear (int year , String source ) throws DatabaseException {
114- CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
114+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue () );
115115 Query query = zStats .whereEqualTo ("year" , String .valueOf (year )).whereEqualTo ("source" , source );
116116 deleteDocumentsByQuery (query );
117117 }
@@ -147,7 +147,7 @@ private void deleteDocumentsByQuery(Query query) throws DatabaseException {
147147 */
148148 @ CacheInvalidateAll (cacheName = "projects-cache" )
149149 public void createProject (Project project ) throws DatabaseException {
150- createDocument (project , FirestoreCollections .PROJECTS .value , project .getId ());
150+ createDocument (project , FirestoreCollections .PROJECTS .getValue () , project .getId ());
151151 }
152152
153153 /**
@@ -157,7 +157,7 @@ public void createProject(Project project) throws DatabaseException {
157157 */
158158 @ CacheResult (cacheName = "projects-cache" )
159159 public List <Project > getAllProjects () throws DatabaseException {
160- CollectionReference zProjects = firestore .collection (FirestoreCollections .PROJECTS .value );
160+ CollectionReference zProjects = firestore .collection (FirestoreCollections .PROJECTS .getValue () );
161161 ApiFuture <QuerySnapshot > querySnapshot = zProjects .get ();
162162 try {
163163 return querySnapshot .get ().getDocuments ().stream ()
@@ -209,7 +209,7 @@ public void deleteAllGitHubOrganizationProjects() throws DatabaseException {
209209 }
210210
211211 private void deleteProjectsBySource (String source ) throws DatabaseException {
212- CollectionReference zProjects = firestore .collection (FirestoreCollections .PROJECTS .value );
212+ CollectionReference zProjects = firestore .collection (FirestoreCollections .PROJECTS .getValue () );
213213 Query query = zProjects .whereEqualTo ("source" , source );
214214 ApiFuture <QuerySnapshot > querySnapshot = query .get ();
215215 try {
@@ -246,7 +246,7 @@ public void deleteAllMembers() throws DatabaseException {
246246 @ CacheInvalidateAll (cacheName = "members-cache" )
247247 public void deleteMember (String memberId ) throws DatabaseException {
248248 try {
249- firestore .collection (FirestoreCollections .MEMBERS .value )
249+ firestore .collection (FirestoreCollections .MEMBERS .getValue () )
250250 .document (memberId )
251251 .delete ()
252252 .get ();
@@ -280,10 +280,10 @@ public <T> void createDocument(T document, String collectionPath, String documen
280280 * @throws DatabaseException exception
281281 */
282282 public <T > void deleteAllDocuments (FirestoreCollections collectionType ) throws DatabaseException {
283- if (collectionType .value == null ) {
283+ if (collectionType .getValue () == null ) {
284284 throw new IllegalArgumentException ("Collection name cannot be null" );
285285 }
286- CollectionReference collection = firestore .collection (collectionType .value );
286+ CollectionReference collection = firestore .collection (collectionType .getValue () );
287287 ApiFuture <QuerySnapshot > querySnapshot = collection .get ();
288288 try {
289289 List <QueryDocumentSnapshot > documents = querySnapshot .get ().getDocuments ();
@@ -302,7 +302,7 @@ public <T> void deleteAllDocuments(FirestoreCollections collectionType) throws D
302302
303303 @ CacheResult (cacheName = "contributions-cache" )
304304 public List <StatsContribution > getStatsForYear (int year ) throws DatabaseException {
305- CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
305+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue () );
306306 Query query = zStats .whereEqualTo ("year" , String .valueOf (year ));
307307 ApiFuture <QuerySnapshot > querySnapshot = query .get ();
308308 try {
@@ -317,7 +317,7 @@ public List<StatsContribution> getStatsForYear(int year) throws DatabaseExceptio
317317 @ CacheResult (cacheName = "contributions-cache" )
318318 public List <StatsContribution > getContributionsForAMemberOrderByYear (String memberId ) throws DatabaseException {
319319 List <StatsContribution > stats = null ;
320- CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
320+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue () );
321321 Query query = zStats .whereEqualTo ("githubHandle" , memberId );
322322 ApiFuture <QuerySnapshot > querySnapshot = query .get ();
323323 try {
@@ -337,7 +337,7 @@ public List<StatsContribution> getContributionsForAMemberOrderByYear(String memb
337337 @ CacheResult (cacheName = "contributions-cache" )
338338 public List <StatsContribution > getContributionsForZenikaMember (String zenikaMemberId ) throws DatabaseException {
339339 List <StatsContribution > stats = null ;
340- CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
340+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue () );
341341 Query query = zStats .whereEqualTo ("idZenikaMember" , zenikaMemberId );
342342 ApiFuture <QuerySnapshot > querySnapshot = query .get ();
343343 try {
@@ -357,7 +357,7 @@ public List<StatsContribution> getContributionsForZenikaMember(String zenikaMemb
357357 public List <StatsContribution > getContributionsForAYearAndMonthOrderByMonth (int year , String month )
358358 throws DatabaseException {
359359 List <StatsContribution > stats = null ;
360- CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
360+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue () );
361361 Query query = zStats .whereEqualTo ("year" , String .valueOf (year )).whereEqualTo ("month" , month );
362362 ApiFuture <QuerySnapshot > querySnapshot = query .get ();
363363 try {
@@ -374,7 +374,7 @@ public List<StatsContribution> getContributionsForAYearAndMonthOrderByMonth(int
374374
375375 @ CacheResult (cacheName = "contributions-cache" )
376376 public List <StatsContribution > getAllStats () throws DatabaseException {
377- CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .value );
377+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue () );
378378 ApiFuture <QuerySnapshot > querySnapshot = zStats .get ();
379379 try {
380380 return querySnapshot .get ().getDocuments ().stream ()
@@ -384,4 +384,26 @@ public List<StatsContribution> getAllStats() throws DatabaseException {
384384 throw new DatabaseException (exception );
385385 }
386386 }
387+
388+ /**
389+ * Check if a member has any statistics records for a specific year and source.
390+ *
391+ * @param memberId the internal Zenika member ID.
392+ * @param year the year to check.
393+ * @param source the source (GitHub or GitLab).
394+ * @return true if at least one record exists.
395+ * @throws DatabaseException if the database query fails.
396+ */
397+ public boolean hasStatsForMemberAndYear (String memberId , int year , String source ) throws DatabaseException {
398+ CollectionReference zStats = firestore .collection (FirestoreCollections .STATS .getValue ());
399+ Query query = zStats .whereEqualTo ("idZenikaMember" , memberId )
400+ .whereEqualTo ("year" , String .valueOf (year ))
401+ .whereEqualTo ("source" , source )
402+ .limit (1 );
403+ try {
404+ return !query .get ().get ().getDocuments ().isEmpty ();
405+ } catch (InterruptedException | ExecutionException e ) {
406+ throw new DatabaseException (e );
407+ }
408+ }
387409}
0 commit comments