Where to add a new type

In the workflows/ directory, jflow provides a types.py file where new types can be added.

├── bin/
├── docs/
├── src/
├── workflows/
│   ├── components/
│   ├── extparsers/
│   ├── __init__.py
│   ├── formats.py
│   ├── rules.py
│   └── types.py   [ file where to add new jflow types ]
├── applications.properties

How to add a new type

In jflow a type is represented by a function named by the desired type name. The function should take only one argument, whose value is given by the user. The function is in charge to check and/or modify the given value. If an error occurred or if the value does not meet the expected criteria, an argparse.ArgumentTypeError should be raised with the suitable error message. This message will be used by jflow to inform the final user of the error.

In the following example, the intBetween1and100 function checks if the input value is in between 1 and 100:

def intBetween1and100(myint):
    # the input argument type is allways a string
        myint = int(myint)
        raise argparse.ArgumentTypeError("'"+str(myint)+"' is not a valid int!")
    if myint <= 100 and myint >= 1:
        return myint
        raise argparse.ArgumentTypeError("'"+str(myint)+"' is not between 1 and 100!")

How to use a new type

The new created type can then be used in both add_parameter and add_parameter_list of the class jflow.workflow.Workflow and jflow.component.Component as following:

def define_parameters(self, function="process"):
    self.add_parameter("my_param", "A value in between 1 and 100", type="intBetween1and100")