Permalink
Browse files

First cut

  • Loading branch information...
1 parent 3601779 commit 7bf052410b88a7d53b9e00f2cbd00fdae31b1a79 @aldrinm aldrinm committed Mar 3, 2012
View
@@ -1,8 +1,10 @@
#Grails Metadata file
-#Thu Feb 09 23:47:44 GMT+05:30 2012
-app.grails.version=2.0.0
+#Mon Feb 27 22:56:17 IST 2012
+app.grails.version=2.0.1
app.name=flavorwocky
app.servlet.version=2.5
app.version=0.1
+plugins.hibernate=2.0.1
plugins.jquery-ui=1.8.15
+plugins.neo4j=1.0.0.M1
plugins.rest=0.7
@@ -2,82 +2,38 @@
Copyright (c) 2012, Luanne Misquitta
All rights reserved. See License.txt
*/
-import groovyx.net.http.RESTClient
-import static groovyx.net.http.ContentType.*
-import static groovyx.net.http.ContentType.JSON
+import com.herokuapp.flavorwocky.Category
class BootStrap {
- def grailsApplication
-
def init = { servletContext ->
//check if there are categories in the db
- try {
- def neo4jTraverseClient = new RESTClient("${grailsApplication.config.neo4j.rest.serverendpoint}/node/0/traverse/node")
- neo4jTraverseClient.auth.basic grailsApplication.config.neo4j.rest.username, grailsApplication.config.neo4j.rest.password
- def postBody = [order: 'breadth_first', relationships: [ direction:'all', type:'CATEGORY'], max_depth: 1]
- def traverseResp = neo4jTraverseClient.post (contentType:JSON, requestContentType:JSON , body: postBody)
- if (traverseResp.status == 200 && traverseResp.data.size()<=0) {
- //create ingredient index
- createIngredientIndex()
- //create Category nodes
- createInitialCategories()
- }
-
- } catch (ConnectException ce) {
- log.error "Connection to server failed"
- log.error ce
+ if (Category.count()<=0) {
+ createInitialCategories()
}
-
}
-
def destroy = {
}
def createInitialCategories() {
- def neo4jCreateClient = new RESTClient("${grailsApplication.config.neo4j.rest.serverendpoint}/node")
- neo4jCreateClient.auth.basic grailsApplication.config.neo4j.rest.username, grailsApplication.config.neo4j.rest.password
-
- //ideally this should be batched.
- ['Fish':'darkblue', 'Poultry':'hotpink', 'Meat':'firebrick', 'Herbs and spices':'yellowgreen',
- 'Condiments':'goldenrod', 'Eggs and dairy':'wheat', 'Vegetables':'darkgreen', 'Fruits':'lightcoral',
- 'Nuts and Grains':'orange', 'Chocolate, Bread and Pastry':'saddlebrown'].each {
- def createResp = neo4jCreateClient.post(
- body: [name: it.key, catColor: it.value],
- requestContentType: JSON,
- contentType: JSON)
- if (createResp.status == 201) {
- log.info "Created category node :: $it"
- def newCat = createResp.data.self
- //now create the relation with node 0
- def relationClient = new RESTClient("${grailsApplication.config.neo4j.rest.serverendpoint}/node/0/relationships")
- relationClient.auth.basic grailsApplication.config.neo4j.rest.username, grailsApplication.config.neo4j.rest.password
-
- def relationshipResponse = relationClient.post(
- body: [to: newCat, type: 'CATEGORY'],
- requestContentType: JSON,
- contentType: JSON)
- if (relationshipResponse.status == 201) {
- log.info "Created CATEGORY relationship to :: $it"
- }
-
+ //todo: is this really being batched? need to verify
+ Category.withTransaction {
+ [
+ 'Fish':'darkblue',
+ 'Poultry':'hotpink',
+ 'Meat':'firebrick',
+ 'Herbs and spices':'yellowgreen',
+ 'Condiments':'goldenrod',
+ 'Eggs and dairy':'wheat',
+ 'Vegetables':'darkgreen',
+ 'Fruits':'lightcoral',
+ 'Nuts and Grains':'orange',
+ 'Chocolate, Bread and Pastry':'saddlebrown'
+ ].each {
+ new Category(name: it.key, catColor: it.value).save(failOnError: true)
}
-
-
}
}
- def createIngredientIndex() {
- def neo4jCreateIndexClient = new RESTClient("${grailsApplication.config.neo4j.rest.serverendpoint}/index/node")
- neo4jCreateIndexClient.auth.basic grailsApplication.config.neo4j.rest.username, grailsApplication.config.neo4j.rest.password
- def createResp = neo4jCreateIndexClient.post(
- body: [name: 'ingredients'],
- requestContentType: JSON,
- contentType: JSON)
- println createResp.status
- if(createResp.status == 201) {
- log.info "Created ingredients index"
- }
- }
}
@@ -33,11 +33,13 @@ grails.project.dependency.resolution = {
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
+ mavenRepo 'http://m2.neo4j.org/releases'
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.16'
+ compile "org.neo4j:neo4j-rest-graphdb:1.6"
}
plugins {
@@ -0,0 +1,71 @@
+environments {
+ development {
+ grails {
+ neo4j {
+ type = "rest"
+ location = "http://localhost:7474/db/data/"
+ }
+ }
+ }
+ test {
+ grails {
+ neo4j {
+ type = "rest"
+ location = "http://localhost:7474/db/data/"
+ }
+ }
+ }
+ production {
+ grails {
+ neo4j {
+ type = "rest"
+ location = "http://localhost:7474/db/data/"
+ }
+ }
+ }
+
+}
+
+//dataSource {
+// pooled = true
+// driverClassName = "org.h2.Driver"
+// username = "sa"
+// password = ""
+//}
+//hibernate {
+// cache.use_second_level_cache = true
+// cache.use_query_cache = true
+// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
+//}
+//// environment specific settings
+//environments {
+// development {
+// dataSource {
+// dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
+// url = "jdbc:h2:mem:devDb;MVCC=TRUE"
+// }
+// }
+// test {
+// dataSource {
+// dbCreate = "update"
+// url = "jdbc:h2:mem:testDb;MVCC=TRUE"
+// }
+// }
+// production {
+// dataSource {
+// dbCreate = "update"
+// url = "jdbc:h2:prodDb;MVCC=TRUE"
+// pooled = true
+// properties {
+// maxActive = -1
+// minEvictableIdleTimeMillis=1800000
+// timeBetweenEvictionRunsMillis=1800000
+// numTestsPerEvictionRun=3
+// testOnBorrow=true
+// testWhileIdle=true
+// testOnReturn=true
+// validationQuery="SELECT 1"
+// }
+// }
+// }
+//}
Oops, something went wrong.

0 comments on commit 7bf0524

Please sign in to comment.