Skip to content

Commit

Permalink
googlechat end of campaign execution now display collapsable executio…
Browse files Browse the repository at this point in the history
…n list (up to 20 lines).
  • Loading branch information
vertigo17 committed Jul 14, 2024
1 parent c205f64 commit 435869b
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,34 @@ public JSONObject toJsonV001(String cerberusURL, List<Invariant> prioritiesList,
return result;
}

public String getColor(String controlStatus) {
String color = null;

if ("OK".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_OK_COL_EXT;
} else if ("KO".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_KO_COL_EXT;
} else if ("FA".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_FA_COL_EXT;
} else if ("CA".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_CA_COL_EXT;
} else if ("NA".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_NA_COL_EXT;
} else if ("NE".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_NE_COL_EXT;
} else if ("WE".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_WE_COL_EXT;
} else if ("PE".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_PE_COL_EXT;
} else if ("QU".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_QU_COL_EXT;
} else if ("QE".equals(controlStatus)) {
color = TestCaseExecution.CONTROLSTATUS_QE_COL_EXT;
} else {
color = "#000000";
}
return color;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public Answer updateEndOfQueueData(String tag) {
mytag.setNbExe(testCaseExecutionService.readNbByTag(tag));

List<TestCaseExecution> executions = testCaseExecutionService.readLastExecutionAndExecutionInQueueByTag(tag);
mytag.setExecutionsNew(executions);

// All the rest of the data are coming from ResultCI Servlet.
JSONObject jsonResponse = ciService.getCIResult(tag, mytag.getCampaign(), executions);
Expand Down Expand Up @@ -220,7 +221,7 @@ public Answer updateEndOfQueueData(String tag) {
}

//TagStatistics, only if it's a campaign and if parameter is activated
if (StringUtil.isNotEmpty(mytag.getCampaign()) && parameterService.getParameterBooleanByKey(Parameter.VALUE_cerberus_featureflipping_tagstatistics_enable, "", false )) {
if (StringUtil.isNotEmpty(mytag.getCampaign()) && parameterService.getParameterBooleanByKey(Parameter.VALUE_cerberus_featureflipping_tagstatistics_enable, "", false)) {
LOG.info("TagStatistics creation for tag {} started.", tag);
tagStatisticService.populateTagStatisticsMap(
tagStatisticService.initTagStatistics(mytag, executions),
Expand Down Expand Up @@ -291,7 +292,7 @@ public Answer createAuto(String tagS, String campaign, String user, JSONArray re
try {
cmp = campaignService.convert(campaignService.readByKey(campaign));
} catch (CerberusException ex) {
LOG.error(ex,ex);
LOG.error(ex, ex);
}
Tag newTag;
if (cmp == null) {
Expand Down Expand Up @@ -432,7 +433,7 @@ public void manageCampaignStartOfExecution(String tag, Timestamp startOfExecutio
}

}

@Override
public String formatResult(Tag tag) {
StringBuilder result = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ public MessageEvent triggerEvent(String eventReference, Object object1, Object o
if (eval_NoFilter(eventHook.getObjectKey1(), eventHook.getObjectKey2())
|| eval_Campaign_Filter(eventHook.getObjectKey1(), eventHook.getObjectKey2(), tag2.getCampaign())) {
// We load the execution list here so that in case of multiple hook, this is done only once.
if (executionList.size() < 1) {
executionList = testCaseExecutionService.readLastExecutionAndExecutionInQueueByTag(tag2.getTag());
tag2.setExecutionsNew(executionList);
}
// if (executionList.size() < 1) {
// executionList = testCaseExecutionService.readLastExecutionAndExecutionInQueueByTag(tag2.getTag());
// tag2.setExecutionsNew(executionList);
// }
// We load the invariant lists that will be used when converting execution to JSON. This is also done only once per event triggered.
// prioritiesList = invariantService.readByIdName("PRIORITY");
// countriesList = invariantService.readByIdName("COUNTRY");
Expand All @@ -186,7 +186,7 @@ public MessageEvent triggerEvent(String eventReference, Object object1, Object o
}
}

} catch (CerberusException | JSONException | ParseException ex) {
} catch (CerberusException | JSONException ex) {
LOG.error(ex, ex);
}

Expand Down Expand Up @@ -360,7 +360,7 @@ private void processEvent_CAMPAIGN_END(EventHook eventHook, Tag tag, JSONObject
if (!StringUtil.isEmpty(eventHook.getHookRecipient())) {
LOG.debug("Generating and Sending a Google Chat Notification to : '" + eventHook.getHookRecipient() + "'");
try {
JSONObject message = chatGenerationService.generateNotifyEndTagExecution(tag);
JSONObject message = chatGenerationService.generateNotifyEndTagExecutionV2(tag);
chatService.sendGoogleChatMessage(message, eventHook.getHookRecipient(), tag.getTag());
} catch (Exception ex) {
LOG.warn("Exception Google Chat notification for '" + eventHook.getEventReference() + "'", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public interface IChatGenerationService {
*/
public JSONObject generateNotifyEndTagExecution(Tag tag) throws Exception;

/**
*
* @param tag
* @return
* @throws Exception
*/
public JSONObject generateNotifyEndTagExecutionV2(Tag tag) throws Exception;

/**
*
* @param exe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ChatGenerationService implements IChatGenerationService {

private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(ChatGenerationService.class);
private static final String IMAGES_URL = "https://vm.cerberus-testing.org/notifications/status-%STATUS%.png";
private static final int MAX_LINES = 20;

@Autowired
private IParameterService parameterService;
Expand Down Expand Up @@ -135,6 +136,93 @@ public JSONObject generateNotifyEndTagExecution(Tag tag) throws UnsupportedEncod

}

@Override
public JSONObject generateNotifyEndTagExecutionV2(Tag tag) throws UnsupportedEncodingException, Exception {

String cerberusUrl = parameterService.getParameterStringByKey("cerberus_gui_url", "", "");
if (StringUtil.isEmpty(cerberusUrl)) {
cerberusUrl = parameterService.getParameterStringByKey("cerberus_url", "", "");
}
cerberusUrl = StringUtil.addSuffixIfNotAlready(cerberusUrl, "/");

String cerberusTagUrl = cerberusUrl + "ReportingExecutionByTag.jsp?Tag=" + URLEncoder.encode(tag.getTag(), "UTF-8");

JSONObject chatMessage = new JSONObject();

JSONArray cards = new JSONArray();
JSONArray cardsV2 = new JSONArray();
JSONObject card = new JSONObject();
JSONObject cardV2 = new JSONObject();

JSONObject textContent = new JSONObject();

if ("OK".equalsIgnoreCase(tag.getCiResult())) {
textContent.put("text", "<b><font color=\"" + TestCaseExecution.CONTROLSTATUS_OK_COL_EXT + "\">Campaign successfully Executed. CI Score = " + tag.getCiScore() + " < " + tag.getCiScoreThreshold() + "</font></b><br>" + tagService.formatResult(tag) + "<br>Click <a href='" + cerberusTagUrl + "'>here</a> for details.");
} else {
textContent.put("text", "<b><font color=\"" + TestCaseExecution.CONTROLSTATUS_KO_COL_EXT + "\">Campaign failed. CI Score = " + tag.getCiScore() + " (>= " + tag.getCiScoreThreshold() + ")</font></b><br>" + tagService.formatResult(tag) + "<br>Click <a href='" + cerberusTagUrl + "'>here</a> for details.");
}

JSONObject textParaContent = new JSONObject();
textParaContent.put("textParagraph", textContent);

JSONArray widgets = new JSONArray();
widgets.put(textParaContent);

String executionText = "";
int totaldisplayed = 0;
int totaltodisplay = 0;
int totallines = 0;
String cerberusExeUrl = "";
for (TestCaseExecution execution : tag.getExecutionsNew()) {
LOG.debug(execution.getControlStatus() + " - " + execution.getControlMessage() + execution.getApplication() + " - " + execution.getDescription());
totallines++;
if (!TestCaseExecution.CONTROLSTATUS_OK.equals(execution.getControlStatus())) {
totaltodisplay++;
if (MAX_LINES > totaldisplayed) {
totaldisplayed++;
if (execution.getId() == 0) {
executionText += execution.getControlStatus() + " [" + execution.getApplication() + "] <i><font color=\"" + execution.getColor(execution.getControlStatus()) + "\">" + execution.getDescription() + "</font></i><br>";
} else {
cerberusExeUrl = cerberusUrl + "TestCaseExecution.jsp?executionId=" + execution.getId();
executionText += "<a href='" + cerberusExeUrl + "'>" + execution.getControlStatus() + "</a> [" + execution.getApplication() + "] <i><font color=\"" + execution.getColor(execution.getControlStatus()) + "\">" + execution.getDescription() + "</font></i><br>";
}
}
}

}

if (totaldisplayed < totaltodisplay) {
executionText += "... Hidden more " + (totaltodisplay - totaldisplayed) + " line(s).";
}

textContent = new JSONObject();
textContent.put("text", executionText);
textParaContent = new JSONObject();
textParaContent.put("textParagraph", textContent);
widgets.put(textParaContent);

JSONArray sections = new JSONArray();
JSONObject widget = new JSONObject();

widget.put("widgets", widgets);
widget.put("collapsible", true);
widget.put("uncollapsibleWidgetsCount", 1);

widget.put("header", "Execution Tag <b>'" + tag.getTag() + "'</b> Ended.");
sections.put(widget);
card.put("sections", sections);

cards.put(card);

cardV2.put("card", card);
cardsV2.put(cardV2);
chatMessage.put("cardsV2", cardsV2);

LOG.debug(chatMessage.toString(3));
return chatMessage;

}

@Override
public JSONObject generateNotifyStartExecution(TestCaseExecution exe) throws Exception {

Expand Down

0 comments on commit 435869b

Please sign in to comment.