Skip to content

Conversation

@thelarsjohansson
Copy link
Contributor

Add query parameter to alarm URI.

// expand tree item if is matches item name
if (tree_view.getRoot() != null && itemName != null) {
for (TreeItem treeItem : tree_view.getRoot().getChildren()) {
if (String.valueOf(treeItem.getValue()).startsWith(itemName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't .equals() be used instead of startsWith()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. The better meaning comparison, the better solution. Drawback in this case is uglier casting and comparison of tree items.

* @throws Exception
*/
private Node create(final URI input) throws Exception
private Node create(final URI input, String itemName) throws Exception
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps the parameter itemName could be given a more descriptive name, like, e.g., itemToExpand or similar? (This also applies to other places in the PR where variations of "item name" are used for naming.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have handled this by javadoc comments. I will expand on javadoc comments for this.

* @return ["localhost:9092", "Accelerator", null] or ["localhost:9092", "Accelerator", "param=value"]
* @throws Exception on error
*/
public static String[] parseAlarmURI(final URI resource) throws Exception
Copy link
Collaborator

@abrahamwolk abrahamwolk Jun 27, 2024

Choose a reason for hiding this comment

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

I would suggest to change the return type of parseAlarmURI() to a type with more structure by:

  1. Importing org.apache.commons.lang3.tuple.ImmutableTriple
  2. Change the return type from String[] to the type ImmutableTriple<String, String, Map<String, String>> which provides more structure.
  3. Basically build the functionality of getRawQueryParameterValue() into this function by computing the map Map<String, String> from parameter-keys to their values, and returning that map as part of the return value of this function.

The function getRawQueryParameterValue() should then most likely no longer be necessary, since the values of parameters can be determined by querying the map from keys to values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand why to consider ImmutableTriple.

It is possible and fairly easy to return e.g. ImmutableMap<String, String> (Guava) with parameters and values. However ImmutableMap does not allow null value. An URI with query string ...?param1=value1&param2 would give null value for param2.

This means that e.g. url "alarm://host.my.site/Test?param1=value&param2" corresponds to map with 2 entries, param and param2 of which first has value "value1" and second has null value. However this does not work when converting this to ImmutableMap. ( names and values are put into Map than then is converted into ImmutableMap )

Therefore, options for method are to return either a Map<String, String> or as currently is done. Going for Map<String, String>.

}
}

OpenTreeViewAction otva = new OpenTreeViewAction(alarmConfigName, "itemName=" + URLEncoder.encode(item_name, StandardCharsets.UTF_8));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the = be replaced by a reference to AlarmURI.DELIMITER_QUERY_PARAMETER_VALUE?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, since the delimiters are standard for URIs I believe, should the two constants AlarmURI.DELIMITER_QUERY_PARAMETERS and AlarmURI.DELIMITER_QUERY_PARAMETER_VALUE be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I recognize that it's somewhat verbose having such constants. I removed those constans and instead introduced constant for "itemName".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Very nice that you have written tests!

/**
* Constructor
* @param alarmConfigName The alarm configuration name
* @param alarmRawQuery raw query for alarm (null if no such information is available)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using null for empty values is of course OK! However, using the type Optional<String> together with the constructor-methods Optional.empty() and Optional.of() would convey the intention of the code more clearly through the types, I think. (This also applies to other places where null is used to mean an empty value.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored constructors to avoid need to explicitly have null value.

Copy link
Collaborator

@georgweiss georgweiss left a comment

Choose a reason for hiding this comment

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

Testing looks good.

@thelarsjohansson thelarsjohansson merged commit 3c74eb1 into master Jul 3, 2024
@thelarsjohansson
Copy link
Contributor Author

Merged after approval

@thelarsjohansson thelarsjohansson deleted the CSSTUDIO-2191-alarm-area-to-tree branch July 3, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants