From 25f59b0ba07a91e4c39b977a686c743eba9c3c8a Mon Sep 17 00:00:00 2001 From: To-om Date: Wed, 8 Nov 2017 10:58:53 +0100 Subject: [PATCH] #32 Add lavel and path to model --- app/org/elastic4play/models/ModelDef.scala | 8 ++++---- app/org/elastic4play/services/AttachmentSrv.scala | 2 +- app/org/elastic4play/services/DBList.scala | 2 +- test/org/elastic4play/services/CreateSrvSpec.scala | 2 +- test/org/elastic4play/services/DeleteSrvSpec.scala | 2 +- test/org/elastic4play/services/UpdateSrvSpec.scala | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/org/elastic4play/models/ModelDef.scala b/app/org/elastic4play/models/ModelDef.scala index 41a75bf..796e911 100644 --- a/app/org/elastic4play/models/ModelDef.scala +++ b/app/org/elastic4play/models/ModelDef.scala @@ -57,7 +57,7 @@ abstract class ModelAttributes(val name: String) extends AttributeDef { val updatedAt = optionalAttribute("updatedAt", AttributeFormat.dateFmt, "user who created this entity", AttributeOption.model) } -abstract class BaseModelDef(name: String) extends ModelAttributes(name) { +abstract class BaseModelDef(name: String, val label: String, val path: String) extends ModelAttributes(name) { def apply(attributes: JsObject): BaseEntity def removeAttribute: JsObject = throw InternalError(s"$name can't be removed") @@ -132,13 +132,13 @@ abstract class EntityDef[M <: BaseModelDef, E <: BaseEntity](model: M, attribute } } -abstract class AbstractModelDef[M <: AbstractModelDef[M, E], E <: BaseEntity](name: String) extends BaseModelDef(name) { +abstract class AbstractModelDef[M <: AbstractModelDef[M, E], E <: BaseEntity](name: String, label: String, path: String) extends BaseModelDef(name, label, path) { override def apply(attributes: JsObject): E } -abstract class ModelDef[M <: ModelDef[M, E], E <: BaseEntity](name: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name) { self: M ⇒ +abstract class ModelDef[M <: ModelDef[M, E], E <: BaseEntity](name: String, label: String, path: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name, label, path) { self: M ⇒ override def apply(attributes: JsObject): E = e.runtimeClass.getConstructor(getClass, classOf[JsObject]).newInstance(self, attributes).asInstanceOf[E] } -abstract class ChildModelDef[M <: ChildModelDef[M, E, PM, PE], E <: BaseEntity, PM <: BaseModelDef, PE <: BaseEntity](val parentModel: PM, name: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name) { self: M ⇒ +abstract class ChildModelDef[M <: ChildModelDef[M, E, PM, PE], E <: BaseEntity, PM <: BaseModelDef, PE <: BaseEntity](val parentModel: PM, name: String, label: String, path: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name, label, path) { self: M ⇒ override def apply(attributes: JsObject): E = e.runtimeClass.getConstructor(getClass, classOf[JsObject]).newInstance(self, attributes).asInstanceOf[E] } \ No newline at end of file diff --git a/app/org/elastic4play/services/AttachmentSrv.scala b/app/org/elastic4play/services/AttachmentSrv.scala index f9ae874..4d78b9c 100644 --- a/app/org/elastic4play/services/AttachmentSrv.scala +++ b/app/org/elastic4play/services/AttachmentSrv.scala @@ -35,7 +35,7 @@ trait AttachmentAttributes { _: AttributeDef ⇒ } @Singleton -class AttachmentModel(datastoreName: String) extends ModelDef[AttachmentModel, AttachmentChunk](datastoreName) with AttachmentAttributes { +class AttachmentModel(datastoreName: String) extends ModelDef[AttachmentModel, AttachmentChunk](datastoreName, "Attachment", "/datastore") with AttachmentAttributes { @Inject() def this(configuration: Configuration) = this(configuration.get[String]("datastore.name")) } class AttachmentChunk(model: AttachmentModel, attributes: JsObject) extends EntityDef[AttachmentModel, AttachmentChunk](model, attributes) with AttachmentAttributes diff --git a/app/org/elastic4play/services/DBList.scala b/app/org/elastic4play/services/DBList.scala index e2b84e9..be08127 100644 --- a/app/org/elastic4play/services/DBList.scala +++ b/app/org/elastic4play/services/DBList.scala @@ -21,7 +21,7 @@ import org.elastic4play.models.{ Attribute, EntityDef, ModelDef, AttributeFormat import org.elastic4play.utils.{ Hasher, RichFuture } @Singleton -class DBListModel(dblistName: String) extends ModelDef[DBListModel, DBListItemEntity](dblistName) { +class DBListModel(dblistName: String) extends ModelDef[DBListModel, DBListItemEntity](dblistName, "DBList", "/list") { model ⇒ @Inject def this(configuration: Configuration) = this(configuration.get[String]("dblist.name")) diff --git a/test/org/elastic4play/services/CreateSrvSpec.scala b/test/org/elastic4play/services/CreateSrvSpec.scala index 73a11c8..1be0ba0 100644 --- a/test/org/elastic4play/services/CreateSrvSpec.scala +++ b/test/org/elastic4play/services/CreateSrvSpec.scala @@ -20,7 +20,7 @@ import org.elastic4play.{ AttributeCheckingError, InvalidFormatAttributeError, M @RunWith(classOf[JUnitRunner]) class CreateSrvSpec extends PlaySpecification with Mockito { - class TestModel extends ModelDef[TestModel, TestEntity]("testModel") { + class TestModel extends ModelDef[TestModel, TestEntity]("testModel", "TestModel", "/test") { val textAttribute: Attribute[String] = attribute("textAttribute", F.textFmt, "textAttribute") val stringAttribute: Attribute[String] = attribute("stringAttribute", F.stringFmt, "stringAttribute") val dateAttribute: Attribute[Date] = attribute("dateAttribute", F.dateFmt, "dateAttribute") diff --git a/test/org/elastic4play/services/DeleteSrvSpec.scala b/test/org/elastic4play/services/DeleteSrvSpec.scala index 5e58602..a16388e 100644 --- a/test/org/elastic4play/services/DeleteSrvSpec.scala +++ b/test/org/elastic4play/services/DeleteSrvSpec.scala @@ -19,7 +19,7 @@ import org.elastic4play.utils.RichFuture @RunWith(classOf[JUnitRunner]) class DeleteSrvSpec extends PlaySpecification with Mockito { - class TestModel extends ModelDef[TestModel, TestEntity]("testModel") { + class TestModel extends ModelDef[TestModel, TestEntity]("testModel", "TestModel", "/test") { val textAttribute = attribute("textAttribute", F.textFmt, "textAttribute") val stringAttribute = attribute("stringAttribute", F.stringFmt, "stringAttribute") val dateAttribute = attribute("dateAttribute", F.dateFmt, "dateAttribute") diff --git a/test/org/elastic4play/services/UpdateSrvSpec.scala b/test/org/elastic4play/services/UpdateSrvSpec.scala index 294b965..1852b27 100644 --- a/test/org/elastic4play/services/UpdateSrvSpec.scala +++ b/test/org/elastic4play/services/UpdateSrvSpec.scala @@ -18,7 +18,7 @@ import org.elastic4play.{ AttributeCheckingError, InvalidFormatAttributeError, U @RunWith(classOf[JUnitRunner]) class UpdateSrvSpec extends PlaySpecification with Mockito { - class TestModel extends ModelDef[TestModel, TestEntity]("testModel") { + class TestModel extends ModelDef[TestModel, TestEntity]("testModel", "TestModel", "/test") { val textAttribute = attribute("textAttribute", F.textFmt, "textAttribute") val stringAttribute = attribute("stringAttribute", F.stringFmt, "stringAttribute") val dateAttribute = attribute("dateAttribute", F.dateFmt, "dateAttribute")