Fix Bug TDI-28720 : tHashOutput uses wrong schema metadata

https://jira.talendforge.org/browse/TDI-28720

git-svn-id: http://talendforge.org/svn/tos/branches/branch-5_2@115054 f6f1c999-d317-4740-80b0-e6d1abc6f99e
This commit is contained in:
wwang
2014-03-14 09:28:55 +00:00
parent 9cc242274c
commit 9446cc007f
5 changed files with 119 additions and 1 deletions

View File

@@ -74,6 +74,7 @@
//only for the lookup branch of the tJoin
boolean isLookOftJoin = false;
boolean isLookOftRecordMatching = false;
boolean isLookOfHashOutput = false;
if(conn.getLineStyle().equals(EConnectionType.FLOW_REF)){
IProcess process = conn.getTarget().getProcess();
for (INode tjoinNode : process.getNodesOfType("tJoin")) {
@@ -98,9 +99,34 @@
}
isLookOftRecordMatching = true;
}
} else if(conn.getLineStyle() == EConnectionType.FLOW_MAIN) {
IProcess process = conn.getTarget().getProcess();
for (INode thashNode : process.getNodesOfType("tHashOutput")) {
if(conn.getTarget().getUniqueName().equals(thashNode.getUniqueName())){
boolean isLinked = "true".equals(ElementParameterParser.getValue(thashNode, "__LINK_WITH__"));
String matchingMode = ElementParameterParser.getValue(thashNode,"__KEYS_MANAGEMENT__");
boolean hashKeyFromInputConnector = "true".equals(ElementParameterParser.getValue(thashNode, "__HASH_KEY_FROM_INPUT_CONNECTOR__"));
if(isLinked || !"KEEP_FIRST".equals(matchingMode) || hashKeyFromInputConnector) {
continue;
}
IMetadataTable thashNodeMetadata = null;
List<IMetadataTable> thashNodeMetadatas = thashNode.getMetadataList();
if (thashNodeMetadatas != null && thashNodeMetadatas.size() > 0) {
thashNodeMetadata = thashNodeMetadatas.get(0);
}
if(thashNodeMetadata!=null) {
for (IMetadataColumn column: thashNodeMetadata.getListColumns()) {
if (column.isKey()) {
hashableColumnsNames.add(column.getLabel());
}
}
}
isLookOfHashOutput = true;
}
}
}
if (!isLookOftJoin && !isLookOftRecordMatching && metadata!=null) {
if (!isLookOftJoin && !isLookOftRecordMatching && !isLookOfHashOutput && metadata!=null) {
for (IMetadataColumn column: metadata.getListColumns()) {
if (column.isKey()) {
hashableColumnsNames.add(column.getLabel());

View File

@@ -74,6 +74,10 @@
<PARAMETER NAME="APPEND" FIELD="CHECK" NUM_ROW="20" READONLY="false" SHOW_IF="LINK_WITH=='false'">
<DEFAULT>true</DEFAULT>
</PARAMETER>
<PARAMETER NAME="HASH_KEY_FROM_INPUT_CONNECTOR" FIELD="CHECK" NUM_ROW="40" SHOW="false">
<DEFAULT>false</DEFAULT>
</PARAMETER>
</PARAMETERS>

View File

@@ -28,3 +28,5 @@ NB_LINE_DELETED.NAME= NB Line Deleted
LIST.NAME=Component list
APPEND.NAME=Append
HASH_KEY_FROM_INPUT_CONNECTOR.NAME=hash key from input connector

View File

@@ -1874,6 +1874,15 @@
name="SetContextDumpHidePasswordToFalse"
version="5.2.4">
</projecttask>
<projecttask
beforeLogon="false"
breaks="5.2.3"
class="org.talend.repository.model.migration.AddHashKeyFromInputConnector4tHashOutput"
description="add HashKeyFromInputConnector property for tHashOutput component"
id="org.talend.repository.model.migration.AddHashKeyFromInputConnector4tHashOutput"
name="AddHashKeyFromInputConnector4tHashOutput"
version="5.2.4">
</projecttask>
</extension>
<extension

View File

@@ -0,0 +1,77 @@
// ============================================================================
//
// Copyright (C) 2006-2013 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.repository.model.migration;
import java.util.Arrays;
import java.util.Date;
import java.util.GregorianCalendar;
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
import org.talend.commons.exception.PersistenceException;
import org.talend.core.model.components.ComponentUtilities;
import org.talend.core.model.components.ModifyComponentsAction;
import org.talend.core.model.components.conversions.IComponentConversion;
import org.talend.core.model.components.filters.IComponentFilter;
import org.talend.core.model.components.filters.NameComponentFilter;
import org.talend.core.model.migration.AbstractJobMigrationTask;
import org.talend.core.model.properties.Item;
import org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
/**
* DOC Administrator class global comment. Detailled comment
*/
public class AddHashKeyFromInputConnector4tHashOutput extends AbstractJobMigrationTask {
@Override
public ExecutionResult execute(Item item) {
final ProcessType processType = getProcessType(item);
String[] compNames = { "tHashOutput" }; //$NON-NLS-1$
IComponentConversion action = new IComponentConversion() {
public void transform(NodeType node) {
if (node == null) {
return;
}
ElementParameterType property = ComponentUtilities.getNodeProperty(node, "HASH_KEY_FROM_INPUT_CONNECTOR");//$NON-NLS-1$
if (property == null) {
ComponentUtilities.addNodeProperty(node, "HASH_KEY_FROM_INPUT_CONNECTOR", "CHECK");//$NON-NLS-1$ //$NON-NLS-2$
ComponentUtilities.setNodeValue(node, "HASH_KEY_FROM_INPUT_CONNECTOR", "true");//$NON-NLS-1$ //$NON-NLS-2$
}
}
};
for (String name : compNames) {
IComponentFilter filter = new NameComponentFilter(name);
try {
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion> asList(action));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
public Date getOrder() {
GregorianCalendar gc = new GregorianCalendar(2014, 2, 3, 12, 0, 0);
return gc.getTime();
}
}