Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

WIP: update event system #2189

Closed
wants to merge 13 commits into from
25 changes: 10 additions & 15 deletions controller/area.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package controller

import (
"fmt"
"net/http"

"github.com/fabric8-services/fabric8-wit/ptr"
Expand Down Expand Up @@ -259,21 +258,17 @@ func ConvertArea(db application.DB, request *http.Request, ar area.Area, options
return i
}

// ConvertAreaSimple converts a simple area ID into a Generic Reletionship
// ConvertAreaSimple converts a simple area ID into a Generic Relationship
func ConvertAreaSimple(request *http.Request, id interface{}) *app.GenericData {
t := area.APIStringTypeAreas
i := fmt.Sprint(id)
return &app.GenericData{
Type: &t,
ID: &i,
Links: createAreaLinks(request, id),
i := ""
switch t := id.(type) {
case string:
i = t
case uuid.UUID:
i = t.String()
}
}

func createAreaLinks(request *http.Request, id interface{}) *app.GenericLinks {
relatedURL := rest.AbsoluteURL(request, app.AreaHref(id))
return &app.GenericLinks{
Self: &relatedURL,
Related: &relatedURL,
return &app.GenericData{
Type: ptr.String(area.APIStringTypeAreas),
ID: &i,
}
}
15 changes: 15 additions & 0 deletions controller/codebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,21 @@ func getBranch(projects []che.WorkspaceProject, codebaseURL string) string {
return ""
}

// ConvertCodebaseSimple converts a simple codebase ID into a Generic Relationship
func ConvertCodebaseSimple(request *http.Request, id interface{}) *app.GenericData {
i := ""
switch t := id.(type) {
case string:
i = t
case uuid.UUID:
i = t.String()
}
return &app.GenericData{
Type: ptr.String(APIStringTypeCodebase),
ID: &i,
}
}

// ConvertCodebase converts between internal and external REST representation
func ConvertCodebase(request *http.Request, codebase codebase.Codebase, options ...CodebaseConvertFunc) *app.Codebase {
relatedURL := rest.AbsoluteURL(request, app.CodebaseHref(codebase.ID))
Expand Down
23 changes: 10 additions & 13 deletions controller/iteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/fabric8-services/fabric8-wit/jsonapi"
"github.com/fabric8-services/fabric8-wit/log"
"github.com/fabric8-services/fabric8-wit/login"
"github.com/fabric8-services/fabric8-wit/ptr"
"github.com/fabric8-services/fabric8-wit/rest"
"github.com/fabric8-services/fabric8-wit/space"
"github.com/fabric8-services/fabric8-wit/space/authz"
Expand Down Expand Up @@ -517,20 +518,16 @@ func ConvertIteration(request *http.Request, itr iteration.Iteration, additional

// ConvertIterationSimple converts a simple Iteration ID into a Generic Reletionship
func ConvertIterationSimple(request *http.Request, id interface{}) *app.GenericData {
t := iteration.APIStringTypeIteration
i := fmt.Sprint(id)
return &app.GenericData{
Type: &t,
ID: &i,
Links: createIterationLinks(request, id),
i := ""
switch t := id.(type) {
case string:
i = t
case uuid.UUID:
i = t.String()
}
}

func createIterationLinks(request *http.Request, id interface{}) *app.GenericLinks {
relatedURL := rest.AbsoluteURL(request, app.IterationHref(id))
return &app.GenericLinks{
Self: &relatedURL,
Related: &relatedURL,
return &app.GenericData{
Type: ptr.String(iteration.APIStringTypeIteration),
ID: &i,
}
}

Expand Down
17 changes: 12 additions & 5 deletions controller/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"github.com/fabric8-services/fabric8-wit/jsonapi"
"github.com/fabric8-services/fabric8-wit/label"
"github.com/fabric8-services/fabric8-wit/login"
"github.com/fabric8-services/fabric8-wit/ptr"
"github.com/fabric8-services/fabric8-wit/rest"
"github.com/fabric8-services/fabric8-wit/space"
"github.com/goadesign/goa"
uuid "github.com/satori/go.uuid"
)

// LabelController implements the label resource.
Expand Down Expand Up @@ -152,7 +154,7 @@ func ConvertLabels(appl application.Application, request *http.Request, labels [
return ls
}

// ConvertLabelsSimple converts an array of Label IDs into a Generic Reletionship List
// ConvertLabelsSimple converts an array of Label IDs into a Generic Relationship List
func ConvertLabelsSimple(request *http.Request, labelIDs []interface{}) []*app.GenericData {
ops := make([]*app.GenericData, 0, len(labelIDs))
for _, labelID := range labelIDs {
Expand All @@ -161,12 +163,17 @@ func ConvertLabelsSimple(request *http.Request, labelIDs []interface{}) []*app.G
return ops
}

// ConvertLabelSimple converts a Label ID into a Generic Reletionship
// ConvertLabelSimple converts a Label ID into a Generic Relationship
func ConvertLabelSimple(request *http.Request, labelID interface{}) *app.GenericData {
t := label.APIStringTypeLabels
i := labelID.(string)
i := ""
switch t := labelID.(type) {
case string:
i = t
case uuid.UUID:
i = t.String()
}
return &app.GenericData{
Type: &t,
Type: ptr.String(label.APIStringTypeLabels),
ID: &i,
}
}
Expand Down
22 changes: 5 additions & 17 deletions controller/test-files/event/list/ok-area.res.payload.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@
{
"attributes": {
"name": "system.area",
"newValue": null,
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
"timestamp": "0001-01-01T00:00:00Z",
"workItemTypeID": "00000000-0000-0000-0000-000000000001"
},
"id": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000002",
"relationships": {
"modifier": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that JSONAPI doesn't allow both to be specified: type+id and links. Instead only one is allowed.

},
"id": "00000000-0000-0000-0000-000000000003",
"type": "identities"
}
},
"newValue": {
"data": [
{
"id": "00000000-0000-0000-0000-000000000003",
"links": {
"related": "http:///api/areas/00000000-0000-0000-0000-000000000003",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000003"
},
"id": "00000000-0000-0000-0000-000000000004",
"type": "areas"
}
]
Expand All @@ -34,10 +26,6 @@
"data": [
{
"id": "",
"links": {
"related": "http:///api/areas/",
"self": "http:///api/areas/"
},
"type": "areas"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,25 @@
{
"attributes": {
"name": "system.assignees",
"newValue": null,
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
"timestamp": "0001-01-01T00:00:00Z",
"workItemTypeID": "00000000-0000-0000-0000-000000000001"
},
"id": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000002",
"relationships": {
"modifier": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002"
},
"id": "00000000-0000-0000-0000-000000000003",
"type": "identities"
}
},
"newValue": {
"data": [
{
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002",
"self": "http:///api/users/00000000-0000-0000-0000-000000000002"
},
"id": "00000000-0000-0000-0000-000000000003",
"type": "users"
}
]
},
"oldValue": {}
}
},
"type": "events"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
{
"attributes": {
"name": "system.description",
"newValue": null,
"newValue": {
"content": "# Description is modified1",
"markup": "Markdown"
},
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
"timestamp": "0001-01-01T00:00:00Z",
"workItemTypeID": "00000000-0000-0000-0000-000000000001"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, that an event needs to know about the work item type at the given point int type. This is important so that the UI can find out how to resolve the name (e.g. system.description) into a field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I should make this a relationships really. Let me do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6020b73

},
"id": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000002",
"relationships": {
"modifier": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002"
},
"id": "00000000-0000-0000-0000-000000000003",
"type": "identities"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@
{
"attributes": {
"name": "system.iteration",
"newValue": null,
"oldValue": null,
"timestamp": "0001-01-01T00:00:00Z"
"timestamp": "0001-01-01T00:00:00Z",
"workItemTypeID": "00000000-0000-0000-0000-000000000001"
},
"id": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000002",
"relationships": {
"modifier": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002"
},
"id": "00000000-0000-0000-0000-000000000003",
"type": "identities"
}
},
"newValue": {
"data": [
{
"id": "00000000-0000-0000-0000-000000000003",
"links": {
"related": "http:///api/iterations/00000000-0000-0000-0000-000000000003",
"self": "http:///api/iterations/00000000-0000-0000-0000-000000000003"
},
"id": "00000000-0000-0000-0000-000000000004",
"type": "iterations"
}
]
Expand All @@ -34,10 +26,6 @@
"data": [
{
"id": "",
"links": {
"related": "http:///api/iterations/",
"self": "http:///api/iterations/"
},
"type": "iterations"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
{
"attributes": {
"name": "myFloatType",
"newValue": "2.99",
"oldValue": "1.99",
"timestamp": "0001-01-01T00:00:00Z"
"newValue": 2.99,
"oldValue": 1.99,
"timestamp": "0001-01-01T00:00:00Z",
"workItemTypeID": "00000000-0000-0000-0000-000000000001"
},
"id": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000002",
"relationships": {
"modifier": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002"
},
"id": "00000000-0000-0000-0000-000000000003",
"type": "identities"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
{
"attributes": {
"name": "myIntType",
"newValue": "4235",
"oldValue": "200",
"timestamp": "0001-01-01T00:00:00Z"
"newValue": 4235,
"oldValue": 200,
"timestamp": "0001-01-01T00:00:00Z",
"workItemTypeID": "00000000-0000-0000-0000-000000000001"
},
"id": "00000000-0000-0000-0000-000000000001",
"id": "00000000-0000-0000-0000-000000000002",
"relationships": {
"modifier": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002"
},
"id": "00000000-0000-0000-0000-000000000003",
"type": "identities"
}
}
Expand Down
Loading