From eefcd8ed9cfd7df1280e40d2efa9abb9721f0f67 Mon Sep 17 00:00:00 2001 From: Claudenir Fonseca Date: Sat, 20 Mar 2021 20:30:34 +0100 Subject: [PATCH] Bugfix class order serialization --- .../inf/ontouml/vp/model/ontouml/model/Class.java | 12 ++++++++++++ .../model/ontouml/serialization/ClassSerializer.java | 2 +- .../ontouml/vp/model/ontouml2vp/IClassLoader.java | 2 +- .../ontouml/vp/model/vp2ontouml/IClassAdapter.java | 10 ++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/model/Class.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/model/Class.java index 1eb4e204..f54708da 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/model/Class.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/model/Class.java @@ -14,6 +14,10 @@ @JsonSerialize(using = ClassSerializer.class) @JsonDeserialize(using = ClassDeserializer.class) public final class Class extends Classifier { + + public static Integer ORDERLESS = Integer.MAX_VALUE; + public static String ORDERLESS_STRING = "*"; + protected Boolean isExtensional; protected Boolean isPowertype; protected Integer order; @@ -86,6 +90,14 @@ public void setOrder(Integer value) { order = value; } + public Optional getOrderAsString() { + if (order == null) return Optional.empty(); + else + return ORDERLESS.equals(order) + ? Optional.of(ORDERLESS_STRING) + : Optional.of(order.toString()); + } + public Set getRestrictedTo() { return restrictedTo; } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/serialization/ClassSerializer.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/serialization/ClassSerializer.java index c8e35e7f..10f40851 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/serialization/ClassSerializer.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml/serialization/ClassSerializer.java @@ -22,7 +22,7 @@ static void serializeFields(Class clazz, JsonGenerator jsonGen) throws IOExcepti Serializer.writeNullableBooleanField( "isExtensional", clazz.isExtensional().orElse(null), jsonGen); Serializer.writeNullableBooleanField("isPowertype", clazz.isPowertype().orElse(null), jsonGen); - Serializer.writeNullableNumberField("order", clazz.getOrder().orElse(null), jsonGen); + Serializer.writeNullableStringField("order", clazz.getOrderAsString().orElse(null), jsonGen); Serializer.writeNullableArrayField("literals", clazz.getLiterals(), jsonGen); if (!clazz.getRestrictedTo().isEmpty()) { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassLoader.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassLoader.java index c7dcb0d3..d2528962 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassLoader.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassLoader.java @@ -32,7 +32,7 @@ public static IClass importElement(Class fromClass) { fromClass.isExtensional().ifPresent(aBoolean -> setIsExtensional(toClass, aBoolean)); fromClass.isPowertype().ifPresent(aBoolean -> setIsPowertype(toClass, aBoolean)); - fromClass.getOrder().ifPresent(anInteger -> setOrder(toClass, anInteger.toString())); + fromClass.getOrderAsString().ifPresent(aString -> setOrder(toClass, aString)); String restrictedTo = getRestrictedToString(fromClass); setRestrictedTo(toClass, restrictedTo); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IClassAdapter.java b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IClassAdapter.java index 9c11dd48..15a53065 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IClassAdapter.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IClassAdapter.java @@ -1,6 +1,7 @@ package it.unibz.inf.ontouml.vp.model.vp2ontouml; import com.vp.plugin.model.*; +import it.unibz.inf.ontouml.vp.model.ontouml.model.Class; import it.unibz.inf.ontouml.vp.utils.StereotypesManager; public class IClassAdapter implements IAdapter { @@ -82,9 +83,14 @@ public Integer getOrder() { Integer order = null; try { - order = value instanceof String ? Integer.parseInt((String) value) : null; + if (value instanceof String) { + order = + Class.ORDERLESS_STRING.equals(value) + ? Class.ORDERLESS + : Integer.parseInt((String) value); + } } catch (NumberFormatException ignored) { - System.out.println("Order is is an integer!"); + System.out.println("Order cannot be converted to an integer or orderless!"); } return order;