Skip to content

Commit

Permalink
Adding seed data and scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Creeger committed Aug 15, 2011
1 parent 08e49c1 commit 274dd9a
Show file tree
Hide file tree
Showing 30 changed files with 1,344 additions and 15 deletions.
3 changes: 2 additions & 1 deletion application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#Grails Metadata file
#Sun Jul 31 15:31:42 PDT 2011
#Thu Aug 04 19:53:48 PDT 2011
app.grails.version=1.3.7
app.name=cafe-centro
app.servlet.version=2.4
app.version=0.1
plugins.console=1.0.1
plugins.hibernate=1.3.7
plugins.tomcat=1.3.7
102 changes: 102 additions & 0 deletions grails-app/conf/BootStrap.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,109 @@
import org.cafeCentro.Venue
import org.cafeCentro.Artist
import groovy.time.TimeCategory
import org.cafeCentro.Event
import java.security.SecureRandom

class BootStrap {

def artists = [
"Prince",
"Death Cab for Cutie",
"Chromeo",
"Geographer",
"Friendly Fires",
"Deadmau5",
"Kings of Leon",
"Muse",
"Arcade Fire",
"Sia",
"Empire Of The Sun",
"Megadeth",
"Metallica",
"Radiohead",
"Adele",
"Kate Nash",
"Hot Chip",
"Blondie",
"Red Hot Chilli Peppers",
"Girl Talk",
"MGMT",
"TV on the Radio",
"The National"
]


def venues = [
[name: "The Independent",coords: "37.775286, -122.437611", city: "San Francisco"],
[name: "Rickshaw Stop",coords: "37.776319, -122.420319", city: "San Francisco"],
[name: "Fox Theatre",coords: "37.808252, -122.270480", city: "Oakland"],
[name: "Fillmore",coords: "37.784228, -122.432845", city: "San Francisco"],
[name: "Great American Music Hall",coords: "37.785125, -122.418851", city: "San Francisco"],
[name: "Paramount Theatre",coords: "37.809847, -122.268633", city: "Oakland"],
[name: "Amnesia",coords: "37.759298, -122.421462", city: "San Francisco"],
[name: "Cafe du nord",coords: "37.766011, -122.430435", city: "San Francisco"],
[name: "The Grand Ballroom",coords: "37.787729, -122.421682", city: "San Francisco"],
[name: "Hotel Utah",coords: "37.779529,-122.397981", city: "San Francisco"],
[name: "Bowery Ballrom",coords: "40.720760, -73.993868", city: "New York"],
[name: "Brooklyn Bowl",coords: "40.722285, -73.957461", city: "Brooklyn"],
[name: "Webster Hall",coords: "40.732329, -73.989863", city: "New York"],
[name: "The 40/40 Club",coords: "40.743159, -73.988891", city: "New York"],
[name: "Rockwood Music Hall",coords: "40.722779, -73.989071", city: "New York"],
[name: "The Mercury Lounge",coords: "40.722715, -73.986955", city: "New York"]
]

def init = { servletContext ->
buildVenues()

buildArtists()

def rnd = new SecureRandom()
1000.times {
def date
use (TimeCategory) {
date = ((1 + rnd.nextInt(730)) * 24).hours.from.now
}

def eventArtists = []

(1 + rnd.nextInt(3)).times {
def added = false
while (!added) {
def artist = Artist.findByName(artists[rnd.nextInt(artists.size())])
if (!eventArtists.contains(artist)) {
eventArtists << artist
added = true
}
}
}

def props = [
venue : Venue.findByName(venues[rnd.nextInt(venues.size())].name),
artists : eventArtists,
date : date
]

new Event(props).save(failOnError:true)
}

}

private def buildArtists() {
artists.each {
if (!Artist.findByName(it)) {
new Artist(name: it).save(failOnError: true)
}
}
}

private def buildVenues() {
venues.each {venueProps ->
if (!Venue.findByName(venueProps.name)) {
new Venue(venueProps).save(failOnError: true)
}
}
}

def destroy = {
}
}
4 changes: 4 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ grails.project.dependency.resolution = {

// runtime 'mysql:mysql-connector-java:5.1.13'
}

plugins {
compile(':build-test-data:1.1.1')
}
}
96 changes: 96 additions & 0 deletions grails-app/conf/TestDataConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
Map venues = ["The Independent":"37.775286, -122.437611",
"Rickshaw Stop":"37.776319, -122.420319",
"Fox Theatre":"37.808252, -122.270480",
"Fillmore":"37.784228, -122.432845",
"Great American Music Hall":"37.785125, -122.418851",
"Paramount Theatre":"37.809847, -122.268633",
"Amnesia":"37.759298, -122.421462",
"Cafe du nord":"37.766011, -122.430435",
"The Grand Ballroom":"37.787729, -122.421682",
"Hotel Utah":"37.779529,-122.397981",
"Bowery Ballrom":"40.720760, -73.993868",
"Brooklyn Bowl":"40.722285, -73.957461",
"Webster Hall":"40.732329, -73.989863",
"The 40/40 Club":"40.743159, -73.988891",
"Rockwood Music Hall":"40.722779, -73.989071",
"The Mercury Lounge":"40.722715, -73.986955"
]

def rnd = new Random(new Date().time)

testDataConfig {
sampleData {
'org.cafeCentro.Venue' {
name = {venues.keySet().toArray()[rnd.nextInt(venues.size())]}
}
'org.cafeCentro.Artist' {
def artistNames = [
"Prince",
"Death Cab for Cutie",
"Chromeo",
"Geographer",
"Friendly Fires",
"Deadmau5",
"Kings of Leon",
"Muse",
"Arcade Fire",
"Sia"
]
name = {artistNames[rnd.nextInt(artistNames.size())]}
}

}
}

/*
// sample for creating a single static value for the com.foo.Book's title property:
// title for all Books that we "build()" will be "The Shining", unless explicitly set
testDataConfig {
sampleData {
'com.foo.Book' {
title = "The Shining"
}
}
}
*/

/*
// sample for creating a dynamic title for com.foo.Book, useful for unique properties:
// just specify a closure that gets called
testDataConfig {
sampleData {
'com.foo.Book' {
def i = 1
title = {-> "title${i++}" } // creates "title1", "title2", ...."titleN"
}
}
}
*/

/*
// When using a closure, if your tests expect a particular value, you'll likely want to reset
// the build-test-data config in the setUp of your test, or in the test itself. Otherwise if
// your tests get run in a different order you'll get different values
// (in test/integration/FooTests.groovy)
void setUp() {
grails.buildtestdata.TestDataConfigurationHolder.reset()
}
*/


/*
// if you'd like to disable the build-test-data plugin in an environment, just set
// the "enabled" property to false
environments {
production {
testDataConfig {
enabled = false
}
}
}
*/
100 changes: 100 additions & 0 deletions grails-app/controllers/org/cafeCentro/ArtistController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.cafeCentro

class ArtistController {

static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

def index = {
redirect(action: "list", params: params)
}

def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[artistInstanceList: Artist.list(params), artistInstanceTotal: Artist.count()]
}

def create = {
def artistInstance = new Artist()
artistInstance.properties = params
return [artistInstance: artistInstance]
}

def save = {
def artistInstance = new Artist(params)
if (artistInstance.save(flush: true)) {
flash.message = "${message(code: 'default.created.message', args: [message(code: 'artist.label', default: 'Artist'), artistInstance.id])}"
redirect(action: "show", id: artistInstance.id)
}
else {
render(view: "create", model: [artistInstance: artistInstance])
}
}

def show = {
def artistInstance = Artist.get(params.id)
if (!artistInstance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'artist.label', default: 'Artist'), params.id])}"
redirect(action: "list")
}
else {
[artistInstance: artistInstance]
}
}

def edit = {
def artistInstance = Artist.get(params.id)
if (!artistInstance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'artist.label', default: 'Artist'), params.id])}"
redirect(action: "list")
}
else {
return [artistInstance: artistInstance]
}
}

def update = {
def artistInstance = Artist.get(params.id)
if (artistInstance) {
if (params.version) {
def version = params.version.toLong()
if (artistInstance.version > version) {

artistInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'artist.label', default: 'Artist')] as Object[], "Another user has updated this Artist while you were editing")
render(view: "edit", model: [artistInstance: artistInstance])
return
}
}
artistInstance.properties = params
if (!artistInstance.hasErrors() && artistInstance.save(flush: true)) {
flash.message = "${message(code: 'default.updated.message', args: [message(code: 'artist.label', default: 'Artist'), artistInstance.id])}"
redirect(action: "show", id: artistInstance.id)
}
else {
render(view: "edit", model: [artistInstance: artistInstance])
}
}
else {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'artist.label', default: 'Artist'), params.id])}"
redirect(action: "list")
}
}

def delete = {
def artistInstance = Artist.get(params.id)
if (artistInstance) {
try {
artistInstance.delete(flush: true)
flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'artist.label', default: 'Artist'), params.id])}"
redirect(action: "list")
}
catch (org.springframework.dao.DataIntegrityViolationException e) {
flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'artist.label', default: 'Artist'), params.id])}"
redirect(action: "show", id: params.id)
}
}
else {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'artist.label', default: 'Artist'), params.id])}"
redirect(action: "list")
}
}
}
Loading

0 comments on commit 274dd9a

Please sign in to comment.