@Override public Object runManageableAction(String action) { Method method = Cls.findMethod(source().getClass(), Str.uncapitalized(action)); if (method != null) { return Cls.invoke(method, source()); } else { return doManageableAction(action); } }
@Override public String kind() { return Manageables.kindOf(source().getClass()); }
@Override public final void reloadManageable() { final Promise<Void> promise = Promises.create(); doReloadManageable(promise); try { promise.get(5000); } catch (TimeoutException e) { Log.error("Couldn't reload the manageable!", e); } }
@Override public List<String> getManageableActions() { Object source = source(); List<String> actions = U.list(); List<Method> actionMethods = Cls.getMethodsAnnotated(source.getClass(), Action.class); // sort the actions by @Order Msc.sortByOrder(actionMethods); for (Method method : actionMethods) { Action action = method.getAnnotation(Action.class); actions.add(!action.name().isEmpty() ? action.name() : method.getName()); } for (Method method : Cls.getMethodsAnnotated(source.getClass(), ActionCondition.class)) { ActionCondition condition = method.getAnnotation(ActionCondition.class); U.must(method.getReturnType() == boolean.class, "The method return type must be boolean: " + method); boolean cond = Cls.invoke(method, source); if (!cond) { String name; if (!condition.name().isEmpty()) { name = condition.name(); } else { name = method.getName(); U.must(name.startsWith("can"), "The action condition method must start with 'can', to infer the action name!"); name = Str.uncapitalized(Str.triml(name, "can")); } actions.remove(name); } } return actions; }
@Override public List<String> getManageableProperties() { BeanProperties props = Beany.propertiesOf(source()); List<String> ps = U.list(); for (Prop prop : props) { if (!prop.getName().contains("manageable")) { TypeKind kind = Cls.kindOf(prop.getType()); if (kind.isPrimitive() || kind.isNumber() || kind.isArray() || kind == TypeKind.STRING || kind == TypeKind.DATE) { ps.add(prop.getName()); } } } return ps; }