impex

package
v1.4.5-alpha1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2019 License: MPL-2.0 Imports: 18 Imported by: 4

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

View Source
const (
	ConstErrorModule = "impex"
	ConstErrorLevel  = env.ConstErrorLevelService

	ConstLogFileName = "impex.log"
)

Package global constants

Variables

View Source
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

View Source
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

func ArgsFindIDKey(args []string) string

ArgsFindIDKey looks for object identifier mention among command attributes

func ArgsFindWorkingAttributes

func ArgsFindWorkingAttributes(args []string) map[string]bool

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

func ArgsGetAsNamed(args []string, includeIndexes bool) map[string]string

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

func ImportCSVScript(csvReader *csv.Reader, output io.Writer, testMode bool) error

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 MapToCSV

func MapToCSV(input []map[string]interface{}, csvWriter *csv.Writer) error

MapToCSV converts map[string]interface{} to csv data

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

func UnRegisterImpexModel(name string) error

UnRegisterImpexModel un-registers InterfaceImpexModel capable model from import/export system

func UnRegisterImportCommand

func UnRegisterImportCommand(commandName string) error

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

func (*ImportCmdAlias) Process

func (it *ImportCmdAlias) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a ALIAS command processor

func (*ImportCmdAlias) Test

func (it *ImportCmdAlias) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a ALIAS command processor for test mode

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

func (*ImportCmdAttributeAdd) Process

func (it *ImportCmdAttributeAdd) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a ATTRIBUTE_ADD command processor

func (*ImportCmdAttributeAdd) Test

func (it *ImportCmdAttributeAdd) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a ATTRIBUTE_ADD command processor

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

func (*ImportCmdDelete) Process

func (it *ImportCmdDelete) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a DELETE command processor

func (*ImportCmdDelete) Test

func (it *ImportCmdDelete) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a DELETE command processor for test mode

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

func (*ImportCmdImport) Process

func (it *ImportCmdImport) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a IMPORT command processor

func (*ImportCmdImport) Test

func (it *ImportCmdImport) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a IMPORT command processor

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

func (*ImportCmdInsert) Process

func (it *ImportCmdInsert) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a INSERT command processor

func (*ImportCmdInsert) Test

func (it *ImportCmdInsert) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a INSERT command processor for test mode

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

func (*ImportCmdMedia) Process

func (it *ImportCmdMedia) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a MEDIA command processor

func (*ImportCmdMedia) Test

func (it *ImportCmdMedia) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a MEDIA command processor for test mode

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

func (*ImportCmdStore) Process

func (it *ImportCmdStore) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a STORE command processor

func (*ImportCmdStore) Test

func (it *ImportCmdStore) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a STORE command processor for test mode

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

func (*ImportCmdUpdate) Process

func (it *ImportCmdUpdate) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a UPDATE command processor

func (*ImportCmdUpdate) Test

func (it *ImportCmdUpdate) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a UPDATE command processor for test mode

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

func (*ImportCmdUpsert) Process

func (it *ImportCmdUpsert) Process(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Process is a UPSERT command processor

func (*ImportCmdUpsert) Test

func (it *ImportCmdUpsert) Test(itemData map[string]interface{}, input interface{}, exchange map[string]interface{}) (interface{}, error)

Test is a UPSERT command processor for test mode

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL