Search in sources :

Example 21 with MetadataColumn

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

the class HL7Message2SchemaDragAndDropHandler method copyColumn.

protected MetadataColumn copyColumn(MetadataColumn column) {
    MetadataColumn newColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
    newColumn.setComment(column.getComment());
    newColumn.setDefaultValue(column.getDefaultValue());
    newColumn.setKey(column.isKey());
    newColumn.setLabel(column.getLabel());
    newColumn.setPattern(column.getPattern());
    if (column.getLength() < 0) {
        newColumn.setLength(0);
    } else {
        newColumn.setLength(column.getLength());
    }
    newColumn.setNullable(column.isNullable());
    if (column.getPrecision() < 0) {
        newColumn.setPrecision(0);
    } else {
        newColumn.setPrecision(column.getPrecision());
    }
    newColumn.setTalendType(column.getTalendType());
    newColumn.setSourceType(column.getSourceType());
    if (column.getOriginalField() == null || column.getOriginalField().equals("")) {
        //$NON-NLS-1$
        newColumn.setLabel(column.getLabel());
    } else {
        newColumn.setOriginalField(column.getOriginalField());
    }
    return newColumn;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn)

Example 22 with MetadataColumn

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

the class JSONWizard method performFinish.

/**
     * This method determine if the 'Finish' button is enable This method is called when 'Finish' button is pressed in
     * the wizard. We will create an operation and run it using wizard as execution context.
     */
@Override
public boolean performFinish() {
    boolean formIsPerformed = false;
    IWizardPage finalPage = getCurrentPage();
    if (finalPage == null) {
        finalPage = propertiesWizardPage;
    }
    // deleteTemFile();
    if (connection.isInputModel()) {
        if (finalPage instanceof JSONFileWizardPage) {
            int step = ((JSONFileWizardPage) finalPage).step;
            if (step == 2) {
                formIsPerformed = finalPage.isPageComplete();
                if (formIsPerformed) {
                    List schemas = connection.getSchema();
                    Set tables = ConnectionHelper.getTables(connection);
                    if (!schemas.isEmpty() && !tables.isEmpty()) {
                        JSONXPathLoopDescriptor currentSchema = (JSONXPathLoopDescriptor) schemas.get(0);
                        MetadataTable currentTable = (MetadataTable) tables.toArray(new MetadataTable[0])[0];
                        if (!currentSchema.getAbsoluteXPathQuery().equals(oldAbstractQueryPath)) {
                            resetMetadata(currentSchema.getSchemaTargets(), true);
                        } else {
                            resetMetadata(currentSchema.getSchemaTargets(), false);
                        }
                    }
                }
            } else {
                formIsPerformed = finalPage.isPageComplete();
            }
        } else {
            formIsPerformed = finalPage.isPageComplete();
        }
    } else {
        formIsPerformed = finalPage.isPageComplete();
    }
    if (formIsPerformed) {
        final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        final IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (creation) {
                            String nextId = factory.getNextId();
                            connectionProperty.setId(nextId);
                            // changed by hqzhang for TDI-19527, label=displayName
                            connectionProperty.setLabel(connectionProperty.getDisplayName());
                            final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                                @Override
                                protected void run() throws LoginException, PersistenceException {
                                    factory.create(connectionItem, propertiesWizardPage.getDestinationPath());
                                }
                            };
                            workUnit.setAvoidUnloadResources(true);
                            factory.executeRepositoryWorkUnit(workUnit);
                        } else {
                            // changed by hqzhang for TDI-19527, label=displayName
                            connectionProperty.setLabel(connectionProperty.getDisplayName());
                            // update schemas
                            Map<String, SchemaTarget> schemaTargetMap = new HashMap<String, SchemaTarget>();
                            EList<JSONXPathLoopDescriptor> schema = connection.getSchema();
                            if (schema != null && schema.size() > 0) {
                                JSONXPathLoopDescriptor jsonXPathLoopDescriptor = schema.get(0);
                                if (jsonXPathLoopDescriptor != null) {
                                    EList<SchemaTarget> schemaTargets = jsonXPathLoopDescriptor.getSchemaTargets();
                                    if (schemaTargets != null && schemaTargets.size() > 0) {
                                        for (SchemaTarget schemaTarget : schemaTargets) {
                                            schemaTargetMap.put(schemaTarget.getTagName(), schemaTarget);
                                        }
                                    }
                                }
                            }
                            Map<String, MetadataColumn> columnsMap = new HashMap<String, MetadataColumn>();
                            MetadataTable[] tables = ConnectionHelper.getTables(connectionItem.getConnection()).toArray(new MetadataTable[0]);
                            for (MetadataTable table : tables) {
                                EList<MetadataColumn> columns = table.getColumns();
                                Iterator<MetadataColumn> columnsIter = columns.iterator();
                                while (columnsIter.hasNext()) {
                                    MetadataColumn column = columnsIter.next();
                                    if (connection.isInputModel()) {
                                        if (schemaTargetMap.get(column.getLabel()) == null) {
                                            columnsIter.remove();
                                        } else {
                                            columnsMap.put(column.getLabel(), column);
                                        }
                                    } else {
                                        columnsMap.put(column.getLabel(), column);
                                    }
                                }
                            }
                            boolean hasAddedColumns = false;
                            Iterator<Entry<String, SchemaTarget>> schemaTargetIter = schemaTargetMap.entrySet().iterator();
                            while (schemaTargetIter.hasNext()) {
                                Map.Entry<String, SchemaTarget> entry = schemaTargetIter.next();
                                String key = entry.getKey();
                                if (columnsMap.get(key) == null) {
                                    hasAddedColumns = true;
                                    break;
                                }
                            }
                            if (hasAddedColumns) {
                                MessageDialog.openInformation(getShell(), "Detect new columns", "There are some new fields to extract, guess your schema manually if you want to apply the update.");
                            }
                            // update
                            RepositoryUpdateManager.updateFileConnection(connectionItem);
                            refreshInFinish(propertiesWizardPage.isNameModifiedByUser());
                            final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                                @Override
                                protected void run() throws LoginException, PersistenceException {
                                    factory.save(connectionItem);
                                }
                            };
                            workUnit.setAvoidUnloadResources(true);
                            factory.executeRepositoryWorkUnit(workUnit);
                            closeLockStrategy();
                        }
                        final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                            @Override
                            protected void run() throws LoginException, PersistenceException {
                                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                            }
                        };
                        workUnit.setAvoidUnloadResources(true);
                        factory.executeRepositoryWorkUnit(workUnit);
                    }
                });
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    // the update the project files need to be done in the workspace runnable to avoid all
                    // notification
                    // of changes before the end of the modifications.
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(true, true, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        //
        }
        return true;
    } else {
        return false;
    }
}
Also used : Set(java.util.Set) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Entry(java.util.Map.Entry) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) SchemaTarget(org.talend.repository.model.json.SchemaTarget) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EList(org.eclipse.emf.common.util.EList) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IWizardPage(org.eclipse.jface.wizard.IWizardPage) Map(java.util.Map) HashMap(java.util.HashMap)

Example 23 with MetadataColumn

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

the class JSONFileOutputStep2Form method initLinker.

private void initLinker(TreeItem node, TableItem[] tableItems) {
    FOXTreeNode treeNode = (FOXTreeNode) node.getData();
    IMetadataColumn column = treeNode.getColumn();
    Properties prop = System.getProperties();
    String os = prop.getProperty("os.name");
    boolean isLastOne = false;
    if (column != null) {
        for (int i = 0; i < tableItems.length; i++) {
            MetadataColumn metadataColumn = (MetadataColumn) tableItems[i].getData();
            if (metadataColumn.getLabel().equals(column.getLabel())) {
                // "isLastOne" directly to false
                if (os.startsWith("Linux")) {
                    isLastOne = true;
                }
                linker.addLoopLink(tableItems[i], tableItems[i].getData(), JSONViewer.getTree(), treeNode, isLastOne);
                break;
            }
        }
    }
    TreeItem[] children = node.getItems();
    for (int i = 0; i < children.length; i++) {
        initLinker(children[i], tableItems);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TreeItem(org.eclipse.swt.widgets.TreeItem) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Properties(java.util.Properties)

Example 24 with MetadataColumn

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

the class JSONFileOutputStep3Form method createMetadataColumn.

private List<MetadataColumn> createMetadataColumn(EList list) {
    List<MetadataColumn> columnList = new ArrayList<MetadataColumn>();
    if (list.size() == 0) {
        return columnList;
    }
    for (int i = 0; i < list.size(); i++) {
        JSONFileNode node = (JSONFileNode) list.get(i);
        String label = node.getRelatedColumn();
        if (label != null && !label.equals("")) {
            MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
            metadataColumn.setLabel(label);
            metadataColumn.setOriginalField(label);
            String type = node.getType();
            if (type != null) {
                metadataColumn.setTalendType(type);
            }
            columnList.add(metadataColumn);
        }
    }
    return columnList;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) JSONFileNode(org.talend.repository.model.json.JSONFileNode) ArrayList(java.util.ArrayList)

Example 25 with MetadataColumn

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

the class JSONFileOutputStep2Form method initSchemaTable.

private void initSchemaTable() {
    List<MetadataColumn> columnList = new ArrayList<MetadataColumn>();
    if (ConnectionHelper.getTables(getConnection()).size() > 0) {
        EList columns = ConnectionHelper.getTables(getConnection()).toArray(new MetadataTable[0])[0].getColumns();
        for (int i = 0; i < columns.size(); i++) {
            columnList.add((MetadataColumn) columns.get(i));
        }
    }
    schemaViewer.setInput(columnList);
    schemaViewer.refresh();
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList)

Aggregations

MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)59 ArrayList (java.util.ArrayList)27 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)22 List (java.util.List)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)10 IModel (org.talend.designer.hl7.model.IModel)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Command (org.eclipse.gef.commands.Command)7 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 ExtendedTableResetDBTypesCommand (org.talend.core.ui.metadata.extended.command.ExtendedTableResetDBTypesCommand)5 MetadataEmfExportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfExportXmlCommand)5 MetadataEmfImportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfImportXmlCommand)5 MetadataEmfPasteCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand)5 HL7MultiSchemaUI (org.talend.designer.hl7.ui.HL7MultiSchemaUI)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4