/*
Create a new menu object.
Dispatches a call to ThrustCore to generate the object and return the new
TargetID in a reply.
*/
556390
func NewMenu() *Menu {
	menu := Menu{}
	menuCreate := Command{
		Action:     "create",
		ObjectType: "menu",
	}
	menu.Sync = MenuSync{
		ReadyChan:        make(chan bool),
		DisplayedChan:    make(chan bool),
		ChildStableChan:  make(chan uint),
		TreeStableChan:   make(chan bool),
		ReadyQueue:       make([]*Command, 0),
		DisplayedQueue:   make([]*Command, 0),
		ChildStableQueue: make([]*ChildCommand, 0),
		TreeStableQueue:  make([]*Command, 0),
	}
	menu.ReplyHandlers = make(map[uint]func(reply CommandResponse, item *MenuItem))
	menu.SetSendChannel(connection.GetInputChannels())
	menu.WaitingResponses = append(menu.WaitingResponses, &menuCreate)
	dispatcher.RegisterHandler(menu.DispatchResponse)

	go menu.SendThread()
	menu.Send(&menuCreate)

	return &menu
}
383558
func (s *REST) Create(ctx context.Context, obj runtime.Object, _ rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
	mapping, ok := obj.(*userinternal.UserIdentityMapping)
	if !ok {
		return nil, kerrs.NewBadRequest("invalid type")
	}
	Strategy.PrepareForCreate(ctx, mapping)
	createdMapping, _, err := s.createOrUpdate(ctx, obj, true)
	return createdMapping, err
}
283965
func (menu *Menu) DispatchResponse(reply CommandResponse) {
	switch reply.Action {
	case "event":
		menu.HandleEvent(reply)
	case "reply":
		menu.HandleReply(reply)
	}

	// for _, child := range menu.Items {
	// 	if child.IsSubMenu() {
	// 		child.SubMenu.DispatchResponse(reply)
	// 	}
	// }
}
499755
func (o *LargeObjects) Create(id pgtype.OID) (pgtype.OID, error) {
	newOID, err := fpInt32(o.fp.CallFn("lo_create", []fpArg{fpIntArg(int32(id))}))
	return pgtype.OID(newOID), err
}
211158
func (c *SpaceIterationsController) Create(ctx *app.CreateSpaceIterationsContext) error {
	currentUser, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	// Validate Request
	if ctx.Payload.Data == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data", nil).Expected("not nil"))
	}
	reqIter := ctx.Payload.Data
	if reqIter.Attributes.Name == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.name", nil).Expected("not nil"))
	}

	var responseData *app.Iteration
	err = application.Transactional(c.db, func(appl application.Application) error {
		s, err := appl.Spaces().Load(ctx, ctx.SpaceID)
		if err != nil {
			return goa.ErrNotFound(err.Error())
		}
		if !uuid.Equal(*currentUser, s.OwnerID) {
			log.Warn(ctx, map[string]interface{}{
				"space_id":     ctx.SpaceID,
				"space_owner":  s.OwnerID,
				"current_user": *currentUser,
			}, "user is not the space owner")
			return errors.NewForbiddenError("user is not the space owner")
		}
		// Put iteration under root iteration
		rootIteration, err := appl.Iterations().Root(ctx, ctx.SpaceID)
		if err != nil {
			return goa.ErrNotFound(err.Error())
		}

		userActive := false
		if reqIter.Attributes.UserActive != nil {
			userActive = *reqIter.Attributes.UserActive
		}
		newItr := iteration.Iteration{
			ID:         uuid.NewV4(),
			SpaceID:    ctx.SpaceID,
			Name:       *reqIter.Attributes.Name,
			StartAt:    reqIter.Attributes.StartAt,
			EndAt:      reqIter.Attributes.EndAt,
			UserActive: userActive,
		}
		newItr.MakeChildOf(*rootIteration)
		if reqIter.Attributes.Description != nil {
			newItr.Description = reqIter.Attributes.Description
		}
		err = appl.Iterations().Create(ctx, &newItr)
		if err != nil {
			return err
		}
		// For create, count will always be zero hence no need to query
		// by passing empty map, updateIterationsWithCounts will be able to put zero values
		wiCounts := make(map[string]workitem.WICountsPerIteration)
		log.Info(ctx, map[string]interface{}{
			"iteration_id": newItr.ID,
			"wiCounts":     wiCounts,
		}, "wicounts for created iteration %s -> %v", newItr.ID.String(), wiCounts)

		if !newItr.Path.IsEmpty() {
			allParentsUUIDs := newItr.Path.ParentPath()
			iterations, error := appl.Iterations().LoadMultiple(ctx, allParentsUUIDs)
			if error != nil {
				return err
			}
			itrMap := make(iterationIDMap)
			for _, itr := range iterations {
				itrMap[itr.ID] = itr
			}
			responseData = ConvertIteration(ctx.Request, newItr, parentPathResolver(itrMap), updateIterationsWithCounts(wiCounts))
		} else {
			responseData = ConvertIteration(ctx.Request, newItr, updateIterationsWithCounts(wiCounts))
		}
		return nil
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	res := &app.IterationSingle{
		Data: responseData,
	}
	ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.Request, app.IterationHref(res.Data.ID)))
	return ctx.Created(res)
}
12188
func NewProjectCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
	var (
		opts projectOpts
	)
	var command = &cobra.Command{
		Use:   "create PROJECT",
		Short: "Create a project",
		Run: func(c *cobra.Command, args []string) {
			if len(args) == 0 {
				c.HelpFunc()(c, args)
				os.Exit(1)
			}
			projName := args[0]
			proj := v1alpha1.AppProject{
				ObjectMeta: v1.ObjectMeta{Name: projName},
				Spec: v1alpha1.AppProjectSpec{
					Description:  opts.description,
					Destinations: opts.GetDestinations(),
					SourceRepos:  opts.sources,
				},
			}
			conn, projIf := argocdclient.NewClientOrDie(clientOpts).NewProjectClientOrDie()
			defer util.Close(conn)

			_, err := projIf.Create(context.Background(), &project.ProjectCreateRequest{Project: &proj})
			errors.CheckError(err)
		},
	}
	addProjFlags(command, &opts)
	return command
}
304517
func (c *FleetClient) Create(
	targets []string, wg *sync.WaitGroup, out, ew io.Writer) {

	units := make([]*schema.Unit, len(targets))

	for i, target := range targets {
		unitName, unitFile, err := c.createUnitFile(target)
		if err != nil {
			fmt.Fprintf(ew, "Error creating: %s\n", err)
			return
		}
		units[i] = &schema.Unit{
			Name:    unitName,
			Options: schema.MapUnitFileToSchemaUnitOptions(unitFile),
		}
	}

	for _, unit := range units {
		wg.Add(1)
		go doCreate(c, unit, wg, out, ew)
	}
}
1064645
func (c *FakeClusterRoleBindings) Create(clusterRoleBinding *v1beta1.ClusterRoleBinding) (result *v1beta1.ClusterRoleBinding, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewRootCreateAction(clusterrolebindingsResource, clusterRoleBinding), &v1beta1.ClusterRoleBinding{})
	if obj == nil {
		return nil, err
	}
	return obj.(*v1beta1.ClusterRoleBinding), err
}
465415
func newMenuItem(parentCtx context.Context, rootID string, o *MenuItemOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) (m *MenuItem) {
	m = &MenuItem{
		o:      o,
		object: newObject(parentCtx, c, d, i, w, i.new()),
		rootID: rootID,
	}
	if o.OnClick != nil {
		m.On(EventNameMenuItemEventClicked, o.OnClick)
	}
	if len(o.SubMenu) > 0 {
		m.s = &SubMenu{newSubMenu(parentCtx, rootID, o.SubMenu, c, d, i, w)}
	}
	return
}
155728
func NewCmdCreate() *cobra.Command {
	return &cobra.Command{
		Use:   "create <imageName> <destination>",
		Short: "Bootstrap a new S2I image repository",
		Long:  "Bootstrap a new S2I image with given imageName inside the destination directory",
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) < 2 {
				cmd.Help()
				return
			}
			b := create.New(args[0], args[1])
			b.AddSTIScripts()
			b.AddDockerfile()
			b.AddReadme()
			b.AddTests()
		},
	}
}
849652
func (d *DevTools) Create(ctx context.Context) (*Target, error) {
	return d.CreateURL(ctx, "")
}
893656
func (c *FakeExamples) Create(example *crv1.Example) (result *crv1.Example, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewCreateAction(examplesResource, c.ns, example), &crv1.Example{})

	if obj == nil {
		return nil, err
	}
	return obj.(*crv1.Example), err
}
581658
func (t *Tray) Create() (err error) {
	if err = t.isActionable(); err != nil {
		return
	}
	var e = Event{Name: EventNameTrayCmdCreate, TargetID: t.id, TrayOptions: t.o}
	_, err = synchronousEvent(t.c, t, t.w, e, EventNameTrayEventCreated)
	return
}
983579
func (menu *Menu) AddSubmenu(commandID uint, label string, child *Menu) {
	command := Command{
		Method: "add_submenu",
		Args: CommandArguments{
			CommandID: commandID,
			Label:     label,
		},
	}

	// Assign Bidirectional navigation elements i.e. DoublyLinkedLists
	child.Parent = menu
	menuItem := MenuItem{
		CommandID: commandID,
		Label:     label,
		SubMenu:   child,
		Parent:    menu,
	}
	menu.Items = append(menu.Items, &menuItem)

	menu.CallWhenChildStable(&command, child)
}
929042
func (c *IterationController) CreateChild(ctx *app.CreateChildIterationContext) error {
	currentUser, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	parentID, err := uuid.FromString(ctx.IterationID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}
	var parentItr *iteration.Iteration
	var itrSpace *space.Space
	err = application.Transactional(c.db, func(appl application.Application) error {
		parentItr, err = appl.Iterations().Load(ctx, parentID)
		if err != nil {
			return err
		}
		itrSpace, err = appl.Spaces().Load(ctx, parentItr.SpaceID)
		return err
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	authorized, spaceOwner, err := verifyUser(ctx, *currentUser, itrSpace)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error()))
	}
	if !authorized && !spaceOwner {
		log.Error(ctx, map[string]interface{}{
			"space_id":     itrSpace.ID,
			"space_owner":  itrSpace.OwnerID,
			"current_user": *currentUser,
		}, "user is not the space owner")
		if !authorized {
			// unauthorized
			return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError("user is not allowed to create an iteration in this space"))
		}
		// forbidden
		// Ideally we never hit following error
		// But written following line to make it verbose 401 vs 403
		return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not allowed to create an iteration in this space"))
	}
	reqItr := ctx.Payload.Data
	if reqItr.Attributes.Name == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.name", nil).Expected("not nil"))
	}

	if ctx.Payload.Data.Attributes.UserActive != nil {
		reqItr.Attributes.UserActive = ctx.Payload.Data.Attributes.UserActive
	} else {
		userActive := false
		reqItr.Attributes.UserActive = &userActive
	}
	itr := &iteration.Iteration{
		SpaceID:     parentItr.SpaceID,
		Name:        *reqItr.Attributes.Name,
		Description: reqItr.Attributes.Description,
		StartAt:     reqItr.Attributes.StartAt,
		EndAt:       reqItr.Attributes.EndAt,
		UserActive:  *reqItr.Attributes.UserActive,
	}
	if reqItr.ID != nil {
		itr.ID = *reqItr.ID
	} else {
		itr.ID = uuid.NewV4()
	}
	itr.MakeChildOf(*parentItr)

	itrMap := make(iterationIDMap)
	err = application.Transactional(c.db, func(appl application.Application) error {
		err = appl.Iterations().Create(ctx, itr)
		if err != nil {
			return err
		}
		// For create, count will always be zero hence no need to query
		// by passing empty map, updateIterationsWithCounts will be able to put zero values
		parentItrs, err := appl.Iterations().LoadMultiple(ctx, itr.Path.ParentPath())
		if err != nil {
			return err
		}
		for _, itr := range parentItrs {
			itrMap[itr.ID] = itr
		}
		return nil
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	wiCounts := make(map[string]workitem.WICountsPerIteration)
	responseData := ConvertIteration(ctx.Request, *itr, parentPathResolver(itrMap), updateIterationsWithCounts(wiCounts))
	res := &app.IterationSingle{
		Data: responseData,
	}
	ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.Request, app.IterationHref(res.Data.ID)))
	return ctx.Created(res)
}
1231288
func (w *Window) NewMenu(i []*MenuItemOptions) *Menu {
	return newMenu(w.ctx, w.id, i, w.c, w.d, w.i, w.w)
}
110386
func (this *Weixinmp) CreateCustomMenu(btn *[]Button) error {
	var menu struct {
		Button *[]Button `json:"button"`
	}
	menu.Button = btn
	data, err := json.Marshal(&menu)
	if err != nil {
		return err
	}
	buf := bytes.NewBuffer(data)
	url := fmt.Sprintf("%smenu/create?access_token=", UrlPrefix)
	// retry
	for i := 0; i < retryNum; i++ {
		token, err := this.AccessToken.Fresh()
		if err != nil {
			if i < retryNum-1 {
				continue
			}
			return err
		}
		if _, err := post(url+token, "text/plain", buf); err != nil {
			if i < retryNum-1 {
				continue
			}
			return err
		}
		break // success
	}
	return nil
}