Skip to content

Commit

Permalink
make use of resourcePackageRename
Browse files Browse the repository at this point in the history
  • Loading branch information
hknots committed May 8, 2024
1 parent eed9591 commit bb9648f
Showing 1 changed file with 115 additions and 115 deletions.
230 changes: 115 additions & 115 deletions generate/java/java_resource_class_tpl.go
Original file line number Diff line number Diff line change
@@ -1,115 +1,115 @@
package java

const RESOURCE_CLASS_TEMPLATE = `package {{ resourcePkg .Package }};
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import javax.validation.Valid;
import javax.validation.constraints.*;
import no.fint.model.felles.kompleksedatatyper.Identifikator;
import no.fint.model.resource.FintLinks;
import no.fint.model.{{ resourceRename (javaType .Stereotype) }};
import no.fint.model.resource.Link;
import no.fint.model.FintIdentifikator;
{{- if .Imports -}}
{{ range $i := .Imports }}
import {{ resource $.Resources $i | extends $.ExtendsResource $.Extends }};
{{- 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 }}Resource {{ if .Extends -}} extends {{ .Extends }}{{ if .ExtendsResource }}Resource{{ end }} {{ end -}} implements {{ resourceRename (javaType .Stereotype) }}, FintLinks {
{{- if .Attributes }}
// Attributes
{{- if .Resources }}
@JsonIgnore
@Override
public List<FintLinks> getNestedResources() {
List<FintLinks> result = {{ if not .ExtendsResource }}FintLinks.{{end}}super.getNestedResources();
{{- range $att := .Resources }}
if ({{$att.Name}} != null) {
result.add{{if $att.List}}All{{end}}({{$att.Name}});
}
{{- end }}
return result;
}
{{- end }}
{{- 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 | resource $.Resources | validFilt $att.Type | listFilt $att.List }} {{ $att.Name }};
{{- end }}
{{- end }}
{{- if .Identifiable }}
@JsonIgnore
public Map<String, FintIdentifikator> getIdentifikators() {
Map<String, FintIdentifikator> identifikators = new HashMap<>();
{{- if .ExtendsIdentifiable}}
identifikators.putAll(super.getIdentifikators());
{{- end}}
{{- range $att := .Attributes}}
{{- if eq $att.Type "Identifikator"}}
identifikators.put("{{ $att.Name }}", this.{{ $att.Name }});
{{- end}}
{{- end}}
return identifikators;
}
{{- end }}
// Relations
@Getter
private final Map<String, List<Link>> links = createLinks();
{{- if .Relations }}
{{ range $i, $rel := .Relations }}
{{- if $rel.Deprecated }}
@Deprecated
{{- end }}
@JsonIgnore
public List<Link> get{{ upperCaseFirst $rel.Name }}() {
return getLinks().getOrDefault("{{$rel.Name}}", Collections.emptyList());
}
{{- if $rel.Deprecated }}
@Deprecated
{{- end }}
public void add{{ upperCaseFirst $rel.Name }}(Link link) {
addLink("{{$rel.Name}}", link);
}
{{- end }}
{{- end }}
}
`
package java

const RESOURCE_CLASS_TEMPLATE = `package {{ resourcePkg .Package }};
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import javax.validation.Valid;
import javax.validation.constraints.*;
import no.fint.model.felles.kompleksedatatyper.Identifikator;
import no.fint.model.resource.FintLinks;
import no.fint.model.{{ resourcePackageRename (javaType .Stereotype) }};
import no.fint.model.resource.Link;
import no.fint.model.FintIdentifikator;
{{- if .Imports -}}
{{ range $i := .Imports }}
import {{ resource $.Resources $i | extends $.ExtendsResource $.Extends }};
{{- 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 }}Resource {{ if .Extends -}} extends {{ .Extends }}{{ if .ExtendsResource }}Resource{{ end }} {{ end -}} implements {{ resourceRename (javaType .Stereotype) }}, FintLinks {
{{- if .Attributes }}
// Attributes
{{- if .Resources }}
@JsonIgnore
@Override
public List<FintLinks> getNestedResources() {
List<FintLinks> result = {{ if not .ExtendsResource }}FintLinks.{{end}}super.getNestedResources();
{{- range $att := .Resources }}
if ({{$att.Name}} != null) {
result.add{{if $att.List}}All{{end}}({{$att.Name}});
}
{{- end }}
return result;
}
{{- end }}
{{- 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 | resource $.Resources | validFilt $att.Type | listFilt $att.List }} {{ $att.Name }};
{{- end }}
{{- end }}
{{- if .Identifiable }}
@JsonIgnore
public Map<String, FintIdentifikator> getIdentifikators() {
Map<String, FintIdentifikator> identifikators = new HashMap<>();
{{- if .ExtendsIdentifiable}}
identifikators.putAll(super.getIdentifikators());
{{- end}}
{{- range $att := .Attributes}}
{{- if eq $att.Type "Identifikator"}}
identifikators.put("{{ $att.Name }}", this.{{ $att.Name }});
{{- end}}
{{- end}}
return identifikators;
}
{{- end }}
// Relations
@Getter
private final Map<String, List<Link>> links = createLinks();
{{- if .Relations }}
{{ range $i, $rel := .Relations }}
{{- if $rel.Deprecated }}
@Deprecated
{{- end }}
@JsonIgnore
public List<Link> get{{ upperCaseFirst $rel.Name }}() {
return getLinks().getOrDefault("{{$rel.Name}}", Collections.emptyList());
}
{{- if $rel.Deprecated }}
@Deprecated
{{- end }}
public void add{{ upperCaseFirst $rel.Name }}(Link link) {
addLink("{{$rel.Name}}", link);
}
{{- end }}
{{- end }}
}
`

0 comments on commit bb9648f

Please sign in to comment.