Search in sources :

Example 86 with MetadataTable

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

the class ImportTreeFromRepository method prepareEmfTreeFromMdm.

private void prepareEmfTreeFromMdm(MDMConnection connection, String selectedConcept) throws Exception {
    if (connection == null || selectedConcept == null) {
        return;
    }
    EList<Concept> schemas = connection.getSchemas();
    Concept selected = null;
    for (int i = 0; i < schemas.size(); i++) {
        Concept concept = schemas.get(i);
        if (selectedConcept.equals(concept.getLabel())) {
            selected = concept;
            break;
        }
    }
    if (selected != null) {
        IMDMProviderService service = (IMDMProviderService) GlobalServiceRegister.getDefault().getService(IMDMProviderService.class);
        if (service != null) {
            boolean initConcepts = service.initConcepts(connection);
            if (initConcepts) {
                if (!MdmConceptType.OUTPUT.equals(selected.getConceptType())) {
                    String prefix = service.getXPathPrefixValue(selected);
                    prefix = TalendTextUtils.removeQuotes(prefix);
                    absoluteXPathQuery = selected.getLoopExpression();
                    EList<ConceptTarget> conceptTargets = selected.getConceptTargets();
                    if (conceptTargets == null || absoluteXPathQuery == null) {
                        return;
                    }
                    this.schemaTargets = conceptTargets;
                    // find corresponding metadata table
                    Set<MetadataTable> metadataTables = ConnectionHelper.getTables(connection);
                    for (MetadataTable table : metadataTables) {
                        if (selected.getLabel() != null && selected.getLabel().equals(table.getLabel())) {
                            metadataTable = table;
                            break;
                        }
                    }
                    List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), absoluteXPathQuery, true);
                    TreeNode pNode = schemaNode;
                    if (MdmConceptType.RECEIVE.equals(selected.getConceptType())) {
                        List<FOXTreeNode> updateNodesList = TreeUtil.parseMDMUpdateReport(shell, true);
                        schemaNode.getChildren().clear();
                        if (updateNodesList == null) {
                            if (prefix != null && !"".equals(prefix)) {
                                String[] preValues = prefix.split(XmlMapUtil.XPATH_SEPARATOR);
                                for (String value : preValues) {
                                    if (!"".equals(value)) {
                                        TreeNode createTreeNode = createModel();
                                        createTreeNode.setName(value);
                                        createTreeNode.setNodeType(NodeType.ELEMENT);
                                        createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                                        createTreeNode.setXpath(XmlMapUtil.getXPath(pNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                        pNode.getChildren().add(createTreeNode);
                                        pNode = createTreeNode;
                                    }
                                }
                                absoluteXPathQuery = prefix + absoluteXPathQuery;
                            }
                        } else {
                            //$NON-NLS-1$
                            TreeNode rootNode = createDefaultTreeNode(pNode, "exchange");
                            //$NON-NLS-1$
                            TreeNode reportNode = createDefaultTreeNode(rootNode, "report");
                            //$NON-NLS-1$
                            TreeNode itemNode = createDefaultTreeNode(rootNode, "item");
                            // parse the update content..
                            prepareEmfTree(updateNodesList, reportNode, true);
                            pNode = itemNode;
                            //$NON-NLS-1$
                            absoluteXPathQuery = "/exchange/item" + absoluteXPathQuery;
                        }
                    } else {
                        schemaNode.getChildren().clear();
                    }
                    prepareEmfTree(list, pNode);
                } else {
                    List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), selected.getRoot().get(0).getXMLPath(), true);
                    schemaNode.getChildren().clear();
                    root = selected.getRoot();
                    loop = selected.getLoop();
                    group = selected.getGroup();
                    groupElements = new ArrayList<TreeNode>();
                    prepareModelFromOutput(list, schemaNode);
                    if (loopNode != null) {
                        fillGroup(loopNode, groupElements);
                    } else {
                        if (!schemaNode.getChildren().isEmpty()) {
                            schemaNode.getChildren().get(0).setLoop(true);
                        }
                    }
                }
            }
        }
    }
}
Also used : Concept(org.talend.core.model.metadata.builder.connection.Concept) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IMDMProviderService(org.talend.core.ui.IMDMProviderService) ConceptTarget(org.talend.core.model.metadata.builder.connection.ConceptTarget) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Example 87 with MetadataTable

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

the class NewDelimitedFileWizardMigrationTask method updateMetadataTable.

@Override
protected boolean updateMetadataTable(Connection oldConnection, Connection genericConnection, ComponentProperties componentProperties) {
    boolean modified = false;
    if (oldConnection == null || genericConnection == null || componentProperties == null) {
        return modified;
    }
    Set<MetadataTable> tables = ConnectionHelper.getTables(oldConnection);
    Set<MetadataTable> newTables = new HashSet<>(tables);
    for (MetadataTable metaTable : newTables) {
        TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
        serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
        serializedPropsTV.setValue(componentProperties.toSerialized());
        metaTable.getTaggedValue().add(serializedPropsTV);
        TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
        schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
        schemaPropertyTV.setValue(SCHEMA);
        metaTable.getTaggedValue().add(schemaPropertyTV);
        ((orgomg.cwm.objectmodel.core.Package) genericConnection).getOwnedElement().add(metaTable);
        Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(metaTable);
        componentProperties.setValue(SCHEMA, schema);
        modified = true;
    }
    return modified;
}
Also used : TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) HashSet(java.util.HashSet)

Example 88 with MetadataTable

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

the class NewSalesforceWizardMigrationTask method updateMetadataTable.

@Override
protected boolean updateMetadataTable(Connection oldConnection, Connection genericConnection, ComponentProperties componentProperties) {
    boolean modified = false;
    if (oldConnection == null || genericConnection == null || componentProperties == null) {
        return modified;
    }
    Set<MetadataTable> tables = ConnectionHelper.getTables(oldConnection);
    Set<MetadataTable> newTables = new HashSet<>();
    newTables.addAll(tables);
    for (MetadataTable metaTable : newTables) {
        try {
            Object object = ReflectionUtils.newInstance(REFLECTION_SALESFORCE_MODULE_PROPERTIES, componentProperties.getClass().getClassLoader(), new Object[] { metaTable.getName() });
            if (object != null && object instanceof ComponentProperties) {
                ComponentProperties salesforceModuleProperties = (ComponentProperties) object;
                //$NON-NLS-1$
                salesforceModuleProperties.getProperties("connection").copyValuesFrom(componentProperties, true, false);
                //$NON-NLS-1$
                NamedThing tmp = salesforceModuleProperties.getProperty("moduleName");
                //$NON-NLS-1$
                ((Property) tmp).setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "moduleName");
                ((Property) tmp).setValue(metaTable.getLabel());
                TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
                serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
                serializedPropsTV.setValue(salesforceModuleProperties.toSerialized());
                metaTable.getTaggedValue().add(serializedPropsTV);
                TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
                schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
                schemaPropertyTV.setValue(SCHEMA_SCHEMA);
                metaTable.getTaggedValue().add(schemaPropertyTV);
                Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(metaTable);
                salesforceModuleProperties.setValue(SCHEMA_SCHEMA, schema);
                ((orgomg.cwm.objectmodel.core.Package) genericConnection).getOwnedElement().add(metaTable);
                modified = true;
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    return modified;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) NamedThing(org.talend.daikon.NamedThing) IOException(java.io.IOException) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.daikon.properties.property.Property) HashSet(java.util.HashSet)

Example 89 with MetadataTable

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

the class SchemaUtils method getMetadataTables.

public static List<MetadataTable> getMetadataTables(orgomg.cwm.objectmodel.core.Package parentPackage, Class containerTypeClass) {
    List<MetadataTable> metadataTables = new ArrayList<>();
    metadataTables.addAll(PackageHelper.getOwnedElements(parentPackage, MetadataTable.class));
    if (containerTypeClass != null) {
        List subContainers = PackageHelper.getOwnedElements(parentPackage, containerTypeClass);
        for (Object subContainer : subContainers) {
            if (subContainer instanceof orgomg.cwm.objectmodel.core.Package) {
                orgomg.cwm.objectmodel.core.Package subContainerPackage = (orgomg.cwm.objectmodel.core.Package) subContainer;
                metadataTables.addAll(getMetadataTables(subContainerPackage, containerTypeClass));
            }
        }
    }
    return metadataTables;
}
Also used : ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)

Example 90 with MetadataTable

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

the class SchemaUtils method getCurrentComponentProperties.

public static ComponentProperties getCurrentComponentProperties(IMetadataTable table) {
    if (table != null) {
        String serializedProperties = null;
        SerializerDeserializer.Deserialized<ComponentProperties> fromSerializedProperties = null;
        if (table instanceof MetadataTableRepositoryObject) {
            MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) table;
            MetadataTable metadataTable = metaTableRepObj.getTable();
            if (metadataTable != null && metadataTable.getTaggedValue() != null) {
                for (TaggedValue serializedProps : metadataTable.getTaggedValue()) {
                    if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(serializedProps.getTag())) {
                        serializedProperties = serializedProps.getValue();
                        break;
                    }
                }
            }
            if (serializedProperties != null) {
                Connection connection = ((ConnectionItem) metaTableRepObj.getViewObject().getProperty().getItem()).getConnection();
                return ComponentsUtils.getComponentPropertiesFromSerialized(serializedProperties, connection);
            }
        } else if (table instanceof org.talend.core.model.metadata.MetadataTable) {
            org.talend.core.model.metadata.MetadataTable metaTable = (org.talend.core.model.metadata.MetadataTable) table;
            Map<String, String> additionalProperties = metaTable.getAdditionalProperties();
            serializedProperties = additionalProperties.get(IComponentConstants.COMPONENT_PROPERTIES_TAG);
            if (serializedProperties != null) {
                fromSerializedProperties = Properties.Helper.fromSerializedPersistent(serializedProperties, ComponentProperties.class, null);
            }
        }
        if (fromSerializedProperties != null) {
            return fromSerializedProperties.object;
        }
    }
    return null;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SerializerDeserializer(org.talend.daikon.serialize.SerializerDeserializer) Map(java.util.Map)

Aggregations

MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)153 ArrayList (java.util.ArrayList)53 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)51 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)25 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)22 List (java.util.List)18 Test (org.junit.Test)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)14 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)14 Connection (org.talend.core.model.metadata.builder.connection.Connection)12 RepositoryNode (org.talend.repository.model.RepositoryNode)12 ConnectionItem (org.talend.core.model.properties.ConnectionItem)10 TdColumn (org.talend.cwm.relational.TdColumn)9 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 IRepositoryNode (org.talend.repository.model.IRepositoryNode)9 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)8 HashMap (java.util.HashMap)7