Customer Portal

Circular Reference in Graph

Comments 2

  • Avatar
    mike
    0
    Comment actions Permalink
    ps By passing file unsorted as it comes... I am hoping that this will work as it will only look at the first two lines?

    Is that correct.
  • Avatar
    avackova
    0
    Comment actions Permalink
    Hi,
    loops in graph are not allowed. You can use reformat component with following transformation to do what you need:
     
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;

    import org.jetel.component.DataRecordTransform;
    import org.jetel.data.DataRecord;
    import org.jetel.exception.TransformException;
    import org.jetel.graph.OutputPort;


    public class transformation extends DataRecordTransform {

    List<DataRecord> records = new ArrayList<DataRecord>();
    Integer lastKey = null;

    @Override
    public boolean transform(DataRecord[] inputRecords,
    DataRecord[] outputRecords) throws TransformException {
    if (lastKey == null || !inputRecords[0].getField("no").getValue().equals(lastKey)) {
    lastKey = (Integer)inputRecords[0].getField("no").getValue();
    return defaultTransform(inputRecords, outputRecords);
    }
    outputRecords[0].reset();
    for (DataRecord record : records) {
    if (!record.getField("no").getValue().equals(lastKey)) {
    records.remove(record);
    outputRecords[0].copyFrom(record);
    break;
    }
    }
    records.add(inputRecords[0].duplicate());
    return true;
    }

    @Override
    public void finished() {
    OutputPort out = getGraph().getNodes().get("REFORMAT0").getOutputPort(0);
    for (DataRecord record : records) {
    try {
    out.writeRecord(record);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    super.finished();
    }

    }

    Only problem is that some output records can be empty.

Please sign in to leave a comment.