summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-05-01 15:48:21 -0400
committerJames Moger <james.moger@gitblit.com>2014-05-01 16:14:15 -0400
commit92a33bc2ef40a7252ca8800cc48657afe66db2ef (patch)
treee3b79783df75b64ce78ce94818c14282e670551d /src
parent0514f28dc561e030af42f6df00ff785594f72646 (diff)
downloadgitblit-92a33bc2ef40a7252ca8800cc48657afe66db2ef.tar.gz
gitblit-92a33bc2ef40a7252ca8800cc48657afe66db2ef.zip
Revert "Implementation of the getTickets capability of recovering all tickets from a nullable RepositoryModel"
This reverts commit 1e6158bbc38a9012053c3bf8bfd16e113d8f5d29.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/gitblit/tickets/BranchTicketService.java114
-rw-r--r--src/main/java/com/gitblit/tickets/FileTicketService.java9
-rw-r--r--src/main/java/com/gitblit/tickets/RedisTicketService.java85
3 files changed, 84 insertions, 124 deletions
diff --git a/src/main/java/com/gitblit/tickets/BranchTicketService.java b/src/main/java/com/gitblit/tickets/BranchTicketService.java
index 7d6926df..284b1be1 100644
--- a/src/main/java/com/gitblit/tickets/BranchTicketService.java
+++ b/src/main/java/com/gitblit/tickets/BranchTicketService.java
@@ -436,84 +436,64 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
@Override
public List<TicketModel> getTickets(RepositoryModel repository, TicketFilter filter) {
List<TicketModel> list = new ArrayList<TicketModel>();
- 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)));
+
+ Repository db = repositoryManager.getRepository(repository.name);
+ try {
+ RefModel ticketsBranch = getTicketsBranch(db);
+ if (ticketsBranch == null) {
+ return list;
}
- }
- else
- {
- databases.add(repositoryManager.getRepository(repository.name));
- models.add(repository);
- }
- for(int i = 0; i < databases.size(); i++)
- {
- Repository db = databases.get(i);
- try {
- RefModel ticketsBranch = getTicketsBranch(db);
- if (ticketsBranch == null) {
- return list;
+ // 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;
}
-
- // 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
+ String json = readTicketsFile(db, path.path);
+ if (StringUtils.isEmpty(json)) {
+ // journal was touched but no changes were written
+ continue;
+ }
+ 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);
continue;
}
- 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) {
+ 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)) {
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;
+ // sort the tickets by creation
+ Collections.sort(list);
+ return list;
+ } finally {
+ db.close();
+ }
}
/**
diff --git a/src/main/java/com/gitblit/tickets/FileTicketService.java b/src/main/java/com/gitblit/tickets/FileTicketService.java
index 7fd9675f..ea5d065f 100644
--- a/src/main/java/com/gitblit/tickets/FileTicketService.java
+++ b/src/main/java/com/gitblit/tickets/FileTicketService.java
@@ -228,7 +228,6 @@ 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);
@@ -254,12 +253,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 {}:{}", model, journal);
+ log.warn("Empty journal for {}:{}", models.get(i), journal);
continue;
}
TicketModel ticket = TicketModel.buildTicket(changes);
- ticket.project = model.projectPath;
- ticket.repository = model.name;
+ ticket.project = models.get(i).projectPath;
+ ticket.repository = models.get(i).name;
ticket.number = ticketId;
// add the ticket, conditionally, to the list
@@ -272,7 +271,7 @@ public class FileTicketService extends ITicketService {
}
} catch (Exception e) {
log.error("failed to deserialize {}/{}\n{}",
- new Object [] { model, journal, e.getMessage()});
+ new Object [] { models.get(i), journal, e.getMessage()});
log.error(null, e);
}
}
diff --git a/src/main/java/com/gitblit/tickets/RedisTicketService.java b/src/main/java/com/gitblit/tickets/RedisTicketService.java
index 48256b2b..2c5b181f 100644
--- a/src/main/java/com/gitblit/tickets/RedisTicketService.java
+++ b/src/main/java/com/gitblit/tickets/RedisTicketService.java
@@ -22,7 +22,6 @@ 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;
@@ -229,65 +228,47 @@ 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;
}
- 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) {
+ 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)) {
list.add(ticket);
- } else {
- if (filter.accept(ticket)) {
- list.add(ticket);
- }
}
}
- } 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);
+ } 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;
}