Skip to content

Commit

Permalink
Bugfix class order serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
claudenirmf committed Mar 20, 2021
1 parent 64fca28 commit eefcd8e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
@JsonSerialize(using = ClassSerializer.class)
@JsonDeserialize(using = ClassDeserializer.class)
public final class Class extends Classifier<Class, ClassStereotype> {

public static Integer ORDERLESS = Integer.MAX_VALUE;
public static String ORDERLESS_STRING = "*";

protected Boolean isExtensional;
protected Boolean isPowertype;
protected Integer order;
Expand Down Expand Up @@ -86,6 +90,14 @@ public void setOrder(Integer value) {
order = value;
}

public Optional<String> getOrderAsString() {
if (order == null) return Optional.empty();
else
return ORDERLESS.equals(order)
? Optional.of(ORDERLESS_STRING)
: Optional.of(order.toString());
}

public Set<Nature> getRestrictedTo() {
return restrictedTo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eefcd8e

Please sign in to comment.