-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeder.js
439 lines (408 loc) · 23.4 KB
/
seeder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/**
* This is a seeder script to set up a mock Wing, with its groups, and squadrons, and members in a local Common API instance.
*
* To use locally, run "npm install" in this directory, and then "node seeder.js", or if you want to
* run the requests thru a proxy if you have Spring Security enabled, you can use something like the "jwt-cli-utility"
* and issue the command "PROXY=http://localhost:<proxy-port>/api/v2 node seeder.js".
*
* This script uses the json-patch content-type for organization updates.
*
*/
'use strict';
const fetch = require('node-fetch');
let url = process.env.PROXY || 'http://localhost:8088/api/v2';
async function addNewPerson(spec) {
console.log("Adding new Person");
let [rank, firstName, middleName, lastName, email] = spec.split(/\s/);
let urlString = `${url}/person`;
if (rank === 'LtCol') rank = "Lt Col";
else if (rank === '2Lt') rank = "2nd Lt";
else if (rank === '1Lt') rank = "1st Lt";
let resp = await fetch(urlString, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
firstName, middleName, lastName, rank, email, branch: 'USAF'
})
});
if (resp.status !== 201) throw new Error("Bad Add Person");
let json = await resp.json();
return json.id;
}
async function addNewOrg(type, name, parentId) {
console.log("Adding new Org");
let urlString = `${url}/organization`;
let resp = await fetch(urlString, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
name, members: [], leader: null, parentOrganization: parentId, orgType: type.toUpperCase(), branchType: 'USAF'
})
});
if (resp.status !== 201) throw new Error("Bad Add Org");
let json = await resp.json();
return json.id;
}
async function addMemberOrgs(id, orgs) {
console.log("Adding member org");
let resp = await fetch(`${url}/organization/${id}/subordinates`, {
method: 'PATCH',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(orgs)
});
if (resp.status !== 200) throw new Error("Bad Add Member Org");
let json = await resp.json();
return json.id;
}
async function addLeader(id, leader) {
console.log("Adding Leader");
let resp = await fetch(`${url}/organization/${id}`, {
method: 'PATCH',
headers: {
'content-type': 'application/json-patch+json'
},
body: JSON.stringify([{ op: 'replace', path: '/leader', value: leader }])
});
if (resp.status !== 200) throw new Error("Bad Add Leader");
let json = await resp.json();
return json.id;
}
async function addMember(id, member) {
console.log("Adding Member");
let resp = await fetch(`${url}/organization/${id}/members`, {
method: 'PATCH',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify([member])
});
if (resp.status !== 200) throw new Error("Bad Add Member");
let json = await resp.json();
return json.id;
}
async function createOrgStructure(org, parent) {
let newOrgId = await addNewOrg(org.type, org.name, parent);
// add leader if present
if (org.leader != null) {
let leaderId = await addNewPerson(org.leader);
await addLeader(newOrgId, leaderId);
}
// add members if present
if (org.members != null) {
for (let member of org.members) {
let memberId = await addNewPerson(member);
await addMember(newOrgId, memberId);
}
}
// if has subordinate orgs
if (org.units != null) {
let subOrgUuids = [];
// go create the suborgs themselves and store the uuids
for (let unit of org.units) {
subOrgUuids.push(await createOrgStructure(unit, newOrgId));
}
// go add the new suborgs to the parent
await addMemberOrgs(newOrgId, subOrgUuids);
}
return newOrgId;
}
const orgStructure = {
name: "181st IW",
type : "WING",
leader : 'Col JOHNNY A APPLESEED [email protected]',
units : [
{
name : "181st ISRG",
type : "GROUP",
leader : 'Col FRED A SMITH [email protected]',
units : [
{
name : "137th IS",
type : "SQUADRON",
leader : 'LtCol JOEY A JOJO [email protected]',
members : [
'SrA Marley Esperanza Windler [email protected]',
'SSgt Turner Oren Pouros [email protected]',
'SrA Hester Davin Leuschke [email protected]',
'SrA Keaton Lauretta Schneider [email protected]',
'MSgt Harrison Hershel Wintheiser [email protected]',
'1Lt Chadd Kyra Wilderman [email protected]',
'2Lt Jacklyn Dereck Schulist [email protected]',
'TSgt Bradly Clarabelle Ruecker [email protected]',
'SSgt Nathanial Tod Oberbrunner [email protected]',
'SrA Angelita Oma Gutmann [email protected]',
'AB Joe Stephanie Bode [email protected]',
'A1C Nils Jaiden Swift [email protected]',
'TSgt Cydney Itzel Stamm [email protected]',
'MSgt Ernesto Alec Dooley [email protected]',
'1Lt Hattie Ulises Doyle [email protected]',
'SrA Jocelyn Raymundo Hermann [email protected]',
'2Lt Velma Ettie Rippin [email protected]',
'AB Antonietta Shaun Kozey [email protected]',
'SSgt Trudie Casey OKon [email protected]',
'SSgt Cordia Ursula Lynch [email protected]',
'1Lt Tavares Conrad Becker [email protected]',
'1Lt Rosamond Maya Raynor [email protected]',
'SSgt Vaughn Jakob Okuneva [email protected]',
'1Lt Hattie Claire Powlowski [email protected]',
'SMSgt Coty Kiley Rohan [email protected]',
'AB Michale Whitney Stracke [email protected]',
'MSgt Ezra Rubye Gibson [email protected]',
'AB Edwin Delphia Powlowski [email protected]',
'2Lt Marta Elfrieda Hoeger [email protected]',
'TSgt Verona Santos Rohan [email protected]',
'2Lt Isabel Dave Cole [email protected]',
'A1C Davon Sadie Ryan [email protected]',
'SSgt Darrick Charlotte Gleason [email protected]',
'TSgt Lilly Lily Conroy [email protected]',
'TSgt Julia Jarvis Parisian [email protected]',
'AB Brooklyn Arnulfo Aufderhar [email protected]',
'A1C Velva Zachary Pollich [email protected]',
'SMSgt Kole Presley Gorczany [email protected]',
'1Lt Orrin Meagan Grimes [email protected]',
'MSgt Tyler Liliane Heidenreich [email protected]',
'1Lt Lonzo Greta Abernathy [email protected]',
'MSgt Eva Elvera Bergstrom [email protected]',
'A1C Ethel Mikayla Ortiz [email protected]',
'AB Clarabelle Lester Bauch [email protected]',
],
units : null,
},
{
name : "137th ISS",
type : "SQUADRON",
leader : 'LtCol CRAIG A SNELLER [email protected]',
members : [
'1Lt Dimitri Easton Zemlak [email protected]',
'SrA Stephanie Nicola Murray [email protected]',
'2Lt Arlene Skyla Weissnat [email protected]',
'TSgt Alta Casper Graham [email protected]',
'AB Darryl Asha McLaughlin [email protected]',
'SrA Russell Gabriella Kris [email protected]',
'SrA Justus Tomasa Macejkovic [email protected]',
'AB Felicity Lucy Hand [email protected]',
'TSgt Ashley Marcelle Fahey [email protected]',
'A1C Jayne Reese Funk [email protected]',
'SMSgt Jaydon Nakia Orn [email protected]',
'SrA Jovanny Jessy Durgan [email protected]',
'1Lt Cecelia Fabian Pouros [email protected]',
'SMSgt Iliana Edward Little [email protected]',
'1Lt Ebba Bryon Bradtke [email protected]',
'AB Berneice Freeda Hartmann [email protected]',
'1Lt Gudrun Chauncey Keeling [email protected]',
'SrA Dawn Gardner Aufderhar [email protected]',
'2Lt Leanne Dakota Pouros [email protected]',
'A1C Sheridan Prince Homenick [email protected]',
'SrA Trevor Dangelo Gerlach [email protected]',
'TSgt Era Destiney Miller [email protected]',
'AB Keanu Conner Johnston [email protected]',
'SMSgt Richard Beverly Will [email protected]',
'AB Dedric Raven Marquardt [email protected]',
'A1C Kian Jamal Kozey [email protected]',
'MSgt Imogene Morton Swaniawski [email protected]',
'TSgt Nicolette Audra Lubowitz [email protected]',
'SSgt Sofia Vernice Wisoky [email protected]',
'2Lt Bertrand Shanie Weissnat [email protected]',
'SrA Bonnie Noah Stamm [email protected]',
'MSgt Dora Blair Bailey [email protected]',
'MSgt Haley Griffin Spinka [email protected]',
'SSgt Lenora Edgardo Heidenreich [email protected]',
'SrA Vivianne Meghan Brekke [email protected]',
'MSgt Kailey Pete Jenkins [email protected]',
'A1C Fae Alysa Larson [email protected]',
'1Lt Devin Alexandria Crooks [email protected]',
'A1C Brandt Joel Huels [email protected]',
'SSgt Russel Ethan Hegmann [email protected]',
'A1C Dasia Ebba Murazik [email protected]',
'2Lt Oren Joe Bode [email protected]',
'TSgt Earl Susie Champlin [email protected]',
'2Lt Moriah Jerrell Brekke [email protected]',
'2Lt Colby Loraine Grant [email protected]',
'SrA Britney Landen Rippin [email protected]',
'SMSgt Joany Robyn Kirlin [email protected]',
'SrA Misael Vesta Bruen [email protected]',
'TSgt Ulices Maryse Kuphal [email protected]',
'SrA Delaney Oren Armstrong [email protected]',
'MSgt Eunice Cade Kerluke [email protected]',
'2Lt Pearlie Zachary Donnelly [email protected]',
'A1C Danyka Dejuan Rosenbaum [email protected]',
'A1C Nash Brett Ledner [email protected]',
'SMSgt Alexa Herta Moen [email protected]',
'A1C Berta Darius Kirlin [email protected]',
'1Lt Zander Loy Koelpin [email protected]',
'TSgt Novella Jeffery Hackett [email protected]',
'A1C Elmer Jakob Homenick [email protected]',
'A1C Darlene Shawn McKenzie [email protected]',
'1Lt Roosevelt Raquel Roob [email protected]',
'SrA Reanna Jamison Gleichner [email protected]',
'SSgt Chasity Edison Towne [email protected]',
'1Lt Marge Jon Corkery [email protected]',
],
units : null,
},
{
name : "137th OSS",
type : "SQUADRON",
leader : 'LtCol BECCA A LEADER [email protected]',
members : [
'MSgt Zora Karl Toy [email protected]',
'1Lt Bernadine Lincoln Quigley [email protected]',
'MSgt Ivy Jaunita Zemlak [email protected]',
'SrA Lucy Cathy Stanton [email protected]',
'2Lt Gladys Tito Mayert [email protected]',
'SSgt Janis Yvette Wiza [email protected]',
'SrA Alice Shemar Cole [email protected]',
'1Lt Jacinthe Sonya Cummerata [email protected]',
'SrA Bulah Krystel Legros [email protected]',
'SSgt Kale Antwan Upton [email protected]',
'SSgt Holden Leopold Brown [email protected]',
'SSgt Orion Karen Jaskolski [email protected]',
'TSgt Dayna Rosina Conn [email protected]',
'1Lt Deontae Constance Greenholt [email protected]',
'SSgt Marilou Ozella Breitenberg [email protected]',
'AB Hailee Camylle Thiel [email protected]',
'SrA Viola Alia Glover [email protected]',
'AB Alexandrea Dustin Muller [email protected]',
'2Lt Mathias Raymundo Runolfsdottir [email protected]',
'A1C Orlo Lyric Vandervort [email protected]',
'A1C Marc Flavio Kemmer [email protected]',
'1Lt Tess Rashawn Blick [email protected]',
'MSgt Isaiah Catherine Herman [email protected]',
'SMSgt Jeffry Veda Toy [email protected]',
'SSgt Maryse Consuelo Dicki [email protected]',
'2Lt Murl Bridgette Hand [email protected]',
'AB Alexandra Ceasar Walter [email protected]',
'2Lt Juvenal Xander Deckow [email protected]',
'TSgt Pauline Lyda Abernathy [email protected]',
'AB Noemie Estelle Bednar [email protected]',
'SrA Alycia Kellie Breitenberg [email protected]',
'MSgt Marcellus Glennie West [email protected]',
'TSgt Major Chris Casper [email protected]',
'AB Alexander Dylan Skiles [email protected]',
'SrA Branson Maureen Renner [email protected]',
'MSgt Fabian Manley Batz [email protected]',
'SSgt Kacey Colby Halvorson [email protected]',
'1Lt Julian Bernhard Senger [email protected]',
'2Lt Dejon Bennie Jacobs [email protected]',
'SMSgt Angela Lilla Kilback [email protected]',
'A1C Dedrick Mylene Wehner [email protected]',
'AB Otho Zachariah Gorczany [email protected]',
'2Lt Lorna Deonte Wiegand [email protected]',
'SSgt Liliana Suzanne Green [email protected]',
'SSgt Danyka Ismael Ondricka [email protected]',
'2Lt Ashley Stacy Blick [email protected]',
'1Lt Layne Angelina Oberbrunner [email protected]',
'1Lt Vilma Sherman Crist [email protected]',
'SSgt Annie Alden Pollich [email protected]',
'MSgt Shad Clark Kirlin [email protected]',
'SMSgt Daron Nathanael Zboncak [email protected]',
'SMSgt Santos Flossie Beer [email protected]',
'AB Isabel Anastacio Veum [email protected]',
'SMSgt Conner Brody Denesik [email protected]',
'2Lt Lucas Myrtice Durgan [email protected]',
'2Lt Maxime Richmond Thompson [email protected]',
'SrA Kelton Marta Brakus [email protected]',
'TSgt Fannie Cordia Swift [email protected]',
],
units : null,
},
],
},
{
name : "181st MSG",
type : "GROUP",
leader : 'Col SARAH A GRAPESEED [email protected]',
units : [
{
name : "181st LRF",
type : "FLIGHT",
leader : 'Maj JIMBO A SUITER [email protected]',
members : [
'MSgt Daryl Mercedes Goodwin [email protected]',
'SMSgt Wilson Mark Welch [email protected]',
'SrA Clemmie Kelli Willms [email protected]',
'MSgt Lawrence Jovany Predovic [email protected]',
'SSgt Kailyn Rey Ziemann [email protected]',
'A1C Craig Santiago Gorczany [email protected]',
'MSgt Freeda Aliza Turcotte [email protected]',
'SrA Erling Harrison Johnston [email protected]',
'1Lt Anabelle Lucile Mohr [email protected]',
'A1C Eldred Weldon Hodkiewicz [email protected]',
'SrA Desmond Marlin Lebsack [email protected]',
'TSgt Michale Maymie Carroll [email protected]',
'2Lt Brook Hyman Schaefer [email protected]',
'2Lt Monica Ayden Hahn [email protected]',
'2Lt Lloyd Montana Champlin [email protected]',
'MSgt Krista Darrel Kub [email protected]',
'SMSgt Joy Gussie Spencer [email protected]',
'A1C Paul Kayli DuBuque [email protected]',
'SrA Sunny Chandler Bailey [email protected]',
'MSgt Karley Evalyn Wyman [email protected]',
'TSgt Edwina Raina Carter [email protected]',
'1Lt Talia Freeda Spencer [email protected]',
'2Lt Godfrey Berta Miller [email protected]',
'SMSgt Melisa Bria Bosco [email protected]',
'AB Antone Aileen Jaskolski [email protected]',
'SrA Werner Harley Jacobs [email protected]',
'TSgt Dorothea Tanya Waelchi [email protected]',
'TSgt Garrick Kathlyn Russel [email protected]',
'MSgt Amya Elenora White [email protected]',
'SMSgt Erika Norberto Lynch [email protected]',
'1Lt Josiane Kraig Sawayn [email protected]',
'2Lt Narciso Sarai Quitzon [email protected]',
'A1C Schuyler Salvador Robel [email protected]',
'SSgt Carli Lia Senger [email protected]',
'SMSgt Gerardo Eladio Rempel [email protected]',
'SSgt Kelly Davon Halvorson [email protected]',
],
units : null,
},
{
name : "181st CF",
leader : 'Maj ARM A STRONG [email protected]',
type : "FLIGHT",
members : [
'TSgt Jalon Dasia Crona [email protected]',
'MSgt Prudence Marcus Ward [email protected]',
'SSgt Jovanny Aryanna Parker [email protected]',
'A1C Fredrick Raphaelle Bartell [email protected]',
'2Lt Sibyl Velda Rice [email protected]',
'SSgt Phyllis Christina Flatley [email protected]',
'1Lt Lora Orland Jacobi [email protected]',
'2Lt Gustave Sydnie Schmitt [email protected]',
'SMSgt Claudia Yasmeen Rippin [email protected]',
'SMSgt Adriel Jacinto Mann [email protected]',
'TSgt Griffin Jacinthe Donnelly [email protected]',
'SSgt Giovanni Chauncey Tillman [email protected]',
'1Lt Madie Denis Monahan [email protected]',
'TSgt Christiana Mariela Beier [email protected]',
'SMSgt Rhianna Bailey Frami [email protected]',
'MSgt Alexandro Darien Veum [email protected]',
'SrA Susan Dejon Barton [email protected]',
'MSgt Mikayla Denis Torp [email protected]',
'SSgt Wiley Vaughn Cormier [email protected]',
'MSgt Arely Rosalinda West [email protected]',
'2Lt Shad Oswald Graham [email protected]',
'SMSgt Rodrick Gwen Conn [email protected]',
'AB Tad Orrin Davis [email protected]',
'AB Meghan Lucy Weber [email protected]',
'AB Isabell Ora Dietrich [email protected]',
'TSgt Sadye Vicky Gutkowski [email protected]',
'SMSgt Trystan Stefan Abshire [email protected]',
'1Lt Johathan Claude Balistreri [email protected]',
'2Lt Ahmed Alexa Boyle [email protected]',
'AB Lauretta Jaiden Jast [email protected]',
'A1C Leda Cordell Graham [email protected]',
'A1C Billie Napoleon Fadel [email protected]',
'1Lt Neal Noe Morar [email protected]',
'2Lt Evan Gene Rice [email protected]',
],
units : null,
}
],
}
],
};
createOrgStructure(orgStructure, null);