Esempio n. 1
0
 /**
  * Method "setColumns" replaces the previous columns by the new ones.
  *
  * @param metadataTable the column set in which to add the columns (must not be null)
  * @param columns the columns to add (must not be null)
  * @return true if the content of the table changed as a result of the call.
  * @deprecate use MetadataTable.getColumns.add()
  */
 public static boolean setColumns(
     MetadataTable metadataTable, Collection<? extends TdColumn> columns) {
   assert metadataTable != null;
   assert columns != null;
   metadataTable.getColumns().clear();
   return metadataTable.getColumns().addAll(columns);
 }
Esempio n. 2
0
 /**
  * DOC mzhao 2009-03-12 Remove all columns from this column set.
  *
  * @param column
  * @param metadataTable
  * @return true if remove successfully, false or else.
  */
 public static void clearAllColumns(MetadataTable metadataTable) {
   // convert to an array because we cannon remove elements from a collection during a for loop
   MetadataColumn[] columns =
       metadataTable.getColumns().toArray(new MetadataColumn[metadataTable.getColumns().size()]);
   for (MetadataColumn col : columns) {
     removeColumn(col, metadataTable);
   }
 }
Esempio n. 3
0
 /**
  * DOC tguiu Comment method "doGetTableNames".
  *
  * @param connection
  * @return
  */
 private static List<String> doGetTableNames(Connection connection) {
   List<String> result = new ArrayList<String>(15);
   for (MetadataTable table : ConnectionHelper.getTables(connection)) {
     if (table == null) {
       continue;
     }
     result.add(table.getLabel());
   }
   return result;
 }
  /** Initialize value, forceFocus first field. */
  @Override
  protected void initialize() {
    // init the metadata Table
    String label = MetadataToolHelper.validateValue(metadataTable.getLabel());
    metadataNameText.setText(label);
    metadataCommentText.setText(metadataTable.getComment());
    metadataEditor.setMetadataTable(metadataTable);
    tableEditorView.setMetadataEditor(metadataEditor);
    tableEditorView.getTableViewerCreator().layout();

    if (getConnection().isReadOnly()) {
      adaptFormToReadOnly();
    } else {
      updateStatus(IStatus.OK, null);
    }
  }
  public static void addTableForSpecifiedDataPackage(
      DatabaseConnection dbconn, MetadataTable dbtable)
      throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
    // if the database connection is contextmodel, need to get the original value of every parameter
    IMetadataConnection imetadataConnection = ConvertionHelper.convert(dbconn);
    DatabaseConnection conn = (DatabaseConnection) imetadataConnection.getCurrentConnection();
    Collection<orgomg.cwm.objectmodel.core.Package> newDataPackage =
        EcoreUtil.copyAll(dbconn.getDataPackage());
    ConnectionHelper.addPackages(newDataPackage, conn);

    // String catalog = "";
    // fixed bug TDI-19395
    String catalog = imetadataConnection.getDatabase();
    String schema = "";
    EObject container = dbtable.eContainer();
    if (container != null) {
      if (container instanceof Schema) {
        schema = ((Schema) container).getName();
        EObject c = container.eContainer();
        if (c != null && c instanceof Catalog) {
          catalog = ((Catalog) c).getName();
        }
      } else if (container instanceof Catalog) {
        catalog = ((Catalog) container).getName();
      }
    }
    boolean isAccess =
        EDatabaseTypeName.ACCESS.getDisplayName().equals(imetadataConnection.getDbType());
    if (!isAccess) {
      schema = ExtractMetaDataUtils.getInstance().getMeataConnectionSchema(imetadataConnection);
    }
    addTableForTemCatalogOrSchema(catalog, schema, dbconn, dbtable, imetadataConnection);
  }
Esempio n. 6
0
 public static MetadataTable findByLabel(SAPFunctionUnit functionUnit, String label) {
   if (functionUnit == null) {
     throw new IllegalArgumentException("null connection"); // $NON-NLS-1$
   }
   if (label == null || "".equals(label)) {
     throw new IllegalArgumentException("null/empty label"); // $NON-NLS-1$
   }
   EList tables = functionUnit.getTables();
   for (int i = 0; i < tables.size(); i++) {
     MetadataTable table = (MetadataTable) tables.get(i);
     if (label.equals(table.getLabel())) {
       return table;
     }
   }
   return null;
 }
Esempio n. 7
0
 /**
  * DOC tguiu Comment method "findByLabel".
  *
  * @deprecated it would be better to use find with some unique identifier
  * @param connection
  * @param label
  * @return
  */
 @Deprecated
 public static MetadataTable findByLabel(Connection connection, String label) {
   if (connection == null) {
     throw new IllegalArgumentException("null connection"); // $NON-NLS-1$
   }
   if (label == null || "".equals(label)) {
     throw new IllegalArgumentException("null/empty label"); // $NON-NLS-1$
   }
   Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
   for (MetadataTable table : tables) {
     if (label.equals(table.getLabel())) {
       return table;
     }
   }
   return null;
 }
  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());
  }
  private String[] getColumnSetOwnerNames() {
    List<String> existingTables = new ArrayList<String>();

    for (ModelElement element : getAnalyzedColumns()) {
      if (element instanceof TdColumn && element.eContainer() instanceof Table) {
        String tableName = ColumnHelper.getTableFullName((TdColumn) element);
        if (!existingTables.contains(tableName)) {
          existingTables.add(tableName);
        }
      } else if (element instanceof Table) {
        String tableName = ((Table) element).getName();
        if (!existingTables.contains(tableName)) {
          existingTables.add(tableName);
        }

      } else if (element instanceof MetadataColumn) {
        // ADD by msjian 2011-5-10 20881: select columns from views, "Tables:" should be followed by
        // blank in
        // the result page
        if (!(element instanceof TdColumn)) {
          // MOD qiongli 2011-1-28,for delimited file
          try {
            MetadataTable table =
                ColumnHelper.getColumnOwnerAsMetadataTable((MetadataColumn) element);
            String tableName = table.getLabel();
            if (!existingTables.contains(tableName)) {
              existingTables.add(tableName);
            }
          } catch (java.lang.NullPointerException e) {
            log.error(
                Messages.getString("AnalysisHandler.CanNotFindColumnParent", element.getName()),
                e); //$NON-NLS-1$
          }
        }
      }
    }

    return existingTables.toArray(new String[existingTables.size()]);
  }
Esempio n. 10
0
  /**
   * removes the column from the MetadataTable, if it is a TdColumn then try to remove it from the
   * primary key and the foreign key that contains it. this eventually removes the private key and
   * foreign key from the table if the are no more refering to any column
   *
   * @param column to be removed
   * @param metadataTable the set to remove the column from
   */
  public static void removeColumn(MetadataColumn column, MetadataTable metadataTable) {
    if (column instanceof TdColumn) { // if of DbColumn then check for
      TdColumn tdColumn = (TdColumn) column;
      // first remove PK if it exists
      if (ColumnHelper.isPrimaryKey(tdColumn)) {
        ColumnHelper.removeColumnFromTablePrimaryKey(tdColumn);
      }

      // remove foreign key if it exists
      if (ColumnHelper.isForeignKey(tdColumn)) {
        ColumnHelper.removeColumnFromTableForeignKey(tdColumn);
      }
    } // else not a db column so simply removes the reference
    metadataTable.getFeature().remove(column);
  }
 private boolean isColumnTaggedAsReadonly(
     org.talend.core.model.metadata.builder.connection.MetadataTable table, String columnName) {
   if (table == null || columnName == null) {
     return false;
   }
   EList<org.talend.core.model.metadata.builder.connection.MetadataColumn> columns =
       table.getColumns();
   for (org.talend.core.model.metadata.builder.connection.MetadataColumn newColumn : columns) {
     if (columnName.equals(newColumn.getLabel())) {
       EList<TaggedValue> taggedValues = newColumn.getTaggedValue();
       for (TaggedValue taggedValue : taggedValues) {
         if (DiSchemaConstants.TALEND6_IS_READ_ONLY.equals(taggedValue.getTag())) {
           return Boolean.valueOf(taggedValue.getValue());
         }
       }
     }
   }
   return false;
 }
Esempio n. 12
0
  /**
   * return the first connection available that refers to this table by moving up to the last
   * Package instance that hold this table and finding the connection linked to it
   *
   * @param metadataTable
   * @return
   */
  public static Connection getFirstConnection(MetadataTable metadataTable) {
    assert metadataTable != null;
    Connection connection = null;
    Namespace namespace = metadataTable.getNamespace();
    // for the file connection
    if (namespace != null && namespace instanceof RecordFile) {
      return ConnectionHelper.getConnection((RecordFile) namespace);
    }

    // for the mdm connection
    if (namespace != null && namespace instanceof TdXmlSchema) {
      return ConnectionHelper.getConnection((Package) namespace);
    }

    if (namespace != null) {
      Package thePackage = SwitchHelpers.PACKAGE_SWITCH.doSwitch(namespace);
      if (thePackage != null) {
        connection = getFirstPackageConnection(thePackage);
      }
    } // else class is not linked to any package
    return connection;
  }
 /* method is used to remove table from database */
 public static void removeTables(
     String tableLabel,
     orgomg.cwm.objectmodel.core.Package subpack,
     DatabaseConnection connection) {
   if (subpack == null) {
     for (orgomg.cwm.objectmodel.core.Package pk : connection.getDataPackage()) {
       Iterator<ModelElement> iterator = pk.getOwnedElement().iterator();
       while (iterator.hasNext()) {
         Object o = iterator.next();
         if (o instanceof MetadataTable) {
           MetadataTable table = (MetadataTable) o;
           if (table.getLabel() != null && table.getLabel().equals(tableLabel)) {
             iterator.remove();
             break;
           }
         }
         if (o instanceof orgomg.cwm.objectmodel.core.Package) {
           subpack = (orgomg.cwm.objectmodel.core.Package) o;
           removeTables(tableLabel, subpack, connection);
         }
       }
     }
   } else {
     Iterator<ModelElement> iterator = subpack.getOwnedElement().iterator();
     while (iterator.hasNext()) {
       Object o = iterator.next();
       if (o instanceof MetadataTable) {
         MetadataTable table = (MetadataTable) o;
         if (table.getLabel() != null && table.getLabel().equals(tableLabel)) {
           iterator.remove();
           break;
         }
       }
     }
   }
 }
  @Test
  public void testExecuteSqlQuery_delimetd() throws Exception {
    String empty = "";
    Analysis analysis = mock(Analysis.class);
    DelimitedFileIndicatorEvaluator delFileIndiEvaluator =
        new DelimitedFileIndicatorEvaluator(analysis);
    DelimitedFileIndicatorEvaluator spyEvaluator = Mockito.spy(delFileIndiEvaluator);
    stub(method(DelimitedFileIndicatorEvaluator.class, "handleByARow"));
    stub(
        method(
            DelimitedFileIndicatorEvaluator.class,
            "addResultToIndicatorToRowMap",
            Indicator.class,
            EMap.class));
    AnalysisContext context = mock(AnalysisContext.class);
    when(analysis.getContext()).thenReturn(context);
    DelimitedFileConnection deliFileConn = mock(DelimitedFileConnection.class);
    when(context.getConnection()).thenReturn(deliFileConn);
    when(deliFileConn.isContextMode()).thenReturn(false);
    String path = "test.txt";
    when(deliFileConn.getFilePath()).thenReturn(path);
    IPath iPath = mock(IPath.class);
    File file = new File(path);
    BufferedWriter output = new BufferedWriter(new FileWriter(file));
    String str =
        "id;Cocust(Tests);owner_id\n"
            + "1;yellow;3301\n"
            + "2;blue;3302\n"
            + " 4;red;3307\n"
            + "5;white;4563\n"
            + "6;pink2;457883\n"
            + "7;blank;231233\n";
    output.write(str);
    output.close();
    when(iPath.toFile()).thenReturn(file);
    when(deliFileConn.getFieldSeparatorValue()).thenReturn(";");
    when(deliFileConn.getEncoding()).thenReturn("US-ASCII");
    AnalysisResult results = mock(AnalysisResult.class);
    when(analysis.getResults()).thenReturn(results);
    EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
    when(results.getIndicToRowMap()).thenReturn(indicToRowMap);

    List<ModelElement> columnElementList = new BasicEList<ModelElement>();
    List<MetadataColumn> columnElementList2 = new BasicEList<MetadataColumn>();
    MetadataColumn mc0 = mock(MetadataColumn.class);
    MetadataColumn mc1 = mock(MetadataColumn.class);
    MetadataColumn mc2 = mock(MetadataColumn.class);
    columnElementList.add(mc0);
    columnElementList.add(mc1);
    columnElementList.add(mc2);
    columnElementList2.add(mc0);
    columnElementList2.add(mc1);
    columnElementList2.add(mc2);
    EList<ModelElement> eLs = (EList<ModelElement>) columnElementList;
    when(context.getAnalysedElements()).thenReturn(eLs);
    PowerMockito.mockStatic(ColumnHelper.class);
    MetadataTable mTable = mock(MetadataTable.class);
    when(mTable.getColumns()).thenReturn((EList<MetadataColumn>) columnElementList2);
    when(ColumnHelper.getColumnOwnerAsMetadataTable(mc0)).thenReturn(mTable);
    when(ColumnHelper.getColumnOwnerAsMetadataTable(mc1)).thenReturn(mTable);
    when(deliFileConn.getHeaderValue()).thenReturn(empty);
    when(deliFileConn.getFooterValue()).thenReturn(empty);
    when(deliFileConn.getLimitValue()).thenReturn(empty);
    when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
    when(deliFileConn.getRowSeparatorValue()).thenReturn("\\n");
    when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
    when(deliFileConn.isSplitRecord()).thenReturn(false);

    PowerMockito.mockStatic(LanguageManager.class);
    when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);

    Mockito.doReturn(true).when(spyEvaluator).continueRun();
    spyEvaluator.executeSqlQuery(empty);
  }
Esempio n. 15
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();
  }
Esempio n. 16
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    // TODO Auto-generated method stub
    currentComposite = null;
    WSDLSchemaConnection connection = ((WSDLSchemaConnection) connectionItem.getConnection());
    if (ConnectionHelper.getTables(connection).size() < 2) {
      MetadataTable metadataTable =
          ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0];
      metadataTable.setLabel("Output");
      MetadataTable inPutMetadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
      IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
      inPutMetadataTable.setLabel("Input");
      inPutMetadataTable.setId(factory.getNextId());
      GenericPackage g =
          (GenericPackage)
              ConnectionHelper.getPackage(
                  connection.getName(), (Connection) connection, GenericPackage.class);
      if (g != null) { // hywang
        g.getOwnedElement().add(inPutMetadataTable);
        ConnectionHelper.getTables(connection).add(inPutMetadataTable);
      } else {
        GenericPackage gpkg = ConnectionFactory.eINSTANCE.createGenericPackage();
        PackageHelper.addMetadataTable(inPutMetadataTable, gpkg);
        ConnectionHelper.addPackage(gpkg, connection);
      }
      // connection.getTables().add(inPutMetadataTable);
    }

    switch (step) {
      case 2:
        currentComposite =
            new WebServiceStep1Form(
                parent, connectionItem, null, new String[] {}, contextModeManager);
        break;
      case 3:
        MetadataTable metadataTable2 = null;
        Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
        Iterator<MetadataTable> it = tables.iterator();
        while (it.hasNext()) {
          MetadataTable table = (MetadataTable) it.next();
          if (table.getLabel().equals("Output")) {
            metadataTable2 = table;
          }
        }
        currentComposite =
            new WebServiceStep2Form(parent, connectionItem, contextModeManager, metadataTable2);
        break;
      default:
        System.out.println("error...");
    }
    currentComposite.setReadOnly(!isRepositoryObjectEditable);
    AbstractForm.ICheckListener listener =
        new AbstractForm.ICheckListener() {

          public void checkPerformed(final AbstractForm source) {

            if (source.isStatusOnError()) {
              WebServiceSchemaWizardPage.this.setPageComplete(false);
              setErrorMessage(source.getStatus());
            } else {
              WebServiceSchemaWizardPage.this.setPageComplete(isRepositoryObjectEditable);
              setErrorMessage(null);
              setMessage(source.getStatus());
            }
          }
        };
    currentComposite.setListener(listener);
    setControl((Composite) currentComposite);
  }