Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The explanation above only describes how to create a Monitoring Dashboard plugin but does not cover how to develop your own indicator set(s). That is done entirely in Java. See the wmaxmfindicators bundle for an example of how to create your own custom indicators. As a starting point you should implement an XMFIndicatorProvider that enables the registration of your custom indicators. See the file DefaultIndicatorsServiceImpl.java in wmaxmfindicators. Refer to the Javadoc for wmaxmfapi in the wm-addon-monitoring package for the interfaces offered by the framework.


...

Developing Custom Bulk Actions


Panel
borderColor#0081C0
titleColor#0081C0

The following applies to XperienCentral versions R28 and higher.


Beginning in XperienCentral R28, it is possible to define your own bulk actions for content items. You can, for example, add the possibility to publish multiple content items at once, change the publication or expiration date for a set of articles in one go, and so forth. The example custom bulk action implementation described below is added in a new XperienCentral plugin. It is also possible to add a custom bulk action to an existing plugin.

The bulk actions available in XperienCentral by default are delete and export. The delete bulk action is available out-of-the-box and the export bulk action is added when you install the Connector API add-on. Bulk actions are accessible in the Actions menu in Advanced Search:

[screengrab]

Bulk Action Factory Implementation

Each bulk action is identified by an action type. This is a unique ID string such as "exportToExcel". Every instance of a bulk action type is created by a custom bulk action factory. The implementation of this custom bulk action factory is also responsible for registering the custom bulk action in XperienCentral. Every custom bulk action factory must extend the class BulkActionFactory. For example:


Code Block
themeEclipse
import nl.gx.webmanager.services.jaxrs.search.bulkactions.api.BulkActionFactory;
public interface ExportToExcelFactory extends BulkActionFactory {
}


The registering and unregistering of a bulk action is performed using the onStart and onStop methods of the factory implementation via the bulk action service injected by OSGi:


Code Block
themeEclipse
public class ExportToExcelBulkActionFactoryImpl extends SimpleServiceComponent implements ExportToExcelFactory {

   private static final String ACTION_TYPE = "exportToExcel";

   // Injected by OSGI
   private ExcelService myExcelService;
   private BulkActionService myBulkActionService;

   @Override
   public void onStart() {
      super.onStart();
      myBulkActionService.addBulkActionFactory(ACTION_TYPE, this);
   }

   @Override
   public void onStop() {
      super.onStop();
      myBulkActionService.removeBulkActionFactory(ACTION_TYPE);
   }


The Actions drop-down menu in Advanced Search is populated with labels provided by all bulk action factories registered to the bulk action service. The method getActionLabel must be overridden in your factory:


Code Block
themeEclipse
@Override
public String getActionLabel(String locale) {
   String name = myNameDescriptions.get(locale);
   if (name == null) {
      name = myNameDescriptions.get(LOCALE_EN);
   }
   return name;
}


Instantiating a bulk action is accomplished by calling the createBulkActionInstance method. You should override this method in your custom factory to return the correct bulk action type:


Code Block
themeEclipse
@Override
public BulkAction createBulkActionInstance(String actionIdentifier, List<String> items,FrameworkDependencies frameworkDependencies, String locale) {
   return new ExportToExcelBulkAction(actionIdentifier, items, frameworkDependencies, locale, myExcelService);
}

A method call to createBulkActionInstance will trigger the creation of a new bulk action of type custom with possibly its own parameters such as an Excel service like that shown in the example above. This method call will usually come from the bulk action handling mechanism in XperienCentral.



...

Bulk Action Implementation

To implement the bulk action itself, your bulk action class must extend AbstractBulkAction and define the members and methods it needs for its custom functionality:


Code Block
themeEclipse
public class ExportToExcelBulkAction extends AbstractBulkAction {
   private ExcelService myExcelService;
   private ConfigurationManagement myConfigurationManagement;

The constructor of your class should look like this:


Code Block
themeEclipse
public ExportToExcelBulkAction(String actionIdentifier, List<String> items, FrameworkDependencies frameworkDependencies, String locale, ExcelService excelService) {
   super(actionIdentifier, items, frameworkDependencies, locale);
   myConfigurationManagement = frameworkDependencies.getConfigurationManagement();
   myExcelService = excelService;


The actionIdentifier parameter is the actionType identifier string. The items parameter is a list of item identifiers like "articleversion-14" that were selected for the bulk action.  The frameWorkDependencies parameter is a collection of services in the framework that are made available for use in your bulk action by the bulk action service. The locale parameter is the locale of the content editor. All these parameters are always passed on by the bulk action service when creating a bulk action. The last parameter, excelService, is a custom parameter used in this example. The call to the super constructor ensures that the bulk action is initialized properly and that the bulk action framework can handle the action.

Next, the actual validation code and business logic for the bulk action needs to be implemented. This is done using the methods checkPermissions, preProcess, treat and postProcess. The method checkPermissions is called after the bulk action selection is made in order to check whether the bulk action can be executed on the selected items. The method is called for every item in the selection. To only allow the action to be executed on items with sufficient edit permissions, you could implement the method like this:

Code Block
themeEclipse
@Override
public ProgressResponseBean.MsgType checkPermissions(BulkContentItemVersion item) {
   return item.checkEditPermissions();
}


The method treat is called in order to execute the actual action on one content item in the bulk action. The bulk action framework will iterate over the selection of items and call this method for every item. An implementation of a bulk action performing a state change on every content item of the selection, for example to publish an entire content set at once, could be implemented as follows:


Code Block
themeEclipse
@Override
public void treat(BulkContentItemVersion bulkContentItemVersion) throws OperationFailedException {
   LOG.log(Level.FINE, "Changing status of item {0} to {1}", new Object[] { bulkContentItemVersion.getTitle(), myWorkflowType.getWorkflowName()});

   ContentItemVersion<?> contentItemVersion = getContentItemVersion(bulkContentItemVersion);
   List<WorkflowModelState> targetWorkflowModelStates = getWorkflowModelStates(contentItemVersion);

   if (targetWorkflowModelStates.size() == 1) {
      try {
         WorkflowUtils.bringToState(contentItemVersion, targetWorkflowModelStates.get(0), myWorkflowService);
      } catch (UnExecutableWorkflowActionException e) {
         throw new OperationFailedException("Failed to change state of " + bulkContentItemVersion.getType() + WITH_ID + bulkContentItemVersion.getId());
      }
   } else if (targetWorkflowModelStates.size() > 1) {
      throw new OperationFailedException("Multiple target WorkflowModelStates found for " + bulkContentItemVersion.getType() + WITH_ID + bulkContentItemVersion.getId());
   } else {
      throw new OperationFailedException("No target WorkflowModelState found for mediaitemversion " + bulkContentItemVersion.getType() + WITH_ID + bulkContentItemVersion.getId());
   }
}


The method preProcess can be overridden in order to prepare and initialize the bulk action. The method postProcess can be overridden in order to perform additional work after all content items are processed. These two methods together with the treat method can be used to export data to Excel, for example:


Code Block
themeEclipse
@Override
public void preProcess() {
   pages = new ArrayList<>();
   2contentItems = new ArrayList<>();
}

@Override
public void treat(BulkContentItemVersion item) {
   LOG.log(Level.FINE, "Exporting data of item {0}", new Object[] { item.getTitle() });
   if (item instanceof BulkContentItemPageVersion) {
      pages.add(item.getId());
   } else if (item instanceof BulkContentItemMediaItemVersion) {
      contentItems.add(item.getId());
   }
}

@Override
public void postProcess(ProgressResponseBean bean) {
   String finishMessage = "";
   File excelFile = null;
   if (checkExportDirectory()) {
      excelFile = myExcelService.createExcel(pages, contentItems, myFilePath);
   }
   if (excelFile != null && excelFile.isFile()) {
      finishMessage = "<br /><a href=\"" + myExportDownloadUrl + "\" download>Download het export Excel bestand</a>.";
   } else {
      finishMessage = "Error";
   }
   bean.finishMessage = finishMessage;
}

Defining the Bulk Action Factory Component

The bulk action factory is a service bundle and must be defined as such in the Activator class of your plugin. Its definition will look something like this:


Code Block
themeEclipse
private ServiceComponentDefinitionImpl getExportToExcelFactoryComponent() {
   ServiceComponentDefinitionImpl definition = new ServiceComponentDefinitionImpl(false);
definition.setId(WCBConstants.EXPORT_TO_EXCEL_FACTORY_COMPONENT_ID);
definition.setName(WCBConstants.EXPORT_TO_EXCEL_FACTORY_COMPONENT_NAME);
definition.setDescription(WCBConstants.EXPORT_TO_EXCEL_FACTORY_COMPONENT_DESCRIPTION);
definition.setTypeId(ServiceComponentType.class.getName());
definition.setProperties(new Hashtable<>());
definition.setImplementationClassName(ExportToExcelBulkActionFactoryImpl.class.getName());
definition.setInterfaceClassNames(new String[]{ExportToExcelFactory.class.getName()});

setRequiredDependencies(definition, ExcelService.class, BulkActionService.class);
   return definition;
}



...

Custom Media Items and the Is Used in Widget
Anchor
custom_media_items_and_the_is_used_in_widget
custom_media_items_and_the_is_used_in_widget

...