use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.
the class OutputTable method initFromExternalData.
public void initFromExternalData(ExternalMapperTable externalMapperTable) {
super.initFromExternalData(externalMapperTable);
if (externalMapperTable != null) {
this.reject = externalMapperTable.isReject();
this.rejectInnerJoin = externalMapperTable.isRejectInnerJoin();
this.isJoinTableOf = externalMapperTable.getIsJoinTableOf();
this.isErrorRejectTable = externalMapperTable.isErrorRejectTable();
List<ExternalMapperTableEntry> externalConstraintTableEntries = externalMapperTable.getConstraintTableEntries();
if (externalConstraintTableEntries != null) {
if (!mapperManager.isAdvancedMap()) {
for (ExternalMapperTableEntry entry : externalConstraintTableEntries) {
FilterTableEntry filterTableEntry = new FilterTableEntry(this, entry.getName(), entry.getExpression());
// mapperManager.getProblemsManager().checkProblemsForTableEntry(filterTableEntry, false);
addFilterEntry(filterTableEntry);
}
} else {
ILanguage currentLanguage = LanguageProvider.getCurrentLanguage();
JavaGenerationManager javaGenerationManager = new JavaGenerationManager(currentLanguage);
DataMapExpressionParser expressionParser = new DataMapExpressionParser(currentLanguage);
String expressionFilter = javaGenerationManager.buildConditions(externalConstraintTableEntries, expressionParser);
if (!expressionFilter.trim().equals("")) {
//$NON-NLS-1$
this.getExpressionFilter().setExpression(expressionFilter);
this.setActivateExpressionFilter(true);
}
}
}
}
}
use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.
the class MapperComponent method replaceLocationsInAllExpressions.
/**
* DOC amaumont Comment method "replaceLocations".
*
* @param oldLocation
* @param newLocation
* @param tableRenamed TODO
* @param newTableName
* @param newColumnName
*/
private void replaceLocationsInAllExpressions(TableEntryLocation oldLocation, TableEntryLocation newLocation, boolean tableRenamed) {
// replace old location by new location for all expressions in mapper
List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
tables.addAll(new ArrayList<ExternalMapperTable>(externalData.getVarsTables()));
tables.addAll(new ArrayList<ExternalMapperTable>(externalData.getOutputTables()));
DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
// loop on all tables
for (ExternalMapperTable table : tables) {
List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
String expressionFilter = replaceLocation(oldLocation, newLocation, table.getExpressionFilter(), dataMapExpressionParser, tableRenamed);
if (expressionFilter != null) {
table.setExpressionFilter(expressionFilter);
}
if (metadataTableEntries != null) {
// loop on all entries of current table
for (ExternalMapperTableEntry entry : metadataTableEntries) {
String expression = replaceLocation(oldLocation, newLocation, entry.getExpression(), dataMapExpressionParser, tableRenamed);
if (expression != null) {
entry.setExpression(expression);
}
}
// for (ExternalMapperTableEntry entry : metadataTableEntries) {
}
if (table.getConstraintTableEntries() != null) {
for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
String expression = replaceLocation(oldLocation, newLocation, entry.getExpression(), dataMapExpressionParser, tableRenamed);
if (expression != null) {
entry.setExpression(expression);
}
}
}
if (table.getGlobalMapKeysValues() != null) {
for (ExternalMapperTableEntry entry : table.getGlobalMapKeysValues()) {
String expression = replaceLocation(oldLocation, newLocation, entry.getExpression(), dataMapExpressionParser, tableRenamed);
if (expression != null) {
entry.setExpression(expression);
}
}
}
}
// for (ExternalMapperTable table : tables) {
}
use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.
the class ExternalMapperData method getLinkedTableColumnsMapping.
public Map<String, Set<String>> getLinkedTableColumnsMapping() {
Map<String, Set<String>> tableColumnsMapping = new HashMap<String, Set<String>>();
DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
List<ExternalMapperTable> tablesHasFilter = new ArrayList<ExternalMapperTable>();
tablesHasFilter.addAll(inputTables);
tablesHasFilter.addAll(outputTables);
for (ExternalMapperTable table : tablesHasFilter) {
TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(table.getExpressionFilter());
for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
if (!tableColumnsMapping.containsKey(tableEntryLocation.tableName)) {
Set<String> columns = new HashSet<String>();
columns.add(tableEntryLocation.columnName);
tableColumnsMapping.put(tableEntryLocation.tableName, columns);
} else {
tableColumnsMapping.get(tableEntryLocation.tableName).add(tableEntryLocation.columnName);
}
}
}
List<ExternalMapperTable> tablesHasColumnExpression = new ArrayList<ExternalMapperTable>();
tablesHasColumnExpression.addAll(varsTables);
tablesHasColumnExpression.addAll(outputTables);
for (ExternalMapperTable table : tablesHasColumnExpression) {
List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
for (ExternalMapperTableEntry entry : metadataTableEntries) {
TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(entry.getExpression());
for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
if (!tableColumnsMapping.containsKey(tableEntryLocation.tableName)) {
Set<String> columns = new HashSet<String>();
columns.add(tableEntryLocation.columnName);
tableColumnsMapping.put(tableEntryLocation.tableName, columns);
} else {
tableColumnsMapping.get(tableEntryLocation.tableName).add(tableEntryLocation.columnName);
}
}
}
}
return tableColumnsMapping;
}
use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.
the class ExternalMapperTable method isSelfFilter.
public boolean isSelfFilter() {
DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(this.expressionFilter);
for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
if (!this.name.equals(tableEntryLocation.tableName)) {
return false;
}
}
return true;
}
use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.
the class UIManager method parseFilterColumn.
public ParseExpressionResult parseFilterColumn(String expression, ITableEntry currentModifiedITableEntry, boolean linkMustHaveSelectedState, boolean checkInputKeyAutomatically, boolean inputExpressionAppliedOrCanceled) {
if (currentModifiedITableEntry instanceof InputColumnTableEntry) {
InputColumnTableEntry entry = (InputColumnTableEntry) currentModifiedITableEntry;
if (StringUtils.trimToNull(expression) == null) {
entry.setOperator(null);
}
}
DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(currentModifiedITableEntry);
boolean linkHasBeenAdded = false;
boolean linkHasBeenRemoved = false;
DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
TableEntryLocation[] tableEntriesLocationsSources = dataMapExpressionParser.parseTableEntryLocations(expression);
Set<TableEntryLocation> alreadyProcessed = new HashSet<TableEntryLocation>();
Set<ITableEntry> sourcesForTarget = mapperManager.getSourcesForTarget(currentModifiedITableEntry);
Set<ITableEntry> sourcesForTargetToDelete = new HashSet<ITableEntry>(sourcesForTarget);
boolean isInputEntry = currentModifiedITableEntry instanceof InputColumnTableEntry;
ECodeLanguage codeLanguage = LanguageProvider.getCurrentLanguage().getCodeLanguage();
for (TableEntryLocation tableEntriesLocationsSource : tableEntriesLocationsSources) {
TableEntryLocation location = tableEntriesLocationsSource;
// tests to know if link must be removed if key is unchecked
boolean dontRemoveLink = (!isInputEntry || isInputEntry && (inputExpressionAppliedOrCanceled || !inputExpressionAppliedOrCanceled && !mapperManager.checkEntryHasInvalidUncheckedKey((InputColumnTableEntry) currentModifiedITableEntry)));
if (!alreadyProcessed.contains(location) && checkSourceLocationIsValid(location, currentModifiedITableEntry) && (mapperManager.isAdvancedMap() || !mapperManager.isAdvancedMap() && dontRemoveLink)) {
ITableEntry sourceTableEntry = mapperManager.retrieveTableEntry(location);
if (sourceTableEntry != null && sourcesForTarget.contains(sourceTableEntry)) {
Set<IMapperLink> targets = mapperManager.getGraphicalLinksFromTarget(currentModifiedITableEntry);
Set<IMapperLink> linksFromTarget = new HashSet<IMapperLink>(targets);
for (IMapperLink link : linksFromTarget) {
link.calculate();
}
}
}
}
mapperManager.orderLinks();
if (!mapperManager.isAdvancedMap()) {
if (dataMapTableView.getZone() == Zone.INPUTS) {
if (linkHasBeenAdded || linkHasBeenRemoved) {
checkTargetInputKey(currentModifiedITableEntry, checkInputKeyAutomatically, inputExpressionAppliedOrCanceled);
}
if (inputExpressionAppliedOrCanceled) {
openChangeKeysDialog((InputDataMapTableView) dataMapTableView);
}
}
}
return new ParseExpressionResult(linkHasBeenAdded, linkHasBeenRemoved);
}
Aggregations