Documentation ¶
Overview ¶
Package models contains the base "domain logic" data types used by Qvain.
Index ¶
- Variables
- func RegisterFamily(id int, name string, newFunc NewFunc, loadFunc LoadFunc, paths []string)
- type AccessGranter
- type Dataset
- func (ds *Dataset) Blob() []byte
- func (ds *Dataset) CreateData(family int, schema string, blob []byte, extra map[string]string) error
- func (ds *Dataset) Family() int
- func (ds *Dataset) IsValid() bool
- func (ds *Dataset) Schema() string
- func (ds *Dataset) SetData(family int, schema string, blob []byte) error
- func (ds *Dataset) SetValid(valid bool)
- func (ds *Dataset) Unwrap() *Dataset
- func (ds *Dataset) UpdateData(family int, schema string, blob []byte, extra map[string]string) error
- type LoadFunc
- type NewFunc
- type OpenDataset
- type SchemaFamily
- type TypeRegistry
- type TypedDataset
- func CreateDatasetFromJson(creator uuid.UUID, data io.Reader, inject map[string]string) (TypedDataset, error)
- func LoadOpenDataset(ds *Dataset) TypedDataset
- func LoadUntypedDataset(ds *Dataset) TypedDataset
- func NewOpenDataset(creator uuid.UUID) (TypedDataset, error)
- func NewUntypedDataset(creator uuid.UUID) (TypedDataset, error)
- func UpdateDatasetFromJson(owner uuid.UUID, data io.Reader, inject map[string]string) (TypedDataset, error)
- type UntypedDataset
- type User
- func (user *User) AddAccessGranter(rawQuery string) string
- func (user *User) AddAllowedProjects(rawQuery string) string
- func (user *User) HasProject(project string) bool
- func (u *User) IsNil() bool
- func (user *User) MarshalJSONObject(enc *gojay.Encoder)
- func (u *User) NKeys() int
- func (user *User) UnmarshalJSON(b []byte) error
- func (user *User) UnmarshalJSONObject(dec *gojay.Decoder, key string) (err error)
Constants ¶
This section is empty.
Variables ¶
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") )
var ErrInvalidFamily = errors.New("Invalid dataset type")
Functions ¶
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 ¶
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) 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.
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)
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 ¶
UserFromJson constructs a new user object by calling unmarshal on the given json byte slice.
func (*User) AddAccessGranter ¶ added in v0.10.3
AddAccessGranter adds REMS access granter metadata to query string.
func (*User) AddAllowedProjects ¶
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 ¶
HasProject returns a boolean value indicating whether a user is a member of a given project.
func (*User) MarshalJSONObject ¶
MarshalJSONObject implements gojay.MarshalJSONObject.
func (*User) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaler interface from the standard library json package.