Hi all,
I’m writing a plugin where I need to get the macro id of the macro being rendered. I followed the advice here: https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-get-Confluence-macro-id-on-execute/qaq-p/474165 and this works on our test environment. However, on our dev environment the macro id I get on the page is different every time I load the page. In test, it’s always the same. Do you know why it would be different? We’re on Confluence version 6.13.4 in test and 6.15.2 in dev, but other than that the environments are the same.
Here’s the code. ReportManager just returns a string of content.
package ca.usask.wiki.reporting;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.pages.Page;
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.spaces.Space;
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.confluence.xhtml.api.MacroDefinition;
import com.atlassian.plugin.spring.scanner.annotation.imports.ConfluenceImport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ca.usask.wiki.reporting.ReportManager.ReportType;
@Named
public class ArticleCreationMacro implements Macro {
private static final Logger log = LoggerFactory.getLogger(ArticleCreationMacro.class);
@ConfluenceImport
private final PageManager pageManager;
@ConfluenceImport
private final SpaceManager spaceManager;
private final ReportManager reportManager;
@Inject
public ArticleCreationMacro(PageManager pageManager, SpaceManager spaceManager, ReportManager reportManager) {
this.pageManager = pageManager;
this.spaceManager = spaceManager;
this.reportManager = reportManager;
}
@Override
public String execute(Map<String, String> map, String string, ConversionContext conversionContext)
throws MacroExecutionException {
log.debug("executing article creation macro");
try {
MacroDefinition macroDefinition = (MacroDefinition) conversionContext.getProperty("macroDefinition");
log.debug("loaded macro definition");
log.debug("macro definition id: " + macroDefinition.getMacroId().get().getId());
Page pageWhereMacroLives = pageManager.getPage(conversionContext.getEntity().getContentId().asLong());
log.debug("page where macro lives: " + pageWhereMacroLives.getTitle());
Space space = CommonUtils.getSpaceFromParameterMap(map, pageWhereMacroLives, spaceManager);
log.debug("space: " + space.getKey());
ReportParameters reportParameters = new ReportParameters(ReportType.ARTICLE_CREATION, map, space,
pageWhereMacroLives, macroDefinition);
return reportManager.getReport(reportParameters);
} catch (Exception e) {
log.error("error while executing article creation macro: ", e);
throw new MacroExecutionException(e);
}
}
@Override
public BodyType getBodyType() {
return BodyType.NONE;
}
@Override
public OutputType getOutputType() {
return OutputType.BLOCK;
}
}
Thanks!
~Collene