0
# Data Provider Framework
1
2
External data source integration for populating form field options dynamically from REST APIs, databases, and other sources.
3
4
## Capabilities
5
6
### Data Provider Interface
7
8
Core interface for implementing external data sources that can populate form field options.
9
10
```java { .api }
11
interface DDMDataProvider {
12
/**
13
* Fetches data from external source based on request parameters
14
*/
15
DDMDataProviderResponse getData(DDMDataProviderRequest ddmDataProviderRequest)
16
throws DDMDataProviderException;
17
}
18
19
class DDMDataProviderRequest {
20
String getDDMDataProviderInstanceId();
21
Map<String, String> getParameters();
22
Locale getLocale();
23
long getCompanyId();
24
long getGroupId();
25
}
26
27
class DDMDataProviderResponse {
28
Map<String, List<Map<String, String>>> getData();
29
int getStatus();
30
}
31
```
32
33
### Data Provider Configuration
34
35
Configuration and settings for data provider instances.
36
37
```java { .api }
38
class DDMDataProviderInstanceSettings {
39
String getCacheable();
40
String getPassword();
41
String getTimeout();
42
String getUrl();
43
String getUsername();
44
Map<String, String> getInputParameters();
45
Map<String, String> getOutputParameters();
46
}
47
48
interface DDMDataProviderTracker {
49
DDMDataProvider getDDMDataProvider(String type);
50
Set<String> getDDMDataProviderTypes();
51
}
52
```
53
54
## Usage Examples
55
56
### Creating a REST API Data Provider
57
58
```java
59
@Component
60
public class RestApiDataProviderExample {
61
62
@Reference
63
private DDMDataProviderInstanceLocalService dataProviderLocalService;
64
65
public DDMDataProviderInstance createCountriesDataProvider(long groupId, long userId)
66
throws PortalException {
67
68
// Create data provider form definition
69
DDMForm settingsForm = new DDMForm();
70
settingsForm.setDefaultLocale(Locale.US);
71
72
// URL field
73
DDMFormField urlField = new DDMFormField("url", "text");
74
urlField.setLabel(new LocalizedValue(Locale.US, "API URL"));
75
urlField.setRequired(true);
76
settingsForm.addDDMFormField(urlField);
77
78
// Timeout field
79
DDMFormField timeoutField = new DDMFormField("timeout", "numeric");
80
timeoutField.setLabel(new LocalizedValue(Locale.US, "Timeout (ms)"));
81
settingsForm.addDDMFormField(timeoutField);
82
83
// Create data provider instance
84
Map<Locale, String> nameMap = Collections.singletonMap(Locale.US, "Countries API");
85
Map<Locale, String> descriptionMap = Collections.singletonMap(Locale.US, "REST API for country data");
86
87
ServiceContext serviceContext = new ServiceContext();
88
serviceContext.setScopeGroupId(groupId);
89
90
return dataProviderLocalService.addDataProviderInstance(
91
userId, groupId, nameMap, descriptionMap,
92
settingsForm, "rest", serviceContext
93
);
94
}
95
}
96
```
97
98
## Types
99
100
### Data Provider Types
101
102
```java { .api }
103
class DDMDataProviderException extends PortalException {
104
DDMDataProviderException(String msg);
105
DDMDataProviderException(String msg, Throwable cause);
106
}
107
108
interface DDMDataProviderParameterSettings {
109
String getInputParameterLabel();
110
String getInputParameterName();
111
String getInputParameterRequired();
112
String getInputParameterType();
113
String getOutputParameterName();
114
String getOutputParameterPath();
115
String getOutputParameterType();
116
}
117
```