@Override
public Object apply(ActionParams params) {
MApiModel am = api.getMetadata().getModel(model.getName());
ModelExecutorContext context = new SimpleModelExecutorContext(api, dao, am, em, params);
ModelDeleteExecutor executor = newDeleteExecutor(context);
Object id = id(params);
DeleteOptions options = cascadeDelete ? getWithId(params, 0) : null;
if (!cascadeDelete) {
Request request = Request.tryGetCurrent();
String param = request.getParameter("cascade_delete");
if (!Strings.isEmpty(param) && Converts.toBoolean(param)) {
throw new BadRequestException("Cascade delete not supported by this operation, check parameter 'cascade_delete'!");
}
}
DeleteOneResult result = executor.deleteOne(id, options);
if (null != result.entity) {
return ApiResponse.of(result.entity);
} else {
if (result.success) {
return ApiResponse.NO_CONTENT;
} else {
throw new NotFoundException(am.getName() + " '" + id.toString() + "' not found");
}
}
}