link

package
v0.0.0-...-ef83997 Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package link contains the code that provides all the required operations to manage work item link, work item link types and work item link categories.

Index

Constants

View Source
const (
	AncestorLevelAll              int = -1
	AncestorLevelParent           int = 1
	AncestorLevelGrandParent      int = 2
	AncestorLevelGreatGrandParent int = 3
)
View Source
const (
	EndpointWorkItemTypes          = "workitemtypes"
	EndpointWorkItems              = "workitems"
	EndpointWorkItemLinkCategories = "workitemlinkcategories"
	EndpointWorkItemLinkTypes      = "workitemlinktypes"
	EndpointWorkItemLinks          = "workitemlinks"
)

End points

Variables

View Source
var (
	SystemWorkItemLinkCategorySystemID = uuid.FromStringOrNil("B1482C65-A64D-4058-BEB0-62F7198CB0F4")
	SystemWorkItemLinkCategoryUserID   = uuid.FromStringOrNil("2F24724F-797C-4073-8B16-4BB8CE9E84A6")
)

Never ever change these UUIDs!!!

View Source
var (
	SystemWorkItemLinkTypeBugBlockerID     = uuid.FromStringOrNil("2CEA3C79-3B79-423B-90F4-1E59174C8F43")
	SystemWorkItemLinkPlannerItemRelatedID = uuid.FromStringOrNil("9B631885-83B1-4ABB-A340-3A9EDE8493FA")
	SystemWorkItemLinkTypeParentChildID    = uuid.FromStringOrNil("25C326A7-6D03-4F5A-B23B-86A9EE4171E9")
)

Never ever change these UUIDs!!!

Functions

This section is empty.

Types

type Ancestor

type Ancestor struct {
	ID              uuid.UUID `gorm:"column:ancestor" sql:"type:uuid"`
	DirectChildID   uuid.UUID `gorm:"column:direct_child" sql:"type:uuid"`
	OriginalChildID uuid.UUID `gorm:"column:original_child" sql:"type:uuid"`
	IsRoot          bool      `gorm:"column:is_root"`
	Level           int64     `gorm:"column:ancestor_level"`
}

Ancestor is essentially an annotated work item ID. Each Ancestor knows for which original child it is the ancestor and whether or not itself is the root.

NOTE: The sql columns noted here are purely virtual and not persitent, see the "working_table" in the query from GetAncestors() function to find out more about each column.

type AncestorList

type AncestorList []Ancestor

AncestorList is just an array of ancestor objects with additional functionality add to it.

func (AncestorList) GetDistinctAncestorIDs

func (l AncestorList) GetDistinctAncestorIDs() id.Slice

GetDistinctAncestorIDs returns a list with distinct ancestor IDs.

func (AncestorList) GetParentOf

func (l AncestorList) GetParentOf(workItemID uuid.UUID) *Ancestor

GetParentOf returns the first parent item that we can find in the list of ancestors; otherwise nil is returned.

type GormWorkItemLinkCategoryRepository

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

GormWorkItemLinkCategoryRepository implements WorkItemLinkCategoryRepository using gorm

func NewWorkItemLinkCategoryRepository

func NewWorkItemLinkCategoryRepository(db *gorm.DB) *GormWorkItemLinkCategoryRepository

NewWorkItemLinkCategoryRepository creates a work item link category repository based on gorm

func (*GormWorkItemLinkCategoryRepository) CheckExists

CheckExists returns nil if the given ID exists otherwise returns an error

func (*GormWorkItemLinkCategoryRepository) Create

Create creates a new work item link category in the repository. Returns BadParameterError, ConversionError or InternalError

func (*GormWorkItemLinkCategoryRepository) Delete

Delete deletes the work item link category with the given id returns NotFoundError or InternalError

func (*GormWorkItemLinkCategoryRepository) List

List returns all work item link categories TODO: Handle pagination

func (*GormWorkItemLinkCategoryRepository) Load

Load returns the work item link category for the given ID. Returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemLinkCategoryRepository) Save

Save updates the given work item link category in storage. Version must be the same as the one int the stored version. returns NotFoundError, VersionConflictError, ConversionError or InternalError

type GormWorkItemLinkRepository

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

GormWorkItemLinkRepository implements WorkItemLinkRepository using gorm

func NewWorkItemLinkRepository

func NewWorkItemLinkRepository(db *gorm.DB) *GormWorkItemLinkRepository

NewWorkItemLinkRepository creates a work item link repository based on gorm

func (*GormWorkItemLinkRepository) CheckExists

func (r *GormWorkItemLinkRepository) CheckExists(ctx context.Context, id uuid.UUID) error

CheckExists returns nil if the given ID exists otherwise returns an error

func (*GormWorkItemLinkRepository) Create

func (r *GormWorkItemLinkRepository) Create(ctx context.Context, sourceID, targetID uuid.UUID, linkTypeID uuid.UUID, creatorID uuid.UUID) (*WorkItemLink, error)

Create creates a new work item link in the repository. Returns BadParameterError, ConversionError or InternalError

func (*GormWorkItemLinkRepository) Delete

func (r *GormWorkItemLinkRepository) Delete(ctx context.Context, linkID uuid.UUID, suppressorID uuid.UUID) error

Delete deletes the work item link with the given id returns NotFoundError or InternalError

func (r *GormWorkItemLinkRepository) DeleteRelatedLinks(ctx context.Context, wiID uuid.UUID, suppressorID uuid.UUID) error

DeleteRelatedLinks deletes all links in which the source or target equals the given work item ID.

func (*GormWorkItemLinkRepository) DetectCycle

func (r *GormWorkItemLinkRepository) DetectCycle(ctx context.Context, sourceID, targetID, linkTypeID uuid.UUID) (hasCycle bool, err error)

DetectCycle returns true if the new link from source to target would cause a cycle when created.

Legend ------

\ = link
* = new link
C = the element that is potentially causing the cycle

Scenarios ---------

I:        II:       III:      IV:       V:       VI:

 C         C         C         C         A        A
  *         \         *         *         \        \
   A         A         A         A         B        C
    \         \         \         \         *        \
     B         B         C         B         C        B
      \         *         \                            *
       C         C         B                            C

In a "tree" topology:

I, II, III are cycles
IV and V are no cycles.
VI violates the single-parent rule

In a "dependency" topology:

I, II, III, and VI are cycles
IV and V are no cycles.

Possibility to detect each cycle (if any) -----------------------------------------

In the existing topology we search for the new link's source and traverse up to get its ancestors. If any of those ancestors match the new link's target, we have found ourselves a cycle. Holds true for I, II, III, V, IV, and VI.

func (*GormWorkItemLinkRepository) GetAncestors

func (r *GormWorkItemLinkRepository) GetAncestors(ctx context.Context, linkTypeID uuid.UUID, upToLevel int, workItemIDs ...uuid.UUID) (ancestors AncestorList, err error)

GetAncestors returns all ancestors for the given work items based on the given level. Level stands for -1=all, 0=no, 1=up to parent, 2=up to grandparent, 3=up to great-grandparent, and so forth.

NOTE: In case the given link type doesn't have a tree topology a work item might have more than one root item. That is why the root IDs is keyed by the the given work item and mapped to an array of root IDs.

func (*GormWorkItemLinkRepository) HasParent

func (r *GormWorkItemLinkRepository) HasParent(ctx context.Context, childID uuid.UUID, linkType WorkItemLinkType) (bool, error)

HasParent returns `true` if a link to a work item with the given `childID` and of the given `linkType` already exists; `false` otherwise.

func (*GormWorkItemLinkRepository) List

List returns all work item links if wiID is nil; otherwise the work item links are returned that have wiID as source or target. TODO: Handle pagination

func (*GormWorkItemLinkRepository) ListByWorkItem

func (r *GormWorkItemLinkRepository) ListByWorkItem(ctx context.Context, wiID uuid.UUID) ([]WorkItemLink, error)

ListByWorkItem returns the work item links that have wiID as source or target. TODO: Handle pagination

func (r *GormWorkItemLinkRepository) ListChildLinks(ctx context.Context, linkTypeID uuid.UUID, parentIDs ...uuid.UUID) (WorkItemLinkList, error)

ListChildLinks gets all links to children for the given parents

func (*GormWorkItemLinkRepository) ListWorkItemChildren

func (r *GormWorkItemLinkRepository) ListWorkItemChildren(ctx context.Context, parentID uuid.UUID, start *int, limit *int) ([]workitem.WorkItem, int, error)

ListWorkItemChildren get all child work items

func (*GormWorkItemLinkRepository) Load

Load returns the work item link for the given ID. Returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemLinkRepository) ValidateTopology

func (r *GormWorkItemLinkRepository) ValidateTopology(ctx context.Context, sourceID uuid.UUID, targetID uuid.UUID, linkType WorkItemLinkType) error

ValidateTopology validates the link topology of the work item given its ID. I.e, the given item should not have a parent with the same kind of link if the `sourceID` arg is not empty, then the corresponding source item is ignored when checking the existing links of the given type.

func (*GormWorkItemLinkRepository) WorkItemHasChildren

func (r *GormWorkItemLinkRepository) WorkItemHasChildren(ctx context.Context, parentID uuid.UUID) (bool, error)

WorkItemHasChildren returns true if the given parent work item has children; otherwise false is returned

type GormWorkItemLinkRevisionRepository

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

GormWorkItemLinkRevisionRepository implements CommentRevisionRepository using gorm

func NewRevisionRepository

func NewRevisionRepository(db *gorm.DB) *GormWorkItemLinkRevisionRepository

NewRevisionRepository creates a GormCommentRevisionRepository

func (*GormWorkItemLinkRevisionRepository) Create

func (r *GormWorkItemLinkRevisionRepository) Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, l WorkItemLink) error

Create stores a new revision for the given work item link.

func (*GormWorkItemLinkRevisionRepository) List

List retrieves all revisions for a given work item link

type GormWorkItemLinkTypeRepository

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

GormWorkItemLinkTypeRepository implements WorkItemLinkTypeRepository using gorm

func NewWorkItemLinkTypeRepository

func NewWorkItemLinkTypeRepository(db *gorm.DB) *GormWorkItemLinkTypeRepository

NewWorkItemLinkTypeRepository creates a work item link type repository based on gorm

func (*GormWorkItemLinkTypeRepository) CheckExists

func (r *GormWorkItemLinkTypeRepository) CheckExists(ctx context.Context, id uuid.UUID) error

CheckExists returns nil if the given ID exists otherwise returns an error

func (*GormWorkItemLinkTypeRepository) Create

Create creates a new work item link type in the repository. Returns BadParameterError, ConversionError or InternalError

func (*GormWorkItemLinkTypeRepository) List

func (r *GormWorkItemLinkTypeRepository) List(ctx context.Context, spaceTemplateID uuid.UUID) ([]WorkItemLinkType, error)

List returns all work item link types

func (*GormWorkItemLinkTypeRepository) Load

Load returns the work item link type for the given ID. Returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemLinkTypeRepository) Save

Save updates the given work item link type in storage. Version must be the same as the one int the stored version. returns NotFoundError, VersionConflictError, ConversionError or InternalError

type Revision

type Revision struct {
	ID uuid.UUID `gorm:"primary_key"`
	// the timestamp of the modification
	Time time.Time `gorm:"column:revision_time"`
	// the type of modification
	Type RevisionType `gorm:"column:revision_type"`
	// the identity of author of the work item modification
	ModifierIdentity uuid.UUID `sql:"type:uuid" gorm:"column:modifier_id"`
	// the ID of the work item link that changed
	WorkItemLinkID uuid.UUID `sql:"type:uuid"`
	// the version of the work item link that changed
	WorkItemLinkVersion int
	// the ID of the source of the work item link that changed
	WorkItemLinkSourceID uuid.UUID `sql:"type:uuid"`
	// the ID of the target of the work item link that changed
	WorkItemLinkTargetID uuid.UUID `sql:"type:uuid"`
	// the ID of the type of the work item link that changed
	WorkItemLinkTypeID uuid.UUID `sql:"type:uuid"`
}

Revision represents a version of a work item link

func (Revision) TableName

func (w Revision) TableName() string

TableName implements gorm.tabler

type RevisionRepository

type RevisionRepository interface {
	// Create stores a new revision for the given work item link.
	Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, l WorkItemLink) error
	// List retrieves all revisions for a given work item link
	List(ctx context.Context, workitemID uuid.UUID) ([]Revision, error)
}

RevisionRepository encapsulates storage & retrieval of historical versions of work item links

type RevisionType

type RevisionType int

RevisionType defines the type of revision for a work item link

const (

	// RevisionTypeCreate a work item link creation
	RevisionTypeCreate RevisionType // 1
	// RevisionTypeDelete a work item link deletion
	RevisionTypeDelete // 2

	// RevisionTypeUpdate a work item link update
	// TODO(kwk): can we remove this "update" revsion type? We no longer support updating a link.
	RevisionTypeUpdate // 4

)

type Topology

type Topology string

Topology determines the way that links can be created

const (
	TopologyNetwork         Topology = "network"
	TopologyDirectedNetwork Topology = "directed_network"
	TopologyDependency      Topology = "dependency"
	TopologyTree            Topology = "tree"
)

func (Topology) CheckValid

func (t Topology) CheckValid() error

CheckValid returns nil if the given topology is valid; otherwise a BadParameterError is returned.

func (Topology) String

func (t Topology) String() string

String implements the Stringer interface

func (Topology) Value

func (t Topology) Value() (driver.Value, error)

Value implements the https://golang.org/pkg/database/sql/driver/#Valuer interface

type WorkItemLink struct {
	gormsupport.Lifecycle
	// ID
	ID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"`
	// Version for optimistic concurrency control
	Version    int
	SourceID   uuid.UUID `sql:"type:uuid"`
	TargetID   uuid.UUID `sql:"type:uuid"`
	LinkTypeID uuid.UUID `sql:"type:uuid"`
}

WorkItemLink represents the connection of two work items as it is stored in the db

func (*WorkItemLink) CheckValidForCreation

func (l *WorkItemLink) CheckValidForCreation() error

CheckValidForCreation returns an error if the work item link cannot be used for the creation of a new work item link.

func (WorkItemLink) Equal

func (l WorkItemLink) Equal(u convert.Equaler) bool

Equal returns true if two WorkItemLink objects are equal; otherwise false is returned.

func (WorkItemLink) GetETagData

func (l WorkItemLink) GetETagData() []interface{}

GetETagData returns the field values to use to generate the ETag

func (WorkItemLink) GetLastModified

func (l WorkItemLink) GetLastModified() time.Time

GetLastModified returns the last modification time

func (WorkItemLink) TableName

func (l WorkItemLink) TableName() string

TableName implements gorm.tabler

type WorkItemLinkCategory

type WorkItemLinkCategory struct {
	gormsupport.Lifecycle
	// ID
	ID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"`
	// Name is the unique name of this work item link category.
	Name string
	// Description is an optional description of the work item link category
	Description *string
	// Version for optimistic concurrency control
	Version int
}

WorkItemLinkCategory represents the category of a work item link as it is stored in the db

func (WorkItemLinkCategory) Equal

Equal returns true if two WorkItemLinkCategory objects are equal; otherwise false is returned.

func (WorkItemLinkCategory) TableName

func (c WorkItemLinkCategory) TableName() string

TableName implements gorm.tabler

type WorkItemLinkCategoryRepository

type WorkItemLinkCategoryRepository interface {
	repository.Exister
	Create(ctx context.Context, linkCat *WorkItemLinkCategory) (*WorkItemLinkCategory, error)
	Load(ctx context.Context, ID uuid.UUID) (*WorkItemLinkCategory, error)
	List(ctx context.Context) ([]WorkItemLinkCategory, error)
	Delete(ctx context.Context, ID uuid.UUID) error
	Save(ctx context.Context, linkCat WorkItemLinkCategory) (*WorkItemLinkCategory, error)
}

WorkItemLinkCategoryRepository encapsulates storage & retrieval of work item link categories

type WorkItemLinkList []WorkItemLink

WorkItemLinkList is just a slice of work item links with some additional methods on it.

func (WorkItemLinkList) GetDistinctListOfTargetIDs

func (list WorkItemLinkList) GetDistinctListOfTargetIDs(linkTypeID uuid.UUID) id.Slice

GetDistinctListOfTargetIDs returns a list of distinct source IDs in the given list.

func (WorkItemLinkList) GetParentIDOf

func (list WorkItemLinkList) GetParentIDOf(childID uuid.UUID, linkTypeID uuid.UUID) uuid.UUID

GetParentIDOf returns the ID (if any) of the parent for the child work item with respect to the link type in the given link list.

type WorkItemLinkRepository

type WorkItemLinkRepository interface {
	repository.Exister
	Create(ctx context.Context, sourceID, targetID uuid.UUID, linkTypeID uuid.UUID, creatorID uuid.UUID) (*WorkItemLink, error)
	Load(ctx context.Context, ID uuid.UUID) (*WorkItemLink, error)
	List(ctx context.Context) ([]WorkItemLink, error)
	ListByWorkItem(ctx context.Context, wiID uuid.UUID) ([]WorkItemLink, error)
	DeleteRelatedLinks(ctx context.Context, wiID uuid.UUID, suppressorID uuid.UUID) error
	Delete(ctx context.Context, ID uuid.UUID, suppressorID uuid.UUID) error
	ListChildLinks(ctx context.Context, linkTypeID uuid.UUID, parentIDs ...uuid.UUID) (WorkItemLinkList, error)
	ListWorkItemChildren(ctx context.Context, parentID uuid.UUID, start *int, limit *int) ([]workitem.WorkItem, int, error)
	WorkItemHasChildren(ctx context.Context, parentID uuid.UUID) (bool, error)
	// GetAncestors returns all ancestors for the given work items.
	GetAncestors(ctx context.Context, linkTypeID uuid.UUID, upToLevel int, workItemIDs ...uuid.UUID) (ancestors AncestorList, err error)
}

WorkItemLinkRepository encapsulates storage & retrieval of work item links

type WorkItemLinkType

type WorkItemLinkType struct {
	gormsupport.Lifecycle `json:"lifecycle,inline"`
	ID                    uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key" json:"id"`
	Name                  string    `json:"name"`                  // Name is the unique name of this work item link type.
	Description           *string   `json:"description,omitempty"` // Description is an optional description of the work item link type
	Version               int       `json:"version"`               // Version for optimistic concurrency control
	Topology              Topology  `json:"topology"`              // Valid values: network, directed_network, dependency, tree
	ForwardName           string    `json:"forward_name"`
	ReverseName           string    `json:"reverse_name"`
	LinkCategoryID        uuid.UUID `sql:"type:uuid" json:"link_category_id"`
	SpaceTemplateID       uuid.UUID `sql:"type:uuid" json:"space_template_id"` // Reference to a space template
}

WorkItemLinkType represents the type of a work item link as it is stored in the db

func (*WorkItemLinkType) CheckValidForCreation

func (t *WorkItemLinkType) CheckValidForCreation() error

CheckValidForCreation returns an error if the work item link type cannot be used for the creation of a new work item link type.

func (WorkItemLinkType) Equal

func (t WorkItemLinkType) Equal(u convert.Equaler) bool

Equal returns true if two WorkItemLinkType objects are equal; otherwise false is returned.

func (WorkItemLinkType) GetETagData

func (t WorkItemLinkType) GetETagData() []interface{}

GetETagData returns the field values to use to generate the ETag

func (WorkItemLinkType) GetLastModified

func (t WorkItemLinkType) GetLastModified() time.Time

GetLastModified returns the last modification time

func (WorkItemLinkType) TableName

func (t WorkItemLinkType) TableName() string

TableName implements gorm.tabler

type WorkItemLinkTypeRepository

type WorkItemLinkTypeRepository interface {
	repository.Exister
	Create(ctx context.Context, linkType *WorkItemLinkType) (*WorkItemLinkType, error)
	Load(ctx context.Context, ID uuid.UUID) (*WorkItemLinkType, error)
	List(ctx context.Context, spaceTemplateID uuid.UUID) ([]WorkItemLinkType, error)
	Save(ctx context.Context, linkCat WorkItemLinkType) (*WorkItemLinkType, error)
}

WorkItemLinkTypeRepository encapsulates storage & retrieval of work item link types

Jump to

Keyboard shortcuts

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