Use a Configured Platform

The ConfiguredPlatformProvider is a Java class that lets you gain access to an instance of a platform configured via the 'conf' files specified in an Appkit project. This is useful when writing custom code which you would like to have access to a platform already defined in an Appkit application, for example indexing or storing documents in a platform.

To use this, simply inject the ConfiguredPlatformProvider into the class in which you want to gain access to the platform’s programmatic API:

private ConfiguredPlatformProvider myPlatformProvider;
You can then access a configured platform using this method
public Platform get(String name)

For example, if you have a platform configured in src/main/resources/conf/platforms/gsa/gsa.conf, in your code you would have:

Platform myPlatform = myPlatformProvider.get("platforms.gsa"); //search the platform //post a document to the platform

Most platforms support these general methods that you might want to use within the custom code that interfaces with the platform:

public twigkit.model.Response search(twigkit.model.Query query) throws twigkit.platform.PlatformException;
public void store(twigkit.model.Content... contents) throws twigkit.platform.PlatformException;
public twigkit.model.Content load(java.lang.String s) throws twigkit.platform.PlatformException;
public void delete(twigkit.model.Query query) throws twigkit.platform.PlatformException;

A PlatformOperationNotSupportedException will be thrown if the method is not supported by the underlying platform. See the Javadoc for the twigkit.model.Platform interface for more information.

Deploying your service

Appkit uses Guice to inject dependencies into Java classes. The easiest way to let Guice know about your new Java class (service) so that it can inject the ConfiguredPlatformProvider is to define your class as a managed Appkit service. This is done by adding a configuration file with the fully qualified name of the Java class under:

        twigkit.service.AppkitService <-- this is a file

You can enter a fully qualified Java class per line for each managed service you want to deploy.

An alternative is to use the AppkitApplication class to get an instance of the ConfiguredPlatformProvider:

ConfiguredPlatformProvider platformProvider = TwigKitApplication.getInstance().getInjector().getInstance(ConfiguredPlatformProvider.class);

This creates code that is more tightly coupled, so is generally less desirable, but still completely functional.