Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Commit

Permalink
Uncommitted files...not sure why. Moving to side branch in case I nee…
Browse files Browse the repository at this point in the history
…d them later.
  • Loading branch information
habuma committed Sep 17, 2012
1 parent 3e9bf92 commit 6dccf08
Show file tree
Hide file tree
Showing 35 changed files with 27,510 additions and 142 deletions.
14 changes: 14 additions & 0 deletions .springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.0.0.201207050701-M3]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/test/java/com/springsource/greenhouse/events/load/JdbcEventLoaderRepositoryTest-context.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>
25 changes: 22 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.2.RELEASE</org.springframework-version>
<org.springframework.test-mvc-version>1.0.0.M1</org.springframework.test-mvc-version>
<org.springframework.security-version>3.1.0.RELEASE</org.springframework.security-version>
<org.springframework.security.oauth-version>1.0.0.RC2</org.springframework.security.oauth-version>
<org.springframework.integration-version>2.1.3.RELEASE</org.springframework.integration-version>
Expand Down Expand Up @@ -346,20 +347,38 @@
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<artifactId>junit-dep</artifactId>
<version>4.10</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test-mvc</artifactId>
<version>${org.springframework.test-mvc-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<artifactId>mockito-core</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import javax.sql.DataSource;

import org.h2.jdbcx.JdbcConnectionPool;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
<intercept-url pattern="/signin/*" access="permitAll" requires-channel="#{environment['application.secureChannel']}" />
<intercept-url pattern="/reset" access="permitAll" requires-channel="#{environment['application.secureChannel']}" />
<!-- TODO this would probably be better mapped to simply /invite?token={token} but not able to vary security policy here based on presence of a request parameter. Consider @Secured on @Controller. -->
<intercept-url pattern="/invite/accept" access="permitAll" requires-channel="#{environment['application.secureChannel']}" />
<intercept-url pattern="/invite/accept" access="permitAll" requires-channel="#{environment['application.secureChannel']}" />
<!-- TODO this should be restricted to admin users only -->
<intercept-url pattern="/admin/**" access="permitAll" />
<intercept-url pattern="/**" access="isAuthenticated()" requires-channel="#{environment['application.secureChannel']}" />
<custom-filter ref="resourceServerFilter" before="EXCEPTION_TRANSLATION_FILTER" />
</http>
Expand Down
271 changes: 155 additions & 116 deletions src/main/java/com/springsource/greenhouse/config/test-data.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ private org.springframework.jdbc.versioned.DatabaseUpgrader createUpgrader(DataS
return upgrader;
}

// Called for completely fresh DB only
private void addInstallChangeSet(GenericDatabaseUpgrader upgrader) {
DatabaseChangeSet changeSet = new DatabaseChangeSet(DatabaseVersion.valueOf("3"));
DatabaseChangeSet changeSet = new DatabaseChangeSet(DatabaseVersion.valueOf("4"));
changeSet.add(installScript("Member.sql"));
changeSet.add(installScript("Group.sql"));
changeSet.add(installScript("Activity.sql"));
Expand All @@ -91,9 +92,11 @@ private DatabaseChange installScript(String resource) {
return SqlDatabaseChange.inResource(new ClassPathResource("install/" + resource, DatabaseUpgrader.class));
}

// Called to upgrade existing DB
private void addUpgradeChangeSets(GenericDatabaseUpgrader upgrader) {
upgrader.addChangeSet(version2ChangeSet());
upgrader.addChangeSet(version3ChangeSet());
upgrader.addChangeSet(version4ChangeSet());
}

private DatabaseChangeSet version2ChangeSet() {
Expand All @@ -110,6 +113,12 @@ private DatabaseChangeSet version3ChangeSet() {
changeSet.add(upgradeScript("v3/DropAccountConnectionTables.sql"));
return changeSet;
}

private DatabaseChangeSet version4ChangeSet() {
DatabaseChangeSet changeSet = new DatabaseChangeSet(DatabaseVersion.valueOf("4"));
changeSet.add(upgradeScript("v4/CreateTimeSlotTable.sql"));
return changeSet;
}

private DatabaseChange upgradeScript(String resource) {
return SqlDatabaseChange.inResource(new ClassPathResource("upgrade/" + resource, DatabaseUpgrader.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ create table Leader (id identity,
primary key (id),
foreign key (member) references Member(id));

create table ExternalLeader (leader bigint,
sourceId bigint,
source varchar,
lastUpdated timestamp not null,
primary key (leader, sourceId, source),
foreign key (leader) references Leader(id)
);

create table Session (id identity,
title varchar not null,
slug varchar not null,
Expand All @@ -36,6 +44,14 @@ create table Event (id identity,
primary key (id),
foreign key (memberGroup) references MemberGroup(id));

create table ExternalEvent (event bigint,
sourceId bigint,
source varchar,
lastUpdated timestamp not null,
primary key (event, sourceId, source),
foreign key (event) references Event(id)
);

create table EventVenue (event bigint,
venue bigint,
primary key (event, venue),
Expand All @@ -51,10 +67,26 @@ create table EventTrack (event bigint,
foreign key (event) references Event(id),
foreign key (chair) references Member(id));

create table EventSession (event bigint,
id int not null,
create table EventTimeSlot (
id identity,
event bigint not null,
label varchar,
startTime timestamp not null,
endTime timestamp not null,
primary key (id),
foreign key (event) references Event(id));

create table ExternalEventTimeSlot (timeSlot bigint,
sourceId bigint,
source varchar,
lastUpdated timestamp not null,
primary key (timeSlot, sourceId, source),
foreign key (timeSlot) references EventTimeSlot(id)
);


create table EventSession (event bigint,
id int not null,
title varchar not null,
description varchar,
hashtag varchar,
Expand All @@ -63,12 +95,22 @@ create table EventSession (event bigint,
room varchar,
rating real,
master bigint,
timeslot bigint,
primary key (event, id),
foreign key (event) references Event(id),
foreign key (event, track) references EventTrack(event, code),
foreign key (venue, room) references VenueRoom(venue, id),
foreign key (master) references Session(id));

foreign key (master) references Session(id),
foreign key (timeslot) references EventTimeSlot(id));

create table ExternalEventSession (event bigint not null,
sessionId int not null,
sourceId bigint not null,
source varchar not null,
lastUpdated timestamp not null,
primary key (event, sessionId, sourceId, source)
);

create table EventSessionLeader (event bigint,
session int,
leader bigint,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
create table EventTimeSlot (
id identity,
startTime timestamp not null,
endTime timestamp not null,
primary key (id)
);

alter table EventSession add column timeslot bigint;
alter table EventSession add foreign key (timeslot) references EventTimeSlot(id);
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,16 @@ public Float rate(Long eventId, Integer sessionId, Long attendeeId, Rating ratin
jdbcTemplate.update("update EventSession set rating = ? where event = ? and id = ?", newAvgRating, eventId, sessionId);
return newAvgRating;
}

@Transactional
public long addEvent() {
return 0;
}

// internal helpers

private boolean isSessionEnded(Long eventId, Integer sessionId) {
Date endTime = jdbcTemplate.queryForObject("select endTime from EventSession where event = ? and id = ?", Date.class, eventId, sessionId);
Date endTime = jdbcTemplate.queryForObject("select ts.endTime from EventTimeSlot ts, EventSession s where s.event = ? and s.id = ? and ts.id = s.timeSlot", Date.class, eventId, sessionId);
return new Date().after(endTime);
}

Expand Down Expand Up @@ -142,7 +147,7 @@ protected void addChild(EventSession session, ResultSet rs) throws SQLException
}
};

private static final String SELECT_FROM_EVENT_SESSION = "select s.id, s.title, s.startTime, s.endTime, s.description, s.hashtag, s.rating, s.venue, s.room, r.name as roomName, (f.attendee is not null) as favorite, l.name from EventSession s ";
private static final String SELECT_FROM_EVENT_SESSION = "select s.id, s.title, ts.startTime, ts.endTime, s.description, s.hashtag, s.rating, s.venue, s.room, r.name as roomName, (f.attendee is not null) as favorite, l.name from EventSession s ";

private static final String SELECT_EVENT = "select e.id, e.title, e.timeZone, e.startTime, e.endTime, e.slug, e.description, g.hashtag, g.slug as groupSlug, g.name as groupName, " +
"v.id as venueId, v.name as venueName, v.postalAddress as venuePostalAddress, v.latitude as venueLatitude, v.longitude as venueLongitude, v.locationHint as venueLocationHint from Event e " +
Expand All @@ -159,15 +164,17 @@ protected void addChild(EventSession session, ResultSet rs) throws SQLException
"left outer join EventSessionFavorite f on s.event = f.event and s.id = f.session and f.attendee = ? " +
"inner join EventSessionLeader sl on s.event = sl.event and s.id = sl.session " +
"inner join Leader l on sl.leader = l.id " +
"where s.event = ? and s.startTime >= ? and s.endTime <= ? " +
"order by s.startTime, s.id, sl.rank";
"inner join EventTimeSlot ts on ts.id = s.timeSlot " +
"where s.event = ? and ts.startTime >= ? and ts.endTime <= ? " +
"order by ts.startTime, s.id, sl.rank";

private static final String SELECT_EVENT_FAVORITES = SELECT_FROM_EVENT_SESSION +
"inner join (select top 10 session, count(*) as favoriteCount from EventSessionFavorite where event = ? group by session) top on s.id = top.session " +
"left outer join VenueRoom r on s.venue = r.venue and s.room = r.id " +
"left outer join EventSessionFavorite f on s.event = f.event and s.id = f.session and f.attendee = ? " +
"inner join EventSessionLeader sl on s.event = sl.event and s.id = sl.session " +
"inner join Leader l on sl.leader = l.id " +
"inner join EventTimeSlot ts on ts.id = s.timeSlot " +
"where s.event = ? " +
"order by top.favoriteCount desc, s.id, sl.rank";

Expand All @@ -176,6 +183,7 @@ protected void addChild(EventSession session, ResultSet rs) throws SQLException
"inner join EventSessionFavorite f on s.event = f.event and s.id = f.session and f.attendee = ? " +
"inner join EventSessionLeader sl on s.event = sl.event and s.id = sl.session " +
"inner join Leader l on sl.leader = l.id " +
"inner join EventTimeSlot ts on ts.id = s.timeSlot " +
"where s.event = ? " +
"order by f.rank, s.id, sl.rank";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.springsource.greenhouse.events.load;

class EventData {

private final long memberGroupId;
private final String name;
private final String description;
private final String abbreviation;
private final String firstDay;
private final String lastDay;
private final String timeZone;
private final String source;
private final long sourceId;

public EventData(long memberGroupId, String name, String description, String abbreviation, String firstDay, String lastDay, String timeZone, String source, long sourceId) {
this.memberGroupId = memberGroupId;
this.name = name;
this.description = description;
this.abbreviation = abbreviation;
this.firstDay = firstDay;
this.lastDay = lastDay;
this.timeZone = timeZone;
this.source = source;
this.sourceId = sourceId;
}

public long getMemberGroupId() {
return memberGroupId;
}

public String getName() {
return name;
}

public String getDescription() {
return description;
}

public String getAbbreviation() {
return abbreviation;
}

public String getFirstDay() {
return firstDay;
}

public String getLastDay() {
return lastDay;
}

public String getTimeZone() {
return timeZone;
}

public String getSource() {
return source;
}

public long getSourceId() {
return sourceId;
}

}
Loading

0 comments on commit 6dccf08

Please sign in to comment.