// workItemIncludeHasChildren adds meta information about existing children
490442
func workItemIncludeHasChildren(ctx context.Context, appl application.Application, childLinks ...link.WorkItemLinkList) WorkItemConvertFunc {
	// TODO: Wrap ctx in a Timeout context?
	return func(request *http.Request, wi *workitem.WorkItem, wi2 *app.WorkItem) error {
		var hasChildren bool
		// If we already have information about children inside the child links
		// we can use that before querying the DB.
		if len(childLinks) == 1 {
			for _, l := range childLinks[0] {
				if l.LinkTypeID == link.SystemWorkItemLinkTypeParentChildID && l.SourceID == wi.ID {
					hasChildren = true
				}
			}
		}
		if !hasChildren {
			var err error
			repo := appl.WorkItemLinks()
			if repo != nil {
				hasChildren, err = appl.WorkItemLinks().WorkItemHasChildren(ctx, wi.ID)
				log.Info(ctx, map[string]interface{}{"wi_id": wi.ID}, "Work item has children: %t", hasChildren)
				if err != nil {
					log.Error(ctx, map[string]interface{}{
						"wi_id": wi.ID,
						"err":   err,
					}, "unable to find out if work item has children: %s", wi.ID)
					// enforce to have no children
					hasChildren = false
					return errs.Wrapf(err, "failed to determine if work item %s has children", wi.ID)
				}
			}
		}
		if wi2.Relationships.Children == nil {
			wi2.Relationships.Children = &app.RelationGeneric{}
		}
		wi2.Relationships.Children.Meta = map[string]interface{}{
			"hasChildren": hasChildren,
		}
		return nil
	}
}
141919
func ConvertWorkItem(request *http.Request, wit workitem.WorkItemType, wi workitem.WorkItem, additional ...WorkItemConvertFunc) (*app.WorkItem, error) {
	// construct default values from input WI
	relatedURL := rest.AbsoluteURL(request, app.WorkitemHref(wi.ID))
	labelsRelated := relatedURL + "/labels"
	workItemLinksRelated := relatedURL + "/links"

	op := &app.WorkItem{
		ID:   &wi.ID,
		Type: APIStringTypeWorkItem,
		Attributes: map[string]interface{}{
			workitem.SystemVersion: wi.Version,
			workitem.SystemNumber:  wi.Number,
		},
		Relationships: &app.WorkItemRelationships{
			BaseType: &app.RelationBaseType{
				Data: &app.BaseTypeData{
					ID:   wi.Type,
					Type: APIStringTypeWorkItemType,
				},
				Links: &app.GenericLinks{
					Self: ptr.String(rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.Type))),
				},
			},
			Space: app.NewSpaceRelation(wi.SpaceID, rest.AbsoluteURL(request, app.SpaceHref(wi.SpaceID.String()))),
			WorkItemLinks: &app.RelationGeneric{
				Links: &app.GenericLinks{
					Related: &workItemLinksRelated,
				},
			},
		},
		Links: &app.GenericLinksForWorkItem{
			Self:    &relatedURL,
			Related: &relatedURL,
		},
	}

	// Move fields into Relationships or Attributes as needed
	// TODO(kwk): Loop based on WorkItemType and match against Field.Type instead of directly to field value
	for name, val := range wi.Fields {
		switch name {
		case workitem.SystemAssignees:
			if val != nil {
				userID := val.([]interface{})
				op.Relationships.Assignees = &app.RelationGenericList{
					Data: ConvertUsersSimple(request, userID),
				}
			}
		case workitem.SystemLabels:
			if val != nil {
				labelIDs := val.([]interface{})
				op.Relationships.Labels = &app.RelationGenericList{
					Data: ConvertLabelsSimple(request, labelIDs),
					Links: &app.GenericLinks{
						Related: &labelsRelated,
					},
				}
			}
		case workitem.SystemBoardcolumns:
			if val != nil {
				columnIDs := val.([]interface{})
				op.Relationships.Boardcolumns = &app.RelationGenericList{
					Data: ConvertBoardColumnsSimple(request, columnIDs),
				}
			}
		case workitem.SystemCreator:
			if val != nil {
				userID := val.(string)
				data, links := ConvertUserSimple(request, userID)
				op.Relationships.Creator = &app.RelationGeneric{
					Data:  data,
					Links: links,
				}
			}
		case workitem.SystemIteration:
			if val != nil {
				valStr := val.(string)
				data, links := ConvertIterationSimple(request, valStr)
				op.Relationships.Iteration = &app.RelationGeneric{
					Data:  data,
					Links: links,
				}
			}
		case workitem.SystemArea:
			if val != nil {
				valStr := val.(string)
				data, links := ConvertAreaSimple(request, valStr)
				op.Relationships.Area = &app.RelationGeneric{
					Data:  data,
					Links: links,
				}
			}

		case workitem.SystemTitle:
			// 'HTML escape' the title to prevent script injection
			op.Attributes[name] = html.EscapeString(val.(string))
		case workitem.SystemDescription:
			description := rendering.NewMarkupContentFromValue(val)
			if description != nil {
				op.Attributes[name] = (*description).Content
				op.Attributes[workitem.SystemDescriptionMarkup] = (*description).Markup
				op.Attributes[workitem.SystemDescriptionRendered] = rendering.RenderMarkupToHTML((*description).Content, (*description).Markup)
			}
		case workitem.SystemCodebase:
			if val != nil {
				op.Attributes[name] = val
				// TODO: Following format is TBD and hence commented out
				cb := val.(codebase.Content)
				editURL := rest.AbsoluteURL(request, app.CodebaseHref(cb.CodebaseID)+"/edit")
				op.Links.EditCodebase = &editURL
			}
		default:
			op.Attributes[name] = val
		}
	}
	if op.Relationships.Assignees == nil {
		op.Relationships.Assignees = &app.RelationGenericList{Data: nil}
	}
	if op.Relationships.Iteration == nil {
		op.Relationships.Iteration = &app.RelationGeneric{Data: nil}
	}
	if op.Relationships.Area == nil {
		op.Relationships.Area = &app.RelationGeneric{Data: nil}
	}
	// Always include Comments Link, but optionally use workItemIncludeCommentsAndTotal
	workItemIncludeComments(request, &wi, op)
	workItemIncludeChildren(request, &wi, op)
	workItemIncludeEvents(request, &wi, op)
	for _, add := range additional {
		if err := add(request, &wi, op); err != nil {
			return nil, errs.Wrap(err, "failed to run additional conversion function")
		}
	}
	return op, nil
}
1180775
func workItemIncludeCommentsAndTotal(ctx context.Context, db application.DB, parentID uuid.UUID) WorkItemConvertFunc {
	// TODO: Wrap ctx in a Timeout context?
	count := make(chan int)
	go func() {
		defer close(count)
		application.Transactional(db, func(appl application.Application) error {
			cs, err := appl.Comments().Count(ctx, parentID)
			if err != nil {
				count <- 0
				return errs.WithStack(err)
			}
			count <- cs
			return nil
		})
	}()
	return func(request *http.Request, wi *workitem.WorkItem, wi2 *app.WorkItem) error {
		wi2.Relationships.Comments = CreateCommentsRelation(request, wi)
		wi2.Relationships.Comments.Meta = map[string]interface{}{
			"totalCount": <-count,
		}
		return nil
	}
}
1335249
func workItemIncludeComments(request *http.Request, wi *workitem.WorkItem, wi2 *app.WorkItem) {
	wi2.Relationships.Comments = CreateCommentsRelation(request, wi)
}
21522
func (c *coverer) expandChildren(cand *candidate, cell Cell, numLevels int) int {
	numLevels--
	var numTerminals int
	last := cell.id.ChildEnd()
	for ci := cell.id.ChildBegin(); ci != last; ci = ci.Next() {
		childCell := CellFromCellID(ci)
		if numLevels > 0 {
			if c.region.IntersectsCell(childCell) {
				numTerminals += c.expandChildren(cand, childCell, numLevels)
			}
			continue
		}
		if child := c.newCandidate(childCell); child != nil {
			cand.children = append(cand.children, child)
			cand.numChildren++
			if child.terminal {
				numTerminals++
			}
		}
	}
	return numTerminals
}
977585
func (s *HlsManifest) SetIncludeIframeOnlyStream(v bool) *HlsManifest {
	s.IncludeIframeOnlyStream = &v
	return s
}
865517
func NewWorkItemLabelsController(service *goa.Service, db application.DB, config WorkItemLabelsControllerConfiguration) *WorkItemLabelsController {
	return &WorkItemLabelsController{
		Controller: service.NewController("WorkItemLabelsController"),
		db:         db,
		config:     config,
	}
}
882725
func (r Hardware_SecurityModule) GetItemPricesFromSoftwareDescriptions(softwareDescriptions []datatypes.Software_Description, includeTranslationsFlag *bool, returnAllPricesFlag *bool) (resp []datatypes.Product_Item, err error) {
	params := []interface{}{
		softwareDescriptions,
		includeTranslationsFlag,
		returnAllPricesFlag,
	}
	err = r.Session.DoRequest("SoftLayer_Hardware_SecurityModule", "getItemPricesFromSoftwareDescriptions", params, &r.Options, &resp)
	return
}
811871
func (llss *llSnapshot) ChildCollectionSnapshot(childCollectionName string) (
	moss.Snapshot, error) {
	childSnapshot, exists := llss.childSnapshots[childCollectionName]
	if !exists {
		return nil, nil
	}
	childSnapshot.addRef()
	return childSnapshot, nil
}
695550
func (wit WorkItemType) ConvertWorkItemStorageToModel(workItem WorkItemStorage) (*WorkItem, error) {
	result := WorkItem{
		ID:                     workItem.ID,
		Number:                 workItem.Number,
		Type:                   workItem.Type,
		Version:                workItem.Version,
		Fields:                 map[string]interface{}{},
		SpaceID:                workItem.SpaceID,
		relationShipsChangedAt: workItem.RelationShipsChangedAt,
	}

	for name, field := range wit.Fields {
		var err error
		if name == SystemCreatedAt {
			continue
		}
		result.Fields[name], err = field.ConvertFromModel(name, workItem.Fields[name])
		if err != nil {
			return nil, errs.WithStack(err)
		}
		result.Fields[SystemOrder] = workItem.ExecutionOrder
	}

	return &result, nil
}
1173124
func (s *RecordingGroup) SetIncludeGlobalResourceTypes(v bool) *RecordingGroup {
	s.IncludeGlobalResourceTypes = &v
	return s
}
1337594
func (s *DescribeChannelInput) SetIncludeStatistics(v bool) *DescribeChannelInput {
	s.IncludeStatistics = &v
	return s
}
252766
func (s *GetFolderInput) SetIncludeCustomMetadata(v bool) *GetFolderInput {
	s.IncludeCustomMetadata = &v
	return s
}
886000
func (s *GetDocumentVersionInput) SetIncludeCustomMetadata(v bool) *GetDocumentVersionInput {
	s.IncludeCustomMetadata = &v
	return s
}
554964
func (s *GetApiKeysInput) SetIncludeValues(v bool) *GetApiKeysInput {
	s.IncludeValues = &v
	return s
}
755293
func (s *HlsPackage) SetIncludeIframeOnlyStream(v bool) *HlsPackage {
	s.IncludeIframeOnlyStream = &v
	return s
}
1228574
func (r *GormWorkItemLinkRepository) WorkItemHasChildren(ctx context.Context, parentID uuid.UUID) (bool, error) {
	defer goa.MeasureSince([]string{"goa", "db", "workitemlink", "has", "children"}, time.Now())
	query := fmt.Sprintf(`
		SELECT EXISTS (
			SELECT 1 FROM %[1]s WHERE id in (
				SELECT target_id FROM %[2]s
				WHERE source_id = $1 AND deleted_at IS NULL AND link_type_id = $2
			)
		)`,
		workitem.WorkItemStorage{}.TableName(),
		WorkItemLink{}.TableName())
	var hasChildren bool
	db := r.db.CommonDB()
	stmt, err := db.Prepare(query)
	if err != nil {
		return false, errs.Wrapf(err, "failed prepare statement: %s", query)
	}
	defer closeable.Close(ctx, stmt)
	err = stmt.QueryRow(parentID.String(), SystemWorkItemLinkTypeParentChildID.String()).Scan(&hasChildren)
	if err != nil {
		return false, errs.Wrapf(err, "failed to check if work item %s has children: %s", parentID.String(), query)
	}
	return hasChildren, nil
}