Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosanchez committed Jan 7, 2015
0 parents commit 90c4b51
Show file tree
Hide file tree
Showing 31 changed files with 5,990 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/
.classpath
.project
*.iml
target/
5 changes: 5 additions & 0 deletions application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Grails Metadata file
#Tue Dec 30 16:20:24 CET 2014
app.grails.version=2.4.4
app.name=jibot
app.version=0.1
7 changes: 7 additions & 0 deletions grails-app/conf/BootStrap.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class BootStrap {

def init = { servletContext ->
}
def destroy = {
}
}
49 changes: 49 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

repositories {
inherits true // Whether to inherit repository definitions from plugins

grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
}

dependencies {
test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"

compile "com.nimbusds:nimbus-jose-jwt:3.5"
compile "com.github.groovy-wslite:groovy-wslite:1.1.0"
}

plugins {
// plugins for the build system only
build ":tomcat:7.0.55"

// plugins for the compile step
compile ':cache:1.1.8'
compile ":asset-pipeline:1.9.9"

// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18"
}
}
117 changes: 117 additions & 0 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// locations to search for config files that get merged into the main config;
// config files can be ConfigSlurper scripts, Java properties files, or classes
// in the classpath in ConfigSlurper format

// grails.config.locations = [ "classpath:${appName}-config.properties",
// "classpath:${appName}-config.groovy",
// "file:${userHome}/.grails/${appName}-config.properties",
// "file:${userHome}/.grails/${appName}-config.groovy"]

// if (System.properties["${appName}.config.location"]) {
// grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }

grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination

// The ACCEPT header will not be used for content negotiation for user agents containing the following strings (defaults to the 4 major rendering engines)
grails.mime.disable.accept.header.userAgents = ['Gecko', 'WebKit', 'Presto', 'Trident']
grails.mime.types = [ // the first one is the default format
all: '*/*', // 'all' maps to '*' or the first available format in withFormat
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
form: 'application/x-www-form-urlencoded',
html: ['text/html','application/xhtml+xml'],
js: 'text/javascript',
json: ['application/json', 'text/json'],
multipartForm: 'multipart/form-data',
rss: 'application/rss+xml',
text: 'text/plain',
hal: ['application/hal+json','application/hal+xml'],
xml: ['text/xml', 'application/xml']
]

// URL Mapping Cache Max Size, defaults to 5000
//grails.urlmapping.cache.maxsize = 1000

// Legacy setting for codec used to encode data with ${}
grails.views.default.codec = "html"

// The default scope for controllers. May be prototype, session or singleton.
// If unspecified, controllers are prototype scoped.
grails.controllers.defaultScope = 'singleton'

// GSP settings
grails {
views {
gsp {
encoding = 'UTF-8'
htmlcodec = 'xml' // use xml escaping instead of HTML4 escaping
codecs {
expression = 'html' // escapes values inside ${}
scriptlet = 'html' // escapes output from scriptlets in GSPs
taglib = 'none' // escapes output from taglibs
staticparts = 'none' // escapes output from static template parts
}
}
// escapes all not-encoded output at final stage of outputting
// filteringCodecForContentType.'text/html' = 'html'
}
}


grails.converters.encoding = "UTF-8"
// scaffolding templates configuration
grails.scaffolding.templates.domainSuffix = 'Instance'

// Set to false to use the new Grails 1.2 JSONBuilder in the render method
grails.json.legacy.builder = false
// enabled native2ascii conversion of i18n properties files
grails.enable.native2ascii = true
// packages to include in Spring bean scanning
grails.spring.bean.packages = []
// whether to disable processing of multi part requests
grails.web.disable.multipart=false

// request parameters to mask when logging exceptions
grails.exceptionresolver.params.exclude = ['password']

// configure auto-caching of queries by default (if false you can cache individual queries with 'cache: true')
grails.hibernate.cache.queries = false

// configure passing transaction's read-only attribute to Hibernate session, queries and criterias
// set "singleSession = false" OSIV mode in hibernate configuration after enabling
grails.hibernate.pass.readonly = false
// configure passing read-only to OSIV session by default, requires "singleSession = false" OSIV mode
grails.hibernate.osiv.readonly = false

environments {
development {
grails.logging.jul.usebridge = true
}
production {
grails.logging.jul.usebridge = false
// TODO: grails.serverURL = "http://www.changeme.com"
}
}

// log4j configuration
log4j.main = {
// Example of changing the log pattern for the default console appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}

error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
}
57 changes: 57 additions & 0 deletions grails-app/conf/DataSource.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}

// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
}
16 changes: 16 additions & 0 deletions grails-app/conf/UrlMappings.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class UrlMappings {

static mappings = {

"/installable/${oauthId}"(controller: 'installable', action: 'delete', method: 'DELETE')

"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}

"/"(view:"/index")
"500"(view:'/error')
}
}
3 changes: 3 additions & 0 deletions grails-app/conf/spring/resources.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place your Spring DSL code here
beans = {
}
42 changes: 42 additions & 0 deletions grails-app/controllers/hipchat/addon/CapabilitiesController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package hipchat.addon

import org.codehaus.groovy.grails.commons.GrailsApplication

class CapabilitiesController {

GrailsApplication grailsApplication

def index() {
render contentType: 'application/json', text: """
{
"name": "Jibot",
"description": "A tiny HipChat add-on that listen for JIRA keys being mentioned on a room, and sends back the link for them plus some additional info",
"key": "es.alvarosanchezmariscal.hipchat.jibot",
"vendor": {
"url": "https://www.linkedin.com/in/mariscal",
"name": "Álvaro Sánchez-Mariscal"
},
"capabilities": {
"hipchatApiConsumer": {
"scopes": [
"send_notification"
]
},
"installable": {
"callbackUrl": "${grailsApplication.config.grails.serverURL}/installable"
},
"configurable": {
"url": "${grailsApplication.config.grails.serverURL}/configure"
},
"webhook": [
{
"url": "${grailsApplication.config.grails.serverURL}/webhook",
"event": "room_message",
"name": "Room message WebHook"
}
]
}
}
"""
}
}
42 changes: 42 additions & 0 deletions grails-app/controllers/hipchat/addon/ConfigureController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package hipchat.addon

class ConfigureController {

JwtService jwtService

def index() {
String signedRequest = params['signed_request']

Tenant tenant = jwtService.parseAndVerify(signedRequest)

if (!tenant) {
render status: 400
return
}

[tenant: tenant]
}

def finishInstallation(String jiraUrl, String jiraUsername, String jiraPassword, String signedRequest) {
Tenant tenant = jwtService.parseAndVerify(signedRequest)

if (!tenant) {
render status: 400
return
}

tenant.jiraUrl = jiraUrl
tenant.jiraUsername = jiraUsername
tenant.jiraPassword = jiraPassword

if (tenant.save(flush: true, failOnError: true)) {
[tenant: tenant]
} else {
tenant.errors.each {println it}
render status: 400
}

}


}
24 changes: 24 additions & 0 deletions grails-app/controllers/hipchat/addon/InstallableController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package hipchat.addon

class InstallableController {

def index() {
Tenant tenant = new Tenant(request.JSON)
if (tenant.save()) {
render status: 200
} else {
tenant.errors.each {println it}
render status: 400
}
}

def delete(String oauthId) {
Tenant tenant = Tenant.findByOauthId(oauthId)
if (tenant) {
tenant.delete(flush: true)
render status: 200
} else {
render status: 404
}
}
}
Loading

0 comments on commit 90c4b51

Please sign in to comment.