if (StringUtils.isEmpty(inputServiceName)) {
System.err.println(MessageFormat.format("Please define a ticket service in \"{0}\"", Keys.tickets.service));
System.exit(1);
}
ITicketService inputService = null;
ITicketService outputService = null;
try {
inputService = getService(inputServiceName, runtimeManager, repositoryManager);
outputService = getService(outputServiceName, runtimeManager, repositoryManager);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
if (!inputService.isReady()) {
System.err.println(String.format("%s INPUT service is not ready, check config.", inputService.getClass().getSimpleName()));
System.exit(1);
}
if (!outputService.isReady()) {
System.err.println(String.format("%s OUTPUT service is not ready, check config.", outputService.getClass().getSimpleName()));
System.exit(1);
}
// migrate tickets
long start = System.nanoTime();
long totalTickets = 0;
long totalChanges = 0;
for (RepositoryModel repository : repositoryManager.getRepositoryModels()) {
Set<Long> ids = inputService.getIds(repository);
if (ids == null || ids.isEmpty()) {
// nothing to migrate
continue;
}
// delete any tickets we may have in the output ticket service
outputService.deleteAll(repository);
for (long id : ids) {
List<Change> journal = inputService.getJournal(repository, id);
if (journal == null || journal.size() == 0) {
continue;
}
TicketModel ticket = outputService.createTicket(repository, id, journal.get(0));
if (ticket == null) {
System.err.println(String.format("Failed to migrate %s #%s", repository.name, id));
System.exit(1);
}
totalTickets++;
System.out.println(String.format("%s #%s: %s", repository.name, ticket.number, ticket.title));
for (int i = 1; i < journal.size(); i++) {
TicketModel updated = outputService.updateTicket(repository, ticket.number, journal.get(i));
if (updated != null) {
System.out.println(String.format(" applied change %d", i));
totalChanges++;
} else {
System.err.println(String.format("Failed to apply change %d:\n%s", i, journal.get(i)));
System.exit(1);
}
}
}
}
inputService.stop();
outputService.stop();
repositoryManager.stop();
runtimeManager.stop();
long end = System.nanoTime();