ngsi

package
v0.0.0-...-0b43983 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: MIT Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const (
	//GeoSpatialRelationNearPoint describes a relation as a max or min distance from a Point
	GeoSpatialRelationNearPoint = "near"
	//GeoSpatialRelationWithinRect describes a relation as an overlapping polygon
	GeoSpatialRelationWithinRect = "within"

	//TemporalRelationAfterTime describes a relation where observedAt >= timeAt
	TemporalRelationAfterTime = "after"
	//TemporalRelationBeforeTime describes a relation where observedAt < timeAt
	TemporalRelationBeforeTime = "before"
	//TemporalRelationBetweenTimes describes a relation where timeAt <= observedAt < endTimeAt
	TemporalRelationBetweenTimes = "between"
	//TemporalRelationTimeProperty contains the temporal property to which the query can be applied
	TemporalRelationTimeProperty = "timeproperty"

	//QueryDefaultPaginationLimit defines the limit that should be used for GET operations
	//when the client does not supply a value
	QueryDefaultPaginationLimit = uint64(1000)
)

Variables

This section is empty.

Functions

func NewCreateEntityHandler

func NewCreateEntityHandler(ctxReg ContextRegistry) http.HandlerFunc

NewCreateEntityHandler handles incoming POST requests for NGSI entities

func NewCreateEntityHandlerWithCallback

func NewCreateEntityHandlerWithCallback(
	ctxReg ContextRegistry,
	logger zerolog.Logger,
	onsuccess CreateEntityCompletionCallback) http.HandlerFunc

func NewQueryEntitiesHandler

func NewQueryEntitiesHandler(ctxReg ContextRegistry) http.HandlerFunc

NewQueryEntitiesHandler handles GET requests for NGSI entities

func NewRegisterContextSourceHandler

func NewRegisterContextSourceHandler(ctxReg ContextRegistry) http.HandlerFunc

NewRegisterContextSourceHandler handles POST requests for csource registrations

func NewRetrieveEntityHandler

func NewRetrieveEntityHandler(ctxReg ContextRegistry) http.HandlerFunc

NewRetrieveEntityHandler retrieves entity by ID.

func NewUpdateEntityAttributesHandler

func NewUpdateEntityAttributesHandler(ctxReg ContextRegistry) http.HandlerFunc

NewUpdateEntityAttributesHandler handles PATCH requests for NGSI entitity attributes

func NewUpdateEntityAttributesHandlerWithCallback

func NewUpdateEntityAttributesHandlerWithCallback(
	ctxReg ContextRegistry,
	logger zerolog.Logger,
	onsuccess UpdateEntityAttributesCompletionCallback) http.HandlerFunc

NewUpdateEntityAttributesHandlerWithCallback handles PATCH requests for NGSI entitity attributes and calls a callback on successful completion

Types

type ContextRegistry

type ContextRegistry interface {
	GetContextSourcesForQuery(query Query) []ContextSource
	GetContextSourcesForEntity(entityID string) []ContextSource
	GetContextSourcesForEntityType(entityType string) []ContextSource

	Register(source ContextSource)
}

ContextRegistry is where Context Sources register the information that they can provide

func NewContextRegistry

func NewContextRegistry() ContextRegistry

NewContextRegistry initializes and returns a new default context registry without any registered context sources

type ContextSource

type ContextSource interface {
	ProvidesAttribute(attributeName string) bool
	ProvidesEntitiesWithMatchingID(entityID string) bool
	GetProvidedTypeFromID(entityID string) (string, error)
	ProvidesType(typeName string) bool

	CreateEntity(typeName, entityID string, request Request) error
	GetEntities(query Query, callback QueryEntitiesCallback) error
	RetrieveEntity(entityID string, request Request) (Entity, error)
	UpdateEntityAttributes(entityID string, request Request) error
}

ContextSource provides query and subscription support for a set of entities

func NewRemoteContextSource

func NewRemoteContextSource(registration CsourceRegistration) (ContextSource, error)

NewRemoteContextSource creates an instance of a ContextSource by wrapping a CsourceRegistration

type ContextSourceMock

type ContextSourceMock struct {
	// CreateEntityFunc mocks the CreateEntity method.
	CreateEntityFunc func(typeName string, entityID string, request Request) error

	// GetEntitiesFunc mocks the GetEntities method.
	GetEntitiesFunc func(query Query, callback QueryEntitiesCallback) error

	// GetProvidedTypeFromIDFunc mocks the GetProvidedTypeFromID method.
	GetProvidedTypeFromIDFunc func(entityID string) (string, error)

	// ProvidesAttributeFunc mocks the ProvidesAttribute method.
	ProvidesAttributeFunc func(attributeName string) bool

	// ProvidesEntitiesWithMatchingIDFunc mocks the ProvidesEntitiesWithMatchingID method.
	ProvidesEntitiesWithMatchingIDFunc func(entityID string) bool

	// ProvidesTypeFunc mocks the ProvidesType method.
	ProvidesTypeFunc func(typeName string) bool

	// RetrieveEntityFunc mocks the RetrieveEntity method.
	RetrieveEntityFunc func(entityID string, request Request) (Entity, error)

	// UpdateEntityAttributesFunc mocks the UpdateEntityAttributes method.
	UpdateEntityAttributesFunc func(entityID string, request Request) error
	// contains filtered or unexported fields
}

ContextSourceMock is a mock implementation of ContextSource.

func TestSomethingThatUsesContextSource(t *testing.T) {

	// make and configure a mocked ContextSource
	mockedContextSource := &ContextSourceMock{
		CreateEntityFunc: func(typeName string, entityID string, request Request) error {
			panic("mock out the CreateEntity method")
		},
		GetEntitiesFunc: func(query Query, callback QueryEntitiesCallback) error {
			panic("mock out the GetEntities method")
		},
		GetProvidedTypeFromIDFunc: func(entityID string) (string, error) {
			panic("mock out the GetProvidedTypeFromID method")
		},
		ProvidesAttributeFunc: func(attributeName string) bool {
			panic("mock out the ProvidesAttribute method")
		},
		ProvidesEntitiesWithMatchingIDFunc: func(entityID string) bool {
			panic("mock out the ProvidesEntitiesWithMatchingID method")
		},
		ProvidesTypeFunc: func(typeName string) bool {
			panic("mock out the ProvidesType method")
		},
		RetrieveEntityFunc: func(entityID string, request Request) (Entity, error) {
			panic("mock out the RetrieveEntity method")
		},
		UpdateEntityAttributesFunc: func(entityID string, request Request) error {
			panic("mock out the UpdateEntityAttributes method")
		},
	}

	// use mockedContextSource in code that requires ContextSource
	// and then make assertions.

}

func (*ContextSourceMock) CreateEntity

func (mock *ContextSourceMock) CreateEntity(typeName string, entityID string, request Request) error

CreateEntity calls CreateEntityFunc.

func (*ContextSourceMock) CreateEntityCalls

func (mock *ContextSourceMock) CreateEntityCalls() []struct {
	TypeName string
	EntityID string
	Request  Request
}

CreateEntityCalls gets all the calls that were made to CreateEntity. Check the length with:

len(mockedContextSource.CreateEntityCalls())

func (*ContextSourceMock) GetEntities

func (mock *ContextSourceMock) GetEntities(query Query, callback QueryEntitiesCallback) error

GetEntities calls GetEntitiesFunc.

func (*ContextSourceMock) GetEntitiesCalls

func (mock *ContextSourceMock) GetEntitiesCalls() []struct {
	Query    Query
	Callback QueryEntitiesCallback
}

GetEntitiesCalls gets all the calls that were made to GetEntities. Check the length with:

len(mockedContextSource.GetEntitiesCalls())

func (*ContextSourceMock) GetProvidedTypeFromID

func (mock *ContextSourceMock) GetProvidedTypeFromID(entityID string) (string, error)

GetProvidedTypeFromID calls GetProvidedTypeFromIDFunc.

func (*ContextSourceMock) GetProvidedTypeFromIDCalls

func (mock *ContextSourceMock) GetProvidedTypeFromIDCalls() []struct {
	EntityID string
}

GetProvidedTypeFromIDCalls gets all the calls that were made to GetProvidedTypeFromID. Check the length with:

len(mockedContextSource.GetProvidedTypeFromIDCalls())

func (*ContextSourceMock) ProvidesAttribute

func (mock *ContextSourceMock) ProvidesAttribute(attributeName string) bool

ProvidesAttribute calls ProvidesAttributeFunc.

func (*ContextSourceMock) ProvidesAttributeCalls

func (mock *ContextSourceMock) ProvidesAttributeCalls() []struct {
	AttributeName string
}

ProvidesAttributeCalls gets all the calls that were made to ProvidesAttribute. Check the length with:

len(mockedContextSource.ProvidesAttributeCalls())

func (*ContextSourceMock) ProvidesEntitiesWithMatchingID

func (mock *ContextSourceMock) ProvidesEntitiesWithMatchingID(entityID string) bool

ProvidesEntitiesWithMatchingID calls ProvidesEntitiesWithMatchingIDFunc.

func (*ContextSourceMock) ProvidesEntitiesWithMatchingIDCalls

func (mock *ContextSourceMock) ProvidesEntitiesWithMatchingIDCalls() []struct {
	EntityID string
}

ProvidesEntitiesWithMatchingIDCalls gets all the calls that were made to ProvidesEntitiesWithMatchingID. Check the length with:

len(mockedContextSource.ProvidesEntitiesWithMatchingIDCalls())

func (*ContextSourceMock) ProvidesType

func (mock *ContextSourceMock) ProvidesType(typeName string) bool

ProvidesType calls ProvidesTypeFunc.

func (*ContextSourceMock) ProvidesTypeCalls

func (mock *ContextSourceMock) ProvidesTypeCalls() []struct {
	TypeName string
}

ProvidesTypeCalls gets all the calls that were made to ProvidesType. Check the length with:

len(mockedContextSource.ProvidesTypeCalls())

func (*ContextSourceMock) RetrieveEntity

func (mock *ContextSourceMock) RetrieveEntity(entityID string, request Request) (Entity, error)

RetrieveEntity calls RetrieveEntityFunc.

func (*ContextSourceMock) RetrieveEntityCalls

func (mock *ContextSourceMock) RetrieveEntityCalls() []struct {
	EntityID string
	Request  Request
}

RetrieveEntityCalls gets all the calls that were made to RetrieveEntity. Check the length with:

len(mockedContextSource.RetrieveEntityCalls())

func (*ContextSourceMock) UpdateEntityAttributes

func (mock *ContextSourceMock) UpdateEntityAttributes(entityID string, request Request) error

UpdateEntityAttributes calls UpdateEntityAttributesFunc.

func (*ContextSourceMock) UpdateEntityAttributesCalls

func (mock *ContextSourceMock) UpdateEntityAttributesCalls() []struct {
	EntityID string
	Request  Request
}

UpdateEntityAttributesCalls gets all the calls that were made to UpdateEntityAttributes. Check the length with:

len(mockedContextSource.UpdateEntityAttributesCalls())

type CreateEntityCompletionCallback

type CreateEntityCompletionCallback func(entityType, entityID string, request Request, logger zerolog.Logger)

type CsourceRegistration

type CsourceRegistration interface {
	Endpoint() string
	GetProvidedTypeFromID(entityID string) (string, error)
	ProvidesAttribute(attributeName string) bool
	ProvidesEntitiesWithMatchingID(entityID string) bool
	ProvidesType(typeName string) bool
}

CsourceRegistration is a wrapper for information about a registered context source

func NewCsourceRegistration

func NewCsourceRegistration(entityTypeName string, attributeNames []string, endpoint string, idpattern *string) (CsourceRegistration, error)

NewCsourceRegistration creates and returns a concrete implementation of the CsourceRegistration interface

func NewCsourceRegistrationFromJSON

func NewCsourceRegistrationFromJSON(jsonBytes []byte) (CsourceRegistration, error)

NewCsourceRegistrationFromJSON unpacks a byte buffer into a CsourceRegistration and validates its contents

type Entity

type Entity interface {
}

Entity is an informational representative of something that is supposed to exist in the real world, physically or conceptually

type GeoQuery

type GeoQuery struct {
	Geometry    string    `json:"geometry"`
	Coordinates []float64 `json:"coordinates"`
	GeoRel      string    `json:"georel"`
	GeoProperty *string   `json:"geoproperty,omitempty"`
	// contains filtered or unexported fields
}

GeoQuery contains information about a geo-query that may be used for subscriptions or when querying entities

func (*GeoQuery) Distance

func (gq *GeoQuery) Distance() (uint32, bool)

Distance returns the required distance in meters from a near Point and a boolean flag indicating if it is inclusive or exclusive

func (*GeoQuery) Point

func (gq *GeoQuery) Point() (float64, float64, error)

Point extracts the position in the enclosed geometry

func (*GeoQuery) Rectangle

func (gq *GeoQuery) Rectangle() (float64, float64, float64, float64, error)

Rectangle extracts the two positions (opposing corners) within the enclosed geometry

type Query

type Query interface {
	HasDeviceReference() bool
	Device() string

	PaginationLimit() uint64
	PaginationOffset() uint64

	IsGeoQuery() bool
	Geo() GeoQuery

	IsTemporalQuery() bool
	Temporal() TemporalQuery

	EntityAttributes() []string
	EntityTypes() []string

	Request() *http.Request
}

Query is an interface to be used when passing queries to context registries and sources

type QueryEntitiesCallback

type QueryEntitiesCallback func(entity Entity) error

QueryEntitiesCallback is used when queried context sources should pass back any entities matching the query that has been passed in

type Request

type Request interface {
	BodyReader() io.Reader
	DecodeBodyInto(v interface{}) error
	Request() *http.Request
}

Request is an interface to be used when passing header and body information for NGSI-LD API requests

type TemporalQuery

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

func (TemporalQuery) Property

func (tq TemporalQuery) Property() string

func (TemporalQuery) TimeSpan

func (tq TemporalQuery) TimeSpan() (time.Time, time.Time)

type UpdateEntityAttributesCompletionCallback

type UpdateEntityAttributesCompletionCallback func(entityType, entityID string, request Request, logger zerolog.Logger)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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