use of org.apache.hop.pipeline.transform.ITransformMeta in project hop by apache.
the class PGBulkLoaderDialog method generateMappings.
/**
* Reads in the fields from the previous transforms and from the ONE next transform and opens an
* EnterMappingDialog with this information. After the user did the mapping, those information is
* put into the Select/Rename table.
*/
private void generateMappings() {
// Determine the source and target fields...
//
IRowMeta sourceFields;
IRowMeta targetFields;
try {
sourceFields = pipelineMeta.getPrevTransformFields(variables, transformMeta);
} catch (HopException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
// refresh data
input.setDatabaseMeta(pipelineMeta.findDatabase(wConnection.getText()));
input.setTableName(variables.resolve(wTable.getText()));
ITransformMeta transformMetaInterface = transformMeta.getTransform();
try {
targetFields = transformMetaInterface.getRequiredFields(variables);
} catch (HopException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
IValueMeta value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName();
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<>();
StringBuilder missingSourceFields = new StringBuilder();
StringBuilder missingTargetFields = new StringBuilder();
int nrFields = wReturn.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wReturn.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
int answer = BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeFieldsNotFoundTitle"), message, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
boolean goOn = (answer & SWT.OK) != 0;
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(PGBulkLoaderDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wReturn.table.removeAll();
wReturn.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wReturn.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
wReturn.setRowNums();
wReturn.optWidth(true);
}
}
use of org.apache.hop.pipeline.transform.ITransformMeta in project hop by apache.
the class PipelinePreviewFactory method generatePreviewPipeline.
public static final PipelineMeta generatePreviewPipeline(IHopMetadataProvider metadataProvider, ITransformMeta oneMeta, String oneTransformName) {
PluginRegistry registry = PluginRegistry.getInstance();
PipelineMeta previewMeta = new PipelineMeta();
// Pass the MetaStore to look up shared metadata at runtime
//
previewMeta.setMetadataProvider(metadataProvider);
// The following operation resets the internal variables!
//
previewMeta.setName("Preview pipeline for " + oneTransformName);
// At it to the first transform.
TransformMeta one = new TransformMeta(registry.getPluginId(TransformPluginType.class, oneMeta), oneTransformName, oneMeta);
one.setLocation(50, 50);
previewMeta.addTransform(one);
DummyMeta twoMeta = new DummyMeta();
TransformMeta two = new TransformMeta(registry.getPluginId(TransformPluginType.class, twoMeta), "dummy", twoMeta);
two.setLocation(250, 50);
previewMeta.addTransform(two);
PipelineHopMeta hop = new PipelineHopMeta(one, two);
previewMeta.addPipelineHop(hop);
return previewMeta;
}
use of org.apache.hop.pipeline.transform.ITransformMeta in project hop by apache.
the class InsertUpdateDialog method generateMappings.
/**
* Reads in the fields from the previous transforms and from the ONE next transform and opens an
* EnterMappingDialog with this information. After the user did the mapping, those information is
* put into the Select/Rename table.
*/
private void generateMappings() {
// Determine the source and target fields...
//
IRowMeta sourceFields;
IRowMeta targetFields;
try {
sourceFields = pipelineMeta.getPrevTransformFields(variables, transformMeta);
} catch (HopException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
// refresh data
input.setConnection(wConnection.getText());
input.getInsertUpdateLookupField().setTableName(variables.resolve(wTable.getText()));
ITransformMeta transformMetaInterface = transformMeta.getTransform();
try {
targetFields = transformMetaInterface.getRequiredFields(variables);
} catch (HopException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
IValueMeta value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName();
}
// Create the existing mapping list...
// Also copy the update status of targets in to a hashmap
//
List<SourceToTargetMapping> mappings = new ArrayList<>();
Map<String, String> targetUpdateStatus = new HashMap<>();
StringBuilder missingSourceFields = new StringBuilder();
StringBuilder missingTargetFields = new StringBuilder();
int nrFields = wReturn.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wReturn.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
targetUpdateStatus.put(item.getText(1), item.getText(3));
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
int answer = BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "InsertUpdateDialog.DoMapping.SomeFieldsNotFoundTitle"), message, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
boolean goOn = (answer & SWT.OK) != 0;
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(InsertUpdateDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wReturn.table.removeAll();
wReturn.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wReturn.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
if (targetUpdateStatus.get(item.getText(1)) == null) {
item.setText(3, "Y");
} else {
item.setText(3, targetUpdateStatus.get(item.getText(1)));
}
}
wReturn.setRowNums();
wReturn.optWidth(true);
}
}
use of org.apache.hop.pipeline.transform.ITransformMeta in project hop by apache.
the class SelectValuesDialog method generateMappings.
/**
* Reads in the fields from the previous transforms and from the ONE next transform and opens an
* EnterMappingDialog with this information. After the user did the mapping, those information is
* put into the Select/Rename table.
*/
private void generateMappings() {
if (!bPreviousFieldsLoaded) {
BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "SelectValuesDialog.ColumnInfo.Loading"), BaseMessages.getString(PKG, "SelectValuesDialog.ColumnInfo.Loading"), SWT.ICON_ERROR | SWT.OK);
return;
}
if ((wRemove.getItemCount() > 0) || (wMeta.getItemCount() > 0)) {
for (int i = 0; i < wRemove.getItemCount(); i++) {
String[] columns = wRemove.getItem(i);
for (String column : columns) {
if (column.length() > 0) {
BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMetaTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMeta"), SWT.ICON_ERROR | SWT.OK);
return;
}
}
}
for (int i = 0; i < wMeta.getItemCount(); i++) {
String[] columns = wMeta.getItem(i);
for (String col : columns) {
if (col.length() > 0) {
BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMetaTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMeta"), SWT.ICON_ERROR | SWT.OK);
return;
}
}
}
}
IRowMeta nextTransformRequiredFields = null;
TransformMeta transformMeta = new TransformMeta(transformName, input);
List<TransformMeta> nextTransforms = pipelineMeta.findNextTransforms(transformMeta);
if (nextTransforms.size() == 0 || nextTransforms.size() > 1) {
BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoNextTransformTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoNextTransform"), SWT.ICON_ERROR | SWT.OK);
return;
}
TransformMeta outputTransformMeta = nextTransforms.get(0);
ITransformMeta transformMetaInterface = outputTransformMeta.getTransform();
try {
nextTransformRequiredFields = transformMetaInterface.getRequiredFields(variables);
} catch (HopException e) {
logError(BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.UnableToFindOutput"));
nextTransformRequiredFields = new RowMeta();
}
String[] inputNames = new String[prevFields.size()];
for (int i = 0; i < prevFields.size(); i++) {
IValueMeta value = prevFields.getValueMeta(i);
inputNames[i] = value.getName();
}
String[] outputNames = new String[nextTransformRequiredFields.size()];
for (int i = 0; i < nextTransformRequiredFields.size(); i++) {
outputNames[i] = nextTransformRequiredFields.getValueMeta(i).getName();
}
String[] selectName = new String[wFields.getItemCount()];
String[] selectRename = new String[wFields.getItemCount()];
for (int i = 0; i < wFields.getItemCount(); i++) {
selectName[i] = wFields.getItem(i, 1);
selectRename[i] = wFields.getItem(i, 2);
}
List<SourceToTargetMapping> mappings = new ArrayList<>();
StringBuilder missingFields = new StringBuilder();
for (int i = 0; i < selectName.length; i++) {
String valueName = selectName[i];
String valueRename = selectRename[i];
int inIndex = prevFields.indexOfValue(valueName);
if (inIndex < 0) {
missingFields.append(Const.CR + " " + valueName + " --> " + valueRename);
continue;
}
if (null == valueRename || valueRename.equals("")) {
valueRename = valueName;
}
int outIndex = nextTransformRequiredFields.indexOfValue(valueRename);
if (outIndex < 0) {
missingFields.append(Const.CR + " " + valueName + " --> " + valueRename);
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(inIndex, outIndex);
mappings.add(mapping);
}
// show a confirm dialog if some misconfiguration was found
if (missingFields.length() > 0) {
int answer = BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.SomeFieldsNotFoundTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.SomeFieldsNotFound", missingFields.toString()), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
boolean goOn = (answer & SWT.YES) != 0;
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(SelectValuesDialog.this.shell, inputNames, outputNames, mappings);
mappings = d.open();
//
if (mappings != null) {
wFields.table.removeAll();
wFields.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wFields.table.getItem(i);
item.setText(1, prevFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(2, outputNames[mapping.getTargetPosition()]);
}
wFields.setRowNums();
wFields.optWidth(true);
wTabFolder.setSelection(0);
}
}
use of org.apache.hop.pipeline.transform.ITransformMeta in project hop by apache.
the class MetaInjectDialog method refreshTree.
private void refreshTree() {
try {
loadPipeline();
treeItemTargetMap = new HashMap<>();
wTree.removeAll();
List<TransformMeta> injectTransforms = new ArrayList<>();
for (TransformMeta transformMeta : injectPipelineMeta.getTransforms()) {
ITransformMeta meta = transformMeta.getTransform();
if (BeanInjectionInfo.isInjectionSupported(meta.getClass())) {
injectTransforms.add(transformMeta);
}
}
Collections.sort(injectTransforms);
for (TransformMeta transformMeta : injectTransforms) {
TreeItem transformItem = new TreeItem(wTree, SWT.NONE);
transformItem.setText(transformMeta.getName());
boolean expanded = false;
Image image = GuiResource.getInstance().getImagesTransforms().get(transformMeta.getPluginId()).getAsBitmapForSize(shell.getDisplay(), ConstUi.ICON_SIZE, ConstUi.ICON_SIZE);
transformItem.setImage(image);
// For each transform, add the keys
//
ITransformMeta metaInterface = transformMeta.getTransform();
if (BeanInjectionInfo.isInjectionSupported(metaInterface.getClass())) {
expanded = expanded || processMDIDescription(transformMeta, transformItem, metaInterface);
}
transformItem.setExpanded(expanded);
}
} catch (Throwable t) {
// Ignore errors
}
//
if (injectPipelineMeta != null) {
String[] sourceTransforms = injectPipelineMeta.getTransformNames();
Arrays.sort(sourceTransforms);
wSourceTransform.setItems(sourceTransforms);
wStreamingTargetTransform.setItems(sourceTransforms);
}
}
Aggregations