use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class HL7Message2SchemaDragAndDropHandler method copyColumn.
protected MetadataColumn copyColumn(MetadataColumn column) {
MetadataColumn newColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
newColumn.setComment(column.getComment());
newColumn.setDefaultValue(column.getDefaultValue());
newColumn.setKey(column.isKey());
newColumn.setLabel(column.getLabel());
newColumn.setPattern(column.getPattern());
if (column.getLength() < 0) {
newColumn.setLength(0);
} else {
newColumn.setLength(column.getLength());
}
newColumn.setNullable(column.isNullable());
if (column.getPrecision() < 0) {
newColumn.setPrecision(0);
} else {
newColumn.setPrecision(column.getPrecision());
}
newColumn.setTalendType(column.getTalendType());
newColumn.setSourceType(column.getSourceType());
if (column.getOriginalField() == null || column.getOriginalField().equals("")) {
//$NON-NLS-1$
newColumn.setLabel(column.getLabel());
} else {
newColumn.setOriginalField(column.getOriginalField());
}
return newColumn;
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn 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.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method initLinker.
private void initLinker(TreeItem node, TableItem[] tableItems) {
FOXTreeNode treeNode = (FOXTreeNode) node.getData();
IMetadataColumn column = treeNode.getColumn();
Properties prop = System.getProperties();
String os = prop.getProperty("os.name");
boolean isLastOne = false;
if (column != null) {
for (int i = 0; i < tableItems.length; i++) {
MetadataColumn metadataColumn = (MetadataColumn) tableItems[i].getData();
if (metadataColumn.getLabel().equals(column.getLabel())) {
// "isLastOne" directly to false
if (os.startsWith("Linux")) {
isLastOne = true;
}
linker.addLoopLink(tableItems[i], tableItems[i].getData(), JSONViewer.getTree(), treeNode, isLastOne);
break;
}
}
}
TreeItem[] children = node.getItems();
for (int i = 0; i < children.length; i++) {
initLinker(children[i], tableItems);
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class JSONFileOutputStep3Form method createMetadataColumn.
private List<MetadataColumn> createMetadataColumn(EList list) {
List<MetadataColumn> columnList = new ArrayList<MetadataColumn>();
if (list.size() == 0) {
return columnList;
}
for (int i = 0; i < list.size(); i++) {
JSONFileNode node = (JSONFileNode) list.get(i);
String label = node.getRelatedColumn();
if (label != null && !label.equals("")) {
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
metadataColumn.setLabel(label);
metadataColumn.setOriginalField(label);
String type = node.getType();
if (type != null) {
metadataColumn.setTalendType(type);
}
columnList.add(metadataColumn);
}
}
return columnList;
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method initSchemaTable.
private void initSchemaTable() {
List<MetadataColumn> columnList = new ArrayList<MetadataColumn>();
if (ConnectionHelper.getTables(getConnection()).size() > 0) {
EList columns = ConnectionHelper.getTables(getConnection()).toArray(new MetadataTable[0])[0].getColumns();
for (int i = 0; i < columns.size(); i++) {
columnList.add((MetadataColumn) columns.get(i));
}
}
schemaViewer.setInput(columnList);
schemaViewer.refresh();
}
Aggregations