fabric8-wit: github.com/fabric8-services/fabric8-wit/workitem/link Index | Files

package link

import "github.com/fabric8-services/fabric8-wit/workitem/link"

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

Package Files

ancestor.go category.go category_repository.go doc.go link.go link_repository.go link_revision.go link_revision_repository.go topology.go type.go type_repository.go

Constants

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

End points

Variables

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

Never ever change these UUIDs!!!

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!!!

type Ancestor Uses

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 Uses

type AncestorList []Ancestor

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

func (AncestorList) GetDistinctAncestorIDs Uses

func (l AncestorList) GetDistinctAncestorIDs() id.Slice

GetDistinctAncestorIDs returns a list with distinct ancestor IDs.

func (AncestorList) GetParentOf Uses

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 Uses

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

GormWorkItemLinkCategoryRepository implements WorkItemLinkCategoryRepository using gorm

func NewWorkItemLinkCategoryRepository Uses

func NewWorkItemLinkCategoryRepository(db *gorm.DB) *GormWorkItemLinkCategoryRepository

NewWorkItemLinkCategoryRepository creates a work item link category repository based on gorm

func (*GormWorkItemLinkCategoryRepository) CheckExists Uses

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

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

func (*GormWorkItemLinkCategoryRepository) Create Uses

func (r *GormWorkItemLinkCategoryRepository) Create(ctx context.Context, linkCat *WorkItemLinkCategory) (*WorkItemLinkCategory, error)

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

func (*GormWorkItemLinkCategoryRepository) Delete Uses

func (r *GormWorkItemLinkCategoryRepository) Delete(ctx context.Context, ID uuid.UUID) error

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

func (*GormWorkItemLinkCategoryRepository) List Uses

func (r *GormWorkItemLinkCategoryRepository) List(ctx context.Context) ([]WorkItemLinkCategory, error)

List returns all work item link categories TODO: Handle pagination

func (*GormWorkItemLinkCategoryRepository) Load Uses

func (r *GormWorkItemLinkCategoryRepository) Load(ctx context.Context, ID uuid.UUID) (*WorkItemLinkCategory, error)

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

func (*GormWorkItemLinkCategoryRepository) Save Uses

func (r *GormWorkItemLinkCategoryRepository) Save(ctx context.Context, linkCat WorkItemLinkCategory) (*WorkItemLinkCategory, error)

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 Uses

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

GormWorkItemLinkRepository implements WorkItemLinkRepository using gorm

func NewWorkItemLinkRepository Uses

func NewWorkItemLinkRepository(db *gorm.DB) *GormWorkItemLinkRepository

NewWorkItemLinkRepository creates a work item link repository based on gorm

func (*GormWorkItemLinkRepository) CheckExists Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (r *GormWorkItemLinkRepository) List(ctx context.Context) ([]WorkItemLink, error)

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 Uses

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 Uses

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 Uses

func (r *GormWorkItemLinkRepository) Load(ctx context.Context, ID uuid.UUID) (*WorkItemLink, error)

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

func (*GormWorkItemLinkRepository) ValidateTopology Uses

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 Uses

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 Uses

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

GormWorkItemLinkRevisionRepository implements CommentRevisionRepository using gorm

func NewRevisionRepository Uses

func NewRevisionRepository(db *gorm.DB) *GormWorkItemLinkRevisionRepository

NewRevisionRepository creates a GormCommentRevisionRepository

func (*GormWorkItemLinkRevisionRepository) Create Uses

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 Uses

func (r *GormWorkItemLinkRevisionRepository) List(ctx context.Context, linkID uuid.UUID) ([]Revision, error)

List retrieves all revisions for a given work item link

type GormWorkItemLinkTypeRepository Uses

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

GormWorkItemLinkTypeRepository implements WorkItemLinkTypeRepository using gorm

func NewWorkItemLinkTypeRepository Uses

func NewWorkItemLinkTypeRepository(db *gorm.DB) *GormWorkItemLinkTypeRepository

NewWorkItemLinkTypeRepository creates a work item link type repository based on gorm

func (*GormWorkItemLinkTypeRepository) CheckExists Uses

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 Uses

func (r *GormWorkItemLinkTypeRepository) Create(ctx context.Context, linkType *WorkItemLinkType) (*WorkItemLinkType, error)

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

func (*GormWorkItemLinkTypeRepository) List Uses

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

List returns all work item link types

func (*GormWorkItemLinkTypeRepository) Load Uses

func (r *GormWorkItemLinkTypeRepository) Load(ctx context.Context, ID uuid.UUID) (*WorkItemLinkType, error)

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

func (*GormWorkItemLinkTypeRepository) Save Uses

func (r *GormWorkItemLinkTypeRepository) Save(ctx context.Context, modelToSave WorkItemLinkType) (*WorkItemLinkType, error)

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 Uses

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 Uses

func (w Revision) TableName() string

TableName implements gorm.tabler

type RevisionRepository Uses

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 Uses

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 Uses

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 Uses

func (t Topology) CheckValid() error

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

func (*Topology) Scan Uses

func (t *Topology) Scan(value interface{}) error

Scan implements the https://golang.org/pkg/database/sql/#Scanner interface See also https://stackoverflow.com/a/25374979/835098 See also https://github.com/jinzhu/gorm/issues/302#issuecomment-80566841

func (Topology) String Uses

func (t Topology) String() string

String implements the Stringer interface

func (Topology) Value Uses

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 Uses

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 Uses

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

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

func (WorkItemLink) GetETagData Uses

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

GetETagData returns the field values to use to generate the ETag

func (WorkItemLink) GetLastModified Uses

func (l WorkItemLink) GetLastModified() time.Time

GetLastModified returns the last modification time

func (WorkItemLink) TableName Uses

func (l WorkItemLink) TableName() string

TableName implements gorm.tabler

type WorkItemLinkCategory Uses

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 Uses

func (c WorkItemLinkCategory) Equal(u convert.Equaler) bool

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

func (WorkItemLinkCategory) TableName Uses

func (c WorkItemLinkCategory) TableName() string

TableName implements gorm.tabler

type WorkItemLinkCategoryRepository Uses

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 Uses

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

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

func (WorkItemLinkList) GetParentIDOf Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

func (WorkItemLinkType) GetETagData Uses

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

GetETagData returns the field values to use to generate the ETag

func (WorkItemLinkType) GetLastModified Uses

func (t WorkItemLinkType) GetLastModified() time.Time

GetLastModified returns the last modification time

func (WorkItemLinkType) TableName Uses

func (t WorkItemLinkType) TableName() string

TableName implements gorm.tabler

type WorkItemLinkTypeRepository Uses

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

Package link imports 19 packages (graph) and is imported by 47 packages. Updated 2018-05-10. Refresh now. Tools for package owners.