ConnectorLib Java 24.4
ConnectorLib Java SDK Programming Guide

# Sample Code for the Synchronize Action

The following code sample demonstrates a complete `synchronize` action. The sample uses a directory on the file system to represent a repository.

    package myconnector;

    import com.autonomy.connector.*;
    import java.io.File;

    public class SimpleSynchronize extends ConnectorBase
    {
        public static class IngestResultHandler
        {
            private final SynchronizeTask task;

            public IngestResultHandler(SynchronizeTask task)
            {
                this.task = task;
            }

            public void handler(DocInfo docInfo, Ingester.TaskType type,
                                         boolean success)
            {
                if (success)
                {
                    task.getLog().writeln(Log.NORMAL, "Document "
                            + docInfo.getDoc().getReference()
                            + " ingest " + type + " succeeded!");
                }
                else
                {
                    task.getLog().writeln(Log.ERROR, "Ingestion failed for "
                            + docInfo.getDoc().getReference());
                }
    	 }
        }

        public SimpleSynchronize(Config config, Log log)
        {
            super("My Connector");
        }

        public void synchronize(SynchronizeTask task) throws Exception
        {
            IngestResultHandler resultHandler = new IngestResultHandler(task);
            task.getIngester().addResultHandler(resultHandler, "handler");

            String directory = task.getTaskConfig().read("Directory", "data");

            File rootEntry = new File(directory);

            if (rootEntry.isDirectory())
            {
                File[] files = rootEntry.listFiles();
                for (int ii = 0; ii < files.length; ++ii)
                {
                    if (task.stop()) return;

                    File fileEntry = new File(files[ii].getAbsolutePath());

                    if (fileEntry.isFile())
                    {
                        DocInfo docInfo = new DocInfo(
                        task.getTaskConfig(),
                        fileEntry.getAbsolutePath(),
                        fileEntry.getAbsolutePath(),
                        false);
                        task.getIngester().add(docInfo);
                    }
                }
            }
        }
    }

Copyright 2024 Open Text
Version 24.4 | Last updated September 2024

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to MFI-swpdl.idoldocsfeedback@opentext.com.

We appreciate your feedback!

Product: IDOL ConnectorLib Java 24.4

Topic Title: Sample Code for the Synchronize Action