cancel
Showing results for 
Search instead for 
Did you mean: 

KM report - add commands

Former Member
0 Kudos

Hi,

when coding a custom report, there is the possibility to add 'commands', more particular in the code in :

/**

  • Gets a single command by its name.

*/

public IReportCommand getCommand(IName name) throws ResourceException {

return (IReportCommand)KenGDeleteReport.m_commandMap.get(name);

}

/**

  • Gets a list of command which can be processed.

*/

public List getCommands() throws ResourceException {

return KenGDeleteReport.m_commandList;

}

Can someone give an example of some implemented code?

Thanks for the help :o))

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Kevin,

I used this code to make commands work in a report:



      static class CreateCommand implements IReportCommand {
  	
  	    public static final IName NAME = new Name(IWcmConst.SAP_WCM_NAMESPACE + IWcmConst.NAMESPACE_SEPARATOR + "reporting", "create");
  	    public static final CreateCommand INSTANCE = new CreateCommand();
  	
  	    public IName getName() {
  	      return NAME;
  	    }
  	
  	    public String getDisplayName(Locale locale) {
  	      return RepositoryPropagationReport.getBundleText(locale, "cmd.disp.create", "Create");
  	    }
  	
  	    public String getDescription(Locale locale) {
  	      return RepositoryPropagationReport.getBundleText(locale, "cmd.desc.create", "Create structure of test data.");
  	    }
  	
  	    public IReportInputMeta getMeta() {
  	      return ReportInputMeta.getInstance(PARAM_NAMES_CREATE, PARAM_DEFINITIONS_CREATE, PARAM_DEFAULTS_CREATE);
  	    }
  	
  	  }

      static class ClearCommand implements IReportCommand {
			
	    public static final IName NAME = new Name(IWcmConst.SAP_WCM_NAMESPACE + IWcmConst.NAMESPACE_SEPARATOR + "reporting", "clear");
	    public static final ClearCommand INSTANCE = new ClearCommand();
	
	    public IName getName() {
	      return NAME;
	    }
	
	    public String getDisplayName(Locale locale) {
	      return RepositoryPropagationReport.getBundleText(locale, "cmd.disp.clear", "Clear");
	    }
	
	    public String getDescription(Locale locale) {
	      return RepositoryPropagationReport.getBundleText(locale, "cmd.desc.clear", "Clear content of root RID collection");
	    }
	
	    public IReportInputMeta getMeta() {
	      return ReportInputMeta.EMPTY_INSTANCE;
	    }
	
	  }


[...]

  static {
    Map tmap = new HashMap();
    tmap.put(ClearCommand.NAME, ClearCommand.INSTANCE);
    tmap.put(CreateCommand.NAME, CreateCommand.INSTANCE);
    COMMANDMAP = Collections.unmodifiableMap(tmap);
    List tlist = new ArrayList();
    tlist.add(ClearCommand.INSTANCE);
    tlist.add(CreateCommand.INSTANCE);
    COMMANDLIST = Collections.unmodifiableList(tlist);
  }

[...]

  public IReportCommand getCommand(IName name) throws ResourceException {
    return (IReportCommand) COMMANDMAP.get(name);
  }
  
  public List getCommands() throws ResourceException {
    return COMMANDLIST;
  }

[...]

  public IReportResult execute(IReportInput input, IResourceContext context, IResultReceiver receiver) 
  		throws ResourceException, InterruptedException {

    // get selected commands
    IReportCommandInput createInput = null;
    IReportCommandInput clearInput = null;
    for (Iterator it = input.getCommandInputs().iterator(); it.hasNext(); ) {
      IReportCommandInput i = (IReportCommandInput)it.next();
      if (i.getCommandName().equals(CreateCommand.NAME)) {
        createInput = i;
      }
      if (i.getCommandName().equals(ClearCommand.NAME)) {
        clearInput = i;
      }
    }

Former Member
0 Kudos

Hi Michael,

thanks for the reply. I implemented your code succesfully.

In the execute method, you have IReportCommandInput clearInput. How can you see if the the checkbox next to the command has been selected or not?

What does, in the static CreateCommand class in the getMeta() method the getInstance(PARAM_NAMES_CREATE, ...) do?

Thanks again,

Kevin

Former Member
0 Kudos

Hi Kevin,

1) if you iterate the List <code>input.getCommandInputs()</code> and you find the IName of your command in it, then the command's checkbox was selected.

2) report commands may have their own properties. So in this example I have a predefined list of property names, property definitions and default values, that are rendered together with the command.<br>

When executing the report you'll access them via the IReportCommandInput object.

Best reagrds,

Michael

Answers (0)