Search in sources :

Example 1 with PropertySpec

use of act.util.PropertySpec in project actframework by actframework.

the class RouterAdmin method listRoutes.

@Command(name = "act.route.list, act.route.print", help = "list routes")
@PropertySpec("method,path,compactHandler")
public Object listRoutes(@Optional("list routes in tree view") boolean tree, @Optional("specify the port name") String name, @Optional("specify route filter") String q) {
    final Router router = S.blank(name) ? app.router() : app.router(name);
    if (S.notBlank(q)) {
        if (q.contains(".") || q.contains("[") || q.contains("*")) {
        // already regex
        } else {
            // make it a regex
            q = ".*" + q + ".*";
        }
    }
    if (tree) {
        TreeNode root = new TreeNode() {

            @Override
            public String id() {
                return "root";
            }

            @Override
            public String label() {
                return "Router";
            }

            @Override
            public List<TreeNode> children() {
                List<TreeNode> l = new ArrayList<>();
                l.add(router._GET);
                l.add(router._POST);
                l.add(router._PUT);
                l.add(router._DEL);
                return l;
            }
        };
        return S.blank(q) ? root : new FilteredTreeNode(root, TreeNodeFilter.Common.pathMatches(q));
    } else {
        return routeInfoList(name, q);
    }
}
Also used : FilteredTreeNode(act.cli.tree.FilteredTreeNode) TreeNode(act.cli.tree.TreeNode) ArrayList(java.util.ArrayList) FilteredTreeNode(act.cli.tree.FilteredTreeNode) PropertySpec(act.util.PropertySpec) Command(act.cli.Command)

Example 2 with PropertySpec

use of act.util.PropertySpec in project actframework by actframework.

the class Endpoint method explore.

private void explore(RequestHandler handler) {
    RequestHandlerProxy proxy = $.cast(handler);
    ReflectedHandlerInvoker invoker = $.cast(proxy.actionHandler().invoker());
    Class<?> controllerClass = invoker.controllerClass();
    Method method = invoker.method();
    returnType = method.getReturnType();
    PropertySpec pspec = method.getAnnotation(PropertySpec.class);
    if (null != pspec) {
        PropertySpec.MetaInfo propSpec = new PropertySpec.MetaInfo();
        for (String v : pspec.value()) {
            propSpec.onValue(v);
        }
        for (String v : pspec.http()) {
            propSpec.onValue(v);
        }
        List<String> outputs = propSpec.outputFieldsForHttp();
        Set<String> excluded = propSpec.excludeFieldsForHttp();
        if (!(outputs.isEmpty() && excluded.isEmpty())) {
            fastJsonPropertyPreFilter = new FastJsonPropertyPreFilter(returnType, outputs, excluded, Act.app().service(DataPropertyRepository.class));
        }
    // just ignore cli value here
    }
    this.id = id(method);
    returnSample = generateSampleJson(BeanSpec.of(method.getGenericReturnType(), null, Act.injector()));
    Description descAnno = method.getAnnotation(Description.class);
    this.description = null == descAnno ? methodDescription(method) : descAnno.value();
    exploreParamInfo(method);
    if (!Modifier.isStatic(method.getModifiers())) {
        exploreParamInfo(controllerClass);
    }
    this.controllerClass = controllerClass;
}
Also used : ReflectedHandlerInvoker(act.handler.builtin.controller.impl.ReflectedHandlerInvoker) PropertySpec(act.util.PropertySpec) RequestHandlerProxy(act.handler.builtin.controller.RequestHandlerProxy) FastJsonPropertyPreFilter(act.util.FastJsonPropertyPreFilter)

Example 3 with PropertySpec

use of act.util.PropertySpec in project actframework by actframework.

the class SysUtilAdmin method ls.

@Command(name = "act.ls, act.dir, act.ll", help = "List files in the current working directory")
@PropertySpec("path as name,size,timestamp")
public List<FileInfo> ls(@act.cli.Optional("specify the path to be listed") String path, @act.cli.Optional(lead = "-a", help = "display hidden files") boolean showHidden, String path2, CliContext ctx) {
    if (S.blank(path) && S.notBlank(path2)) {
        path = path2;
    }
    if (S.blank(path)) {
        ctx.println(pwd());
        return dir(curDir(), showHidden, context);
    } else {
        ctx.println(path);
        File file = getFile(path);
        if (!file.exists()) {
            ctx.println("%s is not a file or directory", path);
            return null;
        } else {
            if (file.isDirectory()) {
                return dir(file, showHidden, context);
            } else {
                return C.list(new FileInfo(file.getParentFile(), file));
            }
        }
    }
}
Also used : File(java.io.File) PropertySpec(act.util.PropertySpec)

Aggregations

PropertySpec (act.util.PropertySpec)3 Command (act.cli.Command)1 FilteredTreeNode (act.cli.tree.FilteredTreeNode)1 TreeNode (act.cli.tree.TreeNode)1 RequestHandlerProxy (act.handler.builtin.controller.RequestHandlerProxy)1 ReflectedHandlerInvoker (act.handler.builtin.controller.impl.ReflectedHandlerInvoker)1 FastJsonPropertyPreFilter (act.util.FastJsonPropertyPreFilter)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1