Skip to content
Eugene edited this page Apr 26, 2022 · 20 revisions

Initialisation

Configure connection using one of constructors of GoodData class. One can then get initialised service he needs from the newly constructed instance. This instance can be also used later for logout from GoodData Platform.

GoodData gd = new GoodData("roman@gooddata.com", "Roman1");

If you need to tune additional settings like maxConnections, connectionTimeout, connectionTimeout or socketTimeout, use GoodDataSettings class and passed its instance to GoodData constructor.

Project API

Manage GoodData projects with its users, user roles, templates, validation and feature flags.

ProjectService projectService = gd.getProjectService();

Get all projects current user has access to.

Collection<Project> projects = projectService.getProjects();

Create new project.

Project project = projectService.createProject(new Project("my project", "MyToken")).get();

Remove project.

projectService.removeProject(project);

Validate project.

Set<ProjectValidationType> types = projectService.getAvailableProjectValidationTypes(project);
ProjectValidationResults results = projectService.validateProject(project, types).get();

List project users.

List<User> users = new ArrayList<>();
List<User> page;
while (!(page = projectService.listUsers(project, new PageRequest(users.size(), 100))).isEmpty()) {
    users.addAll(page);
}

List project user roles.

Set<Role> roles = projectService.getRoles(project);

List project templates.

Collection<ProjectTemplate> templates = projectService.getProjectTemplates(project);

Send invitation

Invitation invitation = new Invitation("user@example.com");
CreatedInvitations invitations = projectService.sendInvitations(project, invitation);        

Add user to project

User user = projectService.addUserToProject(project, account, role1, role2);

Update user in project

projectService.updateUserInProject(project, user)

Account API

Create account in GoodData

Account newAccount = new Account("MyMail@gooddata.com", "Password", "FistName", "LastName");
Account account = accountService.createAccount(newAccount, "MyOrganizationName");

Remove account

accountService.removeAccount(account);

Create and remove account can be executed only by domain admin.

Project Model API

Create and update the project model, execute MAQL DDL,...

ModelService modelService = gd.getModelService();
ModelDiff diff = modelService.getProjectModelDiff(project,
    new InputStreamReader(getClass().getResourceAsStream("/person.json"))).get();
modelService.updateProjectModel(project, diff).get();

modelService.updateProjectModel(project, "MAQL DDL EXPRESSION").get();

Metadata API

Query, create and update project metadata - attributes, facts, metrics, reports,...

MetadataService md = gd.getMetadataService();

String fact = md.getObjUri(project, Fact.class, identifier("fact.person.shoesize"));
Metric m = md.createObj(project, new Metric("Avg shoe size", "SELECT AVG([" + fact + "])", "#,##0"));

Attribute attr = md.getObj(project, Attribute.class, identifier("attr.person.department"));

ReportDefinition definition = GridReportDefinitionContent.create(
        "Department avg shoe size",
        asList("metricGroup"),
        asList(new AttributeInGrid(attr.getDefaultDisplayForm().getUri())),
        asList(new GridElement(m.getUri(), "Avg shoe size"))
);
definition = md.createObj(project, definition);
Report report = md.createObj(project, new Report(definition.getTitle(), definition));

Create and retrieve scheduled mails on reports and dashboards.

ScheduledMail scheduledMail = md.createObj(
    project,
    (new ScheduledMail("Scheduled Mail Title", "Scheduled Mail Summary"))
        .setRecurrency("0:0:0:1*12:0:0")
        .setStartDate(new LocalDate(2012, 6, 5))
        .setTimeZone("America/Los_Angeles")
        .addToAddress("user_in_project@example.com")
        .addBccAddress("another_user_in_project@example.com")
        .setSubject("Mail subject")
        .setBody("Mail body")
        .addReportAttachment(reportDefinition,
                             Collections.singletonMap("pageOrientation", "landscape"),
                             pdf, xls)
);

Collection<Entry> result = md.find(project, ScheduledMail.class);
for (Entry e : result) {
    ScheduledMail schedule = md.getObjByUri(e.getLink(), ScheduledMail.class);
}

Import/Export API

Import/export project metadata.

ImportExportService importExportService = gd.getImportExportService();

PartialMdExport exportConfig = new PartialMdExport("/gdc/md/projectId/obj/123");
PartialMdExportToken exportToken = importExportService.partialExport(projectFrom, exportConfig).get();

importExportService.partialImport(projectTo, exportToken).get();

Dataset API

DatasetService datasetService = gd.getDatasetService();

Upload data to dataset.

datasetService.loadDataset(project, "datasetId", new FileInputStream("data.csv")).get();

Upload data to datasets using batch upload.

DatasetManifest personManifest = datasetService.getDatasetManifest(project, "dataset.person");
personManifest.setSource(getClass().getResourceAsStream("/person.csv"));

DatasetManifest cityManifest = datasetService.getDatasetManifest(project, "dataset.city");
cityManifest.setSource(getClass().getResourceAsStream("/city.csv"));

datasetService.loadDatasets(project, personManifest, cityManifest).get();

Update data in dataset.

datasetService.updateProjectData(project, "DELETE FROM {attr.person.name} WHERE {label.person.name} = \"not exists\";");

List all uploads for a dataset.

Collection<Upload> personUploads = datasetService.listUploadsForDataset(project, "dataset.person");

Get last upload for a dataset.

Upload personLastUpload = datasetService.getLastUploadForDataset(project, "dataset.person");

Get project`s upload statistics (e.g. successful uploads count).

UploadStatistics uploadStatistics = datasetService.getUploadStatistics(project);

int successfulUploadsCount = uploadStatistics.getUploadsCount("OK");

Report API

Execute and export reports.

ReportService reportService = gd.getReportService();
reportService.exportReport(definition, PNG, new FileOutputStream("report.png"));

Execute AFM API

Executes reports with new visualization structures like AFM or Visualization Object.

Execute AFM

Executes AFM object and gets execution response (polling object for execution result).

ExecuteAfmService service = gd.getExecuteAfmService();
Afm afm = new Afm()
                 .addAttribute(new AttributeItem(displayForm, localIdentifier, "Some Attribute"))
                 .addMeasure(new MeasureItem(measureDefinition, "measure1"));
Execution execution = new Execution(afm);
ExecutionResponse response = service.executeAfm(project, execution);

Execute Visualization Object

Executes reference to stored metadata of Visualization Object and gets execution response (polling object for execution result).

ExecuteAfmService service = gd.getExecuteAfmService();
VisualizationExecution execution = new VisualizationExecution("/gdc/md/project123/obj/12");
ExecutionResponse response = service.executeVisualization(project, execution);

Fetch execution result

Fetches execution result data from AFM execution response.

ExecuteAfmService service = gd.getExecuteAfmService();
ExecutionResult executionResult = service.getResult(executionResponse).get();

DataStore API

Manage files on the data store (currently backed by WebDAV) - user staging area.

DataStoreService dataStoreService = gd.getDataStoreService();
dataStoreService.upload("/dir/file.txt", new FileInputStream("file.txt"));
InputStream stream = dataStoreService.download("/dir/file.txt");
dataStoreService.delete("/dir/file.txt");

Warehouse API

Manage warehouses - create, update, list and delete.

WarehouseService warehouseService = gd.getWarehouseService();
Warehouse warehouse = warehouseService.createWarehouse(new Warehouse("title", "authToken", "description")).get();
String jdbc = warehouse.getJdbcConnectionString();

Collection<Warehouse> warehouseList = warehouseService.listWarehouses();
warehouseService.removeWarehouse(warehouse);

Manage warehouse schemas

WarehouseService warehouseService = gd.getWarehouseService();
Warehouse warehouse = warehouseService.getWarehouseById("someId");
WarehouseSchema schema = warehouseService.getDefaultWarehouseSchema(warehouse);

Collection<WarehouseSchema> schemaList = warehouseService.listWarehouseSchemas(warehouse);

Manage S3 credentials for warehouses - create, get, update, delete and list.

WarehouseService warehouseService = gd.getWarehouseService();
Warehouse warehouse = warehouseService.getWarehouseById("someId");
WarehouseS3Credentials newS3Credentials = new WarehouseS3Credentials("region", "accessKey", "secretKey");
newS3Credentials = warehouseService.addS3Credentials(warehouse, s3Credentials).get();

WarehouseS3Credentials s3Credentials = warehouseService.getWarehouseS3Credentials(warehouse, "region", "accessKey");
s3Credentials.setSecretKey("newSecretKey");
s3Credentials = warehouseService.updateS3Credentials(s3Credentials).get();

warehouseService.removeS3Credentials(s3Credentials);
Collection<WarehouseS3Credentials> s3CredentialsList = warehouseService.listWarehouseS3Credentials(warehouse);

Dataload Process API

Manage dataload processes - create, update, list, delete, and process executions - execute, get logs, schedules,...

ProcessService processService = gd.getProcessService();
DataloadProcess create = new DataloadProcess("name", "GRAPH");
DataloadProcess process = processService.createProcess(project, create, new File("path/to/processdatadir"));

ProcessExecution exec = new ProcessExecution(process, "myGraph.grf");
ProcessExecutionDetail executionDetail = processService.executeProcess(exec).get();
processService.getExecutionLog(executionDetail, new FileOutputStream("file/where/the/log/willbewritten"));

processService.createSchedule(project, new Schedule(process, "myGraph.grf", "0 0 * * *"));

Create, update process from appstore. These methods are asynchronous.

ProcessService processService = gd.getProcessService();
DataloadProcess create new DataloadProcess("name", "RUBY" ,"appstorePath");
DataloadProcess process = processService.createProcessFromAppstore(project, create).get();

process.setPath("differentAppstorePath");
process = processService.updateProcessFromAppstore(project, process).get();

Support for DATALOAD processes is rather rudimentary, as they are not documented anywhere, to execute DATALOAD process use:

ProcessExecution exec = new ProcessExecution(process, null, singletonMap("GDC_DE_SYNCHRONIZE_ALL", "true"));
ProcessExecutionDetail executionDetail = processService.executeProcess(exec).get();

Hierarchical Config API

Manage hierarchical configuration.

HierarchicalConfigService hierarchicalConfigService = gd.getHierarchicalConfigService();

Returns all config items for given project (including inherited ones from its hierarchy).

ConfigItems configItems = hierarchicalConfigService.listProjectConfigItems(project);

Returns config item for given project (even if it's inherited from its hierarchy).

ConfigItem configItem = hierarchicalConfigService.getProjectConfigItem(project, configName);

Creates or updates config item for given project.

ConfigItem configItem = new ConfigItem("name", "value");
ConfigItem created = hierarchicalConfigService.setProjectConfigItem(project, configItem);

Removes existing project config item.

hierarchicalConfigService.removeProjectConfigItem(configItem);

Feature Flag API

!!!DEPRECATED!!! Use Hierarchical Configuration API

Manage feature flags.

FeatureFlagService featureFlagService = gd.getFeatureFlagService();

Lists aggregated feature flags for given project and current user (aggregates global, project group, project and user feature flags).

FeatureFlags flags = featureFlagService.listFeatureFlags(project);

List project's feature flags (only project scoped flags).

ProjectFeatureFlags flags = featureFlagService.listProjectFeatureFlags(project);

Get project's feature flag (only project scoped flags) by unique name (aka "key").

ProjectFeatureFlag featureFlag = featureFlagService
        .getProjectFeatureFlag(project, featureFlagName);

Create new project's feature flag.

ProjectFeatureFlag featureFlag = featureFlagService
        .createProjectFeatureFlag(project, new ProjectFeatureFlag(featureFlagName));

Update existing project's feature flag (please note that propagation of these changes may take some time).

ProjectFeatureFlag updatedFeatureFlag = featureFlagService
        .updateProjectFeatureFlag(featureFlagWithChangedValue);

Delete existing project's feature flag.

featureFlagService.deleteFeatureFlag(featureFlag);

Notification API

Create, Delete notification channels, subscriptions,...

Create notification channel

notificationService.createChannel(account,
                                  new Channel(new EmailConfiguration("some@email.com"),
                                              "channel name")
                                  );

Delete notification channel

notificationService.removeChannel(channel);

Create notification subscription

notificationService.createSubscription(project,
                                       account,
                                       new Subscription(Collections.singletonList(new TimerEvent("0 * * * * *")),
                                                        Collections.singletonList(channel),
                                                        new TriggerCondition("true"),
                                                        new MessageTemplate("some message"),
                                                        "test subscription"
                                                        )
                                       );

Delete notification subscription

notificationService.removeSubscription(subscription);

Logout

Logout from GoodData Platform.

gd.logout();