use of java.util.Map.Entry 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 java.util.Map.Entry in project tdi-studio-se by Talend.
the class RFH2Area method toString.
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("<").append(areaName).append(">");
Iterator propsIter = properties.entrySet().iterator();
while (propsIter.hasNext()) {
Entry entry = (Entry) propsIter.next();
Object value = entry.getValue();
if (value != null || includeNullValueInToString()) {
sb.append("<").append(entry.getKey());
if (value instanceof String) {
sb.append(">").append(escapeValue(value.toString()));
} else if (value == null) {
sb.append(" xsi:nil='true'>");
} else if (value instanceof Integer) {
sb.append(" dt='i4'>").append(value);
} else if (value instanceof Long) {
sb.append(" dt='i8'>").append(value);
} else if (value instanceof Short) {
sb.append(" dt='i2'>").append(value);
} else if (value instanceof Byte) {
sb.append(" dt='i1'>").append(value);
} else if (value instanceof Float) {
sb.append(" dt='r4'>").append(value);
} else if (value instanceof Double) {
sb.append(" dt='r8'>").append(value);
} else if (value instanceof Boolean) {
sb.append(" dt='boolean'>");
if (((Boolean) value).booleanValue()) {
sb.append(1);
} else {
sb.append(0);
}
} else {
throw new RuntimeException("Illegal property type:" + value);
}
sb.append("</").append(entry.getKey()).append(">");
}
}
sb.append("</").append(areaName).append(">");
return padFolder(sb).toString();
}
use of java.util.Map.Entry in project tdi-studio-se by Talend.
the class JobletUtil method cloneNode.
public Node cloneNode(Node node, IProcess process, Map<String, List<? extends IElementParameter>> paraMap, boolean lockByOther) {
NodePart nodePart = new NodePart();
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
boolean isInOut = false;
if (service != null) {
isInOut = service.isJobletInOutComponent(node);
}
Node cloneNode = new Node(node.getComponent(), (IProcess2) process, node.getUniqueName());
nodePart.setModel(cloneNode);
if (lockByOther) {
cloneNode.setReadOnly(true);
} else {
cloneNode.setReadOnly(false);
}
cloneNode.setDummy(node.isDummy());
cloneNode.setActivate(node.isActivate());
List<? extends IElementParameter> elementParas = null;
if (paraMap.containsKey(node.getUniqueName())) {
elementParas = paraMap.get(node.getUniqueName());
} else {
elementParas = node.getElementParameters();
}
for (IElementParameter elementPara : elementParas) {
if (elementPara.getName() != null && !elementPara.getName().equals("UNIQUE_NAME")) {
IElementParameter cloneElement = cloneNode.getElementParameter(elementPara.getName());
Object paValue = elementPara.getValue();
if (paValue instanceof List) {
List list = new ArrayList();
list.addAll((List) paValue);
cloneElement.setValue(list);
} else {
// TDI-25599
cloneElement.setContextMode(elementPara.isContextMode());
cloneElement.setValue(elementPara.getValue());
}
if (lockByOther) {
cloneElement.setReadOnly(true);
} else {
cloneElement.setReadOnly(elementPara.isReadOnly());
}
if (elementPara.getChildParameters() != null) {
Map<String, IElementParameter> elementParaChild = elementPara.getChildParameters();
Map<String, IElementParameter> cloneElementChild = cloneElement.getChildParameters();
Iterator<Entry<String, IElementParameter>> ite = elementParaChild.entrySet().iterator();
while (ite.hasNext()) {
Entry<String, IElementParameter> entry = ite.next();
String key = entry.getKey();
IElementParameter c = entry.getValue();
if (key != null && c != null) {
IElementParameter cloneC = cloneElementChild.get(key);
if (cloneC != null) {
cloneC.setValue(c.getValue());
if (lockByOther) {
cloneC.setReadOnly(true);
} else {
cloneC.setReadOnly(c.isReadOnly());
}
}
}
}
}
}
}
for (IElementParameter param : cloneNode.getElementParameters()) {
String repositoryValue = param.getRepositoryValue();
if (param.isShow(cloneNode.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName())) && param.getFieldType() != EParameterFieldType.MEMO_SQL) {
param.setRepositoryValueUsed(true);
param.setReadOnly(true);
}
}
cloneNode.setMetadataList(node.getMetadataList());
cloneNode.setListConnector(node.getListConnector());
cloneNode.setConnectionName(node.getConnectionName());
cloneNode.setLocation(node.getLocation());
IExternalNode externalNode = cloneNode.getExternalNode();
if (externalNode != null) {
if (node.getExternalData() != null) {
try {
externalNode.setExternalData(node.getExternalData().clone());
} catch (CloneNotSupportedException e) {
ExceptionHandler.process(e);
}
cloneNode.setExternalData(externalNode.getExternalData());
}
if (node.getExternalNode().getExternalEmfData() != null) {
externalNode.setExternalEmfData(EcoreUtil.copy(node.getExternalNode().getExternalEmfData()));
}
// when copy a external node, should also copy screeshot
if (node.getExternalNode() != null) {
ImageDescriptor screenshot = node.getExternalNode().getScreenshot();
if (screenshot != null) {
externalNode.setScreenshot(screenshot);
}
}
}
if (node.getElementParameter(EParameterName.LABEL.getName()) != null) {
cloneNode.setPropertyValue(EParameterName.LABEL.getName(), node.getElementParameter(EParameterName.LABEL.getName()).getValue());
} else {
cloneNode.setPropertyValue(EParameterName.LABEL.getName(), node.getLabel());
}
boolean found = false;
for (INode inode : process.getGraphicalNodes()) {
if (inode.getUniqueName().equals(cloneNode.getUniqueName())) {
found = true;
}
}
if (!found) {
((IProcess2) process).removeUniqueNodeName(cloneNode.getUniqueName());
}
return cloneNode;
}
use of java.util.Map.Entry in project tdi-studio-se by Talend.
the class DbGenerationManager method initExpression.
protected String initExpression(DbMapComponent component, ExternalDbMapEntry dbMapEntry) {
String expression = dbMapEntry.getExpression();
if (expression != null) {
List<Map<String, String>> itemNameList = null;
// MapExpressionParser mapParser = new MapExpressionParser("((\\s*(\\w+)\\s*\\.)*)(\\w+)");
// List<String> parseInTableEntryLocations = mapParser.parseInTableEntryLocations2(expression);
// for (String entryLocation : parseInTableEntryLocations) {
//
// }
// context.schema.context.table.column
// context.schema.table.column
// schema.context.table.column
// schema.table.column
// table.column
// add \\w*#* for oracle 12 , schema name start with C##
//$NON-NLS-1$
MapExpressionParser mapParser1 = new MapExpressionParser("((\\s*(\\w*#*\\w+)\\s*\\.)*)(\\w+)");
itemNameList = mapParser1.parseInTableEntryLocations2(expression);
if (itemNameList == null || itemNameList.isEmpty()) {
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
itemNameList = mapParser2.parseInTableEntryLocations(expression);
}
for (Map<String, String> itemNamemap : itemNameList) {
Set<Entry<String, String>> set = itemNamemap.entrySet();
Iterator<Entry<String, String>> ite = set.iterator();
while (ite.hasNext()) {
Entry<String, String> entry = ite.next();
String columnValue = entry.getKey();
String tableValue = entry.getValue();
String tableNameValue = tableValue;
// find original table name if tableValue is alias
String originaltableName = tableValue;
ExternalDbMapData externalData = (ExternalDbMapData) component.getExternalData();
final List<ExternalDbMapTable> inputTables = externalData.getInputTables();
for (ExternalDbMapTable inputTable : inputTables) {
if (inputTable.getAlias() != null && inputTable.getAlias().equals(tableValue)) {
originaltableName = inputTable.getTableName();
tableNameValue = inputTable.getAlias();
}
}
List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
if (inputConnections == null) {
return expression;
}
for (IConnection iconn : inputConnections) {
IMetadataTable metadataTable = iconn.getMetadataTable();
String tName = iconn.getName();
if ((originaltableName.equals(tName) || tableValue.equals(tName)) && metadataTable != null) {
List<IMetadataColumn> lColumn = metadataTable.getListColumns();
String tableName = metadataTable.getTableName();
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (tableValue.contains(".") && tableName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(tableValue);
for (Map<String, String> tableNameMap : tableNameList) {
Set<Entry<String, String>> setTable = tableNameMap.entrySet();
Iterator<Entry<String, String>> iteTable = setTable.iterator();
while (iteTable.hasNext()) {
Entry<String, String> tableEntry = iteTable.next();
String tableLabel = tableEntry.getKey();
String schemaValue = tableEntry.getValue();
if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
//$NON-NLS-1$//$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
//$NON-NLS-1$
expression = expression.replaceFirst(tableValue, schemaValue + "." + tableName);
}
}
}
} else if (tableName != null) {
if (tableValue.equals(metadataTable.getLabel()) && tableColneName.equals(tableValue)) {
//$NON-NLS-1$ //$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
expression = expression.replaceFirst(tableValue, tableName);
}
}
for (IMetadataColumn co : lColumn) {
if (columnValue.equals(co.getLabel())) {
String oriName = co.getOriginalDbColumnName();
// if OriginalDbColumn is empty , still use label to generate sql
if (oriName == null || "".equals(oriName)) {
//$NON-NLS-1$
continue;
}
if (expression.trim().equals(tableValue + "." + oriName)) {
continue;
}
if (expression.trim().equals(originaltableName + "." + oriName)) {
continue;
}
// if it is temp delived table, use label to generate sql
if (iconn.getLineStyle() == EConnectionType.TABLE_REF) {
continue;
}
//$NON-NLS-1$ //$NON-NLS-2$
oriName = oriName.replaceAll("\\$", "\\\\\\$");
expression = //$NON-NLS-1$
expression.replaceFirst(//$NON-NLS-1$
"\\." + co.getLabel(), //$NON-NLS-1$
"\\." + oriName);
expression = expression.replace("\"", "\\\"");
}
}
}
}
}
}
}
return expression;
}
use of java.util.Map.Entry in project tdi-studio-se by Talend.
the class DbGenerationManager method buildTableDeclaration.
protected void buildTableDeclaration(DbMapComponent component, StringBuilder sb, ExternalDbMapTable inputTable) {
Object inConns = component.getIncomingConnections();
List<IConnection> inputConnections = null;
if (inConns != null) {
inputConnections = (List<IConnection>) inConns;
}
if (inputConnections != null) {
IConnection iconn = this.getConnectonByName(inputConnections, inputTable.getTableName());
if (iconn == null) {
return;
}
boolean replace = false;
String inputTableName = inputTable.getName();
IMetadataTable metadataTable = iconn.getMetadataTable();
INode source = iconn.getSource();
String tableName = metadataTable.getTableName();
if (isELTDBMap(source)) {
DbMapComponent externalNode = null;
if (source instanceof DbMapComponent) {
externalNode = (DbMapComponent) source;
} else {
externalNode = (DbMapComponent) source.getExternalNode();
}
DbGenerationManager genManager = externalNode.getGenerationManager();
/* the new tabSpaceString in subquery must not be same with the parent!!! */
//$NON-NLS-1$
String deliveredTable = genManager.buildSqlSelect(externalNode, tableName, tabSpaceString + " ");
int begin = 1;
int end = deliveredTable.length() - 1;
if (begin <= end) {
//$NON-NLS-1$ //$NON-NLS-2$
sb.append("(").append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(" ");
sb.append(deliveredTable.substring(begin, end)).append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(//$NON-NLS-1$
" ) ");
}
}
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (inputTableName.contains(".") && tableName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(inputTableName);
for (Map<String, String> tableNameMap : tableNameList) {
Set<Entry<String, String>> setTable = tableNameMap.entrySet();
Iterator<Entry<String, String>> iteTable = setTable.iterator();
while (iteTable.hasNext()) {
Entry<String, String> tableEntry = iteTable.next();
String tableLabel = tableEntry.getKey();
String schemaValue = tableEntry.getValue();
if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
sb.append(schemaValue);
//$NON-NLS-1$
sb.append(".");
sb.append(tableName);
replace = true;
}
}
}
} else if (tableName != null) {
if (inputTableName.equals(metadataTable.getLabel()) && tableColneName.equals(inputTableName)) {
sb.append(tableName);
replace = true;
}
}
if (!replace) {
sb.append(inputTable.getName());
}
}
}
Aggregations