Improved sample data.

This commit is contained in:
Andrew Lalis 2023-02-06 11:57:58 +01:00
parent 6097b0df7e
commit a8715fa8d2
7 changed files with 114 additions and 52 deletions

View File

@ -1,4 +1,5 @@
country-code,short-name,name
nl,groningen,Groningen nl,groningen,Groningen
nl,amsterdam,Amsterdam nl,amsterdam,Amsterdam
us,tampa,Tampa us,tampa,Tampa
us,new-york-city,New York City us,new-york-city,New York City

1 nl country-code groningen short-name Groningen name
1 country-code short-name name
2 nl nl groningen groningen Groningen Groningen
3 nl nl amsterdam amsterdam Amsterdam Amsterdam
4 us us tampa tampa Tampa Tampa
5 us us new-york-city new-york-city New York City New York City

View File

@ -1,6 +1,7 @@
code,name
us,United States us,United States
nl,Netherlands nl,Netherlands
de,Germany de,Germany
uk,United Kingdom uk,United Kingdom
dk,Denmark dk,Denmark
mx,Mexico mx,Mexico

1 us code United States name
1 code name
2 us us United States United States
3 nl nl Netherlands Netherlands
4 de de Germany Germany
5 uk uk United Kingdom United Kingdom
6 dk dk Denmark Denmark
7 mx mx Mexico Mexico

View File

@ -1,5 +1,6 @@
short-name,name
barbell-bench-press,Barbell Bench Press barbell-bench-press,Barbell Bench Press
barbell-squat,Barbell Squat barbell-squat,Barbell Squat
barbell-deadlift,Barbell Deadlift barbell-deadlift,Barbell Deadlift
barbell-overhead-press,Barbell Overhead Press barbell-overhead-press,Barbell Overhead Press
incline-dumbbell-bicep-curl,Incline Dumbbell Bicep Curl incline-dumbbell-bicep-curl,Incline Dumbbell Bicep Curl

1 barbell-bench-press short-name Barbell Bench Press name
1 short-name name
2 barbell-bench-press barbell-bench-press Barbell Bench Press Barbell Bench Press
3 barbell-squat barbell-squat Barbell Squat Barbell Squat
4 barbell-deadlift barbell-deadlift Barbell Deadlift Barbell Deadlift
5 barbell-overhead-press barbell-overhead-press Barbell Overhead Press Barbell Overhead Press
6 incline-dumbbell-bicep-curl incline-dumbbell-bicep-curl Incline Dumbbell Bicep Curl Incline Dumbbell Bicep Curl

View File

@ -1,3 +1,4 @@
country-code,city-short-name,short-name,name,website-url,latitude,longitude,street-address
nl,groningen,trainmore-munnekeholm,Trainmore Munnekeholm,https://trainmore.nl/clubs/munnekeholm/,53.215939,6.561549,"Munnekeholm 1, 9711 JA Groningen" nl,groningen,trainmore-munnekeholm,Trainmore Munnekeholm,https://trainmore.nl/clubs/munnekeholm/,53.215939,6.561549,"Munnekeholm 1, 9711 JA Groningen"
nl,groningen,trainmore-oude-ebbinge,Trainmore Oude Ebbinge Non-Stop,https://trainmore.nl/clubs/oude-ebbinge/,53.2209,6.565976,Oude Ebbingestraat 54-58 nl,groningen,trainmore-oude-ebbinge,Trainmore Oude Ebbinge Non-Stop,https://trainmore.nl/clubs/oude-ebbinge/,53.2209,6.565976,Oude Ebbingestraat 54-58
us,tampa,powerhouse-gym,Powerhouse Gym Athletic Club,http://www.pgathleticclub.com/,27.997223,-82.496237,"3251-A W Hillsborough Ave, Tampa, FL 33614, United States" us,tampa,powerhouse-gym,Powerhouse Gym Athletic Club,http://www.pgathleticclub.com/,27.997223,-82.496237,"3251-A W Hillsborough Ave, Tampa, FL 33614, United States"

1 nl country-code groningen city-short-name trainmore-munnekeholm short-name Trainmore Munnekeholm name https://trainmore.nl/clubs/munnekeholm/ website-url 53.215939 latitude 6.561549 longitude Munnekeholm 1, 9711 JA Groningen street-address
1 country-code city-short-name short-name name website-url latitude longitude street-address
2 nl nl groningen groningen trainmore-munnekeholm trainmore-munnekeholm Trainmore Munnekeholm Trainmore Munnekeholm https://trainmore.nl/clubs/munnekeholm/ https://trainmore.nl/clubs/munnekeholm/ 53.215939 53.215939 6.561549 6.561549 Munnekeholm 1, 9711 JA Groningen Munnekeholm 1, 9711 JA Groningen
3 nl nl groningen groningen trainmore-oude-ebbinge trainmore-oude-ebbinge Trainmore Oude Ebbinge Non-Stop Trainmore Oude Ebbinge Non-Stop https://trainmore.nl/clubs/oude-ebbinge/ https://trainmore.nl/clubs/oude-ebbinge/ 53.2209 53.2209 6.565976 6.565976 Oude Ebbingestraat 54-58 Oude Ebbingestraat 54-58
4 us us tampa tampa powerhouse-gym powerhouse-gym Powerhouse Gym Athletic Club Powerhouse Gym Athletic Club http://www.pgathleticclub.com/ http://www.pgathleticclub.com/ 27.997223 27.997223 -82.496237 -82.496237 3251-A W Hillsborough Ave, Tampa, FL 33614, United States 3251-A W Hillsborough Ave, Tampa, FL 33614, United States

View File

@ -1,3 +1,4 @@
exercise-short-name,raw-weight,weight-unit,reps,submitter-name,gym-id,video-filename
barbell-overhead-press,60,KG,1,Andrew Lalis,nl_groningen_trainmore-munnekeholm,sample_video_ohp.mp4 barbell-overhead-press,60,KG,1,Andrew Lalis,nl_groningen_trainmore-munnekeholm,sample_video_ohp.mp4
incline-dumbbell-bicep-curl,14,KG,10,Andrew Lalis,nl_groningen_trainmore-munnekeholm,sample_video_curl.mp4 incline-dumbbell-bicep-curl,14,KG,10,Andrew Lalis,nl_groningen_trainmore-munnekeholm,sample_video_curl.mp4
barbell-bench-press,105,KG,5,William Johnson,nl_groningen_trainmore-munnekeholm,sample_video_ohp.mp4 barbell-bench-press,105,KG,5,William Johnson,nl_groningen_trainmore-munnekeholm,sample_video_ohp.mp4
@ -5,4 +6,4 @@ barbell-deadlift,210,LBS,1,Steve,us_tampa_powerhouse-gym,sample_video_curl.mp4
barbell-squat,225,LBS,8,Ronnie Coleman,us_tampa_powerhouse-gym,sample_video_ohp.mp4 barbell-squat,225,LBS,8,Ronnie Coleman,us_tampa_powerhouse-gym,sample_video_ohp.mp4
barbell-overhead-press,110,KG,12,Larry Wheels,nl_groningen_trainmore-oude-ebbinge,sample_video_ohp.mp4 barbell-overhead-press,110,KG,12,Larry Wheels,nl_groningen_trainmore-oude-ebbinge,sample_video_ohp.mp4
barbell-bench-press,785,LBS,1,Julius Maddox,us_tampa_powerhouse-gym,sample_video_ohp.mp4 barbell-bench-press,785,LBS,1,Julius Maddox,us_tampa_powerhouse-gym,sample_video_ohp.mp4
barbell-squat,350,KG,2,Daniel Zamani,nl_groningen_trainmore-oude-ebbinge,sample_video_curl.mp4 barbell-squat,350,KG,2,Daniel Zamani,nl_groningen_trainmore-oude-ebbinge,sample_video_curl.mp4

1 barbell-overhead-press exercise-short-name 60 raw-weight KG weight-unit 1 reps Andrew Lalis submitter-name nl_groningen_trainmore-munnekeholm gym-id sample_video_ohp.mp4 video-filename
1 exercise-short-name raw-weight weight-unit reps submitter-name gym-id video-filename
2 barbell-overhead-press barbell-overhead-press 60 60 KG KG 1 1 Andrew Lalis Andrew Lalis nl_groningen_trainmore-munnekeholm nl_groningen_trainmore-munnekeholm sample_video_ohp.mp4 sample_video_ohp.mp4
3 incline-dumbbell-bicep-curl incline-dumbbell-bicep-curl 14 14 KG KG 10 10 Andrew Lalis Andrew Lalis nl_groningen_trainmore-munnekeholm nl_groningen_trainmore-munnekeholm sample_video_curl.mp4 sample_video_curl.mp4
4 barbell-bench-press barbell-bench-press 105 105 KG KG 5 5 William Johnson William Johnson nl_groningen_trainmore-munnekeholm nl_groningen_trainmore-munnekeholm sample_video_ohp.mp4 sample_video_ohp.mp4
6 barbell-squat barbell-squat 225 225 LBS LBS 8 8 Ronnie Coleman Ronnie Coleman us_tampa_powerhouse-gym us_tampa_powerhouse-gym sample_video_ohp.mp4 sample_video_ohp.mp4
7 barbell-overhead-press barbell-overhead-press 110 110 KG KG 12 12 Larry Wheels Larry Wheels nl_groningen_trainmore-oude-ebbinge nl_groningen_trainmore-oude-ebbinge sample_video_ohp.mp4 sample_video_ohp.mp4
8 barbell-bench-press barbell-bench-press 785 785 LBS LBS 1 1 Julius Maddox Julius Maddox us_tampa_powerhouse-gym us_tampa_powerhouse-gym sample_video_ohp.mp4 sample_video_ohp.mp4
9 barbell-squat barbell-squat 350 350 KG KG 2 2 Daniel Zamani Daniel Zamani nl_groningen_trainmore-oude-ebbinge nl_groningen_trainmore-oude-ebbinge sample_video_curl.mp4 sample_video_curl.mp4

View File

@ -1,4 +1,30 @@
jay.cutler@example.com,testpass,Jay Cutler, email,password,name,roles,following,birth-date,current-weight,current-weight-unit,sex,locale,account-private
mike.mentzer@example.com,testpass,Mike Mentzer, jay.cutler@example.com,testpass,Jay Cutler,,"mike.mentzer@example.com
ronnie.coleman@example.com,testpass,Ronnie 'Lightweight' Coleman, ronnie.coleman@example.com",1973-08-03,260,LBS,MALE,en-US,FALSE
andrew.lalis@example.com,testpass,Andrew Lalis,admin mike.mentzer@example.com,testpass,Mike Mentzer,,"ronnie.coleman@example.com
jay.cutler@example.com
andrew.lalis@example.com",1951-11-15,244,LBS,MALE,en-US,FALSE
ronnie.coleman@example.com,testpass,Ronnie 'Lightweight' Coleman,,jay.cutler@example.com,1964-05-13,315,LBS,MALE,en-US,FALSE
andrew.lalis@example.com,testpass,Andrew Lalis,admin,"said.faroghi@example.com
klaus.lalis@example.com
zino.holwerda@example.com
tom.denboon@example.com
max.verbeek@example.com",1997-12-13,98,KG,MALE,en-US,FALSE
said.faroghi@example.com,testpass,Said Faroghi,,"andrew.lalis@example.com
zino.holwerda@example.com",1995-11-11,68,KG,MALE,en-US,TRUE
erblin.ibrahimi@example.com,testpass,Erblin Ibrahimi,,"max.verbeek@example.com
niels.bugel@example.com
ronnie.coleman@example.com",1998-09-28,101,KG,MALE,nl-NL,FALSE
max.verbeek@example.com,testpass,Max Verbeek,,"erblin.ibrahimi@example.com
niels.bugel@example.com
klaus.lalis@example.com",1998-01-24,85,KG,MALE,nl-NL,FALSE
niels.bugel@example.com,testpass,Niels Bugel,,"erblin.ibrahimi@example.com
max.verbeek@example.com
andrew.lalis@example.com",1996-04-21,95,KG,MALE,nl-NL,FALSE
zino.holwerda@example.com,testpass,Zino Holwerda,,"andrew.lalis@example.com
said.faroghi@example.com
tom.denboon@example.com
klaus.lalis@example.com",1997-04-22,91,KG,MALE,nl-NL,TRUE
tom.denboon@example.com,testpass,Tom den Boon,,zino.holwerda@example.com,1998-11-09,84,KG,MALE,nl-NL,FALSE
klaus.lalis@example.com,testpass,Klaus Lalis,,"andrew.lalis@example.com
zino.holwerda@example.com",2000-12-15,93,KG,MALE,en-US,FALSE

1 jay.cutler@example.com email testpass password Jay Cutler name roles following birth-date current-weight current-weight-unit sex locale account-private
2 mike.mentzer@example.com jay.cutler@example.com testpass testpass Mike Mentzer Jay Cutler mike.mentzer@example.com ronnie.coleman@example.com 1973-08-03 260 LBS MALE en-US FALSE
3 ronnie.coleman@example.com mike.mentzer@example.com testpass testpass Ronnie 'Lightweight' Coleman Mike Mentzer ronnie.coleman@example.com jay.cutler@example.com andrew.lalis@example.com 1951-11-15 244 LBS MALE en-US FALSE
4 andrew.lalis@example.com ronnie.coleman@example.com testpass testpass Andrew Lalis Ronnie 'Lightweight' Coleman admin jay.cutler@example.com 1964-05-13 315 LBS MALE en-US FALSE
5 andrew.lalis@example.com testpass Andrew Lalis admin said.faroghi@example.com klaus.lalis@example.com zino.holwerda@example.com tom.denboon@example.com max.verbeek@example.com 1997-12-13 98 KG MALE en-US FALSE
6 said.faroghi@example.com testpass Said Faroghi andrew.lalis@example.com zino.holwerda@example.com 1995-11-11 68 KG MALE en-US TRUE
7 erblin.ibrahimi@example.com testpass Erblin Ibrahimi max.verbeek@example.com niels.bugel@example.com ronnie.coleman@example.com 1998-09-28 101 KG MALE nl-NL FALSE
8 max.verbeek@example.com testpass Max Verbeek erblin.ibrahimi@example.com niels.bugel@example.com klaus.lalis@example.com 1998-01-24 85 KG MALE nl-NL FALSE
9 niels.bugel@example.com testpass Niels Bugel erblin.ibrahimi@example.com max.verbeek@example.com andrew.lalis@example.com 1996-04-21 95 KG MALE nl-NL FALSE
10 zino.holwerda@example.com testpass Zino Holwerda andrew.lalis@example.com said.faroghi@example.com tom.denboon@example.com klaus.lalis@example.com 1997-04-22 91 KG MALE nl-NL TRUE
11 tom.denboon@example.com testpass Tom den Boon zino.holwerda@example.com 1998-11-09 84 KG MALE nl-NL FALSE
12 klaus.lalis@example.com testpass Klaus Lalis andrew.lalis@example.com zino.holwerda@example.com 2000-12-15 93 KG MALE en-US FALSE
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

View File

@ -11,10 +11,13 @@ import nl.andrewlalis.gymboard_api.domains.api.model.exercise.Exercise;
import nl.andrewlalis.gymboard_api.domains.api.service.cdn_client.CdnClient; import nl.andrewlalis.gymboard_api.domains.api.service.cdn_client.CdnClient;
import nl.andrewlalis.gymboard_api.domains.api.service.submission.ExerciseSubmissionService; import nl.andrewlalis.gymboard_api.domains.api.service.submission.ExerciseSubmissionService;
import nl.andrewlalis.gymboard_api.domains.auth.dao.RoleRepository; import nl.andrewlalis.gymboard_api.domains.auth.dao.RoleRepository;
import nl.andrewlalis.gymboard_api.domains.auth.dao.UserPersonalDetailsRepository;
import nl.andrewlalis.gymboard_api.domains.auth.dao.UserPreferencesRepository;
import nl.andrewlalis.gymboard_api.domains.auth.dao.UserRepository; import nl.andrewlalis.gymboard_api.domains.auth.dao.UserRepository;
import nl.andrewlalis.gymboard_api.domains.auth.dto.UserCreationPayload; import nl.andrewlalis.gymboard_api.domains.auth.dto.UserCreationPayload;
import nl.andrewlalis.gymboard_api.domains.auth.model.Role; import nl.andrewlalis.gymboard_api.domains.auth.model.Role;
import nl.andrewlalis.gymboard_api.domains.auth.model.User; import nl.andrewlalis.gymboard_api.domains.auth.model.User;
import nl.andrewlalis.gymboard_api.domains.auth.model.UserPersonalDetails;
import nl.andrewlalis.gymboard_api.domains.auth.service.UserService; import nl.andrewlalis.gymboard_api.domains.auth.service.UserService;
import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord; import org.apache.commons.csv.CSVRecord;
@ -31,8 +34,7 @@ import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashSet; import java.time.LocalDate;
import java.util.Set;
/** /**
* Simple component that loads sample data that's useful when testing the application. * Simple component that loads sample data that's useful when testing the application.
@ -47,6 +49,8 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
private final ExerciseSubmissionService submissionService; private final ExerciseSubmissionService submissionService;
private final RoleRepository roleRepository; private final RoleRepository roleRepository;
private final UserRepository userRepository; private final UserRepository userRepository;
private final UserPersonalDetailsRepository personalDetailsRepository;
private final UserPreferencesRepository preferencesRepository;
private final UserService userService; private final UserService userService;
@Value("${app.cdn-origin}") @Value("${app.cdn-origin}")
@ -58,7 +62,7 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
GymRepository gymRepository, GymRepository gymRepository,
ExerciseRepository exerciseRepository, ExerciseRepository exerciseRepository,
ExerciseSubmissionService submissionService, ExerciseSubmissionService submissionService,
RoleRepository roleRepository, UserRepository userRepository, UserService userService) { RoleRepository roleRepository, UserRepository userRepository, UserPersonalDetailsRepository personalDetailsRepository, UserPreferencesRepository preferencesRepository, UserService userService) {
this.countryRepository = countryRepository; this.countryRepository = countryRepository;
this.cityRepository = cityRepository; this.cityRepository = cityRepository;
this.gymRepository = gymRepository; this.gymRepository = gymRepository;
@ -66,6 +70,8 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
this.submissionService = submissionService; this.submissionService = submissionService;
this.roleRepository = roleRepository; this.roleRepository = roleRepository;
this.userRepository = userRepository; this.userRepository = userRepository;
this.personalDetailsRepository = personalDetailsRepository;
this.preferencesRepository = preferencesRepository;
this.userService = userService; this.userService = userService;
} }
@ -77,6 +83,7 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
log.info("Generating sample data."); log.info("Generating sample data.");
try { try {
generateSampleData(); generateSampleData();
secondPassGenerateSampleData();
Files.writeString(markerFile, "Yes"); Files.writeString(markerFile, "Yes");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -86,27 +93,32 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
@Transactional @Transactional
protected void generateSampleData() throws Exception { protected void generateSampleData() throws Exception {
loadCsv("exercises", record -> { loadCsv("exercises", record -> {
exerciseRepository.save(new Exercise(record.get(0), record.get(1))); exerciseRepository.save(new Exercise(record.get("short-name"), record.get("name")));
}); });
loadCsv("countries", record -> { loadCsv("countries", record -> {
countryRepository.save(new Country(record.get(0), record.get(1))); countryRepository.save(new Country(record.get("code"), record.get("name")));
}); });
loadCsv("cities", record -> { loadCsv("cities", record -> {
var country = countryRepository.findById(record.get(0)).orElseThrow(); var country = countryRepository.findById(record.get("country-code")).orElseThrow();
cityRepository.save(new City(record.get(1), record.get(2), country)); String shortName = record.get("short-name");
String name = record.get("name");
cityRepository.save(new City(shortName, name, country));
}); });
loadCsv("gyms", record -> { loadCsv("gyms", record -> {
var city = cityRepository.findByShortNameAndCountryCode(record.get(1), record.get(0)).orElseThrow(); var city = cityRepository.findByShortNameAndCountryCode(
record.get("city-short-name"),
record.get("country-code")
).orElseThrow();
gymRepository.save(new Gym( gymRepository.save(new Gym(
city, city,
record.get(2), record.get("short-name"),
record.get(3), record.get("name"),
record.get(4), record.get("website-url"),
new GeoPoint( new GeoPoint(
new BigDecimal(record.get(5)), new BigDecimal(record.get("latitude")),
new BigDecimal(record.get(6)) new BigDecimal(record.get("longitude"))
), ),
record.get(7) record.get("street-address")
)); ));
}); });
@ -114,18 +126,16 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
// We upload a video for each submission, and wait until all uploads are processed before continuing. // We upload a video for each submission, and wait until all uploads are processed before continuing.
final CdnClient cdnClient = new CdnClient(cdnOrigin); final CdnClient cdnClient = new CdnClient(cdnOrigin);
final Set<String> videoIds = new HashSet<>();
loadCsv("submissions", record -> { loadCsv("submissions", record -> {
var exercise = exerciseRepository.findById(record.get(0)).orElseThrow(); var exercise = exerciseRepository.findById(record.get("exercise-short-name")).orElseThrow();
BigDecimal weight = new BigDecimal(record.get(1)); BigDecimal weight = new BigDecimal(record.get("raw-weight"));
WeightUnit unit = WeightUnit.parse(record.get(2)); WeightUnit unit = WeightUnit.parse(record.get("weight-unit"));
int reps = Integer.parseInt(record.get(3)); int reps = Integer.parseInt(record.get("reps"));
String name = record.get(4); String name = record.get("submitter-name");
CompoundGymId gymId = CompoundGymId.parse(record.get(5)); CompoundGymId gymId = CompoundGymId.parse(record.get("gym-id"));
String videoFilename = record.get(6); String videoFilename = record.get("video-filename");
// Upload the video to the CDN, and wait until it's done processing.
log.info("Uploading video {} to CDN...", videoFilename); log.info("Uploading video {} to CDN...", videoFilename);
var video = cdnClient.uploads.uploadVideo(Path.of("sample_data", videoFilename), "video/mp4"); var video = cdnClient.uploads.uploadVideo(Path.of("sample_data", videoFilename), "video/mp4");
submissionService.createSubmission(gymId, new ExerciseSubmissionPayload( submissionService.createSubmission(gymId, new ExerciseSubmissionPayload(
@ -136,28 +146,21 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
reps, reps,
video.id() video.id()
)); ));
videoIds.add(video.id());
}); });
int count = videoIds.size();
while (!videoIds.isEmpty()) {
log.info("Waiting for {} / {} videos to finish processing...", videoIds.size(), count);
Set<String> removalSet = new HashSet<>();
for (var videoId : videoIds) {
String status = cdnClient.uploads.getVideoProcessingStatus(videoId).status();
if (status.equalsIgnoreCase("COMPLETED") || status.equalsIgnoreCase("FAILED")) {
removalSet.add(videoId);
}
}
videoIds.removeAll(removalSet);
Thread.sleep(1000);
}
loadCsv("users", record -> { loadCsv("users", record -> {
String email = record.get(0); String email = record.get("email");
String password = record.get(1); String password = record.get("password");
String name = record.get(2); String name = record.get("name");
String[] roleNames = record.get(3).split("\\s*\\|\\s*"); String[] roleNames = record.get("roles").split("\\s*\\n\\s*");
LocalDate birthDate = LocalDate.parse(record.get("birth-date"));
BigDecimal currentWeight = new BigDecimal(record.get("current-weight"));
WeightUnit currentWeightUnit = WeightUnit.parse(record.get("current-weight-unit"));
BigDecimal metricWeight = new BigDecimal(currentWeight.toString());
if (currentWeightUnit == WeightUnit.POUNDS) {
metricWeight = WeightUnit.toKilograms(metricWeight);
}
UserPersonalDetails.PersonSex sex = UserPersonalDetails.PersonSex.parse(record.get("sex"));
UserCreationPayload payload = new UserCreationPayload(email, password, name); UserCreationPayload payload = new UserCreationPayload(email, password, name);
var resp = userService.createUser(payload, false); var resp = userService.createUser(payload, false);
@ -169,6 +172,30 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
user.getRoles().add(role); user.getRoles().add(role);
} }
userRepository.save(user); userRepository.save(user);
var pd = personalDetailsRepository.findById(user.getId()).orElseThrow();
pd.setBirthDate(birthDate);
pd.setCurrentWeight(currentWeight);
pd.setCurrentWeightUnit(currentWeightUnit);
pd.setCurrentMetricWeight(metricWeight);
pd.setSex(sex);
personalDetailsRepository.save(pd);
var p = preferencesRepository.findById(user.getId()).orElseThrow();
p.setLocale(record.get("locale"));
p.setAccountPrivate(Boolean.parseBoolean(record.get("account-private")));
preferencesRepository.save(p);
});
}
@Transactional
protected void secondPassGenerateSampleData() throws Exception {
loadCsv("users", record -> {
String email = record.get("email");
String[] followingEmails = record.get("following").split("\\s*\\n\\s*");
User user = userRepository.findByEmail(email).orElseThrow();
for (String followingEmail : followingEmails) {
User userToFollow = userRepository.findByEmail(followingEmail).orElseThrow();
userService.followUser(user.getId(), userToFollow.getId());
}
}); });
} }
@ -181,7 +208,11 @@ public class SampleDataLoader implements ApplicationListener<ContextRefreshedEve
String path = "sample_data/" + csvName + ".csv"; String path = "sample_data/" + csvName + ".csv";
log.info("Loading data from {}...", path); log.info("Loading data from {}...", path);
var reader = new FileReader(path); var reader = new FileReader(path);
for (var record : CSVFormat.DEFAULT.parse(reader)) { CSVFormat format = CSVFormat.DEFAULT.builder()
.setHeader()
.setSkipHeaderRecord(true)
.build();
for (var record : format.parse(reader)) {
try { try {
recordConsumer.accept(record); recordConsumer.accept(record);
} catch (Exception e) { } catch (Exception e) {