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 /** 164 * Constructor 165 */ 166 public ModuleConfiguration() { 167 super(); 168 } 169 170 171 public List<String> getConfigKeys() { 172 return getConfigProperties().stream().map(t -> t.getKey()).collect(Collectors.toList()); 173 } 174 175 public List<ModuleConfigProperty> getConfigProperties() { 176 if (myConfigProperties == null) { 177 myConfigProperties = new ArrayList<>(); 178 } 179 return myConfigProperties; 180 } 181 182 public String getConfigProperty(String theKey) { 183 return getConfigProperties().stream() 184 .filter(t -> t.getKey().equals(theKey)) 185 .map(ModuleConfigProperty::getValue) 186 .findFirst() 187 .orElseThrow(() -> new IllegalArgumentException("Unknown key: " + theKey + " - Valid keys: " + getConfigKeys())); 188 } 189 190 public List<ModuleDependency> getDependencies() { 191 if (myDependencies == null) { 192 myDependencies = new ArrayList<>(); 193 } 194 return myDependencies; 195 } 196 197 public String getModuleType() { 198 return myModuleType; 199 } 200 201 public void setModuleType(String moduleType) { 202 this.myModuleType = moduleType; 203 } 204 205 public String getModuleId() { 206 return myModuleId; 207 } 208 209 public void setModuleId(String theModuleId) { 210 myModuleId = theModuleId; 211 } 212 213 public boolean isClusterManager() { 214 return "CLUSTER_MGR".equals(getModuleId()); 215 } 216 217 /** 218 * Single source of truth for "does this module serve a FHIR endpoint?". This covers the FHIR REST 219 * endpoint family (all module types sharing the {@code ENDPOINT_FHIR_REST} prefix, including the 220 * versioned variants such as {@code _DSTU2}/{@code _DSTU3}/{@code _R4}/{@code _R5}), the hybrid 221 * providers endpoint, and the FHIR gateway. 222 * <p> 223 * Both the admin-JSON port lookup ({@code AdminJsonRestClient#getFhirEndpointModuleIdFromPort}) and 224 * the harness endpoint discovery ({@code LocalhostSmileHarness}) consult this method so the two can 225 * never drift apart. Module-type string literals are used rather than 226 * {@code ca.cdr.api.model.enm.ModuleTypeEnum} because this module depends only on the public API 227 * boundary ({@code cdr-api-public-java}) and does not have {@code cdr-api} on its classpath. 228 * 229 * @return {@code true} when this module's type is a FHIR endpoint type; {@code false} for any other 230 * type or when the module type is absent. 231 */ 232 public boolean isFhirEndpointModuleType() { 233 String moduleType = getModuleType(); 234 return moduleType != null 235 && (moduleType.startsWith("ENDPOINT_FHIR_REST") 236 || moduleType.equals("ENDPOINT_HYBRID_PROVIDERS") 237 || moduleType.equals("ENDPOINT_FHIR_GATEWAY")); 238 } 239 } 240 241 @JsonPropertyOrder({ 242 "key", 243 "value", 244 }) 245 public static class ModuleConfigProperty implements IModelJson { 246 @JsonProperty("key") 247 private String myKey; 248 249 @JsonProperty("value") 250 private String myValue; 251 252 /** 253 * Constructor 254 */ 255 public ModuleConfigProperty() { 256 super(); 257 } 258 259 /** 260 * Constructor 261 */ 262 public ModuleConfigProperty(String theKey) { 263 myKey = theKey; 264 } 265 266 267 public String getKey() { 268 return myKey; 269 } 270 271 public void setKey(String theKey) { 272 myKey = theKey; 273 } 274 275 public String getValue() { 276 return myValue; 277 } 278 279 public ModuleConfigProperty setValue(String theValue) { 280 myValue = theValue; 281 return this; 282 } 283 } 284 285 @JsonPropertyOrder({"dependencyType", "targetModuleId", "description", "candidates"}) 286 public static class ModuleDependency implements IModelJson { 287 288 @JsonProperty("candidates") 289 private List<ModuleDependencyCandidateTarget> myCandidates; 290 291 @JsonProperty("type") 292 private String myDependencyType; 293 294 @JsonProperty("description") 295 private String myDescription; 296 297 @JsonProperty("moduleId") 298 private String myTargetModuleId; 299 300 /** 301 * Constructor 302 */ 303 public ModuleDependency() { 304 super(); 305 } 306 307 public List<ModuleDependencyCandidateTarget> getCandidates() { 308 if (myCandidates == null) { 309 myCandidates = new ArrayList<>(); 310 } 311 return myCandidates; 312 } 313 314 public String getDependencyType() { 315 return myDependencyType; 316 } 317 318 public void setDependencyType(String theDependencyType) { 319 myDependencyType = theDependencyType; 320 } 321 322 public String getDescription() { 323 return myDescription; 324 } 325 326 public void setDescription(String theDescription) { 327 myDescription = theDescription; 328 } 329 330 public String getTargetModuleId() { 331 return myTargetModuleId; 332 } 333 334 public void setTargetModuleId(String theTargetModuleId) { 335 myTargetModuleId = theTargetModuleId; 336 } 337 338 @Override 339 public String toString() { 340 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 341 .append("type", myDependencyType) 342 .append("target", myTargetModuleId) 343 .toString(); 344 } 345 346 @JsonPropertyOrder({"moduleId", "shortName", "maturity"}) 347 public static class ModuleDependencyCandidateTarget implements IModelJson { 348 349 @JsonProperty("moduleId") 350 private String myModuleId; 351 352 @JsonProperty("shortName") 353 private String myModuleShortName; 354 355 @JsonProperty("maturity") 356 private String myMaturity; 357 358 /** 359 * Constructor 360 */ 361 public ModuleDependencyCandidateTarget() { 362 super(); 363 } 364 365 /** 366 * Constructor 367 */ 368 public ModuleDependencyCandidateTarget( 369 String theModuleId, String theModuleShortName, String theMaturity) { 370 myModuleId = theModuleId; 371 myModuleShortName = theModuleShortName; 372 myMaturity = theMaturity; 373 } 374 375 public String getModuleId() { 376 return myModuleId; 377 } 378 379 public void setModuleId(String theModuleId) { 380 myModuleId = theModuleId; 381 } 382 383 public String getModuleShortName() { 384 return myModuleShortName; 385 } 386 387 public void setModuleShortName(String theModuleShortName) { 388 myModuleShortName = theModuleShortName; 389 } 390 391 public String getMaturity() { 392 return myMaturity; 393 } 394 395 public void setMaturity(String theMaturity) { 396 myMaturity = theMaturity; 397 } 398 } 399 } 400}