boolean isNumericDataType(Attribute attribute) { AttributeType enumType = attribute.getDataType(); return enumType == INT || enumType == LONG || enumType == DECIMAL; }
boolean isNumericDataType(Attribute attribute) { AttributeType enumType = attribute.getDataType(); return enumType == INT || enumType == LONG || enumType == DECIMAL; }
private boolean isRequiredAttributeAvailable(List<Attribute> availableAttributes, Attribute requiredAttribute) { for (Attribute availableAttribute : availableAttributes) { if (requiredAttribute.getName().equals(availableAttribute.getName())) { if (requiredAttribute.getDataType() == TEXT) { return availableAttribute.getDataType() == TEXT || availableAttribute.getDataType() == STRING; } else return requiredAttribute.getDataType() == availableAttribute.getDataType(); } } return false; } }
/** * Indicates if the attribute is persisted in the database. Compound attributes, computed * attributes with an expression and one-to-many mappedBy attributes are not persisted. * * @param attr the attribute to check * @return boolean indicating if the entity is persisted in the database. */ private static boolean isPersisted(Attribute attr) { return !attr.hasExpression() && attr.getDataType() != COMPOUND && !(attr.getDataType() == ONE_TO_MANY && attr.isMappedBy()); }
private static boolean hasJunctionTable(Attribute attribute) { return isMultipleReferenceType(attribute) && attribute.getDataType() != AttributeType.ONE_TO_MANY; }
private void validateNumericOrDate(Attribute attr) { switch (attr.getDataType()) { case DATE: case DATE_TIME: case DECIMAL: case INT: case LONG: break; // $CASES-OMITTED$ default: throw new IllegalArgumentException( "Can't perform operator '\" + symbol + \"' on attribute '\"" + attr.getName() + "\""); } }
private void updateColumnDataType(EntityType entityType, Attribute attr) { String sqlSetDataType = getSqlSetDataType(entityType, attr); if (LOG.isDebugEnabled()) { LOG.debug( "Changing data type of entity [{}] attribute [{}] to [{}]", entityType.getId(), attr.getName(), attr.getDataType()); if (LOG.isTraceEnabled()) { LOG.trace("SQL: {}", sqlSetDataType); } } jdbcTemplate.execute(sqlSetDataType); }
/** * Returns whether this attribute is stored in the entity table or another table such as a * junction table or referenced entity table. * * @param attr attribute * @return whether this attribute is stored in another table than the entity table */ private static boolean isPersistedInOtherTable(Attribute attr) { boolean bidirectionalOneToMany = attr.getDataType() == ONE_TO_MANY && attr.isMappedBy(); return isMultipleReferenceType(attr) || bidirectionalOneToMany; }
static boolean isTableAttribute(Attribute attr) { return !isMultipleReferenceType(attr) && !(attr.getDataType() == ONE_TO_MANY && attr.isMappedBy()); }
private static void validateChildren(Attribute attr) { boolean childrenIsNullOrEmpty = attr.getChildren() == null || Iterables.isEmpty(attr.getChildren()); if (!childrenIsNullOrEmpty && attr.getDataType() != COMPOUND) { throw new MolgenisDataException( format( "Attribute [%s] is not of type COMPOUND and can therefor not have children", attr.getName())); } }
private static String getSqlCheckConstraint(EntityType entityType, Attribute attr) { if (attr.getDataType() != ENUM) { throw new MolgenisDataException( format("Check constraint only allowed for attribute type [%s]", ENUM.toString())); } return "CONSTRAINT " + getCheckConstraintName(entityType, attr) + " CHECK (" + getColumnName(attr) + " IN (" + attr.getEnumOptions() .stream() .map(enumOption -> '\'' + enumOption + '\'') .collect(joining(",")) + "))"; }
public static boolean filterAttributeRec(Fetch fetch, Attribute attr) { if (attr.getDataType() == COMPOUND) { for (Attribute attrPart : attr.getChildren()) { if (filterAttributeRec(fetch, attrPart)) { return true; } } return false; } else { return fetch.hasField(attr); } }
/** * Returns all non-bidirectional attributes persisted by PostgreSQL in junction tables (e.g. no * compound attributes and attributes with an expression) * * @return stream of attributes persisted by PostgreSQL in junction tables */ static Stream<Attribute> getJunctionTableAttributes(EntityType entityType) { // return all attributes referencing multiple entities except for one-to-many attributes that // are mapped by // another attribute return getPersistedAttributes(entityType) .filter( attr -> isMultipleReferenceType(attr) && !(attr.getDataType() == ONE_TO_MANY && attr.isMappedBy())); }
private static Map<String, Object> attributeToMap(Attribute attribute) { Map<String, Object> map = new HashMap<>(); map.put(AttributeMetadata.NAME, attribute.getName()); map.put(AttributeMetadata.LABEL, attribute.getLabel()); map.put(AttributeMetadata.DESCRIPTION, attribute.getDescription()); map.put(AttributeMetadata.TYPE, attribute.getDataType().toString()); map.put(AttributeMetadata.IS_NULLABLE, attribute.isNillable()); map.put(AttributeMetadata.IS_UNIQUE, attribute.isUnique()); if (attribute.getRefEntity() != null) { map.put(AttributeMetadata.REF_ENTITY_TYPE, attribute.getRefEntity().getId()); } return map; } }
static String getSqlDropCheckConstraint(EntityType entityType, Attribute attr) { if (attr.getDataType() != ENUM) { throw new MolgenisDataException( format("Check constraint only allowed for attribute type [%s]", ENUM.toString())); } return "ALTER TABLE " + getTableName(entityType) + " DROP CONSTRAINT " + getCheckConstraintName(entityType, attr); }
private static Map<String, Object> attributeToMap(Attribute attribute) { Map<String, Object> map = new HashMap<String, Object>(); map.put(AttributeMetadata.NAME, attribute.getName()); map.put(AttributeMetadata.LABEL, attribute.getLabel()); map.put(AttributeMetadata.DESCRIPTION, attribute.getDescription()); map.put(AttributeMetadata.TYPE, attribute.getDataType().toString()); map.put(AttributeMetadata.IS_NULLABLE, attribute.isNillable()); map.put(AttributeMetadata.IS_UNIQUE, attribute.isUnique()); if (attribute.getRefEntity() != null) { map.put(AttributeMetadata.REF_ENTITY_TYPE, attribute.getRefEntity().getId()); } return map; } }
private ConstraintViolation createConstraintViolation( Entity entity, Attribute attribute, EntityType entityType, String message) { Object value = getDataValuesForType(entity, attribute); String dataValue = value != null ? value.toString() : null; String fullMessage = format( "Invalid [%s] value [%s] for attribute [%s] of entity [%s] with type [%s].", attribute.getDataType().toString().toLowerCase(), dataValue, attribute.getLabel(), entity.getLabelValue(), entityType.getId()); fullMessage += " " + message; return new ConstraintViolation(fullMessage); }
public static AttributeResult create(Attribute attr, String languageCode) { return create( attr.getLabel(languageCode), attr.getDescription(languageCode), attr.getDataType().toString()); } }
private static void validateParent(Attribute attr) { if (attr.getParent() != null) { if (attr.getParent().getDataType() != COMPOUND) { throw new MolgenisDataException( format( "Parent attribute [%s] of attribute [%s] is not of type compound", attr.getParent().getName(), attr.getName())); } } }
private void setRowValueForAttribute(Entity row, int index, Column column) { String attributeName = oneClickImporterNamingService.asValidColumnName(column.getName()); Object dataValue = column.getDataValues().get(index); EntityType rowType = row.getEntityType(); Attribute attribute = rowType.getAttribute(attributeName); Object castedValue = oneClickImporterService.castValueAsAttributeType(dataValue, attribute.getDataType()); row.set(attributeName, castedValue); }