Author: kwright
Date: Wed Jun 18 11:37:59 2014
New Revision: 1603415

URL: http://svn.apache.org/r1603415
Log:
Fix CONNECTORS-968 for ElasticSearch connector

Modified:
    
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
    
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java
    
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/resources/org/apache/manifoldcf/agents/output/elasticsearch/editSpecification_ElasticSearch.html

Modified: 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java?rev=1603415&r1=1603414&r2=1603415&view=diff
==============================================================================
--- 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
 (original)
+++ 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
 Wed Jun 18 11:37:59 2014
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Iterator;
+import java.util.HashMap;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.http.conn.HttpClientConnectionManager;
@@ -45,12 +46,12 @@ import org.apache.commons.io.FilenameUti
 import org.apache.manifoldcf.agents.interfaces.IOutputAddActivity;
 import org.apache.manifoldcf.agents.interfaces.IOutputNotifyActivity;
 import org.apache.manifoldcf.agents.interfaces.IOutputRemoveActivity;
-import org.apache.manifoldcf.agents.interfaces.OutputSpecification;
 import org.apache.manifoldcf.agents.interfaces.RepositoryDocument;
 import org.apache.manifoldcf.agents.interfaces.ServiceInterruption;
 import org.apache.manifoldcf.agents.output.BaseOutputConnector;
 import 
org.apache.manifoldcf.agents.output.elasticsearch.ElasticSearchAction.CommandEnum;
 import 
org.apache.manifoldcf.agents.output.elasticsearch.ElasticSearchConnection.Result;
+import org.apache.manifoldcf.core.interfaces.Specification;
 import org.apache.manifoldcf.core.interfaces.ConfigParams;
 import org.apache.manifoldcf.core.interfaces.ConfigurationNode;
 import org.apache.manifoldcf.core.interfaces.IHTTPOutput;
@@ -214,7 +215,8 @@ public class ElasticSearchConnector exte
    * @param out
    * @throws ManifoldCFException */
   private static void outputResource(String resName, IHTTPOutput out,
-      Locale locale, ElasticSearchParam params, String tabName) throws 
ManifoldCFException
+      Locale locale, ElasticSearchParam params,
+      String tabName, Integer sequenceNumber, Integer currentSequenceNumber) 
throws ManifoldCFException
   {
     Map<String,String> paramMap = null;
     if (params != null) {
@@ -222,7 +224,16 @@ public class ElasticSearchConnector exte
       if (tabName != null) {
         paramMap.put("TabName", tabName);
       }
+      if (currentSequenceNumber != null)
+        paramMap.put("SelectedNum",currentSequenceNumber.toString());
     }
+    else
+    {
+      paramMap = new HashMap<String,String>();
+    }
+    if (sequenceNumber != null)
+      paramMap.put("SeqNum",sequenceNumber.toString());
+
     Messages.outputResourceWithVelocity(out, locale, resName, paramMap, true);
   }
 
@@ -234,7 +245,7 @@ public class ElasticSearchConnector exte
     super.outputConfigurationHeader(threadContext, out, locale, parameters,
         tabsArray);
     tabsArray.add(Messages.getString(locale, ELASTICSEARCH_TAB_PARAMETERS));
-    outputResource(EDIT_CONFIG_HEADER_FORWARD, out, locale, null, null);
+    outputResource(EDIT_CONFIG_HEADER_FORWARD, out, locale, null, null, null, 
null);
   }
 
   @Override
@@ -245,20 +256,50 @@ public class ElasticSearchConnector exte
     super.outputConfigurationBody(threadContext, out, locale, parameters,
         tabName);
     ElasticSearchConfig config = this.getConfigParameters(parameters);
-    outputResource(EDIT_CONFIG_FORWARD_PARAMETERS, out, locale, config, 
tabName);
+    outputResource(EDIT_CONFIG_FORWARD_PARAMETERS, out, locale, config, 
tabName, null, null);
   }
 
+  /** Obtain the name of the form check javascript method to call.
+  *@param connectionSequenceNumber is the unique number of this connection 
within the job.
+  *@return the name of the form check javascript method.
+  */
   @Override
-  public void outputSpecificationHeader(IHTTPOutput out, Locale locale,
-      OutputSpecification os, List<String> tabsArray)
-      throws ManifoldCFException, IOException
+  public String getFormCheckJavascriptMethodName(int connectionSequenceNumber)
   {
-    super.outputSpecificationHeader(out, locale, os, tabsArray);
+    return "s"+connectionSequenceNumber+"_checkSpecification";
+  }
+
+  /** Obtain the name of the form presave check javascript method to call.
+  *@param connectionSequenceNumber is the unique number of this connection 
within the job.
+  *@return the name of the form presave check javascript method.
+  */
+  @Override
+  public String getFormPresaveCheckJavascriptMethodName(int 
connectionSequenceNumber)
+  {
+    return "s"+connectionSequenceNumber+"_checkSpecificationForSave";
+  }
+
+  /** Output the specification header section.
+  * This method is called in the head section of a job page which has selected 
a pipeline connection of the current type.  Its purpose is to add the required 
tabs
+  * to the list, and to output any javascript methods that might be needed by 
the job editing HTML.
+  *@param out is the output to which any HTML should be sent.
+  *@param locale is the preferred local of the output.
+  *@param os is the current pipeline specification for this connection.
+  *@param connectionSequenceNumber is the unique number of this connection 
within the job.
+  *@param tabsArray is an array of tab names.  Add to this array any tab names 
that are specific to the connector.
+  */
+  @Override
+  public void outputSpecificationHeader(IHTTPOutput out, Locale locale, 
Specification os,
+    int connectionSequenceNumber, List<String> tabsArray)
+    throws ManifoldCFException, IOException
+  {
+    super.outputSpecificationHeader(out, locale, os, connectionSequenceNumber, 
tabsArray);
     tabsArray.add(Messages.getString(locale, ELASTICSEARCH_TAB_ELASTICSEARCH));
-    outputResource(EDIT_SPEC_HEADER_FORWARD, out, locale, null, null);
+    
+    outputResource(EDIT_SPEC_HEADER_FORWARD, out, locale, null, null, new 
Integer(connectionSequenceNumber), null);
   }
 
-  final private SpecificationNode getSpecNode(OutputSpecification os)
+  final private SpecificationNode getSpecNode(Specification os)
   {
     int l = os.getChildCount();
     for (int i = 0; i < l; i++)
@@ -272,19 +313,42 @@ public class ElasticSearchConnector exte
     return null;
   }
 
+  /** Output the specification body section.
+  * This method is called in the body section of a job page which has selected 
a pipeline connection of the current type.  Its purpose is to present the 
required form elements for editing.
+  * The coder can presume that the HTML that is output from this configuration 
will be within appropriate <html>, <body>, and <form> tags.  The name of the
+  * form is "editjob".
+  *@param out is the output to which any HTML should be sent.
+  *@param locale is the preferred local of the output.
+  *@param os is the current pipeline specification for this job.
+  *@param connectionSequenceNumber is the unique number of this connection 
within the job.
+  *@param actualSequenceNumber is the connection within the job that has 
currently been selected.
+  *@param tabName is the current tab name.
+  */
   @Override
-  public void outputSpecificationBody(IHTTPOutput out, Locale locale,
-      OutputSpecification os, String tabName) throws ManifoldCFException,
-      IOException
+  public void outputSpecificationBody(IHTTPOutput out, Locale locale, 
Specification os,
+    int connectionSequenceNumber, int actualSequenceNumber, String tabName)
+    throws ManifoldCFException, IOException
   {
-    super.outputSpecificationBody(out, locale, os, tabName);
+
     ElasticSearchSpecs specs = getSpecParameters(os);
-    outputResource(EDIT_SPEC_FORWARD_ELASTICSEARCH, out, locale, specs, 
tabName);
+    
+    outputResource(EDIT_SPEC_FORWARD_ELASTICSEARCH, out, locale, specs, 
tabName, new Integer(connectionSequenceNumber), new 
Integer(actualSequenceNumber));
   }
 
+  /** Process a specification post.
+  * This method is called at the start of job's edit or view page, whenever 
there is a possibility that form data for a connection has been
+  * posted.  Its purpose is to gather form information and modify the 
transformation specification accordingly.
+  * The name of the posted form is "editjob".
+  *@param variableContext contains the post data, including binary file-upload 
information.
+  *@param locale is the preferred local of the output.
+  *@param os is the current pipeline specification for this job.
+  *@param connectionSequenceNumber is the unique number of this connection 
within the job.
+  *@return null if all is well, or a string error message if there is an error 
that should prevent saving of the job (and cause a redirection to an error 
page).
+  */
   @Override
-  public String processSpecificationPost(IPostParameters variableContext,
-      Locale locale, OutputSpecification os) throws ManifoldCFException
+  public String processSpecificationPost(IPostParameters variableContext, 
Locale locale, Specification os,
+    int connectionSequenceNumber)
+    throws ManifoldCFException
   {
     ConfigurationNode specNode = getSpecNode(os);
     boolean bAdd = (specNode == null);
@@ -293,12 +357,30 @@ public class ElasticSearchConnector exte
       specNode = new SpecificationNode(
           ElasticSearchSpecs.ELASTICSEARCH_SPECS_NODE);
     }
-    ElasticSearchSpecs.contextToSpecNode(variableContext, specNode);
+    ElasticSearchSpecs.contextToSpecNode(variableContext, specNode, 
connectionSequenceNumber);
     if (bAdd)
       os.addChild(os.getChildCount(), specNode);
     return null;
   }
 
+  /** View specification.
+  * This method is called in the body section of a job's view page.  Its 
purpose is to present the pipeline specification information to the user.
+  * The coder can presume that the HTML that is output from this configuration 
will be within appropriate <html> and <body> tags.
+  *@param out is the output to which any HTML should be sent.
+  *@param locale is the preferred local of the output.
+  *@param connectionSequenceNumber is the unique number of this connection 
within the job.
+  *@param os is the current pipeline specification for this job.
+  */
+  @Override
+  public void viewSpecification(IHTTPOutput out, Locale locale, Specification 
os,
+    int connectionSequenceNumber)
+    throws ManifoldCFException, IOException
+  {
+    outputResource(VIEW_SPEC_FORWARD, out, locale, getSpecParameters(os), 
null, new Integer(connectionSequenceNumber),null);
+
+  }
+
+
   /** Build a Set of ElasticSearch parameters. If configParams is null,
    * getConfiguration() is used.
    * 
@@ -311,7 +393,7 @@ public class ElasticSearchConnector exte
     return new ElasticSearchConfig(configParams);
   }
 
-  final private ElasticSearchSpecs getSpecParameters(OutputSpecification os)
+  final private ElasticSearchSpecs getSpecParameters(Specification os)
       throws ManifoldCFException
   {
     return new ElasticSearchSpecs(getSpecNode(os));
@@ -330,7 +412,7 @@ public class ElasticSearchConnector exte
   }
 
   @Override
-  public String getOutputDescription(OutputSpecification os)
+  public String getPipelineDescription(Specification os)
       throws ManifoldCFException
   {
     ElasticSearchSpecs specs = new ElasticSearchSpecs(getSpecNode(os));
@@ -385,14 +467,7 @@ public class ElasticSearchConnector exte
       IOException
   {
     outputResource(VIEW_CONFIG_FORWARD, out, locale,
-        getConfigParameters(parameters), null);
-  }
-
-  @Override
-  public void viewSpecification(IHTTPOutput out, Locale locale,
-      OutputSpecification os) throws ManifoldCFException, IOException
-  {
-    outputResource(VIEW_SPEC_FORWARD, out, locale, getSpecParameters(os), 
null);
+        getConfigParameters(parameters), null, null, null);
   }
 
   @Override

Modified: 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java?rev=1603415&r1=1603414&r2=1603415&view=diff
==============================================================================
--- 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java
 (original)
+++ 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchSpecs.java
 Wed Jun 18 11:37:59 2014
@@ -95,11 +95,11 @@ public class ElasticSearchSpecs extends 
   }
 
   public static void contextToSpecNode(IPostParameters variableContext,
-      ConfigurationNode specNode)
+      ConfigurationNode specNode, int sequenceNumber)
   {
     for (ParameterEnum param : SPECIFICATIONLIST)
     {
-      String p = variableContext.getParameter(param.name().toLowerCase());
+      String p = 
variableContext.getParameter("s"+sequenceNumber+"_"+param.name().toLowerCase());
       if (p != null)
         specNode.setAttribute(param.name(), p);
     }

Modified: 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/resources/org/apache/manifoldcf/agents/output/elasticsearch/editSpecification_ElasticSearch.html
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/elasticsearch/connector/src/main/resources/org/apache/manifoldcf/agents/output/elasticsearch/editSpecification_ElasticSearch.html?rev=1603415&r1=1603414&r2=1603415&view=diff
==============================================================================
--- 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/resources/org/apache/manifoldcf/agents/output/elasticsearch/editSpecification_ElasticSearch.html
 (original)
+++ 
manifoldcf/trunk/connectors/elasticsearch/connector/src/main/resources/org/apache/manifoldcf/agents/output/elasticsearch/editSpecification_ElasticSearch.html
 Wed Jun 18 11:37:59 2014
@@ -15,31 +15,31 @@
  limitations under the License.
 -->
 
-#if($TABNAME == 
$ResourceBundle.getString('ElasticSearchConnector.ElasticSearch'))
+#if($TABNAME == 
$ResourceBundle.getString('ElasticSearchConnector.ElasticSearch') && ${SEQNUM} 
== ${SELECTEDNUM})
 
 <table class="displaytable">
   <tr>
     <td 
class="description"><nobr>$Encoder.bodyEscape($ResourceBundle.getString('ElasticSearchConnector.MaxFileSizeBytesColon'))</nobr></td>
-    <td class="value"><input name="maxfilesize" type="text"
+    <td class="value"><input name="s${SEQNUM}_maxfilesize" type="text"
       value="$Encoder.attributeEscape($MAXFILESIZE)" size="24" /></td>
   </tr>
   <tr>
     <td 
class="description"><nobr>$Encoder.bodyEscape($ResourceBundle.getString('ElasticSearchConnector.AllowedMIMETypesColon'))</nobr>
     </td>
-    <td class="value"><textarea rows="10" cols="64" 
name="mimetypes">$Encoder.bodyEscape($MIMETYPES)</textarea>
+    <td class="value"><textarea rows="10" cols="64" 
name="s${SEQNUM}_mimetypes">$Encoder.bodyEscape($MIMETYPES)</textarea>
     </td>
   </tr>
   <tr>
     <td 
class="description"><nobr>$Encoder.bodyEscape($ResourceBundle.getString('ElasticSearchConnector.AllowedFileExtensionsColon'))</nobr></td>
-    <td class="value"><textarea rows="10" cols="12" 
name="extensions">$Encoder.bodyEscape($EXTENSIONS)</textarea>
+    <td class="value"><textarea rows="10" cols="12" 
name="s${SEQNUM}_extensions">$Encoder.bodyEscape($EXTENSIONS)</textarea>
     </td>
   </tr>
 </table>
 
 #else
 
-<input type="hidden" name="maxfilesize" 
value="$Encoder.attributeEscape($MAXFILESIZE)" />
-<input type="hidden" name="mimetypes" 
value="$Encoder.attributeEscape($MIMETYPES)" />
-<input type="hidden" name="extensions" 
value="$Encoder.attributeEscape($EXTENSIONS)" />
+<input type="hidden" name="s${SEQNUM}_maxfilesize" 
value="$Encoder.attributeEscape($MAXFILESIZE)" />
+<input type="hidden" name="s${SEQNUM}_mimetypes" 
value="$Encoder.attributeEscape($MIMETYPES)" />
+<input type="hidden" name="s${SEQNUM}_extensions" 
value="$Encoder.attributeEscape($EXTENSIONS)" />
 
 #end


Reply via email to