public String processConfigurationPost()

in connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/SolrConnector.java [1117:1378]


  public String processConfigurationPost(final IThreadContext threadContext, final IPostParameters variableContext, final Locale locale, final ConfigParams parameters) throws ManifoldCFException {
    final String type = variableContext.getParameter("solrtype");
    if (type != null)
      parameters.setParameter(SolrConfig.PARAM_SOLR_TYPE, type);

    final String protocol = variableContext.getParameter("serverprotocol");
    if (protocol != null)
      parameters.setParameter(SolrConfig.PARAM_PROTOCOL, protocol);

    final String server = variableContext.getParameter("servername");
    if (server != null)
      parameters.setParameter(SolrConfig.PARAM_SERVER, server);

    final String port = variableContext.getParameter("serverport");
    if (port != null)
      parameters.setParameter(SolrConfig.PARAM_PORT, port);

    final String webapp = variableContext.getParameter("webappname");
    if (webapp != null)
      parameters.setParameter(SolrConfig.PARAM_WEBAPPNAME, webapp);

    final String core = variableContext.getParameter("core");
    if (core != null)
      parameters.setParameter(SolrConfig.PARAM_CORE, core);

    final String collection = variableContext.getParameter("collection");
    if (collection != null)
      parameters.setParameter(SolrConfig.PARAM_COLLECTION, collection);

    final String connectionTimeout = variableContext.getParameter("connectiontimeout");
    if (connectionTimeout != null)
      parameters.setParameter(SolrConfig.PARAM_CONNECTION_TIMEOUT, connectionTimeout);

    final String socketTimeout = variableContext.getParameter("sockettimeout");
    if (socketTimeout != null)
      parameters.setParameter(SolrConfig.PARAM_SOCKET_TIMEOUT, socketTimeout);

    final String znodePath = variableContext.getParameter("znodepath");
    if (znodePath != null)
      parameters.setParameter(SolrConfig.PARAM_ZOOKEEPER_ZNODE_PATH, znodePath);

    final String zkClientTimeout = variableContext.getParameter("zkclienttimeout");
    if (zkClientTimeout != null)
      parameters.setParameter(SolrConfig.PARAM_ZOOKEEPER_SOCKET_TIMEOUT, zkClientTimeout);

    final String zkConnectTimeout = variableContext.getParameter("zkconnecttimeout");
    if (zkConnectTimeout != null)
      parameters.setParameter(SolrConfig.PARAM_ZOOKEEPER_CONNECTION_TIMEOUT, zkConnectTimeout);

    final String updatePath = variableContext.getParameter("updatepath");
    if (updatePath != null)
      parameters.setParameter(SolrConfig.PARAM_UPDATEPATH, updatePath);

    final String removePath = variableContext.getParameter("removepath");
    if (removePath != null)
      parameters.setParameter(SolrConfig.PARAM_REMOVEPATH, removePath);

    final String statusPath = variableContext.getParameter("statuspath");
    if (statusPath != null)
      parameters.setParameter(SolrConfig.PARAM_STATUSPATH, statusPath);

    final String idField = variableContext.getParameter("idfield");
    if (idField != null)
      parameters.setParameter(SolrConfig.PARAM_IDFIELD, idField);

    final String originalSizeField = variableContext.getParameter("originalsizefield");
    if (originalSizeField != null)
      parameters.setParameter(SolrConfig.PARAM_ORIGINALSIZEFIELD, originalSizeField);

    final String modifiedDateField = variableContext.getParameter("modifieddatefield");
    if (modifiedDateField != null)
      parameters.setParameter(SolrConfig.PARAM_MODIFIEDDATEFIELD, modifiedDateField);

    final String createdDateField = variableContext.getParameter("createddatefield");
    if (createdDateField != null)
      parameters.setParameter(SolrConfig.PARAM_CREATEDDATEFIELD, createdDateField);

    final String indexedDateField = variableContext.getParameter("indexeddatefield");
    if (indexedDateField != null)
      parameters.setParameter(SolrConfig.PARAM_INDEXEDDATEFIELD, indexedDateField);

    final String fileNameField = variableContext.getParameter("filenamefield");
    if (fileNameField != null)
      parameters.setParameter(SolrConfig.PARAM_FILENAMEFIELD, fileNameField);

    final String mimeTypeField = variableContext.getParameter("mimetypefield");
    if (mimeTypeField != null)
      parameters.setParameter(SolrConfig.PARAM_MIMETYPEFIELD, mimeTypeField);

    final String contentField = variableContext.getParameter("contentfield");
    if (contentField != null)
      parameters.setParameter(SolrConfig.PARAM_CONTENTFIELD, contentField);

    final String extractUpdatePresent = variableContext.getParameter("extractupdatepresent");
    if (extractUpdatePresent != null) {
      String extractUpdate = variableContext.getParameter("extractupdate");
      if (extractUpdate == null || extractUpdate.length() == 0)
        extractUpdate = "false";
      parameters.setParameter(SolrConfig.PARAM_EXTRACTUPDATE, extractUpdate);
    }

    final String realm = variableContext.getParameter("realm");
    if (realm != null)
      parameters.setParameter(SolrConfig.PARAM_REALM, realm);

    final String userID = variableContext.getParameter("userid");
    if (userID != null)
      parameters.setParameter(SolrConfig.PARAM_USERID, userID);

    final String password = variableContext.getParameter("password");
    if (password != null)
      parameters.setObfuscatedParameter(SolrConfig.PARAM_PASSWORD, variableContext.mapKeyToPassword(password));

    final String maxLength = variableContext.getParameter("maxdocumentlength");
    if (maxLength != null)
      parameters.setParameter(SolrConfig.PARAM_MAXLENGTH, maxLength);

    final String includedMimeTypes = variableContext.getParameter("includedmimetypes");
    if (includedMimeTypes != null)
      parameters.setParameter(SolrConfig.PARAM_INCLUDEDMIMETYPES, includedMimeTypes);

    final String excludedMimeTypes = variableContext.getParameter("excludedmimetypes");
    if (excludedMimeTypes != null)
      parameters.setParameter(SolrConfig.PARAM_EXCLUDEDMIMETYPES, excludedMimeTypes);

    final String commitsPresent = variableContext.getParameter("commits_present");
    if (commitsPresent != null) {
      String commits = variableContext.getParameter("commits");
      if (commits == null)
        commits = "false";
      parameters.setParameter(SolrConfig.PARAM_COMMITS, commits);
    }

    final String commitWithin = variableContext.getParameter("commitwithin");
    if (commitWithin != null)
      parameters.setParameter(SolrConfig.PARAM_COMMITWITHIN, commitWithin);

    String keystoreValue = variableContext.getParameter("keystoredata");
    if (keystoreValue != null) {
      final IKeystoreManager mgr = KeystoreManagerFactory.make("", keystoreValue);
      parameters.setParameter(SolrConfig.PARAM_KEYSTORE, mgr.getString());
    }

    String x = variableContext.getParameter("count_zookeeper");
    if (x != null && x.length() > 0) {
      // About to gather the bandwidth nodes, so get rid of the old ones.
      int i = 0;
      while (i < parameters.getChildCount()) {
        final ConfigNode node = parameters.getChild(i);
        if (node.getType().equals(SolrConfig.NODE_ZOOKEEPER))
          parameters.removeChild(i);
        else
          i++;
      }
      final int count = Integer.parseInt(x);
      i = 0;
      while (i < count) {
        final String postfix = "zookeeper_" + Integer.toString(i);
        final String op = variableContext.getParameter("op_" + postfix);
        if (op == null || !op.equals("Delete")) {
          // Gather the host etc.
          final String host = variableContext.getParameter("host_" + postfix);
          final String zkport = variableContext.getParameter("port_" + postfix);
          final ConfigNode node = new ConfigNode(SolrConfig.NODE_ZOOKEEPER);
          node.setAttribute(SolrConfig.ATTR_HOST, host);
          node.setAttribute(SolrConfig.ATTR_PORT, zkport);
          parameters.addChild(parameters.getChildCount(), node);
        }
        i++;
      }
      final String addop = variableContext.getParameter("op_zookeeper");
      if (addop != null && addop.equals("Add")) {
        final String host = variableContext.getParameter("host_zookeeper");
        final String zkport = variableContext.getParameter("port_zookeeper");
        final ConfigNode node = new ConfigNode(SolrConfig.NODE_ZOOKEEPER);
        node.setAttribute(SolrConfig.ATTR_HOST, host);
        node.setAttribute(SolrConfig.ATTR_PORT, zkport);
        parameters.addChild(parameters.getChildCount(), node);
      }
    }

    x = variableContext.getParameter("argument_count");
    if (x != null && x.length() > 0) {
      // About to gather the argument nodes, so get rid of the old ones.
      int i = 0;
      while (i < parameters.getChildCount()) {
        final ConfigNode node = parameters.getChild(i);
        if (node.getType().equals(SolrConfig.NODE_ARGUMENT))
          parameters.removeChild(i);
        else
          i++;
      }
      final int count = Integer.parseInt(x);
      i = 0;
      while (i < count) {
        final String prefix = "argument_" + Integer.toString(i);
        final String op = variableContext.getParameter(prefix + "_op");
        if (op == null || !op.equals("Delete")) {
          // Gather the name and value.
          final String name = variableContext.getParameter(prefix + "_name");
          final String value = variableContext.getParameter(prefix + "_value");
          final ConfigNode node = new ConfigNode(SolrConfig.NODE_ARGUMENT);
          node.setAttribute(SolrConfig.ATTRIBUTE_NAME, name);
          node.setAttribute(SolrConfig.ATTRIBUTE_VALUE, value);
          parameters.addChild(parameters.getChildCount(), node);
        }
        i++;
      }
      final String addop = variableContext.getParameter("argument_op");
      if (addop != null && addop.equals("Add")) {
        final String name = variableContext.getParameter("argument_name");
        final String value = variableContext.getParameter("argument_value");
        final ConfigNode node = new ConfigNode(SolrConfig.NODE_ARGUMENT);
        node.setAttribute(SolrConfig.ATTRIBUTE_NAME, name);
        node.setAttribute(SolrConfig.ATTRIBUTE_VALUE, value);
        parameters.addChild(parameters.getChildCount(), node);
      }
    }

    final String configOp = variableContext.getParameter("configop");
    if (configOp != null) {
      IKeystoreManager mgr;
      if (configOp.equals("Delete")) {
        final String alias = variableContext.getParameter("solrkeystorealias");
        keystoreValue = parameters.getParameter(SolrConfig.PARAM_KEYSTORE);
        if (keystoreValue != null)
          mgr = KeystoreManagerFactory.make("", keystoreValue);
        else
          mgr = KeystoreManagerFactory.make("");
        mgr.remove(alias);
        parameters.setParameter(SolrConfig.PARAM_KEYSTORE, mgr.getString());
      } else if (configOp.equals("Add")) {
        final String alias = IDFactory.make(threadContext);
        final byte[] certificateValue = variableContext.getBinaryBytes("solrcertificate");
        keystoreValue = parameters.getParameter(SolrConfig.PARAM_KEYSTORE);
        if (keystoreValue != null)
          mgr = KeystoreManagerFactory.make("", keystoreValue);
        else
          mgr = KeystoreManagerFactory.make("");
        final java.io.InputStream is = new java.io.ByteArrayInputStream(certificateValue);
        String certError = null;
        try {
          mgr.importCertificate(alias, is);
        } catch (final Throwable e) {
          certError = e.getMessage();
        } finally {
          try {
            is.close();
          } catch (final IOException e) {
            // Eat this exception
          }
        }

        if (certError != null) {
          return "Illegal certificate: " + certError;
        }
        parameters.setParameter(SolrConfig.PARAM_KEYSTORE, mgr.getString());
      }
    }

    return null;
  }