diff --git a/src/main/scala/app/CreateRepositoryController.scala b/src/main/scala/app/CreateRepositoryController.scala index af0373b..b2419d0 100644 --- a/src/main/scala/app/CreateRepositoryController.scala +++ b/src/main/scala/app/CreateRepositoryController.scala @@ -9,12 +9,12 @@ import jp.sf.amateras.scalatra.forms._ class CreateRepositoryController extends CreateRepositoryControllerBase - with ProjectService with AccountService with WikiService + with RepositoryService with AccountService with WikiService /** * Creates new repository. */ -trait CreateRepositoryControllerBase extends ControllerBase { self: ProjectService with WikiService => +trait CreateRepositoryControllerBase extends ControllerBase { self: RepositoryService with WikiService => case class RepositoryCreationForm(name: String, description: String) // TODO Option @@ -37,7 +37,7 @@ val loginUserName = context.loginAccount.get.userName // Insert to the database at first - createProject(form.name, loginUserName, Some(form.description)) + createRepository(form.name, loginUserName, Some(form.description)) // Create the actual repository val gitdir = getRepositoryDir(loginUserName, form.name) diff --git a/src/main/scala/app/IndexController.scala b/src/main/scala/app/IndexController.scala index 46fe857..8b51091 100644 --- a/src/main/scala/app/IndexController.scala +++ b/src/main/scala/app/IndexController.scala @@ -2,9 +2,9 @@ import service._ -class IndexController extends IndexControllerBase with ProjectService with AccountService +class IndexController extends IndexControllerBase with RepositoryService with AccountService -trait IndexControllerBase extends ControllerBase { self: ProjectService => +trait IndexControllerBase extends ControllerBase { self: RepositoryService => get("/"){ html.index(getAccessibleRepositories(context.loginAccount, servletContext)) diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index 196f639..285c50e 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -11,12 +11,14 @@ import org.apache.commons.io.FileUtils import org.eclipse.jgit.treewalk._ -class RepositoryViewerController extends RepositoryViewerControllerBase with ProjectService with AccountService +class RepositoryViewerController extends RepositoryViewerControllerBase + with RepositoryService with AccountService /** * The repository viewer. */ -trait RepositoryViewerControllerBase extends ControllerBase { self: ProjectService with AccountService => +trait RepositoryViewerControllerBase extends ControllerBase { + self: RepositoryService with AccountService => // TODO separate to AccountController? /** diff --git a/src/main/scala/app/SettingsController.scala b/src/main/scala/app/SettingsController.scala index a6a9b62..b57e2be 100644 --- a/src/main/scala/app/SettingsController.scala +++ b/src/main/scala/app/SettingsController.scala @@ -2,10 +2,10 @@ import service._ -class SettingsController extends SettingsControllerBase with ProjectService with AccountService +class SettingsController extends SettingsControllerBase with RepositoryService with AccountService -trait SettingsControllerBase extends ControllerBase { self: ProjectService => +trait SettingsControllerBase extends ControllerBase { self: RepositoryService => get("/:owner/:repository/settings") { val owner = params("owner") diff --git a/src/main/scala/app/WikiController.scala b/src/main/scala/app/WikiController.scala index c267954..c8483a9 100644 --- a/src/main/scala/app/WikiController.scala +++ b/src/main/scala/app/WikiController.scala @@ -5,9 +5,10 @@ import util.Directory._ import jp.sf.amateras.scalatra.forms._ -class WikiController extends WikiControllerBase with WikiService with ProjectService with AccountService +class WikiController extends WikiControllerBase + with WikiService with RepositoryService with AccountService -trait WikiControllerBase extends ControllerBase { self: WikiService with ProjectService => +trait WikiControllerBase extends ControllerBase { self: WikiService with RepositoryService => case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String) diff --git a/src/main/scala/service/ProjectService.scala b/src/main/scala/service/ProjectService.scala deleted file mode 100644 index d3be1e4..0000000 --- a/src/main/scala/service/ProjectService.scala +++ /dev/null @@ -1,112 +0,0 @@ -package service - -import model._ -import scala.slick.driver.H2Driver.simple._ -import Database.threadLocalSession -import util.JGitUtil -import javax.servlet.ServletContext - -trait ProjectService { self: AccountService => - import ProjectService._ - - /** - * Creates a new project. - * - * The project is created as public repository at first. Users can modify the project type at the repository settings - * page after the project creation to configure the project as the private repository. - * - * @param repositoryName the repository name - * @param userName the user name of the project owner - * @param description the project description - * @return the created project id - */ - def createProject(repositoryName: String, userName: String, description: Option[String]): Long = { - // TODO create a git repository also here? - - // TODO insert default labels. - - val currentDate = new java.sql.Date(System.currentTimeMillis) - - Repositories.* insert - Repository( - repositoryName = repositoryName, - userName = userName, - repositoryType = Public, - description = description, - defaultBranch = "master", - registeredDate = currentDate, - updatedDate = currentDate, - lastActivityDate = currentDate) - } - - /** - * Returns the specified user's repository informations. - * - * @param userName the user name - * @param servletContext the servlet context - * @return the repository informations which is sorted in descending order of lastActivityDate. - */ - def getRepositoriesOfUser(userName: String, servletContext: ServletContext): List[RepositoryInfo] = { - (Query(Repositories) filter(_.userName is userName.bind) sortBy(_.lastActivityDate desc) list) map { repository => - val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) - RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) - } - } - - /** - * Returns the specified repository information. - * - * @param userName the user name - * @param repositoryName the repository name - * @param servletContext the servlet context - * @return the repository information - */ - def getRepository(userName: String, repositoryName: String, servletContext: ServletContext): Option[RepositoryInfo] = { - (Query(Repositories) filter { repository => - (repository.userName is userName.bind) && (repository.repositoryName is repositoryName.bind) - } firstOption) map { repository => - val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) - RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) - } - } - - /** - * Returns the accessible repository informations for the specified account user. - * - * @param account the account - * @param servletContext the servlet context - * @return the repository informations which is sorted in descending order of lastActivityDate. - */ - def getAccessibleRepositories(account: Option[Account], servletContext: ServletContext): List[RepositoryInfo] = { - account match { - case Some(x) => { - (Query(Repositories) sortBy(_.lastActivityDate desc) list) map { repository => - val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) - RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) - } - } - case None => { - (Query(Repositories) filter(_.repositoryType is Public.bind) sortBy(_.lastActivityDate desc) list) map { repository => - val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) - RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) - } - } - } - } - - /** - * Updates the last activity date of the project. - */ - def updateLastActivityDate(userName: String, projectName: String): Unit = { - - } - -} - -object ProjectService { - - val Public = 0 - val Private = 1 - - case class RepositoryInfo(owner: String, name: String, url: String, repository: Repository, branchList: List[String], tags: List[util.JGitUtil.TagInfo]) -} \ No newline at end of file diff --git a/src/main/scala/service/RepositoryService.scala b/src/main/scala/service/RepositoryService.scala new file mode 100644 index 0000000..ef57982 --- /dev/null +++ b/src/main/scala/service/RepositoryService.scala @@ -0,0 +1,112 @@ +package service + +import model._ +import scala.slick.driver.H2Driver.simple._ +import Database.threadLocalSession +import util.JGitUtil +import javax.servlet.ServletContext + +trait RepositoryService { self: AccountService => + import RepositoryService._ + + /** + * Creates a new repository. + * + * The project is created as public repository at first. Users can modify the project type at the repository settings + * page after the project creation to configure the project as the private repository. + * + * @param repositoryName the repository name + * @param userName the user name of the project owner + * @param description the project description + * @return the created project id + */ + def createRepository(repositoryName: String, userName: String, description: Option[String]): Long = { + // TODO create a git repository also here? + + // TODO insert default labels. + + val currentDate = new java.sql.Date(System.currentTimeMillis) + + Repositories.* insert + Repository( + repositoryName = repositoryName, + userName = userName, + repositoryType = Public, + description = description, + defaultBranch = "master", + registeredDate = currentDate, + updatedDate = currentDate, + lastActivityDate = currentDate) + } + + /** + * Returns the specified user's repository informations. + * + * @param userName the user name + * @param servletContext the servlet context + * @return the repository informations which is sorted in descending order of lastActivityDate. + */ + def getRepositoriesOfUser(userName: String, servletContext: ServletContext): List[RepositoryInfo] = { + (Query(Repositories) filter(_.userName is userName.bind) sortBy(_.lastActivityDate desc) list) map { repository => + val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) + RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) + } + } + + /** + * Returns the specified repository information. + * + * @param userName the user name + * @param repositoryName the repository name + * @param servletContext the servlet context + * @return the repository information + */ + def getRepository(userName: String, repositoryName: String, servletContext: ServletContext): Option[RepositoryInfo] = { + (Query(Repositories) filter { repository => + (repository.userName is userName.bind) && (repository.repositoryName is repositoryName.bind) + } firstOption) map { repository => + val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) + RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) + } + } + + /** + * Returns the accessible repository informations for the specified account user. + * + * @param account the account + * @param servletContext the servlet context + * @return the repository informations which is sorted in descending order of lastActivityDate. + */ + def getAccessibleRepositories(account: Option[Account], servletContext: ServletContext): List[RepositoryInfo] = { + account match { + case Some(x) => { + (Query(Repositories) sortBy(_.lastActivityDate desc) list) map { repository => + val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) + RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) + } + } + case None => { + (Query(Repositories) filter(_.repositoryType is Public.bind) sortBy(_.lastActivityDate desc) list) map { repository => + val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext) + RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) + } + } + } + } + + /** + * Updates the last activity date of the project. + */ + def updateLastActivityDate(userName: String, projectName: String): Unit = { + + } + +} + +object RepositoryService { + + val Public = 0 + val Private = 1 + + case class RepositoryInfo(owner: String, name: String, url: String, repository: Repository, branchList: List[String], tags: List[util.JGitUtil.TagInfo]) +} \ No newline at end of file diff --git a/src/main/scala/view/helpers.scala b/src/main/scala/view/helpers.scala index 098c33b..7c82131 100644 --- a/src/main/scala/view/helpers.scala +++ b/src/main/scala/view/helpers.scala @@ -25,7 +25,7 @@ /** * Converts the issue number and the commit id to the link. */ - private def markdownFilter(value: String, repository: service.ProjectService.RepositoryInfo)(implicit context: app.Context): String = { + private def markdownFilter(value: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context): String = { value .replaceAll("#([0-9]+)", "[$0](%s/%s/%s/issue/$1)".format(context.path, repository.owner, repository.name)) .replaceAll("[0-9a-f]{40}", "[$0](%s/%s/%s/commit/$0)".format(context.path, repository.owner, repository.name)) @@ -34,7 +34,7 @@ /** * Converts Markdown of Wiki pages to HTML. */ - def markdown(value: String, repository: service.ProjectService.RepositoryInfo, wikiLink: Boolean)(implicit context: app.Context): twirl.api.Html = { + def markdown(value: String, repository: service.RepositoryService.RepositoryInfo, wikiLink: Boolean)(implicit context: app.Context): twirl.api.Html = { import org.pegdown._ val html = new PegDownProcessor(Extensions.AUTOLINKS|Extensions.WIKILINKS|Extensions.FENCED_CODE_BLOCKS) .markdownToHtml(markdownFilter(value, repository), new LinkRenderer(){