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

OO-1990: return the decoded path if an error happended, better handling of double points in path

parent 155e5771
No related branches found
No related tags found
No related merge requests found
...@@ -368,10 +368,8 @@ public class BusinessControlFactory { ...@@ -368,10 +368,8 @@ public class BusinessControlFactory {
Matcher m = PAT_CE.matcher(businessControlString); Matcher m = PAT_CE.matcher(businessControlString);
while (m.find()) { while (m.find()) {
String ces = m.group(1); String ces = m.group(1);
int pos = ces.indexOf(':'); int pos = ces.lastIndexOf(':');
OLATResourceable ores; OLATResourceable ores;
// FIXME:chg: 'path=' define only once, same path in SearchResourceContext
if(pos == -1) { if(pos == -1) {
if(ces.startsWith("path=")) { if(ces.startsWith("path=")) {
ces = ces.replace("|", "/"); ces = ces.replace("|", "/");
...@@ -388,7 +386,7 @@ public class BusinessControlFactory { ...@@ -388,7 +386,7 @@ public class BusinessControlFactory {
ores = OresHelper.createOLATResourceableInstanceWithoutCheck(type, key); ores = OresHelper.createOLATResourceableInstanceWithoutCheck(type, key);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
log.warn("Cannot parse business path:" + businessControlString, e); log.warn("Cannot parse business path:" + businessControlString, e);
return Collections.emptyList(); return entries;//return what we decoded
} }
} }
ContextEntry ce = createContextEntry(ores); ContextEntry ce = createContextEntry(ores);
......
...@@ -19,11 +19,9 @@ ...@@ -19,11 +19,9 @@
*/ */
package org.olat.core.id.context; package org.olat.core.id.context;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.olat.core.id.OLATResourceable; import org.olat.core.id.OLATResourceable;
...@@ -40,29 +38,66 @@ import org.olat.core.id.OLATResourceable; ...@@ -40,29 +38,66 @@ import org.olat.core.id.OLATResourceable;
public class BusinessControlFactoryTest { public class BusinessControlFactoryTest {
@Test @Test
public void testPathResource() { public void businessPath() {
String businessPath = "[QPool:0][QItemCollection:340819968][QuestionItem:294649898]";
List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
Assert.assertNotNull(entries);
Assert.assertEquals(3, entries.size());
Assert.assertNotNull(entries.get(0).getOLATResourceable());
Assert.assertNotNull(entries.get(1).getOLATResourceable());
Assert.assertNotNull(entries.get(2).getOLATResourceable());
Assert.assertEquals(new Long(0l), entries.get(0).getOLATResourceable().getResourceableId());
Assert.assertEquals("QPool", entries.get(0).getOLATResourceable().getResourceableTypeName());
Assert.assertEquals(new Long(340819968l), entries.get(1).getOLATResourceable().getResourceableId());
Assert.assertEquals("QItemCollection", entries.get(1).getOLATResourceable().getResourceableTypeName());
Assert.assertEquals(new Long(294649898l), entries.get(2).getOLATResourceable().getResourceableId());
Assert.assertEquals("QuestionItem", entries.get(2).getOLATResourceable().getResourceableTypeName());
}
@Test
public void pathResource() {
String businessPath = "[path=/Pflanzenschutz/Gesetzliches:0]"; String businessPath = "[path=/Pflanzenschutz/Gesetzliches:0]";
List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath); List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
assertNotNull(entries); Assert.assertNotNull(entries);
assertEquals(1, entries.size()); Assert.assertEquals(1, entries.size());
assertNotNull(entries.get(0).getOLATResourceable()); Assert.assertNotNull(entries.get(0).getOLATResourceable());
OLATResourceable ores = entries.get(0).getOLATResourceable(); OLATResourceable ores = entries.get(0).getOLATResourceable();
assertEquals(new Long(0), ores.getResourceableId()); Assert.assertEquals(new Long(0), ores.getResourceableId());
assertEquals("path=/Pflanzenschutz/Gesetzliches", ores.getResourceableTypeName()); Assert.assertEquals("path=/Pflanzenschutz/Gesetzliches", ores.getResourceableTypeName());
} }
@Test @Test
public void testPathResourceWrongButAutomaticallyHealed() { public void pathResourceWrongButAutomaticallyHealed() {
String businessPath = "[path=/Pflanzenschutz/Gesetzliches]"; String businessPath = "[path=/Pflanzenschutz/Gesetzliches]";
List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath); List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
assertNotNull(entries); Assert.assertNotNull(entries);
assertEquals(1, entries.size()); Assert.assertEquals(1, entries.size());
assertNotNull(entries.get(0).getOLATResourceable()); Assert.assertNotNull(entries.get(0).getOLATResourceable());
OLATResourceable ores = entries.get(0).getOLATResourceable(); OLATResourceable ores = entries.get(0).getOLATResourceable();
assertEquals(new Long(0), ores.getResourceableId()); Assert.assertEquals(new Long(0), ores.getResourceableId());
assertEquals("path=/Pflanzenschutz/Gesetzliches", ores.getResourceableTypeName()); Assert.assertEquals("path=/Pflanzenschutz/Gesetzliches", ores.getResourceableTypeName());
}
@Test
public void pathWithDoublePoints() {
String businessPath = "[RepositoryEntry:408649729][CourseNode:93480746431333][path=/Dru34567/Test: double point:0]";
List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
Assert.assertNotNull(entries);
Assert.assertEquals(3, entries.size());
Assert.assertNotNull(entries.get(0).getOLATResourceable());
Assert.assertNotNull(entries.get(1).getOLATResourceable());
Assert.assertNotNull(entries.get(2).getOLATResourceable());
//check every value
Assert.assertEquals("RepositoryEntry", entries.get(0).getOLATResourceable().getResourceableTypeName());
Assert.assertEquals(new Long(408649729l), entries.get(0).getOLATResourceable().getResourceableId());
Assert.assertEquals("CourseNode", entries.get(1).getOLATResourceable().getResourceableTypeName());
Assert.assertEquals(new Long(93480746431333l), entries.get(1).getOLATResourceable().getResourceableId());
Assert.assertEquals("path=/Dru34567/Test: double point", entries.get(2).getOLATResourceable().getResourceableTypeName());
Assert.assertEquals(new Long(0l), entries.get(2).getOLATResourceable().getResourceableId());
} }
} }
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