use of org.talend.core.model.components.conversions.IComponentConversion in project tdi-studio-se by Talend.
the class ReplaceVarcharArrayWithVarcharIssueTDI35719 method execute.
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
final List<String> componentNames = Arrays.asList("tTeradataTPTUtility", "tTeradataTPTExec");
final String tableToCheck = "TPT_COOA_FOR_UPDATE";
final List<String> fieldNames = Arrays.asList("ERRORTABLE1", "ERRORTABLE2", "WORKTABLE");
IComponentFilter filter = new IComponentFilter() {
@Override
public boolean accept(NodeType node) {
return componentNames.contains(node.getComponentName());
}
};
try {
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {
@Override
public void transform(NodeType node) {
String openBrStr = "['";
String closeBrStr = "']";
String openBrPattern = Pattern.quote(openBrStr);
String closeBrPattern = Pattern.quote(closeBrStr);
ProcessType item = (ProcessType) node.eContainer();
for (Object o : item.getNode()) {
NodeType nt = (NodeType) o;
for (Object o1 : nt.getElementParameter()) {
ElementParameterType t = (ElementParameterType) o1;
if ("TABLE".equals(t.getField()) && tableToCheck.equals(t.getName())) {
List<ElementValueType> elementValues = (List<ElementValueType>) t.getElementValue();
for (int i = 0; i < elementValues.size() - 1; i++) {
ElementValueType nameCol = elementValues.get(i);
String nameValue = nameCol.getValue();
if (nameCol.getElementRef().equals("OPTIONAL_ATTRIBUTES_NAME") && nameValue != null && fieldNames.contains(nameValue)) {
ElementValueType valueCol = elementValues.get(++i);
String value = valueCol != null ? valueCol.getValue().trim() : null;
if (value != null && value.contains(openBrStr) || value.contains(closeBrStr)) {
String newValue = value.replaceFirst(openBrPattern, "").replaceFirst(closeBrPattern, "");
if (!value.equals(newValue)) {
valueCol.setValue(newValue);
}
}
}
}
}
}
}
}
}));
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.model.components.conversions.IComponentConversion in project tdi-studio-se by Talend.
the class ReplacetFileOutputXMLParameterMigrationTask method execute.
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
try {
IComponentFilter filter = new NameComponentFilter("tFileOutputXML");
IComponentConversion changeNodeValueConversion = new IComponentConversion() {
public void transform(NodeType node) {
ProcessType item = (ProcessType) node.eContainer();
for (Object o : item.getNode()) {
NodeType nt = (NodeType) o;
for (Object o1 : nt.getElementParameter()) {
ElementParameterType t = (ElementParameterType) o1;
if ("TABLE".equals(t.getField()) && ("MAPPING".equals(t.getName()) || "GROUP_BY".equals(t.getName()))) {
for (ElementValueType type : (List<ElementValueType>) t.getElementValue()) {
if ("LABEL".equals(type.getElementRef())) {
String value = type.getValue();
if (value != null && (!value.trim().startsWith("\""))) {
type.setValue("\"" + value.trim() + "\"");
}
}
}
}
}
}
}
};
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(changeNodeValueConversion));
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.model.components.conversions.IComponentConversion in project tdi-studio-se by Talend.
the class RenametELTMigrationTask method execute.
public ExecutionResult execute(Item item) {
final String[] source = { "tELT", "tELTAggregate", "tELTCommit", "tELTFilterColumns", "tELTFilterRows", "tELTMerge", "tELTRollback" };
final String[] target = { "tSQLTemplate", "tSQLTemplateAggregate", "tSQLTemplateCommit", "tSQLTemplateFilterColumns", "tSQLTemplateFilterRows", "tSQLTemplateMerge", "tSQLTemplateRollback" };
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
try {
for (int i = 0; i < source.length; i++) {
final int j = i;
IComponentFilter filter = new NameComponentFilter(source[i]);
RenameComponentConversion renameConversion = new RenameComponentConversion(target[i]);
IComponentConversion changeNodeNameConversion = new IComponentConversion() {
public void transform(NodeType node) {
ProcessType item = (ProcessType) node.eContainer();
for (Object o : item.getConnection()) {
ConnectionType connection = (ConnectionType) o;
if ("RUN_IF".equals(connection.getConnectorName())) {
for (Object obj : connection.getElementParameter()) {
ElementParameterType type = (ElementParameterType) obj;
if ("CONDITION".equals(type.getName())) {
if (type.getValue() != null && type.getValue().contains(source[j])) {
String replaceAll = type.getValue().replaceAll(source[j], target[j]);
type.setValue(replaceAll);
}
break;
}
}
}
}
for (Object o : item.getNode()) {
NodeType nt = (NodeType) o;
for (Object o1 : nt.getElementParameter()) {
ElementParameterType t = (ElementParameterType) o1;
String value = t.getValue();
if (value != null) {
if (value.contains(source[j])) {
String replaceAll = value.replaceAll(source[j], target[j]);
t.setValue(replaceAll);
}
}
if ("TABLE".equals(t.getField())) {
for (ElementValueType type : (List<ElementValueType>) t.getElementValue()) {
if (type.getValue() != null && type.getValue().contains(source[j])) {
String replaceAll = type.getValue().replaceAll(source[j], target[j]);
type.setValue(replaceAll);
}
}
}
}
}
}
};
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(renameConversion, changeNodeNameConversion));
}
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.model.components.conversions.IComponentConversion in project tdi-studio-se by Talend.
the class RenametFTPToFTPGetMigrationTaskForPerl method execute.
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
try {
ECodeLanguage projectLanguage = getProject().getLanguage();
if (projectLanguage.equals(ECodeLanguage.PERL)) {
//$NON-NLS-1$
IComponentConversion removePropertyComponentConversion = new RemovePropertyComponentConversion("TYPE");
//$NON-NLS-1$
RenameComponentConversion renameComponentConversion = new RenameComponentConversion("tFTPGet");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IComponentFilter filter1 = new PropertyComponentFilter("tFTP", "ACTION", "get");
ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(renameComponentConversion, removePropertyComponentConversion));
//$NON-NLS-1$
renameComponentConversion.setNewName("tFTPPut");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IComponentFilter filter2 = new PropertyComponentFilter("tFTP", "ACTION", "put");
ModifyComponentsAction.searchAndModify(item, processType, filter2, Arrays.<IComponentConversion>asList(renameComponentConversion, removePropertyComponentConversion));
//$NON-NLS-1$
renameComponentConversion.setNewName("tFTPDelete");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IComponentFilter filter3 = new PropertyComponentFilter("tFTP", "ACTION", "delete");
ModifyComponentsAction.searchAndModify(item, processType, filter3, Arrays.<IComponentConversion>asList(renameComponentConversion, removePropertyComponentConversion));
//$NON-NLS-1$
renameComponentConversion.setNewName("tFTPRename");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IComponentFilter filter4 = new PropertyComponentFilter("tFTP", "ACTION", "rename");
ModifyComponentsAction.searchAndModify(item, processType, filter4, Arrays.<IComponentConversion>asList(renameComponentConversion, removePropertyComponentConversion));
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
// do nothing
return ExecutionResult.NOTHING_TO_DO;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.model.components.conversions.IComponentConversion in project tdi-studio-se by Talend.
the class RenametForForPerl method execute.
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
try {
if (getProject().getLanguage().equals(ECodeLanguage.PERL)) {
//$NON-NLS-1$
IComponentFilter filter1 = new NameComponentFilter("tFor");
IComponentConversion addProperty = new AddPropertyLoopTypeConversion();
//$NON-NLS-1$
IComponentConversion renameComponent = new RenameComponentConversion("tLoop");
ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addProperty, renameComponent));
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
// do nothing
return ExecutionResult.NOTHING_TO_DO;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
Aggregations