information-system-model/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyTypeImpl.java

94 lines
2.6 KiB
Java
Raw Normal View History

package org.gcube.informationsystem.types.impl.properties;
2023-01-23 15:33:33 +01:00
import java.io.StringWriter;
2021-10-21 12:47:50 +02:00
import java.util.HashSet;
2020-02-03 10:51:29 +01:00
import java.util.Set;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
2020-07-07 17:04:25 +02:00
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
2021-10-25 10:58:30 +02:00
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
2023-02-03 14:39:25 +01:00
import org.gcube.informationsystem.serialization.ElementMapper;
2020-02-03 10:51:29 +01:00
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
2020-02-03 10:51:29 +01:00
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = PropertyType.NAME)
2020-02-03 10:51:29 +01:00
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
implements PropertyType<P> {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 7532701373450638829L;
2020-02-03 10:51:29 +01:00
protected Set<PropertyDefinition> properties;
2021-10-21 12:47:50 +02:00
private static Set<String> propertyElementAccesTypes;
static {
propertyElementAccesTypes = new HashSet<>();
propertyElementAccesTypes.add(PropertyElement.NAME);
propertyElementAccesTypes.add(LinkedEntity.NAME);
propertyElementAccesTypes.add(TemplateVariable.NAME);
}
protected PropertyTypeImpl() {
super();
}
public PropertyTypeImpl(Class<P> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, PropertyElement.class,
clz == PropertyElement.class ? null : PropertyElement.NAME);
this.properties = retrieveListOfProperties(clz);
}
2020-02-03 10:51:29 +01:00
@Override
public Set<PropertyDefinition> getProperties() {
return properties;
}
@Override
@JsonIgnore
public AccessType getAccessType() {
if(name.compareTo(PropertyType.NAME)==0) {
return AccessType.PROPERTY_TYPE;
}
if(name.compareTo(PropertyDefinition.NAME)==0) {
return AccessType.PROPERTY_DEFINITION;
}
2021-10-21 12:47:50 +02:00
if(propertyElementAccesTypes.contains(name)) {
return AccessType.PROPERTY_ELEMENT;
}
return AccessType.PROPERTY;
}
2023-01-23 15:33:33 +01:00
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ElementMapper.marshal(this.header, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
}