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