agile software developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf ·...
TRANSCRIPT
![Page 1: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/1.jpg)
Produced by
Department of Computing, Maths & PhysicsWaterford Institute of Technologyhttp://www.wit.ie
http://elearning.wit.ie
Agile Software Development
Eamonn de Leastar ([email protected])
![Page 2: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/2.jpg)
Play 2
![Page 3: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/3.jpg)
Web Applications - Request/Response
• Request - http request emitted by browser as a result ot url in address bar, link, button or form submission on page
• Response - web page returned from service to be presented in browser
Http
Http Client Server
![Page 4: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/4.jpg)
Web Applications - MVC
• Model View Controller is a generally accepted pattern or separation of concerns within the server
• Model: Core application domain model + database persistence
• View: User Experience
• Controller: Directly handle all requests, mediate with Model, build and assemble the response using the views
![Page 5: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/5.jpg)
PLAY FRAMEWORK
4
Request/Response Lifecycle
Routing Controller ViewsBrowser Browser
REQUEST RenderingCreation of a dynamic content
Match url to class/method
Handle and process parameters
Define how the page will look; use
templates if necessary
![Page 6: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/6.jpg)
MVC in Play
• Router: examine incoming requests and match to corresponding Controller/Action
• Action: a method in the controller
![Page 7: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/7.jpg)
Routes File Example (Pacemaker)# UI!GET / controllers.Accounts.index()GET /signup controllers.Accounts.signup()GET /login controllers.Accounts.login()GET /logout controllers.Accounts.logout()POST /register controllers.Accounts.register()POST /authenticate controllers.Accounts.authenticate()!GET /dashboard controllers.Dashboard.index()GET /upload controllers.Dashboard.uploadActivityForm()POST /submitactivity controllers.Dashboard.submitActivity()!# API!GET /api/users controllers.PacemakerAPI.users()DELETE /api/users controllers.PacemakerAPI.deleteAllUsers()POST /api/users controllers.PacemakerAPI.createUser()!GET /api/users/:id controllers.PacemakerAPI.user(id: Long)DELETE /api/users/:id controllers.PacemakerAPI.deleteUser(id: Long)PUT /api/users/:id controllers.PacemakerAPI.updateUser(id: Long)!GET /api/users/:userId/activities controllers.PacemakerAPI.activities(userId: Long)POST /api/users/:userId/activities controllers.PacemakerAPI.createActivity(userId: Long)!GET /api/users/:userId/activities/:activityId controllers.PacemakerAPI.activity(userId: Long, activityId:Long)DELETE /api/users/:userId/activities/:activityId controllers.PacemakerAPI.deleteActivity(userId: Long, activityId:Long)PUT /api/users/:userId/activities/:activityId controllers.PacemakerAPI.updateActivity(userId: Long, activityId:Long)!# Map static resources from the /public folder to the /assets URL pathGET /assets/*file controllers.Assets.at(path="/public", file)
![Page 8: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/8.jpg)
Routes - UI# UI!GET / controllers.Accounts.index()GET /signup controllers.Accounts.signup()GET /login controllers.Accounts.login()GET /logout controllers.Accounts.logout()POST /register controllers.Accounts.register()POST /authenticate controllers.Accounts.authenticate()!GET /dashboard controllers.Dashboard.index()GET /upload controllers.Dashboard.uploadActivityForm()POST /submitactivity controllers.Dashboard.submitActivity()
• Routes to deliver UI
• Each of these routes appears in views
• Each of these actions generates and returns a complete HTML page
![Page 9: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/9.jpg)
Routes - API# API!GET /api/users controllers.PacemakerAPI.users()DELETE /api/users controllers.PacemakerAPI.deleteAllUsers()POST /api/users controllers.PacemakerAPI.createUser()!GET /api/users/:id controllers.PacemakerAPI.user(id: Long)DELETE /api/users/:id controllers.PacemakerAPI.deleteUser(id: Long)PUT /api/users/:id controllers.PacemakerAPI.updateUser(id: Long)!GET /api/users/:userId/activities controllers.PacemakerAPI.activities(userId: Long)POST /api/users/:userId/activities controllers.PacemakerAPI.createActivity(userId: Long)!GET /api/users/:userId/activities/:activityId controllers.PacemakerAPI.activity(userId: Long, activityId:Long)DELETE /api/users/:userId/activities/:activityId controllers.PacemakerAPI.deleteActivity(userId: Long, activityId:Long)PUT /api/users/:userId/activities/:activityId controllers.PacemakerAPI.updateActivity(userId: Long, activityId:Long)
• Routes to deliver API
• Each of these routes appears in views an API Request
• Each of these actions generates and returns a JSON payload
![Page 10: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/10.jpg)
Role of Controller
![Page 11: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/11.jpg)
Controller Lifecycle
![Page 12: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/12.jpg)
Controller Lifecycle (detail)
![Page 13: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/13.jpg)
Controller Lifecycle with Content
![Page 14: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/14.jpg)
Play Project Anatomy
app
!
conf
public
build.sbt
![Page 15: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/15.jpg)
App
controllers
models
views
![Page 16: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/16.jpg)
conf
![Page 17: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/17.jpg)
public
![Page 18: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/18.jpg)
build.sbt
name := "pacemakerplay"!version := "1.0-SNAPSHOT"!libraryDependencies ++= Seq( javaJdbc, javaEbean, cache, "net.sf.flexjson" % "flexjson" % "3.1", "postgresql" % "postgresql" % "9.1-901-1.jdbc4") !play.Project.playJavaSettings
![Page 19: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/19.jpg)
pacemakerplay
![Page 20: Agile Software Developmentedeleastar.github.io/agile-software-dev/topic12/talk-2/a-play-2.pdf · Agile Software Development Eamonn de Leastar (edeleastar@wit.ie) Play 2. Web Applications](https://reader036.vdocuments.mx/reader036/viewer/2022070112/60572cb7a411703ded000b4b/html5/thumbnails/20.jpg)
Except where otherwise noted, this content is licensed under a Creative Commons Attribution-NonCommercial 3.0 License. !For more information, please see http://creativecommons.org/licenses/by-nc/3.0/