Skip to content

Commit

Permalink
Merge branch 'robert/dromedarycasebug'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Reppel committed Jun 1, 2018
2 parents 891d829 + d2a0df3 commit 31bec84
Show file tree
Hide file tree
Showing 14 changed files with 441 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Releases

## 0.10.7-alpha (June 01, 2018)

* Fixed https://github.com/Adaptech/les/issues/9
* Typo/wording fixed in les --help.

## 0.10.6-alpha (May 23, 2018)

* Use github release instead of repository for distribution
Expand Down
12 changes: 6 additions & 6 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ Build the les-node image:

Install the 'les' validation tool:

```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.6-alpha/les-linux-amd64 -o /usr/local/bin/les && sudo chmod +x /usr/local/bin/les```
```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.7-alpha/les-linux-amd64 -o /usr/local/bin/les && sudo chmod +x /usr/local/bin/les```

Install 'les-node':

```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.6-alpha/les-node-linux-amd64 -o /usr/local/bin/les-node && sudo chmod +x /usr/local/bin/les-node```
```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.7-alpha/les-node-linux-amd64 -o /usr/local/bin/les-node && sudo chmod +x /usr/local/bin/les-node```

## Darwin AMD64

Install the 'les' validation tool:

```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.6-alpha/les-darwin-amd64 -o /usr/local/bin/les && sudo chmod +x /usr/local/bin/les```
```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.7-alpha/les-darwin-amd64 -o /usr/local/bin/les && sudo chmod +x /usr/local/bin/les```

Install 'les-node':

```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.6-alpha/les-node-darwin-amd64 -o /usr/local/bin/les-node && sudo chmod +x /usr/local/bin/les-node```
```sudo curl -L https://github.com/Adaptech/les/releases/download/release-0.10.7-alpha/les-node-darwin-amd64 -o /usr/local/bin/les-node && sudo chmod +x /usr/local/bin/les-node```

## Windows AMD64

* [Download](https://github.com/Adaptech/les/releases/download/release-0.10.6-alpha/les-windows-amd64.exe) the 'les' validation tool .exe
* [Download](https://github.com/Adaptech/les/releases/download/release-0.10.7-alpha/les-windows-amd64.exe) the 'les' validation tool .exe

* [Download](https://github.com/Adaptech/les/releases/download/release-0.10.6-alpha/les-node-windows-amd64.exe) 'les-node' .exe
* [Download](https://github.com/Adaptech/les/releases/download/release-0.10.7-alpha/les-node-windows-amd64.exe) 'les-node' .exe

2 changes: 1 addition & 1 deletion cmd/compliance-test/emd/EmdReferenceImplementation.emd
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ UserLookup* // userId, notificationEmail

Add Item-> // userId, description
TodoItem Added // description, userId, unknownField
TODO List* // todoitemId, description
TODO List* // todoItemId, description

6 changes: 3 additions & 3 deletions cmd/compliance-test/emd/EmdReferenceImplementation.eml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Contexts:
- Name: description
Type: string
Rules: []
- Name: todoitemId
- Name: todoItemId
Type: string
Rules:
- IsRequired
Expand All @@ -55,7 +55,7 @@ Contexts:
Type: string
- Name: unknownField
Type: string
- Name: todoitemId
- Name: todoItemId
Type: string
Readmodels:
- Readmodel:
Expand All @@ -65,7 +65,7 @@ Contexts:
- UserRegistered
- Readmodel:
Name: TODOList
Key: todoitemId
Key: todoItemId
SubscribesTo:
- TodoItemAdded
Errors: []
8 changes: 4 additions & 4 deletions cmd/compliance-test/emd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func todoListContainsNewItem() {
Get(apiURI+"/r/TODOList").
Send().
ExpectStatus(200).
ExpectJson("0.todoitemId", "10000").
ExpectJson("0.todoItemId", "10000").
ExpectJson("0.userId", testUserID).
ExpectJson("0.description", "Carpe Diem")
}
Expand All @@ -107,8 +107,8 @@ func omittingMandatoryCommandParameterFails() {
SetJson(todoItem{UserID: "123456", Description: "This will fail.", TodoitemID: ""}).
Send().
ExpectStatus(400).
ExpectJson("message.1.field", "todoitemId").
ExpectJson("message.1.msg", "todoitemId is a required field.").
ExpectJson("message.1.field", "todoItemId").
ExpectJson("message.1.msg", "todoItemId is a required field.").
ExpectJsonLength("message", 2) // ... because of the non-existing userId 123456. That's a 2nd validation error, but we aren't interested in it in this test.
}

Expand All @@ -119,6 +119,6 @@ type user struct {

type todoItem struct {
UserID string `json:"userId"`
TodoitemID string `json:"todoitemId"`
TodoitemID string `json:"todoItemId"`
Description string `json:"description"`
}
2 changes: 1 addition & 1 deletion cmd/les-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
)

func main() {
kingpin.Version("0.10.6-alpha")
kingpin.Version("0.10.7-alpha")
kingpin.Parse()
if *buildAPI {
inputFile := useDefaulEmlFileIfInputFileNotSpecified(*inputFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/les-viz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const defaultEmdFile = "Eventstorming.emd"

func main() {
app := kingpin.New("les-viz", "Generates a http://www.graphviz.org/ digraph for an event storming.")
app.Version("0.10.6-alpha")
app.Version("0.10.7-alpha")
file := app.Arg("file", "Event Markdown (.emd) file").String()
kingpin.MustParse(app.Parse(os.Args[1:]))
emdToGraphVizDigraph(*file)
Expand Down
2 changes: 1 addition & 1 deletion cmd/les/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const generatedEmlFile = ".generated.eventsourcing.eml.yaml"

func main() {
app := kingpin.New("les", "Event Markdown (EMD) and Event Markup Language (EML) validation and conversion.")
app.Version("0.10.6-alpha")
app.Version("0.10.7-alpha")
configureConvertCommand(app)
configureValidateCommand(app)
kingpin.MustParse(app.Parse(os.Args[1:]))
Expand Down
34 changes: 21 additions & 13 deletions pkg/convert/emdToEml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package convert
import (
"fmt"
"strings"
"unicode"

"github.com/Adaptech/les/pkg/emd"
"github.com/Adaptech/les/pkg/eml"
Expand Down Expand Up @@ -97,7 +98,7 @@ func getReadmodels(markdown emd.Emd, eventsByPropertyLookup map[string][]string,
// results in readmodel key = userId
//Ensures consistent casing for stream Ids: e.g. TimesheetHoursId is represented as "timesheethoursId".
streamName := properties[0].Name[:len(properties[0].Name)-2]
key := strings.ToLower(streamName) + "Id"
key := firstCharToLower(streamName) + "Id"
readmodelEml.Readmodel.Key = key
}

Expand Down Expand Up @@ -252,7 +253,6 @@ func getCommandPostconditions(markdown emd.Emd) map[string][]string {
eventName := emdEvent.Name
eventNameWords := strings.Split(eventName, " ")
firstWordInEventName := eventNameWords[0]
// streamName := strings.ToLower(firstWordInEventName)
streamName := firstWordInEventName
eventID := strings.Replace(eventName, " ", "", -1)
postConditions[streamName+"."+mostRecentCommandID] = append(postConditions[streamName+"."+mostRecentCommandID], eventID)
Expand All @@ -275,9 +275,9 @@ func ensureThatCommandHasAggregateIDParameter(command *eml.Command, streamName s
// Ensure that the command has a mandatory aggregate id parameter:
hasAggregateID := false
for index, parameter := range command.Command.Parameters {
if strings.ToLower(parameter.Name) == strings.ToLower(streamName+"Id") {
//Ensure consistent casing for stream Ids: e.g. TimesheetHoursId is represented as "timesheethoursId".
command.Command.Parameters[index].Name = strings.ToLower(streamName) + "Id"
if parameter.Name == firstCharToLower(streamName)+"Id" {
//Ensure consistent casing for stream Ids: e.g. TimesheetHoursId is represented as "timesheetHoursId".
command.Command.Parameters[index].Name = firstCharToLower(streamName) + "Id"
if !ruleExists("IsRequired", command.Command.Parameters[index].Rules) {
command.Command.Parameters[index].Rules = append(command.Command.Parameters[index].Rules, "IsRequired")
}
Expand All @@ -286,35 +286,43 @@ func ensureThatCommandHasAggregateIDParameter(command *eml.Command, streamName s
}
if !hasAggregateID {
parameterValidationRules := []string{"IsRequired"}
aggregateIDParameter := eml.Parameter{Name: strings.ToLower(streamName) + "Id", Rules: parameterValidationRules, Type: "string"}
aggregateIDParameter := eml.Parameter{Name: firstCharToLower(streamName) + "Id", Rules: parameterValidationRules, Type: "string"}
command.Command.Parameters = append(command.Command.Parameters, aggregateIDParameter)
}
return command
}

func ensureThatEventHasAggregateIDProperty(event eml.Event, streamName string) eml.Event {
// Ensure that the event has an aggregate id parameter:
hasAggregateID := false
for index, parameter := range event.Event.Properties {
if strings.ToLower(parameter.Name) == strings.ToLower(streamName+"Id") {
//Ensure consistent casing for stream Ids: e.g. TimesheetHoursId is represented as "timesheethoursId".
event.Event.Properties[index].Name = strings.ToLower(streamName) + "Id"
for _, parameter := range event.Event.Properties {
if parameter.Name == firstCharToLower(streamName+"Id") {
hasAggregateID = true
break
}
}

var aggregateIDParameter eml.Property
if !hasAggregateID {
aggregateIDParameter = eml.Property{Name: strings.ToLower(streamName) + "Id", Type: "string"}
aggregateIDParameter = eml.Property{Name: firstCharToLower(streamName) + "Id", Type: "string"}
event.Event.Properties = append(event.Event.Properties, aggregateIDParameter)
}
return event
}

func firstCharToLower(s string) string {
if len(s) == 0 {
return s
}
a := []rune(s)
a[0] = unicode.ToLower(a[0])
return (string(a))
}

func ensureThatAggregateIDParameterIsRequiredField(command *eml.Command, streamName string) *eml.Command {
parameters := []eml.Parameter{}
for _, parameter := range command.Command.Parameters {
if strings.HasSuffix(parameter.Name, "Id") {
if parameter.Name == strings.ToLower(streamName)+"Id" {
if parameter.Name == firstCharToLower(streamName)+"Id" {
if !parameter.RuleExists("IsRequired") {
parameter.Rules = append(parameter.Rules, "IsRequired")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/eml/generate/nodejs/controllerjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class {{ .Stream.Name }}Controller {
{{$parameter.Name}} = foundItem && foundItem.{{ $parameter.MustExistInReadmodel | GetReadmodelKey }};
{{end}}{{end}}
const command = new {{$command.Command.Name | ToNodeJsClassName }}({{range $cnt, $parameter := $command.Command.Parameters}}{{if gt $cnt 0}}, {{end}}{{$parameter.Name}}{{end}});
await commandHandler({{$.Stream.Name | ToNodeJsClassName}}, command.{{ $.Stream.Name | ToNodeJsClassName | ToLower }}Id, command);
await commandHandler({{$.Stream.Name | ToNodeJsClassName}}, command.{{ $.Stream.Name | ToNodeJsClassName | FirstCharToLower }}Id, command);
res.status(202).json(command);
} catch (err) {
if (err.name === "ValidationFailed") {
Expand All @@ -49,6 +49,7 @@ export default class {{ .Stream.Name }}Controller {

funcMap := template.FuncMap{
"ToLower": strings.ToLower,
"FirstCharToLower": FirstCharToLower,
"ToNodeJsClassName": ToNodeJsClassName,
"GetReadmodelKey": ReadmodelKeyLookup,
}
Expand All @@ -70,5 +71,4 @@ export default class {{ .Stream.Name }}Controller {
log.Fatal("error executing ControllerJS template:", err)
}
return buf.String()

}
15 changes: 14 additions & 1 deletion pkg/eml/generate/nodejs/emlNamesToNodeJSNames.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
package nodejs

import "strings"
import (
"strings"
"unicode"
)

// ToNodeJsClassName ...
func ToNodeJsClassName(s string) string {
return strings.Replace(s, " ", "", -1)
}

// FirstCharToLower ...
func FirstCharToLower(s string) string {
if len(s) == 0 {
return s
}
a := []rune(s)
a[0] = unicode.ToLower(a[0])
return (string(a))
}
Loading

0 comments on commit 31bec84

Please sign in to comment.