Skip to content

Commit

Permalink
reduced log size and cleaned some non blocking npe errors.
Browse files Browse the repository at this point in the history
Fixed autocomplet on system variable on some fields.
Improved layout of testcasescript page for small screens.
  • Loading branch information
vertigo17 committed Jul 13, 2024
1 parent e6fff27 commit a3c59f1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.cerberus.core.crud.entity.CountryEnvironmentParameters;
Expand All @@ -53,6 +56,8 @@ public class VariableService implements IVariableService {
private static final Logger LOG = LogManager.getLogger(VariableService.class);

private static final String VALUE_WHEN_NULL = "<null>";
public static final Pattern SYSTEM_VARIABLE_DATE_PATTERN = Pattern.compile("%system.([a-zA-Z0-9-+]*)-([a-z A-Z0-9]*)%");
public static final Pattern SYSTEM_SUBVARIABLE_DATE_PATTERN = Pattern.compile("([a-zA-Z]*)([-+])([0-9]*)");

@Autowired
private PropertyService propertyService;
Expand Down Expand Up @@ -387,43 +392,7 @@ public String decodeStringWithSystemVariable(String stringToDecode, TestCaseExec
/**
* Trying to replace date variables .
*/
stringToDecode = stringToDecode.replace("%SYS_TODAY-yyyy%", DateUtil.getTodayFormat("yyyy"));
stringToDecode = stringToDecode.replace("%SYS_TODAY-MM%", DateUtil.getTodayFormat("MM"));
stringToDecode = stringToDecode.replace("%SYS_TODAY-dd%", DateUtil.getTodayFormat("dd"));
stringToDecode = stringToDecode.replace("%SYS_TODAY-doy%", DateUtil.getTodayFormat("D"));
stringToDecode = stringToDecode.replace("%SYS_TODAY-HH%", DateUtil.getTodayFormat("HH"));
stringToDecode = stringToDecode.replace("%SYS_TODAY-mm%", DateUtil.getTodayFormat("mm"));
stringToDecode = stringToDecode.replace("%SYS_TODAY-ss%", DateUtil.getTodayFormat("ss"));
stringToDecode = stringToDecode.replace("%SYS_YESTERDAY-yyyy%", DateUtil.getYesterdayFormat("yyyy"));
stringToDecode = stringToDecode.replace("%SYS_YESTERDAY-MM%", DateUtil.getYesterdayFormat("MM"));
stringToDecode = stringToDecode.replace("%SYS_YESTERDAY-dd%", DateUtil.getYesterdayFormat("dd"));
stringToDecode = stringToDecode.replace("%SYS_YESTERDAY-doy%", DateUtil.getYesterdayFormat("D"));
stringToDecode = stringToDecode.replace("%SYS_YESTERDAY-HH%", DateUtil.getYesterdayFormat("HH"));
stringToDecode = stringToDecode.replace("%SYS_YESTERDAY-mm%", DateUtil.getYesterdayFormat("mm"));
stringToDecode = stringToDecode.replace("%SYS_YESTERDAY-ss%", DateUtil.getYesterdayFormat("ss"));
stringToDecode = stringToDecode.replace("%SYS_TOMORROW-yyyy%", DateUtil.getTomorrowFormat("yyyy"));
stringToDecode = stringToDecode.replace("%SYS_TOMORROW-MM%", DateUtil.getTomorrowFormat("MM"));
stringToDecode = stringToDecode.replace("%SYS_TOMORROW-dd%", DateUtil.getTomorrowFormat("dd"));
stringToDecode = stringToDecode.replace("%SYS_TOMORROW-doy%", DateUtil.getTomorrowFormat("D"));
//New syntax
stringToDecode = stringToDecode.replace("%system.TODAY-yyyy%", DateUtil.getTodayFormat("yyyy"));
stringToDecode = stringToDecode.replace("%system.TODAY-MM%", DateUtil.getTodayFormat("MM"));
stringToDecode = stringToDecode.replace("%system.TODAY-dd%", DateUtil.getTodayFormat("dd"));
stringToDecode = stringToDecode.replace("%system.TODAY-doy%", DateUtil.getTodayFormat("D"));
stringToDecode = stringToDecode.replace("%system.TODAY-HH%", DateUtil.getTodayFormat("HH"));
stringToDecode = stringToDecode.replace("%system.TODAY-mm%", DateUtil.getTodayFormat("mm"));
stringToDecode = stringToDecode.replace("%system.TODAY-ss%", DateUtil.getTodayFormat("ss"));
stringToDecode = stringToDecode.replace("%system.YESTERDAY-yyyy%", DateUtil.getYesterdayFormat("yyyy"));
stringToDecode = stringToDecode.replace("%system.YESTERDAY-MM%", DateUtil.getYesterdayFormat("MM"));
stringToDecode = stringToDecode.replace("%system.YESTERDAY-dd%", DateUtil.getYesterdayFormat("dd"));
stringToDecode = stringToDecode.replace("%system.YESTERDAY-doy%", DateUtil.getYesterdayFormat("D"));
stringToDecode = stringToDecode.replace("%system.YESTERDAY-HH%", DateUtil.getYesterdayFormat("HH"));
stringToDecode = stringToDecode.replace("%system.YESTERDAY-mm%", DateUtil.getYesterdayFormat("mm"));
stringToDecode = stringToDecode.replace("%system.YESTERDAY-ss%", DateUtil.getYesterdayFormat("ss"));
stringToDecode = stringToDecode.replace("%system.TOMORROW-yyyy%", DateUtil.getTomorrowFormat("yyyy"));
stringToDecode = stringToDecode.replace("%system.TOMORROW-MM%", DateUtil.getTomorrowFormat("MM"));
stringToDecode = stringToDecode.replace("%system.TOMORROW-dd%", DateUtil.getTomorrowFormat("dd"));
stringToDecode = stringToDecode.replace("%system.TOMORROW-doy%", DateUtil.getTomorrowFormat("D"));
stringToDecode = decodeStringWithDateVariable(stringToDecode, execution.getCountryObj().getGp2());

return stringToDecode;

Expand All @@ -434,4 +403,63 @@ public String decodeStringWithSystemVariable(String stringToDecode, TestCaseExec
return stringToDecode;
}

public String decodeStringWithDateVariable(String stringToDecode, String locale) {

Matcher variableMatcher = SYSTEM_VARIABLE_DATE_PATTERN.matcher(stringToDecode);
Matcher subVariableMatcher = null;

if (variableMatcher.find()) {
SimpleDateFormat formater = null; // Define the MySQL Format.

do {

Date today = new Date(); // Getting now.
Calendar cal = Calendar.getInstance();
cal.setTime(today);

switch (variableMatcher.group(1)) {
case "TODAY":
break;
case "TOMORROW":
cal.add(Calendar.HOUR, +24);
break;
case "YESTERDAY":
cal.add(Calendar.HOUR, -24);
break;
default:
subVariableMatcher = SYSTEM_SUBVARIABLE_DATE_PATTERN.matcher(variableMatcher.group(1));
if (subVariableMatcher.matches()) {
switch (subVariableMatcher.group(1)) {
case "DAY":
cal.add(Calendar.DAY_OF_YEAR, Integer.parseInt(subVariableMatcher.group(2) + subVariableMatcher.group(3)));
break;
case "HOUR":
cal.add(Calendar.HOUR, Integer.parseInt(subVariableMatcher.group(2) + subVariableMatcher.group(3)));
break;
case "MINUTE":
cal.add(Calendar.MINUTE, Integer.parseInt(subVariableMatcher.group(2) + subVariableMatcher.group(3)));
break;
default:
}
}
}

try {
if (StringUtil.isNotEmpty(locale)) {
formater = new SimpleDateFormat(variableMatcher.group(2), new Locale(locale.split("-")[0]));
} else {
formater = new SimpleDateFormat(variableMatcher.group(2));
}
stringToDecode = stringToDecode.replace(variableMatcher.group(0), formater.format(cal.getTime()));
} catch (Exception e) {
LOG.error(e, e);
}

} while (variableMatcher.find());

}

return stringToDecode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,32 @@ NOTE: You can also get the nb of rows your variable has by using the `**nbrows**
| %system.**LASTSERVICE_HTTPCODE**% | Http return code of the last service called.
| %system.**LASTSERVICE_CALL**% | Last JSON Service call.
| %system.**LASTSERVICE_RESPONSE**% | Last JSON Service answer.
| %system.**TODAY-yyyy**% | Year of today
| %system.**TODAY-MM**% | Month of today
| %system.**TODAY-dd**% | Day of today
| %system.**TODAY-doy**% | Day of today from the beginning of the year
| %system.**TODAY-HH**% | Hour of today
| %system.**TODAY-mm**% | Minute of today
| %system.**TODAY-ss**% | Second of today
| %system.**YESTERDAY-yyyy**% | Year of yesterday
| %system.**YESTERDAY-MM**% | Month of yesterday
| %system.**YESTERDAY-dd**% | Day of yesterday
| %system.**YESTERDAY-doy**% | Day of yesterday from the beginning of the year
| %system.**YESTERDAY-HH**% | Hour of yesterday
| %system.**YESTERDAY-mm**% | Minute of yesterday
| %system.**YESTERDAY-ss**% | Second of yesterday
| %system.**TOMORROW-yyyy**% | Year of tomorrow
| %system.**TOMORROW-MM**% | Month of tomorrw
| %system.**TOMORROW-dd**% | Day of tomorrw
| %system.**TOMORROW-doy**% | Day of tomorrw from the beginning of the year

|===

==== Date System Variables


%system.**XXXX-YYYY**%


|===

| *Date System Variables* |
| *XXXX* | Any of those key word: TODAY, YESTERDAY, TOMORROW, DAY-n, DAY+n, HOUR-n, HOUR+n, MINUTE-n, MINUTE+n
| *YYYY* | Any of the https://docs.oracle.com/en%2Fjava%2Fjavase%2F11%2Fdocs%2Fapi%2F%2F/java.base/java/text/SimpleDateFormat.html[JAVA Date Patern] such as: *W* (Week in year), *W* (Week in month), *y* (Year), *M* (Month in year), *d* (Day in month), *E* (Day name in week), *H* (Hour in day (0-23)), *m* (Minute in hour), *s* (Second in minute),....

|===

Examples


|===

| %system.**DAY-13-EEEE**% | dimanche (day of week, 13 days ago)
| %system.**MINUTE-3-m**% | 40 (minute of hour, 3 minutes ago)
| %system.**TODAY-dd**% | 11 (day of month, today)


|===

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [ENGINE] New reserved keyword %datalib.DATALIBNAME.value% and %datalib.DATALIBNAME.base64%. Allowing managing upload/download file by uploading files on Cerberus with no more limitation on its size.
* [ENGINE] Added CSV ignoreFirstLine boolean at datalib level.
* [ENGINE] When callService that is attached to an application, host and contextroot of the corresponding application is used (if country env of the application does not exist on the test case application, search is also made on linked environments).
* [ENGINE] New variable for system.dates. You can now for example do %system.DAY-13-d% that will return day of month (d) of 13 days ago. (locale of country invariant is used)
* [GUI] Added service call simulation feature. When editing a service, you can make calls outside a testcase context in order to control and tune the definition of the call.
* [GUI] Improved autocompletion adding boolean, flags and contextual element for select and switchWindow actions.
* [GUI] Improved navigation on campaign execution screen. Adding CTA on top of the screen and toggle buttons for reporting details hidden by default.
Expand All @@ -30,3 +31,4 @@
*Warning to be considered before applying the version (deprecated features)*
[square]
* [ENGINE] Datalib no longuer support direct definition of SOAP Calls. You need to replace them by SOAP services.
* [ENGINE] %SYS_YESTERDAY*, %SYS_TODAY*, %SYS_TOMORROW* are no longuer supported, please change to %system.YESTERDAY*, %system.TODAY*, %system.TOMORROW*
4 changes: 2 additions & 2 deletions source/src/main/webapp/js/global/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function initTags(configs, context) {
datalibPromise = loadDatalib();
}

if (configs.object && !configs.property && context instanceof String){
if (configs.object && !configs.property && context instanceof String) {
objectsPromise = loadApplicationObject(context);
datalibPromise = loadDatalib();
}
Expand Down Expand Up @@ -627,7 +627,7 @@ function initAutocompleteWithTagsNoElement(el, configs, context) {
initTags(configs, context).then(function (tags) {
$(el).each(data => {
// remove array of elements (xpath=, data-cerberus=, etc...) from tags in order not to propose them.
tags.splice(5, 1);
// tags.splice(5, 1);
autocompleteWithTags(el[data], tags);
});
});
Expand Down
6 changes: 3 additions & 3 deletions source/src/main/webapp/js/pages/TestCaseScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,7 @@ Action.prototype.generateContent = function () {
var doc = new Doc();
var row = $("<div></div>").addClass("step-action row").addClass("action");
var content = $("<div></div>").addClass("content col-lg-8");
var firstRow = $("<div style='margin-top:15px;margin-left:0px'></div>").addClass("fieldRow row input-group marginBottom10 col-lg-12");
var firstRow = $("<div style='margin-top:15px;margin-left:0px'></div>").addClass("fieldRow row input-group marginBottom10 col-xs-12 col-lg-12");
var secondRow = $("<div></div>").addClass("fieldRow row secondRow input-group").css("width", "100%");
var thirdRow = $("<div></div>").addClass("fieldRow row thirdRow input-group");

Expand Down Expand Up @@ -3245,8 +3245,8 @@ Control.prototype.generateContent = function () {
var doc = new Doc();
var row = this.html;
var content = $("<div></div>").addClass("content col-lg-8");
var firstRow = $("<div style='margin-top:15px;margin-left:0px'></div>").addClass("fieldRow row input-group marginBottom10 col-lg-12");
var secondRow = $("<div></div>").addClass("fieldRow row secondRow input-group col-lg-12");
var firstRow = $("<div style='margin-top:15px;margin-left:0px'></div>").addClass("fieldRow row input-group marginBottom10 col-xs-12 col-lg-12");
var secondRow = $("<div></div>").addClass("fieldRow row secondRow input-group col-xs-12 col-lg-12");
var thirdRow = $("<div></div>").addClass("fieldRow row thirdRow input-group");

var picture = $("<div></div>").addClass("col-lg-2").css("height", "100%")
Expand Down

0 comments on commit a3c59f1

Please sign in to comment.