use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.
the class JSONShadowProcessHelper method getProcessDescription.
/**
* Create a ProcessDescription and set it width the value of JSONFileConnection.
*
* This method is usefull to adapt a processDescription before run the shadow process.
*
* @param JSONFileConnection
*
* @return ProcessDescription
*/
public static ProcessDescription getProcessDescription(final JSONFileConnection connection, String tempJsonFile) {
ProcessDescription processDescription = new ProcessDescription();
processDescription.setFilepath(TalendQuoteUtils.addQuotes(PathUtils.getPortablePath(tempJsonFile)));
processDescription.setLoopQuery(TalendQuoteUtils.addQuotes(connection.getSchema().get(0).getAbsoluteXPathQuery()));
if (connection.getSchema().get(0).getLimitBoucle() != null && //$NON-NLS-1$
!("").equals(connection.getSchema().get(0).getLimitBoucle()) && (connection.getSchema().get(0).getLimitBoucle().intValue()) != 0) {
processDescription.setLoopLimit(connection.getSchema().get(0).getLimitBoucle());
}
List<Map<String, String>> mapping = new ArrayList<Map<String, String>>();
List<SchemaTarget> schemaTargets = connection.getSchema().get(0).getSchemaTargets();
if (schemaTargets != null && !schemaTargets.isEmpty()) {
Iterator<SchemaTarget> iterate = schemaTargets.iterator();
while (iterate.hasNext()) {
SchemaTarget schemaTarget = iterate.next();
Map<String, String> lineMapping = new HashMap<String, String>();
//$NON-NLS-1$
lineMapping.put("QUERY", TalendQuoteUtils.addQuotes(schemaTarget.getRelativeXPathQuery()));
mapping.add(lineMapping);
}
}
processDescription.setReadbyMode(connection.getReadbyMode());
processDescription.setMapping(mapping);
if (connection.getEncoding() != null && !("").equals(connection.getEncoding())) {
//$NON-NLS-1$
processDescription.setEncoding(TalendQuoteUtils.addQuotes(connection.getEncoding()));
} else {
//$NON-NLS-1$
processDescription.setEncoding(TalendQuoteUtils.addQuotes("UTF-8"));
}
return processDescription;
}
use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.
the class JSONToXPathLinker method createFieldsLinkWithProgressMonitor.
/**
* DOC amaumont Comment method "createFieldsLinkWithProgressDialog".
*
* @param monitorWrap
* @param fieldsTableItems
* @param totalWork
* @param schemaTargetList
*/
private void createFieldsLinkWithProgressMonitor(IProgressMonitor monitorWrap, int totalWork, List<SchemaTarget> schemaTargetList, int startTableItem, int tableItemLength) {
monitorWrap.beginTask("Fields links creation ...", totalWork);
TableItem[] fieldsTableItems = fieldsTableEditorView.getTable().getItems();
for (int i = startTableItem, indexShemaTarget = 0; i < startTableItem + tableItemLength; i++, indexShemaTarget++) {
if (monitorWrap.isCanceled()) {
for (int j = startTableItem + tableItemLength - 2; j >= 0; j--) {
// fieldsTableEditorView.getTable().remove(j);
fieldsTableEditorView.getTable().redraw();
JSONExtractorFieldModel schemaModel = this.fieldsTableEditorView.getModel();
schemaModel.remove(j);
}
return;
}
TableItem tableItem = fieldsTableItems[i];
SchemaTarget schemaTarget = schemaTargetList.get(indexShemaTarget);
String relativeXpathQuery = schemaTarget.getRelativeXPathQuery();
createFieldLinks(relativeXpathQuery, tableItem, monitorWrap, schemaTarget);
monitorWrap.worked(1);
}
getLinksManager().sortLinks(getDrawingLinksComparator());
getBackgroundRefresher().refreshBackground();
}
use of org.talend.repository.model.json.SchemaTarget 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.SchemaTarget in project tdi-studio-se by Talend.
the class JSONToXPathLinker method initFieldsListeners.
/**
* DOC amaumont Comment method "initListeners".
*/
private void initFieldsListeners() {
JSONExtractorFieldModel schemaModel = this.fieldsTableEditorView.getModel();
final Table fieldsTable = this.fieldsTableEditorView.getTable();
schemaModelModifiedBeanListener = new IModifiedBeanListener<SchemaTarget>() {
@Override
public void handleEvent(ModifiedBeanEvent<SchemaTarget> event) {
handleModifiedBeanEvent(event);
}
private void handleModifiedBeanEvent(ModifiedBeanEvent<SchemaTarget> event) {
if (event.column == fieldsTableEditorView.getXPathColumn()) {
onXPathValueChanged(fieldsTable, (String) event.newValue, event.index);
}
}
};
schemaModel.addModifiedBeanListener(schemaModelModifiedBeanListener);
schemaModelBeforeListenableListListener = new IListenableListListener<SchemaTarget>() {
@Override
public void handleEvent(ListenableListEvent<SchemaTarget> event) {
handleListenableListBeforeTableViewerRefreshedEvent(event);
}
};
schemaModel.addBeforeOperationListListener(-50, schemaModelBeforeListenableListListener);
schemaModelAfterListenableListListener = new IListenableListListener<SchemaTarget>() {
@Override
public void handleEvent(ListenableListEvent<SchemaTarget> event) {
handleListenableListAfterTableViewerRefreshedEvent(event);
}
};
schemaModel.addAfterOperationListListener(schemaModelAfterListenableListListener);
SelectionHelper selectionHelper = this.fieldsTableEditorView.getTableViewerCreator().getSelectionHelper();
fieldsTableLineSelectionListener = new ILineSelectionListener() {
@Override
public void handle(LineSelectionEvent e) {
updateLinksStyleAndControlsSelection(e.source.getTable(), true);
}
};
selectionHelper.addAfterSelectionListener(fieldsTableLineSelectionListener);
}
use of org.talend.repository.model.json.SchemaTarget 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);
}
}
Aggregations