use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class BranchTicketService method getAttachment.
/**
* Retrieves the specified attachment from a ticket.
*
* @param repository
* @param ticketId
* @param filename
* @return an attachment, if found, null otherwise
*/
@Override
public Attachment getAttachment(RepositoryModel repository, long ticketId, String filename) {
if (ticketId <= 0L) {
return null;
}
// deserialize the ticket model so that we have the attachment metadata
TicketModel ticket = getTicket(repository, ticketId);
Attachment attachment = ticket.getAttachment(filename);
// attachment not found
if (attachment == null) {
return null;
}
// retrieve the attachment content
Repository db = repositoryManager.getRepository(repository.name);
try {
String attachmentPath = toAttachmentPath(ticketId, attachment.name);
RevTree tree = JGitUtils.getCommit(db, BRANCH).getTree();
byte[] content = JGitUtils.getByteContent(db, tree, attachmentPath, false);
attachment.content = content;
attachment.size = content.length;
return attachment;
} finally {
db.close();
}
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class FileTicketService method getAttachment.
/**
* Retrieves the specified attachment from a ticket.
*
* @param repository
* @param ticketId
* @param filename
* @return an attachment, if found, null otherwise
*/
@Override
public Attachment getAttachment(RepositoryModel repository, long ticketId, String filename) {
if (ticketId <= 0L) {
return null;
}
// deserialize the ticket model so that we have the attachment metadata
TicketModel ticket = getTicket(repository, ticketId);
Attachment attachment = ticket.getAttachment(filename);
// attachment not found
if (attachment == null) {
return null;
}
// retrieve the attachment content
Repository db = repositoryManager.getRepository(repository.name);
try {
String attachmentPath = toAttachmentPath(ticketId, attachment.name);
File file = new File(db.getDirectory(), attachmentPath);
if (file.exists()) {
attachment.content = FileUtils.readContent(file);
attachment.size = attachment.content.length;
}
return attachment;
} finally {
db.close();
}
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class ITicketService method renameMilestone.
/**
* Renames a milestone.
*
* @param repository
* @param oldName
* @param newName
* @param createdBy
* @param notifyOpenTickets
* @return true if successful
* @since 1.6.0
*/
public synchronized boolean renameMilestone(RepositoryModel repository, String oldName, String newName, String createdBy, boolean notifyOpenTickets) {
if (StringUtils.isEmpty(newName)) {
throw new IllegalArgumentException("new milestone can not be empty!");
}
Repository db = null;
try {
db = repositoryManager.getRepository(repository.name);
TicketMilestone tm = getMilestone(repository, oldName);
if (tm == null) {
return false;
}
StoredConfig config = db.getConfig();
config.unsetSection(MILESTONE, oldName);
config.setString(MILESTONE, newName, STATUS, tm.status.name());
config.setString(MILESTONE, newName, COLOR, tm.color);
if (tm.due != null) {
config.setString(MILESTONE, newName, DUE, new SimpleDateFormat(DUE_DATE_PATTERN).format(tm.due));
}
config.save();
milestonesCache.remove(repository.name);
TicketNotifier notifier = createNotifier();
for (QueryResult qr : tm.tickets) {
Change change = new Change(createdBy);
change.setField(Field.milestone, newName);
TicketModel ticket = updateTicket(repository, qr.number, change);
if (notifyOpenTickets && ticket.isOpen()) {
notifier.queueMailing(ticket);
}
}
if (notifyOpenTickets) {
notifier.sendAll();
}
return true;
} catch (IOException e) {
log.error("failed to rename milestone " + oldName + " in " + repository, e);
} finally {
if (db != null) {
db.close();
}
}
return false;
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class ITicketService method updateTicket.
/**
* Updates a ticket and promotes pending links into references.
*
* @param repository
* @param ticketId, or 0 to action pending links in general
* @param change
* @return the ticket model if successful, null if failure or using 0 ticketId
* @since 1.4.0
*/
public final TicketModel updateTicket(RepositoryModel repository, long ticketId, Change change) {
if (change == null) {
throw new RuntimeException("change can not be null!");
}
if (StringUtils.isEmpty(change.author)) {
throw new RuntimeException("must specify a change author!");
}
boolean success = true;
TicketModel ticket = null;
if (ticketId > 0) {
TicketKey key = new TicketKey(repository, ticketId);
ticketsCache.invalidate(key);
success = commitChangeImpl(repository, ticketId, change);
if (success) {
ticket = getTicket(repository, ticketId);
ticketsCache.put(key, ticket);
indexer.index(ticket);
// call the ticket hooks
if (pluginManager != null) {
for (TicketHook hook : pluginManager.getExtensions(TicketHook.class)) {
try {
hook.onUpdateTicket(ticket, change);
} catch (Exception e) {
log.error("Failed to execute extension", e);
}
}
}
}
}
if (success) {
//Now that the ticket has been successfully persisted add references to this ticket from linked tickets
if (change.hasPendingLinks()) {
for (TicketLink link : change.pendingLinks) {
TicketModel linkedTicket = getTicket(repository, link.targetTicketId);
Change dstChange = null;
//Ignore if not available or self reference
if (linkedTicket != null && link.targetTicketId != ticketId) {
dstChange = new Change(change.author, change.date);
switch(link.action) {
case Comment:
{
if (ticketId == 0) {
throw new RuntimeException("must specify a ticket when linking a comment!");
}
dstChange.referenceTicket(ticketId, change.comment.id);
}
break;
case Commit:
{
dstChange.referenceCommit(link.hash);
}
break;
default:
{
throw new RuntimeException(String.format("must add persist logic for link of type %s", link.action));
}
}
}
if (dstChange != null) {
//If not deleted then remain null in journal
if (link.isDelete) {
dstChange.reference.deleted = true;
}
if (updateTicket(repository, link.targetTicketId, dstChange) != null) {
link.success = true;
}
}
}
}
}
return ticket;
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class ITicketService method deleteComment.
/**
* Deletes a comment from a ticket.
*
* @param ticket
* @param commentId
* the id of the comment to delete
* @param deletedBy
* the user deleting the comment
* @return the revised ticket if the deletion was successful
* @since 1.4.0
*/
public final TicketModel deleteComment(TicketModel ticket, String commentId, String deletedBy) {
Change deletion = new Change(deletedBy);
deletion.comment("");
deletion.comment.id = commentId;
deletion.comment.deleted = true;
RepositoryModel repository = repositoryManager.getRepositoryModel(ticket.repository);
TicketModel revisedTicket = updateTicket(repository, ticket.number, deletion);
return revisedTicket;
}
Aggregations