use of io.gravitee.common.http.HttpMethod.GET in project gravitee-management-rest-api by gravitee-io.
the class APIV1toAPIV2Converter method migratePathsToFlows.
/**
* Migrate apiEntity.paths to Flow model.
* @param paths, the map of paths to migrate
* @param policies, the list of available policies, containing available scopes
* @return the list of Flows
*/
private List<Flow> migratePathsToFlows(Map<String, List<Rule>> paths, Set<PolicyEntity> policies) {
List<Flow> flows = new ArrayList<>();
if (!CollectionUtils.isEmpty(paths)) {
paths.forEach((pathKey, pathValue) -> {
// if all rules for a path have the same set of HttpMethods, then we have a unique flow for this path.
// else, we have a flow per rule in the path.
boolean oneFlowPerPathMode = pathValue.stream().map(rule -> {
Set<HttpMethod> methods = new HashSet<>(rule.getMethods());
methods.retainAll(HTTP_METHODS);
return methods;
}).distinct().count() == 1;
if (oneFlowPerPathMode) {
// since, all HttpMethods are the same in this case, we can use `pathValue.getRules().get(0).getMethods()`
final Flow flow = createFlow(pathKey, pathValue.get(0).getMethods());
pathValue.forEach(rule -> {
configurePolicies(policies, rule, flow);
});
// reverse policies of the Post steps otherwise, flow are displayed in the wrong order into the policy studio
Collections.reverse(flow.getPost());
flows.add(flow);
} else {
pathValue.forEach(rule -> {
final Flow flow = createFlow(pathKey, rule.getMethods());
configurePolicies(policies, rule, flow);
// reverse policies of the Post steps otherwise, flow are displayed in the wrong order into the policy studio
Collections.reverse(flow.getPost());
flows.add(flow);
});
}
});
}
return flows;
}
Aggregations