Skip to content

Commit

Permalink
add target and multiplicity to relation enum
Browse files Browse the repository at this point in the history
  • Loading branch information
hknots committed Nov 30, 2023
1 parent b3f75aa commit 7c810e0
Showing 1 changed file with 69 additions and 53 deletions.
122 changes: 69 additions & 53 deletions generate/java/java_class_tpl.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,69 @@
package java

const CLASS_TEMPLATE = `package {{ .Package }};
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.*;
import no.fint.model.{{ javaType .Stereotype }};
{{- if .Imports -}}
{{ range $i := .Imports }}
import {{ $i }};
{{- end -}}
{{ end }}
@Data
@NoArgsConstructor
{{ if .Extends -}}
@EqualsAndHashCode(callSuper=true)
@ToString(callSuper=true)
{{ else -}}
@EqualsAndHashCode
@ToString
{{ end -}}
{{ if .Deprecated -}}
@Deprecated
{{ end -}}
public {{- if .Abstract }} abstract {{- end }} class {{ .Name }} {{ if .Extends -}} extends {{ .Extends }} {{ end -}} implements {{ javaType .Stereotype }} {
{{- if .Relations }}
{{ $c := sub (len .Relations) 1 -}}
public enum Relasjonsnavn {
{{- range $i, $rel := .Relations }}
{{ upperCase $rel.Name }}{{ if ne $i $c }},{{ end -}}
{{ end }}
}
{{ end -}}
{{ if .Attributes }}
{{- range $att := .Attributes }}
{{- if $att.Deprecated }}
@Deprecated
{{- end }}
{{- if not $att.Optional }}
{{ if $att.List }}@NotEmpty{{ else if eq "string" $att.Type }}@NotBlank{{ else }}@NotNull{{ end }}
{{- end }}
private {{ javaType $att.Type | validFilt $att.Type | listFilt $att.List }} {{ $att.Name }};
{{- end }}
{{- end }}
}
`
package java

const CLASS_TEMPLATE = `package {{ .Package }};
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.*;
import no.fint.model.{{ javaType .Stereotype }};
{{- if .Imports -}}
{{ range $i := .Imports }}
import {{ $i }};
{{- end -}}
{{ end }}
@Data
@NoArgsConstructor
{{ if .Extends -}}
@EqualsAndHashCode(callSuper=true)
@ToString(callSuper=true)
{{ else -}}
@EqualsAndHashCode
@ToString
{{ end -}}
{{ if .Deprecated -}}
@Deprecated
{{ end -}}
public {{- if .Abstract }} abstract {{- end }} class {{ .Name }} {{ if .Extends -}} extends {{ .Extends }} {{ end -}} implements {{ javaType .Stereotype }} {
{{- if .Relations }}
{{ $c := sub (len .Relations) 1 -}}
public enum Relasjonsnavn {
{{- range $i, $rel := .Relations }}
{{ upperCase $rel.Name }}("{{ $rel.Target }}", "{{ $rel.Multiplicity }}"){{ if ne $i $c }},{{ end -}}
{{ end }}
private final String typeName;
private final String multiplicity;
private Relasjonsnavn(String typeName, String multiplicity) {
this.typeName = typeName;
this.multiplicity = multiplicity;
}
public String getTypeName() {
return typeName;
}
public String getMultiplicity() {
return multiplicity;
}
}
{{ end -}}
{{ if .Attributes }}
{{- range $att := .Attributes }}
{{- if $att.Deprecated }}
@Deprecated
{{- end }}
{{- if not $att.Optional }}
{{ if $att.List }}@NotEmpty{{ else if eq "string" $att.Type }}@NotBlank{{ else }}@NotNull{{ end }}
{{- end }}
private {{ javaType $att.Type | validFilt $att.Type | listFilt $att.List }} {{ $att.Name }};
{{- end }}
{{- end }}
}
`

0 comments on commit 7c810e0

Please sign in to comment.