SlideShare a Scribd company logo
1 of 24
RESTful Java Play Framework
Simple ebean CRUD
Prerequisite
Play Framework 2.4.x
Download here
Setup the play framework (installing)
JDK 1.8 (or later)
IntelliJ CE
Create New Project
Through Command Line type: activator new
Create New Project
Open IntelliJ and import the new project
Create New Project
choose import project
from external: SBT
And next just let the
default value, click
finish
Create New Project
Here is the
structure of Play
framework
The Objective
Create RESTful with Java Play Framework
Build basic API: GET, POST, PUT, DELETE
Build parameterize API
Use ORM (Object Relational Mapping) : Ebean
Configuration
plugin.sbt at project/ folder, uncomment or add
this:
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0”)
Configuration
build.sbt (root)
name := """Java-Play-RESTful-JPA"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
routesGenerator := InjectedRoutesGenerator
Configuration
conf/application.conf, add:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
For simple purpose (development), we use mem
as database on memory.
Configuration
Still on conf/application.conf, add:
ebean.default="models.*”
This is as ORM related object model mapping
Create Simple POST
At conf/routes, we add url for API access.
POST /person controllers.Application.addPerson()
The method is POST, the access to this API is
{baseurl}/person. For this example, we use json
format for body.
The process is on controllers/Application.java
method addPerson()
Create models
Create models/Person.java
package models;
import com.avaje.ebean.Model;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Person extends Model{
@Id
public Long id;
public String name;
public static Finder<Integer, Person> find
= new Finder<Integer, Person>(Integer.class, Person.class);
}
Create controller
Add the method addPerson() at controller
application.java
@BodyParser.Of(BodyParser.Json.class)
public Result addPerson(){
JsonNode json = request().body().asJson();
Person person = Json.fromJson(json, Person.class);
if (person.toString().equals("")){
return badRequest("Missing parameter");
}
person.save();
return ok();
}
Let’s try
First create run configuration: Choose SBT Task and chose for the Task
is run.
Execute Run.
Because of the first
time server start, it
need trigger script
evolution execute first
by open the base url
on the browser and
apply the script.
Let’s try
Let curl from command line:
curl -X POST -H "Content-Type: application/json" -H "Cache-Control:
no-cache" -d '{
"name":"Faren"
}' 'http://localhost:9000/person’
It will store one object Person.
Create Simple GET
Add url on routes
GET /person controllers.Application.listPerson()
Add controller Application.java
public Result listPerson(){
List<Person> persons = new Model.Finder(String.class,
Person.class).all();
return ok(toJson(persons));
}
Let’s try
No need to Rerun the server. Just curl the GET
method from command line.
curl -X GET -H "Cache-Control: no-cache" 'http://localhost:9000/person’
The Output:
[{"id":1,"name":"Faren"},{"id":33,"name":"Faren"}]
Get single record
Add url on routes
GET /person/:id controllers.Application.getPerson(id: Int)
Add controller Application.java
public Result getPerson(int id){
Person person = Person.find.byId(id);
if (person == null){
return notFound("User not found!");
}
return ok(toJson(person));
}
Let’s try
Run curl on command line:
curl -X GET -H "Cache-Control: no-cache" 'http://localhost:9000/person/1’
The Output:
{
"id": 1,
"name": "Faren"
}
PUT
Add url on routes
PUT /person/:id controllers.Application.updatePerson(id: Int)
Add controller Application.java
@BodyParser.Of(BodyParser.Json.class)
public Result updatePerson(int id){
Person person = Person.find.byId(id);
if (person == null){
return notFound("User not found");
}
JsonNode json = request().body().asJson();
Person personToBe = Json.fromJson(json, Person.class);
person = personToBe;
person.update();
return ok();
}
DELETE
Add url on routes
DELETE /person/:id controllers.Application.deletePerson(id: Int)
Add controller Application.java
public Result deletePerson(int id){
Person person = Person.find.byId(id);
if (person == null){
return notFound("User not found");
}
person.delete();
return ok();
}
API with parameter
For example:
http://localhost:9000/searchperson?name=Faren
Add url on routes
GET /searchperson controllers.Application.searchPerson(name: String)
Add controller Application.java
public Result searchPerson(String name){
List<Person> persons = Person.find.where()
.like("name", "%"+name+"%")
.findList();
if (persons == null){
return notFound("User not found!");
}
return ok(toJson(persons));
}
Full Source Code:
https://github.com/faren/java-play-ebean

More Related Content

What's hot

Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debuggingUtkarsh Mankad
 
모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)Jongwon Kim
 
Robot Framework :: Demo login application
Robot Framework :: Demo login applicationRobot Framework :: Demo login application
Robot Framework :: Demo login applicationSomkiat Puisungnoen
 
LoadRunner Performance Testing
LoadRunner Performance TestingLoadRunner Performance Testing
LoadRunner Performance TestingAtul Pant
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Your first dive into systemd!
Your first dive into systemd!Your first dive into systemd!
Your first dive into systemd!Etsuji Nakai
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Doxygen - Source Code Documentation Generator Tool
Doxygen -  Source Code Documentation Generator ToolDoxygen -  Source Code Documentation Generator Tool
Doxygen - Source Code Documentation Generator ToolGuo Albert
 
Improving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesImproving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesHassan Abid
 
From DTrace to Linux
From DTrace to LinuxFrom DTrace to Linux
From DTrace to LinuxBrendan Gregg
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
강좌 개요
강좌 개요강좌 개요
강좌 개요chcbaram
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKEAbhishek Yadav
 
Run Qt on Linux embedded systems using Yocto
Run Qt on Linux embedded systems using YoctoRun Qt on Linux embedded systems using Yocto
Run Qt on Linux embedded systems using YoctoMarco Cavallini
 
Comparative Analysis Of GoLang Testing Frameworks
Comparative Analysis Of GoLang Testing FrameworksComparative Analysis Of GoLang Testing Frameworks
Comparative Analysis Of GoLang Testing FrameworksDushyant Bhalgami
 
Introduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt ControllerIntroduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt ControllerThe Linux Foundation
 

What's hot (20)

Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)
 
Robot Framework :: Demo login application
Robot Framework :: Demo login applicationRobot Framework :: Demo login application
Robot Framework :: Demo login application
 
LoadRunner Performance Testing
LoadRunner Performance TestingLoadRunner Performance Testing
LoadRunner Performance Testing
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Your first dive into systemd!
Your first dive into systemd!Your first dive into systemd!
Your first dive into systemd!
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Doxygen - Source Code Documentation Generator Tool
Doxygen -  Source Code Documentation Generator ToolDoxygen -  Source Code Documentation Generator Tool
Doxygen - Source Code Documentation Generator Tool
 
Init of Android
Init of AndroidInit of Android
Init of Android
 
Improving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesImproving app performance with Kotlin Coroutines
Improving app performance with Kotlin Coroutines
 
From DTrace to Linux
From DTrace to LinuxFrom DTrace to Linux
From DTrace to Linux
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
강좌 개요
강좌 개요강좌 개요
강좌 개요
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Run Qt on Linux embedded systems using Yocto
Run Qt on Linux embedded systems using YoctoRun Qt on Linux embedded systems using Yocto
Run Qt on Linux embedded systems using Yocto
 
Comparative Analysis Of GoLang Testing Frameworks
Comparative Analysis Of GoLang Testing FrameworksComparative Analysis Of GoLang Testing Frameworks
Comparative Analysis Of GoLang Testing Frameworks
 
Introduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt ControllerIntroduction of AMD Virtual Interrupt Controller
Introduction of AMD Virtual Interrupt Controller
 
Android Thread
Android ThreadAndroid Thread
Android Thread
 

Similar to Java Play RESTful ebean

Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPAFaren faren
 
Projeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfProjeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfAdrianoSantos888423
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Yevgeniy Brikman
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Neelkanth Sachdeva
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Knoldus Inc.
 
Rally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetupRally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetupAnanth Padmanabhan
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in detailsMax Klymyshyn
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript Glenn Stovall
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...DynamicInfraDays
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Tino Isnich
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.xYiguang Hu
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platformsAyush Sharma
 

Similar to Java Play RESTful ebean (20)

Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Projeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfProjeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdf
 
Serverless Java on Kubernetes
Serverless Java on KubernetesServerless Java on Kubernetes
Serverless Java on Kubernetes
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
 
Rally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetupRally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetup
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 

Recently uploaded

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 

Recently uploaded (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 

Java Play RESTful ebean

  • 1. RESTful Java Play Framework Simple ebean CRUD
  • 2. Prerequisite Play Framework 2.4.x Download here Setup the play framework (installing) JDK 1.8 (or later) IntelliJ CE
  • 3. Create New Project Through Command Line type: activator new
  • 4. Create New Project Open IntelliJ and import the new project
  • 5. Create New Project choose import project from external: SBT And next just let the default value, click finish
  • 6. Create New Project Here is the structure of Play framework
  • 7. The Objective Create RESTful with Java Play Framework Build basic API: GET, POST, PUT, DELETE Build parameterize API Use ORM (Object Relational Mapping) : Ebean
  • 8. Configuration plugin.sbt at project/ folder, uncomment or add this: addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0”)
  • 9. Configuration build.sbt (root) name := """Java-Play-RESTful-JPA""" version := "1.0-SNAPSHOT" lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean) scalaVersion := "2.11.6" libraryDependencies ++= Seq( javaJdbc, cache, javaWs ) routesGenerator := InjectedRoutesGenerator
  • 11. Configuration Still on conf/application.conf, add: ebean.default="models.*” This is as ORM related object model mapping
  • 12. Create Simple POST At conf/routes, we add url for API access. POST /person controllers.Application.addPerson() The method is POST, the access to this API is {baseurl}/person. For this example, we use json format for body. The process is on controllers/Application.java method addPerson()
  • 13. Create models Create models/Person.java package models; import com.avaje.ebean.Model; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class Person extends Model{ @Id public Long id; public String name; public static Finder<Integer, Person> find = new Finder<Integer, Person>(Integer.class, Person.class); }
  • 14. Create controller Add the method addPerson() at controller application.java @BodyParser.Of(BodyParser.Json.class) public Result addPerson(){ JsonNode json = request().body().asJson(); Person person = Json.fromJson(json, Person.class); if (person.toString().equals("")){ return badRequest("Missing parameter"); } person.save(); return ok(); }
  • 15. Let’s try First create run configuration: Choose SBT Task and chose for the Task is run. Execute Run. Because of the first time server start, it need trigger script evolution execute first by open the base url on the browser and apply the script.
  • 16. Let’s try Let curl from command line: curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{ "name":"Faren" }' 'http://localhost:9000/person’ It will store one object Person.
  • 17. Create Simple GET Add url on routes GET /person controllers.Application.listPerson() Add controller Application.java public Result listPerson(){ List<Person> persons = new Model.Finder(String.class, Person.class).all(); return ok(toJson(persons)); }
  • 18. Let’s try No need to Rerun the server. Just curl the GET method from command line. curl -X GET -H "Cache-Control: no-cache" 'http://localhost:9000/person’ The Output: [{"id":1,"name":"Faren"},{"id":33,"name":"Faren"}]
  • 19. Get single record Add url on routes GET /person/:id controllers.Application.getPerson(id: Int) Add controller Application.java public Result getPerson(int id){ Person person = Person.find.byId(id); if (person == null){ return notFound("User not found!"); } return ok(toJson(person)); }
  • 20. Let’s try Run curl on command line: curl -X GET -H "Cache-Control: no-cache" 'http://localhost:9000/person/1’ The Output: { "id": 1, "name": "Faren" }
  • 21. PUT Add url on routes PUT /person/:id controllers.Application.updatePerson(id: Int) Add controller Application.java @BodyParser.Of(BodyParser.Json.class) public Result updatePerson(int id){ Person person = Person.find.byId(id); if (person == null){ return notFound("User not found"); } JsonNode json = request().body().asJson(); Person personToBe = Json.fromJson(json, Person.class); person = personToBe; person.update(); return ok(); }
  • 22. DELETE Add url on routes DELETE /person/:id controllers.Application.deletePerson(id: Int) Add controller Application.java public Result deletePerson(int id){ Person person = Person.find.byId(id); if (person == null){ return notFound("User not found"); } person.delete(); return ok(); }
  • 23. API with parameter For example: http://localhost:9000/searchperson?name=Faren Add url on routes GET /searchperson controllers.Application.searchPerson(name: String) Add controller Application.java public Result searchPerson(String name){ List<Person> persons = Person.find.where() .like("name", "%"+name+"%") .findList(); if (persons == null){ return notFound("User not found!"); } return ok(toJson(persons)); }