{
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("CMIS Connection");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("class_name");
child.setValue("org.apache.manifoldcf.crawler.connectors.cmis.CmisRepositoryConnector");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("description");
child.setValue("CMIS Connection");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("max_connections");
child.setValue("10");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("configuration");
//CMIS Repository Connector parameters
//binding
ConfigurationNode cmisBindingNode = new ConfigurationNode("_PARAMETER_");
cmisBindingNode.setAttribute("name", CmisConfig.BINDING_PARAM);
cmisBindingNode.setValue(CmisConfig.BINDING_DEFAULT_VALUE);
child.addChild(child.getChildCount(), cmisBindingNode);
//username
ConfigurationNode cmisUsernameNode = new ConfigurationNode("_PARAMETER_");
cmisUsernameNode.setAttribute("name", CmisConfig.USERNAME_PARAM);
cmisUsernameNode.setValue(CmisConfig.USERNAME_DEFAULT_VALUE);
child.addChild(child.getChildCount(), cmisUsernameNode);
//password
ConfigurationNode cmisPasswordNode = new ConfigurationNode("_PARAMETER_");
cmisPasswordNode.setAttribute("name", CmisConfig.PASSWORD_PARAM);
cmisPasswordNode.setValue(CmisConfig.PASSWORD_DEFAULT_VALUE);
child.addChild(child.getChildCount(), cmisPasswordNode);
//protocol
ConfigurationNode cmisProtocolNode = new ConfigurationNode("_PARAMETER_");
cmisProtocolNode.setAttribute("name", CmisConfig.PROTOCOL_PARAM);
cmisProtocolNode.setValue(CmisConfig.PROTOCOL_DEFAULT_VALUE);
child.addChild(child.getChildCount(), cmisProtocolNode);
//server
ConfigurationNode cmisServerNode = new ConfigurationNode("_PARAMETER_");
cmisServerNode.setAttribute("name", CmisConfig.SERVER_PARAM);
cmisServerNode.setValue(CmisConfig.SERVER_DEFAULT_VALUE);
child.addChild(child.getChildCount(), cmisServerNode);
//port
ConfigurationNode cmisPortNode = new ConfigurationNode("_PARAMETER_");
cmisPortNode.setAttribute("name", CmisConfig.PORT_PARAM);
cmisPortNode.setValue(CmisConfig.PORT_DEFAULT_VALUE);
child.addChild(child.getChildCount(), cmisPortNode);
//path
ConfigurationNode cmisPathNode = new ConfigurationNode("_PARAMETER_");
cmisPathNode.setAttribute("name", CmisConfig.PATH_PARAM);
cmisPathNode.setValue(CmisConfig.PATH_DEFAULT_VALUE);
child.addChild(child.getChildCount(), cmisPathNode);
connectionObject.addChild(connectionObject.getChildCount(),child);
requestObject = new Configuration();
requestObject.addChild(0,connectionObject);
result = performAPIPutOperationViaNodes("repositoryconnections/CMIS%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.tests.TestingOutputConnector");
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("CMIS Connection");
jobObject.addChild(jobObject.getChildCount(),child);
// Revamped way of adding output connection
child = new ConfigurationNode("pipelinestage");
ConfigurationNode pipelineChild = new ConfigurationNode("stage_id");
pipelineChild.setValue("0");
child.addChild(child.getChildCount(),pipelineChild);
pipelineChild = new ConfigurationNode("stage_isoutput");
pipelineChild.setValue("true");
child.addChild(child.getChildCount(),pipelineChild);
pipelineChild = new ConfigurationNode("stage_connectionname");
pipelineChild.setValue("Null Connection");
child.addChild(child.getChildCount(),pipelineChild);
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("cmisQuery",CMIS_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.