Class AbstractConnector

  • All Implemented Interfaces:
    ConnectorLocal, ConnectorPersistLocal, ConnectorPersistRemote, ConnectorRemote, PersistConnectorRemote, PluginControl, PublishingManagementConnector

    public abstract class AbstractConnector
    extends PluginControlDefault
    implements ConnectorLocal, ConnectorPersistLocal
    Base class for easy implementation of connectors.

    This class implements all relevant connector interfaces using simple default implementations.

    • Methods for reading data (interface ConnectorRemote) from content system will return NotImplementedException.
    • Methods for writing data (interface PersistConnectorRemote) to content system will return NotImplementedException.
    • Methods for bulk writing data (interface ConnectorPersistRemote) to content system will return NotImplementedException.
    • Methods for handling configuration life-cycle (interface PluginControl) are fully implemented.

    These methods depend on your implementation of the abstract methods getMappedName(), getConnectorLibrary(), getConfigurationClass().

    Plug-in Life-Cycle

    Deployment of the connector does not have any effects: no special initialization will be started.

    Changing a configuration in the repository will trigger reading the configurations through the afterCreateConfigurations(String, PluginConfigCollection), afterDeleteConfigurations(String, PluginConfigCollection), afterUpdateConfigurations(String, PluginConfigCollection) implementations.

    Overriding any of the "repository events" should call for the super classes method. E.g.

     @Override
     public void afterUpdateConfigurations(String sessionId, PluginConfigCollection updatedConfigs) throws PluginException {
       // your code goes here
       super.afterUpdateConfigurations(sessionId, updatedConfigs);
     }
     

    The first use of getInstanceConfig(String) will also trigger reading the configurations. getInstanceConfig(String) is typically called in any of the data reading/writing method like getRootBuckets etc.

    The first use of getInstanceData(String) will trigger reading the additional data through fetchInstanceData(Configuration). getInstanceData(String) is also typically called in any of the data reading/writing method like getRootBuckets etc.

    Minimal Connector Example

    This is a minimal implementation of a subclass of AbstractConnector.

    Beside the AbstractConnector subclass you will also have to subclass AbstractConnector.Configuration and AbstractConnector.Library.

    @Stateless(mappedName = DemoConnector.MAPPED_NAME)
    @PubServerPlugin
    public class DemoConnector extends AbstractConnector implements ConnectorLocal {
    
      protected static final Logger LOGGER = LoggerFactory.getLogger(DemoConnector.class);
    
      public static final String MAPPED_NAME = "com.priint.pubserver.plugins.connector.demo.DemoConnector";
    
      protected static final Class<?> DATA_CLASS =  Document.class;
    
      protected static final Class<? extends Configuration> CONFIG_CLASS = DemoConnectorConfig.class;
    
      @EJB
      private DemoConnectorLibrary pluginLibrary;
    
      @Override
      protected Class<? extends Configuration> getConfigurationClass() {
        return CONFIG_CLASS;
      }
    
      @Override
      protected Library getConnectorLibrary() {
        return this.pluginLibrary;
      }
    
      @Override
      protected Logger getLogger() {
        return LOGGER;
      }
    
      @Override
      protected String getMappedName() {
        return MAPPED_NAME;
      }
    
      @Override
      protected Object fetchInstanceData(Configuration connectorConfig) {
        // implement this if you need initialization of connector instance
        // the object you return here will be cached
        // and can be retrieved using getInstanceData(instanceName)
        return null;
      }
    
      // list of implemented data getter and setter methods starting with getRootBuckets.
    
      @Override
      @PubServerMethod(type = PluginMethod.MethodType.CONNECTOR, description = "")
      public List<Bucket> getRootBuckets(Context context, ConnectorEntity connectorEntity, String searchStr) throws NotImplementedException,
          DataSourceException, ConnectorException {
        try {
          // your code goes here
          } catch (DataSourceException | ConnectorException e) {
          throw e;
        } catch (Throwable e) {
          throw new DemoConnectorException("Unknown exception", e);
        }
      }
    
      // continue with override of other methods ...
    
    }
    Since:
    4.0.5, 4.1.7 added method getInstanceNames()