use of org.talend.repository.model.json.SchemaTarget 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.SchemaTarget in project tdi-studio-se by Talend.
the class JSONFileStep2Form method addFieldsListeners.
/**
* Main Fields addControls.
*/
@Override
protected void addFieldsListeners() {
// add listener to tableMetadata (listen the event of the toolbars)
fieldsTableEditorView.getExtendedTableModel().addAfterOperationListListener(new IListenableListListener() {
@Override
public void handleEvent(ListenableListEvent event) {
checkFieldsValue();
}
});
fieldsTableEditorView.getExtendedTableModel().addModifiedBeanListener(new IModifiedBeanListener<SchemaTarget>() {
@Override
public void handleEvent(ModifiedBeanEvent<SchemaTarget> event) {
checkFieldsValue();
// updateStatus(IStatus.OK, null);
// String msg = fieldsTableEditorView.checkColumnNames();
// if (!StringUtils.isEmpty(msg)) {
// updateStatus(IStatus.ERROR, msg);
// }
}
});
}
use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.
the class JSONToXPathLinker method getNewSchemaTargetEntry.
public SchemaTarget getNewSchemaTargetEntry(String relativeXPathValue) {
JSONExtractorFieldModel xpathNodeSchemaModel = fieldsTableEditorView.getModel();
SchemaTarget schemaTarget = xpathNodeSchemaModel.createNewSchemaTarget();
schemaTarget.setRelativeXPathQuery(relativeXPathValue);
return schemaTarget;
}
use of org.talend.repository.model.json.SchemaTarget 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);
}
}
use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.
the class ExtractionFieldsWithJSONXPathEditorView method initToolBar.
/*
* (non-Javadoc)
*
* @see org.talend.commons.ui.swt.advanced.dataeditor.AbstractDataTableEditorView#initToolBar()
*/
@Override
protected ExtendedToolbarView initToolBar() {
return new ExtendedToolbarView(getMainComposite(), SWT.NONE, getExtendedTableViewer()) {
@Override
protected AddPushButtonForExtendedTable createAddPushButton() {
return new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {
@Override
protected Object getObjectToAdd() {
UniqueStringGenerator<SchemaTarget> generator = new UniqueStringGenerator<SchemaTarget>("column", getModel().getBeansList()) {
@Override
protected String getBeanString(SchemaTarget bean) {
// TODO Auto-generated method stub
return bean.getRelativeXPathQuery();
}
};
SchemaTarget tarhe = getModel().createNewSchemaTarget();
tarhe.setRelativeXPathQuery(generator.getUniqueString());
tarhe.setTagName(generator.getUniqueString());
return tarhe;
}
};
}
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.extended.ExtendedToolbarView#createPastePushButton()
*/
@Override
protected PastePushButton createPastePushButton() {
return new PastePushButtonForExtendedTable(toolbar, extendedTableViewer) {
@Override
protected Command getCommandToExecute(ExtendedTableModel extendedTableModel, Integer indexWhereInsert) {
return new ExtendedTablePasteCommand(extendedTableModel, indexWhereInsert) {
@Override
public List createPastableBeansList(ExtendedTableModel extendedTableModel, List copiedObjectsList) {
ArrayList list = new ArrayList();
JSONExtractorFieldModel fieldsModel = (JSONExtractorFieldModel) extendedTableModel;
for (Object current : copiedObjectsList) {
if (current instanceof SchemaTarget) {
SchemaTarget original = (SchemaTarget) current;
SchemaTarget copy = fieldsModel.createNewSchemaTarget();
copy.setRelativeXPathQuery(original.getRelativeXPathQuery());
copy.setTagName(original.getTagName());
list.add(copy);
}
}
return list;
}
};
}
};
}
};
}
Aggregations