Search in sources :

Example 1 with JSONFileConnection

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

the class JsonPathMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    boolean modified = false;
    if (item instanceof JSONFileConnectionItem) {
        Connection conn = ((JSONFileConnectionItem) item).getConnection();
        if (conn instanceof JSONFileConnection) {
            ((JSONFileConnection) conn).setReadbyMode(EJsonReadbyMode.XPATH.getValue());
            modified = true;
        }
    }
    try {
        if (modified) {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            factory.save(item, true);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JSONFileConnectionItem(org.talend.repository.model.json.JSONFileConnectionItem)

Example 2 with JSONFileConnection

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

the class JSONRepositoryContentHandler method addNode.

@Override
public void addNode(ERepositoryObjectType type, RepositoryNode recBinNode, IRepositoryViewObject repositoryObject, RepositoryNode node) {
    if (type == JSONRepositoryNodeType.JSON) {
        JSONFileConnection connection = (JSONFileConnection) ((JSONFileConnectionItem) repositoryObject.getProperty().getItem()).getConnection();
        Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
        for (MetadataTable metadataTable : tableset) {
            if (!SubItemHelper.isDeleted(metadataTable)) {
                RepositoryNode tableNode = RepositoryNodeManager.createMetatableNode(node, repositoryObject, metadataTable);
                node.getChildren().add(tableNode);
                if (metadataTable.getColumns().size() > 0) {
                    RepositoryNodeManager.createColumns(tableNode, repositoryObject, metadataTable);
                }
            }
        }
    }
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 3 with JSONFileConnection

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

the class JsonFileService method changeFilePathFromRepository.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.core.service.IJsonFileService#getFilePathFromRepository(org.talend.core.model.metadata.builder.connection
     * .Connection, java.lang.String, org.talend.core.model.process.IElement)
     */
@Override
public boolean changeFilePathFromRepository(Object jsonConneciton, IElementParameter filePathParm, IElement elem, Object value) {
    boolean isParamChanged = false;
    if (jsonConneciton instanceof JSONFileConnection && "FILE_PATH".equals(filePathParm.getRepositoryValue())) {
        if (LinkUtils.isRemoteFile(TalendTextUtils.removeQuotes(String.valueOf(value)))) {
            elem.setPropertyValue("USEURL", true);
            IElementParameter elementParameter = elem.getElementParameter("URLPATH");
            if (elementParameter != null) {
                elementParameter.setRepositoryValueUsed(true);
            }
            isParamChanged = true;
        } else {
            IElementParameter elementParameter = elem.getElementParameter("FILENAME");
            if (elementParameter != null) {
                elementParameter.setRepositoryValueUsed(true);
            }
            elem.setPropertyValue("USEURL", false);
        }
        elem.setPropertyValue("URLPATH", value);
        // store the filepath in this param also
        elem.setPropertyValue(filePathParm.getName(), value);
    }
    return isParamChanged;
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 4 with JSONFileConnection

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

the class JSONConnectionContextUtils method cloneOriginalValueJSONFileConnection.

//$NON-NLS-1$
@SuppressWarnings("unchecked")
public static JSONFileConnection cloneOriginalValueJSONFileConnection(JSONFileConnection fileConn, ContextType contextType) {
    if (fileConn == null) {
        return null;
    }
    JSONFileConnection cloneConn = JsonFactory.eINSTANCE.createJSONFileConnection();
    String filePath = ConnectionContextHelper.getOriginalValue(contextType, fileConn.getJSONFilePath());
    String encoding = ConnectionContextHelper.getOriginalValue(contextType, fileConn.getEncoding());
    filePath = TalendQuoteUtils.removeQuotes(filePath);
    cloneConn.setJSONFilePath(filePath);
    encoding = TalendQuoteUtils.removeQuotes(encoding);
    cloneConn.setEncoding(encoding);
    //
    cloneConn.setMaskXPattern(fileConn.getMaskXPattern());
    cloneConn.setGuess(fileConn.isGuess());
    ConnectionContextHelper.cloneConnectionProperties(fileConn, cloneConn);
    cloneConn.getSchema().clear();
    List<JSONXPathLoopDescriptor> descs = (List<JSONXPathLoopDescriptor>) fileConn.getSchema();
    for (JSONXPathLoopDescriptor desc : descs) {
        JSONXPathLoopDescriptor cloneDesc = JsonFactory.eINSTANCE.createJSONXPathLoopDescriptor();
        cloneDesc.setLimitBoucle(desc.getLimitBoucle().intValue());
        String xPathQuery = ConnectionContextHelper.getOriginalValue(contextType, desc.getAbsoluteXPathQuery());
        xPathQuery = TalendQuoteUtils.removeQuotes(xPathQuery);
        cloneDesc.setAbsoluteXPathQuery(xPathQuery);
        cloneDesc.getSchemaTargets().clear();
        List<org.talend.repository.model.json.SchemaTarget> schemaTargets = (List<org.talend.repository.model.json.SchemaTarget>) desc.getSchemaTargets();
        for (org.talend.repository.model.json.SchemaTarget schemaTarget : schemaTargets) {
            org.talend.repository.model.json.SchemaTarget cloneSchemaTarget = JsonFactory.eINSTANCE.createSchemaTarget();
            cloneSchemaTarget.setRelativeXPathQuery(schemaTarget.getRelativeXPathQuery());
            cloneSchemaTarget.setTagName(schemaTarget.getTagName());
            cloneSchemaTarget.setSchema(cloneDesc);
            cloneDesc.getSchemaTargets().add(cloneSchemaTarget);
        }
        cloneDesc.setConnection(cloneConn);
        cloneConn.getSchema().add(cloneDesc);
    }
    return cloneConn;
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) List(java.util.List)

Example 5 with JSONFileConnection

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

the class JSONConnectionContextHelper method setPropertiesForContextMode.

public static void setPropertiesForContextMode(ConnectionItem connectionItem, ContextItem contextItem, Set<IConnParamName> paramSet, Map<String, String> map) {
    if (connectionItem == null || contextItem == null) {
        return;
    }
    final String label = contextItem.getProperty().getLabel();
    Connection conn = connectionItem.getConnection();
    if (conn instanceof JSONFileConnection) {
        setJSONFilePropertiesForContextMode(label, (JSONFileConnection) conn);
    }
    // set connection for context mode
    connectionItem.getConnection().setContextMode(true);
    connectionItem.getConnection().setContextId(contextItem.getProperty().getId());
    connectionItem.getConnection().setContextName(contextItem.getDefaultContext());
}
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)

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