org.neogroup.warp.resources.GenericResourceProxy Maven / Gradle / Ivy
package org.neogroup.warp.resources;
import org.neogroup.warp.data.DataObject;
import org.neogroup.warp.utils.Introspection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class GenericResourceProxy extends ResourceProxy {
public GenericResourceProxy(String resourceName, Resource resource) {
super(resourceName, resource);
}
public Collection find() {
return createDataCollection(super.find());
}
public Collection insert () {
return createDataCollection(super.insert());
}
public Collection update () {
return createDataCollection(super.update());
}
public Collection delete () {
return createDataCollection(super.delete());
}
private Collection createDataCollection(Collection collection) {
List dataCollection = null;
if (collection != null) {
dataCollection = new ArrayList<>();
for (Object object : collection) {
DataObject dataObject = new DataObject();
List properties = Introspection.getProperties(object.getClass());
for (Introspection.Property property : properties) {
dataObject.set(property.getName(), property.getValue(object));
}
dataCollection.add(dataObject);
}
}
return dataCollection;
}
}