Search in sources :

Example 16 with JSONFileConnection

use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.

the class FileJSONTableWizardPage method createControl.

/**
     * Create the first composite, addComponentsAndControls and initialize TableWizardPage.
     * 
     * @see IDialogPage#createControl(Composite)
     */
public void createControl(final Composite parent) {
    final AbstractForm.ICheckListener listener = new AbstractForm.ICheckListener() {

        public void checkPerformed(final AbstractForm source) {
            if (source.isStatusOnError()) {
                FileJSONTableWizardPage.this.setPageComplete(false);
                setErrorMessage(source.getStatus());
            } else {
                FileJSONTableWizardPage.this.setPageComplete(isRepositoryObjectEditable);
                setErrorMessage(null);
                setMessage(source.getStatus(), source.getStatusLevel());
            }
        }
    };
    Composite theForm = null;
    Connection connection = null;
    if (metadataTable.getNamespace() != null) {
        if (metadataTable.getNamespace() instanceof Package) {
            Package pkg = (Package) metadataTable.getNamespace();
            if (!pkg.getDataManager().isEmpty()) {
                connection = (Connection) pkg.getDataManager().get(0);
            }
        }
    }
    theForm = (Composite) new JsonSwitch() {

        public Object caseJSONFileConnection(final JSONFileConnection object) {
            JSONFileConnection jsonFileConnection = (JSONFileConnection) connectionItem.getConnection();
            boolean isInputModel = jsonFileConnection.isInputModel();
            if (isInputModel) {
                JSONFileStep3Form xmlFileStep3Form = new JSONFileStep3Form(parent, connectionItem, metadataTable, null, TableHelper.getTableNames(object, metadataTable.getLabel()));
                xmlFileStep3Form.setReadOnly(!isRepositoryObjectEditable);
                xmlFileStep3Form.setListener(listener);
                return xmlFileStep3Form;
            } else {
                JSONFileOutputStep3Form xmlFileOutputStep3Form = new JSONFileOutputStep3Form(parent, connectionItem, metadataTable, TableHelper.getTableNames(object, metadataTable.getLabel()));
                xmlFileOutputStep3Form.setReadOnly(!isRepositoryObjectEditable);
                xmlFileOutputStep3Form.setListener(listener);
                return xmlFileOutputStep3Form;
            }
        }
    }.doSwitch(connection);
    setControl(theForm);
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Composite(org.eclipse.swt.widgets.Composite) JsonSwitch(org.talend.repository.model.json.util.JsonSwitch) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) AbstractForm(org.talend.metadata.managment.ui.wizard.AbstractForm) Package(orgomg.cwm.objectmodel.core.Package)

Example 17 with JSONFileConnection

use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.

the class JSONDragAndDropHandler method getTableJSONMappingValue.

private List<Map<String, Object>> getTableJSONMappingValue(Connection connection) {
    List<Map<String, Object>> tableInfo = new ArrayList<Map<String, Object>>();
    if (connection instanceof JSONFileConnection) {
        JSONFileConnection jsonConnection = (JSONFileConnection) connection;
        if (jsonConnection.isInputModel()) {
            EList objectList = jsonConnection.getSchema();
            JSONXPathLoopDescriptor jsonDesc = (JSONXPathLoopDescriptor) objectList.get(0);
            List<SchemaTarget> schemaTargets = jsonDesc.getSchemaTargets();
            tableInfo.clear();
            String tagName;
            for (int j = 0; j < schemaTargets.size(); j++) {
                SchemaTarget schemaTarget = schemaTargets.get(j);
                if (schemaTarget.getTagName() != null && !schemaTarget.getTagName().equals("")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$
                    tagName = "" + schemaTarget.getTagName().trim().replaceAll(" ", "_");
                    tagName = MetadataToolHelper.validateColumnName(tagName, j);
                    Map<String, Object> map = new HashMap<String, Object>();
                    //$NON-NLS-1$
                    map.put("SCHEMA_COLUMN", tagName);
                    String xpath = schemaTarget.getRelativeXPathQuery();
                    String flag = jsonDesc.getFlag();
                    if (flag != null && flag.equals(ConvertJSONString.ROOT)) {
                        if (xpath.startsWith("root/")) {
                            xpath = xpath.replaceFirst("root/", "");
                        }
                    } else if (flag != null && flag.equals(ConvertJSONString.ROOT_OBJECT)) {
                        if (xpath.startsWith("object/")) {
                            xpath = xpath.replaceFirst("object/", "");
                        }
                    }
                    //$NON-NLS-1$
                    map.put("QUERY", TalendQuoteUtils.addQuotes(xpath));
                    tableInfo.add(map);
                }
            }
        }
    }
    return tableInfo;
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConvertJSONString(org.talend.repository.json.util.ConvertJSONString) SchemaTarget(org.talend.repository.model.json.SchemaTarget) EList(org.eclipse.emf.common.util.EList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with JSONFileConnection

use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.

the class JSONDragAndDropHandler method filterNeededComponents.

@Override
public List<IComponent> filterNeededComponents(Item item, RepositoryNode seletetedNode, ERepositoryObjectType type) {
    List<IComponent> neededComponents = new ArrayList<IComponent>();
    if (!(item instanceof JSONFileConnectionItem)) {
        return neededComponents;
    }
    IComponentsService service = (IComponentsService) GlobalServiceRegister.getDefault().getService(IComponentsService.class);
    Set<IComponent> components = service.getComponentsFactory().getComponents();
    JSONFileConnection connection = (JSONFileConnection) ((JSONFileConnectionItem) item).getConnection();
    for (IComponent component : components) {
        if (!connection.isInputModel()) {
            if (isValid(item, type, seletetedNode, component, "JSONOUTPUT") && !neededComponents.contains(component)) {
                neededComponents.add(component);
            }
        } else {
            if (isValid(item, type, seletetedNode, component, JSON) && !neededComponents.contains(component)) {
                neededComponents.add(component);
            }
        }
    }
    // type);
    return neededComponents;
}
Also used : IComponentsService(org.talend.core.model.components.IComponentsService) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) JSONFileConnectionItem(org.talend.repository.model.json.JSONFileConnectionItem)

Example 19 with JSONFileConnection

use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.

the class CreateJSONSchemaAction method doRun.

@Override
protected void doRun() {
    if (repositoryNode == null) {
        repositoryNode = getCurrentRepositoryNode();
    }
    JSONFileConnection connection = null;
    MetadataTable metadataTable = null;
    boolean creation = false;
    if (repositoryNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
        ERepositoryObjectType nodeType = (ERepositoryObjectType) repositoryNode.getProperties(EProperties.CONTENT_TYPE);
        String metadataTableLabel = (String) repositoryNode.getProperties(EProperties.LABEL);
        JSONFileConnectionItem item = null;
        if (nodeType == ERepositoryObjectType.METADATA_CON_TABLE) {
            item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
            connection = (JSONFileConnection) item.getConnection();
            metadataTable = TableHelper.findByLabel(connection, metadataTableLabel);
            creation = false;
        } else if (nodeType == JSONRepositoryNodeType.JSON) {
            item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
            connection = (JSONFileConnection) item.getConnection();
            metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
            String nextId = ProxyRepositoryFactory.getInstance().getNextId();
            metadataTable.setId(nextId);
            metadataTable.setLabel(getStringIndexed(metadataTable.getLabel()));
            RecordFile record = (RecordFile) ConnectionHelper.getPackage(connection.getName(), connection, RecordFile.class);
            if (record != null) {
                // hywang
                PackageHelper.addMetadataTable(metadataTable, record);
            } else {
                RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
                ConnectionHelper.addPackage(newrecord, connection);
                PackageHelper.addMetadataTable(metadataTable, newrecord);
            }
            creation = true;
        } else {
            return;
        }
        initContextMode(item);
        openJSONSchemaWizard(item, metadataTable, false, creation);
    }
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) RecordFile(orgomg.cwm.resource.record.RecordFile) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) JSONFileConnectionItem(org.talend.repository.model.json.JSONFileConnectionItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 20 with JSONFileConnection

use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method createContextParameters.

private static List<IContextParameter> createContextParameters(ConnectionItem connectionItem, Set<IConnParamName> paramSet) {
    if (connectionItem == null) {
        return null;
    }
    final String label = convertContextLabel(connectionItem.getProperty().getLabel());
    Connection conn = connectionItem.getConnection();
    List<IContextParameter> varList = null;
    if (conn instanceof JSONFileConnection) {
        varList = getJSONFileVariables(label, (JSONFileConnection) conn);
    }
    return varList;
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) IContextParameter(org.talend.core.model.process.IContextParameter)

Aggregations

JSONFileConnection (org.talend.repository.model.json.JSONFileConnection)21 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 ArrayList (java.util.ArrayList)4 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)4 EList (org.eclipse.emf.common.util.EList)3 ProcessDescription (org.talend.metadata.managment.ui.preview.ProcessDescription)3 AbstractForm (org.talend.metadata.managment.ui.wizard.AbstractForm)3 JSONFileConnectionItem (org.talend.repository.model.json.JSONFileConnectionItem)3 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 Composite (org.eclipse.swt.widgets.Composite)2 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 IDesignerCoreUIService (org.talend.core.ui.services.IDesignerCoreUIService)2 CsvArray (org.talend.core.utils.CsvArray)2 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)2 JSONXPathLoopDescriptor (org.talend.repository.model.json.JSONXPathLoopDescriptor)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GridData (org.eclipse.swt.layout.GridData)1