workitem

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: 35 Imported by: 0

Documentation

Overview

Package workitem contains the code that allows to manage work items, work item types.

Index

Constants

View Source
const (
	SystemVersion = "version"

	SystemRemoteItemID        = "system.remote_item_id"
	SystemNumber              = "system.number"
	SystemTitle               = "system.title"
	SystemDescription         = "system.description"
	SystemDescriptionMarkup   = "system.description.markup"
	SystemDescriptionRendered = "system.description.rendered"
	SystemState               = "system.state"
	SystemAssignees           = "system.assignees"
	SystemCreator             = "system.creator"
	SystemCreatedAt           = "system.created_at"
	SystemUpdatedAt           = "system.updated_at"
	SystemOrder               = "system.order"
	SystemIteration           = "system.iteration"
	SystemArea                = "system.area"
	SystemCodebase            = "system.codebase"
	SystemLabels              = "system.labels"

	SystemStateOpen       = "open"
	SystemStateNew        = "new"
	SystemStateInProgress = "in progress"
	SystemStateResolved   = "resolved"
	SystemStateClosed     = "closed"
)

String constants for the local work item types.

Variables

View Source
var (
	// base item type with common fields for planner item types like userstory,
	// experience, bug, feature, etc.
	SystemPlannerItem      = uuid.FromStringOrNil("86af5178-9b41-469b-9096-57e5155c3f31") // "planneritem"
	SystemTask             = uuid.FromStringOrNil("bbf35418-04b6-426c-a60b-7f80beb0b624") // "task"
	SystemValueProposition = uuid.FromStringOrNil("3194ab60-855b-4155-9005-9dce4a05f1eb") // "valueproposition"
	SystemFundamental      = uuid.FromStringOrNil("ee7ca005-f81d-4eea-9b9b-1965df0988d0") // "fundamental"
	SystemExperience       = uuid.FromStringOrNil("b9a71831-c803-4f66-8774-4193fffd1311") // "experience"
	SystemFeature          = uuid.FromStringOrNil("0a24d3c2-e0a6-4686-8051-ec0ea1915a28") // "feature"
	SystemScenario         = uuid.FromStringOrNil("71171e90-6d35-498f-a6a7-2083b5267c18") // "scenario"
	SystemBug              = uuid.FromStringOrNil("26787039-b68f-4e28-8814-c2f93be1ef4e") // "bug"
	SystemPapercuts        = uuid.FromStringOrNil("6d603ab4-7c5e-4c5f-bba8-a3ba9d370985") // "papercuts"
)

Never ever change these UUIDs!!!

View Source
var DefaultTableJoins = func() TableJoinMap {
	res := TableJoinMap{
		"iteration": {
			TableName:        "iterations",
			TableAlias:       "iter",
			On:               JoinOnJSONField(SystemIteration, "iter.id"),
			PrefixActivators: []string{"iteration."},
			AllowedColumns:   []string{"name", "created_at"},
		},
		"area": {
			TableName:        "areas",
			TableAlias:       "ar",
			On:               JoinOnJSONField(SystemArea, "ar.id"),
			PrefixActivators: []string{"area."},
			AllowedColumns:   []string{"name"},
		},
		"codebase": {
			TableName:        "codebases",
			TableAlias:       "cb",
			On:               JoinOnJSONField(SystemCodebase, "cb.id"),
			PrefixActivators: []string{"codebase."},
			AllowedColumns:   []string{"url"},
		},
		"work_item_type": {
			TableName:        "work_item_types",
			TableAlias:       "wit",
			On:               "wit.id = " + WorkItemStorage{}.TableName() + ".type",
			PrefixActivators: []string{"wit.", "workitemtype.", "work_item_type.", "type."},
			AllowedColumns:   []string{"name"},
		},
		"creator": {
			TableName:        "users",
			TableAlias:       "creator",
			On:               JoinOnJSONField(SystemCreator, "creator.id"),
			PrefixActivators: []string{"creator.", "author."},
			AllowedColumns:   []string{"full_name"},
		},
		"space": {
			TableName:        "spaces",
			TableAlias:       "space",
			On:               Column("space", "id") + "=" + Column(WorkItemStorage{}.TableName(), "space_id"),
			PrefixActivators: []string{"space."},
			AllowedColumns:   []string{"name"},
		},
		"typegroup": {
			TableName:  "work_item_type_groups",
			TableAlias: "witg",
			On:         fmt.Sprintf(`%s=%s`, Column("witg", "space_template_id"), Column("space", "space_template_id")),

			Where: fmt.Sprintf(`%s=%s AND %s=%s`,
				Column("witg_members", "type_group_id"), Column("witg", "id"),
				Column(WorkItemStorage{}.TableName(), "type"), Column("witg_members", "work_item_type_id"),
			),

			AllowedColumns:     []string{"name"},
			ActivateOtherJoins: []string{"space"},
		},
	}

	res["typegroup_members"] = &TableJoin{
		TableName:          "work_item_type_group_members",
		TableAlias:         "witg_members",
		On:                 Column("witg_members", "type_group_id") + "=" + Column("witg", "id"),
		PrefixActivators:   []string{"typegroup_members.", "typegroup."},
		AllowedColumns:     []string{"work_item_type_id"},
		ActivateOtherJoins: []string{"typegroup"},

		DelegateTo: map[string]*TableJoin{
			"typegroup.": res["typegroup"],
		},
	}
	return res
}

DefaultTableJoins returns the default list of joinable tables used when creating a new expression compiler.

Functions

func ClearGlobalWorkItemTypeCache

func ClearGlobalWorkItemTypeCache()

ClearGlobalWorkItemTypeCache removes all work items from the global cache

func Column

func Column(table, column string) string

Column returns a proper column name from the given column name in the given table.

func ConvertList

func ConvertList(converter Converter, componentType SimpleType, value interface{}) ([]interface{}, error)

func GetTypePathSeparator

func GetTypePathSeparator() string

GetTypePathSeparator returns the work item type's path separator "."

func JoinOnJSONField

func JoinOnJSONField(jsonField, foreignCol string) string

JoinOnJSONField returns the ON part of an SQL JOIN for the given fields

func LtreeSafeID

func LtreeSafeID(witID uuid.UUID) string

LtreeSafeID returns the ID of the work item type in an postgres ltree safe manner The returned string can be used as an ltree node.

func ParseWorkItemIDToUint64

func ParseWorkItemIDToUint64(wiIDStr string) (uint64, error)

ParseWorkItemIDToUint64 does what it says

Types

type ChildType

type ChildType struct {
	gormsupport.Lifecycle
	ID                   uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"`
	ParentWorkItemTypeID uuid.UUID `sql:"type:uuid"`
	ChildWorkItemTypeID  uuid.UUID `sql:"type:uuid"`
	Position             int       // position in type list of child types
}

ChildType models the relationship from one parent work item type to its child types.

func (ChildType) TableName

func (wit ChildType) TableName() string

TableName implements gorm.tabler

type Converter

type Converter func(FieldType, interface{}) (interface{}, error)

type DirectionType

type DirectionType string
const (
	DirectionAbove  DirectionType = "above"
	DirectionBelow  DirectionType = "below"
	DirectionTop    DirectionType = "top"
	DirectionBottom DirectionType = "bottom"
)

type EnumType

type EnumType struct {
	SimpleType       `json:"simple_type"`
	BaseType         SimpleType    `json:"base_type"`
	Values           []interface{} `json:"values"`
	RewritableValues bool          `json:"rewritable_values"`
}

func (EnumType) ConvertFromModel

func (t EnumType) ConvertFromModel(value interface{}) (interface{}, error)

func (EnumType) ConvertToModel

func (t EnumType) ConvertToModel(value interface{}) (interface{}, error)

func (EnumType) DefaultValue

func (t EnumType) DefaultValue(value interface{}) (interface{}, error)

DefaultValue implements FieldType

func (EnumType) Equal

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

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

type FieldDefinition

type FieldDefinition struct {
	Required    bool      `json:"required"`
	ReadOnly    bool      `json:"read_only"`
	Label       string    `json:"label"`
	Description string    `json:"description"`
	Type        FieldType `json:"type"`
}

FieldDefinition describes type & other restrictions of a field

func (FieldDefinition) ConvertFromModel

func (f FieldDefinition) ConvertFromModel(name string, value interface{}) (interface{}, error)

ConvertFromModel converts a field value for use in the REST API layer

func (FieldDefinition) ConvertToModel

func (f FieldDefinition) ConvertToModel(name string, value interface{}) (interface{}, error)

ConvertToModel converts a field value for use in the persistence layer

func (FieldDefinition) Equal

func (f FieldDefinition) Equal(u convert.Equaler) bool

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

func (*FieldDefinition) UnmarshalJSON

func (f *FieldDefinition) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler

type FieldDefinitions

type FieldDefinitions map[string]FieldDefinition

func (FieldDefinitions) Value

func (j FieldDefinitions) Value() (driver.Value, error)

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

type FieldType

type FieldType interface {
	GetKind() Kind
	// ConvertToModel converts a field value for use in the persistence layer
	ConvertToModel(value interface{}) (interface{}, error)
	// ConvertFromModel converts a field value for use in the REST API layer
	ConvertFromModel(value interface{}) (interface{}, error)
	// Implement the Equaler interface
	Equal(u convert.Equaler) bool
	// DefaultValue is called if a field is not specified. In it's simplest form
	// the DefaultValue returns the given input value without any conversion.
	DefaultValue(value interface{}) (interface{}, error)
}

FieldType describes the possible values of a FieldDefinition

type FieldTypeTestDataMap

type FieldTypeTestDataMap map[Kind]ValidInvalid

FieldTypeTestDataMap defines a map with additional functionality on it.

func GetFieldTypeTestData

func GetFieldTypeTestData(t *testing.T) FieldTypeTestDataMap

GetFieldTypeTestData returns a list of legal and illegal values to be used with a given field type (here: the map key).

func (FieldTypeTestDataMap) GetKinds

func (s FieldTypeTestDataMap) GetKinds() []Kind

GetKinds returns the keys of the test data map in sorted order.

type Fields

type Fields map[string]interface{}

func (Fields) Equal

func (f Fields) Equal(u convert.Equaler) bool

Equal returns true if two Fields objects are equal; otherwise false is returned. TODO: (kwk) think about a better comparison for Fields map.

func (Fields) Value

func (f Fields) Value() (driver.Value, error)

type GormRevisionRepository

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

GormRevisionRepository implements RevisionRepository using gorm

func NewRevisionRepository

func NewRevisionRepository(db *gorm.DB) *GormRevisionRepository

NewRevisionRepository creates a GormRevisionRepository

func (*GormRevisionRepository) Create

func (r *GormRevisionRepository) Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, workitem WorkItemStorage) error

Create stores a new revision for the given work item.

func (*GormRevisionRepository) List

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

List retrieves all revisions for a given work item

type GormWorkItemRepository

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

GormWorkItemRepository implements WorkItemRepository using gorm

func NewWorkItemRepository

func NewWorkItemRepository(db *gorm.DB) *GormWorkItemRepository

NewWorkItemRepository creates a GormWorkItemRepository

func (*GormWorkItemRepository) CalculateOrder

func (r *GormWorkItemRepository) CalculateOrder(above, below *float64) float64

CalculateOrder calculates the order of the reorder workitem

func (*GormWorkItemRepository) CheckExists

func (r *GormWorkItemRepository) CheckExists(ctx context.Context, workitemID uuid.UUID) error

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

func (*GormWorkItemRepository) Count

func (r *GormWorkItemRepository) Count(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression) (int, error)

Count returns the amount of work item that satisfy the given criteria.Expression

func (*GormWorkItemRepository) Create

func (r *GormWorkItemRepository) Create(ctx context.Context, spaceID uuid.UUID, typeID uuid.UUID, fields map[string]interface{}, creatorID uuid.UUID) (*WorkItem, error)

Create creates a new work item in the repository returns BadParameterError, ConversionError or InternalError

func (*GormWorkItemRepository) Delete

func (r *GormWorkItemRepository) Delete(ctx context.Context, workitemID uuid.UUID, suppressorID uuid.UUID) error

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

func (*GormWorkItemRepository) Fetch

func (r *GormWorkItemRepository) Fetch(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression) (*WorkItem, error)

Fetch fetches the (first) work item matching by the given criteria.Expression.

func (*GormWorkItemRepository) FindFirstItem

func (r *GormWorkItemRepository) FindFirstItem(ctx context.Context, spaceID uuid.UUID, id uuid.UUID) (*float64, error)

FindFirstItem returns the order of the target workitem

func (*GormWorkItemRepository) FindSecondItem

func (r *GormWorkItemRepository) FindSecondItem(ctx context.Context, order *float64, spaceID uuid.UUID, secondItemDirection DirectionType) (*uuid.UUID, *float64, error)

FindSecondItem returns the order of the second workitem required to reorder. Reordering a workitem requires order of two closest workitems: above and below. If direction == "above", then

	FindFirstItem returns the value above which reorder item has to be placed
     FindSecondItem returns the value below which reorder item has to be placed

If direction == "below", then

	FindFirstItem returns the value below which reorder item has to be placed
     FindSecondItem returns the value above which reorder item has to be placed

func (*GormWorkItemRepository) GetCountsForIteration

func (r *GormWorkItemRepository) GetCountsForIteration(ctx context.Context, itr *iteration.Iteration) (map[string]WICountsPerIteration, error)

GetCountsForIteration returns Closed and Total counts of WIs for given iteration It fetches all child iterations of input iteration and then uses list to counts work items SELECT count(*) AS Total,

count(CASE fields->>'system.state'
          WHEN 'closed' THEN '1'
          ELSE NULL
      END) AS Closed

FROM work_items wi WHERE fields->>'system.iteration' IN ('input iteration ID + children IDs')

AND wi.deleted_at IS NULL

func (*GormWorkItemRepository) GetCountsPerIteration

func (r *GormWorkItemRepository) GetCountsPerIteration(ctx context.Context, spaceID uuid.UUID) (map[string]WICountsPerIteration, error)

GetCountsPerIteration counts WIs including iteration-children and returns a map of iterationID->WICountsPerIteration

func (*GormWorkItemRepository) List

func (r *GormWorkItemRepository) List(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression, parentExists *bool, start *int, limit *int) ([]WorkItem, int, error)

List returns work item selected by the given criteria.Expression, starting with start (zero-based) and returning at most limit items

func (*GormWorkItemRepository) Load

func (r *GormWorkItemRepository) Load(ctx context.Context, spaceID uuid.UUID, wiNumber int) (*WorkItem, error)

Load returns the work item for the given spaceID and item id returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemRepository) LoadBatchByID

func (r *GormWorkItemRepository) LoadBatchByID(ctx context.Context, ids []uuid.UUID) ([]*WorkItem, error)

LoadBatchByID returns work items for the given ids

func (*GormWorkItemRepository) LoadBatchFromDB

func (r *GormWorkItemRepository) LoadBatchFromDB(ctx context.Context, ids []uuid.UUID) ([]WorkItemStorage, error)

LoadBatchFromDB returns the work items using IN query expression.

func (*GormWorkItemRepository) LoadBottomWorkitem

func (r *GormWorkItemRepository) LoadBottomWorkitem(ctx context.Context, spaceID uuid.UUID) (*WorkItem, error)

LoadBottomWorkitem returns bottom work item of the list. Bottom most workitem has the lowest order. returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemRepository) LoadByID

func (r *GormWorkItemRepository) LoadByID(ctx context.Context, id uuid.UUID) (*WorkItem, error)

LoadByID returns the work item for the given id returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemRepository) LoadByIteration

func (r *GormWorkItemRepository) LoadByIteration(ctx context.Context, iterationID uuid.UUID) ([]*WorkItem, error)

LoadByIteration returns the list of work items belongs to given iteration

func (*GormWorkItemRepository) LoadFromDB

LoadFromDB returns the work item with the given natural ID in model representation.

func (*GormWorkItemRepository) LoadHighestOrder

func (r *GormWorkItemRepository) LoadHighestOrder(ctx context.Context, spaceID uuid.UUID) (float64, error)

LoadHighestOrder returns the highest execution order in the given space

func (*GormWorkItemRepository) LoadTopWorkitem

func (r *GormWorkItemRepository) LoadTopWorkitem(ctx context.Context, spaceID uuid.UUID) (*WorkItem, error)

LoadTopWorkitem returns top most work item of the list. Top most workitem has the Highest order. returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemRepository) LookupIDByNamedSpaceAndNumber

func (r *GormWorkItemRepository) LookupIDByNamedSpaceAndNumber(ctx context.Context, ownerName, spaceName string, wiNumber int) (*uuid.UUID, *uuid.UUID, error)

LookupIDByNamedSpaceAndNumber returns the work item's ID for the given owner name, space name and item number returns NotFoundError, ConversionError or InternalError

func (*GormWorkItemRepository) Reorder

func (r *GormWorkItemRepository) Reorder(ctx context.Context, spaceID uuid.UUID, direction DirectionType, targetID *uuid.UUID, wi WorkItem, modifierID uuid.UUID) (*WorkItem, error)

Reorder places the to-be-reordered workitem above the input workitem. The order of workitems are spaced by a factor of 1000. The new order of workitem := (order of previousitem + order of nextitem)/2 Version must be the same as the one int the stored version

func (*GormWorkItemRepository) Save

func (r *GormWorkItemRepository) Save(ctx context.Context, spaceID uuid.UUID, updatedWorkItem WorkItem, modifierID uuid.UUID) (*WorkItem, error)

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

type GormWorkItemTypeGroupRepository

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

GormWorkItemTypeGroupRepository implements WorkItemTypeGroupRepository using gorm

func NewWorkItemTypeGroupRepository

func NewWorkItemTypeGroupRepository(db *gorm.DB) *GormWorkItemTypeGroupRepository

NewWorkItemTypeGroupRepository creates a wi type group repository based on gorm

func (*GormWorkItemTypeGroupRepository) CheckExists

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

func (*GormWorkItemTypeGroupRepository) Create

Create creates a new work item type group in the repository

func (*GormWorkItemTypeGroupRepository) List

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

List returns all work item type groups for the given space template ID ordered by their position value.

func (*GormWorkItemTypeGroupRepository) Load

Load returns the work item type group for the given id

type GormWorkItemTypeRepository

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

GormWorkItemTypeRepository implements WorkItemTypeRepository using gorm

func NewWorkItemTypeRepository

func NewWorkItemTypeRepository(db *gorm.DB) *GormWorkItemTypeRepository

NewWorkItemTypeRepository creates a wi type repository based on gorm

func (*GormWorkItemTypeRepository) AddChildTypes

func (r *GormWorkItemTypeRepository) AddChildTypes(ctx context.Context, parentTypeID uuid.UUID, childTypeIDs []uuid.UUID) error

AddChildTypes adds the given child work item types to the parent work item type.

func (*GormWorkItemTypeRepository) CheckExists

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

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

func (*GormWorkItemTypeRepository) Create

func (r *GormWorkItemTypeRepository) Create(ctx context.Context, spaceTemplateID uuid.UUID, id *uuid.UUID, extendedTypeID *uuid.UUID, name string, description *string, icon string, fields FieldDefinitions, canConstruct bool) (*WorkItemType, error)

Create creates a new work item type in the repository returns BadParameterError, ConversionError or InternalError

func (*GormWorkItemTypeRepository) List

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

List returns work item types selected by the given criteria.Expression, starting with start (zero-based) and returning at most "limit" item types.

func (*GormWorkItemTypeRepository) ListPlannerItemTypes

func (r *GormWorkItemTypeRepository) ListPlannerItemTypes(ctx context.Context, spaceTemplateID uuid.UUID) ([]WorkItemType, error)

ListPlannerItemTypes returns work item types that derives from PlannerItem type

func (*GormWorkItemTypeRepository) Load

Load returns the work item for the given spaceID and id returns NotFoundError, InternalError

type Kind

type Kind string

Kind is the kind of field type

const (
	KindString    Kind = "string"
	KindInteger   Kind = "integer"
	KindFloat     Kind = "float"
	KindBoolean   Kind = "bool"
	KindInstant   Kind = "instant"
	KindDuration  Kind = "duration"
	KindURL       Kind = "url"
	KindIteration Kind = "iteration"
	KindUser      Kind = "user"
	KindLabel     Kind = "label"
	KindEnum      Kind = "enum"
	KindList      Kind = "list"
	KindMarkup    Kind = "markup"
	KindArea      Kind = "area"
	KindCodebase  Kind = "codebase"
)

constants for describing possible field types

func ConvertAnyToKind

func ConvertAnyToKind(any interface{}) (*Kind, error)

func ConvertStringToKind

func ConvertStringToKind(k string) (*Kind, error)

ConvertStringToKind returns the given string as a Kind object

func (Kind) IsSimpleType

func (k Kind) IsSimpleType() bool

IsSimpleType returns 'true' if the kind is simple, i.e., not a list nor an enum

func (Kind) String

func (k Kind) String() string

String implements the Stringer interface and returns the kind as a string object.

type ListType

type ListType struct {
	SimpleType    `json:"simple_type"`
	ComponentType SimpleType `json:"component_type"`
}

ListType describes a list of SimpleType values

func (ListType) ConvertFromModel

func (t ListType) ConvertFromModel(value interface{}) (interface{}, error)

ConvertFromModel implements the FieldType interface

func (ListType) ConvertToModel

func (t ListType) ConvertToModel(value interface{}) (interface{}, error)

ConvertToModel implements the FieldType interface

func (ListType) DefaultValue

func (t ListType) DefaultValue(value interface{}) (interface{}, error)

DefaultValue implements FieldType

func (ListType) Equal

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

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

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 workitem modification
	ModifierIdentity uuid.UUID `sql:"type:uuid" gorm:"column:modifier_id"`
	// the id of the work item that changed
	WorkItemID uuid.UUID `gorm:"column:work_item_id"`
	// Id of the type of this work item
	WorkItemTypeID uuid.UUID `gorm:"column:work_item_type_id"`
	// Version of the workitem that was modified
	WorkItemVersion int `gorm:"column:work_item_version"`
	// the field values (or empty when the work item was deleted)
	WorkItemFields Fields `gorm:"column:work_item_fields" sql:"type:jsonb"`
}

Revision represents a version of a work item

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.
	Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, workitem WorkItemStorage) error
	// List retrieves all revisions for a given work item
	List(ctx context.Context, workitemID uuid.UUID) ([]Revision, error)
}

RevisionRepository encapsulates storage & retrieval of historical versions of work items

type RevisionType

type RevisionType int

RevisionType defines the type of revision for a work item

const (

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

	// RevisionTypeUpdate a work item update
	RevisionTypeUpdate // 4
)

type SimpleType

type SimpleType struct {
	Kind Kind `json:"kind"`
}

SimpleType is an unstructured FieldType

func (SimpleType) ConvertFromModel

func (t SimpleType) ConvertFromModel(value interface{}) (interface{}, error)

ConvertFromModel implements the t interface

func (SimpleType) ConvertToModel

func (t SimpleType) ConvertToModel(value interface{}) (interface{}, error)

ConvertToModel implements the FieldType interface

func (SimpleType) DefaultValue

func (t SimpleType) DefaultValue(value interface{}) (interface{}, error)

DefaultValue implements FieldType

func (SimpleType) Equal

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

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

func (SimpleType) GetKind

func (t SimpleType) GetKind() Kind

GetKind implements FieldType

type TableJoin

type TableJoin struct {
	Active bool // true if this table join is used

	// TableName specifies the foreign table upon which to join
	TableName string // e.g. "iterations"

	// TableAlias allows us to specify an alias for the table to be used in the
	// WHERE clause.
	TableAlias string // e.g. "iter"

	// On is the ON part of the JOIN.
	On string // e.g. `fields@> concat('{"system.iteration": "', iter.ID, '"}')::jsonb`

	// Where defines what condition to place in the main WHERE clause of the
	// query final query.
	Where string

	// PrefixActivators can hold a number of prefix strings that cause this join
	// object to be activated.
	PrefixActivators []string // e.g. []string{"iteration."}

	// disallowedColumns specified all fields that are allowed to be queried
	// from the foreign table. When empty all columns are allowed.
	AllowedColumns []string // e.g. ["name"].

	// DisallowedColumns specified all fields that are not allowed to be queried
	// from the foreign table. When empty all columns are allowed.
	DisallowedColumns []string // e.g. ["created_at"].

	// HandledFields contains those fields that were found to reference this
	// table join. It is later used by Validate() to find out if a field name
	// exists in the database.
	HandledFields []string // e.g. []string{"name", "created_at", "foobar"}

	// ActivateOtherJoins is useful when you make complex joins over mutliple
	// tables. Just put in the names of the table join keys in here that you
	// would like to activate as well. See DefaultTypeGroups() for how the map
	// looks like. If you ask for "A" and that requires "B", then "B" is also
	// added automatically.
	ActivateOtherJoins []string

	// All prefixes in the map keys that would normally be handled by this join
	// will be handled by the join specified here (if any).
	DelegateTo map[string]*TableJoin
}

A TableJoin helps to construct a query like this:

SELECT *
  FROM workitems
  LEFT JOIN iterations iter ON fields@> concat('{"system.iteration": "', iter.ID, '"}')::jsonb
  WHERE iter.name = "foo"

With the prefix activators we can identify if a certain field expression points at data from a joined table. By default there are no restrictions on what can be queried in the joined table but if you fill the allowed/disallowed columns arrays you can explicitly allow or disallow columns to be queried. The names in the allowed/disalowed columns are those of the foreign (aka joined) table.

func Compile

func Compile(where criteria.Expression) (whereClause string, parameters []interface{}, joins []*TableJoin, err []error)

Compile takes an expression and compiles it to a where clause for use with gorm.DB.Where(). Returns the number of expected parameters for the query and a slice of errors if something goes wrong.

func (TableJoin) GetJoinExpression

func (j TableJoin) GetJoinExpression() string

GetJoinExpression returns the SQL JOIN expression for this table join.

func (*TableJoin) HandlesFieldName

func (j *TableJoin) HandlesFieldName(fieldName string) bool

HandlesFieldName returns true if the given field name should be handled by this table join.

func (*TableJoin) TranslateFieldName

func (j *TableJoin) TranslateFieldName(fieldName string) (string, error)

TranslateFieldName returns a non-empty string if the given field name has the prefix specified by the table join and if the field is allowed to be queried; otherwise it returns an empty string.

func (TableJoin) Validate

func (j TableJoin) Validate(db *gorm.DB) error

Validate returns nil if the join is active and all the fields handled by this join do exist in the joined table; otherwise an error is returned.

type TableJoinMap

type TableJoinMap map[string]*TableJoin

TableJoinMap is used to store join in the expression compiler

func (*TableJoinMap) ActivateRequiredJoins

func (joins *TableJoinMap) ActivateRequiredJoins() error

ActivateRequiredJoins recursively walks over all given joins potentially multiple times and activates all other required joins.

func (*TableJoinMap) GetOrderdActivatedJoins

func (joins *TableJoinMap) GetOrderdActivatedJoins() ([]*TableJoin, error)

GetOrderdActivatedJoins returns a slice of activated joins in a proper order, beginning with the join that activates no other join, and ending with the join that activates another join but isn't activated by another join itself.

type TypeBucket

type TypeBucket string

TypeBucket represents a dedicated string type for a bucket of type groups

const (
	BucketPortfolio   TypeBucket = "portfolio"
	BucketRequirement TypeBucket = "requirement"
	BucketIteration   TypeBucket = "iteration"
)

Use following bucket constants while defining static groups. NOTE: Those buckets can later be used by reporting tools for example to gather information on a collective range of work item types.

func (TypeBucket) String

func (t TypeBucket) String() string

String implements the Stringer interface

func (TypeBucket) Value

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

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

type ValidInvalid

type ValidInvalid struct {
	// Valid should contain more than one valid examples so a test function can
	// properly handle work item creation and updating
	Valid   []interface{}
	Invalid []interface{}
	// When the actual value is a zero (0), it will be interpreted as a float64
	// rather than an int. To compensate for that ambiguity, a kind can opt-in
	// to provide a construction function that returns the correct value.
	Compensate func(interface{}) interface{}
}

ValidInvalid given a bunch of tests with expected error results for each work item type field kind, a work item type for each kind...

type WICountsPerIteration

type WICountsPerIteration struct {
	IterationID string `gorm:"column:iterationid"`
	Total       int
	Closed      int
}

WICountsPerIteration counting work item states by iteration

type WorkItem

type WorkItem struct {
	// unique id per installation (used for references at the DB level)
	ID uuid.UUID
	// unique number per _space_
	Number int
	// ID of the type of this work item
	Type uuid.UUID
	// Version for optimistic concurrency control
	Version int
	// ID of the space to which this work item belongs
	SpaceID uuid.UUID
	// The field values, according to the field type
	Fields map[string]interface{}
	// contains filtered or unexported fields
}

WorkItem the model structure for the work item.

func ConvertWorkItemStorageToModel

func ConvertWorkItemStorageToModel(wiType *WorkItemType, wi *WorkItemStorage) (*WorkItem, error)

ConvertWorkItemStorageToModel convert work item model to app WI

func (WorkItem) GetETagData

func (wi WorkItem) GetETagData() []interface{}

GetETagData returns the field values to use to generate the ETag

func (WorkItem) GetLastModified

func (wi WorkItem) GetLastModified() time.Time

GetLastModified returns the last modification time

type WorkItemRepository

type WorkItemRepository interface {
	repository.Exister
	Load(ctx context.Context, spaceID uuid.UUID, wiNumber int) (*WorkItem, error)
	LoadByID(ctx context.Context, id uuid.UUID) (*WorkItem, error)
	LoadBatchByID(ctx context.Context, ids []uuid.UUID) ([]*WorkItem, error)
	LoadByIteration(ctx context.Context, id uuid.UUID) ([]*WorkItem, error)
	LookupIDByNamedSpaceAndNumber(ctx context.Context, ownerName, spaceName string, wiNumber int) (*uuid.UUID, *uuid.UUID, error)
	Save(ctx context.Context, spaceID uuid.UUID, wi WorkItem, modifierID uuid.UUID) (*WorkItem, error)
	Reorder(ctx context.Context, spaceID uuid.UUID, direction DirectionType, targetID *uuid.UUID, wi WorkItem, modifierID uuid.UUID) (*WorkItem, error)
	Delete(ctx context.Context, id uuid.UUID, suppressorID uuid.UUID) error
	Create(ctx context.Context, spaceID uuid.UUID, typeID uuid.UUID, fields map[string]interface{}, creatorID uuid.UUID) (*WorkItem, error)
	List(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression, parentExists *bool, start *int, length *int) ([]WorkItem, int, error)
	Fetch(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression) (*WorkItem, error)
	GetCountsPerIteration(ctx context.Context, spaceID uuid.UUID) (map[string]WICountsPerIteration, error)
	GetCountsForIteration(ctx context.Context, itr *iteration.Iteration) (map[string]WICountsPerIteration, error)
	Count(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression) (int, error)
}

WorkItemRepository encapsulates storage & retrieval of work items

type WorkItemStorage

type WorkItemStorage struct {
	gormsupport.Lifecycle
	// unique id per installation (used for references at the DB level)
	ID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"`
	// unique number per _space_
	Number int
	// Id of the type of this work item
	Type uuid.UUID `sql:"type:uuid"`
	// Version for optimistic concurrency control
	Version int
	// the field values
	Fields Fields `sql:"type:jsonb"`
	// the position of workitem
	ExecutionOrder float64
	// Reference to one Space
	SpaceID uuid.UUID `sql:"type:uuid"`
	// optional timestamp of the latest addition/removal of a relationship with this workitem
	RelationShipsChangedAt *time.Time `sql:"column:relationships_changed_at"`
}

WorkItemStorage represents a work item as it is stored in the database

func (WorkItemStorage) Equal

func (wi WorkItemStorage) Equal(u convert.Equaler) bool

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

func (WorkItemStorage) TableName

func (wi WorkItemStorage) TableName() string

TableName implements gorm.tabler

type WorkItemType

type WorkItemType struct {
	gormsupport.Lifecycle `json:"lifecycle,omitempty"`

	// ID is the primary key of a work item type.
	ID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key" json:"id,omitempty"`

	// Name is a human readable name of this work item type.
	Name string `json:"name,omitempty"`

	// Description is an optional description of the work item type.
	Description *string `json:"description,omitempty"`

	// Icon contains the CSS icon class(es) to render an icon for the work item
	// type.
	Icon string `json:"icon,omitempty"`

	// Version contains the revision number of this work item type and is used
	// for optimistic concurrency control.
	Version int `json:"version,omitempty"`

	// Path contains the IDs of the parents, separated with a dot (".")
	// separator.
	// TODO(kwk): Think about changing this to the dedicated path type also used
	// by iterations.
	Path string `json:"path,omitempty"`

	// Fields contains the definitions of the fields this work item type
	// supports.
	Fields FieldDefinitions `sql:"type:jsonb" json:"fields,omitempty"`

	// SpaceTemplateID refers to the space template to which this work item type
	// belongs.
	SpaceTemplateID uuid.UUID `sql:"type:uuid" json:"space_template_id,omitempty"`

	// Extends is a helper ID to support "extends" attribute of WIT in a space
	// template. This field is not filled when you load a work item type from
	// the DB. Instead the Path member contains the information.
	Extends uuid.UUID `gorm:"-" json:"extends,omitempty"`

	// CanConstruct is true when you can create work items from this work item
	// type.
	CanConstruct bool `gorm:"can_construct" json:"can_construct,omitempty"`

	// ChildTypeIDs is a list of work item type IDs that can be used as child
	// type of this work item. This field is filled upon loading the work item
	// type from the DB.
	ChildTypeIDs []uuid.UUID `gorm:"-" json:"child_types,omitempty"`
}

WorkItemType represents a work item type as it is stored in the db

func (WorkItemType) ConvertWorkItemStorageToModel

func (wit WorkItemType) ConvertWorkItemStorageToModel(workItem WorkItemStorage) (*WorkItem, error)

ConvertWorkItemStorageToModel converts a workItem from the storage/persistence layer into a workItem of the model domain layer

func (WorkItemType) Equal

func (wit WorkItemType) Equal(u convert.Equaler) bool

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

func (WorkItemType) GetETagData

func (wit WorkItemType) GetETagData() []interface{}

GetETagData returns the field values to use to generate the ETag

func (WorkItemType) GetLastModified

func (wit WorkItemType) GetLastModified() time.Time

GetLastModified returns the last modification time

func (WorkItemType) IsTypeOrSubtypeOf

func (wit WorkItemType) IsTypeOrSubtypeOf(typeID uuid.UUID) bool

IsTypeOrSubtypeOf returns true if the work item type with the given type ID, is of the same type as the current WIT or of it is a subtype; otherwise false is returned.

func (WorkItemType) LtreeSafeID

func (wit WorkItemType) LtreeSafeID() string

LtreeSafeID returns the ID of the work item type in an postgres ltree safe manner. The returned string can be used as an ltree node.

func (WorkItemType) TableName

func (wit WorkItemType) TableName() string

TableName implements gorm.tabler

type WorkItemTypeCache

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

WorkItemTypeCache represents WorkItemType cache

func NewWorkItemTypeCache

func NewWorkItemTypeCache() *WorkItemTypeCache

NewWorkItemTypeCache constructs WorkItemTypeCache

func (*WorkItemTypeCache) Clear

func (c *WorkItemTypeCache) Clear()

Clear clears the cache

func (*WorkItemTypeCache) Get

Get returns WorkItemType by ID. The second value (ok) is a bool that is true if the WorkItemType exists in the cache, and false if not.

func (*WorkItemTypeCache) Put

func (c *WorkItemTypeCache) Put(wit WorkItemType)

Put puts a work item type to the cache

type WorkItemTypeGroup

type WorkItemTypeGroup struct {
	gormsupport.Lifecycle `json:"lifecycle"`
	ID                    uuid.UUID   `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key" json:"id"`
	SpaceTemplateID       uuid.UUID   `sql:"type:uuid" json:"space_template_id"`
	Bucket                TypeBucket  `json:"bucket,omitempty"`
	Name                  string      `json:"name,omitempty"` // the name to be displayed to user (is unique)
	Icon                  string      `json:"icon,omitempty"`
	Position              int         `json:"-"`
	TypeList              []uuid.UUID `gorm:"-" json:"type_list,omitempty"`
}

WorkItemTypeGroup represents the node in the group of work item types

func TypeGroupByName

func TypeGroupByName(name string) *WorkItemTypeGroup

TypeGroupByName returns a type group based on its name if such a group exists; otherwise nil is returned.

func TypeGroups

func TypeGroups() []WorkItemTypeGroup

TypeGroups returns the list of work item type groups

func TypeGroupsByBucket

func TypeGroupsByBucket(bucket TypeBucket) []WorkItemTypeGroup

TypeGroupsByBucket returns all type groups which fall into the given bucket

func (WorkItemTypeGroup) Equal

func (witg WorkItemTypeGroup) Equal(u convert.Equaler) bool

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

func (WorkItemTypeGroup) GetETagData

func (witg WorkItemTypeGroup) GetETagData() []interface{}

GetETagData returns the field values to use to generate the ETag

func (WorkItemTypeGroup) GetLastModified

func (witg WorkItemTypeGroup) GetLastModified() time.Time

GetLastModified returns the last modification time

func (WorkItemTypeGroup) TableName

func (witg WorkItemTypeGroup) TableName() string

TableName implements gorm.tabler

type WorkItemTypeGroupRepository

type WorkItemTypeGroupRepository interface {
	repository.Exister
	Create(ctx context.Context, group WorkItemTypeGroup) (*WorkItemTypeGroup, error)
	Load(ctx context.Context, groupID uuid.UUID) (*WorkItemTypeGroup, error)
	List(ctx context.Context, spaceTemplateID uuid.UUID) ([]*WorkItemTypeGroup, error)
}

WorkItemTypeGroupRepository encapsulates storage & retrieval of work item type groups

type WorkItemTypeRepository

type WorkItemTypeRepository interface {
	repository.Exister
	Load(ctx context.Context, id uuid.UUID) (*WorkItemType, error)
	Create(ctx context.Context, spaceTemplateID uuid.UUID, id *uuid.UUID, extendedTypeID *uuid.UUID, name string, description *string, icon string, fields FieldDefinitions, canConstruct bool) (*WorkItemType, error)
	List(ctx context.Context, spaceTemplateID uuid.UUID) ([]WorkItemType, error)
	ListPlannerItemTypes(ctx context.Context, spaceTemplateID uuid.UUID) ([]WorkItemType, error)
	AddChildTypes(ctx context.Context, parentTypeID uuid.UUID, childTypeIDs []uuid.UUID) error
}

WorkItemTypeRepository encapsulates storage & retrieval of work item types

Directories

Path Synopsis
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.
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.

Jump to

Keyboard shortcuts

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