-
Notifications
You must be signed in to change notification settings - Fork 541
Expand file tree
/
Copy pathInfo.java
More file actions
180 lines (158 loc) · 7.15 KB
/
Info.java
File metadata and controls
180 lines (158 loc) · 7.15 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
package edu.harvard.iq.dataverse.api;
import java.util.logging.Logger;
import edu.harvard.iq.dataverse.customization.CustomizationConstants;
import jakarta.ws.rs.*;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import edu.harvard.iq.dataverse.export.ExportService;
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.SystemConfig;
import io.gdcc.spi.export.Exporter;
import io.gdcc.spi.export.ExportException;
import io.gdcc.spi.export.XMLExporter;
import jakarta.ejb.EJB;
import jakarta.json.Json;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonValue;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
@Path("info")
@Tag(name = "info", description = "General information about the Dataverse installation.")
public class Info extends AbstractApiBean {
@EJB
SettingsServiceBean settingsService;
@EJB
SystemConfig systemConfig;
private static final Logger logger = Logger.getLogger(Info.class.getCanonicalName());
@GET
@Path("settings/:DatasetPublishPopupCustomText")
public Response getDatasetPublishPopupCustomText() {
return getSettingResponseByKey(SettingsServiceBean.Key.DatasetPublishPopupCustomText);
}
@GET
@Path("settings/:DatasetPrePublishPopupCustomText")
public Response DatasetPrePublishPopupCustomText() {
return getSettingResponseByKey(SettingsServiceBean.Key.DatasetPrePublishPopupCustomText);
}
@GET
@Path("settings/:PublishDatasetDisclaimerText")
public Response getPublishDatasetDisclaimerText() {
return getSettingResponseByKey(SettingsServiceBean.Key.PublishDatasetDisclaimerText);
}
@GET
@Path("settings/:PrePublishDatasetDisclaimerText")
public Response getPrePublishDatasetDisclaimerText() {
return getSettingResponseByKey(SettingsServiceBean.Key.PrePublishDatasetDisclaimerText);
}
@GET
@Path("settings/:MaxEmbargoDurationInMonths")
public Response getMaxEmbargoDurationInMonths() {
return getSettingResponseByKey(SettingsServiceBean.Key.MaxEmbargoDurationInMonths);
}
@GET
@Path("version")
@Operation(summary = "Get version and build information", description = "Get version and build information")
@APIResponse(responseCode = "200",
description = "Version and build information")
public Response getInfo() {
String versionStr = systemConfig.getVersion(true);
String[] comps = versionStr.split("build",2);
String version = comps[0].trim();
JsonValue build = comps.length > 1 ? Json.createArrayBuilder().add(comps[1].trim()).build().get(0) : JsonValue.NULL;
return ok(Json.createObjectBuilder()
.add("version", version)
.add("build", build));
}
@GET
@Path("server")
public Response getServer() {
return ok(JvmSettings.FQDN.lookup());
}
@GET
@Path("applicationTermsOfUse")
@APIResponse(responseCode = "200",
description = "Application Terms of Use (General Terms of Use) that must be agreed to at signup.")
public Response getApplicationTermsOfUse(
@Parameter(description = "Two-character language code.",
required = false,
example = "en",
schema = @Schema(type = SchemaType.STRING))
@QueryParam("lang") String lang) {
return ok(systemConfig.getApplicationTermsOfUse(lang));
}
@GET
@Path("apiTermsOfUse")
public Response getTermsOfUse() {
return ok(systemConfig.getApiTermsOfUse());
}
@GET
@Path("settings/incompleteMetadataViaApi")
public Response getAllowsIncompleteMetadata() {
return ok(JvmSettings.API_ALLOW_INCOMPLETE_METADATA.lookupOptional(Boolean.class).orElse(false));
}
@GET
@Path("zipDownloadLimit")
public Response getZipDownloadLimit() {
long zipDownloadLimit = SystemConfig.getLongLimitFromStringOrDefault(settingsSvc.getValueForKey(SettingsServiceBean.Key.ZipDownloadLimit), SystemConfig.defaultZipDownloadLimit);
return ok(zipDownloadLimit);
}
@GET
@Path("exportFormats")
public Response getExportFormats() {
JsonObjectBuilder responseModel = Json.createObjectBuilder();
ExportService instance = ExportService.getInstance();
for (String[] labels : instance.getExportersLabels()) {
try {
Exporter exporter = instance.getExporter(labels[1]);
JsonObjectBuilder exporterObject = Json.createObjectBuilder().add("displayName", labels[0])
.add("mediaType", exporter.getMediaType()).add("isHarvestable", exporter.isHarvestable())
.add("isVisibleInUserInterface", exporter.isAvailableToUsers());
if (exporter instanceof XMLExporter xmlExporter) {
exporterObject.add("XMLNameSpace", xmlExporter.getXMLNameSpace())
.add("XMLSchemaLocation", xmlExporter.getXMLSchemaLocation())
.add("XMLSchemaVersion", xmlExporter.getXMLSchemaVersion());
}
responseModel.add(labels[1], exporterObject);
}
catch (ExportException ex){
logger.warning("Failed to get: " + labels[1]);
logger.warning(ex.getLocalizedMessage());
}
}
return ok(responseModel);
}
@GET
@Path("settings/customization/{customizationFileType}")
public Response getCustomizationFile(@PathParam("customizationFileType") String customizationFileType) {
String type = customizationFileType != null ? customizationFileType.toLowerCase() : "";
if (!CustomizationConstants.validTypes.contains(type)) {
return badRequest("Customization type unknown or missing. Must be one of the following: " + CustomizationConstants.validTypes);
}
Client client = ClientBuilder.newClient();
WebTarget endpoint = client.target("http://localhost:8080/CustomizationFilesServlet");
Response response = endpoint.queryParam("customFileType", type)
.request(MediaType.MEDIA_TYPE_WILDCARD)
.get();
if (response.getLength() < 1) {
return notFound(type + " not found.");
} else {
return response;
}
}
private Response getSettingResponseByKey(SettingsServiceBean.Key key) {
String setting = settingsService.getValueForKey(key);
if (setting != null) {
return ok(Json.createObjectBuilder().add("message", setting));
} else {
return notFound("Setting " + key + " not found");
}
}
}