@@ -3,7 +3,9 @@ package {{package_name}};
33import com.fasterxml.jackson.annotation.JsonIgnore;
44import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
55import com.fasterxml.jackson.annotation.JsonProperty;
6+ import com.fasterxml.jackson.annotation.JsonInclude;
67import org.openmetadatainitiative.openminds.utils.*;
8+ import java.util.function.Function;
79
810import java.util.ArrayList;
911import java.util.List;
@@ -20,8 +22,10 @@ import static {{package_name}}.{{ class_name }}.SEMANTIC_NAME;
2022 */
2123@InstanceType(SEMANTIC_NAME)
2224@JsonIgnoreProperties(ignoreUnknown = true)
23- public class {{ class_name }} extends Instance {% if implemented_interfaces %} implements {{ implemented_interfaces|join(', ') }}{% endif %} {
24- static final String SEMANTIC_NAME = "{{ type }}";
25+ @JsonInclude(JsonInclude.Include.NON_NULL)
26+ @SuppressWarnings("unused")
27+ public class {{ class_name }} extends Instance implements org.openmetadatainitiative.openminds.OpenMINDS.{{version[0] |upper}}{{version[1:] }}.Entity{% if implemented_interfaces %} , {{ implemented_interfaces|join(', ') }}{% endif %} {
28+ public static final String SEMANTIC_NAME = "{{ type }}";
2529
2630 @JsonIgnore
2731 public Reference<{{ class_name }}> getReference() {
@@ -32,25 +36,51 @@ public class {{ class_name }} extends Instance {% if implemented_interfaces %}im
3236 return new Reference<> (new InstanceId(instanceId));
3337 }
3438
39+ /** For deserialization **/
40+ private {{ class_name }}() {
41+ this(null);
42+ }
43+
3544 private {{ class_name }}(LocalId localId ) {
36- super(localId);
45+ super(localId, SEMANTIC_NAME);
46+ }
47+
48+ {% if type in embedded_types %}
49+ public class EmbeddedBuilder {
50+
51+ {% for property in properties %} public EmbeddedBuilder {{ builder_for_properties[property] }}
52+ {% endfor %}
53+
54+ public {{ class_name }} build(){
55+ return {{ class_name }}.this;
56+ }
3757 }
3858
59+ public static {{ class_name }}.EmbeddedBuilder createEmbedded(){
60+ return new {{ class_name }}(null).new EmbeddedBuilder();
61+ }
62+ {% endif %}
3963
64+ {% if type not in embedded_types or type not in embedded_only %}
4065 public class Builder implements org.openmetadatainitiative.openminds.utils.Builder<{{ class_name }}>{
41- {% for property in properties %}{% for line in builder_for_properties [property ] %}
42- {{ line }}
43- {% endfor %}{% endfor %}
66+ {% for property in properties %} public Builder {{ builder_for_properties[property] }}
67+ {% endfor %}
4468
4569 public {{ class_name }} build(OpenMINDSContext context) {
46- if ({{ class_name }}.this.id == null) {
47- {{ class_name }}.this.id = InstanceId.withPrefix(UUID.randomUUID().toString(), context.idPrefix());
48- }
49- {{ class_name }}.this.atType = SEMANTIC_NAME;
70+ {{ class_name }}.super.build(context);
5071 return {{ class_name }}.this;
5172 }
5273 }
5374
75+ public static {{ class_name }}.Builder create(LocalId localId){
76+ return new {{ class_name }}(localId).new Builder();
77+ }
78+
79+ public {{ class_name }}.Builder copy(){
80+ return ParsingUtils.OBJECT_MAPPER.convertValue(this, {{ class_name }}.class).new Builder();
81+ }
82+ {% endif %}
83+
5484{% for property in properties %} @JsonProperty(value = "{% if property in absolute_property_translations %} {{absolute_property_translations[property] }}{% else %} {{property}}{% endif %} ")
5585 {{member_for_properties[property] }}
5686 {% if property in property_descriptions and property_descriptions [property ] %}
@@ -60,11 +90,5 @@ public class {{ class_name }} extends Instance {% if implemented_interfaces %}im
6090 {{getter_for_properties[property] }}
6191
6292 {% endfor %}
63- public static {{ class_name }}.Builder create(LocalId localId){
64- return new {{ class_name }}(localId).new Builder();
65- }
6693
67- public {{ class_name }}.Builder copy(){
68- return ParsingUtils.OBJECT_MAPPER.convertValue(this, {{ class_name }}.class).new Builder();
69- }
7094}
0 commit comments