Creating your own NodeProperties plugin (customize search result objects)

NodeProperties is usually used in web services scenarios. Using them, you can customize the result objects from a search query. Usually, as the result of some search query you only need to use a few variables of the returned objects rather than the complete ones.  With large query results, returning less data gives better performance (less time filling data on the server side and less time for marshalling and unmarshalling web services procedures).

You can create your own NodeProperties.

Conditions:

  • The new NodeProperties class must implement the "NodeProperties" interface.
  • The new NodeProperties class must be declared under the package "com.openkm.plugin.properties".
  • The new NodeProperties class must be annotated with "@PluginImplementation".
  • The new NodeProperties class must extend "BasePlugin".

NodeProperties interface:

package com.openkm.plugin.properties;

import com.openkm.bean.Document;
import com.openkm.bean.Folder;
import com.openkm.bean.Mail;
import com.openkm.bean.Record;
import com.openkm.core.DatabaseException;
import com.openkm.core.PathNotFoundException;
import com.openkm.core.RepositoryException;
import com.openkm.db.bean.NodeDocument;
import com.openkm.db.bean.NodeFolder;
import com.openkm.db.bean.NodeMail;
import com.openkm.db.bean.NodeRecord;
import net.xeoh.plugins.base.Plugin;

/**
 * NodeProperties
 */
public interface NodeProperties extends Plugin {

    /**
     * Get document properties
     */
    Document getProperties(String user, NodeDocument nDocument, String linkTarget) throws PathNotFoundException, DatabaseException, RepositoryException;

    /**
     * Get folder properties
     */
    Folder getProperties(String user, NodeFolder nFolder) throws PathNotFoundException, DatabaseException, RepositoryException;

    /**
     * Get mail properties
     */
    Mail getProperties(String user, NodeMail nMail) throws PathNotFoundException, DatabaseException, RepositoryException;

    /**
     * Get record properties
     */
    Record getProperties(String user, NodeRecord nRecord) throws PathNotFoundException, DatabaseException, RepositoryException;
}

The new class must be loaded into the package com.openkm.plugin.properties because the application plugin system will try to load it from there.

Do not miss the tag @PluginImplementation; otherwise, the application plugin system will not be able to retrieve the new class.

More information at: Register a new plugin.

Method description

MethodTypeDescription

getProperties(String user, NodeDocument nDocument, String linkTarget)

Document

Define which values are loaded in the Document object returned by the search engine.

getProperties(String user, NodeFolder nFolder)

Return

Define which values are loaded in the Folder object returned by the search engine.

getProperties(String user, NodeMail nMail)

Mail

Define which values are loaded in the Mail object returned by the search engine.

getProperties(String user, NodeRecord nRecord)

Record

Define which values are loaded in the Record object returned by the search engine.

Example of NodeProperties implementation

package com.openkm.plugin.properties;

import com.openkm.bean.Document;
import com.openkm.bean.Folder;
import com.openkm.bean.Mail;
import com.openkm.bean.Record;
import com.openkm.core.DatabaseException;
import com.openkm.core.PathNotFoundException;
import com.openkm.core.RepositoryException;
import com.openkm.db.bean.NodeDocument;
import com.openkm.db.bean.NodeFolder;
import com.openkm.db.bean.NodeMail;
import com.openkm.db.bean.NodeRecord;
import com.openkm.plugin.BasePlugin;
import net.xeoh.plugins.base.annotations.PluginImplementation;

/**
 * UuidNodeProperties
 */
@PluginImplementation
public class UuidNodeProperties extends BasePlugin implements NodeProperties {

    /**
     * Get document properties
     */
    @Override
    public Document getProperties(String user, NodeDocument nDocument, String linkTarget) throws PathNotFoundException, DatabaseException, RepositoryException {
        Document node = new Document();
        node.setUuid(nDocument.getUuid());
        return node;
    }

    /**
     * Get folder properties
     */
    @Override
    public Folder getProperties(String user, NodeFolder nFolder) throws PathNotFoundException, DatabaseException, RepositoryException {
        Folder node = new Folder();
        node.setUuid(nFolder.getUuid());
        return node;
    }

    /**
     * Get mail properties
     */
    @Override
    public Mail getProperties(String user, NodeMail nMail) throws PathNotFoundException, DatabaseException, RepositoryException {
        Mail node = new Mail();
        node.setUuid(nMail.getUuid());
        return node;
    }

    /**
     * Get record properties
     */
    @Override
    public Record getProperties(String user, NodeRecord nRecord) throws PathNotFoundException, DatabaseException, RepositoryException {
        Record node = new Record();
        node.setUuid(nRecord.getUuid());
        return node;
    }

}