Search in sources :

Example 1 with Condition

use of org.apache.hop.core.Condition in project hop by apache.

the class JoinRowsMeta method readData.

private void readData(Node transformNode) throws HopXmlException {
    try {
        directory = XmlHandler.getTagValue(transformNode, "directory");
        prefix = XmlHandler.getTagValue(transformNode, "prefix");
        cacheSize = Const.toInt(XmlHandler.getTagValue(transformNode, "cache_size"), -1);
        mainTransformName = XmlHandler.getTagValue(transformNode, "main");
        Node compare = XmlHandler.getSubNode(transformNode, "compare");
        Node condnode = XmlHandler.getSubNode(compare, "condition");
        // The new situation...
        if (condnode != null) {
            condition = new Condition(condnode);
        } else {
            condition = new Condition();
        }
    } catch (Exception e) {
        throw new HopXmlException(BaseMessages.getString(PKG, "JoinRowsMeta.Exception.UnableToReadTransformMetaFromXML"), e);
    }
}
Also used : Condition(org.apache.hop.core.Condition) HopXmlException(org.apache.hop.core.exception.HopXmlException) Node(org.w3c.dom.Node) HopException(org.apache.hop.core.exception.HopException) HopXmlException(org.apache.hop.core.exception.HopXmlException) HopTransformException(org.apache.hop.core.exception.HopTransformException)

Example 2 with Condition

use of org.apache.hop.core.Condition in project hop by apache.

the class StringSearcher method stringSearchInObject.

private static void stringSearchInObject(Object obj, int level, List<StringSearchResult> stringList, Object parentObject, Object grandParentObject, Field field) {
    String fieldName = field.getName();
    if (obj instanceof String) {
        // OK, let's add the String
        stringList.add(new StringSearchResult((String) obj, parentObject, grandParentObject, fieldName));
    } else if (obj instanceof String[]) {
        String[] array = (String[]) obj;
        for (int x = 0; x < array.length; x++) {
            if (array[x] != null) {
                stringList.add(new StringSearchResult(array[x], parentObject, grandParentObject, fieldName + " #" + (x + 1)));
            }
        }
    } else if (obj instanceof Boolean) {
        // OK, let's add the String
        stringList.add(new StringSearchResult(((Boolean) obj).toString(), parentObject, grandParentObject, fieldName + " (Boolean)"));
    } else if (obj instanceof Condition) {
        stringList.add(new StringSearchResult(((Condition) obj).toString(), parentObject, grandParentObject, fieldName + " (Condition)"));
    } else if (obj instanceof IDatabase) {
        // Make sure we read the attributes. This is not picked up by default. (getDeclaredFields
        // doesn't pick up
        // inherited fields)
        // 
        IDatabase iDatabase = (IDatabase) obj;
        findMapMetaData(iDatabase.getAttributes(), level + 1, stringList, parentObject, grandParentObject, field);
        findMetaData(obj, level + 1, stringList, parentObject, grandParentObject);
    } else if (obj instanceof Map) {
        findMapMetaData((Map<?, ?>) obj, level, stringList, parentObject, grandParentObject, field);
    } else if (obj instanceof Object[]) {
        for (int j = 0; j < ((Object[]) obj).length; j++) {
            findMetaData(((Object[]) obj)[j], level + 1, stringList, parentObject, grandParentObject);
        }
    } else {
        findMetaData(obj, level + 1, stringList, parentObject, grandParentObject);
    }
}
Also used : Condition(org.apache.hop.core.Condition) IDatabase(org.apache.hop.core.database.IDatabase) Map(java.util.Map)

Example 3 with Condition

use of org.apache.hop.core.Condition in project hop by apache.

the class FilterRowsMetaTest method testClone.

@Test
public void testClone() {
    FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
    filterRowsMeta.setCondition(new Condition());
    filterRowsMeta.setTrueTransformName("true");
    filterRowsMeta.setFalseTransformName("false");
    FilterRowsMeta clone = (FilterRowsMeta) filterRowsMeta.clone();
    assertNotNull(clone.getCondition());
    assertEquals("true", clone.getTrueTransformName());
    assertEquals("false", clone.getFalseTransformName());
}
Also used : Condition(org.apache.hop.core.Condition) Test(org.junit.Test)

Example 4 with Condition

use of org.apache.hop.core.Condition in project hop by apache.

the class TableView method setFilter.

// Filtering...
public void setFilter() {
    if (condition == null) {
        condition = new Condition();
    }
    IRowMeta f = getRowWithoutValues();
    EnterConditionDialog ecd = new EnterConditionDialog(parent.getShell(), SWT.NONE, f, condition);
    Condition cond = ecd.open();
    if (cond != null) {
        ArrayList<Integer> tokeep = new ArrayList<>();
        // Apply the condition to the TableView...
        int nr = table.getItemCount();
        for (int i = nr - 1; i >= 0; i--) {
            RowMetaAndData r = getRow(i);
            boolean keep = cond.evaluate(r.getRowMeta(), r.getData());
            if (keep) {
                tokeep.add(Integer.valueOf(i));
            }
        }
        int[] sels = new int[tokeep.size()];
        for (int i = 0; i < sels.length; i++) {
            sels[i] = (tokeep.get(i)).intValue();
        }
        table.setSelection(sels);
    }
}
Also used : Condition(org.apache.hop.core.Condition) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger) RowMetaAndData(org.apache.hop.core.RowMetaAndData) IRowMeta(org.apache.hop.core.row.IRowMeta) EnterConditionDialog(org.apache.hop.ui.core.dialog.EnterConditionDialog) Point(org.eclipse.swt.graphics.Point)

Example 5 with Condition

use of org.apache.hop.core.Condition in project hop by apache.

the class PipelineDebugDialog method showTransformDebugInformation.

private void showTransformDebugInformation() {
    // 
    for (Control control : wComposite.getChildren()) {
        control.dispose();
    }
    wComposite.layout(true, true);
    int[] selectionIndices = wTransforms.table.getSelectionIndices();
    if (selectionIndices == null || selectionIndices.length != 1) {
        return;
    }
    previousIndex = selectionIndices[0];
    // What transform did we click on?
    // 
    final TransformMeta transformMeta = pipelineDebugMeta.getPipelineMeta().getTransform(selectionIndices[0]);
    // What is the transform debugging metadata?
    // --> This can be null (most likely scenario)
    // 
    final TransformDebugMeta transformDebugMeta = transformDebugMetaMap.get(transformMeta);
    // At the top we'll put a few common items like first[x], etc.
    // 
    // The row count (e.g. number of rows to keep)
    // 
    wRowCount = new LabelText(wComposite, BaseMessages.getString(PKG, "PipelineDebugDialog.RowCount.Label"), BaseMessages.getString(PKG, "PipelineDebugDialog.RowCount.ToolTip"));
    FormData fdRowCount = new FormData();
    fdRowCount.left = new FormAttachment(0, 0);
    fdRowCount.right = new FormAttachment(100, 0);
    fdRowCount.top = new FormAttachment(0, 0);
    wRowCount.setLayoutData(fdRowCount);
    wRowCount.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            ok(false);
        }
    });
    // Do we retrieve the first rows passing?
    // 
    wFirstRows = new Button(wComposite, SWT.CHECK);
    props.setLook(wFirstRows);
    wFirstRows.setText(BaseMessages.getString(PKG, "PipelineDebugDialog.FirstRows.Label"));
    wFirstRows.setToolTipText(BaseMessages.getString(PKG, "PipelineDebugDialog.FirstRows.ToolTip"));
    FormData fdFirstRows = new FormData();
    fdFirstRows.left = new FormAttachment(middle, 0);
    fdFirstRows.right = new FormAttachment(100, 0);
    fdFirstRows.top = new FormAttachment(wRowCount, margin);
    wFirstRows.setLayoutData(fdFirstRows);
    // Do we pause on break point, when the condition is met?
    // 
    wPauseBreakPoint = new Button(wComposite, SWT.CHECK);
    props.setLook(wPauseBreakPoint);
    wPauseBreakPoint.setText(BaseMessages.getString(PKG, "PipelineDebugDialog.PauseBreakPoint.Label"));
    wPauseBreakPoint.setToolTipText(BaseMessages.getString(PKG, "PipelineDebugDialog.PauseBreakPoint.ToolTip"));
    FormData fdPauseBreakPoint = new FormData();
    fdPauseBreakPoint.left = new FormAttachment(middle, 0);
    fdPauseBreakPoint.right = new FormAttachment(100, 0);
    fdPauseBreakPoint.top = new FormAttachment(wFirstRows, margin);
    wPauseBreakPoint.setLayoutData(fdPauseBreakPoint);
    // The condition to pause for...
    // 
    condition = null;
    if (transformDebugMeta != null) {
        condition = transformDebugMeta.getCondition();
    }
    if (condition == null) {
        condition = new Condition();
    }
    // The input fields...
    IRowMeta transformInputFields;
    try {
        transformInputFields = pipelineDebugMeta.getPipelineMeta().getTransformFields(variables, transformMeta);
    } catch (HopTransformException e) {
        transformInputFields = new RowMeta();
    }
    Label wlCondition = new Label(wComposite, SWT.RIGHT);
    props.setLook(wlCondition);
    wlCondition.setText(BaseMessages.getString(PKG, "PipelineDebugDialog.Condition.Label"));
    wlCondition.setToolTipText(BaseMessages.getString(PKG, "PipelineDebugDialog.Condition.ToolTip"));
    FormData fdlCondition = new FormData();
    fdlCondition.left = new FormAttachment(0, 0);
    fdlCondition.right = new FormAttachment(middle, -margin);
    fdlCondition.top = new FormAttachment(wPauseBreakPoint, margin);
    wlCondition.setLayoutData(fdlCondition);
    ConditionEditor wCondition = new ConditionEditor(wComposite, SWT.BORDER, condition, transformInputFields);
    FormData fdCondition = new FormData();
    fdCondition.left = new FormAttachment(middle, 0);
    fdCondition.right = new FormAttachment(100, 0);
    fdCondition.top = new FormAttachment(wPauseBreakPoint, margin);
    fdCondition.bottom = new FormAttachment(100, 0);
    wCondition.setLayoutData(fdCondition);
    getTransformDebugData(transformDebugMeta);
    // Add a "clear" button at the bottom on the left...
    // 
    Button wClear = new Button(wComposite, SWT.PUSH);
    props.setLook(wClear);
    wClear.setText(BaseMessages.getString(PKG, "PipelineDebugDialog.Clear.Label"));
    wClear.setToolTipText(BaseMessages.getString(PKG, "PipelineDebugDialog.Clear.ToolTip"));
    FormData fdClear = new FormData();
    fdClear.left = new FormAttachment(0, 0);
    fdClear.bottom = new FormAttachment(100, 0);
    wClear.setLayoutData(fdClear);
    wClear.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // Clear the preview transform information for this transform...
            // 
            transformDebugMetaMap.remove(transformMeta);
            wTransforms.table.setSelection(new int[] {});
            previousIndex = -1;
            // refresh the transforms list...
            // 
            refreshTransformList();
            showTransformDebugInformation();
        }
    });
    wComposite.layout(true, true);
}
Also used : FormData(org.eclipse.swt.layout.FormData) Condition(org.apache.hop.core.Condition) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ConditionEditor(org.apache.hop.ui.core.widget.ConditionEditor) TransformDebugMeta(org.apache.hop.pipeline.debug.TransformDebugMeta) HopTransformException(org.apache.hop.core.exception.HopTransformException) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelText(org.apache.hop.ui.core.widget.LabelText) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

Condition (org.apache.hop.core.Condition)14 HopException (org.apache.hop.core.exception.HopException)5 IRowMeta (org.apache.hop.core.row.IRowMeta)5 HopTransformException (org.apache.hop.core.exception.HopTransformException)4 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)4 HopXmlException (org.apache.hop.core.exception.HopXmlException)3 RowMeta (org.apache.hop.core.row.RowMeta)3 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)3 ConditionEditor (org.apache.hop.ui.core.widget.ConditionEditor)3 FormAttachment (org.eclipse.swt.layout.FormAttachment)3 FormData (org.eclipse.swt.layout.FormData)3 List (java.util.List)2 Const (org.apache.hop.core.Const)2 Utils (org.apache.hop.core.util.Utils)2 IVariables (org.apache.hop.core.variables.IVariables)2 BaseMessages (org.apache.hop.i18n.BaseMessages)2 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)2 BaseTransformMeta (org.apache.hop.pipeline.transform.BaseTransformMeta)2 ITransformDialog (org.apache.hop.pipeline.transform.ITransformDialog)2 BaseDialog (org.apache.hop.ui.core.dialog.BaseDialog)2