Skip to content
This repository has been archived by the owner on Nov 27, 2017. It is now read-only.

refactor(filter): Filter use now always 'simple', not jsonpath #12

Merged
merged 2 commits into from
Aug 31, 2017

Conversation

rhuss
Copy link
Contributor

@rhuss rhuss commented Aug 28, 2017

A JsonSimplePredicate has been introduced which temporarily tries to convert a string to a JSON map / list so that the simple language expression can be applied to it.

A JsonSimplePredicate has been introduced which temporarily tries to convert a string to a JSON map / list so that the simple language expression can be applied to it.
Copy link
Member

@zregvart zregvart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing that can't be fixed in later PRs, @rhuss let me know if you wish to incorporate anything from the review or address anything in later PRs.

👍

new File(folder, FILE_NAME),
new File(new File(folder, "config"), FILE_NAME)
}) {
if (file.exists() && file.isFile()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to add file.canRead() also here?

@@ -92,34 +99,25 @@ protected static SyndesisModel validateConfig(SyndesisModel config, URL url) {
/**
* Tries to find the configuration from the current directory or a parent folder.
*/
public static SyndesisModel findFromFolder(File folder) throws IOException {
public static SyndesisModel tryFindFromFolder(File folder) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use Optional<SyndesisModel> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an with optional

return model;
}
}
throw new IOException("syndesis.yml could not be found in current directory or parent directories and is not on the classpath");
}


protected static SyndesisModel loadFromFile(File file) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps return Optional<SyndesisModel>

new File(folder, FILE_NAME),
new File(new File(folder, "config"), FILE_NAME)
}) {
if (file.exists() && file.isFile()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need file.canRead() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea.

return answer;
}
throw new IOException("SyndesisModel configuration folder does not exist: " + folder.getPath());
return null;
}

protected static SyndesisModel tryFindConfigOnClassPath() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return Optional<SyndesisModel>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

} else {
message.append(".main()");
}
message.append(functionName).append(".").append(method != null ? method : "main").append("()");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using Optional, but it's a style preference, something like: Optional.ofNullable(method).or("main")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old guys like tertiary operators ;-) but ok, let's try that hipster thing.

message.append(name);
message.append("() ");

if (trigger.equals("http")) {
trigger = DEFAULT_HTTP_ENDPOINT_PREFIX;
} else if (trigger.startsWith("http:") || trigger.startsWith("https:") ||
trigger.startsWith("http://") || trigger.startsWith("https://")) {
} else if (trigger.startsWith("http:") || trigger.startsWith("https:")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the original intent was to support uri as a component URI or uri as a HTTP URL. In camel there are many HTTP components that have their component URI starting with .*http.*: (like http4:... or netty-http:...). Perhaps a comment here would benefit future readers of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually my reasoning was purely based on the observation that if the uri starts with http:// it also starts with http:, so the last two terms are useless.

No idea what the original intent was (but this was confusing to me). I should have resisted but I had simply to clean up :)

@@ -281,6 +261,15 @@ protected RouteDefinition fromOrTo(RouteDefinition route, String name, String ur
return route;
}

private String stripPrefix(String trigger, String ... prefixes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return Optional; even for private method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats all old funktion code originally, I just inherited the baggage.

The logic is a bit complex here, so

// Therefor we set a map instead of the string
Map jsonDocument = jsonStringAsMap((String) msgBody, exchange);
if (jsonDocument != null) {
exchangeToCheck = ExchangeHelper.createCopy(exchange, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the idea is to have simpleExpression work on the parsed JSON instead of the original exchange, but keep the original exchange (the IN message) intact? Perhaps a comment to attest to that could help here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that's the actual PR. You are right, the intention is that only the predicate acts on the converted value, but the original in message still continues to carry the same format as the filter is not supposed to change anything within the exchange.

I added a clarifying comment.

@rhuss
Copy link
Contributor Author

rhuss commented Aug 29, 2017

Fixes #11

@pure-bot
Copy link

pure-bot bot commented Aug 31, 2017

Pull request approved by @zregvart - applying approved label

Copy link
Member

@zregvart zregvart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@pure-bot pure-bot bot added the approved label Aug 31, 2017
@pure-bot pure-bot bot merged commit d8f94de into syndesisio:master Aug 31, 2017
@rhuss
Copy link
Contributor Author

rhuss commented Aug 31, 2017

thx :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants