@Override public String getBaseType() { return getType(); }
public ValidationErrorException(String code, String fieldName) { super(new ValidationErrorImpl(code, fieldName)); }
public SchemaImpl() { setType("schema"); }
public void load(SchemaImpl schema) { this.create = schema.isCreate(); this.update = schema.isUpdate(); this.list = schema.isList(); this.deletable = schema.isDeletable(); this.byId = schema.isById(); this.includeableLinks = new ArrayList<String>(schema.getIncludeableLinks()); this.resourceFields = copyFields(schema.getResourceFields()); this.collectionFilters = copyFilters(schema.getCollectionFilters()); this.resourceActions = copyActions(schema.getResourceActions()); this.collectionActions = copyActions(schema.getCollectionActions()); this.collectionFields = copyFields(schema.getCollectionFields()); }
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); }
@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; }
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); } }
public SchemaImpl(SchemaImpl schema) { this(); this.name = schema.getId(); this.parent = schema.getParent(); this.children = new ArrayList<String>(schema.getChildren()); this.pluralName = schema.getPluralName(); this.load(schema); }
protected FieldImpl getField(SchemaImpl schema, String name) { Field field = schema.getResourceFields().get(name); if (field instanceof FieldImpl) { return (FieldImpl) field; } return null; } }
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 Map<String, URL> getLinks() { Map<String, URL> links = super.getLinks(); links.remove(UrlBuilder.SELF); return links; } }
public ValidationErrorException(String code, String fieldName, String message) { super(new ValidationErrorImpl(code, fieldName)); ((ValidationErrorImpl)getApiError()).setMessage(message); }
protected Resource constructResource(IdFormatter idFormatter, SchemaFactory schemaFactory, Schema schema, Object obj, ApiRequest apiRequest) { return new WrappedResource(idFormatter, schemaFactory, schema, obj, apiRequest.getMethod()); }
protected boolean isResource(Object obj) { if (obj instanceof Resource) { return true; } if (obj instanceof List<?>) { List<?> list = (List<?>)obj; if (list.size() == 0 || isResource(list.get(0))) { return true; } } return false; }
@Override public String getBaseType() { String parent = schema.getParent(); return parent == null ? getType() : parent; }
protected FieldImpl getField(SchemaImpl schema, String name) { Field field = schema.getResourceFields().get(name); if (field instanceof FieldImpl) { return (FieldImpl) field; } return null; }
public static final void throwValidationError(String code, String fieldName, String message, String detail) { throw new ClientVisibleException(new ValidationErrorImpl(code, fieldName, message, detail)); } }
@Override public String getType() { String type = super.getType(); return type == null ? schema.getId() : type; }
protected static Object error(String code, String fieldName) { ValidationErrorImpl error = new ValidationErrorImpl(code, fieldName); throw new ClientVisibleException(error); }