Improved model package. The details are as follows:

* Fix the Profiles class from package object to simple object
* Fix the row case class to model package
* Define the alias of JdbcBackend#Session
This commit is contained in:
shimamoto
2014-07-28 04:52:56 +09:00
parent 723de9e81e
commit b13820fc0e
31 changed files with 195 additions and 180 deletions

View File

@@ -21,9 +21,9 @@ trait AccountComponent { self: Profile =>
val removed = column[Boolean]("REMOVED") val removed = column[Boolean]("REMOVED")
def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed) <> (Account.tupled, Account.unapply) def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed) <> (Account.tupled, Account.unapply)
} }
}
case class Account( case class Account(
userName: String, userName: String,
fullName: String, fullName: String,
mailAddress: String, mailAddress: String,
@@ -37,4 +37,3 @@ trait AccountComponent { self: Profile =>
isGroupAccount: Boolean, isGroupAccount: Boolean,
isRemoved: Boolean isRemoved: Boolean
) )
}

View File

@@ -15,6 +15,7 @@ trait ActivityComponent extends TemplateComponent { self: Profile =>
val activityDate = column[java.util.Date]("ACTIVITY_DATE") val activityDate = column[java.util.Date]("ACTIVITY_DATE")
def * = (userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate, activityId) <> (Activity.tupled, Activity.unapply) def * = (userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate, activityId) <> (Activity.tupled, Activity.unapply)
} }
}
case class Activity( case class Activity(
userName: String, userName: String,
@@ -26,4 +27,3 @@ trait ActivityComponent extends TemplateComponent { self: Profile =>
activityDate: java.util.Date, activityDate: java.util.Date,
activityId: Int = 0 activityId: Int = 0
) )
}

View File

@@ -12,10 +12,10 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(owner: String, repository: String, collaborator: String) = def byPrimaryKey(owner: String, repository: String, collaborator: String) =
byRepository(owner, repository) && (collaboratorName is collaborator.bind) byRepository(owner, repository) && (collaboratorName is collaborator.bind)
} }
}
case class Collaborator( case class Collaborator(
userName: String, userName: String,
repositoryName: String, repositoryName: String,
collaboratorName: String collaboratorName: String
) )
}

View File

@@ -11,10 +11,10 @@ trait GroupMemberComponent { self: Profile =>
val isManager = column[Boolean]("MANAGER") val isManager = column[Boolean]("MANAGER")
def * = (groupName, userName, isManager) <> (GroupMember.tupled, GroupMember.unapply) def * = (groupName, userName, isManager) <> (GroupMember.tupled, GroupMember.unapply)
} }
}
case class GroupMember( case class GroupMember(
groupName: String, groupName: String,
userName: String, userName: String,
isManager: Boolean isManager: Boolean
) )
}

View File

@@ -31,6 +31,7 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId) def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
} }
}
case class Issue( case class Issue(
userName: String, userName: String,
@@ -44,5 +45,5 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
closed: Boolean, closed: Boolean,
registeredDate: java.util.Date, registeredDate: java.util.Date,
updatedDate: java.util.Date, updatedDate: java.util.Date,
isPullRequest: Boolean) isPullRequest: Boolean
} )

View File

@@ -19,6 +19,7 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(commentId: Int) = this.commentId is commentId.bind def byPrimaryKey(commentId: Int) = this.commentId is commentId.bind
} }
}
case class IssueComment( case class IssueComment(
userName: String, userName: String,
@@ -31,4 +32,3 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile =>
registeredDate: java.util.Date, registeredDate: java.util.Date,
updatedDate: java.util.Date updatedDate: java.util.Date
) )
}

View File

@@ -10,10 +10,11 @@ trait IssueLabelComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) = def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
byIssue(owner, repository, issueId) && (this.labelId is labelId.bind) byIssue(owner, repository, issueId) && (this.labelId is labelId.bind)
} }
}
case class IssueLabel( case class IssueLabel(
userName: String, userName: String,
repositoryName: String, repositoryName: String,
issueId: Int, issueId: Int,
labelId: Int) labelId: Int
} )

View File

@@ -14,6 +14,7 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId) def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId) def byPrimaryKey(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId)
} }
}
case class Label( case class Label(
userName: String, userName: String,
@@ -34,4 +35,3 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
} }
} }
} }
}

View File

@@ -17,6 +17,7 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId) def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId) def byPrimaryKey(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId)
} }
}
case class Milestone( case class Milestone(
userName: String, userName: String,
@@ -25,5 +26,5 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
title: String, title: String,
description: Option[String], description: Option[String],
dueDate: Option[java.util.Date], dueDate: Option[java.util.Date],
closedDate: Option[java.util.Date]) closedDate: Option[java.util.Date]
} )

View File

@@ -1,7 +1,7 @@
package model package model
trait Profile { trait Profile {
val profile = slick.driver.H2Driver val profile: slick.driver.JdbcProfile
import profile.simple._ import profile.simple._
// java.util.Date Mapped Column Types // java.util.Date Mapped Column Types
@@ -15,3 +15,27 @@ trait Profile {
} }
} }
object Profile extends {
val profile = slick.driver.H2Driver
} with AccountComponent
with ActivityComponent
with CollaboratorComponent
with GroupMemberComponent
with IssueComponent
with IssueCommentComponent
with IssueLabelComponent
with LabelComponent
with MilestoneComponent
with PullRequestComponent
with RepositoryComponent
with SshKeyComponent
with WebHookComponent with Profile {
/**
* Returns system date.
*/
def currentDate = new java.util.Date()
}

View File

@@ -17,6 +17,7 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId) def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId)
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId) def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId)
} }
}
case class PullRequest( case class PullRequest(
userName: String, userName: String,
@@ -29,4 +30,3 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
commitIdFrom: String, commitIdFrom: String,
commitIdTo: String commitIdTo: String
) )
}

View File

@@ -21,6 +21,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository) def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
} }
}
case class Repository( case class Repository(
userName: String, userName: String,
@@ -36,4 +37,3 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
parentUserName: Option[String], parentUserName: Option[String],
parentRepositoryName: Option[String] parentRepositoryName: Option[String]
) )
}

View File

@@ -14,6 +14,7 @@ trait SshKeyComponent { self: Profile =>
def byPrimaryKey(userName: String, sshKeyId: Int) = (this.userName is userName.bind) && (this.sshKeyId is sshKeyId.bind) def byPrimaryKey(userName: String, sshKeyId: Int) = (this.userName is userName.bind) && (this.sshKeyId is sshKeyId.bind)
} }
}
case class SshKey( case class SshKey(
userName: String, userName: String,
@@ -21,4 +22,3 @@ trait SshKeyComponent { self: Profile =>
title: String, title: String,
publicKey: String publicKey: String
) )
}

View File

@@ -11,10 +11,10 @@ trait WebHookComponent extends TemplateComponent { self: Profile =>
def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url is url.bind) def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url is url.bind)
} }
}
case class WebHook( case class WebHook(
userName: String, userName: String,
repositoryName: String, repositoryName: String,
url: String url: String
) )
}

View File

@@ -1,21 +1,3 @@
package object model extends Profile package object model {
with AccountComponent type Session = slick.jdbc.JdbcBackend#Session
with ActivityComponent
with CollaboratorComponent
with GroupMemberComponent
with IssueComponent
with IssueCommentComponent
with IssueLabelComponent
with LabelComponent
with MilestoneComponent
with PullRequestComponent
with RepositoryComponent
with SshKeyComponent
with WebHookComponent {
/**
* Returns system date.
*/
def currentDate = new java.util.Date()
} }

View File

@@ -1,9 +1,10 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.{Account, GroupMember}
// TODO [Slick 2.0]NOT import directly? // TODO [Slick 2.0]NOT import directly?
import model.dateColumnType import model.Profile.dateColumnType
import service.SystemSettingsService.SystemSettings import service.SystemSettingsService.SystemSettings
import util.StringUtil._ import util.StringUtil._
import util.LDAPUtil import util.LDAPUtil

View File

@@ -1,7 +1,8 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.Activity
trait ActivityService { trait ActivityService {

View File

@@ -3,8 +3,9 @@ package service
import scala.slick.jdbc.{StaticQuery => Q} import scala.slick.jdbc.{StaticQuery => Q}
import Q.interpolation import Q.interpolation
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.{Issue, IssueComment, IssueLabel, Label}
import util.Implicits._ import util.Implicits._
import util.StringUtil._ import util.StringUtil._

View File

@@ -1,7 +1,8 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.Label
trait LabelsService { trait LabelsService {

View File

@@ -1,9 +1,10 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.Milestone
// TODO [Slick 2.0]NOT import directly? // TODO [Slick 2.0]NOT import directly?
import model.dateColumnType import model.Profile.dateColumnType
trait MilestonesService { trait MilestonesService {

View File

@@ -1,7 +1,8 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.{PullRequest, Issue}
trait PullRequestService { self: IssuesService => trait PullRequestService { self: IssuesService =>
import PullRequestService._ import PullRequestService._

View File

@@ -7,7 +7,7 @@ import org.eclipse.jgit.revwalk.RevWalk
import org.eclipse.jgit.treewalk.TreeWalk import org.eclipse.jgit.treewalk.TreeWalk
import org.eclipse.jgit.lib.FileMode import org.eclipse.jgit.lib.FileMode
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import model._ import model.Profile._
import profile.simple._ import profile.simple._
trait RepositorySearchService { self: IssuesService => trait RepositorySearchService { self: IssuesService =>
@@ -107,7 +107,7 @@ object RepositorySearchService {
case class SearchResult( case class SearchResult(
files : List[(String, String)], files : List[(String, String)],
issues: List[(Issue, Int, String)]) issues: List[(model.Issue, Int, String)])
case class IssueSearchResult( case class IssueSearchResult(
issueId: Int, issueId: Int,

View File

@@ -1,7 +1,8 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.{Repository, Account, Collaborator}
import util.JGitUtil import util.JGitUtil
trait RepositoryService { self: AccountService => trait RepositoryService { self: AccountService =>

View File

@@ -1,7 +1,6 @@
package service package service
import model._ import model.{Account, Issue, Session}
import slick.jdbc.JdbcBackend
import util.Implicits.request2Session import util.Implicits.request2Session
/** /**
@@ -12,7 +11,7 @@ import util.Implicits.request2Session
*/ */
trait RequestCache extends SystemSettingsService with AccountService with IssuesService { trait RequestCache extends SystemSettingsService with AccountService with IssuesService {
private implicit def context2Session(implicit context: app.Context): JdbcBackend#Session = private implicit def context2Session(implicit context: app.Context): Session =
request2Session(context.request) request2Session(context.request)
def getIssue(userName: String, repositoryName: String, issueId: String) def getIssue(userName: String, repositoryName: String, issueId: String)

View File

@@ -1,7 +1,8 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.SshKey
trait SshKeyService { trait SshKeyService {

View File

@@ -1,7 +1,8 @@
package service package service
import model._ import model.Profile._
import profile.simple._ import profile.simple._
import model.{WebHook, Account}
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import service.RepositoryService.RepositoryInfo import service.RepositoryService.RepositoryInfo
import util.JGitUtil import util.JGitUtil

View File

@@ -5,7 +5,6 @@ import javax.servlet.http._
import service.{SystemSettingsService, AccountService, RepositoryService} import service.{SystemSettingsService, AccountService, RepositoryService}
import model._ import model._
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import slick.jdbc.JdbcBackend
import util.Implicits._ import util.Implicits._
import util.ControlUtil._ import util.ControlUtil._
import util.Keys import util.Keys
@@ -67,7 +66,7 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
} }
private def getWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo) private def getWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo)
(implicit session: JdbcBackend#Session): Option[Account] = (implicit session: Session): Option[Account] =
authenticate(loadSystemSettings(), username, password) match { authenticate(loadSystemSettings(), username, password) match {
case x @ Some(account) if(hasWritePermission(repository.owner, repository.name, x)) => x case x @ Some(account) if(hasWritePermission(repository.owner, repository.name, x)) => x
case _ => None case _ => None

View File

@@ -17,7 +17,7 @@ import WebHookService._
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import util.JGitUtil.CommitInfo import util.JGitUtil.CommitInfo
import service.IssuesService.IssueSearchCondition import service.IssuesService.IssueSearchCondition
import slick.jdbc.JdbcBackend import model.Session
/** /**
* Provides Git repository via HTTP. * Provides Git repository via HTTP.
@@ -95,7 +95,7 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl: String)(implicit session: JdbcBackend#Session) class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl: String)(implicit session: Session)
extends PostReceiveHook with PreReceiveHook extends PostReceiveHook with PreReceiveHook
with RepositoryService with AccountService with IssuesService with ActivityService with PullRequestService with WebHookService { with RepositoryService with AccountService with IssuesService with ActivityService with PullRequestService with WebHookService {

View File

@@ -5,7 +5,7 @@ import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
import org.apache.commons.io.IOUtils import org.apache.commons.io.IOUtils
import twirl.api.Html import twirl.api.Html
import service.{AccountService, RepositoryService, SystemSettingsService} import service.{AccountService, RepositoryService, SystemSettingsService}
import model.Account import model.{Account, Session}
import util.{JGitUtil, Keys} import util.{JGitUtil, Keys}
import plugin.PluginConnectionHolder import plugin.PluginConnectionHolder
@@ -50,7 +50,7 @@ class PluginActionInvokeFilter extends Filter with SystemSettingsService with Re
} }
private def processRepositoryAction(path: String, request: HttpServletRequest, response: HttpServletResponse) private def processRepositoryAction(path: String, request: HttpServletRequest, response: HttpServletResponse)
(implicit session: model.profile.simple.Session): Boolean = { (implicit session: Session): Boolean = {
val elements = path.split("/") val elements = path.split("/")
if(elements.length > 3){ if(elements.length > 3){
val owner = elements(1) val owner = elements(1)

View File

@@ -12,7 +12,7 @@ import servlet.{Database, CommitLogHook}
import service.{AccountService, RepositoryService, SystemSettingsService} import service.{AccountService, RepositoryService, SystemSettingsService}
import org.eclipse.jgit.errors.RepositoryNotFoundException import org.eclipse.jgit.errors.RepositoryNotFoundException
import javax.servlet.ServletContext import javax.servlet.ServletContext
import model.profile.simple.Session import model.Session
object GitCommand { object GitCommand {
val CommandRegex = """\Agit-(upload|receive)-pack '/([a-zA-Z0-9\-_.]+)/([a-zA-Z0-9\-_.]+).git'\Z""".r val CommandRegex = """\Agit-(upload|receive)-pack '/([a-zA-Z0-9\-_.]+)/([a-zA-Z0-9\-_.]+).git'\Z""".r

View File

@@ -6,11 +6,11 @@ import org.apache.commons.mail.{DefaultAuthenticator, HtmlEmail}
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import app.Context import app.Context
import model.Session
import service.{AccountService, RepositoryService, IssuesService, SystemSettingsService} import service.{AccountService, RepositoryService, IssuesService, SystemSettingsService}
import servlet.Database import servlet.Database
import SystemSettingsService.Smtp import SystemSettingsService.Smtp
import _root_.util.ControlUtil.defining import _root_.util.ControlUtil.defining
import model.profile.simple.Session
trait Notifier extends RepositoryService with AccountService with IssuesService { trait Notifier extends RepositoryService with AccountService with IssuesService {
def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String) def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String)