groovy & grails - lecture 10
Upcoming SlideShare
Loading in...5
×
 

groovy & grails - lecture 10

on

  • 471 views

SVN & google code hosting

SVN & google code hosting
More on GSP
Including third parties libraries
Ajax
Runtime environment
Domains

Statistics

Views

Total Views
471
Views on SlideShare
470
Embed Views
1

Actions

Likes
0
Downloads
11
Comments
0

1 Embed 1

https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • for non-Cuban...\n
  • for non-Cuban...\n
  • for non-Cuban...\n
  • for non-Cuban...\n
  • for non-Cuban...\n
  • for non-Cuban...\n
  • \n
  • we could use other SCM, but svn is more evolved than cvs, widely used, offered by google code, integrated in eclipse or on command line\n
  • \n
  • \n
  • \n
  • \n
  • no trunk/\nacceptpermently\n
  • no trunk/\nacceptpermently\n
  • no trunk/\nacceptpermently\n
  • no trunk/\nacceptpermently\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • as soon as test work, for example\nseveral time a day\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • eop 6-solutions -> jar with build.xml\n
  • eop 6-solutions -> jar with build.xml\n
  • eop 6-solutions -> jar with build.xml\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • _ in file name, but not in template tag attribute\n
  • _ in file name, but not in template tag attribute\n
  • _ in file name, but not in template tag attribute\n
  • Although the form part does not change\nLimited here for the volume, but can be much more heavy\n
  • \n
  • Asynchronous javascript and xml\n
  • Asynchronous javascript and xml\n
  • Asynchronous javascript and xml\n
  • Asynchronous javascript and xml\n
  • Asynchronous javascript and xml\n
  • \n
  • \n
  • \n
  • test=test\ndevelopment=run-app\nproduction=packaged and deployed\n
  • We can change, if you have access to the web during development\n
  • \n
  • \n
  • \n
  • \n
  • def uniprotXmlService in controller will point directly to this bean\n
  • to change from proteins problems...\n
  • problem is simple yet illustrates plenty of aspects of a web application\ngrails: twitter in 40 minutes springsource webinar\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • more fields with whatever classes are possible are possible\n
  • but not very useful\nindeed, you can make SQL call\n(memory DB by default, but we’ll see how to put on file, postgres, mySql...)\n
  • list, add, delete, update...\n
  • \n
  • we’ll see how to generate explicitly all of them later in order to be modified\n
  • we’ll see how to generate explicitly all of them later in order to be modified\n
  • we’ll see how to generate explicitly all of them later in order to be modified\n
  • we’ll see how to generate explicitly all of them later in order to be modified\n
  • \n
  • \n
  • \n
  • \n
  • unique username with given characters\nemail valid\nnon empty first name\n
  • more fields with whatever classes are possible are possible\n
  • Next time: foreign key (Person Person Message)\nCriteria\ndatabase persistence\n

groovy & grails - lecture 10 groovy & grails - lecture 10 Presentation Transcript

  • Groovy: Efficiency Oriented ProgrammingLecture 10Master Proteomics & Bioinformatics - University of GenevaAlexandre Masselot - summer 2011
  • Agenda‣ SVN & google code hosting‣ More on GSP‣ Including third parties libraries‣ Ajax‣ Runtime environment‣ Domains
  • SCM‣ Code evolve in time
  • SCM‣ Code evolve in time‣ Source code is shared
  • SCM‣ Code evolve in time‣ Source code is shared‣ Source Code Management system host code + versioning
  • SCM‣ Code evolve in time‣ Source code is shared‣ Source Code Management system host code + versioning‣ Many solutions exist: CVS, SVN, GIT, SourceSafe...
  • SCM‣ Code evolve in time‣ Source code is shared‣ Source Code Management system host code + versioning‣ Many solutions exist: CVS, SVN, GIT, SourceSafe...‣ SVN is a client/server solution
  • SCM‣ Code evolve in time‣ Source code is shared‣ Source Code Management system host code + versioning‣ Many solutions exist: CVS, SVN, GIT, SourceSafe...‣ SVN is a client/server solution‣ Server can be in-house
  • SCM‣ Code evolve in time‣ Source code is shared‣ Source Code Management system host code + versioning‣ Many solutions exist: CVS, SVN, GIT, SourceSafe...‣ SVN is a client/server solution‣ Server can be in-house‣ Free solution for open source http://code.google.com/hosting/
  • make an google account
  • Create ProjectProject name: geop-demoProject summary: A demo project for GEOP courseProject description: geop demo codeVersion control system: SubversionSource code license:  New BSD LicenseUse a separate content license:license...Project labels:Create project...Project name must start with a lowercase letter, followed by lowercase letters, digits, and dashes, with nospaces. This will be part of your projects URL and cannot be changed later.Project summary will be shown whenever the projects name is displayed.Project description is the main content of your projects home page. You may use wiki markup.Version control system selects the type of your projects repository. Learn more.Licenses determine how others may build upon your work. Code and documentation may be distributed underseparate licenses.Project labels help classify your project so others can easily find it or browse projects by label.
  • Google proposes command line commandsWe’ll see how to integrate svn into eclipse
  • Command-line accessIf you plan to make changes, use this command to check out the code as yourself using HTTPS:# Project members authenticate over HTTPS to allow committing changes.svn checkout https://geop-demo.googlecode.com/svn/trunk/ geop-demo --username alexandre.masselotWhen prompted, enter your generated googlecode.com password.Use this command to anonymously check out the latest project source code:# Non-members may check out a read-only working copy anonymously over HTTP.svn checkout http://geop-demo.googlecode.com/svn/trunk/ geop-demo-read-onlyGUI and IDE accessThis projects Subversion repository may be accessed using many different client programs and plug-ins. See your clientsdocumentation for more information.
  • Google code offers for “free”‣ SVN repository
  • Google code offers for “free”‣ SVN repository‣ Managing contributors to a project
  • Google code offers for “free”‣ SVN repository‣ Managing contributors to a project‣ Wiki
  • Google code offers for “free”‣ SVN repository‣ Managing contributors to a project‣ Wiki‣ Ticketing system
  • Google code offers for “free”‣ SVN repository‣ Managing contributors to a project‣ Wiki‣ Ticketing system‣ Bug reporting
  • Google code offers for “free”‣ SVN repository‣ Managing contributors to a project‣ Wiki‣ Ticketing system‣ Bug reporting‣ Visibility
  • Google code hosting ⇒your code is open source
  • SVN: eclipse or command line
  • Installing svn in Eclipse‣ Help > dashboard > extension - Subversion (subclipse)
  • Installing svn in Eclipse‣ Help > dashboard > extension - Subversion (subclipse)‣ Or command line: installed by default or - sudo apt-get install subversion
  • Eclipse: connecting to the SVN repository‣ menu Window - > open perspective - > SVN repository exploring
  • Eclipse: connecting to the SVN repository‣ menu Window - > open perspective - > SVN repository exploring‣ view SVN repositories - > right click - > new repository location - https://geop-demo.googlecode.com/svn
  • Sharing an existing project to your google code account
  • Sharing an existing project to your google code account‣ Perspective java
  • Sharing an existing project to your google code account‣ Perspective java‣ project right-click - > team - > share project - use specifier folder name trunk/your.project.name
  • ‣ username & password from google page‣ save password check box
  • Commit the project‣ At this stage, the project is only created on the remote server - check with SVN repository exploring perspective - or browse source code from google page
  • Commit the project‣ At this stage, the project is only created on the remote server - check with SVN repository exploring perspective - or browse source code from google page‣ Mark generated file & folder to be ignored from svn - e.g. target/
  • Commit the project‣ At this stage, the project is only created on the remote server - check with SVN repository exploring perspective - or browse source code from google page‣ Mark generated file & folder to be ignored from svn - e.g. target/‣ Right-click > team > add to svn:ignore
  • All eclipse functionalitiescan be replaced by shell commands
  • SVN command line: share project‣ Import original project demo.svn to the repository‣ cd workspace directory svn import -m “initial import” --non-recursive demo.svn https://geop-demo.googlecode.com/svn/trunk/demo.svn‣ Directory itself is not imported, so checkout (with force) svn checkout --force https://geop-demo.googlecode.com/svn/ trunk/demo.svn
  • SVN command line: share project (cont’d) cd demo.svn‣ Add target/ directory to svn:ignore svn propset svn:ignore target .‣ Add other directories to svn svn add $(ls | grep -v target)‣ Commit files svn commit -m "adding all initial files"‣ Back to eclipse, F5 (refresh in package explorer view)
  • Browse your project
  • From google code source page 25
  • SVN for a daily use
  • SVN for a daily use minutely
  • SVN: flow use‣ Checkout out or share an existing project to contribute
  • SVN: flow use‣ Checkout out or share an existing project to contribute‣ Commit changes to the repository
  • SVN: flow use‣ Checkout out or share an existing project to contribute‣ Commit changes to the repository‣ Update changes from repository
  • SVN: flow use‣ Checkout out or share an existing project to contribute‣ Commit changes to the repository‣ Update changes from repository‣ Eclipse: - select project - > right-click - > team - > Synchronize with repository - commit/update/manage conflict
  • SVN: flow use (cont’d)‣ Command linesvn statussvn updatesvn commit -m “my message to describe changes”
  • Commit/update often
  • SVN is more‣ History
  • SVN is more‣ History‣ See contribution from others
  • SVN is more‣ History‣ See contribution from others‣ Tag / branch versions
  • SVN is more‣ History‣ See contribution from others‣ Tag / branch versions‣ Conflict resolution
  • SVN is more‣ History‣ See contribution from others‣ Tag / branch versions‣ Conflict resolution‣ Continuous integration / testing on dedicated server
  • SVN is more‣ History‣ See contribution from others‣ Tag / branch versions‣ Conflict resolution‣ Continuous integration / testing on dedicated server‣ File locking :(
  • SVN is more‣ History‣ See contribution from others‣ Tag / branch versions‣ Conflict resolution‣ Continuous integration / testing on dedicated server‣ File locking :(‣ Integration with tickets
  • SVN is more‣ History‣ See contribution from others‣ Tag / branch versions‣ Conflict resolution‣ Continuous integration / testing on dedicated server‣ File locking :(‣ Integration with tickets‣ Windows integration: http://tortoisesvn.tigris.org/
  • Back to grails... and proteins isoforms
  • Problem: uniprot AC ➙ isoform list in a web application
  • Grails: including a third parties libraries‣ Library is available as a jar (export ➙ .jar)
  • Grails: including a third parties libraries‣ Library is available as a jar (export ➙ .jar)‣ Copy jar in lib/
  • Grails: including a third parties libraries‣ Library is available as a jar (export ➙ .jar)‣ Copy jar in lib/‣ For eclipse completion - right-click - build path - add to build path
  • Get is forms for ac (00:44:01.975)Q70Z44List>Q70Z44-1MQKHSPGPPALALLSQSLLTTGNGDTLIINCPGFGQHRVDPAAFQAVFDRKAIGPVTNYSVATHVNISFTLSAIWNCYSRIHTFNCHHARPWHNQFVQWNPDECGGIKKSGMATENLWLSDVFIEESVDQTPAGLMASMSIVKATSNTISQCGWSASANWTPSISPSMDRARAWRRMSRSFQIHHRTSFRTRREWVLLGIQKRTIKVTVATNQYEQAIFHVAIRRRCRPSPYVVNFLVPSGILIAIDALSFYLPLESGNCAPFKMTVLLGYSVFLLMMNDLLPATSTSSHASLVAPLALMQTPLPAGVYFALCLSLMVGSLLETIFITHLLHVATTQPLPLPRWLHSLLLHCTGQGRCCPTAPQKGNKGPGLTPTHLPGVKEPEVSAGQMPGPGEAELTGGSEWTRAQREHEAQKQHSVELWVQFSHAMDALLFRLYLLFMASSIITVICLWNT>Q70Z44-2MASMSIVKATSNTISQCGWSASANWTPSISPSMDRAERSPSALSPTQVAIRRRCRPSPYVVNFLVPSGILIAIDALSFYLPLESGNCAPFKMTVLLGYSVFLLMMNDLLPATSTSSHASLVRPHPSRDQKRGVYFALCLSLMVGSLLETIFITHLLHVATTQPLPLPRWLHSLLLHCTGQGRCCPTAPQKGNKGPGLTPTHLPGVKEPEVSAGQMPGPGEAELTGGSEWTRAQREHEAQKQHSVELWVQFSHAMDALLFRLYLLFMASSIITVICLWNT
  • Isoforms_v1 -> v5 same controller different views (gsp) for different rendering interaction
  • Isoforms_v1 -> v5 same controller different views (gsp) for different rendering interaction
  • Isoforms_vXController ⇒views/isoforms_vX/ direcgtory with gsp’s
  • IsoformController_v?.groovy def list = { def ac=params.ac def xml=new XmlSlurper() .parseText("http://pir.uniprot.org/uniprot/${ac}.xml".toURL().text).entry UniprotEntrySplicer splicer=[entryXml:xml] def proteins=splicer.buildAllIsoforms().values() asList [proteins: proteins] }
  • v1
  • isoforms_v1/list.gsp<html> <body> <h2>Get is forms for ac (${String.format(%tH:%<tM:%<tS.%<tL, new Date())})</h2> <g:form action="list"> <g:textField name="ac" value="${params.ac}" /> <g:submitButton name="submit" /> </g:form> <h3>List</h3> <g:each in="${proteins}" var="prot"> <pre> ${prot} </pre> </g:each> </body></html>
  • Problem: direct access to /list only
  • v2
  • v2
  • isoforms_v2: add index.gsp<html> <body> <h1>Isoform list application</h1> <h2>Get is forms for ac (${String.format(%tH:%<tM:%<tS.%<tL, new Date())})</h2> <g:form action="list"> <g:textField name="ac" value="${params.ac}" /> <g:submitButton name="submit" /> </g:form> </body></html>
  • Problem: <g:form> is duplicated (DRY!)
  • isoform_v3: use template‣ _form.gsp<h2>Get is forms for ac (${String.format(%tH:%<tM:%<tS.%<tL, new Date())})</h2><g:form action="list"> <g:textField name="ac" value="${params.ac}" /> <g:submitButton name="submit" /></g:form>
  • isoform_v3: use template‣ _form.gsp<h2>Get is forms for ac (${String.format(%tH:%<tM:%<tS.%<tL, new Date())})</h2><g:form action="list"> <g:textField name="ac" value="${params.ac}" /> <g:submitButton name="submit" /></g:form>‣ In index.gsp and list.gsp <g:render template="form" />
  • isoform_v3: use template‣ _form.gsp<h2>Get is forms for ac (${String.format(%tH:%<tM:%<tS.%<tL, new Date())})</h2><g:form action="list"> <g:textField name="ac" value="${params.ac}" /> <g:submitButton name="submit" /></g:form>‣ In index.gsp and list.gsp <g:render template="form" />
  • Problem: all the page is reloaded totally
  • v4
  • Ajax: asynchronous load web browserQ70Z44 submit server isoform/list 47
  • Ajax: asynchronous load web browserQ70Z44 submit server isoform/list 47
  • Ajax: asynchronous load web browserQ70Z44 submit serverList isoform/list>Q70Z44-1MQKHSPGPPALALLSQSLLTTGNGDTLIINCPGFGQHRVDPAAFQAVFDRKAIGPVTNYSVATHVNISFTLSAIWNCYSRIHTFNCHHARPWHNQFVQWNPDECGGIKKSGMATENLWLSDVFIEESVDQTPAGLMASMSIVKATSNTISQCGWSASANWTPSISPSMDRARAWRRMSRSFQIHHRTSFRTRREWVLLGIQKRTIKVTVATNQYEQAIFHVAIRRRCRPSPYVVNFLVPSGILIAIDALSFYLPLESGNCAPFKMTVLLGYSVFLLMMNDLLPATSTSSHASLVAPLALMQTPLPAGVYFALCLSLMVGSLLETIFITHLLHVATTQPLPLPRWLHSLLLHCTGQGRCCPTAPQKGNKGPGLTPTHLPGVKEPEVSAGQMPGPGEAELTGGSEWTRAQREHEAQKQHSVELWVQFSHAMDALLFRLYLLFMASSIITVICLWNT>Q70Z44-2MASMSIVKATSNTISQCGWSASANWTPSISPSMDRAERSPSALSPTQVAIRRRCRPSPYVVNFLVPSGILIAIDALSFYLPLESGNCAPFKMTVLLGYSVFLLMMNDLLPATSTSSHASLVRPHPSRDQKRGVYFALCLSLMVGSLLETIFITHLLHVATTQPLPLPRWLHSLLLHCTGQGRCCPTAPQKGNKGPGLTPTHLPGVKEPEVSAGQMPGPGEAELTGGSEWTRAQREHEAQKQHSVELWVQFSHAMDALLFRLYLLFMASSIITVICLWNT 47
  • isoform_v4/index.gsp<html> <head> <g:javascript library="prototype" /> </head> <body> <h2>Get is forms for ac (${String.format(%tH:%<tM:%<tS.%<tL, new Date())})</h2> <!-- g:formRemote stands for an ajax form --> <g:formRemote name="listForm" url="[action:list]"update="isoforms-list"> <g:textField name="ac" value="${params.ac}" /> <g:submitButton name="submit" /> </g:formRemote> <!-- the target element of the form --> <div id="isoforms-list"/> </body></html>
  • isoform_v4/list.gsp<h3>List</h3><g:each in="${proteins}" var="prot"> <pre>${prot} </pre></g:each>
  • Twitter 1
  • People post messages and follow others
  • database (domain)+ controller (actions) + views (web)
  • Domain: Person & Message
  • Domain: bean definition + database storage
  • Person domain‣ Create the database entry + bean class grails create-domain-class Person project > right-click > grails > create-domain-class Person
  • Person domain‣ Create the database entry + bean class grails create-domain-class Person project > right-click > grails > create-domain-class Person‣ Files created: ./grails-app/domain/eop/lec10/twitter/Person.groovy ./test/unit/eop/lec10/twitter/PersonTests.groovy
  • Person.groovy‣ Created class package eop.lec10.twitter class Person { static constraints = { } }
  • Person.groovy
  • Person.groovy‣ Enriched with fields package eop.lec10.twitter class Person { String username String firstName String lastName String email Date dateCreated static constraints = { } }
  • run-app ⇒ database + table created
  • Web access: need controller + views
  • Scaffolding is pure magic
  • PersonController.groovycreate-controller Person
  • PersonController.groovycreate-controller Person‣ grails-app/controller/PersonController.groovy:package eop.lec10.twitterclass PersonController { def scaffold = true}
  • PersonController.groovy create-controller Person‣ grails-app/controller/PersonController.groovy: package eop.lec10.twitter class PersonController { def scaffold = true }‣ scaffold generate all default action & view implicitely
  • PersonController.groovy create-controller Person‣ grails-app/controller/PersonController.groovy: package eop.lec10.twitter class PersonController { def scaffold = true }‣ scaffold generate all default action & view implicitely
  • http://localhost:8080/eop.lec10.twitter/person‣ Default url is redirected on the list page
  • http://localhost:8080/eop.lec10.twitter/person‣ Default url is redirected on the list page
  • http://localhost:8080/eop.lec10.twitter/person‣ Entering a new Person lucky luke
  • http://localhost:8080/eop.lec10.twitter/person‣ Entering a new Person lucky luke
  • http://localhost:8080/eop.lec10.twitter/person‣ Entering a new Person lucky luke
  • http://localhost:8080/eop.lec10.twitter/person
  • http://localhost:8080/eop.lec10.twitter/person‣ Back to list - view all - edit - delete - sort
  • Domain constraints
  • Person.groovyclass Person { String username String firstName String lastName String email Date dateCreated //firstName is compulsory //email field has an email format //username cannot be null, is unique and is between 6and 20 characters static constraints = { firstName(blank:false) email(email:true, blank:false) username(blank:false, unique:true, matches:/w{6,20}/) }}