Search in sources :

Example 21 with MetadataTable

use of org.talend.core.model.metadata.MetadataTable in project tdi-studio-se by Talend.

the class SapSchemaTypeController method createComboCommand.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
     * .eclipse.swt.custom.CCombo)
     */
@Override
protected Command createComboCommand(CCombo combo) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        /* see bug 16969 */
        // if (repositoryTableMap.containsKey(schemaSelected)) {
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // newRepositoryIdValue = schemaSelected;// + " - " + repositoryMetadata.getLabel();
        // } else {
        // if (repositoryTableMap.keySet().size() == 0) {
        // repositoryMetadata = new MetadataTable();
        // } else {
        // newRepositoryIdValue = repositoryTableMap.keySet().iterator().next();
        // // Gets the schema of the first item in repository schema type combo.
        // repositoryMetadata = repositoryTableMap.get(newRepositoryIdValue);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // // newRepositoryIdValue = newRepositoryIdValue + " - " + repositoryMetadata.getLabel();
        // }
        // }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 22 with MetadataTable

use of org.talend.core.model.metadata.MetadataTable in project tdq-studio-se by Talend.

the class ModelElementEditonDistance method distance.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.emf.compare.match.eobject.EditionDistance#distance(org.eclipse.emf.compare.Comparison,
     * org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
     */
@Override
public double distance(Comparison inProgress, EObject a, EObject b) {
    boolean isSame = false;
    if (a instanceof DatabaseConnection) {
        return 0;
    }
    if (a instanceof Catalog && b instanceof Catalog) {
        Catalog catalog1 = (Catalog) a;
        Catalog catalog2 = (Catalog) b;
        isSame = StringUtils.equalsIgnoreCase(catalog1.getName(), catalog2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof Schema && b instanceof Schema) {
        Schema schema1 = (Schema) a;
        Schema schema2 = (Schema) b;
        isSame = StringUtils.equalsIgnoreCase(schema1.getName(), schema2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdTable && b instanceof TdTable) {
        TdTable tdTable1 = (TdTable) a;
        TdTable tdTable2 = (TdTable) b;
        isSame = StringUtils.equalsIgnoreCase(tdTable1.getName(), tdTable2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdView && b instanceof TdView) {
        TdView tdView1 = (TdView) a;
        TdView tdView2 = (TdView) b;
        isSame = StringUtils.equalsIgnoreCase(tdView1.getName(), tdView2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdColumn && b instanceof TdColumn) {
        TdColumn tdColumn1 = (TdColumn) a;
        TdColumn tdColumn2 = (TdColumn) b;
        isSame = StringUtils.equalsIgnoreCase(tdColumn1.getName(), tdColumn2.getName()) && distance(inProgress, tdColumn1.getSqlDataType(), tdColumn2.getSqlDataType()) == 0;
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TaggedValue && b instanceof TaggedValue) {
        TaggedValue taggedValue1 = (TaggedValue) a;
        TaggedValue taggedValue2 = (TaggedValue) b;
        isSame = StringUtils.equalsIgnoreCase(taggedValue1.getTag(), taggedValue2.getTag()) && StringUtils.equalsIgnoreCase(taggedValue1.getValue(), taggedValue2.getValue());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdExpression && b instanceof TdExpression) {
        TdExpression tdExpression1 = (TdExpression) a;
        TdExpression tdExpression2 = (TdExpression) b;
        isSame = StringUtils.equalsIgnoreCase(tdExpression1.getLanguage(), tdExpression2.getLanguage()) && StringUtils.equalsIgnoreCase(tdExpression1.getBody(), tdExpression2.getBody());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof TdSqlDataType && b instanceof TdSqlDataType) {
        TdSqlDataType tdExpression1 = (TdSqlDataType) a;
        TdSqlDataType tdExpression2 = (TdSqlDataType) b;
        isSame = StringUtils.equalsIgnoreCase(tdExpression1.getName(), tdExpression2.getName());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof MetadataColumn && b instanceof MetadataColumn) {
        // Added yyin TDQ-8360
        MetadataColumn metaColumn1 = (MetadataColumn) a;
        MetadataColumn metaColumn2 = (MetadataColumn) b;
        isSame = StringUtils.equalsIgnoreCase(metaColumn1.getLabel(), metaColumn2.getLabel());
        return isSame ? 0 : Double.MAX_VALUE;
    } else if (a instanceof MetadataTable && b instanceof MetadataTable) {
        MetadataTable mTable1 = (MetadataTable) a;
        MetadataTable mTable2 = (MetadataTable) b;
        isSame = StringUtils.equalsIgnoreCase(mTable1.getLabel(), mTable2.getLabel());
        return isSame ? 0 : Double.MAX_VALUE;
    }
    return super.distance(inProgress, a, b);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) TdView(org.talend.cwm.relational.TdView) TdExpression(org.talend.cwm.relational.TdExpression) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(orgomg.cwm.resource.relational.Schema) MetadataTable(org.talend.core.model.metadata.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 23 with MetadataTable

use of org.talend.core.model.metadata.MetadataTable in project tbd-studio-se by Talend.

the class HadoopSubMultiRepTypeProcessor method selectRepositoryNode.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.repository.ui.processor.SingleTypeProcessor#selectRepositoryNode(org.eclipse.jface.viewers.Viewer,
     * org.talend.repository.model.RepositoryNode, org.talend.repository.model.RepositoryNode)
     */
@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    if (node == null || repositoryTypes == null || repositoryTypes.length == 0) {
        return false;
    }
    ERepositoryObjectType repObjType = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
    if (repObjType == ERepositoryObjectType.REFERENCED_PROJECTS) {
        return true;
    }
    if (node.getType() == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    if (HadoopClusterRepositoryNodeType.HADOOPCLUSTER.equals(repObjType) && ArrayUtils.contains(repositoryTypes, "HADOOPCLUSTER")) {
        // $NON-NLS-1$
        return isValidAttributes(node);
    }
    if (node.getType() == ENodeType.SIMPLE_FOLDER || HCRepositoryUtil.isHadoopContainerNode(node)) {
        return isValidFolder(node);
    }
    IRepositoryViewObject object = node.getObject();
    if (object == null || object.getProperty().getItem() == null) {
        return false;
    }
    if (object instanceof MetadataTable) {
        return false;
    }
    Item item = object.getProperty().getItem();
    if (item instanceof FolderItem) {
        return true;
    }
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.MetadataTable) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 24 with MetadataTable

use of org.talend.core.model.metadata.MetadataTable in project tbd-studio-se by Talend.

the class UIManager method closeNeo4j.

public void closeNeo4j(int response, boolean fromDialog) {
    setNeo4jResponse(response);
    Composite parent = neo4jUI.getNeo4jUIParent();
    saveCurrentUiProperties();
    MetadataTable table = (MetadataTable) neo4jManager.getNeo4jComponent().getMetadataList().get(0);
    boolean hasColumns = (table != null) && (table.getListColumns() != null && table.getListColumns().size() != 0);
    List<Map<String, Object>> originalValuesDataList = neo4jManager.getNeo4jComponent().getOriginalValuesList();
    List<Map<String, Object>> currentValuesDataList = getNewValuesList();
    boolean valuesAll1 = originalValuesDataList.containsAll(currentValuesDataList);
    boolean valuesAll2 = currentValuesDataList.containsAll(originalValuesDataList);
    List<Map<String, Object>> originalIndexesDataList = neo4jManager.getNeo4jComponent().getOriginalIndexesList();
    List<Map<String, Object>> currentIndexesDataList = getNewIndexesList();
    boolean indexesAll1 = originalIndexesDataList.containsAll(currentIndexesDataList);
    boolean indexesAll2 = currentIndexesDataList.containsAll(originalIndexesDataList);
    List<Map<String, Object>> originalRelationshipsDataList = neo4jManager.getNeo4jComponent().getOriginalRelationshipsList();
    List<Map<String, Object>> currentRelationshipsDataList = getNewRelationShipsList();
    boolean relationshipsAll1 = originalRelationshipsDataList.containsAll(currentRelationshipsDataList);
    boolean relationshipsAll2 = currentRelationshipsDataList.containsAll(originalRelationshipsDataList);
    boolean containsAll = valuesAll1 && valuesAll2 && indexesAll1 && indexesAll2 & relationshipsAll1 & relationshipsAll2;
    if (hasColumns && !containsAll && response == SWT.CANCEL) {
        boolean isNotSaveSetting = // $NON-NLS-1$
        MessageDialog.openQuestion(// $NON-NLS-1$
        parent.getShell(), // $NON-NLS-1$
        "Neo4j", "Do you want to close the Neo4j component dialog without save the current settings?");
        if (isNotSaveSetting) {
            saveAllData(originalValuesDataList, originalIndexesDataList, originalRelationshipsDataList);
        } else {
            response = SWT.OK;
            setNeo4jResponse(response);
        }
    }
    if (response == SWT.OK) {
        saveAllData(currentValuesDataList, currentIndexesDataList, currentRelationshipsDataList);
    }
    if (parent instanceof Shell && !fromDialog) {
        ((Shell) parent).close();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) MetadataTable(org.talend.core.model.metadata.MetadataTable) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with MetadataTable

use of org.talend.core.model.metadata.MetadataTable in project tbd-studio-se by Talend.

the class UIManager method getNewValuesList.

private List<Map<String, Object>> getNewValuesList() {
    List<Map<String, Object>> map = new ArrayList<Map<String, Object>>();
    MetadataTable table = (MetadataTable) neo4jManager.getNeo4jComponent().getMetadataList().get(0);
    neo4jManager.convert(neo4jManager.getNeo4jComponent(), table);
    for (IMetadataColumn col : table.getListColumns()) {
        MetadataColumnExt ext = (MetadataColumnExt) col;
        Map<String, Object> value = new HashMap<String, Object>();
        value.put(Neo4jComponent.SCHEMA_COLUMN, ext.getLabel());
        value.put(Neo4jComponent.AUTO_INDEXED, String.valueOf(ext.getData().isAutoIndexed()));
        value.put(Neo4jComponent.INDEX_NAMES, ext.getData().inlineIndexNames());
        map.add(value);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetadataTable(org.talend.core.model.metadata.MetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) HashMap(java.util.HashMap) Map(java.util.Map) MetadataColumnExt(org.talend.designer.neo4j.ui.editor.MetadataColumnExt)

Aggregations

MetadataTable (org.talend.core.model.metadata.MetadataTable)61 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)46 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)29 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)15 Map (java.util.Map)14 IElementParameter (org.talend.core.model.process.IElementParameter)14 Item (org.talend.core.model.properties.Item)14 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)13 IConnection (org.talend.core.model.process.IConnection)13 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 Node (org.talend.designer.core.ui.editor.nodes.Node)11 List (java.util.List)9 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)9 Command (org.eclipse.gef.commands.Command)8 Point (org.eclipse.swt.graphics.Point)8 INode (org.talend.core.model.process.INode)8 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)8 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)8 Connection (org.talend.designer.core.ui.editor.connections.Connection)8