This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object MeetingMongo { | |
| val dateReader: Reads[Date] = new Reads[Date] { | |
| def reads(jsValue: JsValue): JsResult[Date] = { | |
| (jsValue \ "$date").validate[Long].map { l => new Date(l) } | |
| } | |
| } | |
| val dateWriter: Writes[Date] = new Writes[Date] { | |
| def writes(date: Date): JsValue = Json.obj("$date" -> JsNumber(date.getTime)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def batchInsert(elems: Enumerator[Iterator[T]])(implicit ctx: ExecutionContext): Future[Unit] = { | |
| val indexByChunks = Iteratee.foreach[Iterator[T]] { i => | |
| i.grouped(batchSize).foreach { chunk => | |
| val json = Json.toJson(chunk)(Writes.seq) | |
| solr.index(json) | |
| } | |
| } | |
| elems run indexByChunks | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def in(header:String) : Any = // existing method | |
| exchange.getIn.getHeader(header) | |
| def in[T](header: String)(implicit manifest: Manifest[T]) : T = // new method that supports type | |
| exchange.getIn.getHeader(header, manifest.runtimeClass).asInstanceOf[T] | |
| // existing code | |
| val fileName = ex.in("CamelFileName") // fileName is any, which is normally casted | |
| // passing a type, better |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val mongoToFE = | |
| __.json.update((__ \ 'id).json.copyFrom( (__ \ '_id \ '$oid).json.pick )) andThen | |
| (__ \ '_id).json.prune | |
| val FEtoMongo = | |
| __.json.update((__ \ '_id \ '$oid).json.copyFrom( (__ \ 'id).json.pick )) andThen | |
| (__ \ 'id).json.prune | |
| Async { | |
| val items = collection.find(BSONDocument("_id" -> objectId)).cursor[JsObject] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import reactivemongo.api.gridfs.Implicits._ | |
| def listFiles(docId: String) = Action { | |
| Async { | |
| listOfFiles(docId).map (files => Ok(files)) | |
| } | |
| } | |
| def listOfFiles(docId: String) = { | |
| val files = gridFS.find(BSONDocument("document" -> new BSONObjectID(docId))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // controller action | |
| def create = SecuredAction(Seq("roleA"), parse.json) { implicit request => | |
| } | |
| def ldapFind = Action { request => | |
| val results = LdapPlugin.filter("userPrincipalName", "foo", "dc=foo,dc=com", "cn") | |
| Ok(results.map{ r => r.getAttributeValue("cn")}.mkString) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "Document Controller" should { | |
| "create a document" in new WithApplication(FakeApplication(additionalConfiguration = additionalConfig)) { | |
| val json = Json.obj("title" -> "Hello Bob", | |
| "description" -> "description") | |
| val result = DocumentController.createDocument(FakeRequest("POST", "/documents", FakeHeaders(), json)) | |
| status(result) must equalTo(OK) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def uploadFile = Action(gridFSBodyParser(gridFS)) { request => | |
| val upload = request.body.files.head.ref | |
| Async { | |
| upload.map { | |
| case file => { | |
| Ok("File uploaded" + file.id) | |
| } | |
| }.recover { | |
| case _ => BadRequest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package experiments | |
| object LeftOuterJoinMap { | |
| def main(args: Array[String]) { | |
| val map1 = Map(1 -> "a", 2 -> "b", 3 -> "c") | |
| val map2 = Map(1 -> "1", 3 -> "3") | |
| val joined = (new LeftOuterJoinMap(map1, map2)).join |
NewerOlder