Author: kwright
Date: Wed Jun 4 17:54:46 2014
New Revision: 1600395
URL: http://svn.apache.org/r1600395
Log:
Add transformationconnector/transformationconnections support to API
Modified:
manifoldcf/branches/CONNECTORS-946/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
Modified:
manifoldcf/branches/CONNECTORS-946/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-946/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java?rev=1600395&r1=1600394&r2=1600395&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-946/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
(original)
+++
manifoldcf/branches/CONNECTORS-946/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
Wed Jun 4 17:54:46 2014
@@ -1203,10 +1203,12 @@ public class ManifoldCF extends org.apac
protected static final String API_AUTHORITYGROUPNODE = "authoritygroup";
protected static final String API_REPOSITORYCONNECTORNODE =
"repositoryconnector";
protected static final String API_OUTPUTCONNECTORNODE = "outputconnector";
+ protected static final String API_TRANSFORMATIONCONNECTORNODE =
"transformationconnector";
protected static final String API_AUTHORITYCONNECTORNODE =
"authorityconnector";
protected static final String API_MAPPINGCONNECTORNODE = "mappingconnector";
protected static final String API_REPOSITORYCONNECTIONNODE =
"repositoryconnection";
protected static final String API_OUTPUTCONNECTIONNODE = "outputconnection";
+ protected static final String API_TRANSFORMATIONCONNECTIONNODE =
"transformationconnection";
protected static final String API_AUTHORITYCONNECTIONNODE =
"authorityconnection";
protected static final String API_MAPPINGCONNECTIONNODE =
"mappingconnection";
protected static final String API_CHECKRESULTNODE = "check_result";
@@ -1356,6 +1358,48 @@ public class ManifoldCF extends org.apac
return READRESULT_FOUND;
}
+ /** Read a transformation connection status */
+ protected static int apiReadTransformationConnectionStatus(IThreadContext
tc, Configuration output, String connectionName)
+ throws ManifoldCFException
+ {
+ try
+ {
+ ITransformationConnectorPool transformationConnectorPool =
TransformationConnectorPoolFactory.make(tc);
+ ITransformationConnectionManager connectionManager =
TransformationConnectionManagerFactory.make(tc);
+ ITransformationConnection connection =
connectionManager.load(connectionName);
+ if (connection == null)
+ {
+ createErrorNode(output,"Connection '"+connectionName+"' does not
exist");
+ return READRESULT_NOTFOUND;
+ }
+
+ String results;
+ // Grab a connection handle, and call the test method
+ ITransformationConnector connector =
transformationConnectorPool.grab(connection);
+ try
+ {
+ results = connector.check();
+ }
+ catch (ManifoldCFException e)
+ {
+ results = e.getMessage();
+ }
+ finally
+ {
+ transformationConnectorPool.release(connection,connector);
+ }
+
+ ConfigurationNode response = new ConfigurationNode(API_CHECKRESULTNODE);
+ response.setValue(results);
+ output.addChild(output.getChildCount(),response);
+ }
+ catch (ManifoldCFException e)
+ {
+ createErrorNode(output,e);
+ }
+ return READRESULT_FOUND;
+ }
+
/** Read an authority connection status */
protected static int apiReadAuthorityConnectionStatus(IThreadContext tc,
Configuration output, String connectionName)
throws ManifoldCFException
@@ -1515,6 +1559,39 @@ public class ManifoldCF extends org.apac
}
return READRESULT_FOUND;
}
+
+ /** Read a transformation connection's info */
+ protected static int apiReadTransformationConnectionInfo(IThreadContext tc,
Configuration output, String connectionName, String command)
+ throws ManifoldCFException
+ {
+ try
+ {
+ ITransformationConnectorPool transformationConnectorPool =
TransformationConnectorPoolFactory.make(tc);
+ ITransformationConnectionManager connectionManager =
TransformationConnectionManagerFactory.make(tc);
+ ITransformationConnection connection =
connectionManager.load(connectionName);
+ if (connection == null)
+ {
+ createErrorNode(output,"Connection '"+connectionName+"' does not
exist");
+ return READRESULT_NOTFOUND;
+ }
+
+ // Grab a connection handle, and call the test method
+ ITransformationConnector connector =
transformationConnectorPool.grab(connection);
+ try
+ {
+ return
connector.requestInfo(output,command)?READRESULT_FOUND:READRESULT_NOTFOUND;
+ }
+ finally
+ {
+ transformationConnectorPool.release(connection,connector);
+ }
+ }
+ catch (ManifoldCFException e)
+ {
+ createErrorNode(output,e);
+ }
+ return READRESULT_FOUND;
+ }
/** Read a repository connection's info */
protected static int apiReadRepositoryConnectionInfo(IThreadContext tc,
Configuration output, String connectionName, String command)
@@ -1763,6 +1840,57 @@ public class ManifoldCF extends org.apac
return READRESULT_FOUND;
}
+ /** Get transformation connections */
+ protected static int apiReadTransformationConnections(IThreadContext tc,
Configuration output)
+ throws ManifoldCFException
+ {
+ try
+ {
+ ITransformationConnectionManager connManager =
TransformationConnectionManagerFactory.make(tc);
+ ITransformationConnection[] connections =
connManager.getAllConnections();
+ int i = 0;
+ while (i < connections.length)
+ {
+ ConfigurationNode connectionNode = new
ConfigurationNode(API_TRANSFORMATIONCONNECTIONNODE);
+ formatTransformationConnection(connectionNode,connections[i++]);
+ output.addChild(output.getChildCount(),connectionNode);
+ }
+ }
+ catch (ManifoldCFException e)
+ {
+ createErrorNode(output,e);
+ }
+ return READRESULT_FOUND;
+ }
+
+ /** Read transformation connection */
+ protected static int apiReadTransformationConnection(IThreadContext tc,
Configuration output, String connectionName)
+ throws ManifoldCFException
+ {
+ try
+ {
+ ITransformationConnectionManager connectionManager =
TransformationConnectionManagerFactory.make(tc);
+ ITransformationConnection connection =
connectionManager.load(connectionName);
+ if (connection != null)
+ {
+ // Fill the return object with job information
+ ConfigurationNode connectionNode = new
ConfigurationNode(API_TRANSFORMATIONCONNECTIONNODE);
+ formatTransformationConnection(connectionNode,connection);
+ output.addChild(output.getChildCount(),connectionNode);
+ }
+ else
+ {
+ createErrorNode(output,"Connection '"+connectionName+"' does not
exist.");
+ return READRESULT_NOTFOUND;
+ }
+ }
+ catch (ManifoldCFException e)
+ {
+ createErrorNode(output,e);
+ }
+ return READRESULT_FOUND;
+ }
+
/** Get authority connections */
protected static int apiReadAuthorityConnections(IThreadContext tc,
Configuration output)
throws ManifoldCFException
@@ -1953,6 +2081,43 @@ public class ManifoldCF extends org.apac
return READRESULT_FOUND;
}
+ /** List transformation connectors */
+ protected static int apiReadTransformationConnectors(IThreadContext tc,
Configuration output)
+ throws ManifoldCFException
+ {
+ // List registered transformation connectors
+ try
+ {
+ ITransformationConnectorManager manager =
TransformationConnectorManagerFactory.make(tc);
+ IResultSet resultSet = manager.getConnectors();
+ int j = 0;
+ while (j < resultSet.getRowCount())
+ {
+ IResultRow row = resultSet.getRow(j++);
+ ConfigurationNode child = new
ConfigurationNode(API_TRANSFORMATIONCONNECTORNODE);
+ String description = (String)row.getValue("description");
+ String className = (String)row.getValue("classname");
+ ConfigurationNode node;
+ if (description != null)
+ {
+ node = new ConfigurationNode(CONNECTORNODE_DESCRIPTION);
+ node.setValue(description);
+ child.addChild(child.getChildCount(),node);
+ }
+ node = new ConfigurationNode(CONNECTORNODE_CLASSNAME);
+ node.setValue(className);
+ child.addChild(child.getChildCount(),node);
+
+ output.addChild(output.getChildCount(),child);
+ }
+ }
+ catch (ManifoldCFException e)
+ {
+ createErrorNode(output,e);
+ }
+ return READRESULT_FOUND;
+ }
+
/** List authority connectors */
protected static int apiReadAuthorityConnectors(IThreadContext tc,
Configuration output)
throws ManifoldCFException
@@ -2775,6 +2940,10 @@ public class ManifoldCF extends org.apac
{
return apiReadOutputConnectionStatus(tc,output,connectionName);
}
+ else if (connectionType.equals("transformationconnections"))
+ {
+ return apiReadTransformationConnectionStatus(tc,output,connectionName);
+ }
else if (connectionType.equals("mappingconnections"))
{
return apiReadMappingConnectionStatus(tc,output,connectionName);
@@ -2818,6 +2987,10 @@ public class ManifoldCF extends org.apac
{
return apiReadOutputConnectionInfo(tc,output,connectionName,command);
}
+ else if (connectionType.equals("transformationconnections"))
+ {
+ return
apiReadTransformationConnectionInfo(tc,output,connectionName,command);
+ }
else if (connectionType.equals("repositoryconnections"))
{
return
apiReadRepositoryConnectionInfo(tc,output,connectionName,command);
@@ -2864,6 +3037,15 @@ public class ManifoldCF extends org.apac
String connectionName =
decodeAPIPathElement(path.substring("outputconnections/".length()));
return apiReadOutputConnection(tc,output,connectionName);
}
+ else if (path.equals("transformationconnections"))
+ {
+ return apiReadTransformationConnections(tc,output);
+ }
+ else if (path.startsWith("transformationconnections/"))
+ {
+ String connectionName =
decodeAPIPathElement(path.substring("transformationconnections/".length()));
+ return apiReadTransformationConnection(tc,output,connectionName);
+ }
else if (path.equals("mappingconnections"))
{
return apiReadMappingConnections(tc,output);
@@ -2895,6 +3077,10 @@ public class ManifoldCF extends org.apac
{
return apiReadOutputConnectors(tc,output);
}
+ else if (path.equals("transformationconnectors"))
+ {
+ return apiReadTransformationConnectors(tc,output);
+ }
else if (path.equals("mappingconnectors"))
{
return apiReadMappingConnectors(tc,output);
@@ -4500,6 +4686,118 @@ public class ManifoldCF extends org.apac
}
+ // Transformation connection API support
+
+ /** Convert input hierarchy into a TransformationConnection object.
+ */
+ protected static void
processTransformationConnection(org.apache.manifoldcf.agents.transformationconnection.TransformationConnection
connection, ConfigurationNode connectionNode)
+ throws ManifoldCFException
+ {
+ // Walk through the node's children
+ int i = 0;
+ while (i < connectionNode.getChildCount())
+ {
+ ConfigurationNode child = connectionNode.findChild(i++);
+ String childType = child.getType();
+ if (childType.equals(CONNECTIONNODE_ISNEW))
+ {
+ if (child.getValue() == null)
+ throw new ManifoldCFException("Connection isnew node requires a
value");
+ connection.setIsNew(child.getValue().equals("true"));
+ }
+ else if (childType.equals(CONNECTIONNODE_NAME))
+ {
+ if (child.getValue() == null)
+ throw new ManifoldCFException("Connection name node requires a
value");
+ connection.setName(child.getValue());
+ }
+ else if (childType.equals(CONNECTIONNODE_CLASSNAME))
+ {
+ if (child.getValue() == null)
+ throw new ManifoldCFException("Connection classname node requires a
value");
+ connection.setClassName(child.getValue());
+ }
+ else if (childType.equals(CONNECTIONNODE_MAXCONNECTIONS))
+ {
+ if (child.getValue() == null)
+ throw new ManifoldCFException("Connection maxconnections node
requires a value");
+ try
+ {
+ connection.setMaxConnections(Integer.parseInt(child.getValue()));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ManifoldCFException("Error parsing max connections:
"+e.getMessage(),e);
+ }
+ }
+ else if (childType.equals(CONNECTIONNODE_DESCRIPTION))
+ {
+ if (child.getValue() == null)
+ throw new ManifoldCFException("Connection description node requires
a value");
+ connection.setDescription(child.getValue());
+ }
+ else if (childType.equals(CONNECTIONNODE_CONFIGURATION))
+ {
+ // Get the connection's configuration, clear out the children, and
copy new ones from the child.
+ ConfigParams cp = connection.getConfigParams();
+ cp.clearChildren();
+ int j = 0;
+ while (j < child.getChildCount())
+ {
+ ConfigurationNode cn = child.findChild(j++);
+ cp.addChild(cp.getChildCount(),new ConfigNode(cn));
+ }
+ }
+ else
+ throw new ManifoldCFException("Unrecognized output connection field:
'"+childType+"'");
+ }
+ if (connection.getClassName() == null)
+ throw new ManifoldCFException("Missing connection field:
'"+CONNECTIONNODE_CLASSNAME+"'");
+
+ }
+
+ /** Format a transformation connection.
+ */
+ protected static void formatTransformationConnection(ConfigurationNode
connectionNode, ITransformationConnection connection)
+ {
+ ConfigurationNode child;
+ int j;
+
+ child = new ConfigurationNode(CONNECTIONNODE_ISNEW);
+ child.setValue(connection.getIsNew()?"true":"false");
+ connectionNode.addChild(connectionNode.getChildCount(),child);
+
+ child = new ConfigurationNode(CONNECTIONNODE_NAME);
+ child.setValue(connection.getName());
+ connectionNode.addChild(connectionNode.getChildCount(),child);
+
+ child = new ConfigurationNode(CONNECTIONNODE_CLASSNAME);
+ child.setValue(connection.getClassName());
+ connectionNode.addChild(connectionNode.getChildCount(),child);
+
+ child = new ConfigurationNode(CONNECTIONNODE_MAXCONNECTIONS);
+ child.setValue(Integer.toString(connection.getMaxConnections()));
+ connectionNode.addChild(connectionNode.getChildCount(),child);
+
+ if (connection.getDescription() != null)
+ {
+ child = new ConfigurationNode(CONNECTIONNODE_DESCRIPTION);
+ child.setValue(connection.getDescription());
+ connectionNode.addChild(connectionNode.getChildCount(),child);
+ }
+
+ ConfigParams cp = connection.getConfigParams();
+ child = new ConfigurationNode(CONNECTIONNODE_CONFIGURATION);
+ j = 0;
+ while (j < cp.getChildCount())
+ {
+ ConfigurationNode cn = cp.findChild(j++);
+ child.addChild(child.getChildCount(),cn);
+ }
+ connectionNode.addChild(connectionNode.getChildCount(),child);
+
+ }
+
// Authority connection API support
/** Convert input hierarchy into an AuthorityConnection object.