Skip to content

Feature/perfect dev mock data #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 61 additions & 4 deletions src/main/java/backend/configuration/TestDataInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +26,7 @@ import java.time.LocalDateTime
import javax.annotation.PostConstruct

@Service
@Profile(HEROKU)
@Profile(HEROKU, DEVELOPMENT)
class TestDataInitializer {

// Services
Expand All @@ -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)!!
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/backend/model/event/EventService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions src/main/java/backend/model/event/EventServiceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;