final DataSchema primitiveSchema = DataSchemaUtil.classToPrimitiveDataSchema(type); if (primitiveSchema != null)
private static void checkPathsAgainstSchema(RecordDataSchema dataSchema, String resourceClassName, String annotationName, String[] paths) { for (String path : paths) { if (!DataSchemaUtil.containsPath(dataSchema, path)) { throw new ResourceConfigException("In resource class '" + resourceClassName + "', " + annotationName + " annotation " + path + " is not a valid path for " + dataSchema.getName() + "."); } } }
/** * Returns the java class representing the de-referenced type of the input schema. */ public static Class<?> getDataClassFromSchema(DataSchema schema) { if (schema == null) { return null; } return dataSchemaTypeToPrimitiveDataSchemaClass(schema.getDereferencedType()); }
if (s != null) DataSchema.Type found = DataSchemaUtil.typeStringToComplexDataSchemaType(s); if (found != null) DataSchema primitiveDataSchema = DataSchemaUtil.typeStringToPrimitiveDataSchema(s); if (primitiveDataSchema != null)
@Override public String computeFullName(String name) { String fullname; DataSchema schema = DataSchemaUtil.typeStringToPrimitiveDataSchema(name); if (schema != null) { fullname = name; } else if (Name.isFullName(name) || getCurrentNamespace().isEmpty()) { fullname = name; // already a fullname } else if (currentImports.containsKey(name)) { // imported names are higher precedence than names in current namespace fullname = currentImports.get(name).getFullName(); } else { fullname = getCurrentNamespace() + "." + name; // assumed to be in current namespace } return fullname; }
if (DataSchemaUtil.containsPath(prevSchema, pathString)) if (DataSchemaUtil.containsPath(currSchema, pathString)) if (!DataSchemaUtil.getField(currSchema, pathString).getOptional() && annotationClass.equals(ReadOnly.class))
/** * Determines whether a path is valid according to the given data schema. * The path must be a field of a record, and not an enum constant, a member of a union, etc. * Wild card (*) for array indices and map keys are accepted. */ public static boolean containsPath(DataSchema schema, String path) { return getField(schema, path) != null; }
public FieldDef(String name, Class<T> type, DataSchema dataSchema) { _name = name; _type = type; _dataSchema = dataSchema; /** * FieldDefs representing context, pagination, or things relating to synchronization will not * have schemas, so dataSchema and thus dataClass can be null. */ _dataClass = getDataClassFromSchema(_dataSchema); StringBuilder errorMessageBuilder = new StringBuilder(); _field = new RecordDataSchema.Field(_dataSchema); _field.setName(_name, errorMessageBuilder); }
DataSchema.Type type = DataSchemaUtil.typeStringToComplexDataSchemaType(typeString); if (type == null)
DataSchema primitiveSchema = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchema(type); if (primitiveSchema != null)
/** * Look for {@link DataSchema} with the specified name. * * @param fullName to lookup. * @return the {@link DataSchema} if lookup was successful else return null. */ public DataSchema lookupName(String fullName) { DataSchema schema = DataSchemaUtil.typeStringToPrimitiveDataSchema(fullName); if (schema == null) { schema = getResolver().findDataSchema(fullName, errorMessageBuilder()); } return schema; }
/** * Same as {@link #getField(DataSchema, Object[])}, but with the path as string. */ public static RecordDataSchema.Field getField(DataSchema schema, String path) { // Discard the initial / character if present if (path.length() > 0 && path.charAt(0) == DataElement.SEPARATOR) { path = path.substring(1); } return getField(schema, path.split(DataElement.SEPARATOR.toString())); }
.map(val -> DataTemplateUtil.coerceOutput(val, getDataClassFromSchema(itemSchema))) .collect(Collectors.toList()) );
public String computeFullName(String name) { String fullname; if (DataSchemaUtil.typeStringToPrimitiveDataSchema(name) != null) { fullname = name; } else if (Name.isFullName(name)) { fullname = name; // already a fullname } else if (currentImports.containsKey(name)) { // imported names are higher precedence than names in current namespace fullname = currentImports.get(name).getFullName(); } else if (getCurrentNamespace().isEmpty()) { fullname = name; } else { fullname = getCurrentNamespace() + "." + name; // assumed to be in current namespace } return fullname; }
/** * * @param value the stringified value * @param schema the schema of the type * @param type a non-complex type to convert to * @return the converted value */ public static Object convertSimpleValue(final String value, final DataSchema schema, final Class<?> type) { DataSchema.Type dereferencedType = schema.getDereferencedType(); Object underlyingValue; if (schema.getDereferencedDataSchema().isComplex()) { underlyingValue = value; } else { underlyingValue = ValueConverter.coerceString(value, DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchemaClass(dereferencedType)); } return DataTemplateUtil.coerceOutput(underlyingValue, type); }
private static Key buildKey(String resourceName, String keyName, Class<?> keyType, Class<? extends TyperefInfo> typerefInfoClass) { try { // If the key is a non-primitive custom type, initialize the keyType class so that the corresponding coercer is // loaded into memory such that the coercer would have been registered when we process an incoming request for // this resource. if (typerefInfoClass != RestAnnotations.NULL_TYPEREF_INFO.class && DataSchemaUtil.classToPrimitiveDataSchema( keyType) == null) { Custom.initializeCustomClass(keyType); } return new Key(keyName, keyType, getDataSchema(keyType, getSchemaFromTyperefInfo(typerefInfoClass))); } catch (TemplateRuntimeException e) { throw new ResourceConfigException("DataSchema for key '" + keyName + "' of type " + keyType + " on resource " + resourceName + "cannot be found; type is invalid or requires typeref", e); } catch (Exception e) { throw new ResourceConfigException("Typeref for parameter '" + keyName + "' on resource " + resourceName + " cannot be instantiated, " + e.getMessage(), e); } }
/** * Look for {@link DataSchema} with the specified name. * * @param fullName to lookup. * @return the {@link DataSchema} if lookup was successful else return null. */ public DataSchema lookupName(String fullName) { DataSchema schema = DataSchemaUtil.typeStringToPrimitiveDataSchema(fullName); if (schema == null) { schema = getResolver().findDataSchema(fullName, errorMessageBuilder()); } return schema; }
itemType = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchemaClass( itemSchema.getDereferencedType());
/** * Compute the full name from a name. * * If the name identifies a primitive type, return the name. * If the name is unqualified, the full name is computed by * pre-pending the current namespace and "." to the input name. * If the name is a full name, i.e. it contains a ".", then * return the name. * * @param name as input to compute the full name. * @return the computed full name. */ public String computeFullName(String name) { String fullname; DataSchema schema = DataSchemaUtil.typeStringToPrimitiveDataSchema(name); if (schema != null) { fullname = name; } else if (Name.isFullName(name) || getCurrentNamespace().isEmpty()) { fullname = name; } else { fullname = getCurrentNamespace() + "." + name; } return fullname; }
Class<?> targetClass = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchemaClass(parameterSchema.getItems().getDereferencedType());