public static void convertVarNodesToDefineFunctions(VarTable varTable, List<INode> iNodes) {
   // Send back the change to the tPigLoad node if you modified the configure of define dunctions
   for (INode iNode : iNodes) {
     IElementParameter elementParameter =
         iNode.getElementParameter(PigMapConstants.DEFINE_FUNCTION);
     if (elementParameter != null && elementParameter.getValue() instanceof List) {
       List<Map<String, String>> defineFunctions =
           (List<Map<String, String>>) elementParameter.getValue();
       defineFunctions.clear();
       defineFunctionsAlias.clear();
       for (VarNode varNode : varTable.getNodes()) {
         if (iNode.getUniqueName().equals(varNode.getType())) {
           Map<String, String> item = new HashMap<String, String>();
           item.put(
               PigMapConstants.FUNCTION_ALIAS,
               TalendQuoteUtils.addQuotesIfNotExist(varNode.getName()));
           if (varNode.getExpression() != null) {
             String newString = varNode.getExpression().trim();
             if (newString.length() > 0) {
               newString = TalendQuoteUtils.addQuotesIfNotExist(newString);
             }
             item.put(PigMapConstants.UDF_FUNCTION, newString);
           } else {
             item.put(PigMapConstants.UDF_FUNCTION, ""); // $NON-NLS-1$
           }
           defineFunctions.add(item);
           String key = varNode.getName();
           if (!defineFunctionsAlias.containsKey(key)) {
             defineFunctionsAlias.put(key, varNode.getExpression());
           }
         }
       }
     }
   }
 }
 public static void convertVarNodesToDefineFunctions(VarTable varTable) {
   // if you modified the configure of var define functions , we need update .
   defineFunctionsAlias.clear();
   for (VarNode varNode : varTable.getNodes()) {
     Map<String, String> item = new HashMap<String, String>();
     item.put(
         PigMapConstants.FUNCTION_ALIAS, TalendQuoteUtils.addQuotesIfNotExist(varNode.getName()));
     item.put(
         PigMapConstants.UDF_FUNCTION,
         TalendQuoteUtils.addQuotesIfNotExist(varNode.getExpression()));
     String key = varNode.getName();
     if (!defineFunctionsAlias.containsKey(key)) {
       defineFunctionsAlias.put(key, varNode.getExpression());
     }
   }
 }
 private Object getKeySpace(NoSQLConnection connection, String ksName)
     throws NoSQLServerException {
   ContextType contextType = null;
   if (StringUtils.isEmpty(ksName)) {
     return null;
   }
   if (connection.isContextMode()) {
     contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
   }
   if (contextType != null) {
     ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
   }
   // if ksName has quote,then case sensitive
   boolean hasQuote = (ksName.charAt(0) == '"') && (ksName.charAt(ksName.length() - 1) == '"');
   try {
     initCluster(connection);
     List<Object> keySpaces = getKeySpaces(connection);
     for (Object keySpace : keySpaces) {
       String tmpKsName =
           (String) NoSQLReflection.invokeMethod(keySpace, "getName"); // $NON-NLS-1$
       if (hasQuote) {
         ksName = TalendQuoteUtils.removeQuotesIfExist(ksName);
         if (ksName.equals(tmpKsName)) {
           return keySpace;
         }
         // case in-sensitive by default for kaName
       } else if (ksName.equalsIgnoreCase(tmpKsName)) {
         return keySpace;
       }
     }
   } catch (Exception e) {
     throw new NoSQLServerException(e);
   }
   return null;
 }
  /**
   * create ProcessDescription and set it.
   *
   * <p>WARNING ::field FieldSeparator, RowSeparator, EscapeChar and TextEnclosure are surround by
   * double quote.
   *
   * @return processDescription
   */
  private ProcessDescription getProcessDescription(
      SalesforceSchemaConnection originalValueConnection) {

    ProcessDescription processDescription =
        ShadowProcessHelper.getProcessDescription(originalValueConnection);

    SalesforceSchemaBean bean = new SalesforceSchemaBean();

    bean.setWebServerUrl(originalValueConnection.getWebServiceUrl());
    bean.setUserName(originalValueConnection.getUserName());
    bean.setPassword(
        originalValueConnection.getValue(originalValueConnection.getPassword(), false));
    bean.setModuleName(originalValueConnection.getModuleName());
    bean.setQueryCondition(originalValueConnection.getQueryCondition());
    // add for feature 7507
    bean.setBatchSize(originalValueConnection.getBatchSize());
    bean.setUseProxy(originalValueConnection.isUseProxy());
    bean.setUesHttp(originalValueConnection.isUseHttpProxy());
    bean.setProxyHost(originalValueConnection.getProxyHost());
    bean.setProxyPort(originalValueConnection.getProxyPort());
    bean.setProxyUsername(originalValueConnection.getProxyUsername());
    bean.setProxyPassword(
        originalValueConnection.getValue(originalValueConnection.getProxyPassword(), false));

    processDescription.setSalesforceSchemaBean(bean);

    List<IMetadataTable> tableSchema = new ArrayList<IMetadataTable>();
    IMetadataTable tableGet =
        getMetadatasForSalesforce(
            bean.getWebServerUrl(),
            bean.getUserName(),
            bean.getPassword(),
            String.valueOf(bean.getTimeOut()),
            bean.getModuleName(),
            bean.getBatchSize(),
            bean.isUseProxy(),
            bean.isUesHttp(),
            bean.getProxyHost(),
            bean.getProxyPort(),
            bean.getProxyUsername(),
            bean.getProxyPassword(),
            false);

    IMetadataTable table = new org.talend.core.model.metadata.MetadataTable();
    List<IMetadataColumn> schema = new ArrayList<IMetadataColumn>();
    for (IMetadataColumn column : tableGet.getListColumns()) {
      schema.add(column.clone());
    }

    table.setTableName("tSalesforceInput"); // $NON-NLS-1$
    table.setListColumns(schema);
    tableSchema.add(table);

    processDescription.setSchema(tableSchema);

    processDescription.setEncoding(TalendQuoteUtils.addQuotes("ISO-8859-15")); // $NON-NLS-1$

    return processDescription;
  }
  public Object createNewEntry() {
    List<IContextParameter> listParams =
        getContextManager().getDefaultContext().getContextParameterList();
    Integer numParam = new Integer(1);
    boolean paramNameFound;
    String paramName = null;
    do { // look for a new name
      paramNameFound = true;
      paramName = NEW_PARAM_NAME + numParam;
      for (int i = 0; i < listParams.size(); i++) {
        if (paramName.equals(listParams.get(i).getName())) {
          paramNameFound = false;
        }
      }
      if (!paramNameFound) {
        numParam++;
      }
    } while (!paramNameFound);

    JobContextParameter contextParam = new JobContextParameter();
    contextParam.setName(paramName);
    ECodeLanguage curLanguage = LanguageManager.getCurrentLanguage();
    if (curLanguage == ECodeLanguage.JAVA) {
      contextParam.setType(ContextParameterJavaTypeManager.getDefaultJavaType().getId());
    } else {
      contextParam.setType(MetadataTalendType.getDefaultTalendType());
    }
    contextParam.setPrompt(paramName + "?"); // $NON-NLS-1$
    String defaultValue;
    if (curLanguage == ECodeLanguage.JAVA) {
      defaultValue =
          ContextParameterJavaTypeManager.getDefaultValueFromJavaIdType(
              ContextParameterJavaTypeManager.getDefaultJavaType().getId(), false);
    } else {
      defaultValue = TalendQuoteUtils.addQuotes(""); // $NON-NLS-1$
    }
    contextParam.setValue(defaultValue);
    contextParam.setComment(""); // $NON-NLS-1$
    contextParam.setSource(""); // $NON-NLS-1$
    return contextParam;
  }
  @SuppressWarnings("unchecked")
  private static String getDisplayValue(final IElementParameter param) {
    Object value = param.getValue();

    if (value instanceof String) {

      if (param.getName().equals("PROCESS_TYPE_VERSION")
          && value.equals(RelationshipItemBuilder.LATEST_VERSION)) { // $NON-NLS-1$
        String jobId =
            (String)
                param
                    .getParentParameter()
                    .getChildParameters()
                    .get("PROCESS_TYPE_PROCESS")
                    .getValue(); //$NON-NLS-1$
        ProcessItem processItem = ItemCacheManager.getProcessItem(jobId);
        if (processItem == null) {
          return ""; //$NON-NLS-1$
        }
        return processItem.getProperty().getVersion();
      }
      if (param.getName().equals("PROCESS_TYPE_CONTEXT")) { // $NON-NLS-1$
        String jobId =
            (String)
                param
                    .getParentParameter()
                    .getChildParameters()
                    .get("PROCESS_TYPE_PROCESS")
                    .getValue(); //$NON-NLS-1$
        ProcessItem processItem = ItemCacheManager.getProcessItem(jobId);
        if (processItem == null) {
          return ""; //$NON-NLS-1$
        }
        // check if the selected context exists, if not, use the default context of the job.
        boolean contextExists = false;
        for (Object object : processItem.getProcess().getContext()) {
          if (object instanceof ContextType) {
            if (((ContextType) object).getName() != null
                && ((ContextType) object).getName().equals(value)) {
              contextExists = true;
              continue;
            }
          }
        }
        if (!contextExists) {
          return processItem.getProcess().getDefaultContext();
        }
        return (String) value;
      }
      // hywang add for 6484
      if ("SELECTED_FILE".equals(param.getRepositoryValue())) { // $NON-NLS-N$ //$NON-NLS-1$
        IElementParameter propertyParam =
            param
                .getElement()
                .getElementParameter(
                    "PROPERTY:REPOSITORY_PROPERTY_TYPE"); // $NON-NLS-N$ //$NON-NLS-1$
        if (propertyParam != null
            && propertyParam.getValue() != null
            && !propertyParam.getValue().equals("")) { // $NON-NLS-1$
          try {
            IRepositoryViewObject object =
                CoreRuntimePlugin.getInstance()
                    .getProxyRepositoryFactory()
                    .getLastVersion((String) propertyParam.getValue());
            if (object != null) {
              Item item = object.getProperty().getItem();
              String extension = null;

              String rule = ""; // $NON-NLS-1$
              String processLabelAndVersion = null;
              if (item instanceof RulesItem) {
                RulesItem rulesItem = (RulesItem) item;
                extension = rulesItem.getExtension();
                if (param.getElement() instanceof INode) {
                  INode node = (INode) param.getElement();
                  IProcess process = node.getProcess();
                  String jobLabel = process.getName();
                  String jobVersion = process.getVersion();
                  processLabelAndVersion =
                      JavaResourcesHelper.getJobFolderName(jobLabel, jobVersion);
                }

                rule =
                    "rules/final/"
                        + processLabelAndVersion
                        + "/"
                        + rulesItem.getProperty().getLabel() // $NON-NLS-1$ //$NON-NLS-2$
                        + rulesItem.getProperty().getVersion()
                        + extension;
              }
              return TalendQuoteUtils.addQuotes(rule);
            } else {
              return param.getValue().toString();
            }
          } catch (Exception e) {
            ExceptionHandler.process(e);
          }
        }
      }

      return (String) value;
    }
    if (param.getFieldType() == EParameterFieldType.RADIO
        || param.getFieldType() == EParameterFieldType.CHECK
        || param.getFieldType() == EParameterFieldType.AS400_CHECK) {
      if (value instanceof Boolean) {
        return ((Boolean) param.getValue()).toString();
      } else {
        return Boolean.FALSE.toString();
      }
    }

    if (param.getFieldType() == EParameterFieldType.TABLE) {
      List<Map<String, Object>> tableValues = (List<Map<String, Object>>) param.getValue();
      String[] items = param.getListItemsDisplayCodeName();
      String stringValues = "{"; // $NON-NLS-1$
      for (int i = 0; i < tableValues.size(); i++) {
        Map<String, Object> lineValues = tableValues.get(i);
        stringValues += "["; // $NON-NLS-1$
        for (int j = 0; j < items.length; j++) {

          Object currentValue = lineValues.get(items[j]);
          if (currentValue instanceof Integer) {
            IElementParameter tmpParam = (IElementParameter) param.getListItemsValue()[j];
            if (tmpParam.getListItemsDisplayName().length != 0) {
              stringValues += tmpParam.getListItemsDisplayName()[(Integer) currentValue];
            }
          } else {
            stringValues += currentValue;
          }

          if (j != (items.length - 1)) {
            stringValues += ","; // $NON-NLS-1$
          }
        }
        stringValues += "]"; // $NON-NLS-1$
        if (i != (tableValues.size() - 1)) {
          stringValues += ","; // $NON-NLS-1$
        }
      }
      stringValues += "}"; // $NON-NLS-1$
      return stringValues;
    }

    return new String(""); // $NON-NLS-1$
  }