id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
13,300
fabric8-services/fabric8-wit
remoteworkitem/github.go
Fetch
func (g *GithubTracker) Fetch(githubAuthToken string) chan TrackerItemContent { f := githubIssueFetcher{} ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: githubAuthToken}, ) tc := oauth2.NewClient(oauth2.NoContext, ts) f.client = github.NewClient(tc) return g.fetch(&f) }
go
func (g *GithubTracker) Fetch(githubAuthToken string) chan TrackerItemContent { f := githubIssueFetcher{} ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: githubAuthToken}, ) tc := oauth2.NewClient(oauth2.NoContext, ts) f.client = github.NewClient(tc) return g.fetch(&f) }
[ "func", "(", "g", "*", "GithubTracker", ")", "Fetch", "(", "githubAuthToken", "string", ")", "chan", "TrackerItemContent", "{", "f", ":=", "githubIssueFetcher", "{", "}", "\n", "ts", ":=", "oauth2", ".", "StaticTokenSource", "(", "&", "oauth2", ".", "Token", "{", "AccessToken", ":", "githubAuthToken", "}", ",", ")", "\n", "tc", ":=", "oauth2", ".", "NewClient", "(", "oauth2", ".", "NoContext", ",", "ts", ")", "\n", "f", ".", "client", "=", "github", ".", "NewClient", "(", "tc", ")", "\n", "return", "g", ".", "fetch", "(", "&", "f", ")", "\n", "}" ]
// Fetch tracker items from Github
[ "Fetch", "tracker", "items", "from", "Github" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/github.go#L34-L42
13,301
fabric8-services/fabric8-wit
controller/comments.go
NewCommentsController
func NewCommentsController(service *goa.Service, db application.DB, config CommentsControllerConfiguration) *CommentsController { return NewNotifyingCommentsController(service, db, &notification.DevNullChannel{}, config) }
go
func NewCommentsController(service *goa.Service, db application.DB, config CommentsControllerConfiguration) *CommentsController { return NewNotifyingCommentsController(service, db, &notification.DevNullChannel{}, config) }
[ "func", "NewCommentsController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "CommentsControllerConfiguration", ")", "*", "CommentsController", "{", "return", "NewNotifyingCommentsController", "(", "service", ",", "db", ",", "&", "notification", ".", "DevNullChannel", "{", "}", ",", "config", ")", "\n", "}" ]
// NewCommentsController creates a comments controller.
[ "NewCommentsController", "creates", "a", "comments", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L44-L46
13,302
fabric8-services/fabric8-wit
controller/comments.go
NewNotifyingCommentsController
func NewNotifyingCommentsController(service *goa.Service, db application.DB, notificationChannel notification.Channel, config CommentsControllerConfiguration) *CommentsController { n := notificationChannel if n == nil { n = &notification.DevNullChannel{} } return &CommentsController{ Controller: service.NewController("CommentsController"), db: db, notification: n, config: config, } }
go
func NewNotifyingCommentsController(service *goa.Service, db application.DB, notificationChannel notification.Channel, config CommentsControllerConfiguration) *CommentsController { n := notificationChannel if n == nil { n = &notification.DevNullChannel{} } return &CommentsController{ Controller: service.NewController("CommentsController"), db: db, notification: n, config: config, } }
[ "func", "NewNotifyingCommentsController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "notificationChannel", "notification", ".", "Channel", ",", "config", "CommentsControllerConfiguration", ")", "*", "CommentsController", "{", "n", ":=", "notificationChannel", "\n", "if", "n", "==", "nil", "{", "n", "=", "&", "notification", ".", "DevNullChannel", "{", "}", "\n", "}", "\n", "return", "&", "CommentsController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "notification", ":", "n", ",", "config", ":", "config", ",", "}", "\n", "}" ]
// NewNotifyingCommentsController creates a comments controller with notification broadcast.
[ "NewNotifyingCommentsController", "creates", "a", "comments", "controller", "with", "notification", "broadcast", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L49-L60
13,303
fabric8-services/fabric8-wit
controller/comments.go
Update
func (c *CommentsController) Update(ctx *app.UpdateCommentsContext) error { identityID, err := login.ContextIdentity(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error())) } cm, wi, userIsCreator, err := c.loadComment(ctx.Context, ctx.CommentID, *identityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } // User is allowed to update if user is creator of the comment OR user is a space collaborator if !userIsCreator { authorized, err := authz.Authorize(ctx, wi.SpaceID.String()) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error())) } if !authorized { return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not a space collaborator")) } } err = c.performUpdate(ctx, cm, identityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } // This code should change if others type of parents than WI are allowed res := &app.CommentSingle{ Data: ConvertComment(ctx.Request, *cm, CommentIncludeParentWorkItem(ctx, cm)), } c.notification.Send(ctx, notification.NewCommentUpdated(cm.ID.String())) return ctx.OK(res) }
go
func (c *CommentsController) Update(ctx *app.UpdateCommentsContext) error { identityID, err := login.ContextIdentity(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error())) } cm, wi, userIsCreator, err := c.loadComment(ctx.Context, ctx.CommentID, *identityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } // User is allowed to update if user is creator of the comment OR user is a space collaborator if !userIsCreator { authorized, err := authz.Authorize(ctx, wi.SpaceID.String()) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error())) } if !authorized { return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not a space collaborator")) } } err = c.performUpdate(ctx, cm, identityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } // This code should change if others type of parents than WI are allowed res := &app.CommentSingle{ Data: ConvertComment(ctx.Request, *cm, CommentIncludeParentWorkItem(ctx, cm)), } c.notification.Send(ctx, notification.NewCommentUpdated(cm.ID.String())) return ctx.OK(res) }
[ "func", "(", "c", "*", "CommentsController", ")", "Update", "(", "ctx", "*", "app", ".", "UpdateCommentsContext", ")", "error", "{", "identityID", ",", "err", ":=", "login", ".", "ContextIdentity", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "goa", ".", "ErrUnauthorized", "(", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "cm", ",", "wi", ",", "userIsCreator", ",", "err", ":=", "c", ".", "loadComment", "(", "ctx", ".", "Context", ",", "ctx", ".", "CommentID", ",", "*", "identityID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "// User is allowed to update if user is creator of the comment OR user is a space collaborator", "if", "!", "userIsCreator", "{", "authorized", ",", "err", ":=", "authz", ".", "Authorize", "(", "ctx", ",", "wi", ".", "SpaceID", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewUnauthorizedError", "(", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "if", "!", "authorized", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewForbiddenError", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "\n", "err", "=", "c", ".", "performUpdate", "(", "ctx", ",", "cm", ",", "identityID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "// This code should change if others type of parents than WI are allowed", "res", ":=", "&", "app", ".", "CommentSingle", "{", "Data", ":", "ConvertComment", "(", "ctx", ".", "Request", ",", "*", "cm", ",", "CommentIncludeParentWorkItem", "(", "ctx", ",", "cm", ")", ")", ",", "}", "\n", "c", ".", "notification", ".", "Send", "(", "ctx", ",", "notification", ".", "NewCommentUpdated", "(", "cm", ".", "ID", ".", "String", "(", ")", ")", ")", "\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// Update does PATCH comment
[ "Update", "does", "PATCH", "comment" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L86-L115
13,304
fabric8-services/fabric8-wit
controller/comments.go
Delete
func (c *CommentsController) Delete(ctx *app.DeleteCommentsContext) error { identityID, err := login.ContextIdentity(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error())) } cm, wi, userIsCreator, err := c.loadComment(ctx.Context, ctx.CommentID, *identityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } // User is allowed to delete if user is creator of the comment OR user is a space collaborator if !userIsCreator { authorized, err := authz.Authorize(ctx, wi.SpaceID.String()) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error())) } if !authorized { return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not a space collaborator")) } } err = application.Transactional(c.db, func(appl application.Application) error { return appl.Comments().Delete(ctx.Context, cm.ID, *identityID) }) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
go
func (c *CommentsController) Delete(ctx *app.DeleteCommentsContext) error { identityID, err := login.ContextIdentity(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error())) } cm, wi, userIsCreator, err := c.loadComment(ctx.Context, ctx.CommentID, *identityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } // User is allowed to delete if user is creator of the comment OR user is a space collaborator if !userIsCreator { authorized, err := authz.Authorize(ctx, wi.SpaceID.String()) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error())) } if !authorized { return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not a space collaborator")) } } err = application.Transactional(c.db, func(appl application.Application) error { return appl.Comments().Delete(ctx.Context, cm.ID, *identityID) }) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
[ "func", "(", "c", "*", "CommentsController", ")", "Delete", "(", "ctx", "*", "app", ".", "DeleteCommentsContext", ")", "error", "{", "identityID", ",", "err", ":=", "login", ".", "ContextIdentity", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "goa", ".", "ErrUnauthorized", "(", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "cm", ",", "wi", ",", "userIsCreator", ",", "err", ":=", "c", ".", "loadComment", "(", "ctx", ".", "Context", ",", "ctx", ".", "CommentID", ",", "*", "identityID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "// User is allowed to delete if user is creator of the comment OR user is a space collaborator", "if", "!", "userIsCreator", "{", "authorized", ",", "err", ":=", "authz", ".", "Authorize", "(", "ctx", ",", "wi", ".", "SpaceID", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewUnauthorizedError", "(", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "if", "!", "authorized", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewForbiddenError", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "\n", "err", "=", "application", ".", "Transactional", "(", "c", ".", "db", ",", "func", "(", "appl", "application", ".", "Application", ")", "error", "{", "return", "appl", ".", "Comments", "(", ")", ".", "Delete", "(", "ctx", ".", "Context", ",", "cm", ".", "ID", ",", "*", "identityID", ")", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ".", "OK", "(", "[", "]", "byte", "{", "}", ")", "\n", "}" ]
// Delete does DELETE comment
[ "Delete", "does", "DELETE", "comment" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L147-L173
13,305
fabric8-services/fabric8-wit
controller/comments.go
ConvertComments
func ConvertComments(request *http.Request, comments []comment.Comment, additional ...CommentConvertFunc) []*app.Comment { var cs = []*app.Comment{} for _, c := range comments { cs = append(cs, ConvertComment(request, c, additional...)) } return cs }
go
func ConvertComments(request *http.Request, comments []comment.Comment, additional ...CommentConvertFunc) []*app.Comment { var cs = []*app.Comment{} for _, c := range comments { cs = append(cs, ConvertComment(request, c, additional...)) } return cs }
[ "func", "ConvertComments", "(", "request", "*", "http", ".", "Request", ",", "comments", "[", "]", "comment", ".", "Comment", ",", "additional", "...", "CommentConvertFunc", ")", "[", "]", "*", "app", ".", "Comment", "{", "var", "cs", "=", "[", "]", "*", "app", ".", "Comment", "{", "}", "\n", "for", "_", ",", "c", ":=", "range", "comments", "{", "cs", "=", "append", "(", "cs", ",", "ConvertComment", "(", "request", ",", "c", ",", "additional", "...", ")", ")", "\n", "}", "\n", "return", "cs", "\n", "}" ]
// ConvertComments converts between internal and external REST representation
[ "ConvertComments", "converts", "between", "internal", "and", "external", "REST", "representation" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L180-L186
13,306
fabric8-services/fabric8-wit
controller/comments.go
ConvertCommentsResourceID
func ConvertCommentsResourceID(request *http.Request, comments []comment.Comment, additional ...CommentConvertFunc) []*app.Comment { var cs = []*app.Comment{} for _, c := range comments { cs = append(cs, ConvertCommentResourceID(request, c, additional...)) } return cs }
go
func ConvertCommentsResourceID(request *http.Request, comments []comment.Comment, additional ...CommentConvertFunc) []*app.Comment { var cs = []*app.Comment{} for _, c := range comments { cs = append(cs, ConvertCommentResourceID(request, c, additional...)) } return cs }
[ "func", "ConvertCommentsResourceID", "(", "request", "*", "http", ".", "Request", ",", "comments", "[", "]", "comment", ".", "Comment", ",", "additional", "...", "CommentConvertFunc", ")", "[", "]", "*", "app", ".", "Comment", "{", "var", "cs", "=", "[", "]", "*", "app", ".", "Comment", "{", "}", "\n", "for", "_", ",", "c", ":=", "range", "comments", "{", "cs", "=", "append", "(", "cs", ",", "ConvertCommentResourceID", "(", "request", ",", "c", ",", "additional", "...", ")", ")", "\n", "}", "\n", "return", "cs", "\n", "}" ]
// ConvertCommentsResourceID converts between internal and external REST representation, ResourceIdentificationObject only
[ "ConvertCommentsResourceID", "converts", "between", "internal", "and", "external", "REST", "representation", "ResourceIdentificationObject", "only" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L189-L195
13,307
fabric8-services/fabric8-wit
controller/comments.go
ConvertCommentResourceID
func ConvertCommentResourceID(request *http.Request, comment comment.Comment, additional ...CommentConvertFunc) *app.Comment { c := &app.Comment{ Type: APIStringTypeComments, ID: &comment.ID, } for _, add := range additional { add(request, &comment, c) } return c }
go
func ConvertCommentResourceID(request *http.Request, comment comment.Comment, additional ...CommentConvertFunc) *app.Comment { c := &app.Comment{ Type: APIStringTypeComments, ID: &comment.ID, } for _, add := range additional { add(request, &comment, c) } return c }
[ "func", "ConvertCommentResourceID", "(", "request", "*", "http", ".", "Request", ",", "comment", "comment", ".", "Comment", ",", "additional", "...", "CommentConvertFunc", ")", "*", "app", ".", "Comment", "{", "c", ":=", "&", "app", ".", "Comment", "{", "Type", ":", "APIStringTypeComments", ",", "ID", ":", "&", "comment", ".", "ID", ",", "}", "\n", "for", "_", ",", "add", ":=", "range", "additional", "{", "add", "(", "request", ",", "&", "comment", ",", "c", ")", "\n", "}", "\n", "return", "c", "\n", "}" ]
// ConvertCommentResourceID converts between internal and external REST representation, ResourceIdentificationObject only
[ "ConvertCommentResourceID", "converts", "between", "internal", "and", "external", "REST", "representation", "ResourceIdentificationObject", "only" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L198-L207
13,308
fabric8-services/fabric8-wit
controller/comments.go
ConvertComment
func ConvertComment(request *http.Request, comment comment.Comment, additional ...CommentConvertFunc) *app.Comment { relatedURL := rest.AbsoluteURL(request, app.CommentsHref(comment.ID)) relatedCreatorLink := rest.AbsoluteURL(request, fmt.Sprintf("%s/%s", usersEndpoint, comment.Creator)) c := &app.Comment{ Type: APIStringTypeComments, ID: &comment.ID, Attributes: &app.CommentAttributes{ Body: &comment.Body, BodyRendered: ptr.String(rendering.RenderMarkupToHTML(comment.Body, comment.Markup)), Markup: ptr.String(rendering.NilSafeGetMarkup(&comment.Markup)), CreatedAt: &comment.CreatedAt, UpdatedAt: &comment.UpdatedAt, }, Relationships: &app.CommentRelations{ Creator: &app.RelationGeneric{ Data: &app.GenericData{ Type: ptr.String(APIStringTypeUser), ID: ptr.String(comment.Creator.String()), Links: &app.GenericLinks{ Related: &relatedCreatorLink, }, }, }, CreatedBy: &app.CommentCreatedBy{ // Keep old API style until all cients are updated Data: &app.IdentityRelationData{ Type: APIStringTypeUser, ID: &comment.Creator, }, Links: &app.GenericLinks{ Related: &relatedCreatorLink, }, }, }, Links: &app.GenericLinks{ Self: &relatedURL, Related: &relatedURL, }, } if comment.ParentCommentID.Valid == true { c.Relationships.ParentComment = &app.RelationGeneric{ Data: &app.GenericData{ Type: ptr.String(APIStringTypeComments), ID: ptr.String(comment.ParentCommentID.UUID.String()), }, } } for _, add := range additional { add(request, &comment, c) } return c }
go
func ConvertComment(request *http.Request, comment comment.Comment, additional ...CommentConvertFunc) *app.Comment { relatedURL := rest.AbsoluteURL(request, app.CommentsHref(comment.ID)) relatedCreatorLink := rest.AbsoluteURL(request, fmt.Sprintf("%s/%s", usersEndpoint, comment.Creator)) c := &app.Comment{ Type: APIStringTypeComments, ID: &comment.ID, Attributes: &app.CommentAttributes{ Body: &comment.Body, BodyRendered: ptr.String(rendering.RenderMarkupToHTML(comment.Body, comment.Markup)), Markup: ptr.String(rendering.NilSafeGetMarkup(&comment.Markup)), CreatedAt: &comment.CreatedAt, UpdatedAt: &comment.UpdatedAt, }, Relationships: &app.CommentRelations{ Creator: &app.RelationGeneric{ Data: &app.GenericData{ Type: ptr.String(APIStringTypeUser), ID: ptr.String(comment.Creator.String()), Links: &app.GenericLinks{ Related: &relatedCreatorLink, }, }, }, CreatedBy: &app.CommentCreatedBy{ // Keep old API style until all cients are updated Data: &app.IdentityRelationData{ Type: APIStringTypeUser, ID: &comment.Creator, }, Links: &app.GenericLinks{ Related: &relatedCreatorLink, }, }, }, Links: &app.GenericLinks{ Self: &relatedURL, Related: &relatedURL, }, } if comment.ParentCommentID.Valid == true { c.Relationships.ParentComment = &app.RelationGeneric{ Data: &app.GenericData{ Type: ptr.String(APIStringTypeComments), ID: ptr.String(comment.ParentCommentID.UUID.String()), }, } } for _, add := range additional { add(request, &comment, c) } return c }
[ "func", "ConvertComment", "(", "request", "*", "http", ".", "Request", ",", "comment", "comment", ".", "Comment", ",", "additional", "...", "CommentConvertFunc", ")", "*", "app", ".", "Comment", "{", "relatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "CommentsHref", "(", "comment", ".", "ID", ")", ")", "\n", "relatedCreatorLink", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "usersEndpoint", ",", "comment", ".", "Creator", ")", ")", "\n", "c", ":=", "&", "app", ".", "Comment", "{", "Type", ":", "APIStringTypeComments", ",", "ID", ":", "&", "comment", ".", "ID", ",", "Attributes", ":", "&", "app", ".", "CommentAttributes", "{", "Body", ":", "&", "comment", ".", "Body", ",", "BodyRendered", ":", "ptr", ".", "String", "(", "rendering", ".", "RenderMarkupToHTML", "(", "comment", ".", "Body", ",", "comment", ".", "Markup", ")", ")", ",", "Markup", ":", "ptr", ".", "String", "(", "rendering", ".", "NilSafeGetMarkup", "(", "&", "comment", ".", "Markup", ")", ")", ",", "CreatedAt", ":", "&", "comment", ".", "CreatedAt", ",", "UpdatedAt", ":", "&", "comment", ".", "UpdatedAt", ",", "}", ",", "Relationships", ":", "&", "app", ".", "CommentRelations", "{", "Creator", ":", "&", "app", ".", "RelationGeneric", "{", "Data", ":", "&", "app", ".", "GenericData", "{", "Type", ":", "ptr", ".", "String", "(", "APIStringTypeUser", ")", ",", "ID", ":", "ptr", ".", "String", "(", "comment", ".", "Creator", ".", "String", "(", ")", ")", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Related", ":", "&", "relatedCreatorLink", ",", "}", ",", "}", ",", "}", ",", "CreatedBy", ":", "&", "app", ".", "CommentCreatedBy", "{", "// Keep old API style until all cients are updated", "Data", ":", "&", "app", ".", "IdentityRelationData", "{", "Type", ":", "APIStringTypeUser", ",", "ID", ":", "&", "comment", ".", "Creator", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Related", ":", "&", "relatedCreatorLink", ",", "}", ",", "}", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Self", ":", "&", "relatedURL", ",", "Related", ":", "&", "relatedURL", ",", "}", ",", "}", "\n", "if", "comment", ".", "ParentCommentID", ".", "Valid", "==", "true", "{", "c", ".", "Relationships", ".", "ParentComment", "=", "&", "app", ".", "RelationGeneric", "{", "Data", ":", "&", "app", ".", "GenericData", "{", "Type", ":", "ptr", ".", "String", "(", "APIStringTypeComments", ")", ",", "ID", ":", "ptr", ".", "String", "(", "comment", ".", "ParentCommentID", ".", "UUID", ".", "String", "(", ")", ")", ",", "}", ",", "}", "\n", "}", "\n", "for", "_", ",", "add", ":=", "range", "additional", "{", "add", "(", "request", ",", "&", "comment", ",", "c", ")", "\n", "}", "\n", "return", "c", "\n", "}" ]
// ConvertComment converts between internal and external REST representation
[ "ConvertComment", "converts", "between", "internal", "and", "external", "REST", "representation" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L210-L260
13,309
fabric8-services/fabric8-wit
controller/comments.go
CommentIncludeParentWorkItem
func CommentIncludeParentWorkItem(ctx context.Context, c *comment.Comment) CommentConvertFunc { return func(request *http.Request, comment *comment.Comment, data *app.Comment) { HrefFunc := func(obj interface{}) string { return fmt.Sprintf(app.WorkitemHref("%v"), obj) } CommentIncludeParent(request, comment, data, HrefFunc, APIStringTypeWorkItem) } }
go
func CommentIncludeParentWorkItem(ctx context.Context, c *comment.Comment) CommentConvertFunc { return func(request *http.Request, comment *comment.Comment, data *app.Comment) { HrefFunc := func(obj interface{}) string { return fmt.Sprintf(app.WorkitemHref("%v"), obj) } CommentIncludeParent(request, comment, data, HrefFunc, APIStringTypeWorkItem) } }
[ "func", "CommentIncludeParentWorkItem", "(", "ctx", "context", ".", "Context", ",", "c", "*", "comment", ".", "Comment", ")", "CommentConvertFunc", "{", "return", "func", "(", "request", "*", "http", ".", "Request", ",", "comment", "*", "comment", ".", "Comment", ",", "data", "*", "app", ".", "Comment", ")", "{", "HrefFunc", ":=", "func", "(", "obj", "interface", "{", "}", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "app", ".", "WorkitemHref", "(", "\"", "\"", ")", ",", "obj", ")", "\n", "}", "\n", "CommentIncludeParent", "(", "request", ",", "comment", ",", "data", ",", "HrefFunc", ",", "APIStringTypeWorkItem", ")", "\n", "}", "\n", "}" ]
// CommentIncludeParentWorkItem includes a "parent" relation to a WorkItem
[ "CommentIncludeParentWorkItem", "includes", "a", "parent", "relation", "to", "a", "WorkItem" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L266-L273
13,310
fabric8-services/fabric8-wit
controller/comments.go
CommentIncludeParent
func CommentIncludeParent(request *http.Request, comment *comment.Comment, data *app.Comment, href HrefFunc, parentType string) { data.Relationships.Parent = &app.RelationGeneric{ Data: &app.GenericData{ Type: &parentType, ID: ptr.String(comment.ParentID.String()), }, Links: &app.GenericLinks{ Self: ptr.String(rest.AbsoluteURL(request, href(comment.ParentID))), }, } }
go
func CommentIncludeParent(request *http.Request, comment *comment.Comment, data *app.Comment, href HrefFunc, parentType string) { data.Relationships.Parent = &app.RelationGeneric{ Data: &app.GenericData{ Type: &parentType, ID: ptr.String(comment.ParentID.String()), }, Links: &app.GenericLinks{ Self: ptr.String(rest.AbsoluteURL(request, href(comment.ParentID))), }, } }
[ "func", "CommentIncludeParent", "(", "request", "*", "http", ".", "Request", ",", "comment", "*", "comment", ".", "Comment", ",", "data", "*", "app", ".", "Comment", ",", "href", "HrefFunc", ",", "parentType", "string", ")", "{", "data", ".", "Relationships", ".", "Parent", "=", "&", "app", ".", "RelationGeneric", "{", "Data", ":", "&", "app", ".", "GenericData", "{", "Type", ":", "&", "parentType", ",", "ID", ":", "ptr", ".", "String", "(", "comment", ".", "ParentID", ".", "String", "(", ")", ")", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Self", ":", "ptr", ".", "String", "(", "rest", ".", "AbsoluteURL", "(", "request", ",", "href", "(", "comment", ".", "ParentID", ")", ")", ")", ",", "}", ",", "}", "\n", "}" ]
// CommentIncludeParent adds the "parent" relationship to this Comment
[ "CommentIncludeParent", "adds", "the", "parent", "relationship", "to", "this", "Comment" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/comments.go#L276-L286
13,311
fabric8-services/fabric8-wit
rest/http.go
Do
func (d *HttpClientDoer) Do(ctx context.Context, req *http.Request) (*http.Response, error) { return d.HttpClient.Do(req) }
go
func (d *HttpClientDoer) Do(ctx context.Context, req *http.Request) (*http.Response, error) { return d.HttpClient.Do(req) }
[ "func", "(", "d", "*", "HttpClientDoer", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "return", "d", ".", "HttpClient", ".", "Do", "(", "req", ")", "\n", "}" ]
// Do overrides Do method of the default goa client Doer. It's needed for mocking http clients in tests.
[ "Do", "overrides", "Do", "method", "of", "the", "default", "goa", "client", "Doer", ".", "It", "s", "needed", "for", "mocking", "http", "clients", "in", "tests", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/rest/http.go#L31-L33
13,312
fabric8-services/fabric8-wit
controller/user.go
ListSpaces
func (c *UserController) ListSpaces(ctx *app.ListSpacesUserContext) error { client, err := newAuthClient(ctx, c.config, c.httpOptions...) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } res, err := client.ListResourcesUser(goasupport.ForwardContextRequestID(ctx), authservice.ListResourcesUserPath(), authorization.ResourceTypeSpace) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err.Error(), }, "unable to get spaces with a role from the auth service") return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to get spaces with a role from the auth service")) } defer rest.CloseResponse(res) switch res.StatusCode { case 200: // OK case 401: return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(rest.ReadBody(res.Body))) default: return jsonapi.JSONErrorResponse(ctx, errors.NewInternalError(ctx, errs.Errorf("status: %s, body: %s", res.Status, rest.ReadBody(res.Body)))) } spaces, err := client.DecodeUserResourcesList(res) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err.Error(), }, "unable to decode spaces with a role from the auth service") return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to decode spaces with a role from the auth service")) } result, err := convertToUserSpaces(ctx, ctx.Request, c.db, spaces) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err.Error(), }, "unable to returns spaces with a role from the auth service") return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to return spaces with a role from the auth service")) } return ctx.OK(result) }
go
func (c *UserController) ListSpaces(ctx *app.ListSpacesUserContext) error { client, err := newAuthClient(ctx, c.config, c.httpOptions...) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } res, err := client.ListResourcesUser(goasupport.ForwardContextRequestID(ctx), authservice.ListResourcesUserPath(), authorization.ResourceTypeSpace) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err.Error(), }, "unable to get spaces with a role from the auth service") return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to get spaces with a role from the auth service")) } defer rest.CloseResponse(res) switch res.StatusCode { case 200: // OK case 401: return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(rest.ReadBody(res.Body))) default: return jsonapi.JSONErrorResponse(ctx, errors.NewInternalError(ctx, errs.Errorf("status: %s, body: %s", res.Status, rest.ReadBody(res.Body)))) } spaces, err := client.DecodeUserResourcesList(res) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err.Error(), }, "unable to decode spaces with a role from the auth service") return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to decode spaces with a role from the auth service")) } result, err := convertToUserSpaces(ctx, ctx.Request, c.db, spaces) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err.Error(), }, "unable to returns spaces with a role from the auth service") return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to return spaces with a role from the auth service")) } return ctx.OK(result) }
[ "func", "(", "c", "*", "UserController", ")", "ListSpaces", "(", "ctx", "*", "app", ".", "ListSpacesUserContext", ")", "error", "{", "client", ",", "err", ":=", "newAuthClient", "(", "ctx", ",", "c", ".", "config", ",", "c", ".", "httpOptions", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "res", ",", "err", ":=", "client", ".", "ListResourcesUser", "(", "goasupport", ".", "ForwardContextRequestID", "(", "ctx", ")", ",", "authservice", ".", "ListResourcesUserPath", "(", ")", ",", "authorization", ".", "ResourceTypeSpace", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", ",", "}", ",", "\"", "\"", ")", "\n", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "defer", "rest", ".", "CloseResponse", "(", "res", ")", "\n\n", "switch", "res", ".", "StatusCode", "{", "case", "200", ":", "// OK", "case", "401", ":", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewUnauthorizedError", "(", "rest", ".", "ReadBody", "(", "res", ".", "Body", ")", ")", ")", "\n", "default", ":", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "errs", ".", "Errorf", "(", "\"", "\"", ",", "res", ".", "Status", ",", "rest", ".", "ReadBody", "(", "res", ".", "Body", ")", ")", ")", ")", "\n", "}", "\n\n", "spaces", ",", "err", ":=", "client", ".", "DecodeUserResourcesList", "(", "res", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", ",", "}", ",", "\"", "\"", ")", "\n", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "result", ",", "err", ":=", "convertToUserSpaces", "(", "ctx", ",", "ctx", ".", "Request", ",", "c", ".", "db", ",", "spaces", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", ",", "}", ",", "\"", "\"", ")", "\n", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "return", "ctx", ".", "OK", "(", "result", ")", "\n", "}" ]
// ListSpaces returns the list of spaces in which the user has a role
[ "ListSpaces", "returns", "the", "list", "of", "spaces", "in", "which", "the", "user", "has", "a", "role" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/user.go#L118-L156
13,313
fabric8-services/fabric8-wit
spacetemplate/template.go
Equal
func (s SpaceTemplate) Equal(u convert.Equaler) bool { other, ok := u.(SpaceTemplate) if !ok { return false } if !uuid.Equal(s.ID, other.ID) { return false } if s.Name != other.Name { return false } if s.Version != other.Version { return false } if !convert.CascadeEqual(s.Lifecycle, other.Lifecycle) { return false } if s.CanConstruct != other.CanConstruct { return false } if !reflect.DeepEqual(s.Description, other.Description) { return false } return true }
go
func (s SpaceTemplate) Equal(u convert.Equaler) bool { other, ok := u.(SpaceTemplate) if !ok { return false } if !uuid.Equal(s.ID, other.ID) { return false } if s.Name != other.Name { return false } if s.Version != other.Version { return false } if !convert.CascadeEqual(s.Lifecycle, other.Lifecycle) { return false } if s.CanConstruct != other.CanConstruct { return false } if !reflect.DeepEqual(s.Description, other.Description) { return false } return true }
[ "func", "(", "s", "SpaceTemplate", ")", "Equal", "(", "u", "convert", ".", "Equaler", ")", "bool", "{", "other", ",", "ok", ":=", "u", ".", "(", "SpaceTemplate", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "if", "!", "uuid", ".", "Equal", "(", "s", ".", "ID", ",", "other", ".", "ID", ")", "{", "return", "false", "\n", "}", "\n", "if", "s", ".", "Name", "!=", "other", ".", "Name", "{", "return", "false", "\n", "}", "\n", "if", "s", ".", "Version", "!=", "other", ".", "Version", "{", "return", "false", "\n", "}", "\n", "if", "!", "convert", ".", "CascadeEqual", "(", "s", ".", "Lifecycle", ",", "other", ".", "Lifecycle", ")", "{", "return", "false", "\n", "}", "\n", "if", "s", ".", "CanConstruct", "!=", "other", ".", "CanConstruct", "{", "return", "false", "\n", "}", "\n", "if", "!", "reflect", ".", "DeepEqual", "(", "s", ".", "Description", ",", "other", ".", "Description", ")", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns true if two SpaceTemplate objects are equal; otherwise false is // returned.
[ "Equal", "returns", "true", "if", "two", "SpaceTemplate", "objects", "are", "equal", ";", "otherwise", "false", "is", "returned", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/template.go#L69-L93
13,314
fabric8-services/fabric8-wit
errors/errors.go
FromStatusCode
func FromStatusCode(statusCode int, format string, args ...interface{}) error { msg := fmt.Sprintf(format, args...) switch statusCode { case http.StatusNotFound: return NewNotFoundErrorFromString(msg) case http.StatusBadRequest: return NewBadParameterErrorFromString(msg) case http.StatusConflict: return NewVersionConflictError(msg) case http.StatusUnauthorized: return NewUnauthorizedError(msg) case http.StatusForbidden: return NewForbiddenError(msg) default: return NewInternalErrorFromString(msg) } }
go
func FromStatusCode(statusCode int, format string, args ...interface{}) error { msg := fmt.Sprintf(format, args...) switch statusCode { case http.StatusNotFound: return NewNotFoundErrorFromString(msg) case http.StatusBadRequest: return NewBadParameterErrorFromString(msg) case http.StatusConflict: return NewVersionConflictError(msg) case http.StatusUnauthorized: return NewUnauthorizedError(msg) case http.StatusForbidden: return NewForbiddenError(msg) default: return NewInternalErrorFromString(msg) } }
[ "func", "FromStatusCode", "(", "statusCode", "int", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", "\n", "switch", "statusCode", "{", "case", "http", ".", "StatusNotFound", ":", "return", "NewNotFoundErrorFromString", "(", "msg", ")", "\n", "case", "http", ".", "StatusBadRequest", ":", "return", "NewBadParameterErrorFromString", "(", "msg", ")", "\n", "case", "http", ".", "StatusConflict", ":", "return", "NewVersionConflictError", "(", "msg", ")", "\n", "case", "http", ".", "StatusUnauthorized", ":", "return", "NewUnauthorizedError", "(", "msg", ")", "\n", "case", "http", ".", "StatusForbidden", ":", "return", "NewForbiddenError", "(", "msg", ")", "\n", "default", ":", "return", "NewInternalErrorFromString", "(", "msg", ")", "\n", "}", "\n", "}" ]
// FromStatusCode returns an error from the given HTTP status code, using the message and args
[ "FromStatusCode", "returns", "an", "error", "from", "the", "given", "HTTP", "status", "code", "using", "the", "message", "and", "args" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L25-L41
13,315
fabric8-services/fabric8-wit
errors/errors.go
IsInternalError
func IsInternalError(err error) (bool, error) { e, ok := errs.Cause(err).(InternalError) if !ok { return false, nil } return true, e }
go
func IsInternalError(err error) (bool, error) { e, ok := errs.Cause(err).(InternalError) if !ok { return false, nil } return true, e }
[ "func", "IsInternalError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "InternalError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsInternalError returns true if the cause of the given error can be // converted to an InternalError, which is returned as the second result.
[ "IsInternalError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "InternalError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L63-L69
13,316
fabric8-services/fabric8-wit
errors/errors.go
IsUnauthorizedError
func IsUnauthorizedError(err error) (bool, error) { e, ok := errs.Cause(err).(UnauthorizedError) if !ok { return false, nil } return true, e }
go
func IsUnauthorizedError(err error) (bool, error) { e, ok := errs.Cause(err).(UnauthorizedError) if !ok { return false, nil } return true, e }
[ "func", "IsUnauthorizedError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "UnauthorizedError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsUnauthorizedError returns true if the cause of the given error can be // converted to an UnauthorizedError, which is returned as the second result.
[ "IsUnauthorizedError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "UnauthorizedError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L78-L84
13,317
fabric8-services/fabric8-wit
errors/errors.go
IsForbiddenError
func IsForbiddenError(err error) (bool, error) { e, ok := errs.Cause(err).(ForbiddenError) if !ok { return false, nil } return true, e }
go
func IsForbiddenError(err error) (bool, error) { e, ok := errs.Cause(err).(ForbiddenError) if !ok { return false, nil } return true, e }
[ "func", "IsForbiddenError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "ForbiddenError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsForbiddenError returns true if the cause of the given error can be // converted to an ForbiddenError, which is returned as the second result.
[ "IsForbiddenError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "ForbiddenError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L93-L99
13,318
fabric8-services/fabric8-wit
errors/errors.go
IsDataConflictError
func IsDataConflictError(err error) (bool, error) { e, ok := errs.Cause(err).(DataConflictError) if !ok { return false, nil } return true, e }
go
func IsDataConflictError(err error) (bool, error) { e, ok := errs.Cause(err).(DataConflictError) if !ok { return false, nil } return true, e }
[ "func", "IsDataConflictError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "DataConflictError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsDataConflictError returns true if the cause of the given error can be // converted to an IsDataConflictError, which is returned as the second result.
[ "IsDataConflictError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "IsDataConflictError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L137-L143
13,319
fabric8-services/fabric8-wit
errors/errors.go
IsVersionConflictError
func IsVersionConflictError(err error) (bool, error) { e, ok := errs.Cause(err).(VersionConflictError) if !ok { return false, nil } return true, e }
go
func IsVersionConflictError(err error) (bool, error) { e, ok := errs.Cause(err).(VersionConflictError) if !ok { return false, nil } return true, e }
[ "func", "IsVersionConflictError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "VersionConflictError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsVersionConflictError returns true if the cause of the given error can be // converted to an VersionConflictError, which is returned as the second result.
[ "IsVersionConflictError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "VersionConflictError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L152-L158
13,320
fabric8-services/fabric8-wit
errors/errors.go
NewBadParameterError
func NewBadParameterError(param string, actual interface{}) BadParameterError { return BadParameterError{parameter: param, value: actual} }
go
func NewBadParameterError(param string, actual interface{}) BadParameterError { return BadParameterError{parameter: param, value: actual} }
[ "func", "NewBadParameterError", "(", "param", "string", ",", "actual", "interface", "{", "}", ")", "BadParameterError", "{", "return", "BadParameterError", "{", "parameter", ":", "param", ",", "value", ":", "actual", "}", "\n", "}" ]
// NewBadParameterError returns the custom defined error of type NewBadParameterError.
[ "NewBadParameterError", "returns", "the", "custom", "defined", "error", "of", "type", "NewBadParameterError", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L189-L191
13,321
fabric8-services/fabric8-wit
errors/errors.go
IsBadParameterError
func IsBadParameterError(err error) (bool, error) { e, ok := errs.Cause(err).(BadParameterError) if !ok { return false, nil } return true, e }
go
func IsBadParameterError(err error) (bool, error) { e, ok := errs.Cause(err).(BadParameterError) if !ok { return false, nil } return true, e }
[ "func", "IsBadParameterError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "BadParameterError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsBadParameterError returns true if the cause of the given error can be // converted to an BadParameterError, which is returned as the second result.
[ "IsBadParameterError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "BadParameterError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L200-L206
13,322
fabric8-services/fabric8-wit
errors/errors.go
IsConversionError
func IsConversionError(err error) (bool, error) { e, ok := errs.Cause(err).(ConversionError) if !ok { return false, nil } return true, e }
go
func IsConversionError(err error) (bool, error) { e, ok := errs.Cause(err).(ConversionError) if !ok { return false, nil } return true, e }
[ "func", "IsConversionError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "ConversionError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsConversionError returns true if the cause of the given error can be // converted to an ConversionError, which is returned as the second result.
[ "IsConversionError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "ConversionError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L215-L221
13,323
fabric8-services/fabric8-wit
errors/errors.go
IsNotFoundError
func IsNotFoundError(err error) (bool, error) { e, ok := errs.Cause(err).(NotFoundError) if !ok { return false, nil } return true, e }
go
func IsNotFoundError(err error) (bool, error) { e, ok := errs.Cause(err).(NotFoundError) if !ok { return false, nil } return true, e }
[ "func", "IsNotFoundError", "(", "err", "error", ")", "(", "bool", ",", "error", ")", "{", "e", ",", "ok", ":=", "errs", ".", "Cause", "(", "err", ")", ".", "(", "NotFoundError", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "e", "\n", "}" ]
// IsNotFoundError returns true if the cause of the given error can be // converted to an NotFoundError, which is returned as the second result.
[ "IsNotFoundError", "returns", "true", "if", "the", "cause", "of", "the", "given", "error", "can", "be", "converted", "to", "an", "NotFoundError", "which", "is", "returned", "as", "the", "second", "result", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/errors/errors.go#L254-L260
13,324
fabric8-services/fabric8-wit
account/context_information.go
Equal
func (f ContextInformation) Equal(u convert.Equaler) bool { other, ok := u.(ContextInformation) if !ok { return false } return reflect.DeepEqual(f, other) }
go
func (f ContextInformation) Equal(u convert.Equaler) bool { other, ok := u.(ContextInformation) if !ok { return false } return reflect.DeepEqual(f, other) }
[ "func", "(", "f", "ContextInformation", ")", "Equal", "(", "u", "convert", ".", "Equaler", ")", "bool", "{", "other", ",", "ok", ":=", "u", ".", "(", "ContextInformation", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "return", "reflect", ".", "DeepEqual", "(", "f", ",", "other", ")", "\n", "}" ]
// Equal returns true if two ContextInformation objects are equal; otherwise false is returned.
[ "Equal", "returns", "true", "if", "two", "ContextInformation", "objects", "are", "equal", ";", "otherwise", "false", "is", "returned", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/account/context_information.go#L20-L26
13,325
fabric8-services/fabric8-wit
controller/work_item_link.go
NewWorkItemLinkController
func NewWorkItemLinkController(service *goa.Service, db application.DB, config WorkItemLinkControllerConfig) *WorkItemLinkController { return &WorkItemLinkController{ Controller: service.NewController("WorkItemLinkController"), db: db, config: config, } }
go
func NewWorkItemLinkController(service *goa.Service, db application.DB, config WorkItemLinkControllerConfig) *WorkItemLinkController { return &WorkItemLinkController{ Controller: service.NewController("WorkItemLinkController"), db: db, config: config, } }
[ "func", "NewWorkItemLinkController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "WorkItemLinkControllerConfig", ")", "*", "WorkItemLinkController", "{", "return", "&", "WorkItemLinkController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "config", ":", "config", ",", "}", "\n", "}" ]
// NewWorkItemLinkController creates a work-item-link controller.
[ "NewWorkItemLinkController", "creates", "a", "work", "-", "item", "-", "link", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L35-L41
13,326
fabric8-services/fabric8-wit
controller/work_item_link.go
newWorkItemLinkContext
func newWorkItemLinkContext(ctx context.Context, service *goa.Service, appl application.Application, db application.DB, request *http.Request, responseWriter http.ResponseWriter, linkFunc hrefLinkFunc, currentUserIdentityID *uuid.UUID) *workItemLinkContext { return &workItemLinkContext{ Request: request, ResponseWriter: responseWriter, Application: appl, Context: ctx, Service: service, CurrentUserIdentityID: currentUserIdentityID, DB: db, LinkFunc: linkFunc, } }
go
func newWorkItemLinkContext(ctx context.Context, service *goa.Service, appl application.Application, db application.DB, request *http.Request, responseWriter http.ResponseWriter, linkFunc hrefLinkFunc, currentUserIdentityID *uuid.UUID) *workItemLinkContext { return &workItemLinkContext{ Request: request, ResponseWriter: responseWriter, Application: appl, Context: ctx, Service: service, CurrentUserIdentityID: currentUserIdentityID, DB: db, LinkFunc: linkFunc, } }
[ "func", "newWorkItemLinkContext", "(", "ctx", "context", ".", "Context", ",", "service", "*", "goa", ".", "Service", ",", "appl", "application", ".", "Application", ",", "db", "application", ".", "DB", ",", "request", "*", "http", ".", "Request", ",", "responseWriter", "http", ".", "ResponseWriter", ",", "linkFunc", "hrefLinkFunc", ",", "currentUserIdentityID", "*", "uuid", ".", "UUID", ")", "*", "workItemLinkContext", "{", "return", "&", "workItemLinkContext", "{", "Request", ":", "request", ",", "ResponseWriter", ":", "responseWriter", ",", "Application", ":", "appl", ",", "Context", ":", "ctx", ",", "Service", ":", "service", ",", "CurrentUserIdentityID", ":", "currentUserIdentityID", ",", "DB", ":", "db", ",", "LinkFunc", ":", "linkFunc", ",", "}", "\n", "}" ]
// newWorkItemLinkContext returns a new workItemLinkContext
[ "newWorkItemLinkContext", "returns", "a", "new", "workItemLinkContext" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L63-L74
13,327
fabric8-services/fabric8-wit
controller/work_item_link.go
getTypesOfLinks
func getTypesOfLinks(ctx context.Context, appl application.Application, req *http.Request, linksDataArr []*app.WorkItemLinkData) ([]*app.WorkItemLinkTypeData, error) { // Build our "set" of distinct type IDs idMap := map[uuid.UUID]struct{}{} idArr := []uuid.UUID{} for _, linkData := range linksDataArr { id := linkData.Relationships.LinkType.Data.ID if _, ok := idMap[id]; !ok { idMap[id] = struct{}{} idArr = append(idArr, id) } } // Now include the optional link type data in the work item link "included" array linkTypeModels := []link.WorkItemLinkType{} for _, typeID := range idArr { linkTypeModel, err := appl.WorkItemLinkTypes().Load(ctx, typeID) if err != nil { return nil, errs.WithStack(err) } linkTypeModels = append(linkTypeModels, *linkTypeModel) } appLinkTypes, err := ConvertLinkTypesFromModels(req, linkTypeModels) if err != nil { return nil, errs.WithStack(err) } return appLinkTypes.Data, nil }
go
func getTypesOfLinks(ctx context.Context, appl application.Application, req *http.Request, linksDataArr []*app.WorkItemLinkData) ([]*app.WorkItemLinkTypeData, error) { // Build our "set" of distinct type IDs idMap := map[uuid.UUID]struct{}{} idArr := []uuid.UUID{} for _, linkData := range linksDataArr { id := linkData.Relationships.LinkType.Data.ID if _, ok := idMap[id]; !ok { idMap[id] = struct{}{} idArr = append(idArr, id) } } // Now include the optional link type data in the work item link "included" array linkTypeModels := []link.WorkItemLinkType{} for _, typeID := range idArr { linkTypeModel, err := appl.WorkItemLinkTypes().Load(ctx, typeID) if err != nil { return nil, errs.WithStack(err) } linkTypeModels = append(linkTypeModels, *linkTypeModel) } appLinkTypes, err := ConvertLinkTypesFromModels(req, linkTypeModels) if err != nil { return nil, errs.WithStack(err) } return appLinkTypes.Data, nil }
[ "func", "getTypesOfLinks", "(", "ctx", "context", ".", "Context", ",", "appl", "application", ".", "Application", ",", "req", "*", "http", ".", "Request", ",", "linksDataArr", "[", "]", "*", "app", ".", "WorkItemLinkData", ")", "(", "[", "]", "*", "app", ".", "WorkItemLinkTypeData", ",", "error", ")", "{", "// Build our \"set\" of distinct type IDs", "idMap", ":=", "map", "[", "uuid", ".", "UUID", "]", "struct", "{", "}", "{", "}", "\n", "idArr", ":=", "[", "]", "uuid", ".", "UUID", "{", "}", "\n", "for", "_", ",", "linkData", ":=", "range", "linksDataArr", "{", "id", ":=", "linkData", ".", "Relationships", ".", "LinkType", ".", "Data", ".", "ID", "\n", "if", "_", ",", "ok", ":=", "idMap", "[", "id", "]", ";", "!", "ok", "{", "idMap", "[", "id", "]", "=", "struct", "{", "}", "{", "}", "\n", "idArr", "=", "append", "(", "idArr", ",", "id", ")", "\n", "}", "\n", "}", "\n\n", "// Now include the optional link type data in the work item link \"included\" array", "linkTypeModels", ":=", "[", "]", "link", ".", "WorkItemLinkType", "{", "}", "\n", "for", "_", ",", "typeID", ":=", "range", "idArr", "{", "linkTypeModel", ",", "err", ":=", "appl", ".", "WorkItemLinkTypes", "(", ")", ".", "Load", "(", "ctx", ",", "typeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "linkTypeModels", "=", "append", "(", "linkTypeModels", ",", "*", "linkTypeModel", ")", "\n", "}", "\n", "appLinkTypes", ",", "err", ":=", "ConvertLinkTypesFromModels", "(", "req", ",", "linkTypeModels", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "appLinkTypes", ".", "Data", ",", "nil", "\n", "}" ]
// getTypesOfLinks returns an array of distinct work item link types for the // given work item links
[ "getTypesOfLinks", "returns", "an", "array", "of", "distinct", "work", "item", "link", "types", "for", "the", "given", "work", "item", "links" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L78-L104
13,328
fabric8-services/fabric8-wit
controller/work_item_link.go
getWorkItemsOfLinks
func getWorkItemsOfLinks(ctx context.Context, appl application.Application, req *http.Request, linksDataArr []*app.WorkItemLinkData) ([]*app.WorkItem, error) { // Build our "set" of distinct work item IDs idMap := map[uuid.UUID]struct{}{} idArr := []uuid.UUID{} for _, linkData := range linksDataArr { src := linkData.Relationships.Source.Data.ID tgt := linkData.Relationships.Target.Data.ID if _, ok := idMap[src]; !ok { idMap[src] = struct{}{} idArr = append(idArr, src) } if _, ok := idMap[tgt]; !ok { idMap[tgt] = struct{}{} idArr = append(idArr, tgt) } } // Fetch all work items specified in the array res := []*app.WorkItem{} for _, id := range idArr { wi, err := appl.WorkItems().LoadByID(ctx, id) if err != nil { return nil, errs.WithStack(err) } wit, err := appl.WorkItemTypes().Load(ctx, wi.Type) if err != nil { return nil, errs.Wrapf(err, "failed to load work item type: %s", wi.Type) } converted, err := ConvertWorkItem(req, *wit, *wi) if err != nil { return nil, errs.WithStack(err) } res = append(res, converted) } return res, nil }
go
func getWorkItemsOfLinks(ctx context.Context, appl application.Application, req *http.Request, linksDataArr []*app.WorkItemLinkData) ([]*app.WorkItem, error) { // Build our "set" of distinct work item IDs idMap := map[uuid.UUID]struct{}{} idArr := []uuid.UUID{} for _, linkData := range linksDataArr { src := linkData.Relationships.Source.Data.ID tgt := linkData.Relationships.Target.Data.ID if _, ok := idMap[src]; !ok { idMap[src] = struct{}{} idArr = append(idArr, src) } if _, ok := idMap[tgt]; !ok { idMap[tgt] = struct{}{} idArr = append(idArr, tgt) } } // Fetch all work items specified in the array res := []*app.WorkItem{} for _, id := range idArr { wi, err := appl.WorkItems().LoadByID(ctx, id) if err != nil { return nil, errs.WithStack(err) } wit, err := appl.WorkItemTypes().Load(ctx, wi.Type) if err != nil { return nil, errs.Wrapf(err, "failed to load work item type: %s", wi.Type) } converted, err := ConvertWorkItem(req, *wit, *wi) if err != nil { return nil, errs.WithStack(err) } res = append(res, converted) } return res, nil }
[ "func", "getWorkItemsOfLinks", "(", "ctx", "context", ".", "Context", ",", "appl", "application", ".", "Application", ",", "req", "*", "http", ".", "Request", ",", "linksDataArr", "[", "]", "*", "app", ".", "WorkItemLinkData", ")", "(", "[", "]", "*", "app", ".", "WorkItem", ",", "error", ")", "{", "// Build our \"set\" of distinct work item IDs", "idMap", ":=", "map", "[", "uuid", ".", "UUID", "]", "struct", "{", "}", "{", "}", "\n", "idArr", ":=", "[", "]", "uuid", ".", "UUID", "{", "}", "\n", "for", "_", ",", "linkData", ":=", "range", "linksDataArr", "{", "src", ":=", "linkData", ".", "Relationships", ".", "Source", ".", "Data", ".", "ID", "\n", "tgt", ":=", "linkData", ".", "Relationships", ".", "Target", ".", "Data", ".", "ID", "\n", "if", "_", ",", "ok", ":=", "idMap", "[", "src", "]", ";", "!", "ok", "{", "idMap", "[", "src", "]", "=", "struct", "{", "}", "{", "}", "\n", "idArr", "=", "append", "(", "idArr", ",", "src", ")", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "idMap", "[", "tgt", "]", ";", "!", "ok", "{", "idMap", "[", "tgt", "]", "=", "struct", "{", "}", "{", "}", "\n", "idArr", "=", "append", "(", "idArr", ",", "tgt", ")", "\n", "}", "\n", "}", "\n\n", "// Fetch all work items specified in the array", "res", ":=", "[", "]", "*", "app", ".", "WorkItem", "{", "}", "\n", "for", "_", ",", "id", ":=", "range", "idArr", "{", "wi", ",", "err", ":=", "appl", ".", "WorkItems", "(", ")", ".", "LoadByID", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "wit", ",", "err", ":=", "appl", ".", "WorkItemTypes", "(", ")", ".", "Load", "(", "ctx", ",", "wi", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "wi", ".", "Type", ")", "\n", "}", "\n", "converted", ",", "err", ":=", "ConvertWorkItem", "(", "req", ",", "*", "wit", ",", "*", "wi", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "res", "=", "append", "(", "res", ",", "converted", ")", "\n", "}", "\n", "return", "res", ",", "nil", "\n", "}" ]
// getWorkItemsOfLinks returns an array of distinct work items as they appear as // source or target in the given work item links.
[ "getWorkItemsOfLinks", "returns", "an", "array", "of", "distinct", "work", "items", "as", "they", "appear", "as", "source", "or", "target", "in", "the", "given", "work", "item", "links", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L108-L143
13,329
fabric8-services/fabric8-wit
controller/work_item_link.go
enrichLinkSingle
func enrichLinkSingle(ctx context.Context, appl application.Application, req *http.Request, appLinks *app.WorkItemLinkSingle) error { // Include link type //modelLinkType, err := ctx.Application.WorkItemLinkTypes().Load(ctx.Context, appLinks.Data.Relationships.LinkType.Data.ID) modelLinkType, err := appl.WorkItemLinkTypes().Load(ctx, appLinks.Data.Relationships.LinkType.Data.ID) if err != nil { return errs.WithStack(err) } appLinkType := ConvertWorkItemLinkTypeFromModel(req, *modelLinkType) appLinks.Included = append(appLinks.Included, appLinkType.Data) // Include source work item sourceWi, err := appl.WorkItems().LoadByID(ctx, appLinks.Data.Relationships.Source.Data.ID) if err != nil { return errs.WithStack(err) } sourceWIT, err := appl.WorkItemTypes().Load(ctx, sourceWi.Type) if err != nil { return errs.WithStack(err) } convertedSource, err := ConvertWorkItem(req, *sourceWIT, *sourceWi) if err != nil { return errs.WithStack(err) } appLinks.Included = append(appLinks.Included, convertedSource) // Include target work item targetWi, err := appl.WorkItems().LoadByID(ctx, appLinks.Data.Relationships.Target.Data.ID) if err != nil { return errs.WithStack(err) } targetWIT, err := appl.WorkItemTypes().Load(ctx, targetWi.Type) if err != nil { return errs.WithStack(err) } convertedTarget, err := ConvertWorkItem(req, *targetWIT, *targetWi) if err != nil { return errs.WithStack(err) } appLinks.Included = append(appLinks.Included, convertedTarget) return nil }
go
func enrichLinkSingle(ctx context.Context, appl application.Application, req *http.Request, appLinks *app.WorkItemLinkSingle) error { // Include link type //modelLinkType, err := ctx.Application.WorkItemLinkTypes().Load(ctx.Context, appLinks.Data.Relationships.LinkType.Data.ID) modelLinkType, err := appl.WorkItemLinkTypes().Load(ctx, appLinks.Data.Relationships.LinkType.Data.ID) if err != nil { return errs.WithStack(err) } appLinkType := ConvertWorkItemLinkTypeFromModel(req, *modelLinkType) appLinks.Included = append(appLinks.Included, appLinkType.Data) // Include source work item sourceWi, err := appl.WorkItems().LoadByID(ctx, appLinks.Data.Relationships.Source.Data.ID) if err != nil { return errs.WithStack(err) } sourceWIT, err := appl.WorkItemTypes().Load(ctx, sourceWi.Type) if err != nil { return errs.WithStack(err) } convertedSource, err := ConvertWorkItem(req, *sourceWIT, *sourceWi) if err != nil { return errs.WithStack(err) } appLinks.Included = append(appLinks.Included, convertedSource) // Include target work item targetWi, err := appl.WorkItems().LoadByID(ctx, appLinks.Data.Relationships.Target.Data.ID) if err != nil { return errs.WithStack(err) } targetWIT, err := appl.WorkItemTypes().Load(ctx, targetWi.Type) if err != nil { return errs.WithStack(err) } convertedTarget, err := ConvertWorkItem(req, *targetWIT, *targetWi) if err != nil { return errs.WithStack(err) } appLinks.Included = append(appLinks.Included, convertedTarget) return nil }
[ "func", "enrichLinkSingle", "(", "ctx", "context", ".", "Context", ",", "appl", "application", ".", "Application", ",", "req", "*", "http", ".", "Request", ",", "appLinks", "*", "app", ".", "WorkItemLinkSingle", ")", "error", "{", "// Include link type", "//modelLinkType, err := ctx.Application.WorkItemLinkTypes().Load(ctx.Context, appLinks.Data.Relationships.LinkType.Data.ID)", "modelLinkType", ",", "err", ":=", "appl", ".", "WorkItemLinkTypes", "(", ")", ".", "Load", "(", "ctx", ",", "appLinks", ".", "Data", ".", "Relationships", ".", "LinkType", ".", "Data", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "appLinkType", ":=", "ConvertWorkItemLinkTypeFromModel", "(", "req", ",", "*", "modelLinkType", ")", "\n", "appLinks", ".", "Included", "=", "append", "(", "appLinks", ".", "Included", ",", "appLinkType", ".", "Data", ")", "\n\n", "// Include source work item", "sourceWi", ",", "err", ":=", "appl", ".", "WorkItems", "(", ")", ".", "LoadByID", "(", "ctx", ",", "appLinks", ".", "Data", ".", "Relationships", ".", "Source", ".", "Data", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "sourceWIT", ",", "err", ":=", "appl", ".", "WorkItemTypes", "(", ")", ".", "Load", "(", "ctx", ",", "sourceWi", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "convertedSource", ",", "err", ":=", "ConvertWorkItem", "(", "req", ",", "*", "sourceWIT", ",", "*", "sourceWi", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "appLinks", ".", "Included", "=", "append", "(", "appLinks", ".", "Included", ",", "convertedSource", ")", "\n\n", "// Include target work item", "targetWi", ",", "err", ":=", "appl", ".", "WorkItems", "(", ")", ".", "LoadByID", "(", "ctx", ",", "appLinks", ".", "Data", ".", "Relationships", ".", "Target", ".", "Data", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "targetWIT", ",", "err", ":=", "appl", ".", "WorkItemTypes", "(", ")", ".", "Load", "(", "ctx", ",", "targetWi", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "convertedTarget", ",", "err", ":=", "ConvertWorkItem", "(", "req", ",", "*", "targetWIT", ",", "*", "targetWi", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "appLinks", ".", "Included", "=", "append", "(", "appLinks", ".", "Included", ",", "convertedTarget", ")", "\n", "return", "nil", "\n", "}" ]
// enrichLinkSingle includes related resources in the link's "included" array
[ "enrichLinkSingle", "includes", "related", "resources", "in", "the", "link", "s", "included", "array" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L146-L186
13,330
fabric8-services/fabric8-wit
controller/work_item_link.go
enrichLinkList
func enrichLinkList(ctx context.Context, appl application.Application, req *http.Request, linkArr *app.WorkItemLinkList) error { // include link types typeDataArr, err := getTypesOfLinks(ctx, appl, req, linkArr.Data) if err != nil { return errs.WithStack(err) } // Convert slice of objects to slice of interface (see https://golang.org/doc/faq#convert_slice_of_interface) interfaceArr := make([]interface{}, len(typeDataArr)) for i, v := range typeDataArr { interfaceArr[i] = v } linkArr.Included = append(linkArr.Included, interfaceArr...) // TODO(kwk): Include WIs from source and target? workItemDataArr, err := getWorkItemsOfLinks(ctx, appl, req, linkArr.Data) if err != nil { return err } // Convert slice of objects to slice of interface (see https://golang.org/doc/faq#convert_slice_of_interface) interfaceArr = make([]interface{}, len(workItemDataArr)) for i, v := range workItemDataArr { interfaceArr[i] = v } linkArr.Included = append(linkArr.Included, interfaceArr...) return nil }
go
func enrichLinkList(ctx context.Context, appl application.Application, req *http.Request, linkArr *app.WorkItemLinkList) error { // include link types typeDataArr, err := getTypesOfLinks(ctx, appl, req, linkArr.Data) if err != nil { return errs.WithStack(err) } // Convert slice of objects to slice of interface (see https://golang.org/doc/faq#convert_slice_of_interface) interfaceArr := make([]interface{}, len(typeDataArr)) for i, v := range typeDataArr { interfaceArr[i] = v } linkArr.Included = append(linkArr.Included, interfaceArr...) // TODO(kwk): Include WIs from source and target? workItemDataArr, err := getWorkItemsOfLinks(ctx, appl, req, linkArr.Data) if err != nil { return err } // Convert slice of objects to slice of interface (see https://golang.org/doc/faq#convert_slice_of_interface) interfaceArr = make([]interface{}, len(workItemDataArr)) for i, v := range workItemDataArr { interfaceArr[i] = v } linkArr.Included = append(linkArr.Included, interfaceArr...) return nil }
[ "func", "enrichLinkList", "(", "ctx", "context", ".", "Context", ",", "appl", "application", ".", "Application", ",", "req", "*", "http", ".", "Request", ",", "linkArr", "*", "app", ".", "WorkItemLinkList", ")", "error", "{", "// include link types", "typeDataArr", ",", "err", ":=", "getTypesOfLinks", "(", "ctx", ",", "appl", ",", "req", ",", "linkArr", ".", "Data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "// Convert slice of objects to slice of interface (see https://golang.org/doc/faq#convert_slice_of_interface)", "interfaceArr", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "typeDataArr", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "typeDataArr", "{", "interfaceArr", "[", "i", "]", "=", "v", "\n", "}", "\n", "linkArr", ".", "Included", "=", "append", "(", "linkArr", ".", "Included", ",", "interfaceArr", "...", ")", "\n\n", "// TODO(kwk): Include WIs from source and target?", "workItemDataArr", ",", "err", ":=", "getWorkItemsOfLinks", "(", "ctx", ",", "appl", ",", "req", ",", "linkArr", ".", "Data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// Convert slice of objects to slice of interface (see https://golang.org/doc/faq#convert_slice_of_interface)", "interfaceArr", "=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "workItemDataArr", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "workItemDataArr", "{", "interfaceArr", "[", "i", "]", "=", "v", "\n", "}", "\n", "linkArr", ".", "Included", "=", "append", "(", "linkArr", ".", "Included", ",", "interfaceArr", "...", ")", "\n", "return", "nil", "\n", "}" ]
// enrichLinkList includes related resources in the linkArr's "included" element
[ "enrichLinkList", "includes", "related", "resources", "in", "the", "linkArr", "s", "included", "element" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L189-L214
13,331
fabric8-services/fabric8-wit
controller/work_item_link.go
Delete
func (c *WorkItemLinkController) Delete(ctx *app.DeleteWorkItemLinkContext) error { currentUserIdentityID, err := login.ContextIdentity(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error())) } authorized, err := c.checkIfUserIsSpaceCollaboratorOrWorkItemCreator(ctx, ctx.LinkID, *currentUserIdentityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } if !authorized { return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not authorized to delete the link")) } err = application.Transactional(c.db, func(appl application.Application) error { return appl.WorkItemLinks().Delete(ctx.Context, ctx.LinkID, *currentUserIdentityID) }) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
go
func (c *WorkItemLinkController) Delete(ctx *app.DeleteWorkItemLinkContext) error { currentUserIdentityID, err := login.ContextIdentity(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error())) } authorized, err := c.checkIfUserIsSpaceCollaboratorOrWorkItemCreator(ctx, ctx.LinkID, *currentUserIdentityID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } if !authorized { return jsonapi.JSONErrorResponse(ctx, errors.NewForbiddenError("user is not authorized to delete the link")) } err = application.Transactional(c.db, func(appl application.Application) error { return appl.WorkItemLinks().Delete(ctx.Context, ctx.LinkID, *currentUserIdentityID) }) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
[ "func", "(", "c", "*", "WorkItemLinkController", ")", "Delete", "(", "ctx", "*", "app", ".", "DeleteWorkItemLinkContext", ")", "error", "{", "currentUserIdentityID", ",", "err", ":=", "login", ".", "ContextIdentity", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewUnauthorizedError", "(", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "authorized", ",", "err", ":=", "c", ".", "checkIfUserIsSpaceCollaboratorOrWorkItemCreator", "(", "ctx", ",", "ctx", ".", "LinkID", ",", "*", "currentUserIdentityID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "if", "!", "authorized", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewForbiddenError", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "err", "=", "application", ".", "Transactional", "(", "c", ".", "db", ",", "func", "(", "appl", "application", ".", "Application", ")", "error", "{", "return", "appl", ".", "WorkItemLinks", "(", ")", ".", "Delete", "(", "ctx", ".", "Context", ",", "ctx", ".", "LinkID", ",", "*", "currentUserIdentityID", ")", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ".", "OK", "(", "[", "]", "byte", "{", "}", ")", "\n", "}" ]
// // Delete runs the delete action
[ "Delete", "runs", "the", "delete", "action" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L310-L329
13,332
fabric8-services/fabric8-wit
controller/work_item_link.go
ConvertLinkFromModel
func ConvertLinkFromModel(request *http.Request, t link.WorkItemLink) app.WorkItemLinkSingle { linkSelfURL := rest.AbsoluteURL(request, app.WorkItemLinkHref(t.ID.String())) linkTypeRelatedURL := rest.AbsoluteURL(request, app.WorkItemLinkTypeHref(t.LinkTypeID.String())) sourceRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref(t.SourceID.String())) targetRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref(t.TargetID.String())) var converted = app.WorkItemLinkSingle{ Data: &app.WorkItemLinkData{ Type: link.EndpointWorkItemLinks, ID: &t.ID, Attributes: &app.WorkItemLinkAttributes{ CreatedAt: &t.CreatedAt, UpdatedAt: &t.UpdatedAt, Version: &t.Version, }, Links: &app.GenericLinks{ Self: &linkSelfURL, }, Relationships: &app.WorkItemLinkRelationships{ LinkType: &app.RelationWorkItemLinkType{ Data: &app.RelationWorkItemLinkTypeData{ Type: link.EndpointWorkItemLinkTypes, ID: t.LinkTypeID, }, Links: &app.GenericLinks{ Self: &linkTypeRelatedURL, }, }, Source: &app.RelationWorkItem{ Data: &app.RelationWorkItemData{ Type: link.EndpointWorkItems, ID: t.SourceID, }, Links: &app.GenericLinks{ Related: &sourceRelatedURL, }, }, Target: &app.RelationWorkItem{ Data: &app.RelationWorkItemData{ Type: link.EndpointWorkItems, ID: t.TargetID, }, Links: &app.GenericLinks{ Related: &targetRelatedURL, }, }, }, }, } return converted }
go
func ConvertLinkFromModel(request *http.Request, t link.WorkItemLink) app.WorkItemLinkSingle { linkSelfURL := rest.AbsoluteURL(request, app.WorkItemLinkHref(t.ID.String())) linkTypeRelatedURL := rest.AbsoluteURL(request, app.WorkItemLinkTypeHref(t.LinkTypeID.String())) sourceRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref(t.SourceID.String())) targetRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref(t.TargetID.String())) var converted = app.WorkItemLinkSingle{ Data: &app.WorkItemLinkData{ Type: link.EndpointWorkItemLinks, ID: &t.ID, Attributes: &app.WorkItemLinkAttributes{ CreatedAt: &t.CreatedAt, UpdatedAt: &t.UpdatedAt, Version: &t.Version, }, Links: &app.GenericLinks{ Self: &linkSelfURL, }, Relationships: &app.WorkItemLinkRelationships{ LinkType: &app.RelationWorkItemLinkType{ Data: &app.RelationWorkItemLinkTypeData{ Type: link.EndpointWorkItemLinkTypes, ID: t.LinkTypeID, }, Links: &app.GenericLinks{ Self: &linkTypeRelatedURL, }, }, Source: &app.RelationWorkItem{ Data: &app.RelationWorkItemData{ Type: link.EndpointWorkItems, ID: t.SourceID, }, Links: &app.GenericLinks{ Related: &sourceRelatedURL, }, }, Target: &app.RelationWorkItem{ Data: &app.RelationWorkItemData{ Type: link.EndpointWorkItems, ID: t.TargetID, }, Links: &app.GenericLinks{ Related: &targetRelatedURL, }, }, }, }, } return converted }
[ "func", "ConvertLinkFromModel", "(", "request", "*", "http", ".", "Request", ",", "t", "link", ".", "WorkItemLink", ")", "app", ".", "WorkItemLinkSingle", "{", "linkSelfURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "WorkItemLinkHref", "(", "t", ".", "ID", ".", "String", "(", ")", ")", ")", "\n", "linkTypeRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "WorkItemLinkTypeHref", "(", "t", ".", "LinkTypeID", ".", "String", "(", ")", ")", ")", "\n\n", "sourceRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "WorkitemHref", "(", "t", ".", "SourceID", ".", "String", "(", ")", ")", ")", "\n", "targetRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "WorkitemHref", "(", "t", ".", "TargetID", ".", "String", "(", ")", ")", ")", "\n\n", "var", "converted", "=", "app", ".", "WorkItemLinkSingle", "{", "Data", ":", "&", "app", ".", "WorkItemLinkData", "{", "Type", ":", "link", ".", "EndpointWorkItemLinks", ",", "ID", ":", "&", "t", ".", "ID", ",", "Attributes", ":", "&", "app", ".", "WorkItemLinkAttributes", "{", "CreatedAt", ":", "&", "t", ".", "CreatedAt", ",", "UpdatedAt", ":", "&", "t", ".", "UpdatedAt", ",", "Version", ":", "&", "t", ".", "Version", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Self", ":", "&", "linkSelfURL", ",", "}", ",", "Relationships", ":", "&", "app", ".", "WorkItemLinkRelationships", "{", "LinkType", ":", "&", "app", ".", "RelationWorkItemLinkType", "{", "Data", ":", "&", "app", ".", "RelationWorkItemLinkTypeData", "{", "Type", ":", "link", ".", "EndpointWorkItemLinkTypes", ",", "ID", ":", "t", ".", "LinkTypeID", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Self", ":", "&", "linkTypeRelatedURL", ",", "}", ",", "}", ",", "Source", ":", "&", "app", ".", "RelationWorkItem", "{", "Data", ":", "&", "app", ".", "RelationWorkItemData", "{", "Type", ":", "link", ".", "EndpointWorkItems", ",", "ID", ":", "t", ".", "SourceID", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Related", ":", "&", "sourceRelatedURL", ",", "}", ",", "}", ",", "Target", ":", "&", "app", ".", "RelationWorkItem", "{", "Data", ":", "&", "app", ".", "RelationWorkItemData", "{", "Type", ":", "link", ".", "EndpointWorkItems", ",", "ID", ":", "t", ".", "TargetID", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Related", ":", "&", "targetRelatedURL", ",", "}", ",", "}", ",", "}", ",", "}", ",", "}", "\n", "return", "converted", "\n", "}" ]
// ConvertLinkFromModel converts a work item from model to REST representation
[ "ConvertLinkFromModel", "converts", "a", "work", "item", "from", "model", "to", "REST", "representation" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_link.go#L353-L404
13,333
fabric8-services/fabric8-wit
controller/workitemtype.go
NewWorkitemtypeController
func NewWorkitemtypeController(service *goa.Service, db application.DB, config workItemTypeControllerConfiguration) *WorkitemtypeController { return &WorkitemtypeController{ Controller: service.NewController("WorkitemtypeController"), db: db, config: config, } }
go
func NewWorkitemtypeController(service *goa.Service, db application.DB, config workItemTypeControllerConfiguration) *WorkitemtypeController { return &WorkitemtypeController{ Controller: service.NewController("WorkitemtypeController"), db: db, config: config, } }
[ "func", "NewWorkitemtypeController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "workItemTypeControllerConfiguration", ")", "*", "WorkitemtypeController", "{", "return", "&", "WorkitemtypeController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "config", ":", "config", ",", "}", "\n", "}" ]
// NewWorkitemtypeController creates a workitemtype controller.
[ "NewWorkitemtypeController", "creates", "a", "workitemtype", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/workitemtype.go#L31-L37
13,334
fabric8-services/fabric8-wit
controller/workitemtype.go
ConvertWorkItemTypeFromModel
func ConvertWorkItemTypeFromModel(request *http.Request, t *workitem.WorkItemType) app.WorkItemTypeData { spaceTemplateRelatedURL := rest.AbsoluteURL(request, app.SpaceTemplateHref(t.SpaceTemplateID.String())) spaceRelatedURL := rest.AbsoluteURL(request, app.SpaceHref(space.SystemSpace.String())) var converted = app.WorkItemTypeData{ Type: APIStringTypeWorkItemType, ID: ptr.UUID(t.ID), Attributes: &app.WorkItemTypeAttributes{ CreatedAt: ptr.Time(t.CreatedAt.UTC()), UpdatedAt: ptr.Time(t.UpdatedAt.UTC()), Version: &t.Version, Description: t.Description, Icon: t.Icon, Name: t.Name, Fields: map[string]*app.FieldDefinition{}, CanConstruct: ptr.Bool(t.CanConstruct), }, Relationships: &app.WorkItemTypeRelationships{ // TODO(kwk): The Space relationship should be deprecated after clients adopted Space: app.NewSpaceRelation(space.SystemSpace, spaceRelatedURL), SpaceTemplate: app.NewSpaceTemplateRelation(t.SpaceTemplateID, spaceTemplateRelatedURL), }, } for name, def := range t.Fields { ct := ConvertFieldTypeFromModel(def.Type) converted.Attributes.Fields[name] = &app.FieldDefinition{ Required: def.Required, Label: def.Label, Description: def.Description, Type: &ct, } } if len(t.ChildTypeIDs) > 0 { converted.Relationships.GuidedChildTypes = &app.RelationGenericList{ Data: make([]*app.GenericData, len(t.ChildTypeIDs)), } for i, id := range t.ChildTypeIDs { converted.Relationships.GuidedChildTypes.Data[i] = &app.GenericData{ ID: ptr.String(id.String()), Type: ptr.String(APIStringTypeWorkItemType), } } } return converted }
go
func ConvertWorkItemTypeFromModel(request *http.Request, t *workitem.WorkItemType) app.WorkItemTypeData { spaceTemplateRelatedURL := rest.AbsoluteURL(request, app.SpaceTemplateHref(t.SpaceTemplateID.String())) spaceRelatedURL := rest.AbsoluteURL(request, app.SpaceHref(space.SystemSpace.String())) var converted = app.WorkItemTypeData{ Type: APIStringTypeWorkItemType, ID: ptr.UUID(t.ID), Attributes: &app.WorkItemTypeAttributes{ CreatedAt: ptr.Time(t.CreatedAt.UTC()), UpdatedAt: ptr.Time(t.UpdatedAt.UTC()), Version: &t.Version, Description: t.Description, Icon: t.Icon, Name: t.Name, Fields: map[string]*app.FieldDefinition{}, CanConstruct: ptr.Bool(t.CanConstruct), }, Relationships: &app.WorkItemTypeRelationships{ // TODO(kwk): The Space relationship should be deprecated after clients adopted Space: app.NewSpaceRelation(space.SystemSpace, spaceRelatedURL), SpaceTemplate: app.NewSpaceTemplateRelation(t.SpaceTemplateID, spaceTemplateRelatedURL), }, } for name, def := range t.Fields { ct := ConvertFieldTypeFromModel(def.Type) converted.Attributes.Fields[name] = &app.FieldDefinition{ Required: def.Required, Label: def.Label, Description: def.Description, Type: &ct, } } if len(t.ChildTypeIDs) > 0 { converted.Relationships.GuidedChildTypes = &app.RelationGenericList{ Data: make([]*app.GenericData, len(t.ChildTypeIDs)), } for i, id := range t.ChildTypeIDs { converted.Relationships.GuidedChildTypes.Data[i] = &app.GenericData{ ID: ptr.String(id.String()), Type: ptr.String(APIStringTypeWorkItemType), } } } return converted }
[ "func", "ConvertWorkItemTypeFromModel", "(", "request", "*", "http", ".", "Request", ",", "t", "*", "workitem", ".", "WorkItemType", ")", "app", ".", "WorkItemTypeData", "{", "spaceTemplateRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "SpaceTemplateHref", "(", "t", ".", "SpaceTemplateID", ".", "String", "(", ")", ")", ")", "\n", "spaceRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "SpaceHref", "(", "space", ".", "SystemSpace", ".", "String", "(", ")", ")", ")", "\n", "var", "converted", "=", "app", ".", "WorkItemTypeData", "{", "Type", ":", "APIStringTypeWorkItemType", ",", "ID", ":", "ptr", ".", "UUID", "(", "t", ".", "ID", ")", ",", "Attributes", ":", "&", "app", ".", "WorkItemTypeAttributes", "{", "CreatedAt", ":", "ptr", ".", "Time", "(", "t", ".", "CreatedAt", ".", "UTC", "(", ")", ")", ",", "UpdatedAt", ":", "ptr", ".", "Time", "(", "t", ".", "UpdatedAt", ".", "UTC", "(", ")", ")", ",", "Version", ":", "&", "t", ".", "Version", ",", "Description", ":", "t", ".", "Description", ",", "Icon", ":", "t", ".", "Icon", ",", "Name", ":", "t", ".", "Name", ",", "Fields", ":", "map", "[", "string", "]", "*", "app", ".", "FieldDefinition", "{", "}", ",", "CanConstruct", ":", "ptr", ".", "Bool", "(", "t", ".", "CanConstruct", ")", ",", "}", ",", "Relationships", ":", "&", "app", ".", "WorkItemTypeRelationships", "{", "// TODO(kwk): The Space relationship should be deprecated after clients adopted", "Space", ":", "app", ".", "NewSpaceRelation", "(", "space", ".", "SystemSpace", ",", "spaceRelatedURL", ")", ",", "SpaceTemplate", ":", "app", ".", "NewSpaceTemplateRelation", "(", "t", ".", "SpaceTemplateID", ",", "spaceTemplateRelatedURL", ")", ",", "}", ",", "}", "\n", "for", "name", ",", "def", ":=", "range", "t", ".", "Fields", "{", "ct", ":=", "ConvertFieldTypeFromModel", "(", "def", ".", "Type", ")", "\n", "converted", ".", "Attributes", ".", "Fields", "[", "name", "]", "=", "&", "app", ".", "FieldDefinition", "{", "Required", ":", "def", ".", "Required", ",", "Label", ":", "def", ".", "Label", ",", "Description", ":", "def", ".", "Description", ",", "Type", ":", "&", "ct", ",", "}", "\n", "}", "\n", "if", "len", "(", "t", ".", "ChildTypeIDs", ")", ">", "0", "{", "converted", ".", "Relationships", ".", "GuidedChildTypes", "=", "&", "app", ".", "RelationGenericList", "{", "Data", ":", "make", "(", "[", "]", "*", "app", ".", "GenericData", ",", "len", "(", "t", ".", "ChildTypeIDs", ")", ")", ",", "}", "\n", "for", "i", ",", "id", ":=", "range", "t", ".", "ChildTypeIDs", "{", "converted", ".", "Relationships", ".", "GuidedChildTypes", ".", "Data", "[", "i", "]", "=", "&", "app", ".", "GenericData", "{", "ID", ":", "ptr", ".", "String", "(", "id", ".", "String", "(", ")", ")", ",", "Type", ":", "ptr", ".", "String", "(", "APIStringTypeWorkItemType", ")", ",", "}", "\n", "}", "\n", "}", "\n", "return", "converted", "\n", "}" ]
// ConvertWorkItemTypeFromModel converts from models to app representation
[ "ConvertWorkItemTypeFromModel", "converts", "from", "models", "to", "app", "representation" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/workitemtype.go#L59-L102
13,335
fabric8-services/fabric8-wit
controller/workitemtype.go
ConvertFieldTypeFromModel
func ConvertFieldTypeFromModel(t workitem.FieldType) app.FieldType { result := app.FieldType{} result.Kind = string(t.GetKind()) switch modelFieldType := t.(type) { case workitem.ListType: result.ComponentType = ptr.String(string(modelFieldType.ComponentType.GetKind())) if modelFieldType.DefaultValue != nil { result.DefaultValue = &modelFieldType.DefaultValue } case workitem.EnumType: result.BaseType = ptr.String(string(modelFieldType.BaseType.GetKind())) result.Values = modelFieldType.Values if modelFieldType.DefaultValue != nil { result.DefaultValue = &modelFieldType.DefaultValue } case workitem.SimpleType: if modelFieldType.DefaultValue != nil { result.DefaultValue = &modelFieldType.DefaultValue } } return result }
go
func ConvertFieldTypeFromModel(t workitem.FieldType) app.FieldType { result := app.FieldType{} result.Kind = string(t.GetKind()) switch modelFieldType := t.(type) { case workitem.ListType: result.ComponentType = ptr.String(string(modelFieldType.ComponentType.GetKind())) if modelFieldType.DefaultValue != nil { result.DefaultValue = &modelFieldType.DefaultValue } case workitem.EnumType: result.BaseType = ptr.String(string(modelFieldType.BaseType.GetKind())) result.Values = modelFieldType.Values if modelFieldType.DefaultValue != nil { result.DefaultValue = &modelFieldType.DefaultValue } case workitem.SimpleType: if modelFieldType.DefaultValue != nil { result.DefaultValue = &modelFieldType.DefaultValue } } return result }
[ "func", "ConvertFieldTypeFromModel", "(", "t", "workitem", ".", "FieldType", ")", "app", ".", "FieldType", "{", "result", ":=", "app", ".", "FieldType", "{", "}", "\n", "result", ".", "Kind", "=", "string", "(", "t", ".", "GetKind", "(", ")", ")", "\n", "switch", "modelFieldType", ":=", "t", ".", "(", "type", ")", "{", "case", "workitem", ".", "ListType", ":", "result", ".", "ComponentType", "=", "ptr", ".", "String", "(", "string", "(", "modelFieldType", ".", "ComponentType", ".", "GetKind", "(", ")", ")", ")", "\n", "if", "modelFieldType", ".", "DefaultValue", "!=", "nil", "{", "result", ".", "DefaultValue", "=", "&", "modelFieldType", ".", "DefaultValue", "\n", "}", "\n", "case", "workitem", ".", "EnumType", ":", "result", ".", "BaseType", "=", "ptr", ".", "String", "(", "string", "(", "modelFieldType", ".", "BaseType", ".", "GetKind", "(", ")", ")", ")", "\n", "result", ".", "Values", "=", "modelFieldType", ".", "Values", "\n", "if", "modelFieldType", ".", "DefaultValue", "!=", "nil", "{", "result", ".", "DefaultValue", "=", "&", "modelFieldType", ".", "DefaultValue", "\n", "}", "\n", "case", "workitem", ".", "SimpleType", ":", "if", "modelFieldType", ".", "DefaultValue", "!=", "nil", "{", "result", ".", "DefaultValue", "=", "&", "modelFieldType", ".", "DefaultValue", "\n", "}", "\n", "}", "\n\n", "return", "result", "\n", "}" ]
// converts the field type from model to app representation
[ "converts", "the", "field", "type", "from", "model", "to", "app", "representation" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/workitemtype.go#L105-L127
13,336
fabric8-services/fabric8-wit
area/area.go
MakeChildOf
func (m *Area) MakeChildOf(parent Area) { if m.ID == uuid.Nil { m.ID = uuid.NewV4() } m.Path = append(parent.Path, m.ID) }
go
func (m *Area) MakeChildOf(parent Area) { if m.ID == uuid.Nil { m.ID = uuid.NewV4() } m.Path = append(parent.Path, m.ID) }
[ "func", "(", "m", "*", "Area", ")", "MakeChildOf", "(", "parent", "Area", ")", "{", "if", "m", ".", "ID", "==", "uuid", ".", "Nil", "{", "m", ".", "ID", "=", "uuid", ".", "NewV4", "(", ")", "\n", "}", "\n", "m", ".", "Path", "=", "append", "(", "parent", ".", "Path", ",", "m", ".", "ID", ")", "\n", "}" ]
// MakeChildOf does all the path magic to make the current area a child of the // given parent area.
[ "MakeChildOf", "does", "all", "the", "path", "magic", "to", "make", "the", "current", "area", "a", "child", "of", "the", "given", "parent", "area", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/area/area.go#L37-L42
13,337
fabric8-services/fabric8-wit
area/area.go
LoadMultiple
func (m *GormAreaRepository) LoadMultiple(ctx context.Context, ids []uuid.UUID) ([]Area, error) { defer goa.MeasureSince([]string{"goa", "db", "Area", "getmultiple"}, time.Now()) var objs []Area if len(ids) == 0 { return objs, nil } for i := 0; i < len(ids); i++ { m.db = m.db.Or("id = ?", ids[i]) } tx := m.db.Find(&objs) if tx.Error != nil { return nil, errors.NewInternalError(ctx, tx.Error) } return objs, nil }
go
func (m *GormAreaRepository) LoadMultiple(ctx context.Context, ids []uuid.UUID) ([]Area, error) { defer goa.MeasureSince([]string{"goa", "db", "Area", "getmultiple"}, time.Now()) var objs []Area if len(ids) == 0 { return objs, nil } for i := 0; i < len(ids); i++ { m.db = m.db.Or("id = ?", ids[i]) } tx := m.db.Find(&objs) if tx.Error != nil { return nil, errors.NewInternalError(ctx, tx.Error) } return objs, nil }
[ "func", "(", "m", "*", "GormAreaRepository", ")", "LoadMultiple", "(", "ctx", "context", ".", "Context", ",", "ids", "[", "]", "uuid", ".", "UUID", ")", "(", "[", "]", "Area", ",", "error", ")", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "var", "objs", "[", "]", "Area", "\n", "if", "len", "(", "ids", ")", "==", "0", "{", "return", "objs", ",", "nil", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "ids", ")", ";", "i", "++", "{", "m", ".", "db", "=", "m", ".", "db", ".", "Or", "(", "\"", "\"", ",", "ids", "[", "i", "]", ")", "\n", "}", "\n", "tx", ":=", "m", ".", "db", ".", "Find", "(", "&", "objs", ")", "\n", "if", "tx", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "tx", ".", "Error", ")", "\n", "}", "\n", "return", "objs", ",", "nil", "\n", "}" ]
// Load multiple areas
[ "Load", "multiple", "areas" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/area/area.go#L151-L165
13,338
fabric8-services/fabric8-wit
area/area.go
ListChildren
func (m *GormAreaRepository) ListChildren(ctx context.Context, parentArea *Area) ([]Area, error) { defer goa.MeasureSince([]string{"goa", "db", "Area", "querychild"}, time.Now()) var objs []Area tx := m.db.Where("path ~ ($1 || '.*{1}')::lquery", parentArea.Path.Convert()).Find(&objs) if tx.RecordNotFound() { return nil, errors.NewNotFoundError("Area", parentArea.ID.String()) } if tx.Error != nil { return nil, errors.NewInternalError(ctx, tx.Error) } return objs, nil }
go
func (m *GormAreaRepository) ListChildren(ctx context.Context, parentArea *Area) ([]Area, error) { defer goa.MeasureSince([]string{"goa", "db", "Area", "querychild"}, time.Now()) var objs []Area tx := m.db.Where("path ~ ($1 || '.*{1}')::lquery", parentArea.Path.Convert()).Find(&objs) if tx.RecordNotFound() { return nil, errors.NewNotFoundError("Area", parentArea.ID.String()) } if tx.Error != nil { return nil, errors.NewInternalError(ctx, tx.Error) } return objs, nil }
[ "func", "(", "m", "*", "GormAreaRepository", ")", "ListChildren", "(", "ctx", "context", ".", "Context", ",", "parentArea", "*", "Area", ")", "(", "[", "]", "Area", ",", "error", ")", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "var", "objs", "[", "]", "Area", "\n\n", "tx", ":=", "m", ".", "db", ".", "Where", "(", "\"", "\"", ",", "parentArea", ".", "Path", ".", "Convert", "(", ")", ")", ".", "Find", "(", "&", "objs", ")", "\n", "if", "tx", ".", "RecordNotFound", "(", ")", "{", "return", "nil", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "parentArea", ".", "ID", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "tx", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "tx", ".", "Error", ")", "\n", "}", "\n", "return", "objs", ",", "nil", "\n", "}" ]
// ListChildren fetches all Areas belonging to a parent - list all child areas.
[ "ListChildren", "fetches", "all", "Areas", "belonging", "to", "a", "parent", "-", "list", "all", "child", "areas", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/area/area.go#L168-L180
13,339
fabric8-services/fabric8-wit
area/area.go
Root
func (m *GormAreaRepository) Root(ctx context.Context, spaceID uuid.UUID) (*Area, error) { defer goa.MeasureSince([]string{"goa", "db", "Area", "root"}, time.Now()) var rootArea []Area rootArea, err := m.Query(FilterBySpaceID(spaceID), func(db *gorm.DB) *gorm.DB { return db.Where("space_id = ? AND nlevel(path)=1", spaceID) }) if len(rootArea) != 1 { return nil, errors.NewInternalError(ctx, errs.Errorf("single Root area not found for space %s", spaceID)) } if err != nil { return nil, err } return &rootArea[0], nil }
go
func (m *GormAreaRepository) Root(ctx context.Context, spaceID uuid.UUID) (*Area, error) { defer goa.MeasureSince([]string{"goa", "db", "Area", "root"}, time.Now()) var rootArea []Area rootArea, err := m.Query(FilterBySpaceID(spaceID), func(db *gorm.DB) *gorm.DB { return db.Where("space_id = ? AND nlevel(path)=1", spaceID) }) if len(rootArea) != 1 { return nil, errors.NewInternalError(ctx, errs.Errorf("single Root area not found for space %s", spaceID)) } if err != nil { return nil, err } return &rootArea[0], nil }
[ "func", "(", "m", "*", "GormAreaRepository", ")", "Root", "(", "ctx", "context", ".", "Context", ",", "spaceID", "uuid", ".", "UUID", ")", "(", "*", "Area", ",", "error", ")", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "var", "rootArea", "[", "]", "Area", "\n\n", "rootArea", ",", "err", ":=", "m", ".", "Query", "(", "FilterBySpaceID", "(", "spaceID", ")", ",", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "db", ".", "Where", "(", "\"", "\"", ",", "spaceID", ")", "\n", "}", ")", "\n\n", "if", "len", "(", "rootArea", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "errs", ".", "Errorf", "(", "\"", "\"", ",", "spaceID", ")", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "rootArea", "[", "0", "]", ",", "nil", "\n", "}" ]
// Root fetches the Root Areas inside a space.
[ "Root", "fetches", "the", "Root", "Areas", "inside", "a", "space", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/area/area.go#L183-L198
13,340
fabric8-services/fabric8-wit
area/area.go
FilterBySpaceID
func FilterBySpaceID(spaceID uuid.UUID) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("space_id = ?", spaceID) } }
go
func FilterBySpaceID(spaceID uuid.UUID) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("space_id = ?", spaceID) } }
[ "func", "FilterBySpaceID", "(", "spaceID", "uuid", ".", "UUID", ")", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "db", ".", "Where", "(", "\"", "\"", ",", "spaceID", ")", "\n", "}", "\n", "}" ]
// FilterBySpaceID is a gorm filter for a Belongs To relationship.
[ "FilterBySpaceID", "is", "a", "gorm", "filter", "for", "a", "Belongs", "To", "relationship", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/area/area.go#L218-L222
13,341
fabric8-services/fabric8-wit
area/area.go
FilterByName
func FilterByName(name string) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("name = ?", name).Limit(1) } }
go
func FilterByName(name string) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("name = ?", name).Limit(1) } }
[ "func", "FilterByName", "(", "name", "string", ")", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "db", ".", "Where", "(", "\"", "\"", ",", "name", ")", ".", "Limit", "(", "1", ")", "\n", "}", "\n", "}" ]
// FilterByName is a gorm filter by 'name'
[ "FilterByName", "is", "a", "gorm", "filter", "by", "name" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/area/area.go#L225-L229
13,342
fabric8-services/fabric8-wit
controller/work_item_labels.go
NewWorkItemLabelsController
func NewWorkItemLabelsController(service *goa.Service, db application.DB, config WorkItemLabelsControllerConfiguration) *WorkItemLabelsController { return &WorkItemLabelsController{ Controller: service.NewController("WorkItemLabelsController"), db: db, config: config, } }
go
func NewWorkItemLabelsController(service *goa.Service, db application.DB, config WorkItemLabelsControllerConfiguration) *WorkItemLabelsController { return &WorkItemLabelsController{ Controller: service.NewController("WorkItemLabelsController"), db: db, config: config, } }
[ "func", "NewWorkItemLabelsController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "WorkItemLabelsControllerConfiguration", ")", "*", "WorkItemLabelsController", "{", "return", "&", "WorkItemLabelsController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "config", ":", "config", ",", "}", "\n", "}" ]
// NewWorkItemLabelsController creates a work_item_labels controller.
[ "NewWorkItemLabelsController", "creates", "a", "work_item_labels", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_labels.go#L27-L33
13,343
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
String
func (s ImportHelper) String() string { copy := s bytes, err := yaml.Marshal(copy) if err != nil { log.Info(nil, map[string]interface{}{ "err": err, }, "failed to marshal space template to YAML") return "" } return string(bytes) }
go
func (s ImportHelper) String() string { copy := s bytes, err := yaml.Marshal(copy) if err != nil { log.Info(nil, map[string]interface{}{ "err": err, }, "failed to marshal space template to YAML") return "" } return string(bytes) }
[ "func", "(", "s", "ImportHelper", ")", "String", "(", ")", "string", "{", "copy", ":=", "s", "\n", "bytes", ",", "err", ":=", "yaml", ".", "Marshal", "(", "copy", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Info", "(", "nil", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "\"", "\"", "\n", "}", "\n", "return", "string", "(", "bytes", ")", "\n", "}" ]
// String convert a parsed template into a string in YAML format
[ "String", "convert", "a", "parsed", "template", "into", "a", "string", "in", "YAML", "format" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L62-L72
13,344
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
FromString
func FromString(templ string) (*ImportHelper, error) { var s ImportHelper if err := yaml.Unmarshal([]byte(templ), &s); err != nil { log.Info(nil, map[string]interface{}{ "template": templ, "err": err, }, "failed to unmarshal YAML space template") return nil, errs.Wrapf(err, "failed to parse YAML space template: \n%s", templ) } // If the space template has no ID, create one on the fly if uuid.Equal(s.Template.ID, uuid.Nil) { s.Template.ID = uuid.NewV4() } // update all refs to this ID s.SetID(s.Template.ID) if err := s.Validate(); err != nil { return nil, errs.Wrap(err, "failed to validate space template") } return &s, nil }
go
func FromString(templ string) (*ImportHelper, error) { var s ImportHelper if err := yaml.Unmarshal([]byte(templ), &s); err != nil { log.Info(nil, map[string]interface{}{ "template": templ, "err": err, }, "failed to unmarshal YAML space template") return nil, errs.Wrapf(err, "failed to parse YAML space template: \n%s", templ) } // If the space template has no ID, create one on the fly if uuid.Equal(s.Template.ID, uuid.Nil) { s.Template.ID = uuid.NewV4() } // update all refs to this ID s.SetID(s.Template.ID) if err := s.Validate(); err != nil { return nil, errs.Wrap(err, "failed to validate space template") } return &s, nil }
[ "func", "FromString", "(", "templ", "string", ")", "(", "*", "ImportHelper", ",", "error", ")", "{", "var", "s", "ImportHelper", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "[", "]", "byte", "(", "templ", ")", ",", "&", "s", ")", ";", "err", "!=", "nil", "{", "log", ".", "Info", "(", "nil", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "templ", ",", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errs", ".", "Wrapf", "(", "err", ",", "\"", "\\n", "\"", ",", "templ", ")", "\n", "}", "\n", "// If the space template has no ID, create one on the fly", "if", "uuid", ".", "Equal", "(", "s", ".", "Template", ".", "ID", ",", "uuid", ".", "Nil", ")", "{", "s", ".", "Template", ".", "ID", "=", "uuid", ".", "NewV4", "(", ")", "\n", "}", "\n", "// update all refs to this ID", "s", ".", "SetID", "(", "s", ".", "Template", ".", "ID", ")", "\n", "if", "err", ":=", "s", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "&", "s", ",", "nil", "\n", "}" ]
// FromString parses a given string into a parsed template object and validates // it.
[ "FromString", "parses", "a", "given", "string", "into", "a", "parsed", "template", "object", "and", "validates", "it", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L76-L95
13,345
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
SetID
func (s *ImportHelper) SetID(id uuid.UUID) { s.Template.ID = id for _, wit := range s.WITs { wit.SpaceTemplateID = s.Template.ID } for _, wilt := range s.WILTs { wilt.SpaceTemplateID = s.Template.ID } for _, witg := range s.WITGs { witg.SpaceTemplateID = s.Template.ID } for _, wib := range s.WIBs { wib.SpaceTemplateID = s.Template.ID } }
go
func (s *ImportHelper) SetID(id uuid.UUID) { s.Template.ID = id for _, wit := range s.WITs { wit.SpaceTemplateID = s.Template.ID } for _, wilt := range s.WILTs { wilt.SpaceTemplateID = s.Template.ID } for _, witg := range s.WITGs { witg.SpaceTemplateID = s.Template.ID } for _, wib := range s.WIBs { wib.SpaceTemplateID = s.Template.ID } }
[ "func", "(", "s", "*", "ImportHelper", ")", "SetID", "(", "id", "uuid", ".", "UUID", ")", "{", "s", ".", "Template", ".", "ID", "=", "id", "\n", "for", "_", ",", "wit", ":=", "range", "s", ".", "WITs", "{", "wit", ".", "SpaceTemplateID", "=", "s", ".", "Template", ".", "ID", "\n", "}", "\n", "for", "_", ",", "wilt", ":=", "range", "s", ".", "WILTs", "{", "wilt", ".", "SpaceTemplateID", "=", "s", ".", "Template", ".", "ID", "\n", "}", "\n", "for", "_", ",", "witg", ":=", "range", "s", ".", "WITGs", "{", "witg", ".", "SpaceTemplateID", "=", "s", ".", "Template", ".", "ID", "\n", "}", "\n", "for", "_", ",", "wib", ":=", "range", "s", ".", "WIBs", "{", "wib", ".", "SpaceTemplateID", "=", "s", ".", "Template", ".", "ID", "\n", "}", "\n", "}" ]
// SetID updates the space templates IDs and updates the references to that ID.
[ "SetID", "updates", "the", "space", "templates", "IDs", "and", "updates", "the", "references", "to", "that", "ID", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L98-L112
13,346
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
Equal
func (s ImportHelper) Equal(u convert.Equaler) bool { other, ok := u.(ImportHelper) if !ok { return false } // test nested space template on equality if !convert.CascadeEqual(s.Template, other.Template) { return false } if len(s.WITs) != len(other.WITs) { return false } for k := range s.WITs { if other.WITs[k] == nil { return false } if !convert.CascadeEqual(s.WITs[k], *other.WITs[k]) { return false } } if len(s.WILTs) != len(other.WILTs) { return false } for k := range s.WILTs { if other.WILTs[k] == nil { return false } if !convert.CascadeEqual(s.WILTs[k], *other.WILTs[k]) { return false } } if len(s.WITGs) != len(other.WITGs) { return false } for k := range s.WITGs { if other.WITGs[k] == nil { return false } if !convert.CascadeEqual(s.WITGs[k], *other.WITGs[k]) { return false } } if len(s.WIBs) != len(other.WIBs) { return false } for k := range s.WIBs { if other.WIBs[k] == nil { return false } if !convert.CascadeEqual(s.WIBs[k], *other.WIBs[k]) { return false } } return true }
go
func (s ImportHelper) Equal(u convert.Equaler) bool { other, ok := u.(ImportHelper) if !ok { return false } // test nested space template on equality if !convert.CascadeEqual(s.Template, other.Template) { return false } if len(s.WITs) != len(other.WITs) { return false } for k := range s.WITs { if other.WITs[k] == nil { return false } if !convert.CascadeEqual(s.WITs[k], *other.WITs[k]) { return false } } if len(s.WILTs) != len(other.WILTs) { return false } for k := range s.WILTs { if other.WILTs[k] == nil { return false } if !convert.CascadeEqual(s.WILTs[k], *other.WILTs[k]) { return false } } if len(s.WITGs) != len(other.WITGs) { return false } for k := range s.WITGs { if other.WITGs[k] == nil { return false } if !convert.CascadeEqual(s.WITGs[k], *other.WITGs[k]) { return false } } if len(s.WIBs) != len(other.WIBs) { return false } for k := range s.WIBs { if other.WIBs[k] == nil { return false } if !convert.CascadeEqual(s.WIBs[k], *other.WIBs[k]) { return false } } return true }
[ "func", "(", "s", "ImportHelper", ")", "Equal", "(", "u", "convert", ".", "Equaler", ")", "bool", "{", "other", ",", "ok", ":=", "u", ".", "(", "ImportHelper", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "// test nested space template on equality", "if", "!", "convert", ".", "CascadeEqual", "(", "s", ".", "Template", ",", "other", ".", "Template", ")", "{", "return", "false", "\n", "}", "\n", "if", "len", "(", "s", ".", "WITs", ")", "!=", "len", "(", "other", ".", "WITs", ")", "{", "return", "false", "\n", "}", "\n", "for", "k", ":=", "range", "s", ".", "WITs", "{", "if", "other", ".", "WITs", "[", "k", "]", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "!", "convert", ".", "CascadeEqual", "(", "s", ".", "WITs", "[", "k", "]", ",", "*", "other", ".", "WITs", "[", "k", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "if", "len", "(", "s", ".", "WILTs", ")", "!=", "len", "(", "other", ".", "WILTs", ")", "{", "return", "false", "\n", "}", "\n", "for", "k", ":=", "range", "s", ".", "WILTs", "{", "if", "other", ".", "WILTs", "[", "k", "]", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "!", "convert", ".", "CascadeEqual", "(", "s", ".", "WILTs", "[", "k", "]", ",", "*", "other", ".", "WILTs", "[", "k", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "if", "len", "(", "s", ".", "WITGs", ")", "!=", "len", "(", "other", ".", "WITGs", ")", "{", "return", "false", "\n", "}", "\n", "for", "k", ":=", "range", "s", ".", "WITGs", "{", "if", "other", ".", "WITGs", "[", "k", "]", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "!", "convert", ".", "CascadeEqual", "(", "s", ".", "WITGs", "[", "k", "]", ",", "*", "other", ".", "WITGs", "[", "k", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "if", "len", "(", "s", ".", "WIBs", ")", "!=", "len", "(", "other", ".", "WIBs", ")", "{", "return", "false", "\n", "}", "\n", "for", "k", ":=", "range", "s", ".", "WIBs", "{", "if", "other", ".", "WIBs", "[", "k", "]", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "!", "convert", ".", "CascadeEqual", "(", "s", ".", "WIBs", "[", "k", "]", ",", "*", "other", ".", "WIBs", "[", "k", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns true if two ImportHelper objects are equal; otherwise false is // returned.
[ "Equal", "returns", "true", "if", "two", "ImportHelper", "objects", "are", "equal", ";", "otherwise", "false", "is", "returned", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L120-L174
13,347
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
BaseTemplate
func BaseTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("base.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load base template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemBaseTemplateID) return s, nil }
go
func BaseTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("base.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load base template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemBaseTemplateID) return s, nil }
[ "func", "BaseTemplate", "(", ")", "(", "*", "ImportHelper", ",", "error", ")", "{", "bs", ",", "err", ":=", "spacetemplate", ".", "Asset", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "s", ",", "err", ":=", "FromString", "(", "string", "(", "bs", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "s", ".", "SetID", "(", "spacetemplate", ".", "SystemBaseTemplateID", ")", "\n", "return", "s", ",", "nil", "\n", "}" ]
// BaseTemplate returns the base template
[ "BaseTemplate", "returns", "the", "base", "template" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L182-L193
13,348
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
LegacyTemplate
func LegacyTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("legacy.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load legacy template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemLegacyTemplateID) return s, nil }
go
func LegacyTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("legacy.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load legacy template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemLegacyTemplateID) return s, nil }
[ "func", "LegacyTemplate", "(", ")", "(", "*", "ImportHelper", ",", "error", ")", "{", "bs", ",", "err", ":=", "spacetemplate", ".", "Asset", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "s", ",", "err", ":=", "FromString", "(", "string", "(", "bs", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "s", ".", "SetID", "(", "spacetemplate", ".", "SystemLegacyTemplateID", ")", "\n", "return", "s", ",", "nil", "\n", "}" ]
// LegacyTemplate returns the legacy template as it is known to the system
[ "LegacyTemplate", "returns", "the", "legacy", "template", "as", "it", "is", "known", "to", "the", "system" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L196-L207
13,349
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
ScrumTemplate
func ScrumTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("scrum.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load scrum template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemScrumTemplateID) return s, nil }
go
func ScrumTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("scrum.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load scrum template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemScrumTemplateID) return s, nil }
[ "func", "ScrumTemplate", "(", ")", "(", "*", "ImportHelper", ",", "error", ")", "{", "bs", ",", "err", ":=", "spacetemplate", ".", "Asset", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "s", ",", "err", ":=", "FromString", "(", "string", "(", "bs", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "s", ".", "SetID", "(", "spacetemplate", ".", "SystemScrumTemplateID", ")", "\n", "return", "s", ",", "nil", "\n", "}" ]
// ScrumTemplate returns the scrum template as it is known to the system
[ "ScrumTemplate", "returns", "the", "scrum", "template", "as", "it", "is", "known", "to", "the", "system" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L210-L221
13,350
fabric8-services/fabric8-wit
spacetemplate/importer/import_helper.go
AgileTemplate
func AgileTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("agile.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load agile template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemAgileTemplateID) return s, nil }
go
func AgileTemplate() (*ImportHelper, error) { bs, err := spacetemplate.Asset("agile.yaml") if err != nil { return nil, errs.Wrap(err, "failed to load agile template") } s, err := FromString(string(bs)) if err != nil { return nil, errs.WithStack(err) } s.SetID(spacetemplate.SystemAgileTemplateID) return s, nil }
[ "func", "AgileTemplate", "(", ")", "(", "*", "ImportHelper", ",", "error", ")", "{", "bs", ",", "err", ":=", "spacetemplate", ".", "Asset", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "s", ",", "err", ":=", "FromString", "(", "string", "(", "bs", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "s", ".", "SetID", "(", "spacetemplate", ".", "SystemAgileTemplateID", ")", "\n", "return", "s", ",", "nil", "\n", "}" ]
// AgileTemplate returns the agile template as it is known to the system
[ "AgileTemplate", "returns", "the", "agile", "template", "as", "it", "is", "known", "to", "the", "system" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/spacetemplate/importer/import_helper.go#L224-L235
13,351
fabric8-services/fabric8-wit
controller/space_iterations.go
NewSpaceIterationsController
func NewSpaceIterationsController(service *goa.Service, db application.DB, config SpaceIterationsControllerConfiguration) *SpaceIterationsController { return &SpaceIterationsController{Controller: service.NewController("SpaceIterationsController"), db: db, config: config} }
go
func NewSpaceIterationsController(service *goa.Service, db application.DB, config SpaceIterationsControllerConfiguration) *SpaceIterationsController { return &SpaceIterationsController{Controller: service.NewController("SpaceIterationsController"), db: db, config: config} }
[ "func", "NewSpaceIterationsController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "SpaceIterationsControllerConfiguration", ")", "*", "SpaceIterationsController", "{", "return", "&", "SpaceIterationsController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "config", ":", "config", "}", "\n", "}" ]
// NewSpaceIterationsController creates a space-iterations controller.
[ "NewSpaceIterationsController", "creates", "a", "space", "-", "iterations", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/space_iterations.go#L31-L33
13,352
fabric8-services/fabric8-wit
controller/space_areas.go
NewSpaceAreasController
func NewSpaceAreasController(service *goa.Service, db application.DB, config SpaceAreasControllerConfig) *SpaceAreasController { return &SpaceAreasController{ Controller: service.NewController("SpaceAreasController"), db: db, config: config, } }
go
func NewSpaceAreasController(service *goa.Service, db application.DB, config SpaceAreasControllerConfig) *SpaceAreasController { return &SpaceAreasController{ Controller: service.NewController("SpaceAreasController"), db: db, config: config, } }
[ "func", "NewSpaceAreasController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "SpaceAreasControllerConfig", ")", "*", "SpaceAreasController", "{", "return", "&", "SpaceAreasController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "config", ":", "config", ",", "}", "\n", "}" ]
// NewSpaceAreasController creates a space-Areas controller.
[ "NewSpaceAreasController", "creates", "a", "space", "-", "Areas", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/space_areas.go#L26-L32
13,353
fabric8-services/fabric8-wit
workitem/number_sequence/workitem_number_sequence_repository.go
NextVal
func (r *GormWorkItemNumberSequenceRepository) NextVal(ctx context.Context, spaceID uuid.UUID) (*int, error) { // upsert the next val, retrieves full row upsertStmt := fmt.Sprintf(`INSERT INTO %[1]s (space_id, current_val) VALUES ($1,1) ON CONFLICT (space_id) DO UPDATE SET current_val = %[1]s.current_val + EXCLUDED.current_val RETURNING current_val`, WorkItemNumberSequence{}.TableName()) var currentVal int err := r.db.CommonDB().QueryRow(upsertStmt, spaceID).Scan(&currentVal) if err != nil { return nil, errs.Wrapf(err, "failed to obtain next val for space with ID=`%s`", spaceID.String()) } log.Debug(nil, map[string]interface{}{"space_id": spaceID, "next_val": currentVal}, "computed nextVal") return &currentVal, nil }
go
func (r *GormWorkItemNumberSequenceRepository) NextVal(ctx context.Context, spaceID uuid.UUID) (*int, error) { // upsert the next val, retrieves full row upsertStmt := fmt.Sprintf(`INSERT INTO %[1]s (space_id, current_val) VALUES ($1,1) ON CONFLICT (space_id) DO UPDATE SET current_val = %[1]s.current_val + EXCLUDED.current_val RETURNING current_val`, WorkItemNumberSequence{}.TableName()) var currentVal int err := r.db.CommonDB().QueryRow(upsertStmt, spaceID).Scan(&currentVal) if err != nil { return nil, errs.Wrapf(err, "failed to obtain next val for space with ID=`%s`", spaceID.String()) } log.Debug(nil, map[string]interface{}{"space_id": spaceID, "next_val": currentVal}, "computed nextVal") return &currentVal, nil }
[ "func", "(", "r", "*", "GormWorkItemNumberSequenceRepository", ")", "NextVal", "(", "ctx", "context", ".", "Context", ",", "spaceID", "uuid", ".", "UUID", ")", "(", "*", "int", ",", "error", ")", "{", "// upsert the next val, retrieves full row", "upsertStmt", ":=", "fmt", ".", "Sprintf", "(", "`INSERT INTO %[1]s (space_id, current_val) VALUES ($1,1)\n\t\tON CONFLICT (space_id) DO UPDATE SET current_val = %[1]s.current_val + EXCLUDED.current_val\n\t\tRETURNING current_val`", ",", "WorkItemNumberSequence", "{", "}", ".", "TableName", "(", ")", ")", "\n", "var", "currentVal", "int", "\n", "err", ":=", "r", ".", "db", ".", "CommonDB", "(", ")", ".", "QueryRow", "(", "upsertStmt", ",", "spaceID", ")", ".", "Scan", "(", "&", "currentVal", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "spaceID", ".", "String", "(", ")", ")", "\n", "}", "\n", "log", ".", "Debug", "(", "nil", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "spaceID", ",", "\"", "\"", ":", "currentVal", "}", ",", "\"", "\"", ")", "\n", "return", "&", "currentVal", ",", "nil", "\n", "}" ]
// NextVal returns the next work item sequence number for the given space ID. Creates an entry in the DB if none was found before
[ "NextVal", "returns", "the", "next", "work", "item", "sequence", "number", "for", "the", "given", "space", "ID", ".", "Creates", "an", "entry", "in", "the", "DB", "if", "none", "was", "found", "before" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/number_sequence/workitem_number_sequence_repository.go#L30-L42
13,354
fabric8-services/fabric8-wit
workitem/board.go
Equal
func (wib Board) Equal(u convert.Equaler) bool { other, ok := u.(Board) if !ok { return false } if wib.ID != other.ID { return false } if wib.SpaceTemplateID != other.SpaceTemplateID { return false } if !convert.CascadeEqual(wib.Lifecycle, other.Lifecycle) { return false } if wib.Name != other.Name { return false } if wib.Description != other.Description { return false } if wib.Context != other.Context { return false } if wib.ContextType != other.ContextType { return false } if len(wib.Columns) != len(other.Columns) { return false } for i := range wib.Columns { if !convert.CascadeEqual(wib.Columns[i], other.Columns[i]) { return false } } return true }
go
func (wib Board) Equal(u convert.Equaler) bool { other, ok := u.(Board) if !ok { return false } if wib.ID != other.ID { return false } if wib.SpaceTemplateID != other.SpaceTemplateID { return false } if !convert.CascadeEqual(wib.Lifecycle, other.Lifecycle) { return false } if wib.Name != other.Name { return false } if wib.Description != other.Description { return false } if wib.Context != other.Context { return false } if wib.ContextType != other.ContextType { return false } if len(wib.Columns) != len(other.Columns) { return false } for i := range wib.Columns { if !convert.CascadeEqual(wib.Columns[i], other.Columns[i]) { return false } } return true }
[ "func", "(", "wib", "Board", ")", "Equal", "(", "u", "convert", ".", "Equaler", ")", "bool", "{", "other", ",", "ok", ":=", "u", ".", "(", "Board", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "if", "wib", ".", "ID", "!=", "other", ".", "ID", "{", "return", "false", "\n", "}", "\n", "if", "wib", ".", "SpaceTemplateID", "!=", "other", ".", "SpaceTemplateID", "{", "return", "false", "\n", "}", "\n", "if", "!", "convert", ".", "CascadeEqual", "(", "wib", ".", "Lifecycle", ",", "other", ".", "Lifecycle", ")", "{", "return", "false", "\n", "}", "\n", "if", "wib", ".", "Name", "!=", "other", ".", "Name", "{", "return", "false", "\n", "}", "\n", "if", "wib", ".", "Description", "!=", "other", ".", "Description", "{", "return", "false", "\n", "}", "\n", "if", "wib", ".", "Context", "!=", "other", ".", "Context", "{", "return", "false", "\n", "}", "\n", "if", "wib", ".", "ContextType", "!=", "other", ".", "ContextType", "{", "return", "false", "\n", "}", "\n", "if", "len", "(", "wib", ".", "Columns", ")", "!=", "len", "(", "other", ".", "Columns", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "range", "wib", ".", "Columns", "{", "if", "!", "convert", ".", "CascadeEqual", "(", "wib", ".", "Columns", "[", "i", "]", ",", "other", ".", "Columns", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns true if two Board objects are equal; otherwise false is returned.
[ "Equal", "returns", "true", "if", "two", "Board", "objects", "are", "equal", ";", "otherwise", "false", "is", "returned", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/board.go#L33-L68
13,355
fabric8-services/fabric8-wit
workitem/board.go
Equal
func (wibc BoardColumn) Equal(u convert.Equaler) bool { other, ok := u.(BoardColumn) if !ok { return false } if wibc.ID != other.ID { return false } if wibc.BoardID != other.BoardID { return false } if !convert.CascadeEqual(wibc.Lifecycle, other.Lifecycle) { return false } if wibc.Name != other.Name { return false } if wibc.Order != other.Order { return false } if wibc.TransRuleKey != other.TransRuleKey { return false } if wibc.TransRuleArgument != other.TransRuleArgument { return false } return true }
go
func (wibc BoardColumn) Equal(u convert.Equaler) bool { other, ok := u.(BoardColumn) if !ok { return false } if wibc.ID != other.ID { return false } if wibc.BoardID != other.BoardID { return false } if !convert.CascadeEqual(wibc.Lifecycle, other.Lifecycle) { return false } if wibc.Name != other.Name { return false } if wibc.Order != other.Order { return false } if wibc.TransRuleKey != other.TransRuleKey { return false } if wibc.TransRuleArgument != other.TransRuleArgument { return false } return true }
[ "func", "(", "wibc", "BoardColumn", ")", "Equal", "(", "u", "convert", ".", "Equaler", ")", "bool", "{", "other", ",", "ok", ":=", "u", ".", "(", "BoardColumn", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "if", "wibc", ".", "ID", "!=", "other", ".", "ID", "{", "return", "false", "\n", "}", "\n", "if", "wibc", ".", "BoardID", "!=", "other", ".", "BoardID", "{", "return", "false", "\n", "}", "\n", "if", "!", "convert", ".", "CascadeEqual", "(", "wibc", ".", "Lifecycle", ",", "other", ".", "Lifecycle", ")", "{", "return", "false", "\n", "}", "\n", "if", "wibc", ".", "Name", "!=", "other", ".", "Name", "{", "return", "false", "\n", "}", "\n", "if", "wibc", ".", "Order", "!=", "other", ".", "Order", "{", "return", "false", "\n", "}", "\n", "if", "wibc", ".", "TransRuleKey", "!=", "other", ".", "TransRuleKey", "{", "return", "false", "\n", "}", "\n", "if", "wibc", ".", "TransRuleArgument", "!=", "other", ".", "TransRuleArgument", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns true if two BoardColumn objects are equal; otherwise false is returned.
[ "Equal", "returns", "true", "if", "two", "BoardColumn", "objects", "are", "equal", ";", "otherwise", "false", "is", "returned", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/board.go#L111-L138
13,356
fabric8-services/fabric8-wit
controller/user_service.go
Clean
func (c *UserServiceController) Clean(ctx *app.CleanUserServiceContext) error { err := c.CleanTenant(ctx, ctx.Remove) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
go
func (c *UserServiceController) Clean(ctx *app.CleanUserServiceContext) error { err := c.CleanTenant(ctx, ctx.Remove) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
[ "func", "(", "c", "*", "UserServiceController", ")", "Clean", "(", "ctx", "*", "app", ".", "CleanUserServiceContext", ")", "error", "{", "err", ":=", "c", ".", "CleanTenant", "(", "ctx", ",", "ctx", ".", "Remove", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ".", "OK", "(", "[", "]", "byte", "{", "}", ")", "\n", "}" ]
// Clean runs the clean action.
[ "Clean", "runs", "the", "clean", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/user_service.go#L33-L39
13,357
fabric8-services/fabric8-wit
account/user.go
PermanentDelete
func (m *GormUserRepository) PermanentDelete(ctx context.Context, ID uuid.UUID) error { defer goa.MeasureSince([]string{"goa", "db", "user", "permanent_delete"}, time.Now()) tx := m.db.Unscoped().Delete(&User{ID: ID}) if err := tx.Error; err != nil { log.Error(ctx, map[string]interface{}{ "user_id": ID.String(), "err": err, }, "unable to permanently delete the user") return errors.NewInternalError(ctx, err) } if tx.RowsAffected == 0 { log.Error(ctx, map[string]interface{}{ "user_id": ID.String(), }, "none row was affected by the permanently deletion operation") return errors.NewNotFoundError("user", ID.String()) } log.Debug(ctx, map[string]interface{}{ "user_id": ID, }, "User permanently deleted!") return nil }
go
func (m *GormUserRepository) PermanentDelete(ctx context.Context, ID uuid.UUID) error { defer goa.MeasureSince([]string{"goa", "db", "user", "permanent_delete"}, time.Now()) tx := m.db.Unscoped().Delete(&User{ID: ID}) if err := tx.Error; err != nil { log.Error(ctx, map[string]interface{}{ "user_id": ID.String(), "err": err, }, "unable to permanently delete the user") return errors.NewInternalError(ctx, err) } if tx.RowsAffected == 0 { log.Error(ctx, map[string]interface{}{ "user_id": ID.String(), }, "none row was affected by the permanently deletion operation") return errors.NewNotFoundError("user", ID.String()) } log.Debug(ctx, map[string]interface{}{ "user_id": ID, }, "User permanently deleted!") return nil }
[ "func", "(", "m", "*", "GormUserRepository", ")", "PermanentDelete", "(", "ctx", "context", ".", "Context", ",", "ID", "uuid", ".", "UUID", ")", "error", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "tx", ":=", "m", ".", "db", ".", "Unscoped", "(", ")", ".", "Delete", "(", "&", "User", "{", "ID", ":", "ID", "}", ")", "\n", "if", "err", ":=", "tx", ".", "Error", ";", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "ID", ".", "String", "(", ")", ",", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "errors", ".", "NewInternalError", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "if", "tx", ".", "RowsAffected", "==", "0", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "ID", ".", "String", "(", ")", ",", "}", ",", "\"", "\"", ")", "\n", "return", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ID", ".", "String", "(", ")", ")", "\n", "}", "\n", "log", ".", "Debug", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "ID", ",", "}", ",", "\"", "\"", ")", "\n\n", "return", "nil", "\n", "}" ]
// Delete removes a single record. This method use custom SQL to allow soft delete with GORM // to coexist with permanent delete.
[ "Delete", "removes", "a", "single", "record", ".", "This", "method", "use", "custom", "SQL", "to", "allow", "soft", "delete", "with", "GORM", "to", "coexist", "with", "permanent", "delete", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/account/user.go#L195-L216
13,358
fabric8-services/fabric8-wit
account/user.go
UserFilterByID
func UserFilterByID(userID uuid.UUID) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("id = ?", userID) } }
go
func UserFilterByID(userID uuid.UUID) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("id = ?", userID) } }
[ "func", "UserFilterByID", "(", "userID", "uuid", ".", "UUID", ")", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "db", ".", "Where", "(", "\"", "\"", ",", "userID", ")", "\n", "}", "\n", "}" ]
// UserFilterByID is a gorm filter for User ID.
[ "UserFilterByID", "is", "a", "gorm", "filter", "for", "User", "ID", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/account/user.go#L248-L252
13,359
fabric8-services/fabric8-wit
account/user.go
UserFilterByEmail
func UserFilterByEmail(email string) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("email = ?", email) } }
go
func UserFilterByEmail(email string) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { return db.Where("email = ?", email) } }
[ "func", "UserFilterByEmail", "(", "email", "string", ")", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "func", "(", "db", "*", "gorm", ".", "DB", ")", "*", "gorm", ".", "DB", "{", "return", "db", ".", "Where", "(", "\"", "\"", ",", "email", ")", "\n", "}", "\n", "}" ]
// UserFilterByEmail is a gorm filter for User ID.
[ "UserFilterByEmail", "is", "a", "gorm", "filter", "for", "User", "ID", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/account/user.go#L255-L259
13,360
fabric8-services/fabric8-wit
controller/iteration.go
NewIterationController
func NewIterationController(service *goa.Service, db application.DB, config IterationControllerConfiguration) *IterationController { return &IterationController{Controller: service.NewController("IterationController"), db: db, config: config} }
go
func NewIterationController(service *goa.Service, db application.DB, config IterationControllerConfiguration) *IterationController { return &IterationController{Controller: service.NewController("IterationController"), db: db, config: config} }
[ "func", "NewIterationController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "IterationControllerConfiguration", ")", "*", "IterationController", "{", "return", "&", "IterationController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "config", ":", "config", "}", "\n", "}" ]
// NewIterationController creates a iteration controller.
[ "NewIterationController", "creates", "a", "iteration", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/iteration.go#L44-L46
13,361
fabric8-services/fabric8-wit
controller/iteration.go
verifyUser
func verifyUser(ctx context.Context, currentUser uuid.UUID, sp *space.Space) (bool, bool, error) { authorized, err := authz.Authorize(ctx, sp.ID.String()) if err != nil { return false, false, err } var spaceOwner bool if uuid.Equal(currentUser, sp.OwnerID) { spaceOwner = true } return authorized, spaceOwner, nil }
go
func verifyUser(ctx context.Context, currentUser uuid.UUID, sp *space.Space) (bool, bool, error) { authorized, err := authz.Authorize(ctx, sp.ID.String()) if err != nil { return false, false, err } var spaceOwner bool if uuid.Equal(currentUser, sp.OwnerID) { spaceOwner = true } return authorized, spaceOwner, nil }
[ "func", "verifyUser", "(", "ctx", "context", ".", "Context", ",", "currentUser", "uuid", ".", "UUID", ",", "sp", "*", "space", ".", "Space", ")", "(", "bool", ",", "bool", ",", "error", ")", "{", "authorized", ",", "err", ":=", "authz", ".", "Authorize", "(", "ctx", ",", "sp", ".", "ID", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "false", ",", "err", "\n", "}", "\n", "var", "spaceOwner", "bool", "\n", "if", "uuid", ".", "Equal", "(", "currentUser", ",", "sp", ".", "OwnerID", ")", "{", "spaceOwner", "=", "true", "\n", "}", "\n", "return", "authorized", ",", "spaceOwner", ",", "nil", "\n", "}" ]
// verifyUser checks if user is a space owner or a collaborator
[ "verifyUser", "checks", "if", "user", "is", "a", "space", "owner", "or", "a", "collaborator" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/iteration.go#L49-L59
13,362
fabric8-services/fabric8-wit
controller/iteration.go
ConvertIterations
func ConvertIterations(request *http.Request, Iterations []iteration.Iteration, additional ...IterationConvertFunc) []*app.Iteration { var is = []*app.Iteration{} for _, i := range Iterations { is = append(is, ConvertIteration(request, i, additional...)) } return is }
go
func ConvertIterations(request *http.Request, Iterations []iteration.Iteration, additional ...IterationConvertFunc) []*app.Iteration { var is = []*app.Iteration{} for _, i := range Iterations { is = append(is, ConvertIteration(request, i, additional...)) } return is }
[ "func", "ConvertIterations", "(", "request", "*", "http", ".", "Request", ",", "Iterations", "[", "]", "iteration", ".", "Iteration", ",", "additional", "...", "IterationConvertFunc", ")", "[", "]", "*", "app", ".", "Iteration", "{", "var", "is", "=", "[", "]", "*", "app", ".", "Iteration", "{", "}", "\n", "for", "_", ",", "i", ":=", "range", "Iterations", "{", "is", "=", "append", "(", "is", ",", "ConvertIteration", "(", "request", ",", "i", ",", "additional", "...", ")", ")", "\n", "}", "\n", "return", "is", "\n", "}" ]
// ConvertIterations converts between internal and external REST representation
[ "ConvertIterations", "converts", "between", "internal", "and", "external", "REST", "representation" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/iteration.go#L447-L453
13,363
fabric8-services/fabric8-wit
controller/iteration.go
ConvertIteration
func ConvertIteration(request *http.Request, itr iteration.Iteration, additional ...IterationConvertFunc) *app.Iteration { iterationType := iteration.APIStringTypeIteration spaceID := itr.SpaceID.String() relatedURL := rest.AbsoluteURL(request, app.IterationHref(itr.ID)) spaceRelatedURL := rest.AbsoluteURL(request, app.SpaceHref(spaceID)) workitemsRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref("?filter[iteration]="+itr.ID.String())) pathToTopMostParent := itr.Path.ParentPath().String() activeStatus := itr.IsActive() i := &app.Iteration{ Type: iterationType, ID: &itr.ID, Attributes: &app.IterationAttributes{ Name: &itr.Name, CreatedAt: &itr.CreatedAt, UpdatedAt: &itr.UpdatedAt, StartAt: itr.StartAt, EndAt: itr.EndAt, Description: itr.Description, State: itr.State.StringPtr(), ParentPath: &pathToTopMostParent, UserActive: &itr.UserActive, ActiveStatus: &activeStatus, Number: &itr.Number, }, Relationships: &app.IterationRelations{ Space: &app.RelationGeneric{ Data: &app.GenericData{ Type: &space.SpaceType, ID: &spaceID, }, Links: &app.GenericLinks{ Self: &spaceRelatedURL, Related: &spaceRelatedURL, }, }, Workitems: &app.RelationGeneric{ Links: &app.GenericLinks{ Related: &workitemsRelatedURL, }, }, }, Links: &app.GenericLinks{ Self: &relatedURL, Related: &relatedURL, }, } if !itr.Path.ParentPath().IsEmpty() { parentID := itr.Path.ParentID().String() parentRelatedURL := rest.AbsoluteURL(request, app.IterationHref(parentID)) i.Relationships.Parent = &app.RelationGeneric{ Data: &app.GenericData{ Type: &iterationType, ID: &parentID, }, Links: &app.GenericLinks{ Self: &parentRelatedURL, Related: &parentRelatedURL, }, } } for _, add := range additional { add(request, &itr, i) } return i }
go
func ConvertIteration(request *http.Request, itr iteration.Iteration, additional ...IterationConvertFunc) *app.Iteration { iterationType := iteration.APIStringTypeIteration spaceID := itr.SpaceID.String() relatedURL := rest.AbsoluteURL(request, app.IterationHref(itr.ID)) spaceRelatedURL := rest.AbsoluteURL(request, app.SpaceHref(spaceID)) workitemsRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref("?filter[iteration]="+itr.ID.String())) pathToTopMostParent := itr.Path.ParentPath().String() activeStatus := itr.IsActive() i := &app.Iteration{ Type: iterationType, ID: &itr.ID, Attributes: &app.IterationAttributes{ Name: &itr.Name, CreatedAt: &itr.CreatedAt, UpdatedAt: &itr.UpdatedAt, StartAt: itr.StartAt, EndAt: itr.EndAt, Description: itr.Description, State: itr.State.StringPtr(), ParentPath: &pathToTopMostParent, UserActive: &itr.UserActive, ActiveStatus: &activeStatus, Number: &itr.Number, }, Relationships: &app.IterationRelations{ Space: &app.RelationGeneric{ Data: &app.GenericData{ Type: &space.SpaceType, ID: &spaceID, }, Links: &app.GenericLinks{ Self: &spaceRelatedURL, Related: &spaceRelatedURL, }, }, Workitems: &app.RelationGeneric{ Links: &app.GenericLinks{ Related: &workitemsRelatedURL, }, }, }, Links: &app.GenericLinks{ Self: &relatedURL, Related: &relatedURL, }, } if !itr.Path.ParentPath().IsEmpty() { parentID := itr.Path.ParentID().String() parentRelatedURL := rest.AbsoluteURL(request, app.IterationHref(parentID)) i.Relationships.Parent = &app.RelationGeneric{ Data: &app.GenericData{ Type: &iterationType, ID: &parentID, }, Links: &app.GenericLinks{ Self: &parentRelatedURL, Related: &parentRelatedURL, }, } } for _, add := range additional { add(request, &itr, i) } return i }
[ "func", "ConvertIteration", "(", "request", "*", "http", ".", "Request", ",", "itr", "iteration", ".", "Iteration", ",", "additional", "...", "IterationConvertFunc", ")", "*", "app", ".", "Iteration", "{", "iterationType", ":=", "iteration", ".", "APIStringTypeIteration", "\n", "spaceID", ":=", "itr", ".", "SpaceID", ".", "String", "(", ")", "\n", "relatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "IterationHref", "(", "itr", ".", "ID", ")", ")", "\n", "spaceRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "SpaceHref", "(", "spaceID", ")", ")", "\n", "workitemsRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "WorkitemHref", "(", "\"", "\"", "+", "itr", ".", "ID", ".", "String", "(", ")", ")", ")", "\n", "pathToTopMostParent", ":=", "itr", ".", "Path", ".", "ParentPath", "(", ")", ".", "String", "(", ")", "\n", "activeStatus", ":=", "itr", ".", "IsActive", "(", ")", "\n", "i", ":=", "&", "app", ".", "Iteration", "{", "Type", ":", "iterationType", ",", "ID", ":", "&", "itr", ".", "ID", ",", "Attributes", ":", "&", "app", ".", "IterationAttributes", "{", "Name", ":", "&", "itr", ".", "Name", ",", "CreatedAt", ":", "&", "itr", ".", "CreatedAt", ",", "UpdatedAt", ":", "&", "itr", ".", "UpdatedAt", ",", "StartAt", ":", "itr", ".", "StartAt", ",", "EndAt", ":", "itr", ".", "EndAt", ",", "Description", ":", "itr", ".", "Description", ",", "State", ":", "itr", ".", "State", ".", "StringPtr", "(", ")", ",", "ParentPath", ":", "&", "pathToTopMostParent", ",", "UserActive", ":", "&", "itr", ".", "UserActive", ",", "ActiveStatus", ":", "&", "activeStatus", ",", "Number", ":", "&", "itr", ".", "Number", ",", "}", ",", "Relationships", ":", "&", "app", ".", "IterationRelations", "{", "Space", ":", "&", "app", ".", "RelationGeneric", "{", "Data", ":", "&", "app", ".", "GenericData", "{", "Type", ":", "&", "space", ".", "SpaceType", ",", "ID", ":", "&", "spaceID", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Self", ":", "&", "spaceRelatedURL", ",", "Related", ":", "&", "spaceRelatedURL", ",", "}", ",", "}", ",", "Workitems", ":", "&", "app", ".", "RelationGeneric", "{", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Related", ":", "&", "workitemsRelatedURL", ",", "}", ",", "}", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Self", ":", "&", "relatedURL", ",", "Related", ":", "&", "relatedURL", ",", "}", ",", "}", "\n", "if", "!", "itr", ".", "Path", ".", "ParentPath", "(", ")", ".", "IsEmpty", "(", ")", "{", "parentID", ":=", "itr", ".", "Path", ".", "ParentID", "(", ")", ".", "String", "(", ")", "\n", "parentRelatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "IterationHref", "(", "parentID", ")", ")", "\n", "i", ".", "Relationships", ".", "Parent", "=", "&", "app", ".", "RelationGeneric", "{", "Data", ":", "&", "app", ".", "GenericData", "{", "Type", ":", "&", "iterationType", ",", "ID", ":", "&", "parentID", ",", "}", ",", "Links", ":", "&", "app", ".", "GenericLinks", "{", "Self", ":", "&", "parentRelatedURL", ",", "Related", ":", "&", "parentRelatedURL", ",", "}", ",", "}", "\n", "}", "\n", "for", "_", ",", "add", ":=", "range", "additional", "{", "add", "(", "request", ",", "&", "itr", ",", "i", ")", "\n", "}", "\n", "return", "i", "\n", "}" ]
// ConvertIteration converts between internal and external REST representation
[ "ConvertIteration", "converts", "between", "internal", "and", "external", "REST", "representation" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/iteration.go#L456-L520
13,364
fabric8-services/fabric8-wit
controller/iteration.go
ConvertIterationSimple
func ConvertIterationSimple(request *http.Request, id interface{}) (*app.GenericData, *app.GenericLinks) { t := iteration.APIStringTypeIteration i := fmt.Sprint(id) data := &app.GenericData{ Type: &t, ID: &i, } relatedURL := rest.AbsoluteURL(request, app.IterationHref(i)) links := &app.GenericLinks{ Self: &relatedURL, Related: &relatedURL, } return data, links }
go
func ConvertIterationSimple(request *http.Request, id interface{}) (*app.GenericData, *app.GenericLinks) { t := iteration.APIStringTypeIteration i := fmt.Sprint(id) data := &app.GenericData{ Type: &t, ID: &i, } relatedURL := rest.AbsoluteURL(request, app.IterationHref(i)) links := &app.GenericLinks{ Self: &relatedURL, Related: &relatedURL, } return data, links }
[ "func", "ConvertIterationSimple", "(", "request", "*", "http", ".", "Request", ",", "id", "interface", "{", "}", ")", "(", "*", "app", ".", "GenericData", ",", "*", "app", ".", "GenericLinks", ")", "{", "t", ":=", "iteration", ".", "APIStringTypeIteration", "\n", "i", ":=", "fmt", ".", "Sprint", "(", "id", ")", "\n", "data", ":=", "&", "app", ".", "GenericData", "{", "Type", ":", "&", "t", ",", "ID", ":", "&", "i", ",", "}", "\n", "relatedURL", ":=", "rest", ".", "AbsoluteURL", "(", "request", ",", "app", ".", "IterationHref", "(", "i", ")", ")", "\n", "links", ":=", "&", "app", ".", "GenericLinks", "{", "Self", ":", "&", "relatedURL", ",", "Related", ":", "&", "relatedURL", ",", "}", "\n", "return", "data", ",", "links", "\n", "}" ]
// ConvertIterationSimple converts a simple Iteration ID into a Generic // Relationship data+links element
[ "ConvertIterationSimple", "converts", "a", "simple", "Iteration", "ID", "into", "a", "Generic", "Relationship", "data", "+", "links", "element" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/iteration.go#L524-L537
13,365
fabric8-services/fabric8-wit
controller/iteration.go
updateIterationsWithCounts
func updateIterationsWithCounts(wiCounts map[string]workitem.WICountsPerIteration) IterationConvertFunc { return func(request *http.Request, itr *iteration.Iteration, appIteration *app.Iteration) { var counts workitem.WICountsPerIteration if _, ok := wiCounts[appIteration.ID.String()]; ok { counts = wiCounts[appIteration.ID.String()] } else { counts = workitem.WICountsPerIteration{} } if appIteration.Relationships == nil { appIteration.Relationships = &app.IterationRelations{} } if appIteration.Relationships.Workitems == nil { appIteration.Relationships.Workitems = &app.RelationGeneric{} } if appIteration.Relationships.Workitems.Meta == nil { appIteration.Relationships.Workitems.Meta = map[string]interface{}{} } appIteration.Relationships.Workitems.Meta[KeyTotalWorkItems] = counts.Total appIteration.Relationships.Workitems.Meta[KeyClosedWorkItems] = counts.Closed } }
go
func updateIterationsWithCounts(wiCounts map[string]workitem.WICountsPerIteration) IterationConvertFunc { return func(request *http.Request, itr *iteration.Iteration, appIteration *app.Iteration) { var counts workitem.WICountsPerIteration if _, ok := wiCounts[appIteration.ID.String()]; ok { counts = wiCounts[appIteration.ID.String()] } else { counts = workitem.WICountsPerIteration{} } if appIteration.Relationships == nil { appIteration.Relationships = &app.IterationRelations{} } if appIteration.Relationships.Workitems == nil { appIteration.Relationships.Workitems = &app.RelationGeneric{} } if appIteration.Relationships.Workitems.Meta == nil { appIteration.Relationships.Workitems.Meta = map[string]interface{}{} } appIteration.Relationships.Workitems.Meta[KeyTotalWorkItems] = counts.Total appIteration.Relationships.Workitems.Meta[KeyClosedWorkItems] = counts.Closed } }
[ "func", "updateIterationsWithCounts", "(", "wiCounts", "map", "[", "string", "]", "workitem", ".", "WICountsPerIteration", ")", "IterationConvertFunc", "{", "return", "func", "(", "request", "*", "http", ".", "Request", ",", "itr", "*", "iteration", ".", "Iteration", ",", "appIteration", "*", "app", ".", "Iteration", ")", "{", "var", "counts", "workitem", ".", "WICountsPerIteration", "\n", "if", "_", ",", "ok", ":=", "wiCounts", "[", "appIteration", ".", "ID", ".", "String", "(", ")", "]", ";", "ok", "{", "counts", "=", "wiCounts", "[", "appIteration", ".", "ID", ".", "String", "(", ")", "]", "\n", "}", "else", "{", "counts", "=", "workitem", ".", "WICountsPerIteration", "{", "}", "\n", "}", "\n", "if", "appIteration", ".", "Relationships", "==", "nil", "{", "appIteration", ".", "Relationships", "=", "&", "app", ".", "IterationRelations", "{", "}", "\n", "}", "\n", "if", "appIteration", ".", "Relationships", ".", "Workitems", "==", "nil", "{", "appIteration", ".", "Relationships", ".", "Workitems", "=", "&", "app", ".", "RelationGeneric", "{", "}", "\n", "}", "\n", "if", "appIteration", ".", "Relationships", ".", "Workitems", ".", "Meta", "==", "nil", "{", "appIteration", ".", "Relationships", ".", "Workitems", ".", "Meta", "=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "}", "\n", "appIteration", ".", "Relationships", ".", "Workitems", ".", "Meta", "[", "KeyTotalWorkItems", "]", "=", "counts", ".", "Total", "\n", "appIteration", ".", "Relationships", ".", "Workitems", ".", "Meta", "[", "KeyClosedWorkItems", "]", "=", "counts", ".", "Closed", "\n", "}", "\n", "}" ]
// updateIterationsWithCounts accepts map of 'iterationID to a workitem.WICountsPerIteration instance'. // This function returns function of type IterationConvertFunc // Inner function is able to access `wiCounts` in closure and it is responsible // for adding 'closed' and 'total' count of WI in relationship's meta for every given iteration.
[ "updateIterationsWithCounts", "accepts", "map", "of", "iterationID", "to", "a", "workitem", ".", "WICountsPerIteration", "instance", ".", "This", "function", "returns", "function", "of", "type", "IterationConvertFunc", "Inner", "function", "is", "able", "to", "access", "wiCounts", "in", "closure", "and", "it", "is", "responsible", "for", "adding", "closed", "and", "total", "count", "of", "WI", "in", "relationship", "s", "meta", "for", "every", "given", "iteration", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/iteration.go#L572-L592
13,366
fabric8-services/fabric8-wit
workitem/link/link_revision_repository.go
Create
func (r *GormWorkItemLinkRevisionRepository) Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, l WorkItemLink) error { log.Debug(nil, map[string]interface{}{ "modifier_id": modifierID, "revision_type": revisionType, }, "Storing a revision after operation on work item link.") tx := r.db revision := &Revision{ ModifierIdentity: modifierID, Time: time.Now(), Type: revisionType, WorkItemLinkID: l.ID, WorkItemLinkVersion: l.Version, WorkItemLinkSourceID: l.SourceID, WorkItemLinkTargetID: l.TargetID, WorkItemLinkTypeID: l.LinkTypeID, } if err := tx.Create(&revision).Error; err != nil { return errors.NewInternalError(ctx, errs.Wrap(err, "failed to create new work item link revision")) } log.Debug(ctx, map[string]interface{}{"wil_id": l.ID}, "work item link revision occurrence created") return nil }
go
func (r *GormWorkItemLinkRevisionRepository) Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, l WorkItemLink) error { log.Debug(nil, map[string]interface{}{ "modifier_id": modifierID, "revision_type": revisionType, }, "Storing a revision after operation on work item link.") tx := r.db revision := &Revision{ ModifierIdentity: modifierID, Time: time.Now(), Type: revisionType, WorkItemLinkID: l.ID, WorkItemLinkVersion: l.Version, WorkItemLinkSourceID: l.SourceID, WorkItemLinkTargetID: l.TargetID, WorkItemLinkTypeID: l.LinkTypeID, } if err := tx.Create(&revision).Error; err != nil { return errors.NewInternalError(ctx, errs.Wrap(err, "failed to create new work item link revision")) } log.Debug(ctx, map[string]interface{}{"wil_id": l.ID}, "work item link revision occurrence created") return nil }
[ "func", "(", "r", "*", "GormWorkItemLinkRevisionRepository", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "modifierID", "uuid", ".", "UUID", ",", "revisionType", "RevisionType", ",", "l", "WorkItemLink", ")", "error", "{", "log", ".", "Debug", "(", "nil", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "modifierID", ",", "\"", "\"", ":", "revisionType", ",", "}", ",", "\"", "\"", ")", "\n", "tx", ":=", "r", ".", "db", "\n", "revision", ":=", "&", "Revision", "{", "ModifierIdentity", ":", "modifierID", ",", "Time", ":", "time", ".", "Now", "(", ")", ",", "Type", ":", "revisionType", ",", "WorkItemLinkID", ":", "l", ".", "ID", ",", "WorkItemLinkVersion", ":", "l", ".", "Version", ",", "WorkItemLinkSourceID", ":", "l", ".", "SourceID", ",", "WorkItemLinkTargetID", ":", "l", ".", "TargetID", ",", "WorkItemLinkTypeID", ":", "l", ".", "LinkTypeID", ",", "}", "\n", "if", "err", ":=", "tx", ".", "Create", "(", "&", "revision", ")", ".", "Error", ";", "err", "!=", "nil", "{", "return", "errors", ".", "NewInternalError", "(", "ctx", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "log", ".", "Debug", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "l", ".", "ID", "}", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// Create stores a new revision for the given work item link.
[ "Create", "stores", "a", "new", "revision", "for", "the", "given", "work", "item", "link", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/link/link_revision_repository.go#L35-L56
13,367
fabric8-services/fabric8-wit
remoteworkitem/trackeritem_repository.go
Upload
func Upload(db *gorm.DB, tID uuid.UUID, item TrackerItemContent) error { remoteID := item.ID content := string(item.Content) var ti TrackerItem if db.Where("remote_item_id = ? AND tracker_id = ?", remoteID, tID).Find(&ti).RecordNotFound() { ti = TrackerItem{ Item: content, RemoteItemID: remoteID, TrackerID: tID} return db.Create(&ti).Error } ti.Item = content return db.Save(&ti).Error }
go
func Upload(db *gorm.DB, tID uuid.UUID, item TrackerItemContent) error { remoteID := item.ID content := string(item.Content) var ti TrackerItem if db.Where("remote_item_id = ? AND tracker_id = ?", remoteID, tID).Find(&ti).RecordNotFound() { ti = TrackerItem{ Item: content, RemoteItemID: remoteID, TrackerID: tID} return db.Create(&ti).Error } ti.Item = content return db.Save(&ti).Error }
[ "func", "Upload", "(", "db", "*", "gorm", ".", "DB", ",", "tID", "uuid", ".", "UUID", ",", "item", "TrackerItemContent", ")", "error", "{", "remoteID", ":=", "item", ".", "ID", "\n", "content", ":=", "string", "(", "item", ".", "Content", ")", "\n\n", "var", "ti", "TrackerItem", "\n", "if", "db", ".", "Where", "(", "\"", "\"", ",", "remoteID", ",", "tID", ")", ".", "Find", "(", "&", "ti", ")", ".", "RecordNotFound", "(", ")", "{", "ti", "=", "TrackerItem", "{", "Item", ":", "content", ",", "RemoteItemID", ":", "remoteID", ",", "TrackerID", ":", "tID", "}", "\n", "return", "db", ".", "Create", "(", "&", "ti", ")", ".", "Error", "\n", "}", "\n", "ti", ".", "Item", "=", "content", "\n", "return", "db", ".", "Save", "(", "&", "ti", ")", ".", "Error", "\n", "}" ]
// Upload imports the items into database
[ "Upload", "imports", "the", "items", "into", "database" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/trackeritem_repository.go#L19-L33
13,368
fabric8-services/fabric8-wit
remoteworkitem/trackeritem_repository.go
ConvertToWorkItemModel
func ConvertToWorkItemModel(ctx context.Context, db *gorm.DB, item TrackerItemContent, tq TrackerSchedule) (*workitem.WorkItem, error) { remoteID := item.ID content := string(item.Content) trackerItem := TrackerItem{Item: content, RemoteItemID: remoteID, TrackerID: tq.TrackerID} // Converting the remote item to a local work item remoteTrackerItemConvertFunc, ok := RemoteWorkItemImplRegistry[tq.TrackerType] if !ok { return nil, BadParameterError{parameter: tq.TrackerType, value: tq.TrackerType} } remoteTrackerItem, err := remoteTrackerItemConvertFunc(trackerItem) if err != nil { return nil, InternalError{simpleError{message: fmt.Sprintf(" Error parsing the tracker data: %s", err.Error())}} } remoteWorkItem, err := Map(remoteTrackerItem, RemoteWorkItemKeyMaps[tq.TrackerType]) if err != nil { return nil, ConversionError{simpleError{message: fmt.Sprintf("Error mapping to local work item: %s", err.Error())}} } workItem, err := setWorkItemFields(ctx, db, remoteWorkItem, tq) if err != nil { return nil, InternalError{simpleError{message: fmt.Sprintf("Error bind assignees: %s", err.Error())}} } return upsert(ctx, db, *workItem) }
go
func ConvertToWorkItemModel(ctx context.Context, db *gorm.DB, item TrackerItemContent, tq TrackerSchedule) (*workitem.WorkItem, error) { remoteID := item.ID content := string(item.Content) trackerItem := TrackerItem{Item: content, RemoteItemID: remoteID, TrackerID: tq.TrackerID} // Converting the remote item to a local work item remoteTrackerItemConvertFunc, ok := RemoteWorkItemImplRegistry[tq.TrackerType] if !ok { return nil, BadParameterError{parameter: tq.TrackerType, value: tq.TrackerType} } remoteTrackerItem, err := remoteTrackerItemConvertFunc(trackerItem) if err != nil { return nil, InternalError{simpleError{message: fmt.Sprintf(" Error parsing the tracker data: %s", err.Error())}} } remoteWorkItem, err := Map(remoteTrackerItem, RemoteWorkItemKeyMaps[tq.TrackerType]) if err != nil { return nil, ConversionError{simpleError{message: fmt.Sprintf("Error mapping to local work item: %s", err.Error())}} } workItem, err := setWorkItemFields(ctx, db, remoteWorkItem, tq) if err != nil { return nil, InternalError{simpleError{message: fmt.Sprintf("Error bind assignees: %s", err.Error())}} } return upsert(ctx, db, *workItem) }
[ "func", "ConvertToWorkItemModel", "(", "ctx", "context", ".", "Context", ",", "db", "*", "gorm", ".", "DB", ",", "item", "TrackerItemContent", ",", "tq", "TrackerSchedule", ")", "(", "*", "workitem", ".", "WorkItem", ",", "error", ")", "{", "remoteID", ":=", "item", ".", "ID", "\n", "content", ":=", "string", "(", "item", ".", "Content", ")", "\n", "trackerItem", ":=", "TrackerItem", "{", "Item", ":", "content", ",", "RemoteItemID", ":", "remoteID", ",", "TrackerID", ":", "tq", ".", "TrackerID", "}", "\n", "// Converting the remote item to a local work item", "remoteTrackerItemConvertFunc", ",", "ok", ":=", "RemoteWorkItemImplRegistry", "[", "tq", ".", "TrackerType", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "BadParameterError", "{", "parameter", ":", "tq", ".", "TrackerType", ",", "value", ":", "tq", ".", "TrackerType", "}", "\n", "}", "\n", "remoteTrackerItem", ",", "err", ":=", "remoteTrackerItemConvertFunc", "(", "trackerItem", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "InternalError", "{", "simpleError", "{", "message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "}", "}", "\n", "}", "\n", "remoteWorkItem", ",", "err", ":=", "Map", "(", "remoteTrackerItem", ",", "RemoteWorkItemKeyMaps", "[", "tq", ".", "TrackerType", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "ConversionError", "{", "simpleError", "{", "message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "}", "}", "\n", "}", "\n", "workItem", ",", "err", ":=", "setWorkItemFields", "(", "ctx", ",", "db", ",", "remoteWorkItem", ",", "tq", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "InternalError", "{", "simpleError", "{", "message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "}", "}", "\n", "}", "\n", "return", "upsert", "(", "ctx", ",", "db", ",", "*", "workItem", ")", "\n", "}" ]
// Map a remote work item into an WIT work item and persist it into the database.
[ "Map", "a", "remote", "work", "item", "into", "an", "WIT", "work", "item", "and", "persist", "it", "into", "the", "database", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/trackeritem_repository.go#L36-L58
13,369
fabric8-services/fabric8-wit
remoteworkitem/trackeritem_repository.go
setWorkItemFields
func setWorkItemFields(ctx context.Context, db *gorm.DB, remoteWorkItem RemoteWorkItem, tq TrackerSchedule) (*workitem.WorkItem, error) { identityRepository := account.NewIdentityRepository(db) //spaceSelfURL := rest.AbsoluteURL(goa.ContextRequest(ctx), app.SpaceHref(spaceID.String())) workItem := workitem.WorkItem{ // ID: remoteWorkItem.ID, Type: tq.WorkItemTypeID, Fields: make(map[string]interface{}), SpaceID: tq.SpaceID, } // copy all fields from remoteworkitem into result workitem for fieldName, fieldValue := range remoteWorkItem.Fields { // creator if fieldName == remoteCreatorLogin { if fieldValue == nil { workItem.Fields[workitem.SystemCreator] = nil continue } creatorLogin := fieldValue.(string) creatorProfileURL := remoteWorkItem.Fields[remoteCreatorProfileURL].(string) identity, err := identityRepository.Lookup(context.Background(), creatorLogin, creatorProfileURL, tq.TrackerType) if err != nil { return nil, errors.Wrap(err, "failed to create identity during lookup") } // associate the identities to the work item workItem.Fields[workitem.SystemCreator] = identity.ID.String() } else if fieldName == remoteCreatorProfileURL { // ignore here, it is being processed above } else // assignees if fieldName == RemoteAssigneeLogins { if fieldValue == nil { workItem.Fields[workitem.SystemAssignees] = make([]string, 0) continue } var identities []string assigneeLogins := fieldValue.([]string) assigneeProfileURLs := remoteWorkItem.Fields[RemoteAssigneeProfileURLs].([]string) for i, assigneeLogin := range assigneeLogins { assigneeProfileURL := assigneeProfileURLs[i] identity, err := identityRepository.Lookup(context.Background(), assigneeLogin, assigneeProfileURL, tq.TrackerType) if err != nil { return nil, err } identities = append(identities, identity.ID.String()) } // associate the identities to the work item workItem.Fields[workitem.SystemAssignees] = identities } else if fieldName == RemoteAssigneeProfileURLs { // ignore here, it is being processed above } else { // copy other fields workItem.Fields[fieldName] = fieldValue } } if tq.TrackerType == ProviderGithub { workItem.Fields[remoteItemURL] = workItem.Fields[remoteItemID] } workItem.Fields[workitem.SystemRemoteTrackerID] = tq.TrackerQueryID.String() return &workItem, nil }
go
func setWorkItemFields(ctx context.Context, db *gorm.DB, remoteWorkItem RemoteWorkItem, tq TrackerSchedule) (*workitem.WorkItem, error) { identityRepository := account.NewIdentityRepository(db) //spaceSelfURL := rest.AbsoluteURL(goa.ContextRequest(ctx), app.SpaceHref(spaceID.String())) workItem := workitem.WorkItem{ // ID: remoteWorkItem.ID, Type: tq.WorkItemTypeID, Fields: make(map[string]interface{}), SpaceID: tq.SpaceID, } // copy all fields from remoteworkitem into result workitem for fieldName, fieldValue := range remoteWorkItem.Fields { // creator if fieldName == remoteCreatorLogin { if fieldValue == nil { workItem.Fields[workitem.SystemCreator] = nil continue } creatorLogin := fieldValue.(string) creatorProfileURL := remoteWorkItem.Fields[remoteCreatorProfileURL].(string) identity, err := identityRepository.Lookup(context.Background(), creatorLogin, creatorProfileURL, tq.TrackerType) if err != nil { return nil, errors.Wrap(err, "failed to create identity during lookup") } // associate the identities to the work item workItem.Fields[workitem.SystemCreator] = identity.ID.String() } else if fieldName == remoteCreatorProfileURL { // ignore here, it is being processed above } else // assignees if fieldName == RemoteAssigneeLogins { if fieldValue == nil { workItem.Fields[workitem.SystemAssignees] = make([]string, 0) continue } var identities []string assigneeLogins := fieldValue.([]string) assigneeProfileURLs := remoteWorkItem.Fields[RemoteAssigneeProfileURLs].([]string) for i, assigneeLogin := range assigneeLogins { assigneeProfileURL := assigneeProfileURLs[i] identity, err := identityRepository.Lookup(context.Background(), assigneeLogin, assigneeProfileURL, tq.TrackerType) if err != nil { return nil, err } identities = append(identities, identity.ID.String()) } // associate the identities to the work item workItem.Fields[workitem.SystemAssignees] = identities } else if fieldName == RemoteAssigneeProfileURLs { // ignore here, it is being processed above } else { // copy other fields workItem.Fields[fieldName] = fieldValue } } if tq.TrackerType == ProviderGithub { workItem.Fields[remoteItemURL] = workItem.Fields[remoteItemID] } workItem.Fields[workitem.SystemRemoteTrackerID] = tq.TrackerQueryID.String() return &workItem, nil }
[ "func", "setWorkItemFields", "(", "ctx", "context", ".", "Context", ",", "db", "*", "gorm", ".", "DB", ",", "remoteWorkItem", "RemoteWorkItem", ",", "tq", "TrackerSchedule", ")", "(", "*", "workitem", ".", "WorkItem", ",", "error", ")", "{", "identityRepository", ":=", "account", ".", "NewIdentityRepository", "(", "db", ")", "\n", "//spaceSelfURL := rest.AbsoluteURL(goa.ContextRequest(ctx), app.SpaceHref(spaceID.String()))", "workItem", ":=", "workitem", ".", "WorkItem", "{", "// ID: remoteWorkItem.ID,", "Type", ":", "tq", ".", "WorkItemTypeID", ",", "Fields", ":", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", ",", "SpaceID", ":", "tq", ".", "SpaceID", ",", "}", "\n", "// copy all fields from remoteworkitem into result workitem", "for", "fieldName", ",", "fieldValue", ":=", "range", "remoteWorkItem", ".", "Fields", "{", "// creator", "if", "fieldName", "==", "remoteCreatorLogin", "{", "if", "fieldValue", "==", "nil", "{", "workItem", ".", "Fields", "[", "workitem", ".", "SystemCreator", "]", "=", "nil", "\n", "continue", "\n", "}", "\n", "creatorLogin", ":=", "fieldValue", ".", "(", "string", ")", "\n", "creatorProfileURL", ":=", "remoteWorkItem", ".", "Fields", "[", "remoteCreatorProfileURL", "]", ".", "(", "string", ")", "\n", "identity", ",", "err", ":=", "identityRepository", ".", "Lookup", "(", "context", ".", "Background", "(", ")", ",", "creatorLogin", ",", "creatorProfileURL", ",", "tq", ".", "TrackerType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "// associate the identities to the work item", "workItem", ".", "Fields", "[", "workitem", ".", "SystemCreator", "]", "=", "identity", ".", "ID", ".", "String", "(", ")", "\n", "}", "else", "if", "fieldName", "==", "remoteCreatorProfileURL", "{", "// ignore here, it is being processed above", "}", "else", "// assignees", "if", "fieldName", "==", "RemoteAssigneeLogins", "{", "if", "fieldValue", "==", "nil", "{", "workItem", ".", "Fields", "[", "workitem", ".", "SystemAssignees", "]", "=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "continue", "\n", "}", "\n", "var", "identities", "[", "]", "string", "\n", "assigneeLogins", ":=", "fieldValue", ".", "(", "[", "]", "string", ")", "\n", "assigneeProfileURLs", ":=", "remoteWorkItem", ".", "Fields", "[", "RemoteAssigneeProfileURLs", "]", ".", "(", "[", "]", "string", ")", "\n", "for", "i", ",", "assigneeLogin", ":=", "range", "assigneeLogins", "{", "assigneeProfileURL", ":=", "assigneeProfileURLs", "[", "i", "]", "\n", "identity", ",", "err", ":=", "identityRepository", ".", "Lookup", "(", "context", ".", "Background", "(", ")", ",", "assigneeLogin", ",", "assigneeProfileURL", ",", "tq", ".", "TrackerType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "identities", "=", "append", "(", "identities", ",", "identity", ".", "ID", ".", "String", "(", ")", ")", "\n", "}", "\n", "// associate the identities to the work item", "workItem", ".", "Fields", "[", "workitem", ".", "SystemAssignees", "]", "=", "identities", "\n", "}", "else", "if", "fieldName", "==", "RemoteAssigneeProfileURLs", "{", "// ignore here, it is being processed above", "}", "else", "{", "// copy other fields", "workItem", ".", "Fields", "[", "fieldName", "]", "=", "fieldValue", "\n", "}", "\n", "}", "\n", "if", "tq", ".", "TrackerType", "==", "ProviderGithub", "{", "workItem", ".", "Fields", "[", "remoteItemURL", "]", "=", "workItem", ".", "Fields", "[", "remoteItemID", "]", "\n", "}", "\n", "workItem", ".", "Fields", "[", "workitem", ".", "SystemRemoteTrackerID", "]", "=", "tq", ".", "TrackerQueryID", ".", "String", "(", ")", "\n", "return", "&", "workItem", ",", "nil", "\n", "}" ]
// setWorkItemFields retrieves data from remoteWorkItem structure and sets it to relevant fields in work item model
[ "setWorkItemFields", "retrieves", "data", "from", "remoteWorkItem", "structure", "and", "sets", "it", "to", "relevant", "fields", "in", "work", "item", "model" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/trackeritem_repository.go#L61-L120
13,370
fabric8-services/fabric8-wit
workitem/workitemtype_repository.go
Load
func (r *GormWorkItemTypeRepository) Load(ctx context.Context, id uuid.UUID) (*WorkItemType, error) { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "load"}, time.Now()) log.Debug(ctx, map[string]interface{}{ "wit_id": id, }, "Loading work item type") res, ok := cache.Get(id) if !ok { log.Info(ctx, map[string]interface{}{ "wit_id": id, }, "Work item type doesn't exist in the cache. Loading from DB...") res = WorkItemType{} db := r.db.Model(&res).Where("id=?", id).First(&res) if db.RecordNotFound() { log.Error(ctx, map[string]interface{}{ "wit_id": id, }, "work item type not found") return nil, errors.NewNotFoundError("work item type", id.String()) } if err := db.Error; err != nil { return nil, errors.NewInternalError(ctx, err) } childTypes, err := r.loadChildTypeList(ctx, res.ID) if err != nil { return nil, errs.Wrapf(err, `failed to load child types for WIT "%s" (%s)`, res.Name, res.ID) } res.ChildTypeIDs = childTypes cache.Put(res) } return &res, nil }
go
func (r *GormWorkItemTypeRepository) Load(ctx context.Context, id uuid.UUID) (*WorkItemType, error) { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "load"}, time.Now()) log.Debug(ctx, map[string]interface{}{ "wit_id": id, }, "Loading work item type") res, ok := cache.Get(id) if !ok { log.Info(ctx, map[string]interface{}{ "wit_id": id, }, "Work item type doesn't exist in the cache. Loading from DB...") res = WorkItemType{} db := r.db.Model(&res).Where("id=?", id).First(&res) if db.RecordNotFound() { log.Error(ctx, map[string]interface{}{ "wit_id": id, }, "work item type not found") return nil, errors.NewNotFoundError("work item type", id.String()) } if err := db.Error; err != nil { return nil, errors.NewInternalError(ctx, err) } childTypes, err := r.loadChildTypeList(ctx, res.ID) if err != nil { return nil, errs.Wrapf(err, `failed to load child types for WIT "%s" (%s)`, res.Name, res.ID) } res.ChildTypeIDs = childTypes cache.Put(res) } return &res, nil }
[ "func", "(", "r", "*", "GormWorkItemTypeRepository", ")", "Load", "(", "ctx", "context", ".", "Context", ",", "id", "uuid", ".", "UUID", ")", "(", "*", "WorkItemType", ",", "error", ")", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "log", ".", "Debug", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "id", ",", "}", ",", "\"", "\"", ")", "\n", "res", ",", "ok", ":=", "cache", ".", "Get", "(", "id", ")", "\n", "if", "!", "ok", "{", "log", ".", "Info", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "id", ",", "}", ",", "\"", "\"", ")", "\n", "res", "=", "WorkItemType", "{", "}", "\n\n", "db", ":=", "r", ".", "db", ".", "Model", "(", "&", "res", ")", ".", "Where", "(", "\"", "\"", ",", "id", ")", ".", "First", "(", "&", "res", ")", "\n", "if", "db", ".", "RecordNotFound", "(", ")", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "id", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "id", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "err", ":=", "db", ".", "Error", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "childTypes", ",", "err", ":=", "r", ".", "loadChildTypeList", "(", "ctx", ",", "res", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrapf", "(", "err", ",", "`failed to load child types for WIT \"%s\" (%s)`", ",", "res", ".", "Name", ",", "res", ".", "ID", ")", "\n", "}", "\n", "res", ".", "ChildTypeIDs", "=", "childTypes", "\n", "cache", ".", "Put", "(", "res", ")", "\n", "}", "\n", "return", "&", "res", ",", "nil", "\n", "}" ]
// Load returns the work item for the given spaceID and id // returns NotFoundError, InternalError
[ "Load", "returns", "the", "work", "item", "for", "the", "given", "spaceID", "and", "id", "returns", "NotFoundError", "InternalError" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype_repository.go#L45-L75
13,371
fabric8-services/fabric8-wit
workitem/workitemtype_repository.go
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) { wit := WorkItemType{ SpaceTemplateID: spaceTemplateID, Name: name, Description: description, Icon: icon, Fields: fields, CanConstruct: canConstruct, } if id != nil { wit.ID = *id } else { wit.ID = uuid.NewV4() } if extendedTypeID != nil && *extendedTypeID != uuid.Nil { wit.Extends = *extendedTypeID } return r.CreateFromModel(ctx, wit) }
go
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) { wit := WorkItemType{ SpaceTemplateID: spaceTemplateID, Name: name, Description: description, Icon: icon, Fields: fields, CanConstruct: canConstruct, } if id != nil { wit.ID = *id } else { wit.ID = uuid.NewV4() } if extendedTypeID != nil && *extendedTypeID != uuid.Nil { wit.Extends = *extendedTypeID } return r.CreateFromModel(ctx, wit) }
[ "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", ")", "{", "wit", ":=", "WorkItemType", "{", "SpaceTemplateID", ":", "spaceTemplateID", ",", "Name", ":", "name", ",", "Description", ":", "description", ",", "Icon", ":", "icon", ",", "Fields", ":", "fields", ",", "CanConstruct", ":", "canConstruct", ",", "}", "\n", "if", "id", "!=", "nil", "{", "wit", ".", "ID", "=", "*", "id", "\n", "}", "else", "{", "wit", ".", "ID", "=", "uuid", ".", "NewV4", "(", ")", "\n", "}", "\n", "if", "extendedTypeID", "!=", "nil", "&&", "*", "extendedTypeID", "!=", "uuid", ".", "Nil", "{", "wit", ".", "Extends", "=", "*", "extendedTypeID", "\n", "}", "\n", "return", "r", ".", "CreateFromModel", "(", "ctx", ",", "wit", ")", "\n", "}" ]
// Create creates a new work item type according to the given parameters.
[ "Create", "creates", "a", "new", "work", "item", "type", "according", "to", "the", "given", "parameters", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype_repository.go#L97-L115
13,372
fabric8-services/fabric8-wit
workitem/workitemtype_repository.go
CreateFromModel
func (r *GormWorkItemTypeRepository) CreateFromModel(ctx context.Context, model WorkItemType) (*WorkItemType, error) { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "create"}, time.Now()) if model.ID == uuid.Nil { model.ID = uuid.NewV4() } allFields := map[string]FieldDefinition{} path := LtreeSafeID(model.ID) if model.Extends != uuid.Nil { extendedType := WorkItemType{} db := r.db.Model(&extendedType).Where("id=?", model.Extends).First(&extendedType) if db.RecordNotFound() { return nil, errors.NewBadParameterError("extendedTypeID", model.Extends) } if err := db.Error; err != nil { return nil, errors.NewInternalError(ctx, err) } // copy fields from extended type for key, value := range extendedType.Fields { allFields[key] = value } path = extendedType.Path + pathSep + path } // now process new fields, checking whether they are already there. for field, definition := range model.Fields { existing, exists := allFields[field] if exists && !compatibleFields(existing, definition) { return nil, errs.Errorf("incompatible change for field %s", field) } allFields[field] = definition } model.Version = 0 model.Path = path model.Fields = allFields db := r.db.Create(&model) if db.Error != nil { return nil, errors.NewInternalError(ctx, db.Error) } return &model, nil }
go
func (r *GormWorkItemTypeRepository) CreateFromModel(ctx context.Context, model WorkItemType) (*WorkItemType, error) { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "create"}, time.Now()) if model.ID == uuid.Nil { model.ID = uuid.NewV4() } allFields := map[string]FieldDefinition{} path := LtreeSafeID(model.ID) if model.Extends != uuid.Nil { extendedType := WorkItemType{} db := r.db.Model(&extendedType).Where("id=?", model.Extends).First(&extendedType) if db.RecordNotFound() { return nil, errors.NewBadParameterError("extendedTypeID", model.Extends) } if err := db.Error; err != nil { return nil, errors.NewInternalError(ctx, err) } // copy fields from extended type for key, value := range extendedType.Fields { allFields[key] = value } path = extendedType.Path + pathSep + path } // now process new fields, checking whether they are already there. for field, definition := range model.Fields { existing, exists := allFields[field] if exists && !compatibleFields(existing, definition) { return nil, errs.Errorf("incompatible change for field %s", field) } allFields[field] = definition } model.Version = 0 model.Path = path model.Fields = allFields db := r.db.Create(&model) if db.Error != nil { return nil, errors.NewInternalError(ctx, db.Error) } return &model, nil }
[ "func", "(", "r", "*", "GormWorkItemTypeRepository", ")", "CreateFromModel", "(", "ctx", "context", ".", "Context", ",", "model", "WorkItemType", ")", "(", "*", "WorkItemType", ",", "error", ")", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n\n", "if", "model", ".", "ID", "==", "uuid", ".", "Nil", "{", "model", ".", "ID", "=", "uuid", ".", "NewV4", "(", ")", "\n", "}", "\n\n", "allFields", ":=", "map", "[", "string", "]", "FieldDefinition", "{", "}", "\n", "path", ":=", "LtreeSafeID", "(", "model", ".", "ID", ")", "\n", "if", "model", ".", "Extends", "!=", "uuid", ".", "Nil", "{", "extendedType", ":=", "WorkItemType", "{", "}", "\n", "db", ":=", "r", ".", "db", ".", "Model", "(", "&", "extendedType", ")", ".", "Where", "(", "\"", "\"", ",", "model", ".", "Extends", ")", ".", "First", "(", "&", "extendedType", ")", "\n", "if", "db", ".", "RecordNotFound", "(", ")", "{", "return", "nil", ",", "errors", ".", "NewBadParameterError", "(", "\"", "\"", ",", "model", ".", "Extends", ")", "\n", "}", "\n", "if", "err", ":=", "db", ".", "Error", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "// copy fields from extended type", "for", "key", ",", "value", ":=", "range", "extendedType", ".", "Fields", "{", "allFields", "[", "key", "]", "=", "value", "\n", "}", "\n", "path", "=", "extendedType", ".", "Path", "+", "pathSep", "+", "path", "\n", "}", "\n", "// now process new fields, checking whether they are already there.", "for", "field", ",", "definition", ":=", "range", "model", ".", "Fields", "{", "existing", ",", "exists", ":=", "allFields", "[", "field", "]", "\n", "if", "exists", "&&", "!", "compatibleFields", "(", "existing", ",", "definition", ")", "{", "return", "nil", ",", "errs", ".", "Errorf", "(", "\"", "\"", ",", "field", ")", "\n", "}", "\n", "allFields", "[", "field", "]", "=", "definition", "\n", "}", "\n\n", "model", ".", "Version", "=", "0", "\n", "model", ".", "Path", "=", "path", "\n", "model", ".", "Fields", "=", "allFields", "\n\n", "db", ":=", "r", ".", "db", ".", "Create", "(", "&", "model", ")", "\n", "if", "db", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "db", ".", "Error", ")", "\n", "}", "\n", "return", "&", "model", ",", "nil", "\n", "}" ]
// CreateFromModel creates a new work item type in the repository based on the // given model of it.
[ "CreateFromModel", "creates", "a", "new", "work", "item", "type", "in", "the", "repository", "based", "on", "the", "given", "model", "of", "it", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype_repository.go#L119-L161
13,373
fabric8-services/fabric8-wit
workitem/workitemtype_repository.go
ListPlannerItemTypes
func (r *GormWorkItemTypeRepository) ListPlannerItemTypes(ctx context.Context, spaceTemplateID uuid.UUID) ([]WorkItemType, error) { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "listPlannerItemTypes"}, time.Now()) // check space template exists if err := spacetemplate.NewRepository(r.db).CheckExists(ctx, spaceTemplateID); err != nil { return nil, errors.NewNotFoundError("space template", spaceTemplateID.String()) } var wits []WorkItemType db := r.db.Select("id").Where("space_template_id = ? AND path::text LIKE '"+path.ConvertToLtree(SystemPlannerItem)+".%'", spaceTemplateID.String()).Order("created_at") if err := db.Find(&wits).Error; err != nil { log.Error(ctx, map[string]interface{}{ "space_template_id": spaceTemplateID, "err": err, }, "unable to list the work item types that derive off of planner item type") return nil, errs.WithStack(err) } for i, wit := range wits { childTypes, err := r.loadChildTypeList(ctx, wit.ID) if err != nil { return nil, errs.Wrapf(err, `failed to load child types for WIT "%s" (%s)`, wit.Name, wit.ID) } wits[i].ChildTypeIDs = childTypes } return wits, nil }
go
func (r *GormWorkItemTypeRepository) ListPlannerItemTypes(ctx context.Context, spaceTemplateID uuid.UUID) ([]WorkItemType, error) { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "listPlannerItemTypes"}, time.Now()) // check space template exists if err := spacetemplate.NewRepository(r.db).CheckExists(ctx, spaceTemplateID); err != nil { return nil, errors.NewNotFoundError("space template", spaceTemplateID.String()) } var wits []WorkItemType db := r.db.Select("id").Where("space_template_id = ? AND path::text LIKE '"+path.ConvertToLtree(SystemPlannerItem)+".%'", spaceTemplateID.String()).Order("created_at") if err := db.Find(&wits).Error; err != nil { log.Error(ctx, map[string]interface{}{ "space_template_id": spaceTemplateID, "err": err, }, "unable to list the work item types that derive off of planner item type") return nil, errs.WithStack(err) } for i, wit := range wits { childTypes, err := r.loadChildTypeList(ctx, wit.ID) if err != nil { return nil, errs.Wrapf(err, `failed to load child types for WIT "%s" (%s)`, wit.Name, wit.ID) } wits[i].ChildTypeIDs = childTypes } return wits, nil }
[ "func", "(", "r", "*", "GormWorkItemTypeRepository", ")", "ListPlannerItemTypes", "(", "ctx", "context", ".", "Context", ",", "spaceTemplateID", "uuid", ".", "UUID", ")", "(", "[", "]", "WorkItemType", ",", "error", ")", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n\n", "// check space template exists", "if", "err", ":=", "spacetemplate", ".", "NewRepository", "(", "r", ".", "db", ")", ".", "CheckExists", "(", "ctx", ",", "spaceTemplateID", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "spaceTemplateID", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "var", "wits", "[", "]", "WorkItemType", "\n", "db", ":=", "r", ".", "db", ".", "Select", "(", "\"", "\"", ")", ".", "Where", "(", "\"", "\"", "+", "path", ".", "ConvertToLtree", "(", "SystemPlannerItem", ")", "+", "\"", "\"", ",", "spaceTemplateID", ".", "String", "(", ")", ")", ".", "Order", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "db", ".", "Find", "(", "&", "wits", ")", ".", "Error", ";", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "spaceTemplateID", ",", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errs", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "for", "i", ",", "wit", ":=", "range", "wits", "{", "childTypes", ",", "err", ":=", "r", ".", "loadChildTypeList", "(", "ctx", ",", "wit", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "Wrapf", "(", "err", ",", "`failed to load child types for WIT \"%s\" (%s)`", ",", "wit", ".", "Name", ",", "wit", ".", "ID", ")", "\n", "}", "\n", "wits", "[", "i", "]", ".", "ChildTypeIDs", "=", "childTypes", "\n", "}", "\n", "return", "wits", ",", "nil", "\n\n", "}" ]
// ListPlannerItemTypes returns work item types that derives from PlannerItem type
[ "ListPlannerItemTypes", "returns", "work", "item", "types", "that", "derives", "from", "PlannerItem", "type" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype_repository.go#L164-L190
13,374
fabric8-services/fabric8-wit
workitem/workitemtype_repository.go
AddChildTypes
func (r *GormWorkItemTypeRepository) AddChildTypes(ctx context.Context, parentTypeID uuid.UUID, childTypeIDs []uuid.UUID) error { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "add_child_types"}, time.Now()) if len(childTypeIDs) <= 0 { return nil } // Create entries for each child in the type list for idx, ID := range childTypeIDs { childType := ChildType{ ParentWorkItemTypeID: parentTypeID, ChildWorkItemTypeID: ID, Position: idx, } db := r.db.Create(&childType) if db.Error != nil { return errors.NewInternalError(ctx, db.Error) } } ClearGlobalWorkItemTypeCache() return nil }
go
func (r *GormWorkItemTypeRepository) AddChildTypes(ctx context.Context, parentTypeID uuid.UUID, childTypeIDs []uuid.UUID) error { defer goa.MeasureSince([]string{"goa", "db", "workitemtype", "add_child_types"}, time.Now()) if len(childTypeIDs) <= 0 { return nil } // Create entries for each child in the type list for idx, ID := range childTypeIDs { childType := ChildType{ ParentWorkItemTypeID: parentTypeID, ChildWorkItemTypeID: ID, Position: idx, } db := r.db.Create(&childType) if db.Error != nil { return errors.NewInternalError(ctx, db.Error) } } ClearGlobalWorkItemTypeCache() return nil }
[ "func", "(", "r", "*", "GormWorkItemTypeRepository", ")", "AddChildTypes", "(", "ctx", "context", ".", "Context", ",", "parentTypeID", "uuid", ".", "UUID", ",", "childTypeIDs", "[", "]", "uuid", ".", "UUID", ")", "error", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "if", "len", "(", "childTypeIDs", ")", "<=", "0", "{", "return", "nil", "\n", "}", "\n", "// Create entries for each child in the type list", "for", "idx", ",", "ID", ":=", "range", "childTypeIDs", "{", "childType", ":=", "ChildType", "{", "ParentWorkItemTypeID", ":", "parentTypeID", ",", "ChildWorkItemTypeID", ":", "ID", ",", "Position", ":", "idx", ",", "}", "\n", "db", ":=", "r", ".", "db", ".", "Create", "(", "&", "childType", ")", "\n", "if", "db", ".", "Error", "!=", "nil", "{", "return", "errors", ".", "NewInternalError", "(", "ctx", ",", "db", ".", "Error", ")", "\n", "}", "\n", "}", "\n", "ClearGlobalWorkItemTypeCache", "(", ")", "\n", "return", "nil", "\n\n", "}" ]
// AddChildTypes adds the given child work item types to the parent work item // type.
[ "AddChildTypes", "adds", "the", "given", "child", "work", "item", "types", "to", "the", "parent", "work", "item", "type", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype_repository.go#L235-L255
13,375
fabric8-services/fabric8-wit
workitem/workitemtype_repository.go
loadChildTypeList
func (r *GormWorkItemTypeRepository) loadChildTypeList(ctx context.Context, parentTypeID uuid.UUID) ([]uuid.UUID, error) { types := []ChildType{} db := r.db.Model(&types).Where("parent_work_item_type_id=?", parentTypeID).Order("position ASC").Find(&types) if db.RecordNotFound() { log.Error(ctx, map[string]interface{}{"wit_id": parentTypeID}, "work item type child types not found") return nil, errors.NewNotFoundError("work item type child types", parentTypeID.String()) } if err := db.Error; err != nil { return nil, errors.NewInternalError(ctx, err) } res := make([]uuid.UUID, len(types)) for i, childType := range types { res[i] = childType.ChildWorkItemTypeID } return res, nil }
go
func (r *GormWorkItemTypeRepository) loadChildTypeList(ctx context.Context, parentTypeID uuid.UUID) ([]uuid.UUID, error) { types := []ChildType{} db := r.db.Model(&types).Where("parent_work_item_type_id=?", parentTypeID).Order("position ASC").Find(&types) if db.RecordNotFound() { log.Error(ctx, map[string]interface{}{"wit_id": parentTypeID}, "work item type child types not found") return nil, errors.NewNotFoundError("work item type child types", parentTypeID.String()) } if err := db.Error; err != nil { return nil, errors.NewInternalError(ctx, err) } res := make([]uuid.UUID, len(types)) for i, childType := range types { res[i] = childType.ChildWorkItemTypeID } return res, nil }
[ "func", "(", "r", "*", "GormWorkItemTypeRepository", ")", "loadChildTypeList", "(", "ctx", "context", ".", "Context", ",", "parentTypeID", "uuid", ".", "UUID", ")", "(", "[", "]", "uuid", ".", "UUID", ",", "error", ")", "{", "types", ":=", "[", "]", "ChildType", "{", "}", "\n", "db", ":=", "r", ".", "db", ".", "Model", "(", "&", "types", ")", ".", "Where", "(", "\"", "\"", ",", "parentTypeID", ")", ".", "Order", "(", "\"", "\"", ")", ".", "Find", "(", "&", "types", ")", "\n", "if", "db", ".", "RecordNotFound", "(", ")", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "parentTypeID", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "parentTypeID", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "err", ":=", "db", ".", "Error", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "res", ":=", "make", "(", "[", "]", "uuid", ".", "UUID", ",", "len", "(", "types", ")", ")", "\n", "for", "i", ",", "childType", ":=", "range", "types", "{", "res", "[", "i", "]", "=", "childType", ".", "ChildWorkItemTypeID", "\n", "}", "\n", "return", "res", ",", "nil", "\n", "}" ]
// loadChildTypeList loads all child work item types associated with the given // work item type
[ "loadChildTypeList", "loads", "all", "child", "work", "item", "types", "associated", "with", "the", "given", "work", "item", "type" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype_repository.go#L259-L274
13,376
fabric8-services/fabric8-wit
remoteworkitem/tracker_repository.go
Create
func (r *GormTrackerRepository) Create(ctx context.Context, t *Tracker) error { //URL Validation isValid := govalidator.IsURL(t.URL) if isValid != true { return BadParameterError{parameter: "url", value: t.URL} } _, present := RemoteWorkItemImplRegistry[t.Type] // Ensure we support this remote tracker. if present != true { return BadParameterError{parameter: "type", value: t.Type} } if err := r.db.Create(&t).Error; err != nil { return InternalError{simpleError{err.Error()}} } log.Info(ctx, map[string]interface{}{ "tracker": t, }, "Tracker reposity created") return nil }
go
func (r *GormTrackerRepository) Create(ctx context.Context, t *Tracker) error { //URL Validation isValid := govalidator.IsURL(t.URL) if isValid != true { return BadParameterError{parameter: "url", value: t.URL} } _, present := RemoteWorkItemImplRegistry[t.Type] // Ensure we support this remote tracker. if present != true { return BadParameterError{parameter: "type", value: t.Type} } if err := r.db.Create(&t).Error; err != nil { return InternalError{simpleError{err.Error()}} } log.Info(ctx, map[string]interface{}{ "tracker": t, }, "Tracker reposity created") return nil }
[ "func", "(", "r", "*", "GormTrackerRepository", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "t", "*", "Tracker", ")", "error", "{", "//URL Validation", "isValid", ":=", "govalidator", ".", "IsURL", "(", "t", ".", "URL", ")", "\n", "if", "isValid", "!=", "true", "{", "return", "BadParameterError", "{", "parameter", ":", "\"", "\"", ",", "value", ":", "t", ".", "URL", "}", "\n", "}", "\n\n", "_", ",", "present", ":=", "RemoteWorkItemImplRegistry", "[", "t", ".", "Type", "]", "\n", "// Ensure we support this remote tracker.", "if", "present", "!=", "true", "{", "return", "BadParameterError", "{", "parameter", ":", "\"", "\"", ",", "value", ":", "t", ".", "Type", "}", "\n", "}", "\n", "if", "err", ":=", "r", ".", "db", ".", "Create", "(", "&", "t", ")", ".", "Error", ";", "err", "!=", "nil", "{", "return", "InternalError", "{", "simpleError", "{", "err", ".", "Error", "(", ")", "}", "}", "\n", "}", "\n", "log", ".", "Info", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "t", ",", "}", ",", "\"", "\"", ")", "\n\n", "return", "nil", "\n", "}" ]
// Create creates a new tracker configuration in the repository // returns BadParameterError, ConversionError or InternalError
[ "Create", "creates", "a", "new", "tracker", "configuration", "in", "the", "repository", "returns", "BadParameterError", "ConversionError", "or", "InternalError" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/tracker_repository.go#L44-L64
13,377
fabric8-services/fabric8-wit
remoteworkitem/tracker_repository.go
Save
func (r *GormTrackerRepository) Save(ctx context.Context, t *Tracker) (*Tracker, error) { defer goa.MeasureSince([]string{"goa", "db", "tracker", "save"}, time.Now()) res := Tracker{} tx := r.db.Where("id = ?", t.ID).Find(&res) if tx.RecordNotFound() { log.Error(ctx, map[string]interface{}{ "err": tx.Error, "tracker_id": t.ID, }, "tracker repository not found") return nil, errors.NewNotFoundError("tracker", t.ID.String()) } _, present := RemoteWorkItemImplRegistry[t.Type] // Ensure we support this remote tracker. if present != true { return nil, errors.NewBadParameterError("type", t.Type) } if err := tx.Save(&t).Error; err != nil { log.Error(ctx, map[string]interface{}{ "tracker_id": t.ID, "err": err, }, "unable to save tracker repository") return nil, errors.NewInternalError(ctx, err) } return t, nil }
go
func (r *GormTrackerRepository) Save(ctx context.Context, t *Tracker) (*Tracker, error) { defer goa.MeasureSince([]string{"goa", "db", "tracker", "save"}, time.Now()) res := Tracker{} tx := r.db.Where("id = ?", t.ID).Find(&res) if tx.RecordNotFound() { log.Error(ctx, map[string]interface{}{ "err": tx.Error, "tracker_id": t.ID, }, "tracker repository not found") return nil, errors.NewNotFoundError("tracker", t.ID.String()) } _, present := RemoteWorkItemImplRegistry[t.Type] // Ensure we support this remote tracker. if present != true { return nil, errors.NewBadParameterError("type", t.Type) } if err := tx.Save(&t).Error; err != nil { log.Error(ctx, map[string]interface{}{ "tracker_id": t.ID, "err": err, }, "unable to save tracker repository") return nil, errors.NewInternalError(ctx, err) } return t, nil }
[ "func", "(", "r", "*", "GormTrackerRepository", ")", "Save", "(", "ctx", "context", ".", "Context", ",", "t", "*", "Tracker", ")", "(", "*", "Tracker", ",", "error", ")", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "res", ":=", "Tracker", "{", "}", "\n", "tx", ":=", "r", ".", "db", ".", "Where", "(", "\"", "\"", ",", "t", ".", "ID", ")", ".", "Find", "(", "&", "res", ")", "\n", "if", "tx", ".", "RecordNotFound", "(", ")", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "tx", ".", "Error", ",", "\"", "\"", ":", "t", ".", "ID", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "t", ".", "ID", ".", "String", "(", ")", ")", "\n", "}", "\n", "_", ",", "present", ":=", "RemoteWorkItemImplRegistry", "[", "t", ".", "Type", "]", "\n", "// Ensure we support this remote tracker.", "if", "present", "!=", "true", "{", "return", "nil", ",", "errors", ".", "NewBadParameterError", "(", "\"", "\"", ",", "t", ".", "Type", ")", "\n", "}", "\n\n", "if", "err", ":=", "tx", ".", "Save", "(", "&", "t", ")", ".", "Error", ";", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "t", ".", "ID", ",", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errors", ".", "NewInternalError", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "return", "t", ",", "nil", "\n", "}" ]
// Save updates the given tracker in storage. // returns NotFoundError, ConversionError or InternalError
[ "Save", "updates", "the", "given", "tracker", "in", "storage", ".", "returns", "NotFoundError", "ConversionError", "or", "InternalError" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/tracker_repository.go#L107-L132
13,378
fabric8-services/fabric8-wit
remoteworkitem/tracker_repository.go
Delete
func (r *GormTrackerRepository) Delete(ctx context.Context, ID uuid.UUID) error { defer goa.MeasureSince([]string{"goa", "db", "tracker", "delete"}, time.Now()) if ID == uuid.Nil { log.Error(ctx, map[string]interface{}{ "err": errors.NewNotFoundError("tracker", ID.String()), "tracker_id": ID.String(), }, "unable to find the tracker by ID") return errors.NewNotFoundError("tracker", ID.String()) } var t = Tracker{ID: ID} tx := r.db.Delete(t) if err := tx.Error; err != nil { log.Error(ctx, map[string]interface{}{ "err": err, "tracker_id": ID.String(), }, "unable to delete the space") return errors.NewInternalError(ctx, err) } if tx.RowsAffected == 0 { log.Error(ctx, map[string]interface{}{ "err": tx.Error, "space_id": ID.String(), }, "none row was affected by the deletion operation") return errors.NewNotFoundError("space", ID.String()) } return nil }
go
func (r *GormTrackerRepository) Delete(ctx context.Context, ID uuid.UUID) error { defer goa.MeasureSince([]string{"goa", "db", "tracker", "delete"}, time.Now()) if ID == uuid.Nil { log.Error(ctx, map[string]interface{}{ "err": errors.NewNotFoundError("tracker", ID.String()), "tracker_id": ID.String(), }, "unable to find the tracker by ID") return errors.NewNotFoundError("tracker", ID.String()) } var t = Tracker{ID: ID} tx := r.db.Delete(t) if err := tx.Error; err != nil { log.Error(ctx, map[string]interface{}{ "err": err, "tracker_id": ID.String(), }, "unable to delete the space") return errors.NewInternalError(ctx, err) } if tx.RowsAffected == 0 { log.Error(ctx, map[string]interface{}{ "err": tx.Error, "space_id": ID.String(), }, "none row was affected by the deletion operation") return errors.NewNotFoundError("space", ID.String()) } return nil }
[ "func", "(", "r", "*", "GormTrackerRepository", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "ID", "uuid", ".", "UUID", ")", "error", "{", "defer", "goa", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "if", "ID", "==", "uuid", ".", "Nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ID", ".", "String", "(", ")", ")", ",", "\"", "\"", ":", "ID", ".", "String", "(", ")", ",", "}", ",", "\"", "\"", ")", "\n", "return", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ID", ".", "String", "(", ")", ")", "\n", "}", "\n", "var", "t", "=", "Tracker", "{", "ID", ":", "ID", "}", "\n", "tx", ":=", "r", ".", "db", ".", "Delete", "(", "t", ")", "\n", "if", "err", ":=", "tx", ".", "Error", ";", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "\"", "\"", ":", "ID", ".", "String", "(", ")", ",", "}", ",", "\"", "\"", ")", "\n", "return", "errors", ".", "NewInternalError", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "if", "tx", ".", "RowsAffected", "==", "0", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "tx", ".", "Error", ",", "\"", "\"", ":", "ID", ".", "String", "(", ")", ",", "}", ",", "\"", "\"", ")", "\n", "return", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ID", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete deletes the tracker with the given id // returns NotFoundError or InternalError
[ "Delete", "deletes", "the", "tracker", "with", "the", "given", "id", "returns", "NotFoundError", "or", "InternalError" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/tracker_repository.go#L136-L162
13,379
fabric8-services/fabric8-wit
closeable/close.go
Close
func Close(ctx context.Context, c io.Closer) { // need to verify that the value of the `c` interface if not nil, too if c != nil && !reflect.ValueOf(c).IsNil() { err := c.Close() if err != nil { log.Error(ctx, map[string]interface{}{"error": err.Error()}, "error while closing the resource") } } }
go
func Close(ctx context.Context, c io.Closer) { // need to verify that the value of the `c` interface if not nil, too if c != nil && !reflect.ValueOf(c).IsNil() { err := c.Close() if err != nil { log.Error(ctx, map[string]interface{}{"error": err.Error()}, "error while closing the resource") } } }
[ "func", "Close", "(", "ctx", "context", ".", "Context", ",", "c", "io", ".", "Closer", ")", "{", "// need to verify that the value of the `c` interface if not nil, too", "if", "c", "!=", "nil", "&&", "!", "reflect", ".", "ValueOf", "(", "c", ")", ".", "IsNil", "(", ")", "{", "err", ":=", "c", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", "}", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "}" ]
// Close closes the given resource and logs the error if something wrong happened
[ "Close", "closes", "the", "given", "resource", "and", "logs", "the", "error", "if", "something", "wrong", "happened" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/closeable/close.go#L12-L21
13,380
fabric8-services/fabric8-wit
controller/render.go
Render
func (c *RenderController) Render(ctx *app.RenderRenderContext) error { content := ctx.Payload.Data.Attributes.Content markup := ctx.Payload.Data.Attributes.Markup if !rendering.IsMarkupSupported(markup) { return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("Unsupported markup type", markup)) } htmlResult := rendering.RenderMarkupToHTML(content, markup) res := &app.MarkupRenderingSingle{Data: &app.MarkupRenderingData{ ID: uuid.NewV4().String(), Type: RenderingType, Attributes: &app.MarkupRenderingDataAttributes{ RenderedContent: htmlResult, }}} return ctx.OK(res) }
go
func (c *RenderController) Render(ctx *app.RenderRenderContext) error { content := ctx.Payload.Data.Attributes.Content markup := ctx.Payload.Data.Attributes.Markup if !rendering.IsMarkupSupported(markup) { return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("Unsupported markup type", markup)) } htmlResult := rendering.RenderMarkupToHTML(content, markup) res := &app.MarkupRenderingSingle{Data: &app.MarkupRenderingData{ ID: uuid.NewV4().String(), Type: RenderingType, Attributes: &app.MarkupRenderingDataAttributes{ RenderedContent: htmlResult, }}} return ctx.OK(res) }
[ "func", "(", "c", "*", "RenderController", ")", "Render", "(", "ctx", "*", "app", ".", "RenderRenderContext", ")", "error", "{", "content", ":=", "ctx", ".", "Payload", ".", "Data", ".", "Attributes", ".", "Content", "\n", "markup", ":=", "ctx", ".", "Payload", ".", "Data", ".", "Attributes", ".", "Markup", "\n", "if", "!", "rendering", ".", "IsMarkupSupported", "(", "markup", ")", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewBadParameterError", "(", "\"", "\"", ",", "markup", ")", ")", "\n", "}", "\n", "htmlResult", ":=", "rendering", ".", "RenderMarkupToHTML", "(", "content", ",", "markup", ")", "\n", "res", ":=", "&", "app", ".", "MarkupRenderingSingle", "{", "Data", ":", "&", "app", ".", "MarkupRenderingData", "{", "ID", ":", "uuid", ".", "NewV4", "(", ")", ".", "String", "(", ")", ",", "Type", ":", "RenderingType", ",", "Attributes", ":", "&", "app", ".", "MarkupRenderingDataAttributes", "{", "RenderedContent", ":", "htmlResult", ",", "}", "}", "}", "\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// Render runs the render action.
[ "Render", "runs", "the", "render", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/render.go#L28-L42
13,381
fabric8-services/fabric8-wit
jsonapi/jsonapi_utility.go
ErrorToJSONAPIError
func ErrorToJSONAPIError(ctx context.Context, err error) (app.JSONAPIError, int) { cause := errs.Cause(err) detail := cause.Error() var title, code string var statusCode int var id *string log.Error(ctx, map[string]interface{}{"err": cause, "error_message": cause.Error(), "err_type": reflect.TypeOf(cause)}, "an error occurred in our api") switch cause.(type) { case errors.NotFoundError: code = ErrorCodeNotFound title = "Not found error" statusCode = http.StatusNotFound case errors.ConversionError: code = ErrorCodeConversionError title = "Conversion error" statusCode = http.StatusBadRequest case errors.BadParameterError: code = ErrorCodeBadParameter title = "Bad parameter error" statusCode = http.StatusBadRequest case errors.VersionConflictError: code = ErrorCodeVersionConflict title = "Version conflict error" statusCode = http.StatusConflict case errors.DataConflictError: code = ErrorCodeDataConflict title = "Data conflict error" statusCode = http.StatusConflict case errors.InternalError: code = ErrorCodeInternalError title = "Internal error" statusCode = http.StatusInternalServerError case errors.UnauthorizedError: code = ErrorCodeUnauthorizedError title = "Unauthorized error" statusCode = http.StatusUnauthorized case errors.ForbiddenError: code = ErrorCodeForbiddenError title = "Forbidden error" statusCode = http.StatusForbidden default: code = ErrorCodeUnknownError title = "Unknown error" statusCode = http.StatusInternalServerError cause := errs.Cause(err) if err, ok := cause.(goa.ServiceError); ok { statusCode = err.ResponseStatus() idStr := err.Token() id = &idStr title = http.StatusText(statusCode) } if errResp, ok := cause.(*goa.ErrorResponse); ok { code = errResp.Code detail = errResp.Detail } } statusCodeStr := strconv.Itoa(statusCode) jerr := app.JSONAPIError{ ID: id, Code: &code, Status: &statusCodeStr, Title: &title, Detail: detail, } return jerr, statusCode }
go
func ErrorToJSONAPIError(ctx context.Context, err error) (app.JSONAPIError, int) { cause := errs.Cause(err) detail := cause.Error() var title, code string var statusCode int var id *string log.Error(ctx, map[string]interface{}{"err": cause, "error_message": cause.Error(), "err_type": reflect.TypeOf(cause)}, "an error occurred in our api") switch cause.(type) { case errors.NotFoundError: code = ErrorCodeNotFound title = "Not found error" statusCode = http.StatusNotFound case errors.ConversionError: code = ErrorCodeConversionError title = "Conversion error" statusCode = http.StatusBadRequest case errors.BadParameterError: code = ErrorCodeBadParameter title = "Bad parameter error" statusCode = http.StatusBadRequest case errors.VersionConflictError: code = ErrorCodeVersionConflict title = "Version conflict error" statusCode = http.StatusConflict case errors.DataConflictError: code = ErrorCodeDataConflict title = "Data conflict error" statusCode = http.StatusConflict case errors.InternalError: code = ErrorCodeInternalError title = "Internal error" statusCode = http.StatusInternalServerError case errors.UnauthorizedError: code = ErrorCodeUnauthorizedError title = "Unauthorized error" statusCode = http.StatusUnauthorized case errors.ForbiddenError: code = ErrorCodeForbiddenError title = "Forbidden error" statusCode = http.StatusForbidden default: code = ErrorCodeUnknownError title = "Unknown error" statusCode = http.StatusInternalServerError cause := errs.Cause(err) if err, ok := cause.(goa.ServiceError); ok { statusCode = err.ResponseStatus() idStr := err.Token() id = &idStr title = http.StatusText(statusCode) } if errResp, ok := cause.(*goa.ErrorResponse); ok { code = errResp.Code detail = errResp.Detail } } statusCodeStr := strconv.Itoa(statusCode) jerr := app.JSONAPIError{ ID: id, Code: &code, Status: &statusCodeStr, Title: &title, Detail: detail, } return jerr, statusCode }
[ "func", "ErrorToJSONAPIError", "(", "ctx", "context", ".", "Context", ",", "err", "error", ")", "(", "app", ".", "JSONAPIError", ",", "int", ")", "{", "cause", ":=", "errs", ".", "Cause", "(", "err", ")", "\n", "detail", ":=", "cause", ".", "Error", "(", ")", "\n", "var", "title", ",", "code", "string", "\n", "var", "statusCode", "int", "\n", "var", "id", "*", "string", "\n", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "cause", ",", "\"", "\"", ":", "cause", ".", "Error", "(", ")", ",", "\"", "\"", ":", "reflect", ".", "TypeOf", "(", "cause", ")", "}", ",", "\"", "\"", ")", "\n", "switch", "cause", ".", "(", "type", ")", "{", "case", "errors", ".", "NotFoundError", ":", "code", "=", "ErrorCodeNotFound", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusNotFound", "\n", "case", "errors", ".", "ConversionError", ":", "code", "=", "ErrorCodeConversionError", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusBadRequest", "\n", "case", "errors", ".", "BadParameterError", ":", "code", "=", "ErrorCodeBadParameter", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusBadRequest", "\n", "case", "errors", ".", "VersionConflictError", ":", "code", "=", "ErrorCodeVersionConflict", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusConflict", "\n", "case", "errors", ".", "DataConflictError", ":", "code", "=", "ErrorCodeDataConflict", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusConflict", "\n", "case", "errors", ".", "InternalError", ":", "code", "=", "ErrorCodeInternalError", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusInternalServerError", "\n", "case", "errors", ".", "UnauthorizedError", ":", "code", "=", "ErrorCodeUnauthorizedError", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusUnauthorized", "\n", "case", "errors", ".", "ForbiddenError", ":", "code", "=", "ErrorCodeForbiddenError", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusForbidden", "\n", "default", ":", "code", "=", "ErrorCodeUnknownError", "\n", "title", "=", "\"", "\"", "\n", "statusCode", "=", "http", ".", "StatusInternalServerError", "\n\n", "cause", ":=", "errs", ".", "Cause", "(", "err", ")", "\n", "if", "err", ",", "ok", ":=", "cause", ".", "(", "goa", ".", "ServiceError", ")", ";", "ok", "{", "statusCode", "=", "err", ".", "ResponseStatus", "(", ")", "\n", "idStr", ":=", "err", ".", "Token", "(", ")", "\n", "id", "=", "&", "idStr", "\n", "title", "=", "http", ".", "StatusText", "(", "statusCode", ")", "\n", "}", "\n", "if", "errResp", ",", "ok", ":=", "cause", ".", "(", "*", "goa", ".", "ErrorResponse", ")", ";", "ok", "{", "code", "=", "errResp", ".", "Code", "\n", "detail", "=", "errResp", ".", "Detail", "\n", "}", "\n", "}", "\n", "statusCodeStr", ":=", "strconv", ".", "Itoa", "(", "statusCode", ")", "\n", "jerr", ":=", "app", ".", "JSONAPIError", "{", "ID", ":", "id", ",", "Code", ":", "&", "code", ",", "Status", ":", "&", "statusCodeStr", ",", "Title", ":", "&", "title", ",", "Detail", ":", "detail", ",", "}", "\n", "return", "jerr", ",", "statusCode", "\n", "}" ]
// ErrorToJSONAPIError returns the JSONAPI representation // of an error and the HTTP status code that will be associated with it. // This function knows about the models package and the errors from there // as well as goa error classes.
[ "ErrorToJSONAPIError", "returns", "the", "JSONAPI", "representation", "of", "an", "error", "and", "the", "HTTP", "status", "code", "that", "will", "be", "associated", "with", "it", ".", "This", "function", "knows", "about", "the", "models", "package", "and", "the", "errors", "from", "there", "as", "well", "as", "goa", "error", "classes", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/jsonapi/jsonapi_utility.go#L37-L103
13,382
fabric8-services/fabric8-wit
jsonapi/jsonapi_utility.go
ErrorToJSONAPIErrors
func ErrorToJSONAPIErrors(ctx context.Context, err error) (*app.JSONAPIErrors, int) { jerr, httpStatusCode := ErrorToJSONAPIError(ctx, err) jerrors := app.JSONAPIErrors{} jerrors.Errors = append(jerrors.Errors, &jerr) return &jerrors, httpStatusCode }
go
func ErrorToJSONAPIErrors(ctx context.Context, err error) (*app.JSONAPIErrors, int) { jerr, httpStatusCode := ErrorToJSONAPIError(ctx, err) jerrors := app.JSONAPIErrors{} jerrors.Errors = append(jerrors.Errors, &jerr) return &jerrors, httpStatusCode }
[ "func", "ErrorToJSONAPIErrors", "(", "ctx", "context", ".", "Context", ",", "err", "error", ")", "(", "*", "app", ".", "JSONAPIErrors", ",", "int", ")", "{", "jerr", ",", "httpStatusCode", ":=", "ErrorToJSONAPIError", "(", "ctx", ",", "err", ")", "\n", "jerrors", ":=", "app", ".", "JSONAPIErrors", "{", "}", "\n", "jerrors", ".", "Errors", "=", "append", "(", "jerrors", ".", "Errors", ",", "&", "jerr", ")", "\n", "return", "&", "jerrors", ",", "httpStatusCode", "\n", "}" ]
// ErrorToJSONAPIErrors is a convenience function if you // just want to return one error from the models package as a JSONAPI errors // array.
[ "ErrorToJSONAPIErrors", "is", "a", "convenience", "function", "if", "you", "just", "want", "to", "return", "one", "error", "from", "the", "models", "package", "as", "a", "JSONAPI", "errors", "array", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/jsonapi/jsonapi_utility.go#L108-L113
13,383
fabric8-services/fabric8-wit
controller/workitems.go
NewWorkitemsController
func NewWorkitemsController(service *goa.Service, db application.DB, config WorkItemControllerConfig) *WorkitemsController { return NewNotifyingWorkitemsController(service, db, &notification.DevNullChannel{}, config) }
go
func NewWorkitemsController(service *goa.Service, db application.DB, config WorkItemControllerConfig) *WorkitemsController { return NewNotifyingWorkitemsController(service, db, &notification.DevNullChannel{}, config) }
[ "func", "NewWorkitemsController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "config", "WorkItemControllerConfig", ")", "*", "WorkitemsController", "{", "return", "NewNotifyingWorkitemsController", "(", "service", ",", "db", ",", "&", "notification", ".", "DevNullChannel", "{", "}", ",", "config", ")", "\n", "}" ]
// NewWorkitemsController creates a workitems controller.
[ "NewWorkitemsController", "creates", "a", "workitems", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/workitems.go#L35-L37
13,384
fabric8-services/fabric8-wit
controller/workitems.go
NewNotifyingWorkitemsController
func NewNotifyingWorkitemsController(service *goa.Service, db application.DB, notificationChannel notification.Channel, config WorkItemControllerConfig) *WorkitemsController { n := notificationChannel if n == nil { n = &notification.DevNullChannel{} } return &WorkitemsController{ Controller: service.NewController("WorkitemController"), db: db, notification: n, config: config} }
go
func NewNotifyingWorkitemsController(service *goa.Service, db application.DB, notificationChannel notification.Channel, config WorkItemControllerConfig) *WorkitemsController { n := notificationChannel if n == nil { n = &notification.DevNullChannel{} } return &WorkitemsController{ Controller: service.NewController("WorkitemController"), db: db, notification: n, config: config} }
[ "func", "NewNotifyingWorkitemsController", "(", "service", "*", "goa", ".", "Service", ",", "db", "application", ".", "DB", ",", "notificationChannel", "notification", ".", "Channel", ",", "config", "WorkItemControllerConfig", ")", "*", "WorkitemsController", "{", "n", ":=", "notificationChannel", "\n", "if", "n", "==", "nil", "{", "n", "=", "&", "notification", ".", "DevNullChannel", "{", "}", "\n", "}", "\n", "return", "&", "WorkitemsController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "db", ":", "db", ",", "notification", ":", "n", ",", "config", ":", "config", "}", "\n", "}" ]
// NewNotifyingWorkitemsController creates a workitem controller with notification broadcast.
[ "NewNotifyingWorkitemsController", "creates", "a", "workitem", "controller", "with", "notification", "broadcast", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/workitems.go#L40-L50
13,385
fabric8-services/fabric8-wit
controller/deployments.go
NewDeploymentsController
func NewDeploymentsController(service *goa.Service, config *configuration.Registry) *DeploymentsController { return &DeploymentsController{ Controller: service.NewController("DeploymentsController"), Config: config, ClientGetter: &defaultClientGetter{ config: config, }, } }
go
func NewDeploymentsController(service *goa.Service, config *configuration.Registry) *DeploymentsController { return &DeploymentsController{ Controller: service.NewController("DeploymentsController"), Config: config, ClientGetter: &defaultClientGetter{ config: config, }, } }
[ "func", "NewDeploymentsController", "(", "service", "*", "goa", ".", "Service", ",", "config", "*", "configuration", ".", "Registry", ")", "*", "DeploymentsController", "{", "return", "&", "DeploymentsController", "{", "Controller", ":", "service", ".", "NewController", "(", "\"", "\"", ")", ",", "Config", ":", "config", ",", "ClientGetter", ":", "&", "defaultClientGetter", "{", "config", ":", "config", ",", "}", ",", "}", "\n", "}" ]
// NewDeploymentsController creates a deployments controller.
[ "NewDeploymentsController", "creates", "a", "deployments", "controller", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L46-L54
13,386
fabric8-services/fabric8-wit
controller/deployments.go
GetKubeClient
func (g *defaultClientGetter) GetKubeClient(ctx context.Context) (kubernetes.KubeClientInterface, error) { kubeNamespaceName, err := g.getNamespaceName(ctx) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "could not retrieve namespace name") return nil, errs.Wrap(err, "could not retrieve namespace name") } osioclient, err := g.GetAndCheckOSIOClient(ctx) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "could not create OSIO client") return nil, err } baseURLProvider, err := NewURLProvider(ctx, g.config, osioclient) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "could not retrieve tenant data") return nil, errs.Wrap(err, "could not retrieve tenant data") } /* Timeout used per HTTP request to Kubernetes/OpenShift API servers. * Communication with Hawkular currently uses a hard-coded 30 second * timeout per request, and does not use this parameter. */ // create the cluster API client kubeConfig := &kubernetes.KubeClientConfig{ BaseURLProvider: baseURLProvider, UserNamespace: *kubeNamespaceName, Timeout: g.config.GetDeploymentsHTTPTimeoutSeconds(), } kc, err := kubernetes.NewKubeClient(kubeConfig) if err != nil { url, _ := baseURLProvider.GetAPIURL() log.Error(ctx, map[string]interface{}{ "err": err, "user_namespace": *kubeNamespaceName, "cluster": *url, }, "could not create Kubernetes client object") return nil, errs.Wrap(err, "could not create Kubernetes client object") } return kc, nil }
go
func (g *defaultClientGetter) GetKubeClient(ctx context.Context) (kubernetes.KubeClientInterface, error) { kubeNamespaceName, err := g.getNamespaceName(ctx) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "could not retrieve namespace name") return nil, errs.Wrap(err, "could not retrieve namespace name") } osioclient, err := g.GetAndCheckOSIOClient(ctx) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "could not create OSIO client") return nil, err } baseURLProvider, err := NewURLProvider(ctx, g.config, osioclient) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "could not retrieve tenant data") return nil, errs.Wrap(err, "could not retrieve tenant data") } /* Timeout used per HTTP request to Kubernetes/OpenShift API servers. * Communication with Hawkular currently uses a hard-coded 30 second * timeout per request, and does not use this parameter. */ // create the cluster API client kubeConfig := &kubernetes.KubeClientConfig{ BaseURLProvider: baseURLProvider, UserNamespace: *kubeNamespaceName, Timeout: g.config.GetDeploymentsHTTPTimeoutSeconds(), } kc, err := kubernetes.NewKubeClient(kubeConfig) if err != nil { url, _ := baseURLProvider.GetAPIURL() log.Error(ctx, map[string]interface{}{ "err": err, "user_namespace": *kubeNamespaceName, "cluster": *url, }, "could not create Kubernetes client object") return nil, errs.Wrap(err, "could not create Kubernetes client object") } return kc, nil }
[ "func", "(", "g", "*", "defaultClientGetter", ")", "GetKubeClient", "(", "ctx", "context", ".", "Context", ")", "(", "kubernetes", ".", "KubeClientInterface", ",", "error", ")", "{", "kubeNamespaceName", ",", "err", ":=", "g", ".", "getNamespaceName", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "osioclient", ",", "err", ":=", "g", ".", "GetAndCheckOSIOClient", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "baseURLProvider", ",", "err", ":=", "NewURLProvider", "(", "ctx", ",", "g", ".", "config", ",", "osioclient", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "/* Timeout used per HTTP request to Kubernetes/OpenShift API servers.\n\t * Communication with Hawkular currently uses a hard-coded 30 second\n\t * timeout per request, and does not use this parameter. */", "// create the cluster API client", "kubeConfig", ":=", "&", "kubernetes", ".", "KubeClientConfig", "{", "BaseURLProvider", ":", "baseURLProvider", ",", "UserNamespace", ":", "*", "kubeNamespaceName", ",", "Timeout", ":", "g", ".", "config", ".", "GetDeploymentsHTTPTimeoutSeconds", "(", ")", ",", "}", "\n", "kc", ",", "err", ":=", "kubernetes", ".", "NewKubeClient", "(", "kubeConfig", ")", "\n", "if", "err", "!=", "nil", "{", "url", ",", "_", ":=", "baseURLProvider", ".", "GetAPIURL", "(", ")", "\n", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "\"", "\"", ":", "*", "kubeNamespaceName", ",", "\"", "\"", ":", "*", "url", ",", "}", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "kc", ",", "nil", "\n", "}" ]
// GetKubeClient creates a kube client for the appropriate cluster assigned to the current user
[ "GetKubeClient", "creates", "a", "kube", "client", "for", "the", "appropriate", "cluster", "assigned", "to", "the", "current", "user" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L138-L184
13,387
fabric8-services/fabric8-wit
controller/deployments.go
SetDeployment
func (c *DeploymentsController) SetDeployment(ctx *app.SetDeploymentDeploymentsContext) error { // we double check podcount here, because in the future we might have different query parameters // (for setting different Pod switches) and PodCount might become optional if ctx.PodCount == nil { return errors.NewBadParameterError("podCount", "missing") } kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } _ /*oldCount*/, err = kc.ScaleDeployment(*kubeSpaceName, ctx.AppName, ctx.DeployName, *ctx.PodCount) if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "error scaling deployment %s", ctx.DeployName)) } return ctx.OK([]byte{}) }
go
func (c *DeploymentsController) SetDeployment(ctx *app.SetDeploymentDeploymentsContext) error { // we double check podcount here, because in the future we might have different query parameters // (for setting different Pod switches) and PodCount might become optional if ctx.PodCount == nil { return errors.NewBadParameterError("podCount", "missing") } kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } _ /*oldCount*/, err = kc.ScaleDeployment(*kubeSpaceName, ctx.AppName, ctx.DeployName, *ctx.PodCount) if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "error scaling deployment %s", ctx.DeployName)) } return ctx.OK([]byte{}) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "SetDeployment", "(", "ctx", "*", "app", ".", "SetDeploymentDeploymentsContext", ")", "error", "{", "// we double check podcount here, because in the future we might have different query parameters", "// (for setting different Pod switches) and PodCount might become optional", "if", "ctx", ".", "PodCount", "==", "nil", "{", "return", "errors", ".", "NewBadParameterError", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n\n", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "kubeSpaceName", ",", "err", ":=", "c", ".", "getSpaceNameFromSpaceID", "(", "ctx", ",", "ctx", ".", "SpaceID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ctx", ".", "SpaceID", ".", "String", "(", ")", ")", ")", "\n", "}", "\n\n", "_", "/*oldCount*/", ",", "err", "=", "kc", ".", "ScaleDeployment", "(", "*", "kubeSpaceName", ",", "ctx", ".", "AppName", ",", "ctx", ".", "DeployName", ",", "*", "ctx", ".", "PodCount", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "ctx", ".", "DeployName", ")", ")", "\n", "}", "\n\n", "return", "ctx", ".", "OK", "(", "[", "]", "byte", "{", "}", ")", "\n", "}" ]
// SetDeployment runs the setDeployment action.
[ "SetDeployment", "runs", "the", "setDeployment", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L187-L212
13,388
fabric8-services/fabric8-wit
controller/deployments.go
DeleteDeployment
func (c *DeploymentsController) DeleteDeployment(ctx *app.DeleteDeploymentDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error())) } err = kc.DeleteDeployment(*kubeSpaceName, ctx.AppName, ctx.DeployName) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, "space_name": *kubeSpaceName, }, "error deleting deployment") return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
go
func (c *DeploymentsController) DeleteDeployment(ctx *app.DeleteDeploymentDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error())) } err = kc.DeleteDeployment(*kubeSpaceName, ctx.AppName, ctx.DeployName) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, "space_name": *kubeSpaceName, }, "error deleting deployment") return jsonapi.JSONErrorResponse(ctx, err) } return ctx.OK([]byte{}) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "DeleteDeployment", "(", "ctx", "*", "app", ".", "DeleteDeploymentDeploymentsContext", ")", "error", "{", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "kubeSpaceName", ",", "err", ":=", "c", ".", "getSpaceNameFromSpaceID", "(", "ctx", ",", "ctx", ".", "SpaceID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "goa", ".", "ErrNotFound", "(", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n\n", "err", "=", "kc", ".", "DeleteDeployment", "(", "*", "kubeSpaceName", ",", "ctx", ".", "AppName", ",", "ctx", ".", "DeployName", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "\"", "\"", ":", "*", "kubeSpaceName", ",", "}", ",", "\"", "\"", ")", "\n", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "return", "ctx", ".", "OK", "(", "[", "]", "byte", "{", "}", ")", "\n", "}" ]
// DeleteDeployment runs the deleteDeployment action.
[ "DeleteDeployment", "runs", "the", "deleteDeployment", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L215-L237
13,389
fabric8-services/fabric8-wit
controller/deployments.go
ShowDeploymentStatSeries
func (c *DeploymentsController) ShowDeploymentStatSeries(ctx *app.ShowDeploymentStatSeriesDeploymentsContext) error { endTime := time.Now() startTime := endTime.Add(-8 * time.Hour) // default: start time is 8 hours before end time limit := -1 // default: No limit if ctx.Limit != nil { limit = *ctx.Limit } if ctx.Start != nil { startTime = convertToTime(int64(*ctx.Start)) } if ctx.End != nil { endTime = convertToTime(int64(*ctx.End)) } if endTime.Before(startTime) { return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("end", *ctx.End)) } kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } statSeries, err := kc.GetDeploymentStatSeries(*kubeSpaceName, ctx.AppName, ctx.DeployName, startTime, endTime, limit) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } else if statSeries == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("deployment", ctx.DeployName)) } res := &app.SimpleDeploymentStatSeriesSingle{ Data: statSeries, } return ctx.OK(res) }
go
func (c *DeploymentsController) ShowDeploymentStatSeries(ctx *app.ShowDeploymentStatSeriesDeploymentsContext) error { endTime := time.Now() startTime := endTime.Add(-8 * time.Hour) // default: start time is 8 hours before end time limit := -1 // default: No limit if ctx.Limit != nil { limit = *ctx.Limit } if ctx.Start != nil { startTime = convertToTime(int64(*ctx.Start)) } if ctx.End != nil { endTime = convertToTime(int64(*ctx.End)) } if endTime.Before(startTime) { return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("end", *ctx.End)) } kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } statSeries, err := kc.GetDeploymentStatSeries(*kubeSpaceName, ctx.AppName, ctx.DeployName, startTime, endTime, limit) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } else if statSeries == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("deployment", ctx.DeployName)) } res := &app.SimpleDeploymentStatSeriesSingle{ Data: statSeries, } return ctx.OK(res) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "ShowDeploymentStatSeries", "(", "ctx", "*", "app", ".", "ShowDeploymentStatSeriesDeploymentsContext", ")", "error", "{", "endTime", ":=", "time", ".", "Now", "(", ")", "\n", "startTime", ":=", "endTime", ".", "Add", "(", "-", "8", "*", "time", ".", "Hour", ")", "// default: start time is 8 hours before end time", "\n", "limit", ":=", "-", "1", "// default: No limit", "\n\n", "if", "ctx", ".", "Limit", "!=", "nil", "{", "limit", "=", "*", "ctx", ".", "Limit", "\n", "}", "\n\n", "if", "ctx", ".", "Start", "!=", "nil", "{", "startTime", "=", "convertToTime", "(", "int64", "(", "*", "ctx", ".", "Start", ")", ")", "\n", "}", "\n\n", "if", "ctx", ".", "End", "!=", "nil", "{", "endTime", "=", "convertToTime", "(", "int64", "(", "*", "ctx", ".", "End", ")", ")", "\n", "}", "\n\n", "if", "endTime", ".", "Before", "(", "startTime", ")", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewBadParameterError", "(", "\"", "\"", ",", "*", "ctx", ".", "End", ")", ")", "\n", "}", "\n\n", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "kubeSpaceName", ",", "err", ":=", "c", ".", "getSpaceNameFromSpaceID", "(", "ctx", ",", "ctx", ".", "SpaceID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "statSeries", ",", "err", ":=", "kc", ".", "GetDeploymentStatSeries", "(", "*", "kubeSpaceName", ",", "ctx", ".", "AppName", ",", "ctx", ".", "DeployName", ",", "startTime", ",", "endTime", ",", "limit", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "else", "if", "statSeries", "==", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ctx", ".", "DeployName", ")", ")", "\n", "}", "\n\n", "res", ":=", "&", "app", ".", "SimpleDeploymentStatSeriesSingle", "{", "Data", ":", "statSeries", ",", "}", "\n\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// ShowDeploymentStatSeries runs the showDeploymentStatSeries action.
[ "ShowDeploymentStatSeries", "runs", "the", "showDeploymentStatSeries", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L240-L286
13,390
fabric8-services/fabric8-wit
controller/deployments.go
ShowDeploymentPodLimitRange
func (c *DeploymentsController) ShowDeploymentPodLimitRange(ctx *app.ShowDeploymentPodLimitRangeDeploymentsContext) error { // Inputs : spaceId, appName, deployName kc, err := c.GetKubeClient(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } spaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } quotas, err := kc.GetDeploymentPodQuota(*spaceName, ctx.AppName, ctx.DeployName) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } res := &app.SimpleDeploymentPodLimitRangeSingle{ Data: quotas, } return ctx.OK(res) }
go
func (c *DeploymentsController) ShowDeploymentPodLimitRange(ctx *app.ShowDeploymentPodLimitRangeDeploymentsContext) error { // Inputs : spaceId, appName, deployName kc, err := c.GetKubeClient(ctx) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } spaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } quotas, err := kc.GetDeploymentPodQuota(*spaceName, ctx.AppName, ctx.DeployName) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } res := &app.SimpleDeploymentPodLimitRangeSingle{ Data: quotas, } return ctx.OK(res) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "ShowDeploymentPodLimitRange", "(", "ctx", "*", "app", ".", "ShowDeploymentPodLimitRangeDeploymentsContext", ")", "error", "{", "// Inputs : spaceId, appName, deployName", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n", "spaceName", ",", "err", ":=", "c", ".", "getSpaceNameFromSpaceID", "(", "ctx", ",", "ctx", ".", "SpaceID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "quotas", ",", "err", ":=", "kc", ".", "GetDeploymentPodQuota", "(", "*", "spaceName", ",", "ctx", ".", "AppName", ",", "ctx", ".", "DeployName", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "res", ":=", "&", "app", ".", "SimpleDeploymentPodLimitRangeSingle", "{", "Data", ":", "quotas", ",", "}", "\n\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// ShowDeploymentPodLimitRange runs the showDeploymentPodLimitRange action.
[ "ShowDeploymentPodLimitRange", "runs", "the", "showDeploymentPodLimitRange", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L289-L311
13,391
fabric8-services/fabric8-wit
controller/deployments.go
ShowDeploymentStats
func (c *DeploymentsController) ShowDeploymentStats(ctx *app.ShowDeploymentStatsDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } var startTime time.Time if ctx.Start != nil { startTime = convertToTime(int64(*ctx.Start)) } else { // If a start time was not supplied, default to one minute ago startTime = time.Now().Add(-1 * time.Minute) } deploymentStats, err := kc.GetDeploymentStats(*kubeSpaceName, ctx.AppName, ctx.DeployName, startTime) if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "could not retrieve deployment statistics for deployment '%s' in space '%s'", ctx.DeployName, *kubeSpaceName)) } if deploymentStats == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("deployment", ctx.DeployName)) } deploymentStats.ID = ctx.DeployName res := &app.SimpleDeploymentStatsSingle{ Data: deploymentStats, } return ctx.OK(res) }
go
func (c *DeploymentsController) ShowDeploymentStats(ctx *app.ShowDeploymentStatsDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } var startTime time.Time if ctx.Start != nil { startTime = convertToTime(int64(*ctx.Start)) } else { // If a start time was not supplied, default to one minute ago startTime = time.Now().Add(-1 * time.Minute) } deploymentStats, err := kc.GetDeploymentStats(*kubeSpaceName, ctx.AppName, ctx.DeployName, startTime) if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "could not retrieve deployment statistics for deployment '%s' in space '%s'", ctx.DeployName, *kubeSpaceName)) } if deploymentStats == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("deployment", ctx.DeployName)) } deploymentStats.ID = ctx.DeployName res := &app.SimpleDeploymentStatsSingle{ Data: deploymentStats, } return ctx.OK(res) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "ShowDeploymentStats", "(", "ctx", "*", "app", ".", "ShowDeploymentStatsDeploymentsContext", ")", "error", "{", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "kubeSpaceName", ",", "err", ":=", "c", ".", "getSpaceNameFromSpaceID", "(", "ctx", ",", "ctx", ".", "SpaceID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ctx", ".", "SpaceID", ".", "String", "(", ")", ")", ")", "\n", "}", "\n\n", "var", "startTime", "time", ".", "Time", "\n", "if", "ctx", ".", "Start", "!=", "nil", "{", "startTime", "=", "convertToTime", "(", "int64", "(", "*", "ctx", ".", "Start", ")", ")", "\n", "}", "else", "{", "// If a start time was not supplied, default to one minute ago", "startTime", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "-", "1", "*", "time", ".", "Minute", ")", "\n", "}", "\n\n", "deploymentStats", ",", "err", ":=", "kc", ".", "GetDeploymentStats", "(", "*", "kubeSpaceName", ",", "ctx", ".", "AppName", ",", "ctx", ".", "DeployName", ",", "startTime", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "ctx", ".", "DeployName", ",", "*", "kubeSpaceName", ")", ")", "\n", "}", "\n", "if", "deploymentStats", "==", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ctx", ".", "DeployName", ")", ")", "\n", "}", "\n\n", "deploymentStats", ".", "ID", "=", "ctx", ".", "DeployName", "\n\n", "res", ":=", "&", "app", ".", "SimpleDeploymentStatsSingle", "{", "Data", ":", "deploymentStats", ",", "}", "\n\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// ShowDeploymentStats runs the showDeploymentStats action.
[ "ShowDeploymentStats", "runs", "the", "showDeploymentStats", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L318-L355
13,392
fabric8-services/fabric8-wit
controller/deployments.go
ShowSpace
func (c *DeploymentsController) ShowSpace(ctx *app.ShowSpaceDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil || kubeSpaceName == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } // get OpenShift space space, err := kc.GetSpace(*kubeSpaceName) if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "could not retrieve space %s", *kubeSpaceName)) } if space == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("openshift space", *kubeSpaceName)) } // Kubernetes doesn't know about space ID, so add it here space.ID = ctx.SpaceID res := &app.SimpleSpaceSingle{ Data: space, } return ctx.OK(res) }
go
func (c *DeploymentsController) ShowSpace(ctx *app.ShowSpaceDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil || kubeSpaceName == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } // get OpenShift space space, err := kc.GetSpace(*kubeSpaceName) if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "could not retrieve space %s", *kubeSpaceName)) } if space == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("openshift space", *kubeSpaceName)) } // Kubernetes doesn't know about space ID, so add it here space.ID = ctx.SpaceID res := &app.SimpleSpaceSingle{ Data: space, } return ctx.OK(res) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "ShowSpace", "(", "ctx", "*", "app", ".", "ShowSpaceDeploymentsContext", ")", "error", "{", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "kubeSpaceName", ",", "err", ":=", "c", ".", "getSpaceNameFromSpaceID", "(", "ctx", ",", "ctx", ".", "SpaceID", ")", "\n", "if", "err", "!=", "nil", "||", "kubeSpaceName", "==", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ctx", ".", "SpaceID", ".", "String", "(", ")", ")", ")", "\n", "}", "\n\n", "// get OpenShift space", "space", ",", "err", ":=", "kc", ".", "GetSpace", "(", "*", "kubeSpaceName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "*", "kubeSpaceName", ")", ")", "\n", "}", "\n", "if", "space", "==", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "*", "kubeSpaceName", ")", ")", "\n", "}", "\n\n", "// Kubernetes doesn't know about space ID, so add it here", "space", ".", "ID", "=", "ctx", ".", "SpaceID", "\n\n", "res", ":=", "&", "app", ".", "SimpleSpaceSingle", "{", "Data", ":", "space", ",", "}", "\n\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// ShowSpace runs the showSpace action.
[ "ShowSpace", "runs", "the", "showSpace", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L358-L388
13,393
fabric8-services/fabric8-wit
controller/deployments.go
ShowSpaceEnvironments
func (c *DeploymentsController) ShowSpaceEnvironments(ctx *app.ShowSpaceEnvironmentsDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } envs, err := kc.GetEnvironments() if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "error retrieving environments")) } if envs == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("environments", ctx.SpaceID.String())) } res := &app.SimpleEnvironmentList{ Data: envs, } return ctx.OK(res) }
go
func (c *DeploymentsController) ShowSpaceEnvironments(ctx *app.ShowSpaceEnvironmentsDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } envs, err := kc.GetEnvironments() if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "error retrieving environments")) } if envs == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("environments", ctx.SpaceID.String())) } res := &app.SimpleEnvironmentList{ Data: envs, } return ctx.OK(res) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "ShowSpaceEnvironments", "(", "ctx", "*", "app", ".", "ShowSpaceEnvironmentsDeploymentsContext", ")", "error", "{", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "envs", ",", "err", ":=", "kc", ".", "GetEnvironments", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "if", "envs", "==", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ctx", ".", "SpaceID", ".", "String", "(", ")", ")", ")", "\n", "}", "\n\n", "res", ":=", "&", "app", ".", "SimpleEnvironmentList", "{", "Data", ":", "envs", ",", "}", "\n\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// ShowSpaceEnvironments runs the showSpaceEnvironments action. // FIXME Remove this method once showSpaceEnvironments API is removed.
[ "ShowSpaceEnvironments", "runs", "the", "showSpaceEnvironments", "action", ".", "FIXME", "Remove", "this", "method", "once", "showSpaceEnvironments", "API", "is", "removed", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L392-L413
13,394
fabric8-services/fabric8-wit
controller/deployments.go
ShowEnvironmentsBySpace
func (c *DeploymentsController) ShowEnvironmentsBySpace(ctx *app.ShowEnvironmentsBySpaceDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil || kubeSpaceName == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } usage, err := kc.GetSpaceAndOtherEnvironmentUsage(*kubeSpaceName) // Model the response if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "error retrieving environments")) } res := &app.SpaceAndOtherEnvironmentUsageList{ Data: usage, } return ctx.OK(res) }
go
func (c *DeploymentsController) ShowEnvironmentsBySpace(ctx *app.ShowEnvironmentsBySpaceDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } kubeSpaceName, err := c.getSpaceNameFromSpaceID(ctx, ctx.SpaceID) if err != nil || kubeSpaceName == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("osio space", ctx.SpaceID.String())) } usage, err := kc.GetSpaceAndOtherEnvironmentUsage(*kubeSpaceName) // Model the response if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "error retrieving environments")) } res := &app.SpaceAndOtherEnvironmentUsageList{ Data: usage, } return ctx.OK(res) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "ShowEnvironmentsBySpace", "(", "ctx", "*", "app", ".", "ShowEnvironmentsBySpaceDeploymentsContext", ")", "error", "{", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "kubeSpaceName", ",", "err", ":=", "c", ".", "getSpaceNameFromSpaceID", "(", "ctx", ",", "ctx", ".", "SpaceID", ")", "\n", "if", "err", "!=", "nil", "||", "kubeSpaceName", "==", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundError", "(", "\"", "\"", ",", "ctx", ".", "SpaceID", ".", "String", "(", ")", ")", ")", "\n", "}", "\n\n", "usage", ",", "err", ":=", "kc", ".", "GetSpaceAndOtherEnvironmentUsage", "(", "*", "kubeSpaceName", ")", "\n\n", "// Model the response", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n\n", "res", ":=", "&", "app", ".", "SpaceAndOtherEnvironmentUsageList", "{", "Data", ":", "usage", ",", "}", "\n\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// ShowEnvironmentsBySpace runs the showEnvironmentsBySpace action.
[ "ShowEnvironmentsBySpace", "runs", "the", "showEnvironmentsBySpace", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L416-L441
13,395
fabric8-services/fabric8-wit
controller/deployments.go
ShowAllEnvironments
func (c *DeploymentsController) ShowAllEnvironments(ctx *app.ShowAllEnvironmentsDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } envs, err := kc.GetEnvironments() if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "error retrieving environments")) } if envs == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundErrorFromString("no environments found")) } res := &app.SimpleEnvironmentList{ Data: envs, } return ctx.OK(res) }
go
func (c *DeploymentsController) ShowAllEnvironments(ctx *app.ShowAllEnvironmentsDeploymentsContext) error { kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { return jsonapi.JSONErrorResponse(ctx, err) } envs, err := kc.GetEnvironments() if err != nil { return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "error retrieving environments")) } if envs == nil { return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundErrorFromString("no environments found")) } res := &app.SimpleEnvironmentList{ Data: envs, } return ctx.OK(res) }
[ "func", "(", "c", "*", "DeploymentsController", ")", "ShowAllEnvironments", "(", "ctx", "*", "app", ".", "ShowAllEnvironmentsDeploymentsContext", ")", "error", "{", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "err", ")", "\n", "}", "\n\n", "envs", ",", "err", ":=", "kc", ".", "GetEnvironments", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errs", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "if", "envs", "==", "nil", "{", "return", "jsonapi", ".", "JSONErrorResponse", "(", "ctx", ",", "errors", ".", "NewNotFoundErrorFromString", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "res", ":=", "&", "app", ".", "SimpleEnvironmentList", "{", "Data", ":", "envs", ",", "}", "\n\n", "return", "ctx", ".", "OK", "(", "res", ")", "\n", "}" ]
// ShowAllEnvironments runs the showAllEnvironments action.
[ "ShowAllEnvironments", "runs", "the", "showAllEnvironments", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L444-L464
13,396
fabric8-services/fabric8-wit
controller/deployments.go
WatchEnvironmentEvents
func (c *DeploymentsController) WatchEnvironmentEvents(ctx *app.WatchEnvironmentEventsDeploymentsContext) error { c.WatchEnvironmentEventsWSHandler(ctx).ServeHTTP(ctx.ResponseWriter, ctx.Request) return nil }
go
func (c *DeploymentsController) WatchEnvironmentEvents(ctx *app.WatchEnvironmentEventsDeploymentsContext) error { c.WatchEnvironmentEventsWSHandler(ctx).ServeHTTP(ctx.ResponseWriter, ctx.Request) return nil }
[ "func", "(", "c", "*", "DeploymentsController", ")", "WatchEnvironmentEvents", "(", "ctx", "*", "app", ".", "WatchEnvironmentEventsDeploymentsContext", ")", "error", "{", "c", ".", "WatchEnvironmentEventsWSHandler", "(", "ctx", ")", ".", "ServeHTTP", "(", "ctx", ".", "ResponseWriter", ",", "ctx", ".", "Request", ")", "\n", "return", "nil", "\n", "}" ]
// WatchEnvironmentEvents runs the watchEnvironmentEvents action.
[ "WatchEnvironmentEvents", "runs", "the", "watchEnvironmentEvents", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L467-L470
13,397
fabric8-services/fabric8-wit
controller/deployments.go
WatchEnvironmentEventsWSHandler
func (c *DeploymentsController) WatchEnvironmentEventsWSHandler(ctx *app.WatchEnvironmentEventsDeploymentsContext) websocket.Handler { return func(ws *websocket.Conn) { defer ws.Close() kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "error accessing Auth server") sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "unable to access auth server"}) return } store, stopWs := kc.WatchEventsInNamespace(ctx.EnvName) defer close(stopWs) go func() { for { var m string err := websocket.Message.Receive(ws, &m) if err != nil { if err != io.EOF { log.Error(ctx, map[string]interface{}{ "err": err, }, "error reading from websocket") } store.Close() return } } }() for { item, err := store.Pop(cache.PopProcessFunc(func(item interface{}) error { return nil })) event, ok := item.(*v1.Event) if !ok { sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "Kubernetes event was an unexpected type"}) return } if err != nil { if err != cache.FIFOClosedError { log.Error(ctx, map[string]interface{}{ "err": err, }, "error receiving events") sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "unable to access Kubernetes events"}) } return } eventItem := transformItem(event) if err != nil { sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "unable to parse Kubernetes event"}) } else { err = websocket.JSON.Send(ws, eventItem) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "error sending events") return } } } } }
go
func (c *DeploymentsController) WatchEnvironmentEventsWSHandler(ctx *app.WatchEnvironmentEventsDeploymentsContext) websocket.Handler { return func(ws *websocket.Conn) { defer ws.Close() kc, err := c.GetKubeClient(ctx) defer cleanup(kc) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "error accessing Auth server") sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "unable to access auth server"}) return } store, stopWs := kc.WatchEventsInNamespace(ctx.EnvName) defer close(stopWs) go func() { for { var m string err := websocket.Message.Receive(ws, &m) if err != nil { if err != io.EOF { log.Error(ctx, map[string]interface{}{ "err": err, }, "error reading from websocket") } store.Close() return } } }() for { item, err := store.Pop(cache.PopProcessFunc(func(item interface{}) error { return nil })) event, ok := item.(*v1.Event) if !ok { sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "Kubernetes event was an unexpected type"}) return } if err != nil { if err != cache.FIFOClosedError { log.Error(ctx, map[string]interface{}{ "err": err, }, "error receiving events") sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "unable to access Kubernetes events"}) } return } eventItem := transformItem(event) if err != nil { sendWebsocketJSON(ctx, ws, map[string]interface{}{"error": "unable to parse Kubernetes event"}) } else { err = websocket.JSON.Send(ws, eventItem) if err != nil { log.Error(ctx, map[string]interface{}{ "err": err, }, "error sending events") return } } } } }
[ "func", "(", "c", "*", "DeploymentsController", ")", "WatchEnvironmentEventsWSHandler", "(", "ctx", "*", "app", ".", "WatchEnvironmentEventsDeploymentsContext", ")", "websocket", ".", "Handler", "{", "return", "func", "(", "ws", "*", "websocket", ".", "Conn", ")", "{", "defer", "ws", ".", "Close", "(", ")", "\n\n", "kc", ",", "err", ":=", "c", ".", "GetKubeClient", "(", "ctx", ")", "\n", "defer", "cleanup", "(", "kc", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n\n", "sendWebsocketJSON", "(", "ctx", ",", "ws", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", "}", ")", "\n", "return", "\n", "}", "\n\n", "store", ",", "stopWs", ":=", "kc", ".", "WatchEventsInNamespace", "(", "ctx", ".", "EnvName", ")", "\n", "defer", "close", "(", "stopWs", ")", "\n\n", "go", "func", "(", ")", "{", "for", "{", "var", "m", "string", "\n", "err", ":=", "websocket", ".", "Message", ".", "Receive", "(", "ws", ",", "&", "m", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "io", ".", "EOF", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "}", "\n", "store", ".", "Close", "(", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "for", "{", "item", ",", "err", ":=", "store", ".", "Pop", "(", "cache", ".", "PopProcessFunc", "(", "func", "(", "item", "interface", "{", "}", ")", "error", "{", "return", "nil", "\n", "}", ")", ")", "\n\n", "event", ",", "ok", ":=", "item", ".", "(", "*", "v1", ".", "Event", ")", "\n", "if", "!", "ok", "{", "sendWebsocketJSON", "(", "ctx", ",", "ws", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", "}", ")", "\n", "return", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "cache", ".", "FIFOClosedError", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n\n", "sendWebsocketJSON", "(", "ctx", ",", "ws", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "\n", "}", "\n\n", "eventItem", ":=", "transformItem", "(", "event", ")", "\n", "if", "err", "!=", "nil", "{", "sendWebsocketJSON", "(", "ctx", ",", "ws", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", "}", ")", "\n", "}", "else", "{", "err", "=", "websocket", ".", "JSON", ".", "Send", "(", "ws", ",", "eventItem", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "ctx", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ",", "}", ",", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// WatchEnvironmentEventsWSHandler establishes a websocket connection to run the watchEnvironmentEvents action.
[ "WatchEnvironmentEventsWSHandler", "establishes", "a", "websocket", "connection", "to", "run", "the", "watchEnvironmentEvents", "action", "." ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments.go#L473-L543
13,398
fabric8-services/fabric8-wit
space/authz/authz.go
NewAuthzService
func NewAuthzService(config auth.ServiceConfiguration) *AuthzRoleService { return &AuthzRoleService{Config: config, Doer: rest.DefaultHttpDoer()} }
go
func NewAuthzService(config auth.ServiceConfiguration) *AuthzRoleService { return &AuthzRoleService{Config: config, Doer: rest.DefaultHttpDoer()} }
[ "func", "NewAuthzService", "(", "config", "auth", ".", "ServiceConfiguration", ")", "*", "AuthzRoleService", "{", "return", "&", "AuthzRoleService", "{", "Config", ":", "config", ",", "Doer", ":", "rest", ".", "DefaultHttpDoer", "(", ")", "}", "\n", "}" ]
// NewAuthzService constructs a new AuthzRoleService
[ "NewAuthzService", "constructs", "a", "new", "AuthzRoleService" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/space/authz/authz.go#L55-L57
13,399
fabric8-services/fabric8-wit
space/authz/authz.go
Authorize
func (s *AuthzRoleService) Authorize(ctx context.Context, spaceID string) (bool, error) { jwttoken := goajwt.ContextJWT(ctx) if jwttoken == nil { return false, errors.NewUnauthorizedError("missing token") } return s.checkRole(ctx, *jwttoken, spaceID) }
go
func (s *AuthzRoleService) Authorize(ctx context.Context, spaceID string) (bool, error) { jwttoken := goajwt.ContextJWT(ctx) if jwttoken == nil { return false, errors.NewUnauthorizedError("missing token") } return s.checkRole(ctx, *jwttoken, spaceID) }
[ "func", "(", "s", "*", "AuthzRoleService", ")", "Authorize", "(", "ctx", "context", ".", "Context", ",", "spaceID", "string", ")", "(", "bool", ",", "error", ")", "{", "jwttoken", ":=", "goajwt", ".", "ContextJWT", "(", "ctx", ")", "\n", "if", "jwttoken", "==", "nil", "{", "return", "false", ",", "errors", ".", "NewUnauthorizedError", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "s", ".", "checkRole", "(", "ctx", ",", "*", "jwttoken", ",", "spaceID", ")", "\n", "}" ]
// Authorize returns true if the current user is among the space collaborators
[ "Authorize", "returns", "true", "if", "the", "current", "user", "is", "among", "the", "space", "collaborators" ]
54759c80c42ff2cf29b352e0f6c9330ce4ad7fce
https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/space/authz/authz.go#L60-L66