Skip to content

@jakob85 /DataProvider.scala

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
package plugins
import play.api.{Logger, Plugin, Application}
import scala.concurrent.Future
import models.{Lead, DataResponse}
import exceptions.ServiceException
* User: jakobdobrzynski
* Date: 11/4/13
* Time: 4:28 PM
trait RegistrableDataProvider {
def id: String
class DataProviderRegistry[T <: RegistrableDataProvider](label: String) {
private var registry = Map[String, T]()
def register(plugin: T) {
if (registry.contains( ) {
throw new RuntimeException("There is already a %s registered with id %s".format(label,
val p = (, plugin)
registry += p
def unRegister(id: String) {
registry -= id
def get(id: String): Option[T] = registry.get(id) orElse {
Logger.error("[dataProviders] can't find %s for id %s".format(label, id))
def all() = registry
* This is a registry for all the registered dataProviders
object DataProviderRegistry {
lazy val dataProviders = new DataProviderRegistry[DataProvider]("dataProvider")
abstract class DataProvider (application: Application) extends Plugin with RegistrableDataProvider {
* Registers the dataProvider in the Provider Registry
override def onStart() {"[dataProvider] loaded dataProvider plugin: %s".format(id))
* Unregisters the dataProvider
override def onStop() {"[dataProvider] unloaded dataProvider plugin: %s".format(id))
def removeIndex[A](s: Seq[A], n: Int): Seq[A] = s.indices.collect { case i if i != n => s(i) }
def provideDataWithKey(key: String) : Future[List[DataResponse]]
def addListToLead(list: List[DataResponse], lead: Lead) : Future[Either[ServiceException, Lead]]
def getTypeList(list: List[DataResponse]) : List[DataResponse]
def removeForLeadAtIndexInList(id: String, index: Int) : Future[Either[ServiceException, Lead]]
def updateForLeadAtIndexInList(id: String, index: Int, s: String) : Future[Either[ServiceException, Lead]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.