core

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AccessTokenKey is the key for the context information. The context needs to store the
	// full access token with "bearer <token>"
	AccessTokenKey AccessTokenType = "authorization"
	// UserIDKey is the key for the context information. The context needs to store the
	// rexOS user id
	UserIDKey UserIDType = "UserID"
)
View Source
const (
	// ContextDataKey is the identifier for getting the context data
	ContextDataKey = "data"
)

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(domain, clientID, clientSecret string) (string, error)

Authenticate gets a valid token for the given user credentials and returns the plain token information (without the authentication key bearer!). The domain denotes the rexOS base URL (e.g. <scheme>://<host>)

func GetAccessTokenFromContext

func GetAccessTokenFromContext(ctx context.Context) (string, error)

GetAccessTokenFromContext returns the accesstoken from the context

func GetUserIDFromContext

func GetUserIDFromContext(ctx context.Context) (string, error)

GetUserIDFromContext returns the user id from the context

func StripTemplateParameter

func StripTemplateParameter(templateURL string) string

StripTemplateParameter removes the trailing template parameters of an HATEOAS URL

For example: "https://rex.robotic-eyes.com/rex-gateway/api/v2/rexReferences/1000/project{?projection}"

Types

type AccessTokenType

type AccessTokenType string

AccessTokenType is used for the key of the authorization token for the context

type BimModel

type BimModel struct {
	DateCreated     interface{} `json:"dateCreated"`
	CreatedBy       interface{} `json:"createdBy"`
	LastUpdated     string      `json:"lastUpdated"`
	UpdatedBy       string      `json:"updatedBy"`
	Name            string      `json:"name"`
	GlobalID        string      `json:"globalId"`
	Description     interface{} `json:"description"`
	RexDataBlockIds interface{} `json:"rexDataBlockIds"`
	BimProperties   []struct {
		Name      string `json:"name"`
		Type      string `json:"type"`
		ValueText string `json:"valueText"`
	} `json:"bimProperties"`
	Owner    string `json:"owner"`
	Urn      string `json:"urn"`
	Embedded struct {
		BimSites []struct {
			RexDataBlockIds []int  `json:"rexDataBlockIds"`
			GlobalID        string `json:"globalId"`
			Name            string `json:"name"`
			Links           struct {
				Self struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"self"`
				BimModel struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"bimModel"`
				BimBuildings struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"bimBuildings"`
			} `json:"_links"`
		} `json:"bimSites"`
	} `json:"_embedded"`
	Links struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
		BimModel struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"bimModel"`
		SpatialStructure struct {
			Href string `json:"href"`
		} `json:"spatialStructure"`
		RexFile struct {
			Href string `json:"href"`
		} `json:"rexFile"`
		IfcFileUploadCityBim struct {
			Href string `json:"href"`
		} `json:"ifcFile.uploadCityBim"`
		BimSites struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"bimSites"`
	} `json:"_links"`
}

BimModel is the main BIM model structure Currently work in progress, and may change in future!

type BimModelService

type BimModelService interface {
	GetBimModelByID(ctx context.Context, id uint64) (*BimModel, *SpatialStructure, status.RexReturnCode)
}

BimModelService provides the calls for accessing REX models

func NewBimModelService

func NewBimModelService(client *Client, resourceURL string) BimModelService

NewBimModelService creates a new project projectService

type Client

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

Client is the client which is used to send requests to the rexOS. The client should be created once and shared among all services.

func NewClient

func NewClient() *Client

NewClient create a new rexOS HTTP client

func (*Client) Delete added in v1.2.3

func (c *Client) Delete(ctx context.Context, link string) error

Delete sends a DELETE request to the given link.

func (*Client) Get

func (c *Client) Get(ctx context.Context, query string) ([]byte, int, error)

Get performs a GET request to the given query and returns the body response which is of type JSON. The return values also contain the http status code and a potential error which has occured. The request will be setup as JSON request and also takes out the authentication information from the given context.

func (*Client) Post

func (c *Client) Post(ctx context.Context, query string, payload io.Reader, contentType string) ([]byte, int, error)

Post performs a POST request to the given query, using the given payload as data, and the provided content-type. The content-type is typically 'application/json', but can also be of formdata in case of binary data upload.

type ContextData

type ContextData struct {
	AccessToken string
	UserID      string
}

ContextData is used as payload for the REX context in the interface The caller of the functions which takes a context must make sure that both data values are filled. Please use `context.WithValue` to add this information

type Controller

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

Controller implements all interfaces which are required to work with the high-level API. It handles all the access to the rexOS world.

func NewController

func NewController(config RexConfig) *Controller

NewController returns a new instance of the rexOS data rest interface

func (*Controller) CreateProject

func (d *Controller) CreateProject(ctx context.Context, name string) (*adding.Project, error)

CreateProject create a new project with the according rex reference

func (*Controller) GetProjects

func (d *Controller) GetProjects(ctx context.Context, size, page uint64) ([]listing.Project, status.RexReturnCode)

GetProjects fetches the projects and returns a list of projects. The size and page parameters are used to enable paging. The maximal number of items is limited to 100 from the rexOS backend.

func (*Controller) GetUser

GetUser delivers information about the authenticated user

type FileTransformation

type FileTransformation struct {
	Rotation `json:"rotation"`
	Position `json:"position"`
	Scale    float64 `json:"scale"`
}

FileTransformation is used for defining the relationship between the RexReference and the actual file.

func NewFileTransform

func NewFileTransform() *FileTransformation

NewFileTransform create a new valid FileTransformation

type Position

type Position struct {
	Type        string    `json:"type"`
	Coordinates []float64 `json:"coordinates"`
}

Position in form of a GeoJSON

type Project

type Project struct {
	DateCreated string `json:"dateCreated"`
	CreatedBy   string `json:"createdBy"`
	LastUpdated string `json:"lastUpdated"`
	UpdatedBy   string `json:"updatedBy"`
	Name        string `json:"name"`
	Owner       string `json:"owner"`
	TagLine     string `json:"tagLine"`
	Type        string `json:"type"`
	Description string `json:"description"`
	Urn         string `json:"urn"`
	Embedded    struct {
		RootRexReference struct {
			RootReference bool   `json:"rootReference"`
			Key           string `json:"key"`
			Links         struct {
				Self struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"self"`
				Project struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"project"`
				ParentReference struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"parentReference"`
				ChildReferences struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"childReferences"`
				ProjectFiles struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"projectFiles"`
			} `json:"_links"`
		} `json:"rootRexReference"`
		ProjectFiles []struct {
			LastModified string `json:"lastModified"`
			FileSize     int    `json:"fileSize"`
			Name         string `json:"name"`
			Type         string `json:"type"`
			Links        struct {
				Self struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"self"`
				RexReference struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"rexReference"`
				Project struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"project"`
				FileDownload struct {
					Href string `json:"href"`
				} `json:"file.download"`
			} `json:"_links"`
		} `json:"projectFiles"`
		RexReferences []struct {
			RootReference bool   `json:"rootReference"`
			Key           string `json:"key"`
			Links         struct {
				Self struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"self"`
				Project struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"project"`
				ParentReference struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"parentReference"`
				ChildReferences struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"childReferences"`
				ProjectFiles struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"projectFiles"`
			} `json:"_links"`
		} `json:"rexReferences"`
	} `json:"_embedded"`
	Links struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
		Project struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"project"`
		ThumbnailUpload struct {
			Href string `json:"href"`
		} `json:"thumbnail.upload"`
		ThumbnailDownload struct {
			Href string `json:"href"`
		} `json:"thumbnail.download"`
		ProjectFavorite struct {
			Href string `json:"href"`
		} `json:"projectFavorite"`
		RootRexReference struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"rootRexReference"`
		ProjectFiles struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"projectFiles"`
		ProjectAcls struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"projectAcls"`
		RexReferences struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"rexReferences"`
	} `json:"_links"`
}

Project is the structure of a REX project

func (Project) String

func (p Project) String() string

String nicely prints a project

type ProjectAddress

type ProjectAddress struct {
	AddressLine1 string `json:"addressLine1"`
	AddressLine2 string `json:"addressLine2"`
	AddressLine3 string `json:"addressLine3"`
	AddressLine4 string `json:"addressLine4"`
	PostCode     string `json:"postcode"`
	City         string `json:"city"`
	Region       string `json:"region"`
	Country      string `json:"country"`
}

ProjectAddress defines the address information for a project

type ProjectDetailedList

type ProjectDetailedList struct {
	Embedded struct {
		Projects []struct {
			Public                     bool   `json:"public"`
			NumberOfProjectFiles       int    `json:"numberOfProjectFiles"`
			TotalProjectFileSize       int    `json:"totalProjectFileSize"`
			RootRexReferenceKey        string `json:"rootRexReferenceKey"`
			NumberOfReadPermittedUsers int    `json:"numberOfReadPermittedUsers"`
			LastUpdated                string `json:"lastUpdated"`
			DateCreated                string `json:"dateCreated"`
			Owner                      string `json:"owner"`
			Name                       string `json:"name"`
			Urn                        string `json:"urn"`
			Links                      struct {
				Self struct {
					Href string `json:"href"`
				} `json:"self"`
				Project struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"project"`
				RexReferences struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"rexReferences"`
				RootRexReference struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"rootRexReference"`
				ProjectFiles struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"projectFiles"`
			} `json:"_links"`
		} `json:"projects"`
	} `json:"_embedded"`
}

ProjectDetailedList can be used to get a detailed list of project owned by somebody

type ProjectService

type ProjectService interface {
	FindAllByUser(ctx context.Context, owner string, size, page uint64) (*ProjectDetailedList, status.RexReturnCode)
	FindByNameAndOwner(ctx context.Context, name, owner string) (*Project, status.RexReturnCode)
	CreateProject(ctx context.Context, name, owner string) (*Project, status.RexReturnCode)
	UploadProjectFile(ctx context.Context, project Project, projectFileName, fileName string, transform *FileTransformation, r io.Reader) status.RexReturnCode
}

ProjectService provides the calls for accessing REX project(s)

func NewProjectService

func NewProjectService(client *Client, resourceURL string) ProjectService

NewProjectService creates a new project projectService

type ProjectTransformation

type ProjectTransformation struct {
	Rotation `json:"rotation"`
	Position `json:"position"`
}

ProjectTransformation is used for the absoluteTransformation as well as for the relativeTransformation of a RexReference

type RexConfig

type RexConfig struct {
	ProjectResourceURL string
	UserResourceURL    string
	AuthenticationURL  string
}

RexConfig defines all the required settings for the rexOS DataProvider in order to create all rexOS service endpoints. In order to support internal and external usage of gorex, we need to have separate URLs for each resource.

type RexReference

type RexReference struct {
	Key             string                 `json:"key"`
	Project         string                 `json:"project"`
	ParentReference string                 `json:"parentReference"`
	RootReference   bool                   `json:"rootReference"`
	Address         *ProjectAddress        `json:"address"`
	AbsTransform    *ProjectTransformation `json:"absoluteTransformation"`
	RelTransform    *ProjectTransformation `json:"relativeTransformation"`
	FileTransform   *FileTransformation    `json:"fileTransformation"`
}

RexReference is a spatial anchor which can be attached to a project or a project file.

type Rotation

type Rotation struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	Z float64 `json:"z"`
}

Rotation definition given in Euler angles

type SpatialStructure

type SpatialStructure struct {
	Name         string `json:"name"`
	GlobalID     string `json:"globalId"`
	ResourceType string `json:"resourceType"`
	ResourceUrn  string `json:"resourceUrn"`
	ResourceURL  string `json:"resourceUrl"`
	Children     []struct {
		Name         string `json:"name"`
		GlobalID     string `json:"globalId"`
		ResourceType string `json:"resourceType"`
		ResourceUrn  string `json:"resourceUrn"`
		ResourceURL  string `json:"resourceUrl"`
		Children     []struct {
			Name         string `json:"name"`
			ResourceType string `json:"resourceType"`
			ResourceUrn  string `json:"resourceUrn"`
			ResourceURL  string `json:"resourceUrl"`
			Children     []struct {
				Name         string `json:"name"`
				GlobalID     string `json:"globalId"`
				ResourceType string `json:"resourceType"`
				ResourceUrn  string `json:"resourceUrn"`
				ResourceURL  string `json:"resourceUrl"`
			} `json:"children"`
		} `json:"children"`
	} `json:"children"`
}

SpatialStructure contains the hierarchy tree of a bim model

type User

type User struct {
	UserID    string `json:"userId"`
	Username  string `json:"username,omitempty"`
	Email     string `json:"email,omitempty"`
	FirstName string `json:"firstName,omitempty"`
	LastName  string `json:"lastName,omitempty"`
	LastLogin string `json:"lastLogin,omitempty"`
	SelfLink  string
	Roles     []string `json:"roles,omitempty"`
	Links     struct {
		User struct {
			Href string `json:"href"`
		} `json:"user"`
	} `json:"_links,omitempty"`
}

User stores information of the current user.

The user can either contain the currentUser information, but also information from a user query. The SelfLink can be used to directly access the data, but is also often required for other operations (e.g. insert a project).

func (User) String

func (u User) String() string

String nicely prints out the user information.

type UserDetails added in v1.2.3

type UserDetails struct {
	DateCreated               string   `json:"dateCreated"`
	CreatedBy                 string   `json:"createdBy"`
	LastUpdated               string   `json:"lastUpdated"`
	UpdatedBy                 string   `json:"updatedBy"`
	UserID                    string   `json:"userId"`
	Username                  string   `json:"username"`
	Email                     string   `json:"email"`
	FirstName                 string   `json:"firstName"`
	LastName                  string   `json:"lastName"`
	ExpirationDate            string   `json:"expirationDate"`
	Locked                    bool     `json:"locked"`
	Disabled                  bool     `json:"disabled"`
	CredentialsExpirationDate string   `json:"credentialsExpirationDate"`
	LastLogin                 string   `json:"lastLogin"`
	InvitedBy                 string   `json:"invitedBy"`
	PlaintextPassword         string   `json:"plaintextPassword"`
	Roles                     []string `json:"roles"`
	Links                     struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
		User struct {
			Href string `json:"href"`
		} `json:"user"`
		UserDescription struct {
			Href string `json:"href"`
		} `json:"userDescription"`
		Clients struct {
			Href string `json:"href"`
		} `json:"clients"`
		UserLicenses struct {
			Href string `json:"href"`
		} `json:"userLicenses"`
		UserConnections struct {
			Href string `json:"href"`
		} `json:"userConnections"`
		UserPaymentConnections struct {
			Href string `json:"href"`
		} `json:"userPaymentConnections"`
	} `json:"_links"`
}

UserDetails is the full structure of a user for the /users endpoint

type UserIDType

type UserIDType string

UserIDType is used for the key of the user_id in the context

type UserList added in v1.2.3

type UserList struct {
	Embedded struct {
		Users []UserDetails `json:"users"`
	} `json:"_embedded"`
}

UserList is a list of users delivered by the rexos /users endpoint

type UserService

type UserService interface {
	GetCurrentUser(ctx context.Context) (*User, status.RexReturnCode)
	GetTotalNumberOfUsers(ctx context.Context) (uint64, status.RexReturnCode)
	FindUserByEmail(ctx context.Context, email string) (*User, status.RexReturnCode)
	FindUserByUserID(ctx context.Context, userID string) (*User, status.RexReturnCode)
	FindUserBySelfLink(ctx context.Context, selfLink string) (*User, status.RexReturnCode)
	FindAllUsers(ctx context.Context, size, page uint64) ([]UserDetails, status.RexReturnCode)
	DeleteUser(ctx context.Context, selfLink string) status.RexReturnCode
}

UserService provides the calls for accessing REX user resource

func NewUserService

func NewUserService(client *Client, resourceURL string) UserService

NewUserService creates a new project userService

Jump to

Keyboard shortcuts

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