protected Resource constructResource(IdFormatter idFormatter, SchemaFactory schemaFactory, Schema schema, Object obj, ApiRequest apiRequest) { return new WrappedResource(idFormatter, schemaFactory, schema, obj, apiRequest.getMethod()); }
@Override public String getBaseType() { String parent = schema.getParent(); return parent == null ? getType() : parent; }
public WrappedResource(IdFormatter idFormatter, SchemaFactory schemaFactory, Schema schema, Object obj, Map<String, Object> additionalFields, Set<String> priorityFieldNames, String method) { super(); this.schemaFactory = schemaFactory; this.schema = schema; this.resourceFields = schema.getResourceFields(); this.obj = obj; this.idFormatter = idFormatter; this.additionalFields = additionalFields; this.priorityFieldNames = priorityFieldNames; this.method = method; init(); }
addField(name, IdFormatterUtils.formatReference(field, idFormatter, value, schemaFactory)); if (createTsFields && field.getTypeEnum() == FieldType.DATE && value instanceof Date) { addField(name + "TS", ((Date)value).getTime()); String key = entry.getKey(); Field field = resourceFields.get(key); if ((field != null && field.isIncludeInList()) || isResource(value)) { addField(key, value); Object id = idFormatter.formatId(getType(), getIdValue()); if (id != null) { setId(id.toString());
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; }
protected Resource createResource(SchemaFactory schemaFactory, Object obj) { if (obj == null) return null; if (obj instanceof Resource) return (Resource)obj; Schema schema = schemaFactory.getSchema(obj.getClass()); ApiContext apiContext = ApiContext.getContext(); return schema == null ? null : new WrappedResource(apiContext.getIdFormatter(), schemaFactory, schema, obj, apiContext.getApiRequest().getMethod()); }
public static Resource createResourceWithAttachments(final ResourceManager resourceManager, final ApiRequest request, final IdFormatter idFormatter, final SchemaFactory schemaFactory, final Schema schema, Object obj, Map<String, Object> inputAdditionalFields) { Integer depth = DEPTH.get(); try { DEPTH.set(depth + 1); Map<String, Object> additionalFields = new LinkedHashMap<String, Object>(); additionalFields.putAll(DataUtils.getFields(obj)); if (inputAdditionalFields != null && inputAdditionalFields.size() > 0) { additionalFields.putAll(inputAdditionalFields); } if (depth == 0) { Map<String, Object> attachments = ApiUtils.getAttachements(obj, new Transformer() { @Override public Object transform(Object input) { input = ApiUtils.authorize(input); if (input == null) return null; return resourceManager.convertResponse(input, request); } }); additionalFields.putAll(attachments); } String method = request == null ? null : request.getMethod(); return new WrappedResource(idFormatter, schemaFactory, schema, obj, additionalFields, PRIORITY_FIELDS, method); } finally { DEPTH.set(depth); } }