private static void validateUpdateDataType( AttributeType currentDataType, AttributeType newDataType) { EnumSet<AttributeType> allowedDatatypes = DATA_TYPE_ALLOWED_TRANSITIONS.get(currentDataType); if (!allowedDatatypes.contains(newDataType)) { throw new MolgenisDataException( format( "Attribute data type update from [%s] to [%s] not allowed, allowed types are %s", currentDataType.toString(), newDataType.toString(), allowedDatatypes.toString())); } }
if (existingGuess.equals(newGuess)) { return existingGuess; case INT: if (newGuess.equals(DECIMAL)) { return DECIMAL; } else if (newGuess.equals(LONG)) { return LONG; } else { if (newGuess.equals(INT) || newGuess.equals(LONG)) { return DECIMAL; } else { if (newGuess.equals(INT)) { return LONG; } else if (newGuess.equals(DECIMAL)) { return DECIMAL; } else {
private static ConstraintViolation checkText( Entity entity, Attribute attribute, EntityType meta, AttributeType fieldType) { String text = entity.getString(attribute.getName()); if (text == null) { return null; } if (text.length() > fieldType.getMaxLength()) { return createConstraintViolation(entity, attribute, meta); } return null; }
private static ConstraintViolation createConstraintViolation( Entity entity, Attribute attribute, EntityType entityType) { String message = format( "Invalid %s value '%s' for attribute '%s' of entity '%s'.", attribute.getDataType().toString().toLowerCase(), entity.get(attribute.getName()), attribute.getLabel(), entityType.getId()); Range range = attribute.getRange(); if (range != null) { message += format("Value must be between %d and %d", range.getMin(), range.getMax()); } Long maxLength = attribute.getDataType().getMaxLength(); if (maxLength != null) { message += format("Value must be less than or equal to %d characters", maxLength); } return new ConstraintViolation(message); }
if (fieldType.getMaxLength() != null && value.length() > fieldType.getMaxLength()) { throw new MolgenisDataException( "Default value for attribute [" + attr.getName() + "] exceeds the maximum length for datatype " + attr.getDataType().name());
String type = attribute.getDataType() != null ? AttributeType.getValueString(attribute.getDataType()) : null; EditorAttributeIdentifier parent =
private Instant convertToDateTime(Object value) { try { return value != null ? Instant.ofEpochMilli(Double.valueOf(value.toString()).longValue()) : null; } catch (NumberFormatException e) { LOG.debug("", e); throw new AlgorithmException( format("'%s' can't be converted to type '%s'", value.toString(), DATE_TIME.toString())); } }
return enrichedTypeGuess.equals(INT) || enrichedTypeGuess.equals(LONG) || enrichedTypeGuess.equals(DECIMAL) || enrichedTypeGuess.equals(STRING) || enrichedTypeGuess.equals(TEXT); return enrichedTypeGuess.equals(DECIMAL) || enrichedTypeGuess.equals(DATE) || enrichedTypeGuess.equals(DATE_TIME) || enrichedTypeGuess.equals(STRING) || enrichedTypeGuess.equals(TEXT); case LONG: return enrichedTypeGuess.equals(LONG) || enrichedTypeGuess.equals(DECIMAL) || enrichedTypeGuess.equals(DATE) || enrichedTypeGuess.equals(DATE_TIME) || enrichedTypeGuess.equals(STRING) || enrichedTypeGuess.equals(TEXT); case BOOL: return enrichedTypeGuess.equals(STRING) || enrichedTypeGuess.equals(TEXT); case STRING: return enrichedTypeGuess.equals(STRING) || enrichedTypeGuess.equals(TEXT); case DATE_TIME: return enrichedTypeGuess.equals(STRING) || enrichedTypeGuess.equals(TEXT); case DATE: return enrichedTypeGuess.equals(STRING) || enrichedTypeGuess.equals(TEXT); default: return false;
private ConstraintViolation checkHyperlink( Entity entity, Attribute attribute, EntityType entityType) { String link = entity.getString(attribute.getName()); if (link == null) { return null; } try { new URI(link); } catch (URISyntaxException e) { return createConstraintViolation(entity, attribute, entityType, "Not a valid hyperlink."); } if (link.length() > HYPERLINK.getMaxLength()) { return createConstraintViolation(entity, attribute, entityType); } return null; }
private Double convertToDouble(Object value) { try { return value != null ? parseDouble(value.toString()) : null; } catch (NumberFormatException e) { LOG.debug("", e); throw new AlgorithmException( format("'%s' can't be converted to type '%s'", value.toString(), DECIMAL.toString())); } }
private ConstraintViolation checkEmail( Entity entity, Attribute attribute, EntityType entityType) { String email = entity.getString(attribute.getName()); if (email == null) { return null; } if (emailValidator == null) { emailValidator = new EmailValidator(); } if (!emailValidator.isValid(email, null)) { return createConstraintViolation( entity, attribute, entityType, "Not a valid e-mail address."); } if (email.length() > EMAIL.getMaxLength()) { return createConstraintViolation(entity, attribute, entityType); } return null; }
private Long convertToLong(Object value) { Long convertedValue; try { convertedValue = value != null ? round(parseDouble(value.toString())) : null; } catch (NumberFormatException e) { LOG.debug("", e); throw new AlgorithmException( format("'%s' can't be converted to type '%s'", value.toString(), LONG.toString())); } return convertedValue; } }
@Override public AttributeType guessAttributeType(List<Object> dataValues) { boolean guessCompleted = false; int rowCount = dataValues.size(); int currentRowIndex = 0; AttributeType currentGuess = getBasicAttributeType(dataValues.get(0)); currentGuess = getEnrichedType(currentGuess, dataValues.get(currentRowIndex)); while (currentRowIndex < rowCount && !guessCompleted) { Object value = dataValues.get(currentRowIndex); AttributeType basicType = getBasicAttributeType(value); AttributeType basicTypeGuess = getCommonType(currentGuess, basicType); AttributeType enrichedTypeGuess = getEnrichedType(basicTypeGuess, value); // If the newly found type is not narrower than the current type, do not update // e.g. a long does not fit into an integer if (isBroader(enrichedTypeGuess, currentGuess)) { currentGuess = enrichedTypeGuess; } // If a guess is TEXT, there is no other type option suitable if (TEXT.equals(currentGuess)) { guessCompleted = true; } currentRowIndex++; } if (currentGuess == null) { currentGuess = STRING; } return currentGuess; }
this.maxLength = attr.getDataType().getMaxLength(); } else this.maxLength = null;
LocalDate convertToDate(Object value) { try { return value != null ? Instant.ofEpochMilli(Double.valueOf(value.toString()).longValue()) .atZone(ZoneId.systemDefault()) .toLocalDate() : null; } catch (NumberFormatException e) { LOG.debug("", e); throw new AlgorithmException( format("'%s' can't be converted to type '%s'", value.toString(), DATE.toString())); } }
if (!mappingTargetAttributeType.equals(targetRepositoryAttributeType)) { throw new MolgenisDataException( format(
this.description = attr.getDescription(getCurrentUserLanguageCode()); this.enumOptions = attr.getDataType() == AttributeType.ENUM ? attr.getEnumOptions() : null; this.maxLength = attr.getDataType().getMaxLength(); this.expression = attr.getExpression();
private Instant convertToDateTime(Object value) { try { return value != null ? Instant.ofEpochMilli(Double.valueOf(value.toString()).longValue()) : null; } catch (NumberFormatException e) { LOG.debug("", e); throw new AlgorithmException( format("'%s' can't be converted to type '%s'", value.toString(), DATE_TIME.toString())); } }