001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2026 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.test.model; 011 012import ca.cdr.api.model.enm.EnvironmentTypeEnum; 013import ca.cdr.api.model.json.IModelJson; 014import com.fasterxml.jackson.annotation.JsonProperty; 015import com.fasterxml.jackson.annotation.JsonPropertyOrder; 016import org.apache.commons.lang3.Validate; 017import org.apache.commons.lang3.builder.ToStringBuilder; 018import org.apache.commons.lang3.builder.ToStringStyle; 019 020import java.util.ArrayList; 021import java.util.List; 022import java.util.Optional; 023import java.util.stream.Collectors; 024 025/** 026 * This class is a copy of NodeConfigsJson from cdr-api, with all enum references 027 * from cdr-api replaced with string values. 028 * <p> 029 * This class was auto-generated from a private API class, using Claude 3.7 sonnet 030 */ 031public class NodeConfigurations implements IModelJson { 032 033 @JsonProperty(value = "nodes") 034 private List<NodeConfiguration> myNodes; 035 036 public Optional<NodeConfiguration> getNode(String theNodeId) { 037 Validate.notBlank(theNodeId, "theNodeId must not be blank"); 038 039 return getNodes().stream().filter(t -> theNodeId.equals(t.getNodeId())).findFirst(); 040 } 041 042 public List<NodeConfiguration> getNodes() { 043 if (myNodes == null) { 044 myNodes = new ArrayList<>(); 045 } 046 return myNodes; 047 } 048 049 @JsonPropertyOrder({"nodeId", "configLocked", "securityStrict", "modules"}) 050 public static class NodeConfiguration implements IModelJson { 051 052 @JsonProperty("modules") 053 private List<ModuleConfiguration> myModules; 054 055 @JsonProperty("nodeId") 056 private String myNodeId; 057 058 @JsonProperty("serverPortOffset") 059 private Integer myServerPortOffset = 0; 060 061 @JsonProperty("configLocked") 062 private Boolean myConfigLocked = false; 063 064 @JsonProperty("securityStrict") 065 private Boolean mySecurityStrict = false; 066 067 @JsonProperty("propertySource") 068 private String myPropertySource; 069 070 @JsonProperty("environmentType") 071 private EnvironmentTypeEnum myEnvironmentType = EnvironmentTypeEnum.DEV; 072 073 @JsonProperty("archiveUnknownModules") 074 private Boolean myArchiveUnknownModules = false; 075 076 public Optional<ModuleConfiguration> getModule(String theModuleId) { 077 Validate.notBlank(theModuleId, "theModuleId must not be blank"); 078 079 return getModules().stream() 080 .filter(t -> theModuleId.equals(t.getModuleId())) 081 .findFirst(); 082 } 083 084 public List<ModuleConfiguration> getModules() { 085 if (myModules == null) { 086 myModules = new ArrayList<>(); 087 } 088 return myModules; 089 } 090 091 public String getNodeId() { 092 return myNodeId; 093 } 094 095 public NodeConfiguration setNodeId(String theNodeId) { 096 myNodeId = theNodeId; 097 return this; 098 } 099 100 public NodeConfiguration setSecurityStrict(Boolean theSecurityStrict) { 101 mySecurityStrict = theSecurityStrict; 102 return this; 103 } 104 105 public Integer getServerPortOffset() { 106 return myServerPortOffset; 107 } 108 109 public NodeConfiguration setServerPortOffset(Integer theServerPortOffset) { 110 myServerPortOffset = theServerPortOffset; 111 return this; 112 } 113 114 public String getPropertySource() { 115 return myPropertySource; 116 } 117 118 public NodeConfiguration setPropertySource(String thePropertySource) { 119 myPropertySource = thePropertySource; 120 return this; 121 } 122 123 public NodeConfiguration setEnvironmentType(EnvironmentTypeEnum theEnvironmentTypeEnum) { 124 myEnvironmentType = theEnvironmentTypeEnum; 125 return this; 126 } 127 128 public EnvironmentTypeEnum getEnvironmentType() { 129 return myEnvironmentType; 130 } 131 132 public boolean getShouldArchiveUnknownModules() { 133 return Boolean.TRUE.equals(myArchiveUnknownModules); 134 } 135 136 public NodeConfiguration setShouldArchiveUnknownModules(Boolean myArchiveUnknownModules) { 137 this.myArchiveUnknownModules = myArchiveUnknownModules; 138 return this; 139 } 140 } 141 142 @JsonPropertyOrder({ 143 "moduleId", 144 "moduleType", 145 "dependencies", 146 "options", 147 }) 148 public static class ModuleConfiguration implements IModelJson { 149 150 @JsonProperty("options") 151 private List<ModuleConfigProperty> myConfigProperties; 152 153 @JsonProperty("dependencies") 154 private List<ModuleDependency> myDependencies; 155 156 @JsonProperty("moduleId") 157 private String myModuleId; 158 159 @JsonProperty("moduleType") 160 private String myModuleType; 161 162 /** 163 * Constructor 164 */ 165 public ModuleConfiguration() { 166 super(); 167 } 168 169 public List<String> getConfigKeys() { 170 return getConfigProperties().stream().map(t -> t.getKey()).collect(Collectors.toList()); 171 } 172 173 public List<ModuleConfigProperty> getConfigProperties() { 174 if (myConfigProperties == null) { 175 myConfigProperties = new ArrayList<>(); 176 } 177 return myConfigProperties; 178 } 179 180 public String getConfigProperty(String theKey) { 181 return getConfigProperties().stream() 182 .filter(t -> t.getKey().equals(theKey)) 183 .map(ModuleConfigProperty::getValue) 184 .findFirst() 185 .orElseThrow(() -> new IllegalArgumentException( 186 "Unknown key: " + theKey + " - Valid keys: " + getConfigKeys())); 187 } 188 189 public List<ModuleDependency> getDependencies() { 190 if (myDependencies == null) { 191 myDependencies = new ArrayList<>(); 192 } 193 return myDependencies; 194 } 195 196 public String getModuleType() { 197 return myModuleType; 198 } 199 200 public void setModuleType(String moduleType) { 201 this.myModuleType = moduleType; 202 } 203 204 public String getModuleId() { 205 return myModuleId; 206 } 207 208 public void setModuleId(String theModuleId) { 209 myModuleId = theModuleId; 210 } 211 212 public boolean isClusterManager() { 213 return "CLUSTER_MGR".equals(getModuleId()); 214 } 215 216 /** 217 * Single source of truth for "does this module serve a FHIR endpoint?". This covers the FHIR REST 218 * endpoint family (all module types sharing the {@code ENDPOINT_FHIR_REST} prefix, including the 219 * versioned variants such as {@code _DSTU2}/{@code _DSTU3}/{@code _R4}/{@code _R5}), the hybrid 220 * providers endpoint, and the FHIR gateway. 221 * <p> 222 * Both the admin-JSON port lookup ({@code AdminJsonRestClient#getFhirEndpointModuleIdFromPort}) and 223 * the harness endpoint discovery ({@code LocalhostSmileHarness}) consult this method so the two can 224 * never drift apart. Module-type string literals are used rather than 225 * {@code ca.cdr.api.model.enm.ModuleTypeEnum} because this module depends only on the public API 226 * boundary ({@code cdr-api-public-java}) and does not have {@code cdr-api} on its classpath. 227 * 228 * @return {@code true} when this module's type is a FHIR endpoint type; {@code false} for any other 229 * type or when the module type is absent. 230 */ 231 public boolean isFhirEndpointModuleType() { 232 String moduleType = getModuleType(); 233 return moduleType != null 234 && (moduleType.startsWith("ENDPOINT_FHIR_REST") 235 || moduleType.equals("ENDPOINT_HYBRID_PROVIDERS") 236 || moduleType.equals("ENDPOINT_FHIR_GATEWAY")); 237 } 238 } 239 240 @JsonPropertyOrder({ 241 "key", "value", 242 }) 243 public static class ModuleConfigProperty implements IModelJson { 244 @JsonProperty("key") 245 private String myKey; 246 247 @JsonProperty("value") 248 private String myValue; 249 250 /** 251 * Constructor 252 */ 253 public ModuleConfigProperty() { 254 super(); 255 } 256 257 /** 258 * Constructor 259 */ 260 public ModuleConfigProperty(String theKey) { 261 myKey = theKey; 262 } 263 264 public String getKey() { 265 return myKey; 266 } 267 268 public void setKey(String theKey) { 269 myKey = theKey; 270 } 271 272 public String getValue() { 273 return myValue; 274 } 275 276 public ModuleConfigProperty setValue(String theValue) { 277 myValue = theValue; 278 return this; 279 } 280 } 281 282 @JsonPropertyOrder({"dependencyType", "targetModuleId", "description", "candidates"}) 283 public static class ModuleDependency implements IModelJson { 284 285 @JsonProperty("candidates") 286 private List<ModuleDependencyCandidateTarget> myCandidates; 287 288 @JsonProperty("type") 289 private String myDependencyType; 290 291 @JsonProperty("description") 292 private String myDescription; 293 294 @JsonProperty("moduleId") 295 private String myTargetModuleId; 296 297 /** 298 * Constructor 299 */ 300 public ModuleDependency() { 301 super(); 302 } 303 304 public List<ModuleDependencyCandidateTarget> getCandidates() { 305 if (myCandidates == null) { 306 myCandidates = new ArrayList<>(); 307 } 308 return myCandidates; 309 } 310 311 public String getDependencyType() { 312 return myDependencyType; 313 } 314 315 public void setDependencyType(String theDependencyType) { 316 myDependencyType = theDependencyType; 317 } 318 319 public String getDescription() { 320 return myDescription; 321 } 322 323 public void setDescription(String theDescription) { 324 myDescription = theDescription; 325 } 326 327 public String getTargetModuleId() { 328 return myTargetModuleId; 329 } 330 331 public void setTargetModuleId(String theTargetModuleId) { 332 myTargetModuleId = theTargetModuleId; 333 } 334 335 @Override 336 public String toString() { 337 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 338 .append("type", myDependencyType) 339 .append("target", myTargetModuleId) 340 .toString(); 341 } 342 343 @JsonPropertyOrder({"moduleId", "shortName", "maturity"}) 344 public static class ModuleDependencyCandidateTarget implements IModelJson { 345 346 @JsonProperty("moduleId") 347 private String myModuleId; 348 349 @JsonProperty("shortName") 350 private String myModuleShortName; 351 352 @JsonProperty("maturity") 353 private String myMaturity; 354 355 /** 356 * Constructor 357 */ 358 public ModuleDependencyCandidateTarget() { 359 super(); 360 } 361 362 /** 363 * Constructor 364 */ 365 public ModuleDependencyCandidateTarget(String theModuleId, String theModuleShortName, String theMaturity) { 366 myModuleId = theModuleId; 367 myModuleShortName = theModuleShortName; 368 myMaturity = theMaturity; 369 } 370 371 public String getModuleId() { 372 return myModuleId; 373 } 374 375 public void setModuleId(String theModuleId) { 376 myModuleId = theModuleId; 377 } 378 379 public String getModuleShortName() { 380 return myModuleShortName; 381 } 382 383 public void setModuleShortName(String theModuleShortName) { 384 myModuleShortName = theModuleShortName; 385 } 386 387 public String getMaturity() { 388 return myMaturity; 389 } 390 391 public void setMaturity(String theMaturity) { 392 myMaturity = theMaturity; 393 } 394 } 395 } 396}