Skip to content
Snippets Groups Projects
Commit 15a93c7d authored by srosse's avatar srosse
Browse files

Merge OpenOLAT 9.3 to OpenOLAT default branch with 472bb3b6db6a20577f91f82bb41f6efc30f4f646

parents bc89a7c2 77978dfd
No related branches found
No related tags found
No related merge requests found
...@@ -244,7 +244,7 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController { ...@@ -244,7 +244,7 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController {
public void event(UserRequest ureq, Component source, Event event) { public void event(UserRequest ureq, Component source, Event event) {
if (source == backLink) { if (source == backLink) {
flc.contextPut("showButton","false"); flc.contextPut("showButton","false");
} else if(source == autoCompleterContainer.getComponent()) { } else if(autoCompleterContainer != null && source == autoCompleterContainer.getComponent()) {
if (event.getCommand().equals(COMMAND_SELECT)) { if (event.getCommand().equals(COMMAND_SELECT)) {
doSelect(ureq); doSelect(ureq);
} }
...@@ -253,9 +253,6 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController { ...@@ -253,9 +253,6 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController {
} }
} }
/**
*
*/
@Override @Override
protected void doFireSelection(UserRequest ureq, List<String> res) { protected void doFireSelection(UserRequest ureq, List<String> res) {
// if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty // if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty
......
...@@ -68,6 +68,8 @@ public class StringHelper { ...@@ -68,6 +68,8 @@ public class StringHelper {
private static final String WHITESPACE_REGEXP = "^\\s*$"; private static final String WHITESPACE_REGEXP = "^\\s*$";
private static final Pattern WHITESPACE_PATTERN = Pattern.compile(WHITESPACE_REGEXP); private static final Pattern WHITESPACE_PATTERN = Pattern.compile(WHITESPACE_REGEXP);
private static final int LONG_MAX_LENGTH = Long.toString(Long.MAX_VALUE).length();
/** /**
* regex for not allowing * regex for not allowing
* <code>;,:</code> <code>ALL_WITHOUT_COMMA_2POINT_STRPNT</code> * <code>;,:</code> <code>ALL_WITHOUT_COMMA_2POINT_STRPNT</code>
...@@ -384,11 +386,21 @@ public class StringHelper { ...@@ -384,11 +386,21 @@ public class StringHelper {
return FileUtils.normalizeFilename(s); return FileUtils.normalizeFilename(s);
} }
/**
* The method do only a precheck if the string can be a number. It's goal
* is to prevent to generate hunderds of exceptions in a loop by using
* the Long.parseLong() method (exceptions is time and CPU intensive).
*
* return True if the string can be a digit (there is not boundaries check)
*/
public static boolean isLong(String string) { public static boolean isLong(String string) {
if(string == null || string.length() == 0) { if(string == null || string.length() == 0) {
return false; return false;
} }
int stop = string.startsWith("-") ? 1 : 0; int stop = string.startsWith("-") ? 1 : 0;
if(string.length() > LONG_MAX_LENGTH + stop) {
return false;
}
char[] charArr = string.toCharArray(); char[] charArr = string.toCharArray();
for(int i=charArr.length; i-->stop; ) { for(int i=charArr.length; i-->stop; ) {
char ch = charArr[i]; char ch = charArr[i];
......
...@@ -172,8 +172,12 @@ public class PersistingCourseGroupManager extends BasicManager implements Course ...@@ -172,8 +172,12 @@ public class PersistingCourseGroupManager extends BasicManager implements Course
public boolean existGroup(String nameOrKey) { public boolean existGroup(String nameOrKey) {
SearchBusinessGroupParams params = new SearchBusinessGroupParams(); SearchBusinessGroupParams params = new SearchBusinessGroupParams();
if(StringHelper.isLong(nameOrKey)) { if(StringHelper.isLong(nameOrKey)) {
params.setGroupKeys(Collections.singletonList(new Long(nameOrKey))); try {
}else { params.setGroupKeys(Collections.singletonList(new Long(nameOrKey)));
} catch (NumberFormatException e) {
params.setExactName(nameOrKey);
}
} else {
params.setExactName(nameOrKey); params.setExactName(nameOrKey);
} }
return businessGroupService.countBusinessGroups(params, courseResource) > 0; return businessGroupService.countBusinessGroups(params, courseResource) > 0;
......
...@@ -108,4 +108,16 @@ public class StringHelperTest { ...@@ -108,4 +108,16 @@ public class StringHelperTest {
String value12 = StringHelper.cleanUTF8ForXml("Hello\u10B7x pahlavi"); String value12 = StringHelper.cleanUTF8ForXml("Hello\u10B7x pahlavi");
Assert.assertEquals("Pahlavi test", "Hello\u10B7x pahlavi", value12); Assert.assertEquals("Pahlavi test", "Hello\u10B7x pahlavi", value12);
} }
@Test
public void isLong() {
Assert.assertTrue(StringHelper.isLong("234"));
Assert.assertTrue(StringHelper.isLong("9223372036854775807"));
Assert.assertTrue(StringHelper.isLong("-9223372036854775807"));
Assert.assertFalse(StringHelper.isLong("10223372036854775807"));
Assert.assertFalse(StringHelper.isLong("-dru"));
Assert.assertFalse(StringHelper.isLong("OpenOLAT"));
Assert.assertFalse(StringHelper.isLong("A very long number with a lot of characters"));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment