forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodData.java
More file actions
139 lines (113 loc) · 5.37 KB
/
Copy pathGoodData.java
File metadata and controls
139 lines (113 loc) · 5.37 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
/*
* Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
*/
package com.gooddata;
import com.gooddata.account.AccountService;
import com.gooddata.dataset.DatasetService;
import com.gooddata.gdc.DataStoreService;
import com.gooddata.gdc.GdcService;
import com.gooddata.http.client.GoodDataHttpClient;
import com.gooddata.http.client.LoginSSTRetrievalStrategy;
import com.gooddata.http.client.SSTRetrievalStrategy;
import com.gooddata.md.MetadataService;
import com.gooddata.model.ModelService;
import com.gooddata.project.ProjectService;
import com.gooddata.report.ReportService;
import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.VersionInfo;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import java.util.Arrays;
import static com.gooddata.Validate.notEmpty;
import static java.util.Collections.singletonMap;
/**
*/
public class GoodData {
public static final String GDC_REQUEST_ID_HEADER = "X-GDC-REQUEST";
private static final String PROTOCOL = "https";
private static final int PORT = 443;
private static final String HOSTNAME = "secure.gooddata.com";
private static final String UNKNOWN_VERSION = "UNKNOWN";
private final AccountService accountService;
private final ProjectService projectService;
private final MetadataService metadataService;
private final ModelService modelService;
private final GdcService gdcService;
private final DataStoreService dataStoreService;
private final DatasetService datasetService;
private final ReportService reportService;
public GoodData(String login, String password) {
this(HOSTNAME, login, password);
}
public GoodData(String hostname, String login, String password) {
notEmpty(hostname, "hostname");
notEmpty(login, "login");
notEmpty(password, "password");
final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setUserAgent(getUserAgent());
final RestTemplate restTemplate = createRestTemplate(hostname, login, password, httpClientBuilder);
accountService = new AccountService(restTemplate);
projectService = new ProjectService(restTemplate, accountService);
metadataService = new MetadataService(restTemplate);
modelService = new ModelService(restTemplate);
gdcService = new GdcService(restTemplate);
dataStoreService = new DataStoreService(httpClientBuilder, gdcService, login, password);
datasetService = new DatasetService(restTemplate, dataStoreService);
reportService = new ReportService(restTemplate);
}
private RestTemplate createRestTemplate(String hostname, String login, String password, HttpClientBuilder httpClientBuilder) {
final HttpHost host = new HttpHost(hostname, PORT, PROTOCOL);
final CloseableHttpClient httpClient = httpClientBuilder.build();
final SSTRetrievalStrategy strategy = new LoginSSTRetrievalStrategy(httpClient, host, login, password);
final HttpClient client = new GoodDataHttpClient(httpClient, strategy);
final UriPrefixingClientHttpRequestFactory factory = new UriPrefixingClientHttpRequestFactory(
new HttpComponentsClientHttpRequestFactory(client), hostname, PORT, PROTOCOL);
final RestTemplate restTemplate = new RestTemplate(factory);
restTemplate.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
new HeaderSettingRequestInterceptor(singletonMap("Accept", MediaType.APPLICATION_JSON_VALUE))));
restTemplate.setErrorHandler(new ResponseErrorHandler(restTemplate.getMessageConverters()));
return restTemplate;
}
private String getUserAgent() {
final Package pkg = Package.getPackage("com.gooddata");
final String clientVersion = pkg != null && pkg.getImplementationVersion() != null
? pkg.getImplementationVersion() : UNKNOWN_VERSION;
final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", HttpClientBuilder.class.getClassLoader());
final String apacheVersion = vi != null ? vi.getRelease() : UNKNOWN_VERSION;
return String.format("%s/%s (%s; %s) %s/%s", "GoodData-Java-SDK", clientVersion,
System.getProperty("os.name"), System.getProperty("java.specification.version"),
"Apache-HttpClient", apacheVersion);
}
public void logout() {
getAccountService().logout();
}
public ProjectService getProjectService() {
return projectService;
}
public AccountService getAccountService() {
return accountService;
}
public MetadataService getMetadataService() {
return metadataService;
}
public ModelService getModelService() {
return modelService;
}
public GdcService getGdcService() {
return gdcService;
}
public DataStoreService getDataStoreService() {
return dataStoreService;
}
public DatasetService getDatasetService() {
return datasetService;
}
public ReportService getReportService() {
return reportService;
}
}