Skip to content

Commit

Permalink
Use getId() method
Browse files Browse the repository at this point in the history
  • Loading branch information
miwurster committed Mar 9, 2021
1 parent 4dbfeb1 commit 457a560
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions edmm-core/src/main/java/io/github/edmm/plugins/rules/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public Rule(String name, String description, int priority, ReplacementReason rea
ruleAssessor = new RuleAssessor();
}

public Rule (String name, String description, ReplacementReason reason) {
public Rule(String name, String description, ReplacementReason reason) {
this(name, description, DEFAULT_PRIORITY, reason);
}

public Rule(String name, String description) {
this(name,description, DEFAULT_PRIORITY, ReplacementReason.UNSUPPORTED);
this(name, description, DEFAULT_PRIORITY, ReplacementReason.UNSUPPORTED);
}

/**
Expand All @@ -56,7 +56,7 @@ public Rule(String name, String description) {
public boolean evaluate(DeploymentModel actualModel, RootComponent currentComponent) {
DeploymentModel expectedModel = DeploymentModel.of(fromTopology(new EdmmYamlBuilder()).build());

RuleAssessor.Result assessResult = ruleAssessor.assess(expectedModel,actualModel,currentComponent,false);
RuleAssessor.Result assessResult = ruleAssessor.assess(expectedModel, actualModel, currentComponent, false);
// the unsupportedComponents should be retrieved immediately after the asses function
// if evaluate returns true its value is valid and will be used in the execute function
unsupportedComponents = assessResult.getUnsupportedComponents();
Expand All @@ -65,13 +65,13 @@ public boolean evaluate(DeploymentModel actualModel, RootComponent currentCompon

if (exceptYamlBuilders != null && assessResult.matches()) {
// if the topology matches we check for exceptions
for (EdmmYamlBuilder yamlBuilder: exceptYamlBuilders) {
DeploymentModel exceptionModel = DeploymentModel.of(yamlBuilder.build());
if ( ruleAssessor.assess(exceptionModel, actualModel, currentComponent, true).matches() ) {
// if there is an exact match this rule shouldn't be evaluated because
// we found a topology representing an exception
return false;
}
for (EdmmYamlBuilder yamlBuilder : exceptYamlBuilders) {
DeploymentModel exceptionModel = DeploymentModel.of(yamlBuilder.build());
if (ruleAssessor.assess(exceptionModel, actualModel, currentComponent, true).matches()) {
// if there is an exact match this rule shouldn't be evaluated because
// we found a topology representing an exception
return false;
}
}
}
return assessResult.matches();
Expand All @@ -93,9 +93,9 @@ public Rule.Result execute() throws NullPointerException {
protected abstract EdmmYamlBuilder toTopology(EdmmYamlBuilder yamlBuilder);

/**
* @return an array of topologies that are exceptions w.r.t. fromTopology
* i.e. the plugin supports Auth0 but not any other Saas: fromTopology function will return Saas,
* while this function will return Auth0, so that this rule will match every Saas except Auth0
* @return an array of topologies that are exceptions w.r.t. fromTopology i.e. the plugin supports Auth0 but not any
* other Saas: fromTopology function will return Saas, while this function will return Auth0, so that this rule will
* match every Saas except Auth0
*/
protected EdmmYamlBuilder[] exceptTopologies() {
return null;
Expand All @@ -106,7 +106,7 @@ public static List<Rule> getDefault() {
rules.add(new PaasDefaultRule());
rules.add(new SaasDefaultRule());
rules.add(new DbaasDefaultRule());
return rules;
return rules;
}

@Override
Expand Down Expand Up @@ -140,15 +140,14 @@ public String toString() {
public class Result {
private final String reason;
private final List<String> unsupportedComponents;
private final Map<String,Object> toTopology;
private final Map<String, Object> toTopology;

public Result(ReplacementReason reason, List<RootComponent> unsupportedComponents, Map<String,Object> toTopology) {
public Result(ReplacementReason reason, List<RootComponent> unsupportedComponents, Map<String, Object> toTopology) {
this.reason = reason.toString();
this.toTopology = toTopology;

this.unsupportedComponents = unsupportedComponents.stream()
.map(BaseElement::getName)
.collect(Collectors.toList());
.map(BaseElement::getId)
.collect(Collectors.toList());
}

public boolean isUnsupported() {
Expand Down

0 comments on commit 457a560

Please sign in to comment.