use of com.gitblit.models.TicketModel.Change in project gitblit by gitblit.
the class TicketPage method review.
protected void review(Score score) {
UserModel user = GitBlitWebSession.get().getUser();
Patchset ps = ticket.getCurrentPatchset();
Change change = new Change(user.username);
change.review(ps, score, !ticket.isReviewer(user.username));
if (!ticket.isWatching(user.username)) {
change.watch(user.username);
}
TicketModel updatedTicket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);
app().tickets().createNotifier().sendMailing(updatedTicket);
redirectTo(TicketsPage.class, getPageParameters());
}
use of com.gitblit.models.TicketModel.Change in project gitblit by gitblit.
the class CommentPanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
Form<String> form = new Form<String>("editorForm");
add(form);
form.add(new AjaxButton("submit", new Model<String>(getString("gb.comment")), form) {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
String txt = markdownEditor.getText();
if (change == null) {
// new comment
Change newComment = new Change(user.username);
newComment.comment(txt);
if (!ticket.isWatching(user.username)) {
newComment.watch(user.username);
}
RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment);
if (updatedTicket != null) {
app().tickets().createNotifier().sendMailing(updatedTicket);
redirectTo(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number));
} else {
error("Failed to add comment!");
}
} else {
// TODO update comment
}
}
/**
* Steal from BasePage to realize redirection.
*
* @see BasePage
* @author krulls@GitHub; ECG Leipzig GmbH, Germany, 2015
*
* @param pageClass
* @param parameters
* @return
*/
private void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
String relativeUrl = urlFor(pageClass, parameters).toString();
String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(canonicalUrl));
}
}.setVisible(ticket != null && ticket.number > 0));
final IModel<String> markdownPreviewModel = Model.of();
markdownPreview = new Label("markdownPreview", markdownPreviewModel);
markdownPreview.setEscapeModelStrings(false);
markdownPreview.setOutputMarkupId(true);
add(markdownPreview);
markdownEditor = new MarkdownTextArea("markdownEditor", markdownPreviewModel, markdownPreview);
markdownEditor.setRepository(repositoryName);
WicketUtils.setInputPlaceholder(markdownEditor, getString("gb.leaveComment"));
add(markdownEditor);
}
use of com.gitblit.models.TicketModel.Change in project gitblit by gitblit.
the class FileTicketService method getTickets.
/**
* Returns all the tickets in the repository. Querying tickets from the
* repository requires deserializing all tickets. This is an expensive
* process and not recommended. Tickets are indexed by Lucene and queries
* should be executed against that index.
*
* @param repository
* @param filter
* optional filter to only return matching results
* @return a list of tickets
*/
@Override
public List<TicketModel> getTickets(RepositoryModel repository, TicketFilter filter) {
List<TicketModel> list = new ArrayList<TicketModel>();
Repository db = repositoryManager.getRepository(repository.name);
try {
// Collect the set of all json files
File dir = new File(db.getDirectory(), TICKETS_PATH);
List<File> 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<Change> changes = TicketSerializer.deserializeJournal(json);
if (ArrayUtils.isEmpty(changes)) {
log.warn("Empty journal for {}:{}", repository, journal);
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);
}
}
} catch (Exception e) {
log.error("failed to deserialize {}/{}\n{}", new Object[] { repository, journal, e.getMessage() });
log.error(null, e);
}
}
// sort the tickets by creation
Collections.sort(list);
return list;
} finally {
db.close();
}
}
use of com.gitblit.models.TicketModel.Change in project gitblit by gitblit.
the class FileTicketService method getTicketImpl.
/**
* Retrieves the ticket from the repository.
*
* @param repository
* @param ticketId
* @return a ticket, if it exists, otherwise null
*/
@Override
protected TicketModel getTicketImpl(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;
}
TicketModel ticket = TicketModel.buildTicket(changes);
if (ticket != null) {
ticket.project = repository.projectPath;
ticket.repository = repository.name;
ticket.number = ticketId;
}
return ticket;
} finally {
db.close();
}
}
use of com.gitblit.models.TicketModel.Change in project gitblit by gitblit.
the class FileTicketService method getJournal.
/**
* Returns the journal for the specified ticket.
*
* @param db
* @param ticketId
* @return a list of changes
*/
private List<Change> getJournal(Repository db, long ticketId) {
if (ticketId <= 0L) {
return new ArrayList<Change>();
}
String journalPath = toTicketPath(ticketId) + "/" + JOURNAL;
File journal = new File(db.getDirectory(), journalPath);
if (!journal.exists()) {
return new ArrayList<Change>();
}
String json = null;
try {
json = new String(FileUtils.readContent(journal), Constants.ENCODING);
} catch (Exception e) {
log.error(null, e);
}
if (StringUtils.isEmpty(json)) {
return new ArrayList<Change>();
}
List<Change> list = TicketSerializer.deserializeJournal(json);
return list;
}
Aggregations