Documentation ¶
Overview ¶
Package impex is a implementation of import/export service
Package impex represents import/export service. It provides a set of interfaces and helpers for extending it's functionality as well as implements basic ideas of import/export functionality.
Importing and exporting happens through CSV files you should specify within API request in order to ue this service. CSV file converts into map[string]interface{} objects which applies to model instances.
Refer to "Ottemo Import/Export Manual" for detail on service usage.
Index ¶
- Constants
- Variables
- func ArgsFindIDKey(args []string) string
- func ArgsFindWorkingAttributes(args []string) map[string]bool
- func ArgsFindWorkingModel(args []string, neededInterfaces []string) (models.InterfaceModel, error)
- func ArgsGetAsNamed(args []string, includeIndexes bool) map[string]string
- func ArgsGetAsNamedBySeparators(args []string, includeIndexes bool, separators ...rune) map[string]string
- func CSVToMap(csvReader *csv.Reader, processorFunc func(item map[string]interface{}) bool, ...) error
- func CheckModelImplements(modelName string, neededInterfaces []string) (models.InterfaceModel, error)
- func ImportCSVData(commandLine string, exchangeDict map[string]interface{}, csvReader *csv.Reader, ...) error
- func ImportCSVScript(csvReader *csv.Reader, output io.Writer, testMode bool) error
- func ImportStartHandler(next api.FuncAPIHandler) api.FuncAPIHandler
- func MapToCSV(input []map[string]interface{}, csvWriter *csv.Writer) error
- func RegisterImpexModel(name string, instance InterfaceImpexModel) error
- func RegisterImportCommand(commandName string, command InterfaceImpexImportCmd) error
- func UnRegisterImpexModel(name string) error
- func UnRegisterImportCommand(commandName string) error
- type ImportCmdAlias
- func (it *ImportCmdAlias) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdAlias) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdAlias) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdAttributeAdd
- func (it *ImportCmdAttributeAdd) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdAttributeAdd) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdAttributeAdd) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdDelete
- func (it *ImportCmdDelete) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdDelete) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdDelete) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdImport
- func (it *ImportCmdImport) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdImport) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdImport) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdInsert
- func (it *ImportCmdInsert) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdInsert) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdInsert) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdMedia
- func (it *ImportCmdMedia) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdMedia) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdMedia) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdStore
- func (it *ImportCmdStore) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdStore) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdStore) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdUpdate
- func (it *ImportCmdUpdate) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdUpdate) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdUpdate) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type ImportCmdUpsert
- func (it *ImportCmdUpsert) Init(args []string, exchange map[string]interface{}) error
- func (it *ImportCmdUpsert) Process(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- func (it *ImportCmdUpsert) Test(itemData map[string]interface{}, input interface{}, ...) (interface{}, error)
- type InterfaceImpexImportCmd
- type InterfaceImpexModel
- type StructImportStatus
- type StructImportingFile
Constants ¶
const ( ConstErrorModule = "impex" ConstErrorLevel = env.ConstErrorLevelService ConstLogFileName = "impex.log" )
Package global constants
Variables ¶
var ( ConstImpexLog = true // flag indicates to make log of values going to be processed ConstDebugLog = false // flag indicates to have extra log information // ConstCSVColumnRegexp is a regular expression used to grab csv column information // // column format: [flags]path [memorize] [type] [convertors] // [~|^|?][@a.b.c.]path [={name}|>{name}] [<{type}>] // // flags - optional column modificator // format: [~|^|?] // "~" - ignore column on collapse lookup // "^" - array column // "?" - maybe array column // // path - attribute name in result map sub-levels separated by "." // format: [@a.b.c.]d // "@a" - memorized value // // memorize - marks column to hold value in memorize map, these values can be used in path like "item.@value.label" // format: ={name} | >{name} // {name} - alphanumeric value // ={name} - saves {column path} + {column value} to memorize map // >{name} - saves {column value} to memorize map // // type - optional type for column // format: <{type}> // {type} - int | float | bool // // convertors - text template modifications you can apply to value before use it // format: see (http://golang.org/pkg/text/template/) ConstCSVColumnRegexp = regexp.MustCompile(`^\s*([~^?])?((?:@?\w+\.)*@?\w+)(\s+(?:=|>)\s*\w+)?(?:\s+<([^>]+)>)?\s*(.*)$`) ConversionFuncs = map[string]interface{}{} )
Package global variables
var ImportResultHandler = func(context api.InterfaceApplicationContext, result interface{}, err error) { importStatus.state = constImportStateIdle importStatus.sessions[context.GetSession().GetID()] = map[string]interface{}{ "result": result, "err": err, } }
ImportResultHandler will process import call's result It return no values, because of async handler result processing.
Functions ¶
func ArgsFindIDKey ¶
ArgsFindIDKey looks for object identifier mention among command attributes
func ArgsFindWorkingAttributes ¶
ArgsFindWorkingAttributes looks for model attributes inclusion/exclusion mention among command attributes
func ArgsFindWorkingModel ¶
func ArgsFindWorkingModel(args []string, neededInterfaces []string) (models.InterfaceModel, error)
ArgsFindWorkingModel looks for model mention among command attributes
func ArgsGetAsNamed ¶
ArgsGetAsNamed collects arguments into map, unnamed arguments will go as position index
func ArgsGetAsNamedBySeparators ¶
func ArgsGetAsNamedBySeparators(args []string, includeIndexes bool, separators ...rune) map[string]string
ArgsGetAsNamedBySeparators collects arguments into map, unnamed arguments will go as position index - separators could be defined as argument
func CSVToMap ¶
func CSVToMap(csvReader *csv.Reader, processorFunc func(item map[string]interface{}) bool, exchange map[string]interface{}) error
CSVToMap converts csv data to map[string]interface{} and sends to processorFunc
func CheckModelImplements ¶
func CheckModelImplements(modelName string, neededInterfaces []string) (models.InterfaceModel, error)
CheckModelImplements checks that model support InterfaceObject and InterfaceStorable interfaces
func ImportCSVData ¶
func ImportCSVData(commandLine string, exchangeDict map[string]interface{}, csvReader *csv.Reader, output io.Writer, testMode bool) error
ImportCSVData imports csv data block specified command line
func ImportCSVScript ¶
ImportCSVScript imports csv impex script format
func ImportStartHandler ¶
func ImportStartHandler(next api.FuncAPIHandler) api.FuncAPIHandler
ImportStartHandler is a middleware to init importState for async "next" procedure.
func RegisterImpexModel ¶
func RegisterImpexModel(name string, instance InterfaceImpexModel) error
RegisterImpexModel registers model instance which supports InterfaceImpexModel interface to import/export system
func RegisterImportCommand ¶
func RegisterImportCommand(commandName string, command InterfaceImpexImportCmd) error
RegisterImportCommand registers new command to import/export system
func UnRegisterImpexModel ¶
UnRegisterImpexModel un-registers InterfaceImpexModel capable model from import/export system
func UnRegisterImportCommand ¶
UnRegisterImportCommand un-registers command from import/export system
Types ¶
type ImportCmdAlias ¶
type ImportCmdAlias struct {
// contains filtered or unexported fields
}
ImportCmdAlias is a implementer of InterfaceImpexImportCmd
- command allows to make record field alias to object attribute value
func (*ImportCmdAlias) Init ¶
func (it *ImportCmdAlias) Init(args []string, exchange map[string]interface{}) error
Init is a ALIAS command initialization routines
type ImportCmdAttributeAdd ¶
type ImportCmdAttributeAdd struct {
// contains filtered or unexported fields
}
ImportCmdAttributeAdd is a implementer of InterfaceImpexImportCmd
- command allows to create custom attributes on model
func (*ImportCmdAttributeAdd) Init ¶
func (it *ImportCmdAttributeAdd) Init(args []string, exchange map[string]interface{}) error
Init is a ATTRIBUTE_ADD command initialization routines
type ImportCmdDelete ¶
type ImportCmdDelete struct {
// contains filtered or unexported fields
}
ImportCmdDelete is a implementer of InterfaceImpexImportCmd
- command allows to delete model items from the system
func (*ImportCmdDelete) Init ¶
func (it *ImportCmdDelete) Init(args []string, exchange map[string]interface{}) error
Init is a DELETE command initialization routines
type ImportCmdImport ¶
type ImportCmdImport struct {
// contains filtered or unexported fields
}
ImportCmdImport is a implementer of InterfaceImpexImportCmd
- command allows to work with InterfaceImpexModel instances
func (*ImportCmdImport) Init ¶
func (it *ImportCmdImport) Init(args []string, exchange map[string]interface{}) error
Init is a IMPORT command initialization routine
type ImportCmdInsert ¶
type ImportCmdInsert struct {
// contains filtered or unexported fields
}
ImportCmdInsert is a implementer of InterfaceImpexImportCmd
- command allows to upload data in system through model item abstraction
func (*ImportCmdInsert) Init ¶
func (it *ImportCmdInsert) Init(args []string, exchange map[string]interface{}) error
Init is a INSERT command initialization routine
type ImportCmdMedia ¶
type ImportCmdMedia struct {
// contains filtered or unexported fields
}
ImportCmdMedia is a implementer of InterfaceImpexImportCmd
- command allows to assign media content to models item
func (*ImportCmdMedia) Init ¶
func (it *ImportCmdMedia) Init(args []string, exchange map[string]interface{}) error
Init is a MEDIA command initialization routines
type ImportCmdStore ¶
type ImportCmdStore struct {
// contains filtered or unexported fields
}
ImportCmdStore is a implementer of InterfaceImpexImportCmd
- command allows temporary load/store previous command results during import process
func (*ImportCmdStore) Init ¶
func (it *ImportCmdStore) Init(args []string, exchange map[string]interface{}) error
Init is a STORE command initialization routines
type ImportCmdUpdate ¶
type ImportCmdUpdate struct {
// contains filtered or unexported fields
}
ImportCmdUpdate is a implementer of InterfaceImpexImportCmd
- command allows to update model item data in system
func (*ImportCmdUpdate) Init ¶
func (it *ImportCmdUpdate) Init(args []string, exchange map[string]interface{}) error
Init is a UPDATE command initialization routines
type ImportCmdUpsert ¶
type ImportCmdUpsert struct {
// contains filtered or unexported fields
}
ImportCmdUpsert is a implementer of InterfaceImpexImportCmd
- command allows to update model item data in system by uniqueKeys or will insert new record
- skipInsertErrors will continue processing in case of errors during insert
func (*ImportCmdUpsert) Init ¶
func (it *ImportCmdUpsert) Init(args []string, exchange map[string]interface{}) error
Init is a UPSERT command initialization routine
type InterfaceImpexImportCmd ¶
type InterfaceImpexImportCmd interface { Init(args []string, exchange map[string]interface{}) error Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error) }
InterfaceImpexImportCmd is an interface used to work with registered import commands
type InterfaceImpexModel ¶
type InterfaceImpexModel interface { Import(item map[string]interface{}, testMode bool) (map[string]interface{}, error) Export(func(map[string]interface{}) bool) error }
InterfaceImpexModel is an interface model should implement to make it work with impex service
type StructImportStatus ¶
type StructImportStatus struct {
// contains filtered or unexported fields
}
StructImportStatus holds current import status. The result of import will be stored in "sessions" map per Session.
type StructImportingFile ¶
type StructImportingFile struct {
// contains filtered or unexported fields
}
StructImportingFile holds currently importing file information