[skip ci] options in test page

This commit is contained in:
alandavis
2022-08-06 14:25:35 +01:00
parent 9838d5cc44
commit 29b053eaa1
11 changed files with 367 additions and 201 deletions

View File

@@ -26,8 +26,8 @@
*/
package org.alfresco.transform.base;
import org.alfresco.transform.base.html.OptionLister;
import org.alfresco.transform.base.logging.LogEntry;
import org.alfresco.transform.base.probes.ProbeTransform;
import org.alfresco.transform.base.transform.TransformHandler;
import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest;
@@ -102,6 +102,8 @@ public class TransformController
@Autowired TransformHandler transformHandler;
@Autowired
private String coreVersion;
@Autowired
private OptionLister optionLister;
TransformEngine transformEngine;
@@ -149,6 +151,9 @@ public class TransformController
public String test(Model model)
{
model.addAttribute("title", transformEngine.getTransformEngineName() + " Test Page");
TransformConfig transformConfig = ((TransformRegistry) transformRegistry).getTransformConfig();
transformConfig = setOrClearCoreVersion(transformConfig, 0);
model.addAttribute("transformOptions", optionLister.getOptionNames(transformConfig.getTransformOptions()));
return "test"; // display test.html
}

View File

@@ -0,0 +1,71 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2022 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.transform.base.html;
import org.alfresco.transform.config.TransformOption;
import org.alfresco.transform.config.TransformOptionGroup;
import org.alfresco.transform.config.TransformOptionValue;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@Component
public class OptionLister
{
public Set<String> getOptionNames(Map<String, Set<TransformOption>> transformOptionsByName)
{
Set<String> set = new TreeSet<>();
transformOptionsByName.forEach(((optionName, optionSet) -> {
optionSet.stream().forEach(option -> addToList(set, option));
}));
return set;
}
private void addToList(Set<String> set, TransformOption option)
{
if (option instanceof TransformOptionGroup)
{
addGroupToList(set, (TransformOptionGroup)option);
}
else
{
addValueToList(set, (TransformOptionValue)option);
}
}
private void addGroupToList(Set<String> set, TransformOptionGroup group)
{
group.getTransformOptions().stream().forEach(option -> addToList(set, option));
}
private void addValueToList(Set<String> set, TransformOptionValue value)
{
set.add(value.getName());
}
}

View File

@@ -111,9 +111,8 @@ public abstract class StreamHandler
{
inputStream.close();
}
catch (IOException e)
catch (IOException ignore)
{
throw new RuntimeException(e);
}
}
}

View File

@@ -5,7 +5,7 @@
<form method="POST" enctype="multipart/form-data" action="/test">
<table>
<tr><td><div style="text-align:right">file</div></td><td><input type="file" name="file" /></td></tr>
<tr><td><div style="text-align:right">Direct Url</div></td><td><input type="text" name="directAccessUrl"/></td></tr>
<tr><td><div style="text-align:right">directAccessUrl</div></td><td><input type="text" name="directAccessUrl"/></td></tr>
<tr><td><div style="text-align:right">sourceMimetype</div></td><td><input type="text" name="sourceMimetype" value="" /></td>
<td><select name="_sourceMimetype">
<option value="" >-- file extension --</option>
@@ -28,166 +28,20 @@
<option value="text/html">html</option>
<option value="text/plain">txt</option>
</select></td></tr>
<tr><td><select name="name0">
<option value="sourceEncoding" >sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value0" /></td></tr>
<tr><td><select name="name1">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth" selected="selected">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value1" value="" /></td></tr>
<tr><td><select name="name2">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight" selected="selected">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value2" value="" /></td></tr>
<tr><td><select name="name3">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail" selected="selected">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value3" value="" /></td></tr>
<tr><td><select name="name4">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value4" value="" /></td></tr>
<tr><td><input type="text" name="name5" value="" /></td><td><input type="text" name="value5" value="" /></td></tr>
<tr><td><input type="text" name="name6" value="" /></td><td><input type="text" name="value6" value="" /></td></tr>
<tr><td><input type="text" name="name7" value="" /></td><td><input type="text" name="value7" value="" /></td></tr>
<tr><td><input type="text" name="name8" value="" /></td><td><input type="text" name="value8" value="" /></td></tr>
<tr><td><input type="text" name="name9" value="" /></td><td><input type="text" name="value9" value="" /></td></tr>
<tr><td><input type="text" name="name10" value="" /></td><td><input type="text" name="value10" value="" /></td></tr>
<tr><td><input type="text" name="name11" value="" /></td><td><input type="text" name="value11" value="" /></td></tr>
<tr><td><input type="text" name="name12" value="" /></td><td><input type="text" name="value12" value="" /></td></tr>
<tr><td><input type="text" name="name13" value="" /></td><td><input type="text" name="value13" value="" /></td></tr>
<tr><td><input type="text" name="name14" value="" /></td><td><input type="text" name="value14" value="" /></td></tr>
<th:block th:each="i: ${#numbers.sequence(0, T(java.lang.Math).min(18, transformOptions.size) - 1)}">
<tr><td><select th:name="${'name'+i}">
<option th:each="transformOption, iStat: ${transformOptions}"
th:value="${transformOption}" th:text="${transformOption}"
th:selected="${iStat.index eq i}"/>
</select></td><td><input type="text" th:name="${'value'+i}" /></td></tr>
</th:block>
<th:block th:each="i: ${#numbers.sequence(T(java.lang.Math).min(18, transformOptions.size), T(java.lang.Math).min(18, transformOptions.size) + 2)}">
<tr><td><input type="text" th:name="${'name'+i}" value="" /></td>
<td><input type="text" th:name="${'value'+i}" value="" /></td></tr>
</th:block>
<tr><td><div style="text-align:right">timeout</div></td><td><input type="text" name="timeout" value="" /></td></tr>
<tr><td></td><td><input type="submit" value="Transform" /></td></tr>
</table>

View File

@@ -0,0 +1,189 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2022 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.transform.base.http;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.alfresco.transform.base.html.OptionLister;
import org.alfresco.transform.config.TransformOption;
import org.alfresco.transform.config.TransformOptionGroup;
import org.alfresco.transform.config.TransformOptionValue;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Used in the html test page.
*/
public class OptionListerTest
{
OptionLister optionLister = new OptionLister();
@Test
public void emptyListTest()
{
Map<String, Set<TransformOption>> transformOptionsByName = Collections.emptyMap();
assertEquals(Collections.emptySet(), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void singleOptionNameWithSingleValue()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("Dummy", ImmutableSet.of(
new TransformOptionValue(true, "startPage")));
assertEquals(ImmutableSet.of("startPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void whenOptionNameEndsInOptions_stripIt()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(true, "startPage")));
assertEquals(ImmutableSet.of("startPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void singleOptionNameWithASingleRequiredValue()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(true, "startPage")));
assertEquals(ImmutableSet.of("startPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void singleOptionNameWithACoupleOfValues()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "startPage"),
new TransformOptionValue(true, "endPage")));
assertEquals(ImmutableSet.of("startPage", "endPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void sortedValues()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "a"),
new TransformOptionValue(false, "n"),
new TransformOptionValue(false, "k"),
new TransformOptionValue(false, "f"),
new TransformOptionValue(true, "z")));
assertEquals(ImmutableList.of("a", "f", "k", "n", "z"), new ArrayList<>(optionLister.getOptionNames(transformOptionsByName)));
}
@Test
public void multipleOptionNames()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "startPage"),
new TransformOptionValue(true, "endPage")),
"Another", ImmutableSet.of(
new TransformOptionValue(false, "scale")),
"YetAnother", ImmutableSet.of(
new TransformOptionValue(false, "x"),
new TransformOptionValue(false, "y"),
new TransformOptionValue(true, "ratio"))
);
assertEquals(ImmutableSet.of(
"startPage",
"endPage",
"scale",
"x",
"y",
"ratio"),
optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void multipleOptionNamesWithDuplicates()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "startPage"),
new TransformOptionValue(true, "endPage")),
"Another", ImmutableSet.of(
new TransformOptionValue(false, "scale")),
"YetAnother", ImmutableSet.of(
new TransformOptionValue(false, "x"),
new TransformOptionValue(false, "y"),
new TransformOptionValue(true, "scale"))
);
assertEquals(ImmutableSet.of(
"startPage",
"endPage",
"scale",
"x",
"y"),
optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void nestedGroups()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "1"),
new TransformOptionValue(true, "2"),
new TransformOptionGroup(false, ImmutableSet.of(
new TransformOptionValue(false, "3.1"),
new TransformOptionValue(true, "3.2"),
new TransformOptionValue(false, "3.3"))),
new TransformOptionGroup(true, ImmutableSet.of(
new TransformOptionValue(false, "4.1"),
new TransformOptionGroup(false, ImmutableSet.of(
new TransformOptionValue(false, "4.2.1"),
new TransformOptionGroup(true, ImmutableSet.of(
new TransformOptionValue(false, "4.2.2.1"))),
new TransformOptionValue(true, "4.2.3"))),
new TransformOptionValue(false, "4.3")))));
assertEquals(ImmutableSet.of(
"1",
"2",
"3.1",
"3.2",
"3.3",
"4.1",
"4.2.1",
"4.2.2.1",
"4.2.3",
"4.3"),
optionLister.getOptionNames(transformOptionsByName));
}
}