models

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: GPL-3.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package models contains the base "domain logic" data types used by Qvain.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIdMissing          = errors.New("missing dataset id")
	ErrIdPresent          = errors.New("dataset already has id")
	ErrDatasetTypeMissing = errors.New("dataset type is missing")
	ErrSchemaMissing      = errors.New("schema identifier is missing")
	ErrDatasetMissing     = errors.New("dataset is missing or empty")
)
View Source
var ErrInvalidFamily = errors.New("Invalid dataset type")

Functions

func RegisterFamily

func RegisterFamily(id int, name string, newFunc NewFunc, loadFunc LoadFunc, paths []string)

RegisterFamily registers a dataset type into the global registry.

Types

type AccessGranter added in v0.10.3

type AccessGranter struct {
	UserID string `json:"userid"`
	Name   string `json:"name"`
	Email  string `json:"email"`
}

AccessGranter is used for REMS access granter metadata.

type Dataset

type Dataset struct {
	Id      uuid.UUID
	Creator uuid.UUID
	Owner   uuid.UUID

	Created  time.Time
	Modified time.Time
	Synced   time.Time

	Published bool
	Removed   bool
	// contains filtered or unexported fields
}

func NewDataset

func NewDataset(creator uuid.UUID) (*Dataset, error)

NewDataset creates a new dataset record with given Creator (which is also set into the Owner field). NOTE: the database will set Created and Modified dates to Now() by default.

func (*Dataset) Blob

func (ds *Dataset) Blob() []byte

func (*Dataset) CreateData

func (ds *Dataset) CreateData(family int, schema string, blob []byte, extra map[string]string) error

CreateData allows dataset types to override what happens on dataset creation.

func (*Dataset) Family

func (ds *Dataset) Family() int

func (*Dataset) IsValid

func (ds *Dataset) IsValid() bool

func (*Dataset) Schema

func (ds *Dataset) Schema() string

func (*Dataset) SetData

func (ds *Dataset) SetData(family int, schema string, blob []byte) error

SetData sets the schema family and name as well as the metadata blob. It is an error not to provide the appropriate schema family and name.

func (*Dataset) SetValid

func (ds *Dataset) SetValid(valid bool)

func (*Dataset) Unwrap

func (ds *Dataset) Unwrap() *Dataset

func (*Dataset) UpdateData

func (ds *Dataset) UpdateData(family int, schema string, blob []byte, extra map[string]string) error

UpdateData allows dataset types to override what happens on update of an existing dataset.

type LoadFunc

type LoadFunc func(*Dataset) TypedDataset

LoadFunc is a constructor function that wraps a base dataset returning a typed dataset satisfying the TypedDataset interface.

type NewFunc

type NewFunc func(uuid.UUID) (TypedDataset, error)

NewFunc is a constructor function that creates a new typed datatset satisfying the TypedDataset interface.

type OpenDataset

type OpenDataset struct {
	*Dataset
}

OpenDataset is a dataset type with no restrictions.

type SchemaFamily

type SchemaFamily struct {
	Id       int
	Name     string
	NewFunc  NewFunc
	LoadFunc LoadFunc
	// contains filtered or unexported fields
}

SchemaFamily defines a dataset type.

func LookupFamily

func LookupFamily(id int) (*SchemaFamily, error)

LookupFamily looks up a dataset type from the global registry.

func (*SchemaFamily) IsPartial

func (fam *SchemaFamily) IsPartial() bool

IsPartial returns a boolean indicating if this is a dataset that is only partially shown to the API.

func (*SchemaFamily) IsPathPublic

func (fam *SchemaFamily) IsPathPublic(p string) bool

IsPathPublic returns a boolean indicating if the dataset's subkey can be shown via API. A nil path list means no restrictions.

func (*SchemaFamily) Key

func (fam *SchemaFamily) Key() string

Key returns the key containing the partial dataset; the first element of the publicPaths slice.

type TypeRegistry

type TypeRegistry struct {
	// contains filtered or unexported fields
}

func NewTypeRegistry

func NewTypeRegistry() *TypeRegistry

func (*TypeRegistry) Lookup

func (reg *TypeRegistry) Lookup(id int) (*SchemaFamily, error)

func (*TypeRegistry) Register

func (reg *TypeRegistry) Register(id int, name string, newFunc NewFunc, loadFunc LoadFunc, paths []string)

type TypedDataset

type TypedDataset interface {
	CreateData(int, string, []byte, map[string]string) error
	UpdateData(int, string, []byte, map[string]string) error
	Unwrap() *Dataset
}

TypedDataset is a wrapper around a base dataset that allows different dataset types to fondle the data in ways that pleases them.

func CreateDatasetFromJson

func CreateDatasetFromJson(creator uuid.UUID, data io.Reader, inject map[string]string) (TypedDataset, error)

CreateDatasetFromJson creates a typed dataset with JSON data originating from the web API. Caller closes body.

func LoadOpenDataset

func LoadOpenDataset(ds *Dataset) TypedDataset

LoadUntypedDataset constructs an existing open dataset from an existing base dataset.

func LoadUntypedDataset

func LoadUntypedDataset(ds *Dataset) TypedDataset

LoadUntypedDataset constructs an existing untyped dataset from an existing base dataset.

func NewOpenDataset

func NewOpenDataset(creator uuid.UUID) (TypedDataset, error)

NewOpenDataset creates a new Open (unrestricted) dataset.

func NewUntypedDataset

func NewUntypedDataset(creator uuid.UUID) (TypedDataset, error)

NewUntypedDataset creates an untyped dataset.

func UpdateDatasetFromJson

func UpdateDatasetFromJson(owner uuid.UUID, data io.Reader, inject map[string]string) (TypedDataset, error)

UpdateDatasetFromJson makes a – potentially partial – typed dataset with JSON data originating from the web API. func UpdateDatasetFromJson(owner uuid.UUID, data []byte) (TypedDataset, error) {

type UntypedDataset

type UntypedDataset struct {
	*Dataset
}

UntypedDataset is a fall-back dataset type for datasets without type.

type User

type User struct {
	// Uid is the qvain user id.
	Uid uuid.UUID

	// Identity is the identity the user logged in with. Can be empty if the user didn't actually log in.
	Identity string

	// Service is the service from which the identity originated. Can be empty if the user didn't actually log in.
	Service string

	// Name is the user's name, if available.
	Name string

	// Email is the user's primary email address (if provided).
	Email string

	// Organisation is the organisation the external identity is a member of (if provided).
	Organisation string

	// Projects are a sort of user groups defined in the token.
	// This is a list instead of a map/set because lists are faster for small numbers of elements (~20).
	Projects []string
}

User defines a basic user object to hold common session information.

func UserFromJson

func UserFromJson(b []byte) (u *User, err error)

UserFromJson constructs a new user object by calling unmarshal on the given json byte slice.

func (*User) AddAccessGranter added in v0.10.3

func (user *User) AddAccessGranter(rawQuery string) string

AddAccessGranter adds REMS access granter metadata to query string.

func (*User) AddAllowedProjects

func (user *User) AddAllowedProjects(rawQuery string) string

AddAllowedProjects adds user projects to a query string as a comma-separated allowed_projects parameter. The raw query string is used directly instead of using query.Encode() to avoid escaping commas.

func (*User) HasProject

func (user *User) HasProject(project string) bool

HasProject returns a boolean value indicating whether a user is a member of a given project.

func (*User) IsNil

func (u *User) IsNil() bool

IsNil implements gojay.IsNil interface.

func (*User) MarshalJSONObject

func (user *User) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements gojay.MarshalJSONObject.

func (*User) NKeys

func (u *User) NKeys() int

func (*User) UnmarshalJSON

func (user *User) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the Unmarshaler interface from the standard library json package.

func (*User) UnmarshalJSONObject

func (user *User) UnmarshalJSONObject(dec *gojay.Decoder, key string) (err error)

UnmarshalerJSONObject implements gojay.UnmarshalerJSONObject.

Jump to

Keyboard shortcuts

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