leodagdag / play2-morphia-plugin Goto Github PK
View Code? Open in Web Editor NEWPlugin to use Morphia/MongoDB with Play! framework 2.0
Plugin to use Morphia/MongoDB with Play! framework 2.0
After review the code, find out that there's no parameters for mongodb credentials.
It would be nice to have such feature
adding lthe following lines to project/plugins.sbt:
resolvers += "LeoDagDag repository" at "http://leodagdag.github.com/repository/"
addSbtPlugin("leodagdag" %% "play2-morphia-plugin" % "0.0.14")
Does not work:
[warn] ==== LeoDagDag repository: tried
[warn] http://leodagdag.github.com/repository/leodagdag/play2-morphia-plugin_2.10_0.13/0.0.14/play2-morphia-plugin-0.0.14.pom
play 2.2.1 is using "sbt.version=0.13.0".
How I can make it work? Thanks
Hai!
Error:
com.google.code.morphia.mapping.MappingException: Error mapping field:models.Post.picture
add.scala.html
@(postForm: Form[Post])
@import helper._
@main("addPost"){
<h1>Add Post</h1>
@form(routes.Application.addPostSave(),'enctype -> "multipart/form-data"){
@inputText(postForm("title"))
@inputFile(postForm("picture"))
<input type="submit" value="Created">
}
}
Routes File
GET / controllers.Application.index()
GET /addPost controllers.Application.addPost()
POST /addPost controllers.Application.addPostSave()
GET /assets/*file controllers.Assets.at(path="/public", file)
controller
package controllers;
import java.io.File;
import com.google.code.morphia.mapping.MappingException;
import leodagdag.play2morphia.Blob;
import models.Post;
import play.;
//import play.api.data.Form;
import play.api.data.Form;
import play.api.libs.MimeTypes;
import play.mvc.;
import views.html.*;
public class Application extends Controller {
public static Result index() {
return ok(index.render("Your new application is ready."));
}
static play.data.Form postForm = form(Post.class);
public static Result addPost(){
return ok(addPost.render(postForm));
}
public static Result addPostSave(){
try{
play.mvc.Http.MultipartFormData body = request().body().asMultipartFormData();
play.mvc.Http.MultipartFormData.FilePart picture = body.getFile("picture");
File file = new File("C:/Users/Kenla_15/Pictures/thumbbig-150464.JPG");
play.data.Form filledForm = postForm.bindFromRequest();
if(filledForm.hasErrors()){
return ok(addPost.render(postForm));
}else{
System.out.println();
Post post = new Post();
post.title = filledForm.get().title;
//String mimetype = MimeTypes.forFileName(file.getName()).get();
String mimetype = "JPG";//MimeTypes.forFileName(file.getName()).get();
Blob blob = new Blob(file, mimetype);
post.picture = blob;
post.insert();
return ok(index.render("The image is created"));
}
}catch(MappingException e){
System.out.println();
return ok(index.render(e.toString()));
}
}
}
index.scala.html
@(message: String)
@main("Welcome to Play 2.0") {
@play20.welcome(message, style = "Java")
}
I hope I made mistake. If you know where then. please help me!
Thanking you!
T.Balamanikandan
How to install it to play2?
Hai!
Model
public class User extends Model{
public ObjectId id;
public String userName;
public String userType; //(Admin / Client)
public boolean canUpdate; //(true / false)
@transient
public static Model.Finder<ObjectId, User> find = new Model.Finder<ObjectId, User>(ObjectId.class, User.class);
public static List showAllUsers(){
return User.find.all();
}
public static List showAllAdminUsers(){
return User.find.filter("userType", "Admin").asList();
}
public static List showAllClientUsers(){
return User.find.filter("userType", "Client").asList();
}
}
Controller:-
public class Application extends Controller {
public static Result showUser(){
List user = User.find.showAllUsers();
System.out.println("All User Count : "+user.size() );
return null;
}
public static Result showAdminUser(){
List user = User.find.showAllAdminUsers();
System.out.println("All Admin Count : "+user.size() );
return null;
}
public static Result showClientUsers(){
List user = User.find.showAllClientUsers();
System.out.println("All Client Count : "+user.size() );
return null;
}
}
All User Count : 10
All Admin Count : 5
All Client Count : 5
All User Count : 10
All Admin Count : 1
All Client Count : 1
I don't know why? it is happen.
if you known the reason please help me.
Thanking you!
by
Balamanikandan.T
Hi,
I have a model with a geo-coordinate index:
@Indexed(IndexDirection.GEO2D)
public Double[] coordinate = new Double[2];
However, when I check whether the index is there, I get:
> db.providers.getIndexes()
[ ]
This is because Datastore.ensureIndexes() hasn't been called in MorphiaPlugin (see http://code.google.com/p/morphia/wiki/Datastore#Ensure_Indexes_and_Caps)
Steve
hai!
This is my User model
public class User extends Model{
@id
public ObjectId id;
public String userType; // (Admin / User / Others / Employee)
...
public static Model.Finder<ObjectId, User> find()
{
return new Model.Finder<ObjectId, User>(ObjectId.class, User.class);
}
// I need to filter Admin or User
// how to use Or filter this or that
public static List<User> userNameFind(Object userName1)
{
List<User> nnUser = User.find().filter("Type", {"Admin"||"User"}).asList();
return nnUser;
}
}
This is not working
Do you known where i made mistake please guide me...
Thanking you!
by
Balamanikandan.T
(bdeveloper01)
I am not able to use the plugin with Scala 2.10-RC1
val appDependencies = Seq(
// Add your project dependencies here,
javaCore,
"leodagdag" % "play2-morphia-plugin_2.9.1" % "0.0.9"
)
Please help!
Hi,
I have an object with a Blob which I save on upload:
MultipartFormData body = request().body().asMultipartFormData();
FilePart picture = body.getFile("thumbnail");
...
// populate other fields of the obj with the form
...
if (picture != null) {
File file = picture.getFile();
obj.setThumbnailUpload(file);
}
obj.save();
This will work when I first upload the file. However, when I subsequently re-save the deal without updating the picture it will say it lost a chunk. What do I need to do to not overwrite the blob?
[ERROR] [10/19/2012 00:04:24.640] [promise-akka.actor.default-dispatcher-170] [akka.dispatch.Dispatcher] can't find a chunk! file id: 507f89250364707ed55a816f chunk: 0
com.mongodb.MongoException: can't find a chunk! file id: 507f89250364707ed55a816f chunk: 0
at com.mongodb.gridfs.GridFSDBFile.getChunk(GridFSDBFile.java:103)
at com.mongodb.gridfs.GridFSDBFile$MyInputStream.read(GridFSDBFile.java:151)
at com.mongodb.gridfs.GridFSDBFile$MyInputStream.read(GridFSDBFile.java:142)
at play.api.libs.iteratee.Enumerator$$anonfun$fromStream$2.apply(Iteratee.scala:980)
at play.api.libs.iteratee.Enumerator$$anonfun$fromStream$2.apply(Iteratee.scala:978)
at play.api.libs.iteratee.Enumerator$$anon$17$$anonfun$22.apply(Iteratee.scala:949)
at play.api.libs.iteratee.Enumerator$$anon$17$$anonfun$22.apply(Iteratee.scala:948)
at play.api.libs.iteratee.Cont$$anon$21.fold(Iteratee.scala:341)
at play.api.libs.iteratee.Iteratee$$anon$18$$anonfun$fold$1.apply(Iteratee.scala:16)
at play.api.libs.iteratee.Iteratee$$anon$18$$anonfun$fold$1.apply(Iteratee.scala:16)
at play.api.libs.concurrent.AkkaPromise$$anonfun$flatMap$1.apply(Akka.scala:58)
at play.api.libs.concurrent.AkkaPromise$$anonfun$flatMap$1.apply(Akka.scala:57)
at akka.dispatch.Future$$anonfun$onSuccess$1.apply(Future.scala:484)
at akka.dispatch.Future$$anonfun$onSuccess$1.apply(Future.scala:483)
at akka.dispatch.KeptPromise$$anonfun$onComplete$2.apply$mcV$sp(Future.scala:956)
at akka.dispatch.Future$$anon$4$$anonfun$run$1.apply$mcV$sp(Future.scala:386)
at akka.dispatch.Future$$anon$4$$anonfun$run$1.apply(Future.scala:378)
at akka.dispatch.Future$$anon$4$$anonfun$run$1.apply(Future.scala:378)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
at akka.dispatch.Future$$anon$4.run(Future.scala:378)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:94)
at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Thanks
Steve
MorphiaLoggerFactory.reset();
MorphiaLoggerFactory.registerLogger(SLF4JLogrImplFactory.class);
That logger issue spent me several hours, until I found your code and article, thank you!
How should I install version 0.0.14? I tried the following on Build.scala with no success:
val appDependencies = Seq(
"leodagdag" % "play2-morphia-plugin_2.10.0" % "0.0.14"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers ++= Seq(Resolvers.leoDagDagRepository)
)
object Resolvers {
val leoDagDagRepository = "LeoDagDag repository" at "http://leodagdag.github.com/repository/"
}
I also tried it with Resolver.ivyStylePatterns but it couldn't find it.
The yabe sample is not working either. It would be good if it was always updated together with the source code so it'd be straight forward to figure out how to install it.
I set morphia.id.type=Long in conf file already. then model code is here:
@Entity("post")
public class PostModel extends Model{
@Id
public Long id;
@Required
public String name;
public String url;
public String[] imgUrl;
...
}
I found there's no way to get Model's id if remove the field "id"(not like play-morphia), but if declare the field "id", the _id will be generated as a objectId when saving that causes driver mapping error.
How could I really use Long as id type, automatically generated?
The Model#Finder extends com.google.code.morphia.query.QueryImpl
which is a mutable class (not like the ebean one).
So we can't declare a public static finder instance to reuse it all the time.
For the example you provided, the Post
class has a finder. If you run:
Post.find.filter("_id", new ObjectId("someid"))
Then:
Post.find.asList
You will find the later one only return one instance.
So we have to declare the find
as:
public static Finder find() {
return new Finder();
}
Hi,
Thanks for pushing out v0.0.7. The plugin doesn't seem to compile against Play 2.0.4. This is the error message after doing a clean then compile.
[error] warning: leodagdag/play2morphia/MorphiaPlugin.class(leodagdag/play2morphia:MorphiaPlugin.class): major version 51 is newer than 50, the highest major version supported by this compiler.
[error] It is recommended that the compiler be upgraded.
[error] warning: leodagdag/play2morphia/Model.class(leodagdag/play2morphia:Model.class): major version 51 is newer than 50, the highest major version supported by this compiler.
[error] It is recommended that the compiler be upgraded.
[error] warning: leodagdag/play2morphia/Blob.class(leodagdag/play2morphia:Blob.class): major version 51 is newer than 50, the highest major version supported by this compiler.
Is v0.0.7 compatible with Play 2.0.4?
Thanks
Steve
Hi
I have a question?
can i install morphia-plugin in latest playframework 2.3.8?
Thanks for help me.
Anybody got this working with new module system?
Hi,
When I try to run yabe example as well installing to new project, I get unresolved dependency error. Would you please tell me how to fix it. I presume the concerned repo is displaced?
Please have a look at below for the whole error log for more information.
Thanks in advance.
Fahied
[warn] problem while downloading module descriptor: http://repo1.maven.org/maven2/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom: invalid sha1: expected=bf6942f274dd31a7a2da15cffbe1389cc8e7a84a computed=97693070b018e070dc9aad71946e8324339b7c32 (130ms)
[warn] problem while downloading module descriptor: http://repo1.maven.org/maven2/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom: invalid sha1: expected=bf6942f274dd31a7a2da15cffbe1389cc8e7a84a computed=97693070b018e070dc9aad71946e8324339b7c32 (129ms)
[warn] module not found: com.thoughtworks.proxytoys#proxytoys;1.0
[warn] ==== local: tried
[warn] /Users/spider/developer/Tools/play-2.0.3/framework/../repository/local/com.thoughtworks.proxytoys/proxytoys/1.0/ivys/ivy.xml
[warn] ==== Typesafe Releases Repository: tried
[warn] http://repo.typesafe.com/typesafe/releases/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom
[warn] ==== Typesafe Snapshots Repository: tried
[warn] http://repo.typesafe.com/typesafe/snapshots/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom
[warn] ==== LeoDagDag repository: tried
[warn] http://leodagdag.github.com/repository/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom
[warn] ==== Morphia repository: tried
[warn] http://morphia.googlecode.com/svn/mavenrepo/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/com/thoughtworks/proxytoys/proxytoys/1.0/proxytoys-1.0.pom
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.thoughtworks.proxytoys#proxytoys;1.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Hai!
Model
public class User extends Model{
public ObjectId id;
public String userName;
public String userType; //(Admin / Client)
public boolean canUpdate; //(true / false)
@transient
public static Model.Finder<ObjectId, User> find = new Model.Finder<ObjectId, User>(ObjectId.class, User.class);
public static List showAllUsers(){
return User.find.all();
}
public static List showAllAdminUsers(){
return User.find.filter("userType", "Admin").asList();
}
public static List showAllClientUsers(){
return User.find.filter("userType", "Client").asList();
}
}
Controller:-
public class Application extends Controller {
public static Result showUser(){
List user = User.find.showAllUsers();
System.out.println("All User Count : "+user.size() );
return showAdminUser();
}
public static Result showAdminUser(){
List user = User.find.showAllAdminUsers();
System.out.println("All Admin Count : "+user.size() );
return showClientUsers();
}
public static Result showClientUsers(){
List user = User.find.showAllClientUsers();
System.out.println("All Client Count : "+user.size() );
return showCanUpdate();
}
public static Result showCanUpdate(){
List user = User.find.filter("userType", "Admin").filter("canUpdate", true).asList();
System.out.println("All Admin Can Update : "+user.size() );
return null;
}
}
All User Count : 10
All Admin Count : 5
All Client Count : 5
All Admin Can Update : 0
All User Count : 10
All Admin Count : 1
All Client Count : 1
All Admin Can Update : 0
I don't know why? this Always 0 count. "All Admin Can Update : 0"
if you known the reason please help me.
Thanking you!
by
Balamanikandan.T
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.