2020-01-30 10:26:43 +01:00
|
|
|
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;
|
|
|
|
|
2021-06-29 17:34:54 +02:00
|
|
|
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
2020-07-07 17:04:25 +02:00
|
|
|
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
2021-02-11 17:24:22 +01:00
|
|
|
import org.gcube.informationsystem.base.reference.AccessType;
|
2020-01-30 10:26:43 +01:00
|
|
|
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;
|
2021-02-11 22:09:02 +01:00
|
|
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
2020-02-03 10:51:29 +01:00
|
|
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
2020-01-30 10:26:43 +01:00
|
|
|
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
|
|
|
|
2021-01-19 15:32:19 +01:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2020-01-30 10:26:43 +01:00
|
|
|
@JsonTypeName(value = PropertyType.NAME)
|
2020-02-03 10:51:29 +01:00
|
|
|
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
|
2020-01-30 10:26:43 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-30 10:26:43 +01:00
|
|
|
protected PropertyTypeImpl() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public PropertyTypeImpl(Class<P> clz) {
|
|
|
|
super(clz);
|
|
|
|
this.superClasses = retrieveSuperClasses(clz, PropertyElement.class,
|
|
|
|
clz == PropertyElement.class ? null : PropertyElement.NAME);
|
2020-12-11 13:09:02 +01:00
|
|
|
|
|
|
|
this.properties = retrieveListOfProperties(clz);
|
2020-01-30 10:26:43 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 10:51:29 +01:00
|
|
|
@Override
|
|
|
|
public Set<PropertyDefinition> getProperties() {
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
2021-02-11 17:24:22 +01:00
|
|
|
@Override
|
2021-06-29 17:34:54 +02:00
|
|
|
@JsonIgnore
|
2021-02-11 17:24:22 +01:00
|
|
|
public AccessType getAccessType() {
|
|
|
|
|
2021-02-11 22:09:02 +01:00
|
|
|
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)) {
|
2021-02-11 17:24:22 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-30 10:26:43 +01:00
|
|
|
}
|