{
int i;
// Create a basic file system connection, and save it.
ConfigurationNode connectionObject;
ConfigurationNode child;
Configuration requestObject;
Configuration result;
connectionObject = new ConfigurationNode("repositoryconnection");
child = new ConfigurationNode("name");
child.setValue("Alfresco Connection");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("class_name");
child.setValue("org.apache.manifoldcf.crawler.connectors.alfresco.AlfrescoRepositoryConnector");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("description");
child.setValue("An Alfresco Repository Connection");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("max_connections");
child.setValue("10");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("configuration");
//Alfresco Repository Connector parameters
//username
ConfigurationNode alfrescoUsernameNode = new ConfigurationNode("_PARAMETER_");
alfrescoUsernameNode.setAttribute("name", AlfrescoConfig.USERNAME_PARAM);
alfrescoUsernameNode.setValue(ALFRESCO_USERNAME);
child.addChild(child.getChildCount(), alfrescoUsernameNode);
//password
ConfigurationNode alfrescoPasswordNode = new ConfigurationNode("_PARAMETER_");
alfrescoPasswordNode.setAttribute("name", AlfrescoConfig.PASSWORD_PARAM);
alfrescoPasswordNode.setValue(ALFRESCO_PASSWORD);
child.addChild(child.getChildCount(), alfrescoPasswordNode);
//protocol
ConfigurationNode alfrescoProtocolNode = new ConfigurationNode("_PARAMETER_");
alfrescoProtocolNode.setAttribute("name", AlfrescoConfig.PROTOCOL_PARAM);
alfrescoProtocolNode.setValue(ALFRESCO_PROTOCOL);
child.addChild(child.getChildCount(), alfrescoProtocolNode);
//server
ConfigurationNode alfrescoServerNode = new ConfigurationNode("_PARAMETER_");
alfrescoServerNode.setAttribute("name", AlfrescoConfig.SERVER_PARAM);
alfrescoServerNode.setValue(ALFRESCO_SERVER);
child.addChild(child.getChildCount(), alfrescoServerNode);
//port
ConfigurationNode alfrescoPortNode = new ConfigurationNode("_PARAMETER_");
alfrescoPortNode.setAttribute("name", AlfrescoConfig.PORT_PARAM);
alfrescoPortNode.setValue(ALFRESCO_PORT);
child.addChild(child.getChildCount(), alfrescoPortNode);
//path
ConfigurationNode alfrescoPathNode = new ConfigurationNode("_PARAMETER_");
alfrescoPathNode.setAttribute("name", AlfrescoConfig.PATH_PARAM);
alfrescoPathNode.setValue(ALFRESCO_PATH);
child.addChild(child.getChildCount(), alfrescoPathNode);
//socketTimeout
ConfigurationNode socketTimeoutNode = new ConfigurationNode("_PARAMETER_");
socketTimeoutNode.setAttribute("name", AlfrescoConfig.SOCKET_TIMEOUT_PARAM);
socketTimeoutNode.setValue(String.valueOf(SOCKET_TIMEOUT));
child.addChild(child.getChildCount(), socketTimeoutNode);
connectionObject.addChild(connectionObject.getChildCount(),child);
requestObject = new Configuration();
requestObject.addChild(0,connectionObject);
result = performAPIPutOperationViaNodes("repositoryconnections/Alfresco%20Connection",201,requestObject);
i = 0;
while (i < result.getChildCount())
{
ConfigurationNode resultNode = result.findChild(i++);
if (resultNode.getType().equals("error"))
throw new Exception(resultNode.getValue());
}
// Create a basic null output connection, and save it.
connectionObject = new ConfigurationNode("outputconnection");
child = new ConfigurationNode("name");
child.setValue("Null Connection");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("class_name");
child.setValue("org.apache.manifoldcf.agents.output.nullconnector.NullConnector");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("description");
child.setValue("Null Connection");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("max_connections");
child.setValue("100");
connectionObject.addChild(connectionObject.getChildCount(),child);
requestObject = new Configuration();
requestObject.addChild(0,connectionObject);
result = performAPIPutOperationViaNodes("outputconnections/Null%20Connection",201,requestObject);
i = 0;
while (i < result.getChildCount())
{
ConfigurationNode resultNode = result.findChild(i++);
if (resultNode.getType().equals("error"))
throw new Exception(resultNode.getValue());
}
// Create a job.
ConfigurationNode jobObject = new ConfigurationNode("job");
child = new ConfigurationNode("description");
child.setValue("Test Job");
jobObject.addChild(jobObject.getChildCount(),child);
child = new ConfigurationNode("repository_connection");
child.setValue("Alfresco Connection");
jobObject.addChild(jobObject.getChildCount(),child);
child = new ConfigurationNode("output_connection");
child.setValue("Null Connection");
jobObject.addChild(jobObject.getChildCount(),child);
child = new ConfigurationNode("run_mode");
child.setValue("scan once");
jobObject.addChild(jobObject.getChildCount(),child);
child = new ConfigurationNode("start_mode");
child.setValue("manual");
jobObject.addChild(jobObject.getChildCount(),child);
child = new ConfigurationNode("hopcount_mode");
child.setValue("accurate");
jobObject.addChild(jobObject.getChildCount(),child);
child = new ConfigurationNode("document_specification");
//Job configuration
ConfigurationNode sn = new ConfigurationNode("startpoint");
sn.setAttribute("luceneQuery",ALFRESCO_TEST_QUERY);
child.addChild(child.getChildCount(),sn);
jobObject.addChild(jobObject.getChildCount(),child);
requestObject = new Configuration();
requestObject.addChild(0,jobObject);
result = performAPIPostOperationViaNodes("jobs",201,requestObject);
String jobIDString = null;
i = 0;
while (i < result.getChildCount())
{
ConfigurationNode resultNode = result.findChild(i++);
if (resultNode.getType().equals("error"))
throw new Exception(resultNode.getValue());
else if (resultNode.getType().equals("job_id"))
jobIDString = resultNode.getValue();
}
if (jobIDString == null)
throw new Exception("Missing job_id from return!");
// Now, start the job, and wait until it completes.