use of org.talend.designer.mapper.external.data.ExternalMapperData in project tdi-studio-se by Talend.
the class ProblemsAnalyserTest method testGetLookupTableProblem.
@Test
public void testGetLookupTableProblem() {
MapperComponent mapperComponent = createMapperComponent();
ExternalMapperData externalData = (ExternalMapperData) mapperComponent.getExternalData();
MapperManager mapperManager = mapperComponent.getMapperMain().getMapperManager();
ExternalDataConverter converter = new ExternalDataConverter(mapperManager);
MapperMain mapperMain = ((MapperComponent) mapperManager.getAbstractMapComponent()).getMapperMain();
List<? extends IConnection> incomingConnections = new ArrayList<IConnection>(mapperManager.getAbstractMapComponent().getIncomingConnections());
ArrayList<IOConnection> inputsIOConnections = mapperMain.createIOConnections(incomingConnections);
ArrayList<InputTable> inputTables = converter.prepareInputTables(inputsIOConnections, externalData);
InputTable lookupTable = inputTables.get(1);
ProblemsAnalyser analyser = new ProblemsAnalyser(mapperManager);
// match mode:Unique Match +no expression
lookupTable.setMatchingMode(TMAP_MATCHING_MODE.UNIQUE_MATCH);
analyser.getLookupTableProblem(lookupTable, mapperManager.isTableHasAtLeastOneHashKey(lookupTable));
List<Problem> problems = analyser.getProblems();
Assert.assertEquals(problems.size(), 1);
Assert.assertEquals(problems.get(0).getDescription(), "The lookup table 'row2' should have at least one expression key filled.");
// match mode:All Row +expression
lookupTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
lookupTable.getColumnEntries().get(0).setExpression("row1.newColumn1");
analyser = new ProblemsAnalyser(mapperComponent.getMapperMain().getMapperManager());
analyser.getLookupTableProblem(lookupTable, mapperManager.isTableHasAtLeastOneHashKey(lookupTable));
problems = analyser.getProblems();
Assert.assertEquals(problems.size(), 1);
Assert.assertEquals(problems.get(0).getDescription(), "The expression key can't be used in lookup table 'row2' with match mode 'All Rows'.");
}
use of org.talend.designer.mapper.external.data.ExternalMapperData in project tdi-studio-se by Talend.
the class TMapSaveToEmfMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
ProcessType processType = getProcessType(item);
boolean modified = false;
if (processType != null) {
for (Object obj : processType.getNode()) {
NodeType nodeType = (NodeType) obj;
StringReader stringReader = null;
if (nodeType.getStringData() != null && !"".equals(nodeType.getStringData())) {
stringReader = new StringReader(nodeType.getStringData());
}
final String componentName = nodeType.getComponentName();
if (stringReader != null) {
if ("tMap".equals(componentName)) {
modified = true;
Unmarshaller unmarshaller = new Unmarshaller(ExternalMapperData.class);
unmarshaller.setWhitespacePreserve(true);
try {
ExternalMapperData externalData = (ExternalMapperData) unmarshaller.unmarshal(stringReader);
final MapperData emfMapperData = MapperFactory.eINSTANCE.createMapperData();
MapperHelper.saveDataToEmf(externalData, emfMapperData);
nodeType.setNodeData(emfMapperData);
nodeType.setStringData("");
} catch (MarshalException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} catch (ValidationException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} finally {
if (stringReader != null) {
stringReader.close();
}
}
}
}
}
}
try {
if (modified) {
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.designer.mapper.external.data.ExternalMapperData in project tdi-studio-se by Talend.
the class UIManager method removeUnsavedOutputsFromProcess.
private void removeUnsavedOutputsFromProcess() {
AbstractMapComponent abstractMapComponent = getAbstractMapperManager().getAbstractMapComponent();
IProcess process = abstractMapComponent.getProcess();
List<OutputTable> currentOutputTablesList = mapperManager.getOutputTables();
HashSet<String> currentTables = new HashSet<String>(currentOutputTablesList.size());
for (OutputTable outputTable : currentOutputTablesList) {
currentTables.add(outputTable.getName());
}
ExternalMapperData originalExternalData = (ExternalMapperData) mapperManager.getOriginalExternalData();
HashSet<String> originalTableNames = new HashSet<String>();
if (originalExternalData != null) {
List<ExternalMapperTable> originalOutputTables = originalExternalData.getOutputTables();
for (ExternalMapperTable outputTable : originalOutputTables) {
originalTableNames.add(outputTable.getName());
}
}
for (String currentTable : currentTables) {
if (!originalTableNames.contains(currentTable)) {
process.removeUniqueConnectionName(currentTable);
}
}
}
use of org.talend.designer.mapper.external.data.ExternalMapperData in project tdi-studio-se by Talend.
the class DesignerMapperService method getRepositorySchemaIds.
public List<String> getRepositorySchemaIds(IExternalData nodeData) {
List<String> schemaIds = new ArrayList<String>();
if (nodeData != null && nodeData instanceof ExternalMapperData) {
ExternalMapperData mapperData = (ExternalMapperData) nodeData;
List<ExternalMapperTable> inputTables = mapperData.getInputTables();
if (inputTables != null && inputTables.size() > 0) {
for (ExternalMapperTable inputTable : inputTables) {
String id = inputTable.getId();
if (id != null && !schemaIds.contains(id)) {
schemaIds.add(id);
}
}
}
List<ExternalMapperTable> outputTables = mapperData.getOutputTables();
if (outputTables != null && outputTables.size() > 0) {
for (ExternalMapperTable outputTable : outputTables) {
String id = outputTable.getId();
if (id != null && !schemaIds.contains(id)) {
schemaIds.add(id);
}
}
}
}
return schemaIds;
}
use of org.talend.designer.mapper.external.data.ExternalMapperData in project tdi-studio-se by Talend.
the class MapperComponent method getExternalEmfData.
@Override
public AbstractExternalData getExternalEmfData() {
final MapperData emfMapperData = MapperFactory.eINSTANCE.createMapperData();
initMapperMain(false);
mapperMain.createModelFromExternalData(getIncomingConnections(), getOutgoingConnections(), externalData, getMetadataList(), false);
ExternalMapperData data = mapperMain.buildExternalData();
if (mapperMain != null && data != null) {
if (externalData != null) {
// fwang fixed bug TDI-8027
this.externalData = data;
MapperHelper.saveDataToEmf(data, emfMapperData);
}
}
return emfMapperData;
}
Aggregations