diff --git a/src/main/java/backend/configuration/TestDataInitializer.kt b/src/main/java/backend/configuration/TestDataInitializer.kt index aff53920..9958291c 100644 --- a/src/main/java/backend/configuration/TestDataInitializer.kt +++ b/src/main/java/backend/configuration/TestDataInitializer.kt @@ -11,11 +11,13 @@ import backend.model.user.Admin import backend.model.user.Participant import backend.model.user.Sponsor import backend.model.user.UserService +import backend.util.Profiles.DEVELOPMENT import backend.util.Profiles.HEROKU import backend.util.euroOf import org.javamoney.moneta.Money import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.Profile +import org.springframework.jdbc.core.JdbcTemplate import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.core.context.SecurityContextHolder import org.springframework.security.core.userdetails.UserDetailsService @@ -24,7 +26,7 @@ import java.time.LocalDateTime import javax.annotation.PostConstruct @Service -@Profile(HEROKU) +@Profile(HEROKU, DEVELOPMENT) class TestDataInitializer { // Services @@ -35,15 +37,26 @@ class TestDataInitializer { @Autowired lateinit private var sponsoringService: SponsoringService @Autowired lateinit private var challengeService: ChallengeService @Autowired lateinit private var userDetailsService: UserDetailsService + @Autowired lateinit private var template: JdbcTemplate @PostConstruct fun initialize() { - val date = LocalDateTime.of(2016, 6, 3, 0, 0) + // Don't perform population if an event exists already + if (eventService.exists(1)) { + return + } + + val date = LocalDateTime.now().minusHours(1) // ---- Events ---- - val eventMunich = eventService.createEvent("Breakout München 2016", date, "München", Coord(48.1374300, 11.5754900), 36) - val eventBerlin = eventService.createEvent("Breakout Berlin 2016", date, "Berlin", Coord(52.5243700, 13.4105300), 36) + val eventMunich = eventService.createEvent("Breakout München", date, "München", Coord(48.1374300, 11.5754900), 36) + val eventBerlin = eventService.createEvent("Breakout Berlin", date, "Berlin", Coord(52.5243700, 13.4105300), 36) + + arrayOf(eventMunich, eventBerlin).forEach { + eventService.markAsCurrent(it.id!!) + eventService.allowNewSponsoring(it.id!!) + } // --- iOS Devs Test Accounts --- val leo = userService.create("leokaessner@me.com", "password", { addRole(Participant::class) }).getRole(Participant::class)!! @@ -102,6 +115,50 @@ class TestDataInitializer { locationService.create(Coord(53.5753200, 10.0153400), participant3, date.plusHours(2)) locationService.create(Coord(52.3740300, 4.8896900), participant3, date.plusHours(2)) + template.execute(""" + INSERT INTO `oauth_client_details` ( + `client_id`, + `resource_ids`, + `client_secret`, + `scope`, + `authorized_grant_types`, + `web_server_redirect_uri`, + `authorities`, + `access_token_validity`, + `refresh_token_validity`, + `additional_information`, + `autoapprove` + ) + + VALUES + ( + 'test_breakout_app', + 'BREAKOUT_BACKEND', + '123456789', + 'read,write', + 'password,refresh_token', + '', + 'USER', + NULL, + NULL, + '{}', + '' + ), + ( + 'test_client_app', + 'BREAKOUT_BACKEND', + '123456789', + 'read,write', + 'password,refresh_token', + '', + 'USER', + NULL, + NULL, + '{}', + '' + ); + """.trimIndent()) + } private fun setAuthenticatedUser(email: String) { diff --git a/src/main/java/backend/model/event/EventService.kt b/src/main/java/backend/model/event/EventService.kt index 7359da66..48daa9b9 100644 --- a/src/main/java/backend/model/event/EventService.kt +++ b/src/main/java/backend/model/event/EventService.kt @@ -39,4 +39,8 @@ interface EventService { fun getDonateSum(id: Long): DonateSums fun regenerateCache(eventId: Long?) + + fun markAsCurrent(eventId: Long): Event + + fun allowNewSponsoring(eventId: Long): Event } diff --git a/src/main/java/backend/model/event/EventServiceImpl.kt b/src/main/java/backend/model/event/EventServiceImpl.kt index 24bd4674..b84012c6 100644 --- a/src/main/java/backend/model/event/EventServiceImpl.kt +++ b/src/main/java/backend/model/event/EventServiceImpl.kt @@ -99,4 +99,16 @@ class EventServiceImpl @Autowired constructor(val repository: EventRepository, accSums.fullSum + donateSums.fullSum) }.orElseGet { DonateSums(BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO) } } + + override fun markAsCurrent(id: Long): Event { + val event = this.findById(id) ?: throw NotFoundException("event with id $id does not exist") + event.isCurrent = true + return repository.save(event) + } + + override fun allowNewSponsoring(id: Long): Event { + val event = this.findById(id) ?: throw NotFoundException("event with id $id does not exist") + event.allowNewSponsoring = true + return repository.save(event) + } } diff --git a/src/main/resources/db/migration/V201806012220__add_emoji_support_to_posting.sql b/src/main/resources/db/migration/V201806012220__add_emoji_support_to_posting.sql index 8fdcbf34..2f18e4f2 100644 --- a/src/main/resources/db/migration/V201806012220__add_emoji_support_to_posting.sql +++ b/src/main/resources/db/migration/V201806012220__add_emoji_support_to_posting.sql @@ -120,12 +120,12 @@ alter table posting_media convert to character set utf8mb4 collate utf8mb4_unico alter table postinglike convert to character set utf8mb4 collate utf8mb4_unicode_ci; -alter table schema_version convert to character set utf8mb4 collate utf8mb4_unicode_ci; -ALTER TABLE `schema_version` CHANGE `version` `version` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL; -ALTER TABLE `schema_version` CHANGE `description` `description` VARCHAR(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; -ALTER TABLE `schema_version` CHANGE `type` `type` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; -ALTER TABLE `schema_version` CHANGE `script` `script` VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; -ALTER TABLE `schema_version` CHANGE `installed_by` `installed_by` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; +-- alter table schema_version convert to character set utf8mb4 collate utf8mb4_unicode_ci; +-- ALTER TABLE `schema_version` CHANGE `version` `version` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL; +-- ALTER TABLE `schema_version` CHANGE `description` `description` VARCHAR(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; +-- ALTER TABLE `schema_version` CHANGE `type` `type` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; +-- ALTER TABLE `schema_version` CHANGE `script` `script` VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; +-- ALTER TABLE `schema_version` CHANGE `installed_by` `installed_by` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''; alter table sponsoring convert to character set utf8mb4 collate utf8mb4_unicode_ci; ALTER TABLE `sponsoring` CHANGE `amount_per_km` `amount_per_km` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL; diff --git a/src/main/resources/db/migration/V201904050000__refactored_teamoverview.sql b/src/main/resources/db/migration/V201904050000__refactored_teamoverview.sql index 3132efab..9e6218df 100644 --- a/src/main/resources/db/migration/V201904050000__refactored_teamoverview.sql +++ b/src/main/resources/db/migration/V201904050000__refactored_teamoverview.sql @@ -13,7 +13,7 @@ CREATE TABLE `contact_with_headquarters` ( `reason` int(11) NOT NULL, `comment` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) +); -- Add going to sleep column alter table team add column `asleep` BIT DEFAULT 0; \ No newline at end of file