private boolean nameExist(String name) {
    existedNames.clear();
    for (int i = 0; i < this.temConnection.getModules().size(); i++) {
      if (this.temConnection.getModules().get(i).getModuleName().equals(moduleName)) {
        for (int j = 0; j < temConnection.getModules().get(i).getTables().size(); j++) {
          existedNames.add(temConnection.getModules().get(i).getTables().get(j).getLabel());
        }
        break;
      }
    }
    boolean result = false;
    int number = 0;
    for (int i = 0; i < this.existedNames.size(); i++) {
      if (existedNames.get(i).equals(name)) {
        number++;
      }
    }
    if (number > 1) {
      result = true;
    } else {
      result = false;
    }

    return result;
  }
Esempio n. 2
0
  private void initProxySettings(SalesforceSchemaConnection ssCon) {

    Properties properties = System.getProperties();
    String oldProxyHost = (String) properties.get(SalesforceModuleParseAPI.SOCKS_PROXY_HOST);
    String oldProxyPort = (String) properties.get(SalesforceModuleParseAPI.SOCKS_PROXY_PORT);
    String oldProxyUser = (String) properties.get(SalesforceModuleParseAPI.SOCKS_PROXY_USERNAME);
    String oldProxyPwd = (String) properties.get(SalesforceModuleParseAPI.SOCKS_PROXY_PASSWORD);

    ssCon.setProxyHost(oldProxyHost);
    ssCon.setProxyPort(oldProxyPort);
    ssCon.setProxyUsername(oldProxyUser);
    ssCon.setProxyPassword(oldProxyPwd);
  }
 private void initTreeNavigatorNodes() {
   List<String> selectedNames = new ArrayList<String>();
   EList<SalesforceModuleUnit> modules = temConnection.getModules();
   // EList<SalesforceModuleUnit> modules = getConnection().getModules();
   for (int i = 0; i < modules.size(); i++) {
     if (modules.get(i).getModuleName().equals(moduleName)) {
       for (int j = 0; j < modules.get(i).getTables().size(); j++) {
         selectedNames.add(modules.get(i).getTables().get(j).getLabel());
       }
       break;
     }
   }
   tableNavigator.removeAll();
   TableItem subItem = null;
   String lastSelectName = null;
   if (selectedNames != null && selectedNames.size() >= 1) {
     for (int i = 0; i < selectedNames.size(); i++) {
       subItem = new TableItem(tableNavigator, SWT.NULL);
       subItem.setText(selectedNames.get(i));
       lastSelectName = selectedNames.get(i);
     }
     metadataNameText.setText(subItem.getText());
     tableNavigator.setSelection(subItem);
     metadataTable = getTableByLabel(lastSelectName);
   } else {
     subItem = new TableItem(tableNavigator, SWT.NULL);
     subItem.setText(moduleName);
   }
   metadataEditor.setMetadataTable(metadataTable);
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.swt.widgets.Control#setVisible(boolean)
  */
 @Override
 public void setVisible(boolean visible) {
   super.setVisible(visible);
   if (super.isVisible()) {
     initTreeNavigatorNodes();
     changeTableNavigatorStatus(checkFieldsValue());
     SalesforceSchemaConnection originalValueConnection = getOriginalValueConnection();
     if (originalValueConnection.getWebServiceUrl() != null
         && (!originalValueConnection.getWebServiceUrl().equals("")) // $NON-NLS-1$
         && (tableEditorView.getMetadataEditor().getBeanCount() <= 0)) {
       runShadowProcess();
     }
     if (isReadOnly() != readOnly) {
       adaptFormToReadOnly();
     }
   }
   checkFieldsValue();
 }
 @Override
 protected org.talend.core.model.metadata.builder.connection.MetadataTable getTableByLabel(
     String label) {
   org.talend.core.model.metadata.builder.connection.MetadataTable result = null;
   EList<SalesforceModuleUnit> modules = temConnection.getModules();
   for (int i = 0; i < modules.size(); i++) {
     if (modules.get(i).getModuleName().equals(moduleName)) {
       for (int j = 0; j < modules.get(i).getTables().size(); j++) {
         if (modules.get(i).getTables().get(j).getLabel().equals(label)) {
           result = modules.get(i).getTables().get(j);
         }
       }
     }
   }
   return result;
 }
  protected void addMetadataTable() {
    // Create a new metadata and Add it on the connection
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
    metadataTable.setId(factory.getNextId());
    // initExistingNames();

    metadataTable.setLabel(IndiceHelper.getIndexedLabel(metadataTable.getLabel(), existingNames));
    EList<SalesforceModuleUnit> modules = temConnection.getModules();
    // EList<SalesforceModuleUnit> modules = getConnection().getModules();
    for (int i = 0; i < modules.size(); i++) {
      if (modules.get(i).getModuleName().equals(moduleName)) {

        modules.get(i).getTables().add(modules.get(i).getTables().size(), metadataTable);
        break;
      }
    }
    // init TreeNavigator
    initTreeNavigatorNodes();
    metadataNameText.setText(metadataTable.getLabel());
  }
Esempio n. 7
0
  public SalesforceSchemaWizard(
      IWorkbench workbench,
      boolean creation,
      RepositoryNode node,
      String[] existingNames,
      boolean isSinglePageOnly) {
    super(workbench, creation);
    this.existingNames = existingNames;
    this.isSinglePageOnly = isSinglePageOnly;
    setNeedsProgressMonitor(true);

    // TODO: should to changed icon.
    setDefaultPageImageDescriptor(ImageProvider.getImageDesc(ECoreImage.DEFAULT_WIZ));
    switch (node.getType()) {
      case SIMPLE_FOLDER:
      case REPOSITORY_ELEMENT:
        pathToSave = RepositoryNodeUtilities.getPath(node);
        break;
      case SYSTEM_FOLDER:
        pathToSave = new Path(""); // $NON-NLS-1$
        break;
    }

    switch (node.getType()) {
      case SIMPLE_FOLDER:
      case SYSTEM_FOLDER:
        connection = ConnectionFactory.eINSTANCE.createSalesforceSchemaConnection();
        connection.setName(ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA.getKey());
        MetadataTable metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        metadataTable.setId(factory.getNextId());
        RecordFile record =
            (RecordFile)
                ConnectionHelper.getPackage(connection.getName(), connection, RecordFile.class);
        if (record != null) { // hywang
          PackageHelper.addMetadataTable(metadataTable, record);
        } else {
          RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
          newrecord.setName(connection.getName());
          ConnectionHelper.addPackage(newrecord, connection);
          PackageHelper.addMetadataTable(metadataTable, newrecord);
        }
        connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
        connectionProperty.setAuthor(
            ((RepositoryContext)
                    CoreRuntimePlugin.getInstance()
                        .getContext()
                        .getProperty(Context.REPOSITORY_CONTEXT_KEY))
                .getUser());
        connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
        connectionProperty.setStatusCode(""); // $NON-NLS-1$

        connectionItem = PropertiesFactory.eINSTANCE.createSalesforceSchemaConnectionItem();
        connectionItem.setProperty(connectionProperty);
        connectionItem.setConnection(connection);
        initProxySettings(connection);
        break;

      case REPOSITORY_ELEMENT:
        connection =
            (SalesforceSchemaConnection)
                ((ConnectionItem) node.getObject().getProperty().getItem()).getConnection();
        connectionProperty = node.getObject().getProperty();
        connectionItem = (ConnectionItem) node.getObject().getProperty().getItem();
        // set the repositoryObject, lock and set isRepositoryObjectEditable
        setRepositoryObject(node.getObject());
        isRepositoryObjectEditable();
        initLockStrategy();
        break;
    }
    if (!creation) {
      this.originaleObjectLabel = this.connectionItem.getProperty().getLabel();
      this.originalVersion = this.connectionItem.getProperty().getVersion();
      this.originalDescription = this.connectionItem.getProperty().getDescription();
      this.originalPurpose = this.connectionItem.getProperty().getPurpose();
      this.originalStatus = this.connectionItem.getProperty().getStatusCode();
    }
    initConnection();
  }
  /** run a ShadowProcess to determined the Metadata. */
  protected void runShadowProcess() {
    initGuessSchema();
    SalesforceSchemaConnection originalValueConnection = getOriginalValueConnection();
    // if no file, the process don't be executed
    if (originalValueConnection.getWebServiceUrl() == null
        || originalValueConnection.getWebServiceUrl().equals("")) { // $NON-NLS-1$
      informationLabel.setText(
          "Salesforce endpoint lost" //$NON-NLS-1$
              + "                                                                              "); //$NON-NLS-1$
      return;
    }

    // try {
    informationLabel.setText(
        "   " + Messages.getString("FileStep3.guessProgress")); // $NON-NLS-1$ //$NON-NLS-2$

    // get the XmlArray width an adapt ProcessDescription
    ProcessDescription processDescription = getProcessDescription(originalValueConnection);

    IMetadataTable metadataTableOrder = readMetadataDetail();
    if (metadataTableOrder != null) {
      metadataTableClone = metadataTableOrder.clone();
      metadataTableOrder = modifyMetadataTable();
    }
    List<IMetadataTable> schema = processDescription.getSchema();
    if (schema != null && schema.size() > 0) {
      if (useAlphbet) {
        if (metadataTableOrder != null) {
          schema.get(0).setListColumns(metadataTableOrder.getListColumns());
        }
      } else {
        if (metadataTableClone != null) {
          schema.get(0).setListColumns(metadataTableClone.getListColumns());
        }
      }
    }
    // the web service url is used by tSalesforceInput, see 0004027: Studio crashes when clicking
    // Next on
    // Step 3 of SF wizard
    // processDescription.getSalesforceSchemaBean().setWebServerUrl(TSALESFORCE_INPUT_URL);
    //            CsvArray csvArray = ShadowProcessHelper.getCsvArray(processDescription,
    // "SALESFORCE_SCHEMA", true); //$NON-NLS-1$
    //
    // if (csvArray == null) {
    //                informationLabel.setText("   " +
    // Messages.getString("FileStep3.guessFailure")); //$NON-NLS-1$ //$NON-NLS-2$
    // } else {
    // refreshMetaDataTable(csvArray, processDescription);
    // }

    // } catch (CoreException e) {
    // if (getParent().getChildren().length == 1) {
    //                new ErrorDialogWidthDetailArea(getShell(), PID,
    // Messages.getString("FileStep3.guessFailureTip") + "\n" //$NON-NLS-1$ //$NON-NLS-2$
    //                        + Messages.getString("FileStep3.guessFailureTip2"), e.getMessage());
    // //$NON-NLS-1$
    // } else {
    //                new ErrorDialogWidthDetailArea(getShell(), PID,
    // Messages.getString("FileStep3.guessFailureTip"), e.getMessage()); //$NON-NLS-1$
    // }
    //            log.error(Messages.getString("FileStep3.guessFailure") + " " + e.getMessage());
    // //$NON-NLS-1$ //$NON-NLS-2$
    // }
    guessSchema(processDescription);
    checkFieldsValue();
  }
  /**
   * 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;
  }