domain

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package domain contains all Ikuzo domain models.

To ensure decoupling and optimal reuse we have gathered the models in domain, the service package contains the services for each model. The storage package contains various implementations of the service store interfaces.

TODO: document the main flow of the application and the use of the models.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrIDTooLong          = errors.New("identifier is too long")
	ErrIDNotLowercase     = errors.New("uppercase not allowed in identifier")
	ErrIDInvalidCharacter = errors.New("only letters and numbers are allowed in organization")
	ErrIDCannotBeEmpty    = errors.New("empty string is not a valid identifier")
	ErrIDExists           = errors.New("identifier already exists")
	ErrOrgNotFound        = errors.New("organization not found")
	ErrHubIDInvalid       = errors.New("HubID strings is invalid")
)

errors

View Source
var (
	ErrNameSpaceNotFound       = errors.New("namespace not found")
	ErrNameSpaceDuplicateEntry = errors.New("prefix and base stored in different entries")
	ErrNameSpaceNotValid       = errors.New("prefix or base not valid")
)
View Source
var ErrServiceNotEnabled = fmt.Errorf("service not enabled for this organization")
View Source
var (
	// MaxLengthID the maximum length of an identifier
	MaxLengthID = 12
)

Functions

func SetOrganization added in v0.3.0

func SetOrganization(r *http.Request, org *Organization) *http.Request

SetOrganization sets the orgID in the context of a *http.Request

This function is called by the middleware

func SetOrganizationID added in v0.2.0

func SetOrganizationID(r *http.Request, orgID string) *http.Request

SetOrganizationID sets the orgID in the context of a *http.Request

This function is called by the middleware

func SplitURI

func SplitURI(uri string) (base, name string)

SplitURI takes a given URI and splits it into a base-URI and a localname. When the URI can't be split, the full URI is returned as the label with an empty base.

Example
package main

import (
	"fmt"

	"github.com/delving/hub3/ikuzo/domain"
)

func main() {
	fmt.Println(domain.SplitURI("http://purl.org/dc/elements/1.1/subject"))
}
Output:

http://purl.org/dc/elements/1.1/ subject

func URLParam added in v0.2.0

func URLParam(r *http.Request, key string) string

Types

type ArchesConfig added in v0.3.0

type ArchesConfig struct {
	Enabled           bool   `json:"enabled"`
	URL               string `json:"url"`
	OAuthClientID     string `json:"oAuthClientID"`
	OAuthClientSecret string `json:"oAuthClientSecret"`
	UserName          string `json:"userName"`
	Password          string `json:"password"`
	DSN               string `json:"dsn"` // arches postgresql
}

type DataSetRevisions added in v0.2.0

type DataSetRevisions struct {
	Number      int `json:"revisionNumber"`
	RecordCount int `json:"recordCount"`
}

DataSetRevisions holds the type-frequency data for each revision for a given DataSet

type HubID added in v0.3.0

type HubID struct {
	OrgID     string
	DatasetID string
	LocalID   string
}

func NewHubID added in v0.3.0

func NewHubID(input string) (HubID, error)

func (HubID) String added in v0.3.0

func (h HubID) String() string

type Namespace added in v0.2.1

type Namespace struct {

	// ID is the unique identifier of a namespace.
	// This identifier will be generated when empty.
	//
	// example: "f9ca66c45c2c0a61"
	ID string `json:"uuid"`

	// Base is the default base-URI for a namespace
	// example: "http://purl.org/dc/elements/1.1/"
	Base string `json:"base"`

	// Prefix is the default short version that identifies the base-URI
	// example: "dc"
	Prefix string `json:"prefix"`

	// BaseAlt are alternative base-URI for the same prefix.
	// Sometimes historically the base-URIs for a namespace changes and we still
	// have to correctly resolve both.
	//
	// example: "["http://purl.org/dc/elements/1.1/"]"
	BaseAlt []string `json:"baseAlt,omitempty"`

	// PrefixAlt are altenative prefixes for the default base URI.
	// Different content-providers and organizations have at time selected alternative
	// prefixes for the same base URI. We need to support both entry-points.
	//
	// example: "["dce", "dc11"]"
	PrefixAlt []string `json:"prefixAlt,omitempty"`

	// Schema is an URL to the RDFS or OWL definition of namespace
	// example: "https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_terms.ttl"
	Schema string `json:"schema,omitempty"`

	// Temporary defines if the NameSpace has been given a temporary prefix because
	// only the base-URI was known when the NameSpace was created.
	// Namespaces with prefix collissions will also be given a temporary prefix
	//
	// example: "true"
	// default: "false"
	Temporary bool `json:"temporary,omitempty"`
}

Namespace is a container for URI conversions for RDF- and XML-namespaces.

func (*Namespace) AddBase added in v0.2.1

func (ns *Namespace) AddBase(base string) error

AddBase adds a base-URI to the list of base alternatives.

When the base-URI is already present in BaseAlt no error is thrown.

func (*Namespace) AddPrefix added in v0.2.1

func (ns *Namespace) AddPrefix(prefix string) error

AddPrefix adds a prefix to the list of prefix alternatives.

When the prefix is already present in PrefixAlt no error is thrown.

func (*Namespace) BaseURIs added in v0.2.1

func (ns *Namespace) BaseURIs() []string

BaseURIs returns all namespace base-URIs linked to this NameSpace. This includes the default Base and all alternative base-URIs.

func (*Namespace) GetID added in v0.2.1

func (ns *Namespace) GetID() string

GetID returns a string representation of a UUID. When no UUID is set, this function will generate it and update the NameSpace.

func (*Namespace) Merge added in v0.2.1

func (ns *Namespace) Merge(other *Namespace) error

Merge merges the values of two NameSpace objects. The prefixes and alternative base URIs of the other NameSpace are merged into ns.

func (*Namespace) Prefixes added in v0.2.1

func (ns *Namespace) Prefixes() []string

Prefixes returns all namespace prefix linked to this NameSpace. This includes the default Prefix and all alternative prefixes.

func (*Namespace) String added in v0.2.1

func (ns *Namespace) String() string

func (*Namespace) XMLNS added in v0.3.0

func (ns *Namespace) XMLNS() string

type OAIPMHConfig added in v0.3.0

type OAIPMHConfig struct {
	Enabled        bool     `json:"enabled"`
	AdminEmails    []string `json:"adminEmails"`
	RepositoryName string   `json:"repositoryName"`
	Deleted        string   `json:"deleted"` // no, persistent, transient

}

type OrgConfigRetriever added in v0.3.0

type OrgConfigRetriever interface {
	RetrieveConfig(orgID string) (cfg OrganizationConfig, ok bool)
}

type Organization

type Organization struct {
	ID     OrganizationID     `json:"orgID"`
	Config OrganizationConfig `json:"config"`
}

Organization is a basic building block for storing information. Everything that is stored by ikuzo must have an organization.ID as part of its metadata.

func GetOrganization added in v0.3.0

func GetOrganization(r *http.Request) (Organization, bool)

GetOrganization retrieves an Organization from a *http.Request.

This Organization is set by middleware and available for each request

func (*Organization) NewDatasetURI added in v0.2.0

func (o *Organization) NewDatasetURI(spec string) string

func (*Organization) RawID added in v0.2.0

func (o *Organization) RawID() string

RawID returns the raw direct identifier string for an Organization

type OrganizationConfig added in v0.2.0

type OrganizationConfig struct {
	Domains     []string      `json:"domains,omitempty"`
	Default     bool          `json:"default"`
	CustomID    string        `json:"customID"`
	Name        string        `json:"name"`
	Description string        `json:"description"`
	IndexTypes  []string      `json:"indexTypes,omitempty"`
	Arches      *ArchesConfig `json:"arches"`
	// archivespace config
	ArchivesSpace struct {
		Enabled      bool   `json:"enabled"`
		URL          string `json:"url"`
		RepositoryID string `json:"repositoryID"`
	} `json:"archivesspace"`
	// Sitemaps       []SitemapConfig `json:"sitemaps,omitempty"`
	Sitemaps []struct {
		ID            string   `json:"id"`
		BaseURL       string   `json:"baseURL"`
		Query         string   `json:"query"`
		Filters       []string `json:"filters"` // qf and q URL params
		OrgID         string   `json:"-"`
		ExcludedSpecs []string `json:"excludedSpecs"`
	} `json:"sitemaps"`
	Config struct {
		Identifiers struct {
			ArkNAAN      string `json:"arkNAAN"`
			IsilCode     string `json:"isilCode"`
			BrocadeOrgID string `json:"brocadeOrgID"`
		} `json:"identifiers"`
		ShortName   string `json:"shortName"`
		SubTitle    string `json:"subTitle"`
		Description string `json:"description"`
		Location    string `json:"location"`
	} `json:"config"`
	ElasticSearch struct {
		// base of the index aliases
		IndexName string `json:"indexName,omitempty"`
		// if non-empty digital objects will be indexed in a dedicated v2 index
		DigitalObjectSuffix string `json:"digitalObjectSuffix,omitempty"`
		// IndexTypes options are v1, v2, fragment
		IndexTypes []string `json:"indexTypes,omitempty"`
		// Shards is the number of index shards created
		Shards int `json:"shards"`
		// Replicas is the number of replicas created
		Replicas int `json:"replicas"`
		// TrackTotalHits determins if elasticsearch counts results over 10.000
		TrackTotalHits bool `json:"trackTotalHits"`
		// Defaults are the search defaults to be used in the API
		Defaults struct {
			// maxTreeSize is the maximum size of the number of nodes in the tree navigation API
			MaxTreeSize int `json:"maxTreeSize"`
			// FacetSize is the default number of facet items returned from the v2 API
			FacetSize int `json:"facetSize"`
			// Limit is the default number of results returned from from the v2 API
			Limit int `json:"limit"`
			// MaxLimit is the maximum number of results returned from the v2 API
			MaxLimit int `json:"maxLimit"`
		} `json:"defaults"`
	} `json:"elasticSearch,omitempty"`
	OAIPMH struct {
		Enabled        bool     `json:"enabled"`
		AdminEmails    []string `json:"adminEmails"`
		RepositoryName string   `json:"repositoryName"`
		ResponseSize   int      `json:"responseSize"`
	} `json:"oaipmh,omitempty"`
	RDF struct {
		RDFBaseURL     string `json:"rdfBaseURL"`
		MintDatasetURL string `json:"mintDatasetURL"`
		MintOrgIDURL   string `json:"mintOrgIDURL"`
	} `json:"rdf,omitempty"`
	SPARQL struct {
		Enabled        bool   `json:"enabled"`    // Enable the SPARQL proxy
		Host           string `json:"host"`       // the base-url to the SPARQL endpoint including the scheme and the port
		QueryPath      string `json:"queryPath"`  // the relative path of the endpoint. This can should contain the database name that is injected when the sparql endpoint is build
		UpdatePath     string `json:"updatePath"` // the relative path of the update endpoint. This can should contain the database name that is injected when the sparql endpoint is build
		GraphStorePath string `json:"dataPath"`   // the relative GraphStore path of the endpoint. This can should contain the database name that is injected when the sparql endpoint is build
		UserName       string `json:"userName"`
		Password       string `json:"password"`
	} `json:"sparql,omitempty"`
	// contains filtered or unexported fields
}

func (*OrganizationConfig) GetDigitalObjectIndexName added in v0.3.0

func (cfg *OrganizationConfig) GetDigitalObjectIndexName() string

GetDigitalObjectIndexName returns the names for the digitalobject index. In some cases the indices for records and digitalobjects need to be split in separated indexes. The v2 indexname is returned when the digitalobject suffix is empty.

func (*OrganizationConfig) GetFragmentsIndexName added in v0.3.0

func (cfg *OrganizationConfig) GetFragmentsIndexName() string

GetFragmentsIndexName returns the indexname for lod-fragments

func (*OrganizationConfig) GetGraphStoreEndpoint added in v0.3.0

func (cfg *OrganizationConfig) GetGraphStoreEndpoint(dbName string) string

GetGraphStoreEndpoint builds the GraphStore endpoint from the RDF Config object. When the dbName is empty the OrgId from the configuration is used.

func (*OrganizationConfig) GetIndexName added in v0.3.0

func (cfg *OrganizationConfig) GetIndexName() string

GetIndexName returns the lowercased indexname for the v2 index This inforced correct behavior when creating an index in ElasticSearch.

func (*OrganizationConfig) GetSparqlEndpoint added in v0.3.0

func (cfg *OrganizationConfig) GetSparqlEndpoint(dbName string) string

GetSparqlEndpoint builds the SPARQL endpoint from the RDF Config object. When the dbName is empty the OrgId from the configuration is used.

func (*OrganizationConfig) GetSparqlUpdateEndpoint added in v0.3.0

func (cfg *OrganizationConfig) GetSparqlUpdateEndpoint(dbName string) string

GetSparqlUpdateEndpoint builds the SPARQL Update endpoint from the RDF Config object. When the dbName is empty the OrgId from the configuration is used.

func (*OrganizationConfig) GetSuggestIndexName added in v0.3.0

func (cfg *OrganizationConfig) GetSuggestIndexName() string

func (*OrganizationConfig) GetV1IndexName added in v0.3.0

func (cfg *OrganizationConfig) GetV1IndexName() string

GetV1IndexName returns the v1 index name

func (*OrganizationConfig) OrgID added in v0.3.0

func (cfg *OrganizationConfig) OrgID() string

func (*OrganizationConfig) SetOrgID added in v0.3.0

func (cfg *OrganizationConfig) SetOrgID(id string)

type OrganizationFilter added in v0.1.8

type OrganizationFilter struct {
	// OffSet is the start of the results returned
	OffSet int
	// Limit is the number of items returned from the filter
	Limit int
	// Org can be used to filter the results based on the filled in value.
	// This is mostly useful if you want to filter by attributes..
	Org Organization
}

type OrganizationID

type OrganizationID string

OrganizationID represents a short identifier for an Organization.

The maximum length is MaxLengthID.

In JSON the OrganizationID is represented as 'orgID'.

func GetOrganizationID added in v0.2.0

func GetOrganizationID(r *http.Request) OrganizationID

GetOrganizationID retrieves an OrganizationID from a *http.Request.

This orgID is set by middleware and available for each request

func NewOrganizationID

func NewOrganizationID(input string) (OrganizationID, error)

NewOrganizationID returns an OrganizationID and an error if the supplied input is invalid.

func (OrganizationID) String added in v0.2.0

func (id OrganizationID) String() string

String returns the OrganizationID as a string

func (OrganizationID) Valid

func (id OrganizationID) Valid() error

Valid validates the identifier.

- ErrIDTooLong is returned when ID is too long

- ErrIDInvalidCharacter is returned when ID contains non-letters

type PostHookItem added in v0.2.0

type PostHookItem struct {
	Graph   *rdf2go.Graph
	Deleted bool
	Subject string

	// TODO(kiivihal): replace with single domain.HubID later
	OrgID     string
	DatasetID string
	HubID     string
	Revision  int
}

PostHookItem holds the input data that a PostHookService can manipulate before submitting it to the endpoint

type PostHookService added in v0.2.0

type PostHookService interface {
	// Add adds PostHookItems to the processing queue
	// Add(item ...PostHookItem) error
	// Publish pushes all the submitted jobs to PostHook endpoint
	Publish(item ...*PostHookItem) error
	Valid(datasetID string) bool
	DropDataset(id string, revision int) (*http.Response, error)
	// run this custom function before DropDataset
	Run(datasetID string) error
	// Metrics()
	// OrgID returns OrgID that the posthook applies to
	OrgID() string
	Name() string
}

type Router added in v0.3.0

type Router interface {
	Routes(pattern string, router chi.Router)
}

Router implements a callback to register routes to a chi.Router If pattern is non-empty this mount point will be used, instead of the default specified by the domain.Service implementation

type Service added in v0.3.0

type Service interface {
	// Metrics() interface{}
	http.Handler
	Router
	SetServiceBuilder(b *ServiceBuilder)
	Shutdown
}

Service defines minimal API service of an ikuzo.Service

type ServiceBuilder added in v0.3.0

type ServiceBuilder struct {
	Logger *logger.CustomLogger
	Orgs   OrgConfigRetriever
}

type Shutdown added in v0.3.0

type Shutdown interface {
	Shutdown(ctx context.Context) error
}

Shutdown must be implement by each service that uses background services or connections.

type URI

type URI string

URI represents a NameSpace URI.

func (URI) String

func (uri URI) String() string

String returns a string representation of URI

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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