]> source.dussan.org Git - gitblit.git/commitdiff
Implementation of the getTickets capability of recovering all tickets from a nullable...
authorHybris95 <hybris_95@hotmail.com>
Wed, 16 Apr 2014 14:42:18 +0000 (16:42 +0200)
committerBUISSON Christian <cbuisson@deltadore.com>
Fri, 18 Apr 2014 08:43:24 +0000 (10:43 +0200)
src/main/java/com/gitblit/tickets/BranchTicketService.java
src/main/java/com/gitblit/tickets/FileTicketService.java
src/main/java/com/gitblit/tickets/RedisTicketService.java

index 284b1be19ee0eee2de705699cc051f2fb8ce31e1..7d6926dff8f4feae8c6b8ddea6beb79bffb6a548 100644 (file)
@@ -436,64 +436,84 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
        @Override
        public List<TicketModel> getTickets(RepositoryModel repository, TicketFilter filter) {
                List<TicketModel> list = new ArrayList<TicketModel>();
-
-               Repository db = repositoryManager.getRepository(repository.name);
-               try {
-                       RefModel ticketsBranch = getTicketsBranch(db);
-                       if (ticketsBranch == null) {
-                               return list;
+               List<Repository> databases = new ArrayList<Repository>();
+               List<RepositoryModel> models = new ArrayList<RepositoryModel>();
+               
+               if(repository == null)
+               {
+                       List<String> allRepo = repositoryManager.getRepositoryList();
+                       for(int i = 0; i < allRepo.size(); i++)
+                       {
+                               databases.add(repositoryManager.getRepository(allRepo.get(i)));
+                               models.add(repositoryManager.getRepositoryModel(allRepo.get(i)));
                        }
+               }
+               else
+               {
+                       databases.add(repositoryManager.getRepository(repository.name));
+                       models.add(repository);
+               }
 
-                       // Collect the set of all json files
-                       List<PathModel> paths = JGitUtils.getDocuments(db, Arrays.asList("json"), BRANCH);
-
-                       // Deserialize each ticket and optionally filter out unwanted tickets
-                       for (PathModel path : paths) {
-                               String name = path.name.substring(path.name.lastIndexOf('/') + 1);
-                               if (!JOURNAL.equals(name)) {
-                                       continue;
-                               }
-                               String json = readTicketsFile(db, path.path);
-                               if (StringUtils.isEmpty(json)) {
-                                       // journal was touched but no changes were written
-                                       continue;
+               for(int i = 0; i < databases.size(); i++)
+               {
+                       Repository db = databases.get(i);
+                       try {
+                               RefModel ticketsBranch = getTicketsBranch(db);
+                               if (ticketsBranch == null) {
+                                       return list;
                                }
-                               try {
-                                       // Reconstruct ticketId from the path
-                                       // id/26/326/journal.json
-                                       String tid = path.path.split("/")[2];
-                                       long ticketId = Long.parseLong(tid);
-                                       List<Change> changes = TicketSerializer.deserializeJournal(json);
-                                       if (ArrayUtils.isEmpty(changes)) {
-                                               log.warn("Empty journal for {}:{}", repository, path.path);
+       
+                               // Collect the set of all json files
+                               List<PathModel> paths = JGitUtils.getDocuments(db, Arrays.asList("json"), BRANCH);
+       
+                               // Deserialize each ticket and optionally filter out unwanted tickets
+                               for (PathModel path : paths) {
+                                       String name = path.name.substring(path.name.lastIndexOf('/') + 1);
+                                       if (!JOURNAL.equals(name)) {
+                                               continue;
+                                       }
+                                       String json = readTicketsFile(db, path.path);
+                                       if (StringUtils.isEmpty(json)) {
+                                               // journal was touched but no changes were written
                                                continue;
                                        }
-                                       TicketModel ticket = TicketModel.buildTicket(changes);
-                                       ticket.project = repository.projectPath;
-                                       ticket.repository = repository.name;
-                                       ticket.number = ticketId;
-
-                                       // add the ticket, conditionally, to the list
-                                       if (filter == null) {
-                                               list.add(ticket);
-                                       } else {
-                                               if (filter.accept(ticket)) {
+                                       try {
+                                               // Reconstruct ticketId from the path
+                                               // id/26/326/journal.json
+                                               String tid = path.path.split("/")[2];
+                                               long ticketId = Long.parseLong(tid);
+                                               List<Change> changes = TicketSerializer.deserializeJournal(json);
+                                               if (ArrayUtils.isEmpty(changes)) {
+                                                       log.warn("Empty journal for {}:{}", models.get(i), path.path);
+                                                       continue;
+                                               }
+                                               TicketModel ticket = TicketModel.buildTicket(changes);
+                                               ticket.project = models.get(i).projectPath;
+                                               ticket.repository = models.get(i).name;
+                                               ticket.number = ticketId;
+       
+                                               // add the ticket, conditionally, to the list
+                                               if (filter == null) {
                                                        list.add(ticket);
+                                               } else {
+                                                       if (filter.accept(ticket)) {
+                                                               list.add(ticket);
+                                                       }
                                                }
+                                       } catch (Exception e) {
+                                               log.error("failed to deserialize {}/{}\n{}",
+                                                               new Object [] { repository, path.path, e.getMessage()});
+                                               log.error(null, e);
                                        }
-                               } catch (Exception e) {
-                                       log.error("failed to deserialize {}/{}\n{}",
-                                                       new Object [] { repository, path.path, e.getMessage()});
-                                       log.error(null, e);
                                }
+                       } finally {
+                               db.close();
                        }
-
-                       // sort the tickets by creation
-                       Collections.sort(list);
-                       return list;
-               } finally {
-                       db.close();
                }
+
+               // sort the tickets by creation
+               Collections.sort(list);
+               return list;
        }
 
        /**
index ea5d065f98059138fae30eb9d2b5aaca0cb060aa..7fd9675f1bc58a05f323786dd29d2bbc3bc9e2c0 100644 (file)
@@ -228,6 +228,7 @@ public class FileTicketService extends ITicketService {
                for(int i = 0; i < databases.size(); i++)
                {
                        Repository db = databases.get(i);
+                       RepositoryModel model = models.get(i);
                        try {
                                // Collect the set of all json files
                                File dir = new File(db.getDirectory(), TICKETS_PATH);
@@ -253,12 +254,12 @@ public class FileTicketService extends ITicketService {
                                                long ticketId = Long.parseLong(tid);
                                                List<Change> changes = TicketSerializer.deserializeJournal(json);
                                                if (ArrayUtils.isEmpty(changes)) {
-                                                       log.warn("Empty journal for {}:{}", models.get(i), journal);
+                                                       log.warn("Empty journal for {}:{}", model, journal);
                                                        continue;
                                                }
                                                TicketModel ticket = TicketModel.buildTicket(changes);
-                                               ticket.project = models.get(i).projectPath;
-                                               ticket.repository = models.get(i).name;
+                                               ticket.project = model.projectPath;
+                                               ticket.repository = model.name;
                                                ticket.number = ticketId;
        
                                                // add the ticket, conditionally, to the list
@@ -271,7 +272,7 @@ public class FileTicketService extends ITicketService {
                                                }
                                        } catch (Exception e) {
                                                log.error("failed to deserialize {}/{}\n{}",
-                                                               new Object [] { models.get(i), journal, e.getMessage()});
+                                                               new Object [] { model, journal, e.getMessage()});
                                                log.error(null, e);
                                        }
                                }
index 2c5b181fba225b0d7821204a2782451cf10c1cba..48256b2b3dff8c474c58e808580e875b2ea7a815 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.eclipse.jgit.lib.Repository;
 
 import redis.clients.jedis.Client;
 import redis.clients.jedis.Jedis;
@@ -228,47 +229,65 @@ public class RedisTicketService extends ITicketService {
        public List<TicketModel> getTickets(RepositoryModel repository, TicketFilter filter) {
                Jedis jedis = pool.getResource();
                List<TicketModel> list = new ArrayList<TicketModel>();
+               List<RepositoryModel> models = new ArrayList<RepositoryModel>();
+               
+               if(repository == null)
+               {
+                       List<String> allRepo = repositoryManager.getRepositoryList();
+                       for(int i = 0; i < allRepo.size(); i++)
+                       {
+                               models.add(repositoryManager.getRepositoryModel(allRepo.get(i)));
+                       }
+               }
+               else
+               {
+                       models.add(repository);
+               }
+               
                if (jedis == null) {
                        return list;
                }
-               try {
-                       // Deserialize each journal, build the ticket, and optionally filter
-                       Set<String> keys = jedis.keys(key(repository, KeyType.journal, "*"));
-                       for (String key : keys) {
-                               // {repo}:journal:{id}
-                               String id = key.split(":")[2];
-                               long ticketId = Long.parseLong(id);
-                               List<Change> changes = getJournal(jedis, repository, ticketId);
-                               if (ArrayUtils.isEmpty(changes)) {
-                                       log.warn("Empty journal for {}:{}", repository, ticketId);
-                                       continue;
-                               }
-                               TicketModel ticket = TicketModel.buildTicket(changes);
-                               ticket.project = repository.projectPath;
-                               ticket.repository = repository.name;
-                               ticket.number = ticketId;
-
-                               // add the ticket, conditionally, to the list
-                               if (filter == null) {
-                                       list.add(ticket);
-                               } else {
-                                       if (filter.accept(ticket)) {
+               for(int i = 0; i < models.size(); i++)
+               {
+                       RepositoryModel model = models.get(i);
+                       try {
+                               // Deserialize each journal, build the ticket, and optionally filter
+                               Set<String> keys = jedis.keys(key(model, KeyType.journal, "*"));
+                               for (String key : keys) {
+                                       // {repo}:journal:{id}
+                                       String id = key.split(":")[2];
+                                       long ticketId = Long.parseLong(id);
+                                       List<Change> changes = getJournal(jedis, model, ticketId);
+                                       if (ArrayUtils.isEmpty(changes)) {
+                                               log.warn("Empty journal for {}:{}", model, ticketId);
+                                               continue;
+                                       }
+                                       TicketModel ticket = TicketModel.buildTicket(changes);
+                                       ticket.project = model.projectPath;
+                                       ticket.repository = model.name;
+                                       ticket.number = ticketId;
+       
+                                       // add the ticket, conditionally, to the list
+                                       if (filter == null) {
                                                list.add(ticket);
+                                       } else {
+                                               if (filter.accept(ticket)) {
+                                                       list.add(ticket);
+                                               }
                                        }
                                }
-                       }
-
-                       // sort the tickets by creation
-                       Collections.sort(list);
-               } catch (JedisException e) {
-                       log.error("failed to retrieve tickets from Redis @ " + getUrl(), e);
-                       pool.returnBrokenResource(jedis);
-                       jedis = null;
-               } finally {
-                       if (jedis != null) {
-                               pool.returnResource(jedis);
+                       } catch (JedisException e) {
+                               log.error("failed to retrieve tickets from Redis @ " + getUrl(), e);
+                               pool.returnBrokenResource(jedis);
+                               jedis = null;
+                       } finally {
+                               if (jedis != null) {
+                                       pool.returnResource(jedis);
+                               }
                        }
                }
+               // sort the tickets by creation
+               Collections.sort(list);
                return list;
        }