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);
}
}
}
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONWizard method performFinish.
/**
* This method determine if the 'Finish' button is enable This method is called when 'Finish' button is pressed in
* the wizard. We will create an operation and run it using wizard as execution context.
*/
@Override
public boolean performFinish() {
boolean formIsPerformed = false;
IWizardPage finalPage = getCurrentPage();
if (finalPage == null) {
finalPage = propertiesWizardPage;
}
// deleteTemFile();
if (connection.isInputModel()) {
if (finalPage instanceof JSONFileWizardPage) {
int step = ((JSONFileWizardPage) finalPage).step;
if (step == 2) {
formIsPerformed = finalPage.isPageComplete();
if (formIsPerformed) {
List schemas = connection.getSchema();
Set tables = ConnectionHelper.getTables(connection);
if (!schemas.isEmpty() && !tables.isEmpty()) {
JSONXPathLoopDescriptor currentSchema = (JSONXPathLoopDescriptor) schemas.get(0);
MetadataTable currentTable = (MetadataTable) tables.toArray(new MetadataTable[0])[0];
if (!currentSchema.getAbsoluteXPathQuery().equals(oldAbstractQueryPath)) {
resetMetadata(currentSchema.getSchemaTargets(), true);
} else {
resetMetadata(currentSchema.getSchemaTargets(), false);
}
}
}
} else {
formIsPerformed = finalPage.isPageComplete();
}
} else {
formIsPerformed = finalPage.isPageComplete();
}
} else {
formIsPerformed = finalPage.isPageComplete();
}
if (formIsPerformed) {
final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (creation) {
String nextId = factory.getNextId();
connectionProperty.setId(nextId);
// changed by hqzhang for TDI-19527, label=displayName
connectionProperty.setLabel(connectionProperty.getDisplayName());
final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
factory.create(connectionItem, propertiesWizardPage.getDestinationPath());
}
};
workUnit.setAvoidUnloadResources(true);
factory.executeRepositoryWorkUnit(workUnit);
} else {
// changed by hqzhang for TDI-19527, label=displayName
connectionProperty.setLabel(connectionProperty.getDisplayName());
// update schemas
Map<String, SchemaTarget> schemaTargetMap = new HashMap<String, SchemaTarget>();
EList<JSONXPathLoopDescriptor> schema = connection.getSchema();
if (schema != null && schema.size() > 0) {
JSONXPathLoopDescriptor jsonXPathLoopDescriptor = schema.get(0);
if (jsonXPathLoopDescriptor != null) {
EList<SchemaTarget> schemaTargets = jsonXPathLoopDescriptor.getSchemaTargets();
if (schemaTargets != null && schemaTargets.size() > 0) {
for (SchemaTarget schemaTarget : schemaTargets) {
schemaTargetMap.put(schemaTarget.getTagName(), schemaTarget);
}
}
}
}
Map<String, MetadataColumn> columnsMap = new HashMap<String, MetadataColumn>();
MetadataTable[] tables = ConnectionHelper.getTables(connectionItem.getConnection()).toArray(new MetadataTable[0]);
for (MetadataTable table : tables) {
EList<MetadataColumn> columns = table.getColumns();
Iterator<MetadataColumn> columnsIter = columns.iterator();
while (columnsIter.hasNext()) {
MetadataColumn column = columnsIter.next();
if (connection.isInputModel()) {
if (schemaTargetMap.get(column.getLabel()) == null) {
columnsIter.remove();
} else {
columnsMap.put(column.getLabel(), column);
}
} else {
columnsMap.put(column.getLabel(), column);
}
}
}
boolean hasAddedColumns = false;
Iterator<Entry<String, SchemaTarget>> schemaTargetIter = schemaTargetMap.entrySet().iterator();
while (schemaTargetIter.hasNext()) {
Map.Entry<String, SchemaTarget> entry = schemaTargetIter.next();
String key = entry.getKey();
if (columnsMap.get(key) == null) {
hasAddedColumns = true;
break;
}
}
if (hasAddedColumns) {
MessageDialog.openInformation(getShell(), "Detect new columns", "There are some new fields to extract, guess your schema manually if you want to apply the update.");
}
// update
RepositoryUpdateManager.updateFileConnection(connectionItem);
refreshInFinish(propertiesWizardPage.isNameModifiedByUser());
final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
factory.save(connectionItem);
}
};
workUnit.setAvoidUnloadResources(true);
factory.executeRepositoryWorkUnit(workUnit);
closeLockStrategy();
}
final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
}
};
workUnit.setAvoidUnloadResources(true);
factory.executeRepositoryWorkUnit(workUnit);
}
});
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
new ProgressMonitorDialog(null).run(true, true, iRunnableWithProgress);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
//
}
return true;
} else {
return false;
}
}
use of org.talend.repository.model.json.JSONXPathLoopDescriptor in project tdi-studio-se by Talend.
the class JSONWizard method addPages.
/**
* Adding the page to the wizard.
*/
@Override
public void addPages() {
if (isToolbar) {
pathToSave = null;
}
propertiesWizardPage = new Step0WizardPage(connectionProperty, pathToSave, JSONRepositoryNodeType.JSON, !isRepositoryObjectEditable(), creation);
jsonFileSelectPage = new JSONFileSelectWizardPage(creation, connectionItem, isRepositoryObjectEditable(), existingNames);
setDefaultPageImageDescriptor(ImageProvider.getImageDesc(JSONImage.JSON_ICON32));
if (connection != null) {
List schemas = connection.getSchema();
if (!schemas.isEmpty()) {
JSONXPathLoopDescriptor currentSchema = (JSONXPathLoopDescriptor) schemas.get(0);
oldAbstractQueryPath = currentSchema.getAbsoluteXPathQuery();
}
}
if (creation) {
setWindowTitle("New Json File");
propertiesWizardPage.setTitle("File - Step" + " 1 " + "of" + " 5");
propertiesWizardPage.setDescription("Add a Metadata File on repository\\nDefine the properties");
addPage(propertiesWizardPage);
propertiesWizardPage.setPageComplete(false);
jsonFileSelectPage.setTitle("File - Step" + " 2 " + "of" + " 5");
jsonFileSelectPage.setDescription("Select input or output model to create json metadata connection");
addPage(jsonFileSelectPage);
jsonFileSelectPage.setPageComplete(true);
} else {
setWindowTitle("Edit an existing Json File");
propertiesWizardPage.setTitle("File - Step" + " 1 " + "of" + " 4");
propertiesWizardPage.setDescription("Edit an existing Metadata File on repository\\nUpdate the properties");
addPage(propertiesWizardPage);
jsonFileSelectPage.setTitle("File - Step" + " 2 " + "of" + " 4");
jsonFileSelectPage.setDescription("Select input or output model to create json metadata connection");
addPage(jsonFileSelectPage);
jsonFileSelectPage.setPageComplete(true);
if (!isRepositoryObjectEditable()) {
creation = true;
}
}
}
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