ScreenTemplateManager { public List<Input> getInputsForScreen(String screenId, Map<String,Object> contextBindings, ObjectPredicate objectPredicate) { Stream<ScreenInput> stream = screenInputAccessor.getScreenInputsByScreenId(screenId).stream(); if(objectPredicate != null) { stream = stream.filter(objectPredicate); } List<Input> screenInputs = stream.map(i->i.getInput()).collect(Collectors.toList()); List<Input> result = new ArrayList<>(); List<Input> inputs = Activator.findAllMatches(contextBindings, screenInputs, defaultScriptEngine); for(Input input:inputs) { List<Option> options = input.getOptions(); List<Option> activeOptions = null; if(options!=null) { activeOptions = Activator.findAllMatches(contextBindings, options, defaultScriptEngine); } Input clone = new Input(input.getType(), input.getId(), input.getLabel(), input.getDescription(), activeOptions); clone.setValueHtmlTemplate(input.getValueHtmlTemplate()); clone.setSearchMapperService(input.getSearchMapperService()); result.add(clone); } return result; } ScreenTemplateManager(ScreenInputAccessor screenInputAccessor, Configuration configuration); List<Input> getInputsForScreen(String screenId, Map<String,Object> contextBindings, ObjectPredicate objectPredicate); void moveInput(String inputId, int offset); void registerListener(ScreenTemplateChangeListener listener); void notifyChange();  }
@Test public void test() { ScreenInputAccessor a = new ScreenInputAccessor() { @Override public List<ScreenInput> getScreenInputsByScreenId(String screenId) { if(screenId.equals("testScreen1")) { List<ScreenInput> result = new ArrayList<>(); result.add(new ScreenInput("testScreen1", new Input("Param1"))); result.add(new ScreenInput("testScreen1", new Input("Param2", Arrays.asList(new Option[] {new Option("Option1"), new Option("Option2")})))); result.add(new ScreenInput("testScreen1", new Input(InputType.TEXT,"Param3","LabelParam3", Arrays.asList(new Option[] {new Option("Option1"), new Option("Option2"), new Option("Option3","user=='user1'")})))); ScreenInput i = new ScreenInput("testScreen1", new Input(InputType.TEXT,"Param4","LabelParam4", Arrays.asList(new Option[] {new Option("Option1"), new Option("Option2")}))); i.getInput().setActivationExpression(new Expression("user=='user1'")); result.add(i); i = new ScreenInput("testScreen1", new Input("Param5", Arrays.asList(new Option[] {new Option("Option1"), new Option("Option2")}))); i.getInput().setActivationExpression(new Expression("user=='user1'")); result.add(i); return result; } throw new RuntimeException("Unknown screen "+screenId); } @Override public void remove(ObjectId id) { } @Override public ScreenInput save(ScreenInput entity) { return null; } @Override public void save(Collection<? extends ScreenInput> entities) { } @Override public ScreenInput get(ObjectId id) { return null; } @Override public ScreenInput findByAttributes(Map<String, String> attributes) { return null; } @Override public Iterator<ScreenInput> getAll() { return null; } @Override public Spliterator<ScreenInput> findManyByAttributes(Map<String, String> attributes) { return null; } @Override public ScreenInput findByAttributes(Map<String, String> attributes, String attributesMapKey) { return null; } @Override public Spliterator<ScreenInput> findManyByAttributes(Map<String, String> attributes, String attributesMapKey) { return null; } @Override public ScreenInput get(String id) { return get(new ObjectId(id)); } @Override public List<ScreenInput> getRange(int skip, int limit) { return null; } }; ScreenTemplateManager s = new ScreenTemplateManager(a, new Configuration()); List<Input> inputs = s.getInputsForScreen("testScreen1", new HashMap<String, Object>(), newPredicate()); Assert.assertEquals(3, inputs.size()); Assert.assertEquals(inputs.get(0), new Input(InputType.TEXT, "Param1", "Param1",null)); List<Option> options = getDefaultOptionList(); Assert.assertEquals(inputs.get(1), new Input(InputType.DROPDOWN, "Param2", "Param2",options)); Assert.assertEquals(inputs.get(2), new Input(InputType.TEXT, "Param3", "LabelParam3",options)); HashMap<String, Object> ctx = new HashMap<String, Object>(); ctx.put("user", "user1"); inputs = s.getInputsForScreen("testScreen1", ctx, newPredicate()); Assert.assertEquals(5, inputs.size()); Assert.assertEquals(inputs.get(2), new Input(InputType.TEXT, "Param3", "LabelParam3",getOptionListForUser1())); Assert.assertEquals(inputs.get(3), new Input(InputType.TEXT, "Param4", "LabelParam4",options)); Assert.assertEquals(inputs.get(4), new Input(InputType.DROPDOWN, "Param5", "Param5",options)); }