From 3380373c3123f875f50e48b0290c84dfae0519e4 Mon Sep 17 00:00:00 2001 From: BUISSON Christian Date: Tue, 15 Apr 2014 15:21:33 +0200 Subject: [PATCH] First Step in My Tickets --- .../gitblit/tickets/FileTicketService.java | 116 +++++++++------- .../com/gitblit/tickets/ITicketService.java | 11 +- .../com/gitblit/wicket/GitBlitWebApp.java | 2 + .../gitblit/wicket/GitBlitWebApp.properties | 3 +- .../wicket/GitBlitWebApp_fr.properties | 1 + .../gitblit/wicket/pages/MyTicketsPage.html | 50 +++++++ .../gitblit/wicket/pages/MyTicketsPage.java | 128 ++++++++++++++++++ .../com/gitblit/wicket/pages/RootPage.java | 1 + 8 files changed, 262 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/gitblit/wicket/pages/MyTicketsPage.html create mode 100644 src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java diff --git a/src/main/java/com/gitblit/tickets/FileTicketService.java b/src/main/java/com/gitblit/tickets/FileTicketService.java index 4386020f..ea5d065f 100644 --- a/src/main/java/com/gitblit/tickets/FileTicketService.java +++ b/src/main/java/com/gitblit/tickets/FileTicketService.java @@ -207,62 +207,82 @@ public class FileTicketService extends ITicketService { @Override public List getTickets(RepositoryModel repository, TicketFilter filter) { List list = new ArrayList(); - - Repository db = repositoryManager.getRepository(repository.name); - try { - // Collect the set of all json files - File dir = new File(db.getDirectory(), TICKETS_PATH); - List journals = findAll(dir, JOURNAL); - - // Deserialize each ticket and optionally filter out unwanted tickets - for (File journal : journals) { - String json = null; - try { - json = new String(FileUtils.readContent(journal), Constants.ENCODING); - } catch (Exception e) { - log.error(null, e); - } - 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 path = FileUtils.getRelativePath(dir, journal); - String tid = path.split("/")[1]; - long ticketId = Long.parseLong(tid); - List changes = TicketSerializer.deserializeJournal(json); - if (ArrayUtils.isEmpty(changes)) { - log.warn("Empty journal for {}:{}", repository, journal); + List databases = new ArrayList(); + List models = new ArrayList(); + + if(repository == null) + { + List 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); + } + + for(int i = 0; i < databases.size(); i++) + { + Repository db = databases.get(i); + try { + // Collect the set of all json files + File dir = new File(db.getDirectory(), TICKETS_PATH); + List journals = findAll(dir, JOURNAL); + + // Deserialize each ticket and optionally filter out unwanted tickets + for (File journal : journals) { + String json = null; + try { + json = new String(FileUtils.readContent(journal), Constants.ENCODING); + } catch (Exception e) { + log.error(null, e); + } + 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 path = FileUtils.getRelativePath(dir, journal); + String tid = path.split("/")[1]; + long ticketId = Long.parseLong(tid); + List changes = TicketSerializer.deserializeJournal(json); + if (ArrayUtils.isEmpty(changes)) { + log.warn("Empty journal for {}:{}", models.get(i), journal); + 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 [] { models.get(i), journal, e.getMessage()}); + log.error(null, e); } - } catch (Exception e) { - log.error("failed to deserialize {}/{}\n{}", - new Object [] { repository, journal, 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; } private List findAll(File dir, String filename) { diff --git a/src/main/java/com/gitblit/tickets/ITicketService.java b/src/main/java/com/gitblit/tickets/ITicketService.java index 3261ca96..e7b4c71d 100644 --- a/src/main/java/com/gitblit/tickets/ITicketService.java +++ b/src/main/java/com/gitblit/tickets/ITicketService.java @@ -779,12 +779,21 @@ public abstract class ITicketService { * @since 1.4.0 */ public abstract boolean hasTicket(RepositoryModel repository, long ticketId); + + /** + * Returns all tickets. This is not a Lucene search! + * + * @return all tickets + */ + public List getTickets() { + return getTickets(null, null); + } /** * Returns all tickets. This is not a Lucene search! * * @param repository - * @return all tickets + * @return all tickets of a given repository * @since 1.4.0 */ public List getTickets(RepositoryModel repository) { diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java index d4c1bc40..9f002d2b 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java @@ -81,6 +81,7 @@ import com.gitblit.wicket.pages.TicketsPage; import com.gitblit.wicket.pages.TreePage; import com.gitblit.wicket.pages.UserPage; import com.gitblit.wicket.pages.UsersPage; +import com.gitblit.wicket.pages.MyTicketsPage; public class GitBlitWebApp extends WebApplication { @@ -191,6 +192,7 @@ public class GitBlitWebApp extends WebApplication { mount("/tickets/export", ExportTicketPage.class, "r", "h"); mount("/milestones/new", NewMilestonePage.class, "r"); mount("/milestones/edit", EditMilestonePage.class, "r", "h"); + mount("/mytickets", MyTicketsPage.class, "r", "h"); // setup the markup document urls mount("/docs", DocsPage.class, "r"); diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index 1394890f..030c5ebe 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -677,4 +677,5 @@ gb.editMilestone = edit milestone gb.notifyChangedOpenTickets = send notification for changed open tickets gb.overdue = overdue gb.openMilestones = open milestones -gb.closedMilestones = closed milestones \ No newline at end of file +gb.closedMilestones = closed milestones +gb.mytickets = my tickets \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp_fr.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp_fr.properties index 8a725cf4..75a3ab7a 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp_fr.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp_fr.properties @@ -670,3 +670,4 @@ gb.repositoryDoesNotAcceptPatchsets = Ce d gb.serverDoesNotAcceptPatchsets = Ce serveur n'accepte pas de patchsets. gb.ticketIsClosed = Ce ticket est clos. gb.mergeToDescription = default integration branch for merging ticket patchsets +gb.mytickets = mes tickets diff --git a/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.html b/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.html new file mode 100644 index 00000000..bbb2b96b --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.html @@ -0,0 +1,50 @@ + + + + + + + Responsible Tickets + + + + + + +
+ + + Author Tickets + + + + + + +
+ + + Voted Tickets + + + + + + +
+ + + Watched Tickets + + + + + + +
+
+ + \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java b/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java new file mode 100644 index 00000000..509b00ca --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java @@ -0,0 +1,128 @@ +package com.gitblit.wicket.pages; + +import java.util.ArrayList; +import java.util.List; + +import com.gitblit.models.UserModel; +import com.gitblit.models.TicketModel; +import com.gitblit.tickets.ITicketService; +import com.gitblit.wicket.GitBlitWebApp; +import com.gitblit.wicket.GitBlitWebSession; +import com.gitblit.wicket.panels.LinkPanel; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.PageParameters; + +public class MyTicketsPage extends RootPage { + + public MyTicketsPage(PageParameters params) + { + this(); + } + + public MyTicketsPage() + { + super(); + setupPage("", ""); + + UserModel currentUser = GitBlitWebSession.get().getUser(); + if (currentUser == null) { + currentUser = UserModel.ANONYMOUS; + } + String username = currentUser.getName(); + + ITicketService tickets = GitBlitWebApp.get().tickets(); + List returnedTickets = tickets.getTickets(null); + + List responsibleTickets = new ArrayList(); + List authorTickets = new ArrayList(); + List votedTickets = new ArrayList(); + List watchedTickets = new ArrayList(); + for(int i = 0; i < returnedTickets.size(); i++) + { + TicketModel ticket = returnedTickets.get(i); + if(ticket.isOpen()) + { + if(ticket.isResponsible(username)) + { + responsibleTickets.add(ticket); + } + if(ticket.isAuthor(username)) + { + authorTickets.add(ticket); + } + if(ticket.isVoter(username)) + { + votedTickets.add(ticket); + } + if(ticket.isWatching(username)) + { + watchedTickets.add(ticket); + } + } + } + + ListView responsibleView = new ListView("responsibleTickets", responsibleTickets) + { + private static final long serialVersionUID = 1L; + + @Override + public void populateItem(final ListItem item) + { + final TicketModel ticket = item.getModelObject(); + String ticketUrl = app().tickets().getTicketUrl(ticket); + item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl)); + item.add(new Label("ticketDescription", ticket.body)); + } + }; + + ListView authorView = new ListView("authorTickets", authorTickets) + { + private static final long serialVersionUID = 1L; + + @Override + public void populateItem(final ListItem item) + { + final TicketModel ticket = item.getModelObject(); + String ticketUrl = app().tickets().getTicketUrl(ticket); + item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl)); + item.add(new Label("ticketDescription", ticket.body)); + } + }; + + ListView votedView = new ListView("votedTickets", votedTickets) + { + private static final long serialVersionUID = 1L; + + @Override + public void populateItem(final ListItem item) + { + final TicketModel ticket = item.getModelObject(); + String ticketUrl = app().tickets().getTicketUrl(ticket); + item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl)); + item.add(new Label("ticketDescription", ticket.body)); + } + }; + + ListView watchedView = new ListView("watchedTickets", watchedTickets) + { + private static final long serialVersionUID = 1L; + + @Override + public void populateItem(final ListItem item) + { + final TicketModel ticket = item.getModelObject(); + String ticketUrl = app().tickets().getTicketUrl(ticket); + item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl)); + item.add(new Label("ticketDescription", ticket.body)); + } + }; + + add(responsibleView); + add(authorView); + add(votedView); + add(watchedView); + } +} diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java index 5ccc3a4c..ec413b19 100644 --- a/src/main/java/com/gitblit/wicket/pages/RootPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java @@ -173,6 +173,7 @@ public abstract class RootPage extends BasePage { pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class, getRootPageParameters())); pages.add(new PageRegistration("gb.activity", ActivityPage.class, getRootPageParameters())); + pages.add(new PageRegistration("gb.mytickets", MyTicketsPage.class, getRootPageParameters())); if (app().settings().getBoolean(Keys.web.allowLuceneIndexing, true)) { pages.add(new PageRegistration("gb.search", LuceneSearchPage.class)); } -- 2.39.5