if (target instanceof PersistableClass) {
// if we post to a schema, we can just consider this a post to the table
target = (Persistable) Identification.idForString(((PersistableClass) target).getId().toString() + "/").getTarget();
}
if (bodyData instanceof Persistable) {
Persistable newObject = (Persistable) bodyData;
ScriptableObject arrayProto = (ScriptableObject) ScriptableObject.getClassPrototype(GlobalData.getGlobalScope(), "Array");
ScriptableObject objectProto = (ScriptableObject) ScriptableObject.getClassPrototype(GlobalData.getGlobalScope(), "Object");
if ("".equals(((Persistable) target).getId().subObjectId)
&& (((Persistable) bodyData).getPrototype() == objectProto || ((Persistable) bodyData).getPrototype() == arrayProto)) {
// this means it is a generic object or list, we need to make it be the right class
DataSource thisSource = ((Persistable) target).getId().source;
Class targetClass = DataSourceManager.getObjectsClass(thisSource).objectsClass;
if (bodyData instanceof List) {
// this means that an array was provided for a data source that takes objects; we
// will assume this means that the user wants to create multiple objects
int i = 0;
for (Object obj : (List) bodyData) {
if (obj instanceof Persistable) {
newObject = Persevere.newObject(((Persistable) target).getId());
for (Map.Entry<String, Object> entry : ((Persistable) obj).entrySet(0)) {
newObject.set(entry.getKey(), entry.getValue());
}
((List) bodyData).set(i++, newObject);
} else
throw new RuntimeException("Bulk update arrays should only include objects");
}
return bodyData;
} else {
newObject = bodyData instanceof List ? Persevere.newArray(((Persistable) target).getId()) : Persevere
.newObject(((Persistable) target).getId());
for (Map.Entry<String, Object> entry : ((Persistable) bodyData).entrySet(0)) {
newObject.set(entry.getKey(), entry.getValue());
}
}
}
Client.getCurrentObjectResponse().getConnection().changeClientSideObject((Persistable) bodyData, newObject);
bodyData = newObject;