com.atsid.play.controllers.CrudController Maven / Gradle / Ivy
package com.atsid.play.controllers;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.databind.JsonNode;
import play.Logger;
import play.Play;
import play.db.ebean.Model;
import play.libs.Json;
import java.util.ArrayList;
import java.util.List;
/**
* TODO: Thinking about changing this from an inheritance pattern to a composition.
* Controller that provides built-in CRUD operations for flat models.
* @param The type of model managed by this controller.
*/
public class CrudController extends BaseCrudController {
public CrudController(Class modelType) {
super(Long.class, modelType);
}
protected List getItemsFromRequest() {
JsonNode body = request().body().asJson();
if (body != null && body.isArray()) {
List items = new ArrayList();
for (final JsonNode itemNode : body) {
if (itemNode.isNumber()) {
items.add(itemNode.asLong());
} else if (itemNode.isObject()) {
items.add(itemNode.get("id").asLong());
}
}
return items;
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy