summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/tickets/BranchTicketService.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-04-28 14:56:15 -0400
committerJames Moger <james.moger@gitblit.com>2014-05-02 15:31:01 -0400
commit4d81c92b668bce79d7db7bc278f0d399fe693e65 (patch)
tree04e98e6182deeb78724d9a39a1d9c25a8efa10d2 /src/main/java/com/gitblit/tickets/BranchTicketService.java
parenta98ebb22fd088bbc2e40d752b065e4eb2210a734 (diff)
downloadgitblit-4d81c92b668bce79d7db7bc278f0d399fe693e65.tar.gz
gitblit-4d81c92b668bce79d7db7bc278f0d399fe693e65.zip
Implementation of a ticket mgration tool
Diffstat (limited to 'src/main/java/com/gitblit/tickets/BranchTicketService.java')
-rw-r--r--src/main/java/com/gitblit/tickets/BranchTicketService.java67
1 files changed, 57 insertions, 10 deletions
diff --git a/src/main/java/com/gitblit/tickets/BranchTicketService.java b/src/main/java/com/gitblit/tickets/BranchTicketService.java
index 284b1be1..8c000550 100644
--- a/src/main/java/com/gitblit/tickets/BranchTicketService.java
+++ b/src/main/java/com/gitblit/tickets/BranchTicketService.java
@@ -378,6 +378,37 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
}
/**
+ * Returns the assigned ticket ids.
+ *
+ * @return the assigned ticket ids
+ */
+ @Override
+ public synchronized Set<Long> getIds(RepositoryModel repository) {
+ Repository db = repositoryManager.getRepository(repository.name);
+ try {
+ if (getTicketsBranch(db) == null) {
+ return Collections.emptySet();
+ }
+ Set<Long> ids = new TreeSet<Long>();
+ List<PathModel> paths = JGitUtils.getDocuments(db, Arrays.asList("json"), BRANCH);
+ for (PathModel path : paths) {
+ String name = path.name.substring(path.name.lastIndexOf('/') + 1);
+ if (!JOURNAL.equals(name)) {
+ continue;
+ }
+ String tid = path.path.split("/")[2];
+ long ticketId = Long.parseLong(tid);
+ ids.add(ticketId);
+ }
+ return ids;
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ }
+ }
+
+ /**
* Assigns a new ticket id.
*
* @param repository
@@ -398,16 +429,10 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
}
AtomicLong lastId = lastAssignedId.get(repository.name);
if (lastId.get() <= 0) {
- List<PathModel> paths = JGitUtils.getDocuments(db, Arrays.asList("json"), BRANCH);
- for (PathModel path : paths) {
- String name = path.name.substring(path.name.lastIndexOf('/') + 1);
- if (!JOURNAL.equals(name)) {
- continue;
- }
- String tid = path.path.split("/")[2];
- long ticketId = Long.parseLong(tid);
- if (ticketId > lastId.get()) {
- lastId.set(ticketId);
+ Set<Long> ids = getIds(repository);
+ for (long id : ids) {
+ if (id > lastId.get()) {
+ lastId.set(id);
}
}
}
@@ -526,6 +551,28 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
}
/**
+ * Retrieves the journal for the ticket.
+ *
+ * @param repository
+ * @param ticketId
+ * @return a journal, if it exists, otherwise null
+ */
+ @Override
+ protected List<Change> getJournalImpl(RepositoryModel repository, long ticketId) {
+ Repository db = repositoryManager.getRepository(repository.name);
+ try {
+ List<Change> changes = getJournal(db, ticketId);
+ if (ArrayUtils.isEmpty(changes)) {
+ log.warn("Empty journal for {}:{}", repository, ticketId);
+ return null;
+ }
+ return changes;
+ } finally {
+ db.close();
+ }
+ }
+
+ /**
* Returns the journal for the specified ticket.
*
* @param db