use of org.talend.repository.model.json.JSONXPathLoopDescriptor 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.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONToXPathLinker method createLinks.
/**
* DOC amaumont Comment method "createLinks".
*/
public void createLinks() {
removeAllLinks();
getBackgroundRefresher().refreshBackground();
ProgressDialog progressDialog = new ProgressDialog(getTree().getShell(), 1000) {
private IProgressMonitor monitorWrap;
@Override
public void run(IProgressMonitor monitor) {
TableItem[] loopTableItems = loopTableEditorView.getTable().getItems();
TableItem[] fieldsTableItems = fieldsTableEditorView.getTable().getItems();
monitorWrap = new EventLoopProgressMonitor(monitor);
String taskName = "Loop links creation ...";
int totalWork = loopTableItems.length + fieldsTableItems.length;
monitorWrap.beginTask(taskName, totalWork);
List<JSONXPathLoopDescriptor> xpathLoopDescriptorList = loopTableEditorView.getModel().getBeansList();
for (int i = 0; i < loopTableItems.length; i++) {
if (monitorWrap.isCanceled()) {
return;
}
TableItem tableItem = loopTableItems[i];
JSONXPathLoopDescriptor xpathLoopDescriptor = xpathLoopDescriptorList.get(i);
String originalValue = xpathLoopDescriptor.getAbsoluteXPathQuery();
if (xpathLoopDescriptor.getConnection() != null) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(xpathLoopDescriptor.getConnection(), xpathLoopDescriptor.getConnection().getContextName());
if (contextType != null) {
originalValue = ConnectionContextHelper.getOriginalValue(contextType, xpathLoopDescriptor.getAbsoluteXPathQuery());
originalValue = TalendQuoteUtils.removeQuotes(originalValue);
}
}
if (originalValue != null) {
createLoopLinks(originalValue, tableItem, monitorWrap);
}
monitorWrap.worked(1);
}
List<SchemaTarget> schemaTargetList = fieldsTableEditorView.getModel().getBeansList();
createFieldsLinkWithProgressMonitor(monitorWrap, schemaTargetList.size() + loopTableItems.length, schemaTargetList, 0, fieldsTableItems.length);
monitorWrap.done();
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
// Nothing to do
}
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class ExtractionLoopWithJSONXPathEditorView method createColumns.
/*
* (non-Javadoc)
*
* @see
* org.talend.commons.ui.swt.advanced.macrotable.AbstractExtendedTableViewer#createColumns(org.talend.commons.ui
* .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
*/
@Override
protected void createColumns(TableViewerCreator<JSONXPathLoopDescriptor> tableViewerCreator, final Table table) {
CellEditorValueAdapter intValueAdapter = new CellEditorValueAdapter() {
@Override
public Object getOriginalTypedValue(final CellEditor cellEditor, Object value) {
try {
return new Integer(value.toString());
} catch (Exception ex) {
return null;
}
}
@Override
public Object getCellEditorTypedValue(final CellEditor cellEditor, Object value) {
if (value != null) {
return String.valueOf(value);
}
//$NON-NLS-1$
return "";
}
};
// //////////////////////////////////////////////////////////////////////////////////////
// column for mouse selection
TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
//$NON-NLS-1$
column.setTitle("");
//$NON-NLS-1$
column.setDefaultInternalValue("");
column.setWidth(15);
// //////////////////////////////////////////////////////////////////////////////////////
// X Path Query
column = new TableViewerCreatorColumn(tableViewerCreator);
xPathColumn = column;
column.setTitle("Absolute path expression");
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<JSONXPathLoopDescriptor, String>() {
@Override
public String get(JSONXPathLoopDescriptor bean) {
return bean.getAbsoluteXPathQuery();
}
@Override
public void set(JSONXPathLoopDescriptor bean, String value) {
String currentFlag = ConvertJSONString.getCurrentFlag();
bean.setAbsoluteXPathQuery(value);
bean.setFlag(currentFlag);
}
});
xPathCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.NONE, column);
column.setCellEditor(xPathCellEditor);
xPathCellEditor.addListener(new DialogErrorForCellEditorListener(xPathCellEditor, column) {
@Override
public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
if (state == CELL_EDITOR_STATE.APPLYING) {
// linker.onXPathValueChanged(table, newValue.toString(), itemIndex);
}
}
@Override
public String validateValue(String newValue, int beanPosition) {
return linker.validateXPathExpression(newValue);
}
});
column.setModifiable(true);
column.setWeight(30);
column.setMinimumWidth(50);
//$NON-NLS-1$
column.setDefaultInternalValue("");
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
// Loop limit
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Loop limit");
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<JSONXPathLoopDescriptor, Integer>() {
@Override
public Integer get(JSONXPathLoopDescriptor bean) {
return bean.getLimitBoucle();
}
@Override
public void set(JSONXPathLoopDescriptor bean, Integer value) {
if (value != null) {
bean.setLimitBoucle(value.intValue());
} else {
bean.setLimitBoucle(0);
}
}
});
column.setModifiable(true);
column.setWidth(59);
column.setCellEditor(new TextCellEditor(table), intValueAdapter);
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONToJsonPathLinker 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 (target.getConnection().isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(target.getConnection(), target.getConnection().getContextName());
path = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, path));
}
}
if (path == null) {
return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
}
boolean expressionIsAbsolute = false;
if (path.trim().startsWith(getRootSeperator())) {
expressionIsAbsolute = true;
}
//$NON-NLS-1$
String fullPath = "";
if (!expressionIsAbsolute) {
if (0 < loopXpathNodes.size()) {
fullPath = loopXpathNodes.get(0) + getFieldSeperator();
}
fullPath = fullPath + path;
} else {
fullPath = path;
}
TreeItem treeItem = treePopulator.getTreeItem(fullPath);
if (treeItem != null) {
return treeItem;
} else {
return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
}
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method revertJSONFilePropertiesForContextMode.
static void revertJSONFilePropertiesForContextMode(JSONFileConnection conn, ContextType contextType) {
if (conn == null || contextType == null) {
return;
}
if (!conn.isInputModel()) {
String outputFilePath = getOriginalValue(contextType, conn.getOutputFilePath());
outputFilePath = TalendQuoteUtils.removeQuotes(outputFilePath);
conn.setOutputFilePath(outputFilePath);
} else {
String filePath = getOriginalValue(contextType, conn.getJSONFilePath());
String encoding = getOriginalValue(contextType, conn.getEncoding());
filePath = TalendQuoteUtils.removeQuotes(filePath);
conn.setJSONFilePath(filePath);
encoding = TalendQuoteUtils.removeQuotes(encoding);
conn.setEncoding(encoding);
EList schema = conn.getSchema();
if (schema != null) {
if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
String xPahtQuery = getOriginalValue(contextType, descriptor.getAbsoluteXPathQuery());
xPahtQuery = TalendQuoteUtils.removeQuotes(xPahtQuery);
descriptor.setAbsoluteXPathQuery(xPahtQuery);
}
}
}
}
Aggregations