Commit 30e71336 authored by anthony's avatar anthony Committed by julienmege

fix(page import) import all widgets except pb*

change the way ustom widgets are identified at page import
- import all widget except the ones starting with pb
(widgets created outside the UI designer may not be named custom*)

Covers [BS-18256](https://bonitasoft.atlassian.net/browse/BS-18256)
parent 269cea10
......@@ -147,12 +147,26 @@ public abstract class AbstractLoader<T extends Identifiable> implements Loader<T
protected List<T> loadAll(Path directory, String glob) throws IOException {
List<T> objects = new ArrayList<>();
try (DirectoryStream<Path> directoryStream = newDirectoryStream(directory, glob)) {
for (Path path : directoryStream) {
String id = getComponentId(path);
objects.add(load(resolve(directory, id)));
}
objects = loadAll(directory, directoryStream);
}
return objects;
}
protected List<T> loadAll(Path directory, DirectoryStream.Filter<Path> filter) throws IOException {
List<T> objects = new ArrayList<>();
try (DirectoryStream<Path> directoryStream = newDirectoryStream(directory, filter)) {
objects = loadAll(directory, directoryStream);
}
return objects;
}
private List<T> loadAll(Path directory, DirectoryStream<Path> directoryStream) {
List<T> objects = new ArrayList<>();
for (Path path : directoryStream) {
String id = getComponentId(path);
objects.add(load(resolve(directory, id)));
}
return objects;
}
......
......@@ -15,6 +15,7 @@
package org.bonitasoft.web.designer.repository;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
......@@ -51,7 +52,12 @@ public class WidgetLoader extends AbstractLoader<Widget>{
}
public List<Widget> loadAllCustom(Path widgetsFolder) throws IOException {
return loadAll(widgetsFolder, "custom*");
return loadAll(widgetsFolder, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path path) throws IOException {
return !path.getFileName().toString().startsWith("pb");
}
});
}
@Override
......
......@@ -92,7 +92,7 @@ public class WidgetLoaderTest {
@Test
public void should_retrieve_all_custom_widgets() throws Exception {
Widget input = aWidget().id("input").build();
Widget input = aWidget().id("pbInput").build();
Widget custom1 = aWidget().id("custom1").custom().build();
Widget custom2 = aWidget().id("custom2").custom().build();
addToDirectory(widgetDirectory, input, custom1, custom2);
......
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