Skip to content
Brian Gormanly edited this page Sep 28, 2016 · 4 revisions

FdfCommonServices API

The Service layer is the icing on the onion (I started the layers of the onion, not cake, earlier, so it best to stay consistent). The FdfCommonServices abstract class contains the implementation for many common service methods. You can extend this class in your application and partake in all the available 4DF API goodness.

Here are some examples of how your services can leverage and extend the library, I have created a imaginary service for a Onion class.

getAllOnions()

    public List<Onion> getAllOnions() {
        return this.getAllCurrent(Onion.class);
    }

getAllOnionsWithHistory()

    public List<FdfEntity<Onion>> getAllOnionsWithHistory() {
        return this.getAll(Onion.class);
    }

getOnionsByColor()

Returns a FdfEntity list with results. getEntitiesByValueForPassedField allows you to query by any property in your class like so:

    public List<FdfEntity<Onion>> getOnionByColor(String color) {
        return getEntitiesByValueForPassedField(Onion.class, "color", color);
    }

getOnionsByColorAndName()

use getEntitiesByValuesForPassedFields to do queries by multiple fields in a HashMap.

    public List<FdfEntity<Onion>> getOnionsByColorAndName(String color, String name) {
        HashMap<String, String> fieldsAndValues = new HashMap<>();
        fieldsAndValues.put("color", color);
        fieldsAndValues.put("name", name);

        List<FdfEntity<Onion>> onions =
                    getEntitiesByValuesForPassedFields(Onion.class, fieldsAndValues);

        return onions;
    }

save example

Saving an Onion:

    public Role save(Onion onion) {
        return this.save(onion, Onion.class);
    }