Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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(plugin.id) ) {
throw new RuntimeException("There is already a %s registered with id %s".format(label, plugin.id))
}
val p = (plugin.id, 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))
None
}
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() {
Logger.info("[dataProvider] loaded dataProvider plugin: %s".format(id))
DataProviderRegistry.dataProviders.register(this)
}
/**
* Unregisters the dataProvider
*/
override def onStop() {
Logger.info("[dataProvider] unloaded dataProvider plugin: %s".format(id))
DataProviderRegistry.dataProviders.unRegister(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.