forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
87 lines (70 loc) · 3.71 KB
/
Copy pathExample.java
File metadata and controls
87 lines (70 loc) · 3.71 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
/*
* Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
*/
package com.gooddata;
import com.gooddata.account.Account;
import com.gooddata.account.AccountService;
import com.gooddata.dataset.DatasetManifest;
import com.gooddata.dataset.DatasetService;
import com.gooddata.md.Attribute;
import com.gooddata.md.Fact;
import com.gooddata.md.MetadataService;
import com.gooddata.md.Metric;
import com.gooddata.md.Restriction;
import com.gooddata.md.report.AttributeInGrid;
import com.gooddata.md.report.GridElement;
import com.gooddata.md.report.GridReportDefinitionContent;
import com.gooddata.md.report.Report;
import com.gooddata.md.report.ReportDefinition;
import com.gooddata.model.MaqlDdlTaskStatus;
import com.gooddata.model.ModelDiff;
import com.gooddata.model.ModelService;
import com.gooddata.project.Project;
import com.gooddata.project.ProjectService;
import com.gooddata.report.ReportExportFormat;
import com.gooddata.report.ReportService;
import java.io.InputStreamReader;
import java.util.Collection;
import static java.util.Arrays.asList;
public class Example {
public static void main(String... args) {
final GoodData gd = new GoodData("roman@gooddata.com", "Roman1");
final AccountService accountService = gd.getAccountService();
final Account current = accountService.getCurrent();
System.out.println(current.getId());
final ProjectService projectService = gd.getProjectService();
final Collection<Project> projects = projectService.getProjects();
System.out.println(projects);
final Project project = projectService.createProject(new Project("sparkling", "pgroup2")).get();
System.out.println(project.getSelfLink());
final ModelService modelService = gd.getModelService();
final ModelDiff projectModelDiff = modelService.getProjectModelDiff(project,
new InputStreamReader(Example.class.getResourceAsStream("/person.json"))).get();
final Collection<FutureResult<MaqlDdlTaskStatus>> results = modelService
.updateProjectModel(project, projectModelDiff);
for (FutureResult<MaqlDdlTaskStatus> fr : results) {
final MaqlDdlTaskStatus taskStatus = fr.get();
System.out.println("MAQL update task success: " + taskStatus.isSuccess());
}
final MetadataService md = gd.getMetadataService();
final String factUri = md.findObjUri(project, Fact.class, Restriction.title("Person Age"));
final String attrUri = md.findObjUri(project, Attribute.class, Restriction.title("Department"));
final Metric m = md.createObj(project, new Metric("Age Sum", "SELECT SUM([" + factUri + "])", "#,##0"));
ReportDefinition definition = GridReportDefinitionContent.create(
"my report",
asList("metricGroup"),
asList(new AttributeInGrid(attrUri)),
asList(new GridElement(factUri, "Age Sum"))
);
definition = md.createObj(project, definition);
final Report report = md.createObj(project, new Report(definition.getTitle(), definition.getUri(), null));
final DatasetService datasetService = gd.getDatasetService();
final DatasetManifest manifest = datasetService.getDatasetManifest(project, "dataset.person");
datasetService.loadDataset(project, manifest, Example.class.getResourceAsStream("/person.csv")).get();
final ReportDefinition reportDef = md.getObjByUri("/gdc/md/GoodSalesDemoKokot1/obj/1962", ReportDefinition.class);
final ReportService reportService = gd.getReportService();
final String imgUri = reportService.exportReport(reportDef, ReportExportFormat.PDF);
System.out.println(imgUri);
gd.logout();
}
}