forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.java
More file actions
694 lines (579 loc) · 19 KB
/
Project.java
File metadata and controls
694 lines (579 loc) · 19 KB
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/*
* Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata.project;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gooddata.md.Meta;
import com.gooddata.util.BooleanDeserializer;
import com.gooddata.util.GDDateTimeDeserializer;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.gooddata.util.GoodDataToStringBuilder;
import org.joda.time.DateTime;
import org.springframework.web.util.UriTemplate;
import java.util.HashSet;
import java.util.Set;
import static com.gooddata.util.Validate.notEmpty;
import static com.gooddata.util.Validate.notNull;
import static com.gooddata.util.Validate.notNullState;
import static java.util.Arrays.asList;
/**
* Project in GoodData platform
*/
@JsonTypeName("project")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Project {
public static final String PROJECTS_URI = "/gdc/account/profile/{id}/projects";
public static final String URI = Projects.URI + "/{id}";
public static final UriTemplate TEMPLATE = new UriTemplate(URI);
private static final Set<String> PREPARING_STATES = new HashSet<>(asList("PREPARING", "PREPARED", "LOADING"));
@JsonProperty("content")
private final ProjectContent content;
@JsonProperty("meta")
private final ProjectMeta meta;
@JsonIgnore
private Links links;
public Project(String title, String authorizationToken) {
content = new ProjectContent(authorizationToken);
meta = new ProjectMeta(title);
}
public Project(String title, String summary, String authorizationToken) {
content = new ProjectContent(authorizationToken);
meta = new ProjectMeta(title, summary);
}
@JsonCreator
private Project(@JsonProperty("content") ProjectContent content, @JsonProperty("meta") ProjectMeta meta,
@JsonProperty("links") Links links) {
this.content = content;
this.meta = meta;
this.links = links;
}
public void setProjectTemplate(String uri) {
meta.setProjectTemplate(uri);
}
@JsonIgnore
public String getId() {
return TEMPLATE.match(getUri()).get("id");
}
@JsonIgnore
public String getState() {
return content.getState();
}
@JsonIgnore
public String getAuthorizationToken() {
return content.getAuthorizationToken();
}
@JsonIgnore
public String getDriver() {
return content.getDriver();
}
@JsonIgnore
public String getGuidedNavigation() {
return content.getGuidedNavigation();
}
@JsonIgnore
public String getCluster() {
return content.getCluster();
}
@JsonIgnore
public Boolean isPublic() {
return "1".equals(content.getIsPublic());
}
@JsonIgnore
public String getTitle() {
return meta.getTitle();
}
@JsonIgnore
public String getSummary() {
return meta.getSummary();
}
@JsonIgnore
public String getAuthor() {
return meta.getAuthor();
}
@JsonIgnore
public String getContributor() {
return meta.getContributor();
}
@JsonIgnore
public DateTime getCreated() {
return meta.getCreated();
}
@JsonIgnore
public DateTime getUpdated() {
return meta.getUpdated();
}
@JsonIgnore
public String getUri() {
return notNullState(links, "links").getSelf();
}
/**
* @return users URI string
* @deprecated use {@link #getUsersUri()} instead
*/
@Deprecated
@JsonIgnore
public String getUsersLink() {
return getUsersUri();
}
@JsonIgnore
public String getUsersUri() {
return notNullState(links, "links").getUsers();
}
/**
* @return roles URI string
* @deprecated use {@link #getRolesUri()} instead
*/
@Deprecated
@JsonIgnore
public String getRolesLink() {
return getRolesUri();
}
@JsonIgnore
public String getRolesUri() {
return notNullState(links, "links").getRoles();
}
/**
* @return groups URI string
* @deprecated use {@link #getGroupsUri()} instead
*/
@Deprecated
@JsonIgnore
public String getGroupsLink() {
return getGroupsUri();
}
@JsonIgnore
public String getGroupsUri() {
return notNullState(links, "links").getGroups();
}
/**
* @return invitations URI string
* @deprecated use {@link #getInvitationsUri()} instead
*/
@Deprecated
@JsonIgnore
public String getInvitationsLink() {
return getInvitationsUri();
}
@JsonIgnore
public String getInvitationsUri() {
return notNullState(links, "links").getInvitations();
}
/**
* @return LDM URI string
* @deprecated use {@link #getLdmUri()} instead
*/
@Deprecated
@JsonIgnore
public String getLdmLink() {
return getLdmUri();
}
@JsonIgnore
public String getLdmUri() {
return links.getLdm();
}
/**
* @return LDM thumbnail URI string
* @deprecated use {@link #getLdmThumbnailUri()} instead
*/
@Deprecated
@JsonIgnore
public String getLdmThumbnailLink() {
return getLdmThumbnailUri();
}
@JsonIgnore
public String getLdmThumbnailUri() {
return notNullState(links, "links").getLdmThumbnail();
}
/**
* @return metadata URI string
* @deprecated use {@link #getMetadataUri()} instead
*/
@Deprecated
@JsonIgnore
public String getMetadataLink() {
return getMetadataUri();
}
@JsonIgnore
public String getMetadataUri() {
return notNullState(links, "links").getMetadata();
}
/**
* @return public artifacts URI string
* @deprecated use {@link #getPublicArtifactsUri()} instead
*/
@Deprecated
@JsonIgnore
public String getPublicArtifactsLink() {
return getPublicArtifactsUri();
}
@JsonIgnore
public String getPublicArtifactsUri() {
return notNullState(links, "links").getPublicArtifacts();
}
/**
* @return templates URI string
* @deprecated use {@link #getTemplatesUri()} instead
*/
@Deprecated
@JsonIgnore
public String getTemplatesLink() {
return getTemplatesUri();
}
@JsonIgnore
public String getTemplatesUri() {
return notNullState(links, "links").getTemplates();
}
/**
* @return connectors URI string
* @deprecated use {@link #getConnectorsUri()} instead
*/
@Deprecated
@JsonIgnore
public String getConnectorsLink() {
return getConnectorsUri();
}
@JsonIgnore
public String getConnectorsUri() {
return notNullState(links, "links").getConnectors();
}
/**
* @return data load URI string
* @deprecated use {@link #getDataLoadUri()} instead
*/
@Deprecated
@JsonIgnore
public String getDataLoadLink() {
return getDataLoadUri();
}
@JsonIgnore
public String getDataLoadUri() {
return notNullState(links, "links").getDataLoad();
}
/**
* @return schedules URI string
* @deprecated use {@link #getSchedulesUri()} instead
*/
@Deprecated
@JsonIgnore
public String getSchedulesLink() {
return getSchedulesUri();
}
@JsonIgnore
public String getSchedulesUri() {
return notNullState(links, "links").getSchedules();
}
/**
* @return execute URI string
* @deprecated use {@link #getExecuteUri()} instead
*/
@Deprecated
@JsonIgnore
public String getExecuteLink() {
return getExecuteUri();
}
@JsonIgnore
public String getExecuteUri() {
return notNullState(links, "links").getExecute();
}
/**
* @return event stores URI string
* @deprecated use {@link #getEventStoresUri()} instead
*/
@Deprecated
@JsonIgnore
public String getEventStoresLink() {
return getEventStoresUri();
}
@JsonIgnore
public String getEventStoresUri() {
return notNullState(links, "links").getEventStores();
}
/**
* @return clear caches URI string
* @deprecated use {@link #getClearCachesUri()} instead
*/
@Deprecated
@JsonIgnore
public String getClearCachesLink() {
return getClearCachesUri();
}
@JsonIgnore
public String getClearCachesUri() {
return notNullState(links, "links").getClearCaches();
}
/**
* @return uploads URI string
* @deprecated use {@link #getUploadsUri()} instead
*/
@Deprecated
@JsonIgnore
public String getUploadsLink() {
return getUploadsUri();
}
@JsonIgnore
public String getUploadsUri() {
return notNullState(links, "links").getUploads();
}
@JsonIgnore
public boolean isPreparing() {
return PREPARING_STATES.contains(getState());
}
@JsonIgnore
public boolean isEnabled() {
return "ENABLED".equals(getState());
}
public void setDriver(String driver) {
notEmpty(driver, "driver");
content.setDriver(driver);
}
public void setDriver(ProjectDriver driver) {
notNull(driver, "driver");
setDriver(driver.getValue());
}
@JsonIgnore
public String getEnvironment() {
return content.getEnvironment();
}
@JsonIgnore
public void setEnvironment(final String environment) {
content.setEnvironment(environment);
}
public void setEnvironment(final ProjectEnvironment environment) {
notNull(environment, "environment");
setEnvironment(environment.name());
}
public void setEnvironment(final Environment environment) {
notNull(environment, "environment");
setEnvironment(environment.name());
}
@Override
public String toString() {
return GoodDataToStringBuilder.defaultToString(this);
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
private static class ProjectContent {
@JsonProperty("authorizationToken")
private final String authorizationToken;
@JsonProperty("driver")
private String driver;
@JsonProperty("guidedNavigation")
private final String guidedNavigation;
@JsonIgnore
private String cluster;
@JsonIgnore
private String isPublic;
@JsonIgnore
private String state;
@JsonProperty
private String environment;
public ProjectContent(final String authorizationToken) {
this.authorizationToken = authorizationToken;
guidedNavigation = "1";
driver = ProjectDriver.POSTGRES.getValue();
}
@JsonCreator
public ProjectContent(@JsonProperty("authorizationToken") String authorizationToken,
@JsonProperty("driver") String driver,
@JsonProperty("cluster") String cluster,
@JsonProperty("guidedNavigation") String guidedNavigation,
@JsonProperty("isPublic") String isPublic,
@JsonProperty("environment") String environment,
@JsonProperty("state") String state) {
this.authorizationToken = authorizationToken;
this.guidedNavigation = guidedNavigation;
this.driver = driver;
this.cluster = cluster;
this.isPublic = isPublic;
this.state = state;
this.environment = environment;
}
public String getState() {
return state;
}
public String getAuthorizationToken() {
return authorizationToken;
}
public String getDriver() {
return driver;
}
public String getGuidedNavigation() {
return guidedNavigation;
}
public String getCluster() {
return cluster;
}
public String getIsPublic() {
return isPublic;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getEnvironment() {
return environment;
}
public void setEnvironment(final String environment) {
this.environment = environment;
}
@Override
public String toString() {
return GoodDataToStringBuilder.defaultToString(this);
}
}
@JsonIgnoreProperties(ignoreUnknown = true)
private static class Links {
private final String self;
private final String users;
private final String roles;
private final String groups;
private final String invitations;
private final String ldm;
private final String ldmThumbnail;
private final String metadata;
private final String publicArtifacts;
private final String templates;
private final String connectors;
private final String dataLoad;
private final String schedules;
private final String execute;
private final String eventStores;
private final String clearCaches;
private final String uploads;
@JsonCreator
public Links(@JsonProperty("self") String self,
@JsonProperty("users") String users,
@JsonProperty("roles") String roles,
@JsonProperty("groups") String groups,
@JsonProperty("invitations") String invitations,
@JsonProperty("ldm") String ldm,
@JsonProperty("ldm_thumbnail") String ldmThumbnail,
@JsonProperty("metadata") String metadata,
@JsonProperty("publicartifacts") String publicArtifacts,
@JsonProperty("templates") String templates,
@JsonProperty("connectors") String connectors,
@JsonProperty("dataload") String dataLoad,
@JsonProperty("schedules") String schedules,
@JsonProperty("execute") String execute,
@JsonProperty("eventstores") String eventStores,
@JsonProperty("clearCaches") String clearCaches,
@JsonProperty("uploads") String uploads) {
this.self = self;
this.users = users;
this.roles = roles;
this.groups = groups;
this.invitations = invitations;
this.ldm = ldm;
this.ldmThumbnail = ldmThumbnail;
this.metadata = metadata;
this.publicArtifacts = publicArtifacts;
this.templates = templates;
this.connectors = connectors;
this.dataLoad = dataLoad;
this.schedules = schedules;
this.execute = execute;
this.eventStores = eventStores;
this.clearCaches = clearCaches;
this.uploads = uploads;
}
public String getSelf() {
return self;
}
public String getUsers() {
return users;
}
public String getRoles() {
return roles;
}
public String getGroups() {
return groups;
}
public String getInvitations() {
return invitations;
}
public String getLdm() {
return ldm;
}
public String getLdmThumbnail() {
return ldmThumbnail;
}
public String getMetadata() {
return metadata;
}
public String getPublicArtifacts() {
return publicArtifacts;
}
public String getTemplates() {
return templates;
}
public String getConnectors() {
return connectors;
}
public String getDataLoad() {
return dataLoad;
}
public String getSchedules() {
return schedules;
}
public String getExecute() {
return execute;
}
public String getEventStores() {
return eventStores;
}
public String getClearCaches() {
return clearCaches;
}
public String getUploads() {
return uploads;
}
}
private static class ProjectMeta extends Meta {
private String projectTemplate;
@JsonCreator
private ProjectMeta(@JsonProperty("author") String author,
@JsonProperty("contributor") String contributor,
@JsonProperty("created") @JsonDeserialize(using = GDDateTimeDeserializer.class) DateTime created,
@JsonProperty("updated") @JsonDeserialize(using = GDDateTimeDeserializer.class) DateTime updated,
@JsonProperty("summary") String summary,
@JsonProperty("title") String title,
@JsonProperty("category") String category,
@JsonProperty("tags") Set<String> tags,
@JsonProperty("uri") String uri,
@JsonProperty("identifier") String identifier,
@JsonProperty("deprecated") @JsonDeserialize(using = BooleanDeserializer.class) Boolean deprecated,
@JsonProperty("isProduction") @JsonDeserialize(using = BooleanDeserializer.class) Boolean production,
@JsonProperty("locked") @JsonDeserialize(using = BooleanDeserializer.class) Boolean locked,
@JsonProperty("unlisted") @JsonDeserialize(using = BooleanDeserializer.class) Boolean unlisted,
@JsonProperty("sharedWithSomeone") @JsonDeserialize(using = BooleanDeserializer.class) Boolean sharedWithSomeone,
@JsonProperty("flags") Set<String> flags) {
super(author, contributor, created, updated, summary, title, category, tags, uri, identifier,
deprecated, production, locked, unlisted, sharedWithSomeone, flags);
}
private ProjectMeta(String title) {
super(title);
}
private ProjectMeta(String title, String summary) {
super(title, summary);
}
public String getProjectTemplate() {
return projectTemplate;
}
public void setProjectTemplate(String projectTemplate) {
this.projectTemplate = projectTemplate;
}
@Override
public String toString() {
return GoodDataToStringBuilder.defaultToString(this);
}
}
}