@Test public void executeWhenInsideDashboardMacro() throws Exception { BeanManager beanManager = this.mocker.getInstance(BeanManager.class); BeanDescriptor descriptor = mock(BeanDescriptor.class); when(beanManager.getBeanDescriptor(any())).thenReturn(descriptor); when(descriptor.getProperties()).thenReturn(Collections.emptyList()); Execution execution = this.mocker.getInstance(Execution.class); ExecutionContext ec = new ExecutionContext(); when(execution.getContext()).thenReturn(ec); ec.setProperty("dashboardMacroCalls", 1); DashboardMacroParameters parameters = new DashboardMacroParameters(); MacroTransformationContext macroContext = new MacroTransformationContext(); try { this.mocker.getComponentUnderTest().execute(parameters, "", macroContext); fail("Exception should have been raised here"); } catch (MacroExecutionException expected) { assertEquals("Dashboard macro recursion detected. Don't call the Dashboard macro inside of itself...", expected.getMessage()); } }
@Override public List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { preventDashboardRecursion(); List<Gadget> gadgets; try { gadgets = this.gadgetSource.getGadgets(parameters.getSource(), context); } catch (Exception e) { String message = "Could not get the gadgets."; this.logger.error(message, e); throw new MacroExecutionException(message, e); } boolean isInEditMode = this.gadgetSource.isEditing(); DashboardRenderer renderer = getDashboardRenderer(StringUtils.isEmpty(parameters.getLayout()) ? "columns" : parameters.getLayout()); if (renderer == null) { String message = "Could not find dashboard renderer " + parameters.getLayout(); this.logger.error(message); throw new MacroExecutionException(message); } GadgetRenderer gadgetRenderer = getGadgetRenderer(isInEditMode); List<Block> layoutedResult; try { layoutedResult = renderer.renderGadgets(gadgets, gadgetRenderer, context); } catch (Exception e) { String message = "Could not render the gadgets for layout " + parameters.getLayout(); this.logger.error(message, e); throw new MacroExecutionException(message, e); } this.includeResources(isInEditMode); GroupBlock topLevel = new GroupBlock(); if (isInEditMode) { topLevel.addChildren(this.gadgetSource.getDashboardSourceMetadata(parameters.getSource(), context)); } topLevel.addChildren(layoutedResult); topLevel.setParameter("class", MACRO_NAME + (StringUtils.isEmpty(parameters.getStyle()) ? "" : " " + parameters.getStyle())); reduceDashboardRecursionCounter(); return Collections.<Block> singletonList(topLevel); }
DashboardMacro extends AbstractMacro<DashboardMacroParameters> implements NestedScriptMacroEnabled { @Override public List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { preventDashboardRecursion(); List<Gadget> gadgets; try { gadgets = this.gadgetSource.getGadgets(parameters.getSource(), context); } catch (Exception e) { String message = "Could not get the gadgets."; this.logger.error(message, e); throw new MacroExecutionException(message, e); } boolean isInEditMode = this.gadgetSource.isEditing(); DashboardRenderer renderer = getDashboardRenderer(StringUtils.isEmpty(parameters.getLayout()) ? "columns" : parameters.getLayout()); if (renderer == null) { String message = "Could not find dashboard renderer " + parameters.getLayout(); this.logger.error(message); throw new MacroExecutionException(message); } GadgetRenderer gadgetRenderer = getGadgetRenderer(isInEditMode); List<Block> layoutedResult; try { layoutedResult = renderer.renderGadgets(gadgets, gadgetRenderer, context); } catch (Exception e) { String message = "Could not render the gadgets for layout " + parameters.getLayout(); this.logger.error(message, e); throw new MacroExecutionException(message, e); } this.includeResources(isInEditMode); GroupBlock topLevel = new GroupBlock(); if (isInEditMode) { topLevel.addChildren(this.gadgetSource.getDashboardSourceMetadata(parameters.getSource(), context)); } topLevel.addChildren(layoutedResult); topLevel.setParameter("class", MACRO_NAME + (StringUtils.isEmpty(parameters.getStyle()) ? "" : " " + parameters.getStyle())); reduceDashboardRecursionCounter(); return Collections.<Block> singletonList(topLevel); } }
DashboardMacro extends AbstractMacro<DashboardMacroParameters> implements NestedScriptMacroEnabled { @Override public List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { preventDashboardRecursion(); List<Gadget> gadgets; try { gadgets = this.gadgetSource.getGadgets(parameters.getSource(), context); } catch (Exception e) { String message = "Could not get the gadgets."; this.logger.error(message, e); throw new MacroExecutionException(message, e); } boolean isInEditMode = this.gadgetSource.isEditing(); DashboardRenderer renderer = getDashboardRenderer(StringUtils.isEmpty(parameters.getLayout()) ? "columns" : parameters.getLayout()); if (renderer == null) { String message = "Could not find dashboard renderer " + parameters.getLayout(); this.logger.error(message); throw new MacroExecutionException(message); } GadgetRenderer gadgetRenderer = getGadgetRenderer(isInEditMode); List<Block> layoutedResult; try { layoutedResult = renderer.renderGadgets(gadgets, gadgetRenderer, context); } catch (Exception e) { String message = "Could not render the gadgets for layout " + parameters.getLayout(); this.logger.error(message, e); throw new MacroExecutionException(message, e); } this.includeResources(isInEditMode); GroupBlock topLevel = new GroupBlock(); if (isInEditMode) { topLevel.addChildren(this.gadgetSource.getDashboardSourceMetadata(parameters.getSource(), context)); } topLevel.addChildren(layoutedResult); topLevel.setParameter("class", MACRO_NAME + (StringUtils.isEmpty(parameters.getStyle()) ? "" : " " + parameters.getStyle())); reduceDashboardRecursionCounter(); return Collections.<Block> singletonList(topLevel); } DashboardMacro(); }
DashboardMacro extends AbstractMacro<DashboardMacroParameters> implements NestedScriptMacroEnabled { @Override public List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { preventDashboardRecursion(); List<Gadget> gadgets; try { gadgets = this.gadgetSource.getGadgets(parameters.getSource(), context); } catch (Exception e) { String message = "Could not get the gadgets."; this.logger.error(message, e); throw new MacroExecutionException(message, e); } boolean isInEditMode = this.gadgetSource.isEditing(); DashboardRenderer renderer = getDashboardRenderer(StringUtils.isEmpty(parameters.getLayout()) ? "columns" : parameters.getLayout()); if (renderer == null) { String message = "Could not find dashboard renderer " + parameters.getLayout(); this.logger.error(message); throw new MacroExecutionException(message); } GadgetRenderer gadgetRenderer = getGadgetRenderer(isInEditMode); List<Block> layoutedResult; try { layoutedResult = renderer.renderGadgets(gadgets, gadgetRenderer, context); } catch (Exception e) { String message = "Could not render the gadgets for layout " + parameters.getLayout(); this.logger.error(message, e); throw new MacroExecutionException(message, e); } this.includeResources(isInEditMode); GroupBlock topLevel = new GroupBlock(); if (isInEditMode) { topLevel.addChildren(this.gadgetSource.getDashboardSourceMetadata(parameters.getSource(), context)); } topLevel.addChildren(layoutedResult); topLevel.setParameter("class", MACRO_NAME + (StringUtils.isEmpty(parameters.getStyle()) ? "" : " " + parameters.getStyle())); reduceDashboardRecursionCounter(); return Collections.<Block> singletonList(topLevel); } DashboardMacro(); @Override List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context); @Override boolean supportsInlineMode(); }
DashboardMacro extends AbstractMacro<DashboardMacroParameters> implements NestedScriptMacroEnabled { @Override public List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { preventDashboardRecursion(); List<Gadget> gadgets; try { gadgets = this.gadgetSource.getGadgets(parameters.getSource(), context); } catch (Exception e) { String message = "Could not get the gadgets."; this.logger.error(message, e); throw new MacroExecutionException(message, e); } boolean isInEditMode = this.gadgetSource.isEditing(); DashboardRenderer renderer = getDashboardRenderer(StringUtils.isEmpty(parameters.getLayout()) ? "columns" : parameters.getLayout()); if (renderer == null) { String message = "Could not find dashboard renderer " + parameters.getLayout(); this.logger.error(message); throw new MacroExecutionException(message); } GadgetRenderer gadgetRenderer = getGadgetRenderer(isInEditMode); List<Block> layoutedResult; try { layoutedResult = renderer.renderGadgets(gadgets, gadgetRenderer, context); } catch (Exception e) { String message = "Could not render the gadgets for layout " + parameters.getLayout(); this.logger.error(message, e); throw new MacroExecutionException(message, e); } this.includeResources(isInEditMode); GroupBlock topLevel = new GroupBlock(); if (isInEditMode) { topLevel.addChildren(this.gadgetSource.getDashboardSourceMetadata(parameters.getSource(), context)); } topLevel.addChildren(layoutedResult); topLevel.setParameter("class", MACRO_NAME + (StringUtils.isEmpty(parameters.getStyle()) ? "" : " " + parameters.getStyle())); reduceDashboardRecursionCounter(); return Collections.<Block> singletonList(topLevel); } DashboardMacro(); @Override List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context); @Override boolean supportsInlineMode(); static final String GADGET_CONTAINER; static final String GADGET_CONTAINER_PREFIX; static final String METADATA; static final String EDIT_URL; static final String ADD_URL; static final String REMOVE_URL; static final String SOURCE_PAGE; static final String SOURCE_SPACE; static final String SOURCE_WIKI; static final String SOURCE_URL; static final String MACRO_NAME; }