use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method setJSONFilePropertiesForContextMode.
static void setJSONFilePropertiesForContextMode(String prefixName, JSONFileConnection conn) {
if (conn == null || prefixName == null) {
return;
}
prefixName = prefixName + LINE;
String paramName = null;
if (conn.isInputModel()) {
paramName = prefixName + EParamName.FilePath;
conn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
paramName = prefixName + EParamName.Encoding;
conn.setEncoding(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
EList schema = conn.getSchema();
if (schema != null) {
if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
paramName = prefixName + EParamName.XPathQuery;
descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
}
}
} else {
paramName = prefixName + EParamName.OutputFilePath;
conn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(paramName, LANGUAGE));
}
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method setJSONFilePropertiesForExistContextMode.
static void setJSONFilePropertiesForExistContextMode(JSONFileConnection jsonConn, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
if (jsonConn == null) {
return;
}
String jsonVariableName = null;
for (IConnParamName param : paramSet) {
if (param instanceof EParamName) {
EParamName jsonParam = (EParamName) param;
if (map != null && map.size() > 0) {
for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : map.entrySet()) {
List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
for (ConectionAdaptContextVariableModel model : modelList) {
if (model.getValue().equals(jsonParam.name())) {
jsonVariableName = model.getName();
break;
}
}
}
}
if (jsonConn.isInputModel()) {
switch(jsonParam) {
case FilePath:
jsonConn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
break;
case Encoding:
jsonConn.setEncoding(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
break;
case XPathQuery:
EList schema = jsonConn.getSchema();
if (schema != null) {
if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
}
}
default:
}
} else {
if (jsonParam.equals(EParamName.OutputFilePath)) {
jsonConn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
}
}
}
}
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONToXPathLinker method initLoopListeners.
/**
* DOC amaumont Comment method "initListeners".
*/
private void initLoopListeners() {
JSONExtractorLoopModel loopModel = this.loopTableEditorView.getModel();
final Table loopTable = this.loopTableEditorView.getTableViewerCreator().getTable();
loopModelModifiedBeanListener = new IModifiedBeanListener<JSONXPathLoopDescriptor>() {
@Override
public void handleEvent(ModifiedBeanEvent<JSONXPathLoopDescriptor> event) {
handleModifiedBeanEvent(event);
}
private void handleModifiedBeanEvent(ModifiedBeanEvent<JSONXPathLoopDescriptor> event) {
if (event.column == loopTableEditorView.getXPathColumn()) {
onXPathValueChanged(loopTable, (String) event.newValue, event.index);
}
}
};
loopModel.addModifiedBeanListener(loopModelModifiedBeanListener);
loopTableExtendedControlListener = new IExtendedControlListener() {
@Override
public void handleEvent(ExtendedControlEvent event) {
if (event.getType() == EVENT_TYPE.MODEL_CHANGED) {
nodeRetriever.setCurrentLoopXPath(getCurrentLoopXPath());
}
}
};
this.loopTableEditorView.getExtendedTableViewer().addListener(loopTableExtendedControlListener);
SelectionHelper selectionHelper = this.loopTableEditorView.getTableViewerCreator().getSelectionHelper();
afterLineSelectionListener = new ILineSelectionListener() {
@Override
public void handle(LineSelectionEvent e) {
updateLinksStyleAndControlsSelection(e.source.getTable(), true);
}
};
selectionHelper.addAfterSelectionListener(afterLineSelectionListener);
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONToXPathLinker method getTreeItem.
@Override
protected TreeItem getTreeItem(Tree tree, Object dataOfTreeItem, Object dataOfTableItem) {
String path = null;
if (dataOfTableItem instanceof SchemaTarget) {
SchemaTarget target = (SchemaTarget) dataOfTableItem;
path = target.getRelativeXPathQuery();
} else if (dataOfTableItem instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor target = (JSONXPathLoopDescriptor) dataOfTableItem;
path = target.getAbsoluteXPathQuery();
}
if (path == null) {
return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
}
boolean expressionIsAbsolute = false;
if (path.trim().startsWith("/")) {
//$NON-NLS-1$
expressionIsAbsolute = true;
}
//$NON-NLS-1$
String fullPath = "";
if (!expressionIsAbsolute) {
if (loopXpathNodes.size() > 0) {
//$NON-NLS-1$
fullPath = loopXpathNodes.get(0) + "/";
}
// adapt relative path
//$NON-NLS-1$
String[] relatedSplitedPaths = path.split("\\.\\./");
if (relatedSplitedPaths.length > 1) {
int pathsToRemove = relatedSplitedPaths.length - 1;
//$NON-NLS-1$
String[] fullPathSplited = fullPath.split("/");
//$NON-NLS-1$
fullPath = "";
for (int j = 1; j < (fullPathSplited.length - pathsToRemove); j++) {
//$NON-NLS-1$
fullPath += "/" + fullPathSplited[j];
}
//$NON-NLS-1$
fullPath += "/" + relatedSplitedPaths[pathsToRemove];
} else {
fullPath += path;
}
} else {
fullPath = path;
}
TreeItem treeItem = treePopulator.getTreeItem(fullPath);
if (treeItem != null) {
return treeItem;
} else {
return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
}
}
Aggregations