private List<String> resourceScopes = Lists.newArrayList();
private List<String> resourceQualifiers = Lists.newArrayList();
private List<String> resourceLanguages = Lists.newArrayList();
+ private String resourceKeyRegexp;
private String resourceName;
private Date fromDate = null, toDate = null;
private boolean userFavourites = false;
return this;
}
+ public String getResourceKeyRegexp() {
+ return resourceKeyRegexp;
+ }
+
+ public MeasureFilter setResourceKeyRegexp(String s) {
+ this.resourceKeyRegexp = s;
+ return this;
+ }
+
public MeasureFilter addCondition(MeasureFilterCondition condition) {
this.measureConditions.add(condition);
return this;
filter.setResourceQualifiers((List<String>) map.get("qualifiers"));
filter.setResourceLanguages((List<String>) map.get("languages"));
filter.setResourceName((String) map.get("name"));
+ filter.setResourceKeyRegexp((String) map.get("keyRegexp"));
if (map.containsKey("fromDate")) {
filter.setFromDate(toDate(map, "fromDate"));
if (isValid(filter, context)) {
MeasureFilterSql sql = new MeasureFilterSql(database, filter, context);
context.setSql(sql.sql());
+ System.out.println(sql.sql());
Connection connection = session.getConnection();
rows = sql.execute(connection);
} else {
}
sql.append(") ");
}
+ if (StringUtils.isNotBlank(filter.getResourceKeyRegexp())) {
+ sql.append(" AND UPPER(p.kee) LIKE '");
+ // limitation : special characters _ and % are not escaped
+ String regexp = StringEscapeUtils.escapeSql(filter.getResourceKeyRegexp());
+ regexp = StringUtils.replaceChars(regexp, '*', '%');
+ regexp = StringUtils.replaceChars(regexp, '?', '_');
+ sql.append(StringUtils.upperCase(regexp)).append("'");
+ }
SnapshotDto baseSnapshot = context.getBaseSnapshot();
if (baseSnapshot != null) {
if (filter.isOnBaseResourceChildren()) {
@Test
public void should_decode() throws ParseException {
String json = "{\"base\": \"org.struts\", \"onBaseChildren\": true, \"scopes\": [\"PRJ\"], " +
- "\"qualifiers\": [\"TRK\",\"CLA\"], " +
+ "\"qualifiers\": [\"TRK\",\"CLA\"], \"keyRegexp\": \"*foo*\"" +
"\"languages\": [\"java\", \"php\"], \"name\": \"Struts\", \"fromDate\": \"2012-12-25\", " +
"\"toDate\": \"2013-01-31\", " +
"\"favourites\": true, " +
assertThat(filter.getResourceQualifiers()).containsExactly("TRK", "CLA");
assertThat(filter.getResourceLanguages()).containsExactly("java", "php");
assertThat(filter.getResourceName()).isEqualTo("Struts");
+ assertThat(filter.getResourceKeyRegexp()).isEqualTo("*foo*");
assertThat(filter.getFromDate().getYear()).isEqualTo(2012 - 1900);
assertThat(filter.getToDate().getYear()).isEqualTo(2013 - 1900);
assertThat(filter.isOnFavourites()).isTrue();
assertThat(filter.getResourceQualifiers()).isEmpty();
assertThat(filter.getResourceLanguages()).isEmpty();
assertThat(filter.getResourceName()).isNull();
+ assertThat(filter.getResourceKeyRegexp()).isNull();
assertThat(filter.getFromDate()).isNull();
assertThat(filter.getToDate()).isNull();
assertThat(filter.isOnFavourites()).isFalse();
verifyPhpProject(rows.get(0));
}
+ @Test
+ public void filter_by_resource_key_star_regexp() throws SQLException {
+ MeasureFilter filter = new MeasureFilter().setResourceQualifiers("TRK").setResourceKeyRegexp("java*");
+ List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+
+ assertThat(rows).hasSize(1);
+ verifyJavaProject(rows.get(0));
+ }
+
+ @Test
+ public void filter_by_resource_key_exclamation_mark() throws SQLException {
+ MeasureFilter filter = new MeasureFilter().setResourceQualifiers("TRK").setResourceKeyRegexp("JaV?_proje*");
+ List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+ assertThat(rows).hasSize(1);
+ verifyJavaProject(rows.get(0));
+ }
+
@Test
public void filter_by_base_resource() throws SQLException {
MeasureFilter filter = new MeasureFilter().setResourceQualifiers("CLA").setBaseResourceKey("java_project");
key_criterion=filter.criterion('key')
if key_criterion
- #java_filter.setKeyRegexp(key_criterion.text_value)
+ filter_json[:keyRegexp]=name_criterion.text_value
end
name_criterion=filter.criterion('name')