use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry 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.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.
the class MapperComponent method hasOrRenameData.
/**
*
* DOC amaumont Comment method "hasOrRenameData".
*
* @param oldName
* @param newName can be null if <code>renameAction</code> is false
* @param renameAction true to rename in all expressions, false to get boolean if present in one of the expressions
* @return
*/
@Override
protected boolean hasOrRenameData(String oldName, String newName, boolean renameAction) {
if (oldName == null || newName == null && renameAction) {
throw new NullPointerException();
}
if (externalData != null) {
List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
tables.addAll(externalData.getOutputTables());
if (externalData.getVarsTables() != null) {
tables.addAll(externalData.getVarsTables());
}
for (ExternalMapperTable table : tables) {
if (table.getExpressionFilter() != null) {
Pattern pattern = getRenamePattern(oldName);
if (pattern != null) {
PatternMatcher matcher = new Perl5Matcher();
((Perl5Matcher) matcher).setMultiline(true);
if (renameAction) {
Perl5Substitution substitution = getRenameSubstitution(newName);
String expression = renameDataIntoExpression(pattern, matcher, substitution, table.getExpressionFilter());
table.setExpressionFilter(expression);
} else {
if (hasDataIntoExpression(pattern, matcher, table.getExpressionFilter())) {
return true;
}
}
}
}
List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
if (metadataTableEntries != null) {
// loop on all entries of current table
for (ExternalMapperTableEntry entry : metadataTableEntries) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
// for (ExternalMapperTableEntry entry : metadataTableEntries) {
}
if (table.getConstraintTableEntries() != null) {
for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
}
}
}
return false;
}
use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.
the class MapperComponent method getExternalEntities.
private List<ExternalMapperTableEntry> getExternalEntities(List<MapperTableEntry> pEntities) {
List<ExternalMapperTableEntry> entityList = new ArrayList<ExternalMapperTableEntry>();
if (pEntities != null && !pEntities.isEmpty()) {
for (MapperTableEntry pEntity : pEntities) {
ExternalMapperTableEntry externalEntity = new ExternalMapperTableEntry();
externalEntity.setExpression(pEntity.getExpression());
externalEntity.setName(pEntity.getName());
externalEntity.setNullable(pEntity.isNullable());
externalEntity.setType(pEntity.getType());
externalEntity.setOperator(pEntity.getOperator());
entityList.add(externalEntity);
}
return entityList;
} else {
// fix for tuj tMap_01_basics_04 , need to return null if no entity
return null;
}
}
use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.
the class ExternalDataConverter method fillExternalTable.
/**
*
* DOC amaumont Comment method "fillExternalTable".
*
* @param table
* @param externalMapperTable
*/
private void fillExternalTable(InputTable table, ExternalMapperTable externalMapperTable) {
externalMapperTable.setInnerJoin(table.isInnerJoin());
externalMapperTable.setPersistent(table.isPersistent());
externalMapperTable.setActivateExpressionFilter(table.isActivateExpressionFilter());
externalMapperTable.setActivateCondensedTool(table.isActivateCondensedTool());
externalMapperTable.setActivateColumnNameFilter(table.isActivateColumnNameFilter());
externalMapperTable.setId(table.getId());
String expressionFilter = null;
if (table.getExpressionFilter() != null && table.getExpressionFilter().getExpression() != null) {
expressionFilter = table.getExpressionFilter().getExpression();
}
externalMapperTable.setExpressionFilter(expressionFilter);
String matchingMode = null;
if (table.getMatchingMode() != null) {
matchingMode = table.getMatchingMode().toString();
}
externalMapperTable.setMatchingMode(matchingMode);
String lookupMode = null;
if (table.getLookupMode() != null) {
lookupMode = table.getLookupMode().toString();
}
externalMapperTable.setLookupMode(lookupMode);
ArrayList<ExternalMapperTableEntry> globalMapEntries = new ArrayList<ExternalMapperTableEntry>();
for (GlobalMapEntry constraintTableEntry : table.getGlobalMapEntries()) {
ExternalMapperTableEntry externalMapperTableEntry = new ExternalMapperTableEntry();
externalMapperTableEntry.setExpression(constraintTableEntry.getExpression());
externalMapperTableEntry.setName(constraintTableEntry.getName());
globalMapEntries.add(externalMapperTableEntry);
}
externalMapperTable.setGlobalMapKeysValues(globalMapEntries);
fillExternalTableWithCommonsData(table, externalMapperTable);
inputTables.add(externalMapperTable);
}
use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.
the class MapperComponent method renameMetadataColumnName.
@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
if (conectionName == null || oldColumnName == null || newColumnName == null) {
throw new NullPointerException();
}
if (externalData != null) {
// rename metadata column name
List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
tables.addAll(externalData.getOutputTables());
ExternalMapperTable tableFound = null;
for (ExternalMapperTable table : tables) {
if (table.getName().equals(conectionName)) {
List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
for (ExternalMapperTableEntry entry : metadataTableEntries) {
if (entry.getName().equals(oldColumnName)) {
entry.setName(newColumnName);
tableFound = table;
break;
}
}
break;
}
}
// it is necessary to update expressions only if renamed column come from input table
if (tableFound != null && externalData.getInputTables().indexOf(tableFound) != -1) {
TableEntryLocation oldLocation = new TableEntryLocation(conectionName, oldColumnName);
TableEntryLocation newLocation = new TableEntryLocation(conectionName, newColumnName);
replaceLocationsInAllExpressions(oldLocation, newLocation, false);
}
}
}
Aggregations