001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2025 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.EqualsBuilder; 018import org.apache.commons.lang3.builder.HashCodeBuilder; 019import org.apache.commons.lang3.builder.ToStringBuilder; 020import org.apache.commons.lang3.builder.ToStringStyle; 021 022import java.util.ArrayList; 023import java.util.List; 024import java.util.Optional; 025import java.util.stream.Collectors; 026 027/** 028 * This class is a copy of NodeConfigsJson from cdr-api, with all enum references 029 * from cdr-api replaced with string values. 030 * <p> 031 * This class was auto-generated from a private API class, using Claude 3.7 sonnet 032 */ 033public class NodeConfigurations implements IModelJson { 034 035 @JsonProperty(value = "nodes") 036 private List<NodeConfiguration> myNodes; 037 038 public Optional<NodeConfiguration> getNode(String theNodeId) { 039 Validate.notBlank(theNodeId, "theNodeId must not be blank"); 040 041 return getNodes().stream().filter(t -> theNodeId.equals(t.getNodeId())).findFirst(); 042 } 043 044 public List<NodeConfiguration> getNodes() { 045 if (myNodes == null) { 046 myNodes = new ArrayList<>(); 047 } 048 return myNodes; 049 } 050 051 @JsonPropertyOrder({"nodeId", "configLocked", "securityStrict", "modules"}) 052 public static class NodeConfiguration implements IModelJson { 053 054 @JsonProperty("modules") 055 private List<ModuleConfiguration> myModules; 056 057 @JsonProperty("nodeId") 058 private String myNodeId; 059 060 @JsonProperty("serverPortOffset") 061 private Integer myServerPortOffset = 0; 062 063 @JsonProperty("configLocked") 064 private Boolean myConfigLocked = false; 065 066 @JsonProperty("securityStrict") 067 private Boolean mySecurityStrict = false; 068 069 @JsonProperty("propertySource") 070 private String myPropertySource; 071 072 @JsonProperty("environmentType") 073 private EnvironmentTypeEnum myEnvironmentType = EnvironmentTypeEnum.DEV; 074 075 @JsonProperty("archiveUnknownModules") 076 private Boolean myArchiveUnknownModules = false; 077 078 public Optional<ModuleConfiguration> getModule(String theModuleId) { 079 Validate.notBlank(theModuleId, "theModuleId must not be blank"); 080 081 return getModules().stream() 082 .filter(t -> theModuleId.equals(t.getModuleId())) 083 .findFirst(); 084 } 085 086 public List<ModuleConfiguration> getModules() { 087 if (myModules == null) { 088 myModules = new ArrayList<>(); 089 } 090 return myModules; 091 } 092 093 public String getNodeId() { 094 return myNodeId; 095 } 096 097 public NodeConfiguration setNodeId(String theNodeId) { 098 myNodeId = theNodeId; 099 return this; 100 } 101 102 public NodeConfiguration setSecurityStrict(Boolean theSecurityStrict) { 103 mySecurityStrict = theSecurityStrict; 104 return this; 105 } 106 107 public Integer getServerPortOffset() { 108 return myServerPortOffset; 109 } 110 111 public NodeConfiguration setServerPortOffset(Integer theServerPortOffset) { 112 myServerPortOffset = theServerPortOffset; 113 return this; 114 } 115 116 public String getPropertySource() { 117 return myPropertySource; 118 } 119 120 public NodeConfiguration setPropertySource(String thePropertySource) { 121 myPropertySource = thePropertySource; 122 return this; 123 } 124 125 public NodeConfiguration setEnvironmentType(EnvironmentTypeEnum theEnvironmentTypeEnum) { 126 myEnvironmentType = theEnvironmentTypeEnum; 127 return this; 128 } 129 130 public EnvironmentTypeEnum getEnvironmentType() { 131 return myEnvironmentType; 132 } 133 134 public boolean getShouldArchiveUnknownModules() { 135 return Boolean.TRUE.equals(myArchiveUnknownModules); 136 } 137 138 public NodeConfiguration setShouldArchiveUnknownModules(Boolean myArchiveUnknownModules) { 139 this.myArchiveUnknownModules = myArchiveUnknownModules; 140 return this; 141 } 142 } 143 144 @JsonPropertyOrder({ 145 "moduleId", 146 "moduleType", 147 "dependencies", 148 "options", 149 }) 150 public static class ModuleConfiguration implements IModelJson { 151 152 @JsonProperty("options") 153 private List<ModuleConfigProperty> myConfigProperties; 154 155 @JsonProperty("dependencies") 156 private List<ModuleDependency> myDependencies; 157 158 @JsonProperty("moduleId") 159 private String myModuleId; 160 161 @JsonProperty("moduleType") 162 private String myModuleType; 163 164 165 /** 166 * Constructor 167 */ 168 public ModuleConfiguration() { 169 super(); 170 } 171 172 173 public List<String> getConfigKeys() { 174 return getConfigProperties().stream().map(t -> t.getKey()).collect(Collectors.toList()); 175 } 176 177 public List<ModuleConfigProperty> getConfigProperties() { 178 if (myConfigProperties == null) { 179 myConfigProperties = new ArrayList<>(); 180 } 181 return myConfigProperties; 182 } 183 184 public String getConfigProperty(String theKey) { 185 return getConfigProperties().stream() 186 .filter(t -> t.getKey().equals(theKey)) 187 .map(ModuleConfigProperty::getValue) 188 .findFirst() 189 .orElseThrow(() -> { 190 return new IllegalArgumentException("Unknown key: " + theKey + " - Valid keys: " + getConfigKeys()); 191 }); 192 } 193 194 public List<ModuleDependency> getDependencies() { 195 if (myDependencies == null) { 196 myDependencies = new ArrayList<>(); 197 } 198 return myDependencies; 199 } 200 201 202 public String getModuleType() { 203 return myModuleType; 204 } 205 206 public void setModuleType(String moduleType) { 207 this.myModuleType = moduleType; 208 } 209 210 public String getModuleId() { 211 return myModuleId; 212 } 213 214 public void setModuleId(String theModuleId) { 215 myModuleId = theModuleId; 216 } 217 218 public boolean isClusterManager() { 219 return "CLUSTER_MGR".equals(getModuleId()); 220 } 221 } 222 223 @JsonPropertyOrder({ 224 "key", 225 "value", 226 }) 227 public static class ModuleConfigProperty implements IModelJson { 228 @JsonProperty("key") 229 private String myKey; 230 231 @JsonProperty("value") 232 private String myValue; 233 234 /** 235 * Constructor 236 */ 237 public ModuleConfigProperty() { 238 super(); 239 } 240 241 /** 242 * Constructor 243 */ 244 public ModuleConfigProperty(String theKey) { 245 myKey = theKey; 246 } 247 248 249 public String getKey() { 250 return myKey; 251 } 252 253 public void setKey(String theKey) { 254 myKey = theKey; 255 } 256 257 public String getValue() { 258 return myValue; 259 } 260 261 public ModuleConfigProperty setValue(String theValue) { 262 myValue = theValue; 263 return this; 264 } 265 } 266 267 @JsonPropertyOrder({"dependencyType", "targetModuleId", "description", "candidates"}) 268 public static class ModuleDependency implements IModelJson { 269 270 @JsonProperty("candidates") 271 private List<ModuleDependencyCandidateTarget> myCandidates; 272 273 @JsonProperty("dependencyType") 274 private String myDependencyType; 275 276 @JsonProperty("description") 277 private String myDescription; 278 279 @JsonProperty("targetModuleId") 280 private String myTargetModuleId; 281 282 public List<ModuleDependencyCandidateTarget> getCandidates() { 283 if (myCandidates == null) { 284 myCandidates = new ArrayList<>(); 285 } 286 return myCandidates; 287 } 288 289 public String getDependencyType() { 290 return myDependencyType; 291 } 292 293 public void setDependencyType(String theDependencyType) { 294 myDependencyType = theDependencyType; 295 } 296 297 public String getDescription() { 298 return myDescription; 299 } 300 301 public void setDescription(String theDescription) { 302 myDescription = theDescription; 303 } 304 305 public String getTargetModuleId() { 306 return myTargetModuleId; 307 } 308 309 public void setTargetModuleId(String theTargetModuleId) { 310 myTargetModuleId = theTargetModuleId; 311 } 312 313 @Override 314 public String toString() { 315 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 316 .append("type", myDependencyType) 317 .append("target", myTargetModuleId) 318 .toString(); 319 } 320 321 @JsonPropertyOrder({"moduleId", "shortName", "maturity"}) 322 public static class ModuleDependencyCandidateTarget implements IModelJson { 323 324 @JsonProperty("moduleId") 325 private String myModuleId; 326 327 @JsonProperty("shortName") 328 private String myModuleShortName; 329 330 @JsonProperty("maturity") 331 private String myMaturity; 332 333 /** 334 * Constructor 335 */ 336 public ModuleDependencyCandidateTarget() { 337 super(); 338 } 339 340 /** 341 * Constructor 342 */ 343 public ModuleDependencyCandidateTarget( 344 String theModuleId, String theModuleShortName, String theMaturity) { 345 myModuleId = theModuleId; 346 myModuleShortName = theModuleShortName; 347 myMaturity = theMaturity; 348 } 349 350 public String getModuleId() { 351 return myModuleId; 352 } 353 354 public void setModuleId(String theModuleId) { 355 myModuleId = theModuleId; 356 } 357 358 public String getModuleShortName() { 359 return myModuleShortName; 360 } 361 362 public void setModuleShortName(String theModuleShortName) { 363 myModuleShortName = theModuleShortName; 364 } 365 366 public String getMaturity() { 367 return myMaturity; 368 } 369 370 public void setMaturity(String theMaturity) { 371 myMaturity = theMaturity; 372 } 373 } 374 } 375 376 public static class ModuleId implements IModelJson { 377 378 @JsonProperty("moduleId") 379 private String myModuleId; 380 381 @JsonProperty("nodeId") 382 private String myNodeId; 383 384 /** 385 * Constructor 386 */ 387 public ModuleId() { 388 super(); 389 } 390 391 /** 392 * Constructor 393 */ 394 public ModuleId(String theNodeId, String theModuleId) { 395 setNodeId(theNodeId); 396 setModuleId(theModuleId); 397 } 398 399 @Override 400 public boolean equals(Object theO) { 401 if (this == theO) { 402 return true; 403 } 404 405 if (theO == null || getClass() != theO.getClass()) { 406 return false; 407 } 408 409 ModuleId that = (ModuleId) theO; 410 411 return new EqualsBuilder() 412 .append(getNodeId(), that.getNodeId()) 413 .append(getModuleId(), that.getModuleId()) 414 .isEquals(); 415 } 416 417 public String getModuleId() { 418 return myModuleId; 419 } 420 421 public ModuleId setModuleId(String theModuleId) { 422 myModuleId = theModuleId; 423 return this; 424 } 425 426 public String getNodeId() { 427 return myNodeId; 428 } 429 430 public ModuleId setNodeId(String theNodeId) { 431 myNodeId = theNodeId; 432 return this; 433 } 434 435 @Override 436 public int hashCode() { 437 return new HashCodeBuilder(17, 37) 438 .append(getNodeId()) 439 .append(getModuleId()) 440 .toHashCode(); 441 } 442 443 @Override 444 public String toString() { 445 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 446 .append("myModuleId", myModuleId) 447 .append("myNodeId", myNodeId) 448 .toString(); 449 } 450 } 451}