Skip to content

Commit

Permalink
[RHCLOUD-28663] Add query param for emitted events
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicarod7 committed Jan 10, 2025
1 parent 7ffe725 commit f6eee6f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.inject.Inject;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@ApplicationScoped
Expand Down Expand Up @@ -36,7 +37,7 @@ public class InsightsUrlsBuilder {
*/
public Optional<String> buildInventoryUrl(JsonObject data) {
String path;
ArrayList<String> queryParamParts = new ArrayList<>();
ArrayList<String> queryParamParts = new ArrayList<>(List.of("from=notifications"));
JsonObject context = data.getJsonObject("context");
if (context == null) {
return Optional.empty();
Expand All @@ -45,7 +46,7 @@ public Optional<String> buildInventoryUrl(JsonObject data) {
// A provided host url does not need to be modified
String host_url = context.getString("host_url", "");
if (!host_url.isEmpty()) {
return Optional.of(host_url);
return Optional.of(host_url + "?" + String.join("&", queryParamParts));
}

String environmentUrl = environment.url();
Expand All @@ -68,12 +69,7 @@ public Optional<String> buildInventoryUrl(JsonObject data) {
return Optional.empty();
}

if (!queryParamParts.isEmpty()) {
String queryParams = "?" + String.join("&", queryParamParts);
path += queryParams;
}

return Optional.of(environmentUrl + path);
return Optional.of(environmentUrl + path + "?" + String.join("&", queryParamParts));
}

/**
Expand All @@ -88,6 +84,7 @@ public Optional<String> buildInventoryUrl(JsonObject data) {
*/
public String buildApplicationUrl(JsonObject data) {
String path = "";
ArrayList<String> queryParamParts = new ArrayList<>(List.of("from=notifications"));

String environmentUrl = environment.url();
String bundle = data.getString("bundle", "");
Expand All @@ -104,6 +101,10 @@ public String buildApplicationUrl(JsonObject data) {
}

path += application;
if (!queryParamParts.isEmpty()) {
String queryParams = "?" + String.join("&", queryParamParts);
path += queryParams;
}

return String.format("%s/%s", environmentUrl, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class GoogleChatProcessorTest extends CamelProcessorTest {
"triggered{/if} from {data.source.application.display_name} - {data.source.bundle.display_name}. " +
"<{data.application_url}|Open {data.source.application.display_name}>\"}";

private static final String GOOGLE_CHAT_EXPECTED_MSG = "{\"text\":\"<" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/inventory/6ad30f3e-0497-4e74-99f1-b3f9a6120a6f|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies|Open Policies>\"}";
private static final String GOOGLE_CHAT_EXPECTED_MSG = "{\"text\":\"<" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/inventory/6ad30f3e-0497-4e74-99f1-b3f9a6120a6f?from=notifications|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies?from=notifications|Open Policies>\"}";

private static final String GOOGLE_CHAT_EXPECTED_MSG_WITH_HOST_URL = "{\"text\":\"<" + CONTEXT_HOST_URL + "|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies|Open Policies>\"}";
private static final String GOOGLE_CHAT_EXPECTED_MSG_WITH_HOST_URL = "{\"text\":\"<" + CONTEXT_HOST_URL + "?from=notifications|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies?from=notifications|Open Policies>\"}";

@Inject
GoogleChatProcessor googleSpacesProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public class SlackProcessorTest extends CamelProcessorTest {
"{#else}{data.events.size()} event{#if data.events.size() > 1}s{/if} triggered{/if} " +
"from {data.source.application.display_name} - {data.source.bundle.display_name}. " +
"<{data.application_url}|Open {data.source.application.display_name}>";
private static final String SLACK_EXPECTED_MSG = "<" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/inventory/6ad30f3e-0497-4e74-99f1-b3f9a6120a6f|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies|Open Policies>";
private static final String SLACK_EXPECTED_MSG_WITH_HOST_URL = "<" + CONTEXT_HOST_URL + "|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies|Open Policies>";
private static final String SLACK_EXPECTED_MSG = "<" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/inventory/6ad30f3e-0497-4e74-99f1-b3f9a6120a6f?from=notifications|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies?from=notifications|Open Policies>";
private static final String SLACK_EXPECTED_MSG_WITH_HOST_URL = "<" + CONTEXT_HOST_URL + "?from=notifications|my-computer> " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. <" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies?from=notifications|Open Policies>";

@Inject
SlackProcessor slackProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class TeamsProcessorTest extends CamelProcessorTest {
"from {data.source.application.display_name} - {data.source.bundle.display_name}. " +
"[Open {data.source.application.display_name}]({data.application_url})\"}";

private static final String TEAMS_EXPECTED_MSG = "{\"text\":\"[my-computer](" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/inventory/6ad30f3e-0497-4e74-99f1-b3f9a6120a6f) " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. [Open Policies](" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies)\"}";
private static final String TEAMS_EXPECTED_MSG = "{\"text\":\"[my-computer](" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/inventory/6ad30f3e-0497-4e74-99f1-b3f9a6120a6f?from=notifications) " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. [Open Policies](" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies?from=notifications)\"}";

private static final String TEAMS_EXPECTED_MSG_WITH_HOST_URL = "{\"text\":\"[my-computer](" + CONTEXT_HOST_URL + ") " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. [Open Policies](" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies)\"}";
private static final String TEAMS_EXPECTED_MSG_WITH_HOST_URL = "{\"text\":\"[my-computer](" + CONTEXT_HOST_URL + "?from=notifications) " +
"triggered 1 event from Policies - Red Hat Enterprise Linux. [Open Policies](" + EnvironmentTest.expectedTestEnvUrlValue + "/insights/policies?from=notifications)\"}";

@Inject
TeamsProcessor teamsProcessor;
Expand Down

0 comments on commit f6eee6f

Please sign in to comment.