Skip to content

Commit

Permalink
Shanu:Added db deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanu committed Dec 5, 2010
1 parent 685266c commit c2c1322
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 41 deletions.
7 changes: 0 additions & 7 deletions DB/001_BaseLine.sql

This file was deleted.

Empty file removed DB/Data.sql
Empty file.
48 changes: 48 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<project name="mgift" default="setupdb">
<property name="db.driver" value="org.postgresql.Driver"/>
<property name="db.url" value="jdbc:postgresql://localhost:5432/GIFTDB"/>
<property name="db.username" value="app_user"/>
<property name="db.password" value="password"/>

<path id="project.classpath">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<fileset dir="buildlib">
<include name="*.jar"/>
</fileset>
</path>

<macrodef name="exec_sql">
<attribute name="src"/>
<attribute name="onerror"/>
<sequential>
<sql
classpathref="project.classpath"
driver="${db.driver}"
url="${db.url}"
userid="${db.username}"
password="${db.password}"
src="@{src}"
onerror="@{onerror}"
delimiter=";"
/>
</sequential>
</macrodef>


<taskdef name="dbdeploy" classname="com.dbdeploy.AntTarget" classpathref="project.classpath"/>

<target name="drop.create.schema"
description="drop the current schema and builds the baseline database">
<exec_sql src="sql/schema.sql" onerror="abort"/>
</target>

<target name="setupdb" depends="drop.create.schema">
<dbdeploy driver="${db.driver}" url="${db.url}"
userid="app_user"
password="password"
dir="sql"
/>
</target>
</project>
Binary file added buildlib/dbdeploy-ant-3.0M2.jar
Binary file not shown.
15 changes: 15 additions & 0 deletions grails-app/conf/BootStrap.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import com.breigns.gift.AppUser
import com.breigns.gift.AppUserRole
import com.breigns.gift.Role

class BootStrap {
def springSecurityService
def init = { servletContext ->

/*def adminRole = Role.findByAuthority('ROLE_ADMIN')
def adminUser = AppUser.findByUsername('admin') ?: new AppUser(
firstName:'Fanzeem',
lastName:'Ahmed',
username: 'admin',
password: springSecurityService.encodePassword('breigns$123'),
enabled: true).save(failOnError: true)
if (!adminUser.authorities.contains(adminRole)) {
AppUserRole.create adminUser, adminRole
}*/

}
def destroy = {
}
Expand Down
6 changes: 3 additions & 3 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ log4j = {


// Added by the Spring Security Core plugin:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'com.malabar.gift.AppUser'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'com.malabar.gift.AppUserRole'
grails.plugins.springsecurity.authority.className = 'com.malabar.gift.Role'
grails.plugins.springsecurity.userLookup.userDomainClassName = 'com.breigns.gift.AppUser'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'com.breigns.gift.AppUserRole'
grails.plugins.springsecurity.authority.className = 'com.breigns.gift.Role'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package com.breigns.controller

class AdminController{
def index = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.breigns.controller

import grails.converters.JSON

import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
Expand All @@ -9,6 +11,7 @@ import org.springframework.security.authentication.LockedException
import org.springframework.security.core.context.SecurityContextHolder as SCH
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
import org.springframework.security.core.context.SecurityContextHolder

class LoginController {

Expand Down Expand Up @@ -57,7 +60,7 @@ class LoginController {
*/
def denied = {
if (springSecurityService.isLoggedIn() &&
authenticationTrustResolver.isRememberMe(SCH.context?.authentication)) {
authenticationTrustResolver.isRememberMe(SecurityContextHolder.context?.authentication)) {
// have cookie but the page is guarded with IS_AUTHENTICATED_FULLY
redirect action: full, params: params
}
Expand All @@ -69,7 +72,7 @@ class LoginController {
def full = {
def config = SpringSecurityUtils.securityConfig
render view: 'auth', params: params,
model: [hasCookie: authenticationTrustResolver.isRememberMe(SCH.context?.authentication),
model: [hasCookie: authenticationTrustResolver.isRememberMe(SecurityContextHolder.context?.authentication),
postUrl: "${request.contextPath}${config.apf.filterProcessesUrl}"]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.breigns.controller

import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils

class LogoutController {
Expand Down
27 changes: 27 additions & 0 deletions grails-app/domain/com/breigns/gift/AppUser.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.breigns.gift

class AppUser {
String firstName
String lastName
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
Date dateCreated
Date lastUpdated

static constraints = {
username blank: false, unique: true
password blank: false
}

static mapping = {
password column: '`password`'
}

Set<Role> getAuthorities() {
AppUserRole.findAllByAppUser(this).collect { it.role } as Set
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.malabar.gift
package com.breigns.gift

import org.apache.commons.lang.builder.HashCodeBuilder

Expand Down
9 changes: 9 additions & 0 deletions grails-app/domain/com/breigns/gift/Company.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.breigns.gift

class Company {
String name
String address
Date dateCreated

static hasMany = [vouchers:Voucher]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.malabar.gift
package com.breigns.gift

class Role {

Expand Down
15 changes: 15 additions & 0 deletions grails-app/domain/com/breigns/gift/Voucher.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.breigns.gift

class Voucher {
Integer sequenceNumber
String barcodeAlpha
Double value
Date dateCreated
Date lastUpdated

static belongsTo = Company

static constraints = {
barcodeAlpha(maxSize:10,minSize:10)
}
}
24 changes: 0 additions & 24 deletions grails-app/domain/com/malabar/gift/AppUser.groovy

This file was deleted.

4 changes: 4 additions & 0 deletions grails-app/services/com/breigns/service/AdminService.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.breigns.service

class AdminService {
}
20 changes: 20 additions & 0 deletions grails-app/services/com/breigns/service/CompanyService.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.breigns.service

import com.breigns.gift.Company
import com.breigns.gift.Voucher
import org.apache.commons.lang.RandomStringUtils

class CompanyService {
void createVouchers(String companyName, int sequenceStart, int sequenceEnd,double price) {
def company = Company.findByName(companyName)
for(int i=sequenceStart;i<=sequenceEnd;i++){
company.addToVouchers(new Voucher(sequenceNumber:i,
barcodeAlpha:generateBarCodeAlpha(),value:price))
}

}

String generateBarCodeAlpha(){
RandomStringUtils.randomAlphabetic(10).toUpperCase()
}
}
15 changes: 12 additions & 3 deletions grails-app/views/admin/dashboard.gsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head><title>Simple GSP page</title></head>
<body>Place your content here</body>
<head><title>Admin DashBoard</title>
<style type="text/css">
body {
color: black;
font-family: verdana, arial, sans-serif;
font-size: 17px;
font-weight: bold;
background-color: #e4c52d;
}
</style>
</head>
<body>Place your content here</body>
</html>
18 changes: 18 additions & 0 deletions sql/001_BaseLine.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
create table app_user (id int8 not null, version int8 not null, account_expired bool not null, account_locked bool not null, date_created timestamp not null, enabled bool not null, first_name varchar(255) not null, last_name varchar(255) not null, last_updated timestamp not null, "password" varchar(255) not null, password_expired bool not null, username varchar(255) not null unique, primary key (id));
create table app_user_role (role_id int8 not null, app_user_id int8 not null, primary key (role_id, app_user_id));
create table company (id int8 not null, version int8 not null, address varchar(255) not null, date_created timestamp not null, name varchar(255) not null, primary key (id));
create table company_voucher (company_vouchers_id int8, voucher_id int8);
create table role (id int8 not null, version int8 not null, authority varchar(255) not null unique, primary key (id));
create table voucher (id int8 not null, version int8 not null, barcode_alpha varchar(10) not null, date_created timestamp not null, last_updated timestamp not null, sequence_number int4 not null, value float8 not null, primary key (id));
alter table app_user_role add constraint FK9CE8F3CC1BE77175 foreign key (role_id) references role;
alter table app_user_role add constraint FK9CE8F3CCF927EE22 foreign key (app_user_id) references app_user;
alter table company_voucher add constraint FKC3CDA4ECDE2BF275 foreign key (company_vouchers_id) references company;
alter table company_voucher add constraint FKC3CDA4EC2BD3799F foreign key (voucher_id) references voucher;
create sequence hibernate_sequence;

--Data
insert into role(id,version,authority) values (1,1,'ROLE_ADMIN');
insert into role(id,version,authority) values (2,1,'ROLE_DEALER');

INSERT INTO app_user(id, "version", account_expired, account_locked, date_created,enabled, first_name, last_name, last_updated, "password", password_expired,username)VALUES (1, 1, false, false, current_timestamp,true, 'Fanzeem', 'Ahmed', current_timestamp,'3723e615dd927e7534f2f4eafa71adae6df823219ee71265bae56ba5e6927f18', false,'admin');
insert into app_user_role(role_id, app_user_id )values(1,1);
8 changes: 8 additions & 0 deletions sql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
drop schema if exists public cascade;
create schema public authorization app_user;
CREATE TABLE changelog (
change_number BIGINT NOT NULL,
complete_dt TIMESTAMP NOT NULL,
applied_by text NOT NULL,
description text NOT NULL
);

0 comments on commit c2c1322

Please sign in to comment.