* Finds a persistable object via the persistable querier.
*/
private Object getPersistable(Object actual,
Class<? extends Persistable> type, String parameterName) {
Class<? extends Persistable> ptype = type.asSubclass(Persistable.class);
Querier querier = ThreadContext.getWebSite().getQuerier();
int id = -1;
Method p = findQueryMethod(ptype);
if ("".equals(actual)) {
return null;
}
if (p != null) {
String name = p.getName();
name = name.substring(3, 4).toLowerCase() + name.substring(4);
id = querier.getIdFromProperty(ptype, name, (String) actual);
} else {
try {
id = Integer.parseInt(String.valueOf(actual));
} catch (NumberFormatException e) {
throw new BadRequestException(String.format("Expected '%s' to be an integer, but it was %s", parameterName, actual));
}
}
return querier.getObject(ptype, id);
}