|
1 | 1 | package com.DesktopApplicationClientJava.Api; |
2 | 2 |
|
3 | | -public class ApiConfig {} |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.InputStream; |
| 5 | +import java.util.Properties; |
| 6 | + |
| 7 | +public final class ApiConfig { |
| 8 | + |
| 9 | + private static final Properties PROPS = new Properties(); |
| 10 | + |
| 11 | + static { |
| 12 | + try (InputStream in = ApiConfig.class.getResourceAsStream("/api.properties")) { |
| 13 | + if (in == null) { |
| 14 | + throw new IllegalStateException("api.properties not found on classpath"); |
| 15 | + } |
| 16 | + PROPS.load(in); |
| 17 | + } catch (IOException e) { |
| 18 | + throw new ExceptionInInitializerError(e); |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + private ApiConfig() {} |
| 23 | + |
| 24 | + public static String baseUrl() { |
| 25 | + return required("api.baseUrl"); |
| 26 | + } |
| 27 | + |
| 28 | + public static long connectTimeoutMs() { |
| 29 | + return Long.parseLong(required("api.connectTimeoutMs")); |
| 30 | + } |
| 31 | + |
| 32 | + public static long readTimeoutMs() { |
| 33 | + return Long.parseLong(required("api.readTimeoutMs")); |
| 34 | + } |
| 35 | + |
| 36 | + public static String pathLogin() { |
| 37 | + return required("api.path.login"); |
| 38 | + } |
| 39 | + |
| 40 | + public static String pathRefresh() { |
| 41 | + return required("api.path.refresh"); |
| 42 | + } |
| 43 | + |
| 44 | + public static String pathLogout() { |
| 45 | + return required("api.path.logout"); |
| 46 | + } |
| 47 | + |
| 48 | + public static String pathMe() { |
| 49 | + return required("api.path.me"); |
| 50 | + } |
| 51 | + |
| 52 | + public static String pathResource() { |
| 53 | + return required("api.path.resource"); |
| 54 | + } |
| 55 | + |
| 56 | + public static String pathAdmin() { |
| 57 | + return required("api.path.admin"); |
| 58 | + } |
| 59 | + |
| 60 | + public static String pathExportUsers() { |
| 61 | + return required("api.path.export.users"); |
| 62 | + } |
| 63 | + |
| 64 | + public static String pathExportResources() { |
| 65 | + return required("api.path.export.resources"); |
| 66 | + } |
| 67 | + |
| 68 | + /** /api/v1/admin/resource/{uuid}/files/export */ |
| 69 | + public static String pathExportResourceFiles(String resourceId) { |
| 70 | + return pathAdmin() + "/resource/" + resourceId + "/files/export"; |
| 71 | + } |
| 72 | + |
| 73 | + /** /api/v1/resource/{uuid}/file */ |
| 74 | + public static String pathResourceFiles(String resourceId) { |
| 75 | + return pathResource() + "/" + resourceId + "/file"; |
| 76 | + } |
| 77 | + |
| 78 | + /** /api/v1/resource/{uuid}/file/{fileId} */ |
| 79 | + public static String pathResourceFile(String resourceId, String fileId) { |
| 80 | + return pathResource() + "/" + resourceId + "/file/" + fileId; |
| 81 | + } |
| 82 | + |
| 83 | + private static String required(String key) { |
| 84 | + String value = PROPS.getProperty(key); |
| 85 | + if (value == null || value.isBlank()) { |
| 86 | + throw new IllegalStateException("Missing config property: " + key); |
| 87 | + } |
| 88 | + return value; |
| 89 | + } |
| 90 | +} |
0 commit comments