[Notice] Announcing the End of Demo Server [Read me]

Insert essential data the first time hive runs.
@47c8c706238f3cd7e95867dcdaa9eeb3eaa6e2fa
--- app/Global.java
+++ app/Global.java
... | ... | @@ -17,58 +17,65 @@ |
17 | 17 |
|
18 | 18 |
public class Global extends GlobalSettings { |
19 | 19 |
public void onStart(Application app) { |
20 |
+ insertInitialData(); |
|
20 | 21 |
if (app.isTest()) { |
21 | 22 |
insertTestData(); |
22 | 23 |
} |
23 | 24 |
} |
24 | 25 |
|
25 |
- private static void insertTestData() { |
|
26 |
+ private static void insertDataFromYaml(String yamlFileName, String[] entityNames) { |
|
27 |
+ @SuppressWarnings("unchecked") |
|
28 |
+ Map<String, List<Object>> all = (Map<String, List<Object>>) Yaml |
|
29 |
+ .load(yamlFileName); |
|
30 |
+ |
|
31 |
+ // Check whether every entities exist. |
|
32 |
+ for (String entityName : entityNames) { |
|
33 |
+ if (all.get(entityName) == null) { |
|
34 |
+ throw new RuntimeException("Failed to find the '" + entityName |
|
35 |
+ + "' entity in '" + yamlFileName + "'"); |
|
36 |
+ } |
|
37 |
+ } |
|
38 |
+ |
|
39 |
+ for (String entityName : entityNames) { |
|
40 |
+ Ebean.save(all.get(entityName)); |
|
41 |
+ } |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ private static void insertInitialData() { |
|
26 | 45 |
if (Ebean.find(User.class).findRowCount() == 0) { |
27 |
- String initFileName = "initial-data.test.yml"; |
|
28 |
- |
|
29 |
- @SuppressWarnings("unchecked") |
|
30 |
- Map<String, List<Object>> all = (Map<String, List<Object>>) Yaml |
|
31 |
- .load(initFileName); |
|
32 |
- |
|
33 | 46 |
String[] entityNames = { |
34 |
- "users", "projects", "milestones", |
|
35 |
- "issues", "issueComments", |
|
36 |
- "postings", "postingComments", |
|
37 |
- "roles", "projectUsers", |
|
38 |
- "siteAdmins" |
|
47 |
+ "users", "roles", "siteAdmins" |
|
39 | 48 |
}; |
40 | 49 |
|
41 |
- // Check whether every entities exist. |
|
42 |
- for (String entityName : entityNames) { |
|
43 |
- if (all.get(entityName) == null) { |
|
44 |
- throw new RuntimeException("Failed to find the '" + entityName |
|
45 |
- + "' entity in '" + initFileName + "'"); |
|
46 |
- } |
|
50 |
+ insertDataFromYaml("initial-data.yml", entityNames); |
|
51 |
+ } |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ private static void insertTestData() { |
|
55 |
+ String[] entityNames = { |
|
56 |
+ "projects", "milestones", "issues", "issueComments", "postings", |
|
57 |
+ "postingComments", "projectUsers" |
|
58 |
+ }; |
|
59 |
+ |
|
60 |
+ insertDataFromYaml("test-data.yml", entityNames); |
|
61 |
+ |
|
62 |
+ // Do numbering for issues and postings. |
|
63 |
+ for (Project project : Project.find.findList()) { |
|
64 |
+ List<Issue> issues = Issue.finder.where() |
|
65 |
+ .eq("project.id", project.id).orderBy("id desc") |
|
66 |
+ .findList(); |
|
67 |
+ |
|
68 |
+ for (Issue issue: issues) { |
|
69 |
+ issue.save(); |
|
47 | 70 |
} |
48 | 71 |
|
49 |
- for (String entityName : entityNames) { |
|
50 |
- Ebean.save(all.get(entityName)); |
|
72 |
+ List<Posting> postings = Posting.finder.where() |
|
73 |
+ .eq("project.id", project.id).orderBy("id desc") |
|
74 |
+ .findList(); |
|
75 |
+ |
|
76 |
+ for (Posting posting: postings) { |
|
77 |
+ posting.save(); |
|
51 | 78 |
} |
52 |
- |
|
53 |
- // Do numbering for issues and postings. |
|
54 |
- for (Project project : Project.find.findList()) { |
|
55 |
- List<Issue> issues = Issue.finder.where() |
|
56 |
- .eq("project.id", project.id).orderBy("id desc") |
|
57 |
- .findList(); |
|
58 |
- |
|
59 |
- for (Issue issue: issues) { |
|
60 |
- issue.save(); |
|
61 |
- } |
|
62 |
- |
|
63 |
- List<Posting> postings = Posting.finder.where() |
|
64 |
- .eq("project.id", project.id).orderBy("id desc") |
|
65 |
- .findList(); |
|
66 |
- |
|
67 |
- for (Posting posting: postings) { |
|
68 |
- posting.save(); |
|
69 |
- } |
|
70 |
- } |
|
71 |
- |
|
72 | 79 |
} |
73 | 80 |
} |
74 | 81 |
|
+++ conf/initial-data.yml
... | ... | @@ -0,0 +1,24 @@ |
1 | +# Users | |
2 | +users: | |
3 | + - !!models.User | |
4 | + name: Site admin | |
5 | + loginId: admin | |
6 | + password: 5v4TVjzLo1bqullT1CU4/bENUNOUfX97WpdunGLvJvw= | |
7 | + passwordSalt: '[B@1032a4' | |
8 | + email: admin@nhn.com | |
9 | + avatarUrl: /assets/images/default-avatar-128.png | |
10 | + createdDate: 2012-11-01 08:00:00 | |
11 | + | |
12 | +siteAdmins: | |
13 | + - !!models.SiteAdmin | |
14 | + admin: !!models.User | |
15 | + id: 1 | |
16 | + | |
17 | +# Role | |
18 | +roles: | |
19 | + - !!models.Role | |
20 | + name: manager | |
21 | + active: true | |
22 | + - !!models.Role | |
23 | + name: member | |
24 | + active: true |
--- conf/initial-data.test.yml
+++ conf/test-data.yml
No changes |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?