Commit cabbacc0 authored by Bert Leunis's avatar Bert Leunis

HSTTWO-4247 prepend the pickerInitialPath with the root path to make it always absolute

I removed the second component and component interface test class. It was not needed: the different configurations for pickers per field must be available for tests. They can be in the same class.
parent 266d7bae
......@@ -283,10 +283,11 @@ public class HstManageContentTag extends TagSupport {
}
if (jcrPath != null) {
final String pickerRootPath = getFirstNonBlankString(absoluteRootPath, jcrPath.pickerRootPath(), getChannelRootPath());
writeToMap(result, "pickerConfiguration", jcrPath.pickerConfiguration());
writeToMap(result, "pickerInitialPath", jcrPath.pickerInitialPath());
writeToMap(result, "pickerInitialPath", getPickerInitialPath(jcrPath.pickerInitialPath(), pickerRootPath));
writeToMap(result, "pickerRemembersLastVisited", Boolean.toString(jcrPath.pickerRemembersLastVisited()));
writeToMap(result, "pickerRootPath", getFirstNonBlankString(absoluteRootPath, jcrPath.pickerRootPath(), getChannelRootPath()));
writeToMap(result, "pickerRootPath", pickerRootPath);
final String nodeTypes = Arrays.stream(jcrPath.pickerSelectableNodeTypes()).collect(Collectors.joining(","));
writeToMap(result, "pickerSelectableNodeTypes", nodeTypes);
......@@ -311,6 +312,14 @@ public class HstManageContentTag extends TagSupport {
return Arrays.stream(strings).filter(StringUtils::isNotBlank).findFirst().orElse(null);
}
private String getPickerInitialPath(final String pickerInitialPath, final String prependRootPath) {
if ("".equals(pickerInitialPath) || pickerInitialPath.startsWith("/")) {
return pickerInitialPath;
} else {
return prependRootPath + (prependRootPath.endsWith("/") ? "" : "/") + pickerInitialPath;
}
}
/*
* when a currentNode is of type hippo:handle, we return this node, else we check the parent, until we are at the jcr root node.
* When we hit the jcr root node, we return null;
......
......@@ -691,8 +691,7 @@ public class HstManageContentTagTest {
@Test
public void supplyChannelContentRootAsDefaultPickerRootPath() throws Exception {
tag.setParameterName("docPathParameter");
window.setComponent(new TestComponentWithoutPickerRootPath());
tag.setParameterName("absPath");
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
......@@ -706,7 +705,7 @@ public class HstManageContentTagTest {
assertThat(response.getContentAsString(), is("<!-- {"
+ "\"HST-Type\":\"MANAGE_CONTENT_LINK\","
+ "\"parameterName\":\"docPathParameter\","
+ "\"parameterName\":\"absPath\","
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\","
......@@ -716,8 +715,7 @@ public class HstManageContentTagTest {
@Test
public void supplyChannelContentRootAsDefaultPickerRootPathAndPickerInitialPath() throws Exception {
tag.setParameterName("pickerPath");
window.setComponent(new TestComponentWithoutPickerRootPath());
tag.setParameterName("pickerNoRootPath");
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
......@@ -731,13 +729,37 @@ public class HstManageContentTagTest {
assertThat(response.getContentAsString(), is("<!-- {"
+ "\"HST-Type\":\"MANAGE_CONTENT_LINK\","
+ "\"parameterName\":\"pickerPath\","
+ "\"parameterValueIsRelativePath\":\"true\","
+ "\"pickerConfiguration\":\"picker-config\","
+ "\"parameterName\":\"pickerNoRootPath\","
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerInitialPath\":\"/my/channel/path/initial-path\","
+ "\"pickerRemembersLastVisited\":\"false\","
+ "\"pickerRootPath\":\"/my/channel/path\","
+ "\"pickerSelectableNodeTypes\":\"node-type-1,node-type-2\""
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path\""
+ "} -->"));
}
@Test
public void supplyChannelContentRootAsDefaultPickerRootPathAndAbsolutePickerInitialPath() throws Exception {
tag.setParameterName("pickerAbsoluteInitialPath");
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
assertThat(response.getContentAsString(), is("<!-- {"
+ "\"HST-Type\":\"MANAGE_CONTENT_LINK\","
+ "\"parameterName\":\"pickerAbsoluteInitialPath\","
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerInitialPath\":\"/initial-path\","
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path\""
+ "} -->"));
}
......@@ -785,33 +807,17 @@ public class HstManageContentTagTest {
)
String getPickerPath();
@Parameter(name = "string")
String getString();
}
@ParametersInfo(type = TestComponentInfoWithoutPickerRootPath.class)
public class TestComponentWithoutPickerRootPath extends GenericHstComponent {
}
private interface TestComponentInfoWithoutPickerRootPath {
@Parameter(name = "docPathParameter")
@JcrPath
String getAbsPath();
@Parameter(name = "relPath")
@JcrPath(isRelative = true)
String getRelPath();
@Parameter(name = "pickerNoRootPath")
@JcrPath(
pickerInitialPath = "initial-path"
)
String getPickerNoRootPath();
@Parameter(name = "pickerPath")
@Parameter(name = "pickerAbsoluteInitialPath")
@JcrPath(
isRelative = true,
pickerInitialPath = "initial-path",
pickerConfiguration = "picker-config",
pickerRemembersLastVisited = false,
pickerSelectableNodeTypes = {"node-type-1", "node-type-2"}
pickerInitialPath = "/initial-path"
)
String getPickerPath();
String getPickerAbsoluteInitialPath();
@Parameter(name = "string")
String getString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment