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;
}
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);
}
}
}
}
}
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;
}
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;
}
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());
}
Aggregations