feed

package
v0.0.0-...-1a0708b Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSchemas

func CreateSchemas(v *viper.Viper, exporter Exporter) error

CreateSchemas generates schemas for the data feeds without fetching any data

func ExportFeeds

func ExportFeeds(v *viper.Viper, apiClient *api.Client, exporter Exporter) error

ExportFeeds fetches all the feeds data from server and stores them in the format provided

func ExportInspectionReports

func ExportInspectionReports(v *viper.Viper, apiClient *api.Client, exporter *ReportExporter) error

ExportInspectionReports download all the reports for inspections and stores them on disk

func GetActionLimit

func GetActionLimit(v *viper.Viper) int

GetActionLimit Return 100 (upper bound value) if param value > 100

func GetIssueLimit

func GetIssueLimit(v *viper.Viper) int

GetIssueLimit Return 100 (upper bound value) if param value > 100

func GetLogString

func GetLogString(feedName string, cfg *LogStringConfig) string

GetLogString build a log string based on input arguments

func GetWaitTime

func GetWaitTime(retryTimeout int) time.Duration

GetWaitTime - Default wait time is 1 second otherwise specified timeout/15. Can't be more than 4 seconds.

func WriteSchemas

func WriteSchemas(v *viper.Viper, exporter *SchemaExporter) error

WriteSchemas is used to print the schema of each feed to console output

Types

type Action

type Action struct {
	ID              string     `json:"id" csv:"action_id" gorm:"primarykey;column:action_id;size:36"`
	Title           string     `json:"title" csv:"title"`
	Description     string     `json:"description" csv:"description"`
	SiteID          string     `json:"site_id" csv:"site_id" gorm:"size:41"`
	Priority        string     `json:"priority" csv:"priority" gorm:"size:20"`
	Status          string     `json:"status" csv:"status" gorm:"size:20"`
	DueDate         time.Time  `json:"due_date" csv:"due_date"`
	CreatedAt       time.Time  `json:"created_at" csv:"created_at"`
	ModifiedAt      time.Time  `json:"modified_at" csv:"modified_at" gorm:"index:idx_act_modified_at,sort:desc"`
	ExportedAt      time.Time  `json:"exported_at" csv:"exported_at" gorm:"index:idx_act_modified_at;autoUpdateTime"`
	CreatorUserID   string     `json:"creator_user_id" csv:"creator_user_id" gorm:"size:37"`
	CreatorUserName string     `json:"creator_user_name" csv:"creator_user_name"`
	TemplateID      string     `json:"template_id" csv:"template_id" gorm:"size:100"`
	AuditID         string     `json:"audit_id" csv:"audit_id" gorm:"size:100"`
	AuditTitle      string     `json:"audit_title" csv:"audit_title"`
	AuditItemID     string     `json:"audit_item_id" csv:"audit_item_id" gorm:"size:100"`
	AuditItemLabel  string     `json:"audit_item_label" csv:"audit_item_label"`
	OrganisationID  string     `json:"organisation_id" csv:"organisation_id" gorm:"index:idx_act_modified_at;size:37"`
	CompletedAt     *time.Time `json:"completed_at" csv:"completed_at"`
}

Action represents a row from the actions feed

type ActionAssignee

type ActionAssignee struct {
	ID             string    `json:"id" csv:"id" gorm:"primarykey;size:375"`
	ActionID       string    `json:"action_id" csv:"action_id" gorm:"index:idx_act_action_id;size:36"`
	AssigneeID     string    `json:"assignee_id" csv:"assignee_id" gorm:"size:256"`
	Type           string    `json:"type" csv:"type" gorm:"size:10"`
	Name           string    `json:"name" csv:"name"`
	OrganisationID string    `json:"organisation_id" csv:"organisation_id" gorm:"index:idx_act_asg_modified_at;size:37"`
	ModifiedAt     time.Time `json:"modified_at" csv:"modified_at" gorm:"index:idx_act_asg_modified_at,sort:desc"`
	ExportedAt     time.Time `json:"exported_at" csv:"exported_at" gorm:"index:idx_act_asg_modified_at;autoUpdateTime"`
}

ActionAssignee represents a row from the action_assignees feed

type ActionAssigneeFeed

type ActionAssigneeFeed struct {
	ModifiedAfter time.Time
	Incremental   bool
}

ActionAssigneeFeed is a representation of the action_assignees feed

func (*ActionAssigneeFeed) Columns

func (f *ActionAssigneeFeed) Columns() []string

Columns returns the columns of the row

func (*ActionAssigneeFeed) CreateSchema

func (f *ActionAssigneeFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*ActionAssigneeFeed) Export

func (f *ActionAssigneeFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*ActionAssigneeFeed) Model

func (f *ActionAssigneeFeed) Model() interface{}

Model returns the model of the feed row

func (*ActionAssigneeFeed) Name

func (f *ActionAssigneeFeed) Name() string

Name is the name of the feed

func (*ActionAssigneeFeed) Order

func (f *ActionAssigneeFeed) Order() string

Order returns the ordering when retrieving an export

func (*ActionAssigneeFeed) PrimaryKey

func (f *ActionAssigneeFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*ActionAssigneeFeed) RowsModel

func (f *ActionAssigneeFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type ActionFeed

type ActionFeed struct {
	ModifiedAfter time.Time
	Incremental   bool
	Limit         int
}

ActionFeed is a representation of the actions feed

func (*ActionFeed) Columns

func (f *ActionFeed) Columns() []string

Columns returns the columns of the row

func (*ActionFeed) CreateSchema

func (f *ActionFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*ActionFeed) Export

func (f *ActionFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*ActionFeed) Model

func (f *ActionFeed) Model() interface{}

Model returns the model of the feed row

func (*ActionFeed) Name

func (f *ActionFeed) Name() string

Name is the name of the feed

func (*ActionFeed) Order

func (f *ActionFeed) Order() string

Order returns the ordering when retrieving an export

func (*ActionFeed) PrimaryKey

func (f *ActionFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*ActionFeed) RowsModel

func (f *ActionFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type CSVExporter

type CSVExporter struct {
	*SQLExporter
	ExportPath     string
	MaxRowsPerFile int
	Logger         *zap.SugaredLogger
	// contains filtered or unexported fields
}

CSVExporter is an interface to export data feeds to CSV files

func NewCSVExporter

func NewCSVExporter(exportPath, exportMediaPath string, maxRowsPerFile int) (*CSVExporter, error)

NewCSVExporter creates a new instance of CSVExporter

func (*CSVExporter) CreateSchema

func (e *CSVExporter) CreateSchema(feed Feed, rows interface{}) error

CreateSchema generated schema for a feed in csv format

func (*CSVExporter) FinaliseExport

func (e *CSVExporter) FinaliseExport(feed Feed, rows interface{}) error

FinaliseExport closes out an export

func (*CSVExporter) GetDuration

func (e *CSVExporter) GetDuration() time.Duration

GetDuration will return the duration for exporting a batch

type Exporter

type Exporter interface {
	InitFeed(feed Feed, opts *InitFeedOptions) error
	CreateSchema(feed Feed, rows interface{}) error

	WriteRows(feed Feed, rows interface{}) error
	UpdateRows(feed Feed, primaryKeys []string, element map[string]interface{}) (int64, error)

	FinaliseExport(feed Feed, rows interface{}) error
	LastModifiedAt(feed Feed, modifiedAfter time.Time, orgID string) (time.Time, error)
	WriteMedia(auditID string, mediaID string, contentType string, body []byte) error
	DeleteRowsIfExist(feed Feed, query string, args ...interface{}) error
	GetDuration() time.Duration

	SupportsUpsert() bool
	ParameterLimit() int
}

Exporter is an interface to a Feed exporter. It provides methods to write rows out to a implemented format

type Feed

type Feed interface {
	Name() string
	Model() interface{}
	RowsModel() interface{}

	PrimaryKey() []string
	Columns() []string
	Order() string

	CreateSchema(exporter Exporter) error
	Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error
}

Feed is an interface to a data feed. It provides methods to export the data to an exporter

func GetFeeds

func GetFeeds(v *viper.Viper) []Feed

GetFeeds returns list of all available data feeds

type Group

type Group struct {
	ID             string    `json:"id" csv:"group_id" gorm:"primarykey;column:group_id;size:37"`
	Name           string    `json:"name" csv:"name"`
	OrganisationID string    `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
	ExportedAt     time.Time `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
}

Group represents a row from the groups feed

type GroupFeed

type GroupFeed struct{}

GroupFeed is a representation of the groups feed

func (*GroupFeed) Columns

func (f *GroupFeed) Columns() []string

Columns returns the columns of the row

func (*GroupFeed) CreateSchema

func (f *GroupFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*GroupFeed) Export

func (f *GroupFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*GroupFeed) Model

func (f *GroupFeed) Model() interface{}

Model returns the model of the feed row

func (*GroupFeed) Name

func (f *GroupFeed) Name() string

Name is the name of the feed

func (*GroupFeed) Order

func (f *GroupFeed) Order() string

Order returns the ordering when retrieving an export

func (*GroupFeed) PrimaryKey

func (f *GroupFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*GroupFeed) RowsModel

func (f *GroupFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type GroupUser

type GroupUser struct {
	UserID         string    `json:"user_id" csv:"user_id" gorm:"primaryKey;size:37"`
	GroupID        string    `json:"group_id" csv:"group_id" gorm:"primaryKey;size:37"`
	OrganisationID string    `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
	ExportedAt     time.Time `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
}

GroupUser represents a row from the group_users feed

type GroupUserFeed

type GroupUserFeed struct{}

GroupUserFeed is a representation of the group_users feed

func (*GroupUserFeed) Columns

func (f *GroupUserFeed) Columns() []string

Columns returns the columns of the row

func (*GroupUserFeed) CreateSchema

func (f *GroupUserFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*GroupUserFeed) Export

func (f *GroupUserFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*GroupUserFeed) Model

func (f *GroupUserFeed) Model() interface{}

Model returns the model of the feed row

func (*GroupUserFeed) Name

func (f *GroupUserFeed) Name() string

Name is the name of the feed

func (*GroupUserFeed) Order

func (f *GroupUserFeed) Order() string

Order returns the ordering when retrieving an export

func (*GroupUserFeed) PrimaryKey

func (f *GroupUserFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*GroupUserFeed) RowsModel

func (f *GroupUserFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type InitFeedOptions

type InitFeedOptions struct {
	Truncate bool
}

InitFeedOptions contains the options used when initialising a feed

type Inspection

type Inspection struct {
	ID              string     `json:"id" csv:"audit_id" gorm:"primarykey;column:audit_id;size:100"`
	Name            string     `json:"name" csv:"name"`
	Archived        bool       `json:"archived" csv:"archived"`
	OwnerName       string     `json:"owner_name" csv:"owner_name"`
	OwnerID         string     `json:"owner_id" csv:"owner_id" gorm:"size:37"`
	AuthorName      string     `json:"author_name" csv:"author_name"`
	AuthorID        string     `json:"author_id" csv:"author_id" gorm:"size:37"`
	Score           float32    `json:"score" csv:"score"`
	MaxScore        float32    `json:"max_score" csv:"max_score"`
	ScorePercentage float32    `json:"score_percentage" csv:"score_percentage"`
	Duration        int64      `json:"duration" csv:"duration"`
	TemplateID      string     `json:"template_id" csv:"template_id" gorm:"size:100"`
	OrganisationID  string     `json:"organisation_id" csv:"organisation_id" gorm:"index:idx_ins_modified_at;size:37"`
	TemplateName    string     `json:"template_name" csv:"template_name"`
	TemplateAuthor  string     `json:"template_author" csv:"template_author"`
	SiteID          string     `json:"site_id" csv:"site_id" gorm:"size:41"`
	DateStarted     time.Time  `json:"date_started" csv:"date_started"`
	DateCompleted   *time.Time `json:"date_completed" csv:"date_completed"`
	DateModified    time.Time  `json:"date_modified" csv:"date_modified"`
	CreatedAt       time.Time  `json:"created_at" csv:"created_at"`
	ModifiedAt      time.Time  `json:"modified_at" csv:"modified_at" gorm:"index:idx_ins_modified_at,sort:desc"`
	ExportedAt      time.Time  `json:"exported_at" csv:"exported_at" gorm:"index:idx_ins_modified_at;autoUpdateTime"`
	DocumentNo      string     `json:"document_no" csv:"document_no"`
	PreparedBy      string     `json:"prepared_by" csv:"prepared_by"`
	Location        string     `json:"location" csv:"location"`
	ConductedOn     *time.Time `json:"conducted_on" csv:"conducted_on"`
	Personnel       string     `json:"personnel" csv:"personnel"`
	ClientSite      string     `json:"client_site" csv:"client_site"`
	Latitude        *float64   `json:"latitude" csv:"latitude"`
	Longitude       *float64   `json:"longitude" csv:"longitude"`
	WebReportLink   string     `json:"web_report_link" csv:"web_report_link"`
	Deleted         bool       `json:"deleted" csv:"deleted"`
}

Inspection represents a row from the inspections feed

type InspectionFeed

type InspectionFeed struct {
	SkipIDs       []string
	ModifiedAfter time.Time
	TemplateIDs   []string
	Archived      string
	Completed     string
	Incremental   bool
	Limit         int
	WebReportLink string
}

InspectionFeed is a representation of the inspections feed

func (*InspectionFeed) Columns

func (f *InspectionFeed) Columns() []string

Columns returns the columns of the row

func (*InspectionFeed) CreateSchema

func (f *InspectionFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*InspectionFeed) Export

func (f *InspectionFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*InspectionFeed) Model

func (f *InspectionFeed) Model() interface{}

Model returns the model of the feed row

func (*InspectionFeed) Name

func (f *InspectionFeed) Name() string

Name is the name of the feed

func (*InspectionFeed) Order

func (f *InspectionFeed) Order() string

Order returns the ordering when retrieving an export

func (*InspectionFeed) PrimaryKey

func (f *InspectionFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*InspectionFeed) RowsModel

func (f *InspectionFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type InspectionItem

type InspectionItem struct {
	ID                      string    `json:"id" csv:"id" gorm:"primarykey;size:150"`
	ItemID                  string    `json:"item_id" csv:"item_id" gorm:"size:100"`
	AuditID                 string    `json:"audit_id" csv:"audit_id" gorm:"size:100"`
	ItemIndex               int64     `json:"item_index" csv:"item_index"`
	TemplateID              string    `json:"template_id" csv:"template_id" gorm:"size:100"`
	ParentID                string    `json:"parent_id" csv:"parent_id" gorm:"size:100"`
	CreatedAt               time.Time `json:"created_at" csv:"created_at"`
	ModifiedAt              time.Time `json:"modified_at" csv:"modified_at" gorm:"index:idx_ins_itm_modified_at,sort:desc"`
	ExportedAt              time.Time `json:"exported_at" csv:"exported_at" gorm:"index:idx_ins_itm_modified_at;autoUpdateTime"`
	Type                    string    `json:"type" csv:"type" gorm:"size:20"`
	Category                string    `json:"category" csv:"category"`
	CategoryID              string    `json:"category_id" csv:"category_id" gorm:"size:100"`
	OrganisationID          string    `json:"organisation_id" csv:"organisation_id" gorm:"index:idx_ins_itm_modified_at;size:37"`
	ParentIDs               string    `json:"parent_ids" csv:"parent_ids"`
	Label                   string    `json:"label" csv:"label"`
	Response                string    `json:"response" csv:"response"`
	ResponseID              string    `json:"response_id" csv:"response_id" gorm:"size:100"`
	ResponseSetID           string    `json:"response_set_id" csv:"response_set_id" gorm:"size:100"`
	IsFailedResponse        bool      `json:"is_failed_response" csv:"is_failed_response"`
	Comment                 string    `json:"comment" csv:"comment"`
	MediaFiles              string    `json:"media_files" csv:"media_files"`
	MediaIDs                string    `json:"media_ids" csv:"media_ids"`
	MediaHypertextReference string    `json:"media_hypertext_reference" csv:"media_hypertext_reference"`
	Score                   float32   `json:"score" csv:"score"`
	MaxScore                float32   `json:"max_score" csv:"max_score"`
	ScorePercentage         float32   `json:"score_percentage" csv:"score_percentage"`
	CombinedScore           float32   `json:"combined_score" csv:"combined_score"`
	CombinedMaxScore        float32   `json:"combined_max_score" csv:"combined_max_score"`
	CombinedScorePercentage float32   `json:"combined_score_percentage" csv:"combined_score_percentage"`
	Mandatory               bool      `json:"mandatory" csv:"mandatory"`
	Inactive                bool      `json:"inactive" csv:"inactive"`
	LocationLatitude        *float32  `json:"location_latitude" csv:"location_latitude"`
	LocationLongitude       *float32  `json:"location_longitude" csv:"location_longitude"`
}

InspectionItem represents a row from the inspection_items feed

type InspectionItemFeed

type InspectionItemFeed struct {
	SkipIDs         []string
	ModifiedAfter   time.Time
	TemplateIDs     []string
	Archived        string
	Completed       string
	IncludeInactive bool
	Incremental     bool
	ExportMedia     bool
	Limit           int
}

InspectionItemFeed is a representation of the inspection_items feed

func (*InspectionItemFeed) Columns

func (f *InspectionItemFeed) Columns() []string

Columns returns the columns of the row

func (*InspectionItemFeed) CreateSchema

func (f *InspectionItemFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*InspectionItemFeed) Export

func (f *InspectionItemFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*InspectionItemFeed) Model

func (f *InspectionItemFeed) Model() interface{}

Model returns the model of the feed row

func (*InspectionItemFeed) Name

func (f *InspectionItemFeed) Name() string

Name is the name of the feed

func (*InspectionItemFeed) Order

func (f *InspectionItemFeed) Order() string

Order returns the ordering when retrieving an export

func (*InspectionItemFeed) PrimaryKey

func (f *InspectionItemFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*InspectionItemFeed) RowsModel

func (f *InspectionItemFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type Issue

type Issue struct {
	ID              string     `json:"id" csv:"id" gorm:"primarykey;column:id;size:36"`
	Title           string     `json:"title" csv:"title"`
	Description     string     `json:"description" csv:"description"`
	CreatorID       string     `json:"creator_id" csv:"creator_id"`
	CreatorUserName string     `json:"creator_user_name" csv:"creator_user_name"`
	CreatedAt       time.Time  `json:"created_at" csv:"created_at"`
	DueAt           *time.Time `json:"due_at,omitempty" csv:"due_at"`
	Priority        string     `json:"priority" csv:"priority"`
	Status          string     `json:"status" csv:"status"`
	TemplateID      string     `json:"template_id" csv:"template_id"`
	InspectionID    string     `json:"inspection_id" csv:"inspection_id"`
	InspectionName  string     `json:"inspection_name" csv:"inspection_name"`
	SiteID          string     `json:"site_id" csv:"site_id"`
	SiteName        string     `json:"site_name" csv:"site_name"`
	LocationName    string     `json:"location_name" csv:"location_name"`
	CategoryID      string     `json:"category_id" csv:"category_id"`
	CategoryLabel   string     `json:"category_label" csv:"category_label"`
}

Issue represents a row from the issues feed

type IssueFeed

type IssueFeed struct {
	Limit       int
	Incremental bool
}

IssueFeed is a representation of the issues feed

func (*IssueFeed) Columns

func (f *IssueFeed) Columns() []string

Columns returns the columns of the row

func (*IssueFeed) CreateSchema

func (f *IssueFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*IssueFeed) Export

func (f *IssueFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*IssueFeed) Model

func (f *IssueFeed) Model() interface{}

Model returns the model of the feed row

func (*IssueFeed) Name

func (f *IssueFeed) Name() string

Name returns the name of the feed

func (*IssueFeed) Order

func (f *IssueFeed) Order() string

Order returns the ordering when retrieving an export

func (*IssueFeed) PrimaryKey

func (f *IssueFeed) PrimaryKey() []string

PrimaryKey return the primary key

func (*IssueFeed) RowsModel

func (f *IssueFeed) RowsModel() interface{}

RowsModel returns the model of the feed rows

type LogStringConfig

type LogStringConfig struct {
	RemainingRecords int64
	HTTPDuration     time.Duration
	ExporterDuration time.Duration
}

LogStringConfig is the config for GetLogString function

type ReportExporter

type ReportExporter struct {
	*SQLExporter
	Logger       *zap.SugaredLogger
	ExportPath   string
	PreferenceID string
	Filename     string
	Format       []string
	Mu           sync.Mutex
}

ReportExporter is an interface to export data feeds to CSV files

func NewReportExporter

func NewReportExporter(exportPath string, format []string, preferenceID string, filename string) (*ReportExporter, error)

NewReportExporter returns a new instance of ReportExporter

func (*ReportExporter) GetDuration

func (e *ReportExporter) GetDuration() time.Duration

GetDuration will return the duration for exporting a batch

func (*ReportExporter) SaveReports

func (e *ReportExporter) SaveReports(ctx context.Context, apiClient *api.Client, feed *InspectionFeed) error

SaveReports downloads and stores inspection reports on disk

type SQLExporter

type SQLExporter struct {
	DB              *gorm.DB
	Logger          *zap.SugaredLogger
	AutoMigrate     bool
	ExportMediaPath string
	// contains filtered or unexported fields
}

SQLExporter is an interface to export data feeds to SQL databases

func NewSQLExporter

func NewSQLExporter(dialect, connectionString string, autoMigrate bool, exportMediaPath string) (*SQLExporter, error)

NewSQLExporter creates a new instance of the SQLExporter

func (*SQLExporter) CreateSchema

func (e *SQLExporter) CreateSchema(feed Feed, _ interface{}) error

CreateSchema creates the schema on the DB for the supplied feed

func (*SQLExporter) DeleteRowsIfExist

func (e *SQLExporter) DeleteRowsIfExist(feed Feed, query string, args ...interface{}) error

DeleteRowsIfExist will delete the rows if already exist

func (*SQLExporter) FinaliseExport

func (e *SQLExporter) FinaliseExport(Feed, interface{}) error

FinaliseExport closes out an export

func (*SQLExporter) GetDuration

func (e *SQLExporter) GetDuration() time.Duration

GetDuration will return the duration for exporting a batch

func (*SQLExporter) InitFeed

func (e *SQLExporter) InitFeed(feed Feed, opts *InitFeedOptions) error

InitFeed initialises any tables required to export

func (*SQLExporter) LastModifiedAt

func (e *SQLExporter) LastModifiedAt(feed Feed, modifiedAfter time.Time, orgID string) (time.Time, error)

LastModifiedAt returns the latest stored modified at date for the feed

func (*SQLExporter) ParameterLimit

func (e *SQLExporter) ParameterLimit() int

ParameterLimit returns the number of parameters supported by the target DB

func (*SQLExporter) SupportsUpsert

func (e *SQLExporter) SupportsUpsert() bool

SupportsUpsert returns a bool if the exporter supports upserts

func (*SQLExporter) UpdateRows

func (e *SQLExporter) UpdateRows(feed Feed, primaryKeys []string, element map[string]interface{}) (int64, error)

UpdateRows batch updates. Returns number of rows updated or error. Works with single PKey, not with composed PKeys

func (*SQLExporter) WriteMedia

func (e *SQLExporter) WriteMedia(auditID, mediaID, contentType string, body []byte) error

WriteMedia writes the media to a file

func (*SQLExporter) WriteRows

func (e *SQLExporter) WriteRows(feed Feed, rows interface{}) error

WriteRows writes out the rows to the DB

type Schedule

type Schedule struct {
	ID              string     `json:"id" csv:"schedule_id" gorm:"primarykey;column:schedule_id;size:45"`
	Description     string     `json:"description" csv:"description"`
	Recurrence      string     `json:"recurrence" csv:"recurrence" gorm:"size:100"`
	Duration        string     `json:"duration" csv:"duration" gorm:"size:50"`
	ModifiedAt      time.Time  `json:"modified_at" csv:"modified_at"`
	ExportedAt      time.Time  `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
	FromDate        time.Time  `json:"from_date" csv:"from_date"`
	ToDate          *time.Time `json:"to_date" csv:"to_date"`
	StartTimeHour   int        `json:"start_time_hour" csv:"start_time_hour"`
	StartTimeMinute int        `json:"start_time_minute" csv:"start_time_minute"`
	AllMustComplete bool       `json:"all_must_complete" csv:"all_must_complete"`
	Status          string     `json:"status" csv:"status" gorm:"size:10"`
	OrganisationID  string     `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
	Timezone        string     `json:"timezone" csv:"timezone"`
	CanLateSubmit   bool       `json:"can_late_submit" csv:"can_late_submit"`
	SiteID          string     `json:"site_id" csv:"site_id" gorm:"size:41"`
	TemplateID      string     `json:"template_id" csv:"template_id" gorm:"size:100"`
	CreatorUserID   string     `json:"creator_user_id" csv:"creator_user_id" gorm:"size:37"`
}

Schedule represents a row from the schedules feed

type ScheduleAssignee

type ScheduleAssignee struct {
	ID             string    `json:"id" csv:"id" gorm:"primarykey;size:100"`
	ScheduleID     string    `json:"schedule_id" csv:"schedule_id" gorm:"size:45"`
	AssigneeID     string    `json:"assignee_id" csv:"assignee_id" gorm:"size:37"`
	OrganisationID string    `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
	Type           string    `json:"type" csv:"type" gorm:"size:10"`
	Name           string    `json:"name" csv:"name"`
	ExportedAt     time.Time `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
}

ScheduleAssignee represents a row from the schedule_assignees feed

type ScheduleAssigneeFeed

type ScheduleAssigneeFeed struct {
	TemplateIDs []string
}

ScheduleAssigneeFeed is a representation of the schedule_assignees feed

func (*ScheduleAssigneeFeed) Columns

func (f *ScheduleAssigneeFeed) Columns() []string

Columns returns the columns of the row

func (*ScheduleAssigneeFeed) CreateSchema

func (f *ScheduleAssigneeFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*ScheduleAssigneeFeed) Export

func (f *ScheduleAssigneeFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*ScheduleAssigneeFeed) Model

func (f *ScheduleAssigneeFeed) Model() interface{}

Model returns the model of the feed row

func (*ScheduleAssigneeFeed) Name

func (f *ScheduleAssigneeFeed) Name() string

Name is the name of the feed

func (*ScheduleAssigneeFeed) Order

func (f *ScheduleAssigneeFeed) Order() string

Order returns the ordering when retrieving an export

func (*ScheduleAssigneeFeed) PrimaryKey

func (f *ScheduleAssigneeFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*ScheduleAssigneeFeed) RowsModel

func (f *ScheduleAssigneeFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type ScheduleFeed

type ScheduleFeed struct {
	TemplateIDs []string
}

ScheduleFeed is a representation of the schedules feed

func (*ScheduleFeed) Columns

func (f *ScheduleFeed) Columns() []string

Columns returns the columns of the row

func (*ScheduleFeed) CreateSchema

func (f *ScheduleFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*ScheduleFeed) Export

func (f *ScheduleFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*ScheduleFeed) Model

func (f *ScheduleFeed) Model() interface{}

Model returns the model of the feed row

func (*ScheduleFeed) Name

func (f *ScheduleFeed) Name() string

Name is the name of the feed

func (*ScheduleFeed) Order

func (f *ScheduleFeed) Order() string

Order returns the ordering when retrieving an export

func (*ScheduleFeed) PrimaryKey

func (f *ScheduleFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*ScheduleFeed) RowsModel

func (f *ScheduleFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type ScheduleOccurrence

type ScheduleOccurrence struct {
	ID               string     `json:"id" csv:"id" gorm:"primarykey;size:128"`
	ScheduleID       string     `json:"schedule_id" csv:"schedule_id" gorm:"size:45"`
	OccurrenceID     string     `json:"occurrence_id" csv:"occurrence_id" gorm:"size:30"`
	TemplateID       string     `json:"template_id" csv:"template_id" gorm:"size:100"`
	OrganisationID   string     `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
	StartTime        *time.Time `json:"start_time" csv:"start_time"`
	DueTime          *time.Time `json:"due_time" csv:"due_time"`
	MissTime         *time.Time `json:"miss_time" csv:"miss_time"`
	OccurrenceStatus string     `json:"occurrence_status" csv:"occurrence_status" gorm:"size:20"`
	AuditID          *string    `json:"audit_id" csv:"audit_id" gorm:"size:100"`
	CompletedAt      *time.Time `json:"completed_at" csv:"completed_at"`
	ExportedAt       time.Time  `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
	UserID           string     `json:"user_id" csv:"user_id" gorm:"size:37"`
	AssigneeStatus   string     `json:"assignee_status" csv:"assignee_status" gorm:"size:20"`
}

ScheduleOccurrence represents a row from the schedule_occurrences feed

type ScheduleOccurrenceFeed

type ScheduleOccurrenceFeed struct {
	TemplateIDs []string
}

ScheduleOccurrenceFeed is a representation of the schedule_occurrences feed

func (*ScheduleOccurrenceFeed) Columns

func (f *ScheduleOccurrenceFeed) Columns() []string

Columns returns the columns of the row

func (*ScheduleOccurrenceFeed) CreateSchema

func (f *ScheduleOccurrenceFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*ScheduleOccurrenceFeed) Export

func (f *ScheduleOccurrenceFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*ScheduleOccurrenceFeed) Model

func (f *ScheduleOccurrenceFeed) Model() interface{}

Model returns the model of the feed row

func (*ScheduleOccurrenceFeed) Name

func (f *ScheduleOccurrenceFeed) Name() string

Name is the name of the feed

func (*ScheduleOccurrenceFeed) Order

func (f *ScheduleOccurrenceFeed) Order() string

Order returns the ordering when retrieving an export

func (*ScheduleOccurrenceFeed) PrimaryKey

func (f *ScheduleOccurrenceFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*ScheduleOccurrenceFeed) RowsModel

func (f *ScheduleOccurrenceFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type SchemaExporter

type SchemaExporter struct {
	*SQLExporter
	Logger *zap.SugaredLogger
	Output io.Writer
}

SchemaExporter is an interface to export data feeds to CSV files

func NewSchemaExporter

func NewSchemaExporter(output io.Writer) (*SchemaExporter, error)

NewSchemaExporter creates a new instance of SchemaExporter

func (*SchemaExporter) GetDuration

func (e *SchemaExporter) GetDuration() time.Duration

GetDuration will return the duration for exporting a batch

func (*SchemaExporter) WriteSchema

func (e *SchemaExporter) WriteSchema(feed Feed) error

WriteSchema writes schema of a feed to output in tabular format

type Site

type Site struct {
	ID             string    `json:"id" csv:"site_id" gorm:"primarykey;column:site_id;size:41"`
	Name           string    `json:"name" csv:"name"`
	CreatorID      string    `json:"creator_id" csv:"creator_id" gorm:"size:37"`
	OrganisationID string    `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
	ExportedAt     time.Time `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
	Deleted        bool      `json:"deleted" csv:"deleted" gorm:"deleted"`
	SiteUUID       string    `json:"site_uuid" csv:"site_uuid" gorm:"size:36"`
	MetaLabel      string    `json:"meta_label" csv:"meta_label" gorm:"size:36"`
	ParentID       string    `json:"parent_id" csv:"parent_id" gorm:"size:41"`
}

Site represents a row from the sites feed

type SiteFeed

type SiteFeed struct {
	IncludeDeleted       bool
	IncludeFullHierarchy bool
}

SiteFeed is a representation of the sites feed

func (*SiteFeed) Columns

func (f *SiteFeed) Columns() []string

Columns returns the columns of the row

func (*SiteFeed) CreateSchema

func (f *SiteFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*SiteFeed) Export

func (f *SiteFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*SiteFeed) Model

func (f *SiteFeed) Model() interface{}

Model returns the model of the feed row

func (*SiteFeed) Name

func (f *SiteFeed) Name() string

Name is the name of the feed

func (*SiteFeed) Order

func (f *SiteFeed) Order() string

Order returns the ordering when retrieving an export

func (*SiteFeed) PrimaryKey

func (f *SiteFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*SiteFeed) RowsModel

func (f *SiteFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type SiteMember

type SiteMember struct {
	SiteID     string    `json:"site_id" csv:"site_id" gorm:"primarykey;column:site_id;size:41"`
	MemberID   string    `json:"member_id" csv:"member_id" gorm:"primarykey;column:member_id;size:37"`
	ExportedAt time.Time `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
}

SiteMember represents a row from the site members feed

type SiteMemberFeed

type SiteMemberFeed struct {
}

SiteMemberFeed is a representation of the sites feed

func (*SiteMemberFeed) Columns

func (f *SiteMemberFeed) Columns() []string

Columns returns the columns of the row

func (*SiteMemberFeed) CreateSchema

func (f *SiteMemberFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*SiteMemberFeed) Export

func (f *SiteMemberFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*SiteMemberFeed) Model

func (f *SiteMemberFeed) Model() interface{}

Model returns the model of the feed row

func (*SiteMemberFeed) Name

func (f *SiteMemberFeed) Name() string

Name is the name of the feed

func (*SiteMemberFeed) Order

func (f *SiteMemberFeed) Order() string

Order returns the ordering when retrieving an export

func (*SiteMemberFeed) PrimaryKey

func (f *SiteMemberFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*SiteMemberFeed) RowsModel

func (f *SiteMemberFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type Template

type Template struct {
	ID             string    `json:"id" csv:"template_id" gorm:"primarykey;column:template_id;size:100"`
	Archived       bool      `json:"archived" csv:"archived"`
	Name           string    `json:"name" csv:"name"`
	Description    string    `json:"description" csv:"description"`
	OrganisationID string    `json:"organisation_id" csv:"organisation_id" gorm:"index:idx_tml_modified_at;size:37"`
	OwnerName      string    `json:"owner_name" csv:"owner_name"`
	OwnerID        string    `json:"owner_id" csv:"owner_id" gorm:"size:37"`
	AuthorName     string    `json:"author_name" csv:"author_name"`
	AuthorID       string    `json:"author_id" csv:"author_id" gorm:"size:37"`
	CreatedAt      time.Time `json:"created_at" csv:"created_at"`
	ModifiedAt     time.Time `json:"modified_at" csv:"modified_at" gorm:"index:idx_tml_modified_at,sort:desc"`
	ExportedAt     time.Time `json:"exported_at" csv:"exported_at" gorm:"index:idx_tml_modified_at;autoUpdateTime"`
}

Template represents a row from the templates feed

type TemplateFeed

type TemplateFeed struct {
	ModifiedAfter time.Time
	Incremental   bool
}

TemplateFeed is a representation of the templates feed

func (*TemplateFeed) Columns

func (f *TemplateFeed) Columns() []string

Columns returns the columns of the row

func (*TemplateFeed) CreateSchema

func (f *TemplateFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*TemplateFeed) Export

func (f *TemplateFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*TemplateFeed) Model

func (f *TemplateFeed) Model() interface{}

Model returns the model of the feed row

func (*TemplateFeed) Name

func (f *TemplateFeed) Name() string

Name is the name of the feed

func (*TemplateFeed) Order

func (f *TemplateFeed) Order() string

Order returns the ordering when retrieving an export

func (*TemplateFeed) PrimaryKey

func (f *TemplateFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*TemplateFeed) RowsModel

func (f *TemplateFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type TemplatePermission

type TemplatePermission struct {
	ID             string `json:"id" csv:"permission_id" gorm:"primarykey;column:permission_id;size:375"`
	TemplateID     string `json:"template_id" csv:"template_id" gorm:"size:100"`
	Permission     string `json:"permission" csv:"permission" gorm:"size:10"`
	AssigneeID     string `json:"assignee_id" csv:"assignee_id" gorm:"size:256"`
	AssigneeType   string `json:"assignee_type" csv:"assignee_type" gorm:"size:10"`
	OrganisationID string `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
}

TemplatePermission represents a row from the template_permissions feed

type TemplatePermissionFeed

type TemplatePermissionFeed struct {
	ModifiedAfter time.Time
	Incremental   bool
}

TemplatePermissionFeed is a representation of the template_permissions feed

func (*TemplatePermissionFeed) Columns

func (f *TemplatePermissionFeed) Columns() []string

Columns returns the columns of the row

func (*TemplatePermissionFeed) CreateSchema

func (f *TemplatePermissionFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*TemplatePermissionFeed) Export

func (f *TemplatePermissionFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*TemplatePermissionFeed) Model

func (f *TemplatePermissionFeed) Model() interface{}

Model returns the model of the feed row

func (*TemplatePermissionFeed) Name

func (f *TemplatePermissionFeed) Name() string

Name is the name of the feed

func (*TemplatePermissionFeed) Order

func (f *TemplatePermissionFeed) Order() string

Order returns the ordering when retrieving an export

func (*TemplatePermissionFeed) PrimaryKey

func (f *TemplatePermissionFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*TemplatePermissionFeed) RowsModel

func (f *TemplatePermissionFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

type User

type User struct {
	ID             string     `json:"id" csv:"user_id" gorm:"primarykey;column:user_id;size:37"`
	OrganisationID string     `json:"organisation_id" csv:"organisation_id" gorm:"size:37"`
	Email          string     `json:"email" csv:"email" gorm:"size:256"`
	Firstname      string     `json:"firstname" csv:"firstname"`
	Lastname       string     `json:"lastname" csv:"lastname"`
	Active         bool       `json:"active" csv:"active"`
	LastSeenAt     *time.Time `json:"last_seen_at" csv:"last_seen_at"`
	ExportedAt     time.Time  `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"`
}

User represents a row from the users feed

type UserFeed

type UserFeed struct{}

UserFeed is a representation of the users feed

func (*UserFeed) Columns

func (f *UserFeed) Columns() []string

Columns returns the columns of the row

func (*UserFeed) CreateSchema

func (f *UserFeed) CreateSchema(exporter Exporter) error

CreateSchema creates the schema of the feed for the supplied exporter

func (*UserFeed) Export

func (f *UserFeed) Export(ctx context.Context, apiClient *api.Client, exporter Exporter, orgID string) error

Export exports the feed to the supplied exporter

func (*UserFeed) Model

func (f *UserFeed) Model() interface{}

Model returns the model of the feed row

func (*UserFeed) Name

func (f *UserFeed) Name() string

Name is the name of the feed

func (*UserFeed) Order

func (f *UserFeed) Order() string

Order returns the ordering when retrieving an export

func (*UserFeed) PrimaryKey

func (f *UserFeed) PrimaryKey() []string

PrimaryKey returns the primary key(s)

func (*UserFeed) RowsModel

func (f *UserFeed) RowsModel() interface{}

RowsModel returns the model of feed rows

Jump to

Keyboard shortcuts

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