Skip to content

Commit 5b6f56d

Browse files
committed
fix: let users pass page HRID for plan general condition
see https://gravitee.atlassian.net/browse/GKO-2703
1 parent 74a77d7 commit 5b6f56d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/apim/core/plan/domain_service/ValidatePlanDomainService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.HashMap;
3131
import java.util.List;
3232
import java.util.Map;
33+
import java.util.Optional;
34+
import java.util.UUID;
3335
import lombok.CustomLog;
3436
import lombok.RequiredArgsConstructor;
3537

@@ -70,6 +72,19 @@ public Result<Input> validateAndSanitize(Input input) {
7072
}
7173

7274
plan.setHrid(k);
75+
if (plan.getGeneralConditions() != null && !isUUID(planCRD.getGeneralConditions())) {
76+
input.pages
77+
.stream()
78+
.filter(page -> plan.getGeneralConditions().equalsIgnoreCase(page.getHrid()))
79+
.findAny()
80+
.ifPresent(page -> {
81+
planCRD.setGeneralConditions(page.getId());
82+
planCRD.setGeneralConditionsHrid(page.getHrid());
83+
plan.setGeneralConditions(page.getId());
84+
plan.setGeneralConditionsHrid(page.getHrid());
85+
});
86+
}
87+
7388
if (
7489
(planCRD.getGeneralConditions() == null || planCRD.getGeneralConditions().isEmpty()) &&
7590
(planCRD.getGeneralConditionsHrid() != null && !planCRD.getGeneralConditionsHrid().isEmpty())
@@ -104,4 +119,14 @@ public Result<Input> validateAndSanitize(Input input) {
104119

105120
return Result.ofBoth(input.sanitized(sanitizedPlans), errors);
106121
}
122+
123+
public boolean isUUID(String str) {
124+
if (str == null) return false;
125+
try {
126+
UUID.fromString(str);
127+
return true;
128+
} catch (IllegalArgumentException e) {
129+
return false;
130+
}
131+
}
107132
}

0 commit comments

Comments
 (0)