func NewDefinition(rep *DefinitionRep) (def *Definition, err error) {
	defer support.HandlePanic("NewDefinition", &err)
	ef := expression.NewFactory(GetDataResolver())
	def = &Definition{}
	def.name = rep.Name
	def.modelID = rep.ModelID
	def.metadata = rep.Metadata
	def.explicitReply = rep.ExplicitReply
	def.tasks = make(map[string]*Task)
	def.links = make(map[int]*Link)
	if len(rep.Tasks) != 0 {
		for _, taskRep := range rep.Tasks {
			task, err := createTask(def, taskRep, ef)
			if err != nil {
				return nil, fmt.Errorf("error creating task [%s] in flow [%s]: %s", taskRep.ID, rep.Name, err.Error())
			}
			def.tasks[task.id] = task
		}
	}
	if len(rep.Links) != 0 {
		for id, linkRep := range rep.Links {
			link, err := createLink(def.tasks, linkRep, id, ef)
			if err != nil {
				var linkLabel string
				if len(linkRep.Label) > 0 {
					linkLabel = fmt.Sprintf("[%s -> %s] with label [%s]", linkRep.FromID, linkRep.ToID, linkRep.Label)
				} else {
					linkLabel = fmt.Sprintf("[%s -> %s]", linkRep.FromID, linkRep.ToID)
				}
				return nil, fmt.Errorf("error creating link %s in flow [%s]: %s", linkLabel, rep.Name, err.Error())
			}
			def.links[link.id] = link
		}
	}
	if rep.ErrorHandler != nil {
		errorHandler := &ErrorHandler{}
		errorHandler.tasks = make(map[string]*Task)
		errorHandler.links = make(map[int]*Link)
		def.errorHandler = errorHandler
		if len(rep.ErrorHandler.Tasks) != 0 {
			for _, taskRep := range rep.ErrorHandler.Tasks {
				task, err := createTask(def, taskRep, ef)
				if err != nil {
					return nil, fmt.Errorf("error creating task [%s] in flow [%s]'s error handler:%s", taskRep.ID, rep.Name, err.Error())
				}
				errorHandler.tasks[task.id] = task
			}
		}
		if len(rep.ErrorHandler.Links) != 0 {
			idOffset := len(rep.Links)
			for id, linkRep := range rep.ErrorHandler.Links {
				link, err := createLink(errorHandler.tasks, linkRep, id+idOffset, ef)
				if err != nil {
					return nil, fmt.Errorf("error creating link [%s] in flow [%s]'s error handler:%s", linkRep.Name, rep.Name, err.Error())
				}
				errorHandler.links[link.id] = link
			}
		}
	}
	return def, nil
}
NewDefinition creates a flow Definition from a serializable
definition representation
package definition
import (
	"errors"
	"fmt"
	"strconv"
	"github.com/project-flogo/core/app/resolve"
	"github.com/project-flogo/core/data"
	"github.com/project-flogo/core/data/coerce"
	"github.com/project-flogo/core/activity"
	"github.com/project-flogo/core/data/expression"
	"github.com/project-flogo/core/data/mapper"
	"github.com/project-flogo/core/data/metadata"
	"github.com/project-flogo/core/data/schema"
	"github.com/project-flogo/core/support"
	"github.com/project-flogo/core/support/log"
	flowutil "github.com/project-flogo/flow/util"
)
type DefinitionRep struct {
	ExplicitReply bool                 `json:"explicitReply,omitempty"`
	Name          string               `json:"name"`
	ModelID       string               `json:"model,omitempty"`
	Metadata      *metadata.IOMetadata `json:"metadata,omitempty"`
	Tasks         []*TaskRep           `json:"tasks"`
	Links         []*LinkRep           `json:"links,omitempty"`
	ErrorHandler  *ErrorHandlerRep     `json:"errorHandler,omitempty"`
}
type ErrorHandlerRep struct {
	Tasks []*TaskRep `json:"tasks"`
	Links []*LinkRep `json:"links,omitempty"`
}
type TaskRep struct {
	ID             string                 `json:"id"`
	Type           string                 `json:"type,omitempty"`
	Name           string                 `json:"name,omitempty"`
	Settings       map[string]interface{} `json:"settings,omitempty"`
	ActivityCfgRep *activity.Config       `json:"activity"`
}
type LinkRep struct {
	Type   string `json:"type,omitempty"`
	Name   string `json:"name,omitempty"`
	ToID   string `json:"to"`
	FromID string `json:"from"`
	Label  string `json:"label"`
	Value  string `json:"value,omitempty"`
}