use of org.molgenis.data.meta.IllegalAttributeTypeException in project molgenis by molgenis.
the class EntityModelWriter method addRelationForAttribute.
private void addRelationForAttribute(Model model, Resource subject, IRI predicate, Entity objectEntity, Attribute objectAttribute) {
String name = objectAttribute.getName();
AttributeType attributeType = objectAttribute.getDataType();
switch(attributeType) {
case MREF:
case CATEGORICAL_MREF:
addRelationForMrefTypeAttribute(model, subject, predicate, objectEntity.getEntities(name));
break;
case BOOL:
model.add(subject, predicate, valueFactory.createLiteral(objectEntity.getBoolean(name)));
break;
case DATE:
XMLGregorianCalendar calendar = DATATYPE_FACTORY.newXMLGregorianCalendar(objectEntity.getLocalDate(name).toString());
model.add(subject, predicate, valueFactory.createLiteral(calendar));
break;
case DATE_TIME:
calendar = DATATYPE_FACTORY.newXMLGregorianCalendar(objectEntity.getInstant(name).toString());
model.add(subject, predicate, valueFactory.createLiteral(calendar));
break;
case DECIMAL:
model.add(subject, predicate, valueFactory.createLiteral(objectEntity.getDouble(name)));
break;
case LONG:
model.add(subject, predicate, valueFactory.createLiteral(objectEntity.getLong(name)));
break;
case INT:
model.add(subject, predicate, valueFactory.createLiteral(objectEntity.getInt(name)));
break;
case ENUM:
case EMAIL:
case HTML:
case TEXT:
case SCRIPT:
case STRING:
addRelationForStringTypeAttribute(model, subject, predicate, objectEntity.getString(name));
break;
case HYPERLINK:
model.add(subject, predicate, valueFactory.createIRI(objectEntity.getString(name)));
break;
case XREF:
case CATEGORICAL:
case FILE:
addRelationForXrefTypeAttribute(model, subject, predicate, objectEntity.getEntity(name));
break;
default:
throw new IllegalAttributeTypeException(attributeType);
}
}
use of org.molgenis.data.meta.IllegalAttributeTypeException in project molgenis by molgenis.
the class EntityMapperImpl method mapRecursive.
private Object mapRecursive(Entity entity, Attribute attribute, Selection filter, Selection expand, int depth) {
Object value;
String attributeName = attribute.getName();
AttributeType attributeType = attribute.getDataType();
switch(attributeType) {
case BOOL:
value = entity.getBoolean(attributeName);
break;
case CATEGORICAL:
case FILE:
case XREF:
value = mapReference(entity, attribute, filter, expand, depth + 1);
break;
case CATEGORICAL_MREF:
case MREF:
case ONE_TO_MANY:
value = mapReferences(entity, attribute, filter, expand, depth + 1);
break;
case DATE:
value = entity.getLocalDate(attributeName);
break;
case DATE_TIME:
value = entity.getInstant(attributeName);
break;
case DECIMAL:
value = entity.getDouble(attributeName);
break;
case EMAIL:
case ENUM:
case HTML:
case HYPERLINK:
case SCRIPT:
case STRING:
case TEXT:
value = entity.getString(attributeName);
break;
case INT:
value = entity.getInt(attributeName);
break;
case LONG:
value = entity.getLong(attributeName);
break;
case COMPOUND:
throw new IllegalAttributeTypeException(attributeType);
default:
throw new UnexpectedEnumException(attributeType);
}
return value;
}
use of org.molgenis.data.meta.IllegalAttributeTypeException in project molgenis by molgenis.
the class RestService method toEntityValue.
/**
* Converts a HTTP request parameter to a entity value of which the type is defined by the
* attribute. For file attributes persists the file in the file store and persist a file meta data
* entity.
*
* @param attr attribute
* @param paramValue HTTP parameter value
* @return Object
*/
public Object toEntityValue(Attribute attr, Object paramValue, Object id) {
// Treat empty strings as null
if ((paramValue instanceof String) && ((String) paramValue).isEmpty()) {
paramValue = null;
}
Object value;
AttributeType attrType = attr.getDataType();
switch(attrType) {
case BOOL:
value = convertBool(attr, paramValue);
break;
case EMAIL:
case ENUM:
case HTML:
case HYPERLINK:
case SCRIPT:
case STRING:
case TEXT:
value = convertString(attr, paramValue);
break;
case CATEGORICAL:
case XREF:
value = convertRef(attr, paramValue);
break;
case CATEGORICAL_MREF:
case MREF:
case ONE_TO_MANY:
value = convertMref(attr, paramValue);
break;
case DATE:
value = convertDate(attr, paramValue);
break;
case DATE_TIME:
value = convertDateTime(attr, paramValue);
break;
case DECIMAL:
value = convertDecimal(attr, paramValue);
break;
case FILE:
value = convertFile(attr, paramValue, id);
break;
case INT:
value = convertInt(attr, paramValue);
break;
case LONG:
value = convertLong(attr, paramValue);
break;
case COMPOUND:
throw new IllegalAttributeTypeException(attrType);
default:
throw new UnexpectedEnumException(attrType);
}
return value;
}
use of org.molgenis.data.meta.IllegalAttributeTypeException in project molgenis by molgenis.
the class PostgreSqlUtils method getPostgreSqlValue.
/**
* Returns the PostgreSQL value for the given entity attribute
*
* @param entity entity
* @param attr attribute
* @return PostgreSQL value
*/
static Object getPostgreSqlValue(Entity entity, Attribute attr) {
String attrName = attr.getName();
AttributeType attrType = attr.getDataType();
switch(attrType) {
case BOOL:
return entity.getBoolean(attrName);
case CATEGORICAL:
case XREF:
Entity xrefEntity = entity.getEntity(attrName);
return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null;
case CATEGORICAL_MREF:
case MREF:
case ONE_TO_MANY:
Iterable<Entity> entities = entity.getEntities(attrName);
return stream(entities).map(mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())).collect(toList());
case DATE:
return entity.getLocalDate(attrName);
case DATE_TIME:
// As a workaround for #5674, we don't store milliseconds
Instant instant = entity.getInstant(attrName);
return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null;
case DECIMAL:
return entity.getDouble(attrName);
case EMAIL:
case ENUM:
case HTML:
case HYPERLINK:
case SCRIPT:
case STRING:
case TEXT:
return entity.getString(attrName);
case FILE:
FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class);
return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null;
case INT:
return entity.getInt(attrName);
case LONG:
return entity.getLong(attrName);
case COMPOUND:
throw new IllegalAttributeTypeException(attrType);
default:
throw new UnexpectedEnumException(attrType);
}
}
use of org.molgenis.data.meta.IllegalAttributeTypeException in project molgenis by molgenis.
the class PostgreSqlQueryGenerator method getSqlCreateJunctionTable.
static String getSqlCreateJunctionTable(EntityType entityType, Attribute attr) {
Attribute idAttr = entityType.getIdAttribute();
StringBuilder sql = new StringBuilder("CREATE TABLE ").append(getJunctionTableName(entityType, attr)).append(" (").append(getJunctionTableOrderColumnName()).append(" INT,").append(getColumnName(idAttr)).append(' ').append(getPostgreSqlType(idAttr)).append(" NOT NULL, ").append(getColumnName(attr)).append(' ').append(getPostgreSqlType(attr.getRefEntity().getIdAttribute())).append(" NOT NULL").append(", FOREIGN KEY (").append(getColumnName(idAttr)).append(") REFERENCES ").append(getTableName(entityType)).append('(').append(getColumnName(idAttr)).append(") ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED");
if (isPersistedInPostgreSql(attr.getRefEntity())) {
sql.append(", FOREIGN KEY (").append(getColumnName(attr)).append(") REFERENCES ").append(getTableName(attr.getRefEntity())).append('(').append(getColumnName(attr.getRefEntity().getIdAttribute())).append(") DEFERRABLE INITIALLY DEFERRED");
}
AttributeType attrType = attr.getDataType();
switch(attrType) {
case CATEGORICAL_MREF:
case MREF:
sql.append(", UNIQUE (").append(getColumnName(idAttr)).append(',').append(getColumnName(attr)).append(')');
break;
default:
throw new IllegalAttributeTypeException(attrType);
}
sql.append(", UNIQUE (").append(getJunctionTableOrderColumnName()).append(',').append(getColumnName(idAttr)).append(')');
sql.append(')');
return sql.toString();
}
Aggregations