added getTypeName() function in Element

This commit is contained in:
Luca Frosini 2023-04-27 10:50:37 +02:00
parent a5f2953fe7
commit b26681665e
5 changed files with 21 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import java.io.StringWriter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.TypeUtility;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -30,4 +31,10 @@ public class ElementImpl implements Element {
return super.toString(); return super.toString();
} }
} }
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
} }

View File

@ -32,4 +32,6 @@ public interface Element extends Serializable {
*/ */
public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS Z"; public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS Z";
public String getTypeName();
} }

View File

@ -32,6 +32,7 @@ import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
import org.gcube.informationsystem.types.impl.relations.RelationTypeImpl; import org.gcube.informationsystem.types.impl.relations.RelationTypeImpl;
import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.Version; import org.gcube.informationsystem.utils.Version;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -289,4 +290,9 @@ public class TypeImpl implements Type {
return null; return null;
} }
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
} }

View File

@ -12,6 +12,7 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.types.PropertyTypeName; import org.gcube.informationsystem.types.PropertyTypeName;
import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.Version; import org.gcube.informationsystem.utils.Version;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -281,4 +282,9 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
} }
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
} }

View File

@ -24,10 +24,6 @@ public class TypeUtility {
return getTypeName(jsonNode); return getTypeName(jsonNode);
} }
public static String getTypeName(Element element){
return getTypeName(element.getClass());
}
public static <E extends Element> String getTypeName(Class<E> clz){ public static <E extends Element> String getTypeName(Class<E> clz){
return TypeMapper.getType(clz); return TypeMapper.getType(clz);
} }