All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.neogroup.warp.resources.GenericResourceProxy Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy