protected void copyAccessors(Schema schema) { SchemaFactory parentSchemaFactory = schemaFactory; Class<?> clz = parentSchemaFactory.getSchemaClass(schema.getId()); if (clz == null) { return; } schemaClasses.put(schema.getId().toLowerCase(), clz); Schema parentSchema = parentSchemaFactory.getSchema(clz); for (Map.Entry<String, Field> entry : schema.getResourceFields().entrySet()) { ((FieldImpl) entry.getValue()).setName(entry.getKey()); Field parentField = parentSchema.getResourceFields().get(entry.getKey()); if (parentField == null || !(parentField instanceof FieldImpl)) { continue; } ((FieldImpl) entry.getValue()).setReadMethod(((FieldImpl) parentField).getReadMethod()); } }
protected void addField(SchemaImpl schema, String name, FieldType type, String... options) { Field f = schema.getResourceFields().get(name); if (f != null) { return; } FieldImpl newField = new FieldImpl(); newField.setTypeEnum(type); newField.setName(name); if (type == FieldType.ENUM) { newField.setOptions(Arrays.asList(options)); } else { newField.setNullable(true); } schema.getResourceFields().put(name, newField); }
protected void processProperty(SchemaImpl schema, PropertyDescriptor prop) { if (TypeUtils.ID_FIELD.equals(prop.getName())) { return; } FieldImpl field = getField(schema, prop.getName()); Method writeMethod = prop.getWriteMethod(); Method readMethod = prop.getReadMethod(); if (field == null || writeMethod == null) { return; } Column column = writeMethod.getAnnotation(Column.class); if (column == null && readMethod != null) { column = readMethod.getAnnotation(Column.class); } if (column == null) { return; } field.setNullable(field.getTypeEnum() == FieldType.STRING ? true : column.nullable()); if (column.length() > 0) { field.setMaxLength((long) column.length()); } if (!prop.getName().equals(TypeUtils.ID_FIELD)) { field.setCreate(true); } field.setUpdate(true); }
protected void addStates(SchemaImpl schema, SchemaFactory factory) { String type = factory.getBaseType(schema.getId()); Set<String> validStates = this.validStates.get(type); Field stateField = schema.getResourceFields().get(ObjectMetaDataManager.STATE_FIELD); if (validStates != null && stateField instanceof FieldImpl) { FieldImpl field = (FieldImpl) stateField; field.setOptions(new ArrayList<String>(validStates)); field.setTypeEnum(FieldType.ENUM); } }
protected void assignSimpleProps(FieldImpl field, io.github.ibuildthecloud.gdapi.annotation.Field f) { if (!StringUtils.isEmpty(f.defaultValue())) { field.setDefault(f.defaultValue()); } if (!StringUtils.isEmpty(f.validChars())) { field.setValidChars(f.validChars()); } if (!StringUtils.isEmpty(f.invalidChars())) { field.setInvalidChars(f.invalidChars()); } if (f == this.defaultField) { field.setNullable(writableByDefault); field.setUpdate(writableByDefault); field.setCreate(writableByDefault); } else { field.setNullable(f.nullable()); field.setUpdate(f.update()); field.setCreate(f.create()); field.setTransform(f.transform()); } field.setUnique(f.unique()); field.setRequired(f.required()); }
protected FieldImpl getField(Class<?> clz, PropertyDescriptor prop) { FieldImpl field = new FieldImpl(); return null; field.setReadMethod(readMethod); field.setName(prop.getName()); } else { field.setName(f.name()); field.setDescription(f.description()); field.setDisplayIndex(f.displayIndex()); field.setIncludeInList(false);
Field oldField = existingFields.put(entry.getKey(), entry.getValue()); if (oldField instanceof FieldImpl) { ((FieldImpl)entry.getValue()).setReadMethod(((FieldImpl) oldField).getReadMethod()); ((FieldImpl)entry.getValue()).setAttributes(oldField.getAttributes());
public FieldImpl(Field field) { this.name = field.getName(); this.description = field.getDescription(); this.validChars = field.getValidChars(); this.invalidChars = field.getInvalidChars(); this.create = field.isCreate(); this.readOnCreateOnly = field.isReadOnCreateOnly(); this.transform = field.getTransform(); this.update = field.isUpdate(); this.includeInList = field.isIncludeInList(); this.nullable = field.isNullable(); this.unique = field.isUnique(); this.required = field.isRequired(); this.min = field.getMin(); this.max = field.getMax(); this.minLength = field.getMinLength(); this.maxLength = field.getMaxLength(); this.defaultValue = field.getDefault(); this.options = field.getOptions() == null ? null : new ArrayList<String>(field.getOptions()); this.displayIndex = field.getDisplayIndex(); this.attributes = new HashMap<String, Object>(field.getAttributes()); if (field instanceof FieldImpl) { this.readMethod = ((FieldImpl)field).getReadMethod(); this.defaultIsNull = ((FieldImpl)field).isDefaultIsNull(); } setType(field.getType()); }
protected FieldType assignSimpleType(Class<?> clzType, FieldImpl field) { FieldType result = null; if (clzType.isEnum()) { result = FieldType.ENUM; } else { outer: for (FieldType type : FieldType.values()) { Class<?>[] clzs = type.getClasses(); if (clzs == null) continue; for (Class<?> clz : clzs) { if (clz.isAssignableFrom(clzType)) { result = type; if ((Number.class.isAssignableFrom(clzType) || Boolean.class.isAssignableFrom(clzType)) && !clz.isPrimitive() && field != null) { field.setNullable(true); } break outer; } } } } if (field != null) { field.setTypeEnum(result); } return result; }
protected void assignType(PropertyDescriptor prop, FieldImpl field, io.github.ibuildthecloud.gdapi.annotation.Field f) { if (f.type() != FieldType.NONE) { field.setTypeEnum(f.type()); return; } if (!StringUtils.isEmpty(f.typeString())) { field.setType(f.typeString()); return; } if (f.password()) { field.setTypeEnum(FieldType.PASSWORD); return; } assignSimpleType(prop.getPropertyType(), field); List<TypeAndName> types = new ArrayList<FieldType.TypeAndName>(); Method readMethod = prop.getReadMethod(); if (readMethod != null) { getTypes(readMethod.getGenericReturnType(), types); } if (types.size() == 1) { field.setType(types.get(0).getName()); } else if (types.size() > 1) { types.remove(0); field.setSubTypesList(types); } }
protected void assignLengths(FieldImpl field, io.github.ibuildthecloud.gdapi.annotation.Field f) { if (f.min() != Long.MIN_VALUE) { field.setMin(f.min()); } if (f.max() != Long.MAX_VALUE) { field.setMax(f.max()); } if (f.minLength() != Long.MIN_VALUE) { field.setMinLength(f.minLength()); } if (f.maxLength() != Long.MAX_VALUE) { field.setMaxLength(f.maxLength()); } }
@Override public SchemaImpl postProcessRegister(SchemaImpl schema, SchemaFactory factory) { schema.setCreate(false); schema.setUpdate(false); schema.setDeletable(false); for (Field field : schema.getResourceFields().values()) { if (field instanceof FieldImpl) { ((FieldImpl) field).setCreate(false); ((FieldImpl) field).setUpdate(false); } } return schema; }
fieldImpl.setCreate(perm.isCreate()); fieldImpl.setUpdate(perm.isUpdate()); fieldImpl.setReadOnCreateOnly(perm.isReadOnCreateOnly());
protected List<String> getModifiers(FieldImpl field) { FieldType type = field.getTypeEnum(); if (type == null) { return Collections.emptyList(); } List<String> conditions = new ArrayList<String>(type.getModifiers().size() + 2); for (ConditionType conditionType : type.getModifiers()) { conditions.add(conditionType.getExternalForm()); } if (field.isNullable()) { if (!conditions.contains(ConditionType.NULL.getExternalForm())) { conditions.add(ConditionType.NULL.getExternalForm()); } if (!conditions.contains(ConditionType.NOTNULL.getExternalForm())) { conditions.add(ConditionType.NOTNULL.getExternalForm()); } } return conditions; }
@Override public Schema parseSchema(String name) { SchemaImpl schema = readSchema(name); Class<?> clz = typeToClass.get(name); processParent(schema); List<Field> fields = getFields(clz); for (Map.Entry<String, Field> entry : schema.getResourceFields().entrySet()) { Field field = entry.getValue(); if (field instanceof FieldImpl) { ((FieldImpl)field).setName(entry.getKey()); } fields.add(field); } Map<String, Field> resourceFields = sortFields(fields); schema.setResourceFields(resourceFields); schema.getResourceActions().putAll(getResourceActions(clz)); schema.getCollectionActions().putAll(getCollectionActions(clz)); for (SchemaPostProcessor processor : postProcessors) { schema = processor.postProcess(schema, this); } addToMap(schemasByName, schema, schema); if (clz == null && schema.getParent() != null) { clz = typeToClass.get(schema.getParent()); if (clz != null) { addToMap(typeToClass, schema, clz); } } return schema; }
protected Map<String, Field> copyFields(Map<String, Field> input) { Map<String, Field> result = new LinkedHashMap<String, Field>(); for (String key : input.keySet()) { result.put(key, new FieldImpl(input.get(key))); } return result; }
protected void assignOptions(PropertyDescriptor prop, FieldImpl field, io.github.ibuildthecloud.gdapi.annotation.Field f) { Class<?> clz = prop.getPropertyType(); if (!clz.isEnum()) { return; } List<String> options = new ArrayList<String>(clz.getEnumConstants().length); for (Object o : clz.getEnumConstants()) { options.add(o.toString()); } field.setOptions(options); }
fieldImpl.setType(FieldType.toString(FieldType.REFERENCE, factory.getSchema(relationship.getObjectType()).getId()));