use of org.apache.hop.core.SourceToTargetMapping in project hop by apache.
the class SalesforceUpdateDialog 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 (!checkInput()) {
return;
}
// Determine the source and target fields...
//
IRowMeta sourceFields;
IRowMeta targetFields = new RowMeta();
try {
sourceFields = pipelineMeta.getPrevTransformFields(variables, transformMeta);
} catch (HopException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceUpdateDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SalesforceUpdateDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
try {
String[] fields = getModuleFields();
for (int i = 0; i < fields.length; i++) {
targetFields.addValueMeta(new ValueMetaNone(fields[i]));
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceUpdateDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SalesforceUpdateDialog.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<>();
StringBuffer missingSourceFields = new StringBuffer();
StringBuffer missingTargetFields = new StringBuffer();
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 + " " + source + " --> " + target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR + " " + source + " --> " + 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, "SalesforceUpdateDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "SalesforceUpdateDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "SalesforceUpdateDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
int answer = BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "SalesforceUpdateDialog.DoMapping.SomeFieldsNotFoundTitle"), message, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
boolean goOn = (answer & SWT.OK) != 0;
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(SalesforceUpdateDialog.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.core.SourceToTargetMapping in project hop by apache.
the class SalesforceUpsertDialog 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 (!checkInput()) {
return;
}
// Determine the source and target fields...
//
IRowMeta sourceFields;
IRowMeta targetFields = new RowMeta();
try {
sourceFields = pipelineMeta.getPrevTransformFields(variables, transformMeta);
} catch (HopException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
try {
String[] fields = getModuleFields();
for (int i = 0; i < fields.length; i++) {
targetFields.addValueMeta(new ValueMetaNone(fields[i]));
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SalesforceUpsertDialog.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<>();
StringBuffer missingSourceFields = new StringBuffer();
StringBuffer missingTargetFields = new StringBuffer();
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 + " " + source + " --> " + target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR + " " + source + " --> " + 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, "SalesforceUpsertDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
int answer = BaseDialog.openMessageBox(shell, BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.SomeFieldsNotFoundTitle"), message, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
boolean goOn = (answer & SWT.OK) != 0;
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(SalesforceUpsertDialog.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.core.SourceToTargetMapping 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.core.SourceToTargetMapping in project hop by apache.
the class GraphOutputDialog method enterMapping.
private void enterMapping() {
//
try {
if (activeModel == null) {
if (!loadActiveModel()) {
return;
}
}
// Input fields
//
IRowMeta inputRowMeta = pipelineMeta.getPrevTransformFields(variables, transformMeta);
String[] inputFields = inputRowMeta.getFieldNames();
// Node properties
//
String separator = " . ";
List<String> targetPropertiesList = new ArrayList<>();
for (GraphNode node : activeModel.getNodes()) {
for (GraphProperty property : node.getProperties()) {
String combo = node.getName() + " . " + property.getName();
targetPropertiesList.add(combo);
}
}
for (GraphRelationship relationship : activeModel.getRelationships()) {
for (GraphProperty property : relationship.getProperties()) {
String combo = relationship.getName() + " . " + property.getName();
targetPropertiesList.add(combo);
}
}
String[] targetProperties = targetPropertiesList.toArray(new String[0]);
// Preserve mappings...
//
List<SourceToTargetMapping> mappings = new ArrayList<>();
for (int i = 0; i < wFieldMappings.nrNonEmpty(); i++) {
TableItem item = wFieldMappings.getNonEmpty(i);
int sourceIndex = Const.indexOfString(item.getText(1), inputFields);
int targetIndex = Const.indexOfString(item.getText(3) + separator + item.getText(4), targetProperties);
if (sourceIndex >= 0 && targetIndex >= 0) {
mappings.add(new SourceToTargetMapping(sourceIndex, targetIndex));
}
}
EnterMappingDialog dialog = new EnterMappingDialog(shell, inputFields, targetProperties, mappings);
mappings = dialog.open();
if (mappings != null) {
wFieldMappings.clearAll();
for (SourceToTargetMapping mapping : mappings) {
String field = mapping.getSourceString(inputFields);
String target = mapping.getTargetString(targetProperties);
int index = target.indexOf(separator);
String targetName = target.substring(0, index);
String property = target.substring(index + separator.length());
String targetType = null;
if (activeModel.findNode(targetName) != null) {
targetType = "Node";
} else if (activeModel.findRelationship(targetName) != null) {
targetType = "Relationship";
} else {
throw new HopException("Neither node nor pipeline found for target '" + targetName + ": internal error");
}
wFieldMappings.add(field, targetType, targetName, property);
}
wFieldMappings.removeEmptyRows();
wFieldMappings.setRowNums();
wFieldMappings.optWidth(true);
}
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error mapping input fields to node properties", e);
}
}
use of org.apache.hop.core.SourceToTargetMapping in project hop by apache.
the class WorkflowExecutorDialog method mapFieldsToWorkflowParameters.
protected void mapFieldsToWorkflowParameters() {
try {
// The field names
//
IRowMeta inputFields = pipelineMeta.getPrevTransformFields(variables, transformMeta);
String[] inputFieldNames = inputFields.getFieldNames();
loadWorkflow();
String[] parameters = executorWorkflowMeta.listParameters();
// Get the current mapping...
//
List<SourceToTargetMapping> mappings = new ArrayList<>();
for (TableItem item : wWorkflowExecutorParameters.getNonEmptyItems()) {
int sourceIndex = Const.indexOfString(item.getText(1), parameters);
int targetIndex = Const.indexOfString(item.getText(2), inputFieldNames);
if (sourceIndex >= 0 && targetIndex >= 0) {
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
}
// Now we can ask for the mapping...
//
EnterMappingDialog enterMappingDialog = new EnterMappingDialog(shell, inputFieldNames, parameters, mappings);
mappings = enterMappingDialog.open();
if (mappings != null) {
wWorkflowExecutorParameters.removeAll();
for (SourceToTargetMapping mapping : mappings) {
TableItem item = new TableItem(wWorkflowExecutorParameters.table, SWT.NONE);
item.setText(1, Const.NVL(mapping.getTargetString(parameters), ""));
item.setText(2, Const.NVL(mapping.getSourceString(inputFieldNames), ""));
item.setText(3, "");
}
wWorkflowExecutorParameters.removeEmptyRows();
wWorkflowExecutorParameters.setRowNums();
wWorkflowExecutorParameters.optWidth(true);
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "WorkflowExecutorDialog.ErrorLoadingSpecifiedJob.Title"), BaseMessages.getString(PKG, "WorkflowExecutorDialog.ErrorLoadingSpecifiedJob.Message"), e);
}
}
Aggregations