Skip to content

Commit

Permalink
Merge branch 'release/v0.9.0b33'
Browse files Browse the repository at this point in the history
  • Loading branch information
uchidayuichi committed Nov 5, 2016
2 parents 64f801c + d7a1bc6 commit 3defd12
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 25 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Migrate your projects from Redmine to [Backlog].
* The Backlog Space's administrator roles.

## Update
* 2016/10/06 0.9.0b33 released
* 2016/09/30 0.9.0b32 released
* 2016/09/30 0.9.0b31 released
* 2016/09/21 0.9.0b30 released
Expand Down Expand Up @@ -285,6 +286,7 @@ Redmineのプロジェクトを[Backlog]に移行するためのツールです
* Backlogの管理者権限

## 更新履歴
* 2016/10/06 0.9.0b33 リリース
* 2016/09/30 0.9.0b32 リリース
* 2016/09/30 0.9.0b31 リリース
* 2016/09/21 0.9.0b30 リリース
Expand Down Expand Up @@ -539,4 +541,4 @@ https://www.backlog.jp/contact/

[Backlog]: http://www.backlog.jp/

[Jar]: https://github.com/nulab/BacklogMigration-Redmine/releases/download/v0.9.0b32/backlog-migration-redmine-0.9.0b32.jar
[Jar]: https://github.com/nulab/BacklogMigration-Redmine/releases/download/v0.9.0b33/backlog-migration-redmine-0.9.0b33.jar
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "backlog-migration-redmine"

organization := "com.nulabinc"

version := "0.9.0b32"
version := "0.9.0b33"

scalaVersion := "2.11.6"

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/nulabinc/r2b/cli/ExecuteCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ExecuteCommand(conf: R2BConfig) extends CommonCommand {

private def confirmUseProject(projectKey: ParamProjectKey): Option[ParamProjectKey] = {
val backlogService: BacklogService = new BacklogService(BacklogConfig(conf.backlogUrl, conf.backlogKey))
if (backlogService.getProject(projectKey.getBacklogKey()).isRight) {
if (backlogService.getProject(projectKey.getBacklogKey()).isDefined) {

newLine()

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/nulabinc/r2b/cli/ParameterValidator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ParameterValidator(conf: R2BConfig) extends R2BLogging {
projectKey.backlog match {
case Some(backlog) =>
backlogService.getProject(backlog) match {
case Right(_) => Seq.empty[String]
case Left(_) => Seq("- " + Messages("message.project_not_exist", projectKey.backlog.get))
case Some(_) => Seq.empty[String]
case None => Seq("- " + Messages("message.project_not_exist", projectKey.backlog.get))
}
case None => Seq.empty[String]
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/nulabinc/r2b/conf/ConfigBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.io.File
object ConfigBase {
val LOG_APPLICATION_LABEL = "[R2B]"
val NAME: String = "Backlog Migration for Redmine"
val VERSION: String = "0.9.0b32"
val VERSION: String = "0.9.0b33"

val root = new File(".").getAbsoluteFile.getParent
val R2B_ROOT = root + "/backlog-migration-redmine"
Expand Down
25 changes: 25 additions & 0 deletions src/main/scala/com/nulabinc/r2b/service/AttachmentDownloader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.nulabinc.r2b.service
import java.io.{File, FileOutputStream}
import java.net.URL
import java.nio.channels.{Channels, ReadableByteChannel}
import java.security.{GeneralSecurityException, SecureRandom}
import java.security.cert.X509Certificate
import javax.net.ssl.{HttpsURLConnection, SSLContext, TrustManager, X509TrustManager}

import com.nulabinc.r2b.conf.ConfigBase
import com.nulabinc.r2b.utils.IOUtil
Expand Down Expand Up @@ -49,9 +52,31 @@ object AttachmentDownloader {
}

private def download(downloadInfo: DownloadInfo) = {
val tm: Array[TrustManager] = Array(
new X509TrustManager() {
override def getAcceptedIssuers: Array[X509Certificate] = null

override def checkClientTrusted(x509Certificates: Array[X509Certificate], s: String): Unit = {}

override def checkServerTrusted(x509Certificates: Array[X509Certificate], s: String): Unit = {}
}
)

try {
val sc:SSLContext = SSLContext.getInstance("SSL")
sc.init(null, tm, new SecureRandom())
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
} catch {
case e:GeneralSecurityException =>
throw new ExceptionInInitializerError(e)
}

val rbc: ReadableByteChannel = Channels.newChannel(downloadInfo.url.openStream())
val fos: FileOutputStream = new FileOutputStream(downloadInfo.path)
fos.getChannel.transferFrom(rbc, 0, java.lang.Long.MAX_VALUE)

rbc.close()
fos.close()
}

}
22 changes: 11 additions & 11 deletions src/main/scala/com/nulabinc/r2b/service/BacklogService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.nulabinc.r2b.actor.utils.R2BLogging
import scala.collection.JavaConverters._

/**
* @author uchida
*/
* @author uchida
*/
class BacklogService(conf: BacklogConfig) extends R2BLogging {

val backlog: BacklogClient = getBacklogClient
Expand All @@ -22,20 +22,20 @@ class BacklogService(conf: BacklogConfig) extends R2BLogging {
def getPriorities: Seq[Priority] = backlog.getPriorities.asScala

def getIssues(projectKey: String): Seq[Issue] = {
val result: Either[Throwable, Project] = getProject(projectKey)
if (result.isLeft) return Seq.empty[Issue]

val params: GetIssuesParams = new GetIssuesParams(List(result.right.get.getId.asInstanceOf[java.lang.Long]).asJava)
backlog.getIssues(params).asScala
val optProject: Option[Project] = getProject(projectKey)
if (optProject.isDefined) {
val params: GetIssuesParams = new GetIssuesParams(List(optProject.get.getId.asInstanceOf[java.lang.Long]).asJava)
backlog.getIssues(params).asScala
} else Seq.empty[Issue]
}


def getProject(projectKey: String): Either[Throwable, Project] = try {
Right(backlog.getProject(projectKey))
def getProject(projectKey: String): Option[Project] = try {
Some(backlog.getProject(projectKey))
} catch {
case e: BacklogAPIException =>
if(!e.getMessage.contains("No project")) error(e)
Left(e)
if (!(e.getMessage.contains("No project") || e.getMessage.contains("No such project"))) error(e)
None
}

private def getBacklogClient: BacklogClient = {
Expand Down
15 changes: 8 additions & 7 deletions src/main/scala/com/nulabinc/r2b/service/RedmineMarshaller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.nulabinc.r2b.domain._
import com.osinka.i18n.Lang
import com.taskadapter.redmineapi.bean._
import org.joda.time.DateTime
import org.joda.time.format.ISODateTimeFormat
import spray.json._

import scala.collection.JavaConverters._
Expand All @@ -19,7 +20,7 @@ object RedmineMarshaller {
import RedmineJsonProtocol._

val dateFormat = "yyyy-MM-dd"
val timestampFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
val parserISO = ISODateTimeFormat.dateTimeNoMillis()

object Issue {
def apply(issue: Issue, project: Project, users: Seq[User]): String =
Expand All @@ -44,8 +45,8 @@ object RedmineMarshaller {
journals = getRedmineJournals(issue, users),
customFields = getRedmineCustomFields(issue),
author = getUserLogin(Option(issue.getAuthor), users),
createdOn = Option(issue.getCreatedOn).map(date => new DateTime(date).toString(timestampFormat)),
updatedOn = Option(issue.getUpdatedOn).map(date => new DateTime(date).toString(timestampFormat))).toJson.prettyPrint
createdOn = Option(issue.getCreatedOn).map(date => parserISO.print(new DateTime(date))),
updatedOn = Option(issue.getUpdatedOn).map(date => parserISO.print(new DateTime(date)))).toJson.prettyPrint

private def getRedmineAttachments(issue: Issue): Seq[RedmineAttachment] = {
val attachments: Array[Attachment] = issue.getAttachments.toArray(new Array[Attachment](issue.getAttachments.size()))
Expand Down Expand Up @@ -77,8 +78,8 @@ object RedmineMarshaller {
user = getUserLogin(Option(wikiPageDetail.getUser), users),
comments = Option(wikiPageDetail.getComments),
parentTitle = Option(wikiPageDetail.getParent).map(_.getTitle),
createdOn = Option(wikiPageDetail.getCreatedOn).map(date => new DateTime(date).toString(timestampFormat)),
updatedOn = Option(wikiPageDetail.getUpdatedOn).map(date => new DateTime(date).toString(timestampFormat)),
createdOn = Option(wikiPageDetail.getCreatedOn).map(date => parserISO.print(new DateTime(date))),
updatedOn = Option(wikiPageDetail.getUpdatedOn).map(date => parserISO.print(new DateTime(date))),
attachments = getRedmineAttachments(wikiPageDetail)).toJson.prettyPrint
}

Expand Down Expand Up @@ -109,7 +110,7 @@ object RedmineMarshaller {
description = news.getDescription,
link = Option(news.getLink),
user = getUserLogin(Option(news.getUser), users),
createdOn = Option(news.getCreatedOn).map(date => new DateTime(date).toString(timestampFormat)))
createdOn = Option(news.getCreatedOn).map(date => parserISO.print(new DateTime(date))))
}

object Membership {
Expand Down Expand Up @@ -203,7 +204,7 @@ object RedmineMarshaller {
notes = Option(journal.getNotes),
details = journal.getDetails.asScala.map(getRedmineJournalDetail),
user = getUserLogin(Option(journal.getUser), users),
createdOn = Option(journal.getCreatedOn).map(date => new DateTime(date).toString(timestampFormat)))
createdOn = Option(journal.getCreatedOn).map(date => parserISO.print(new DateTime(date))))

private def getRedmineJournalDetail(journalDetail: JournalDetail): RedmineJournalDetail =
RedmineJournalDetail(
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/com/nulabinc/r2b/core/R2BSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class R2BSpec extends FlatSpec with ShouldMatchers with BeforeAndAfterAll with S
val redmineWikiUserId = userMapping.convert(redmineWikiUser.getLogin)

redmineWikiPageDetail.getTitle should equal(backlogWiki.getName)
redmineContent.replaceAll("\r\n", "\n") should equal(backlogWiki.getContent)
redmineContent should equal(backlogWiki.getContent)
redmineWikiUserId should equal(backlogWiki.getCreatedUser.getUserId)
redmineWikiUserId should equal(backlogWiki.getUpdatedUser.getUserId)
timestampToString(redmineWikiPageDetail.getCreatedOn) should equal(timestampToString(backlogWiki.getCreated))
Expand Down

0 comments on commit 3defd12

Please sign in to comment.