Search in sources :

Example 1 with Input

use of info.xiancloud.core.Input in project xian by happyyangyuan.

the class UnitMdBuilderHandler method build.

@Override
public void build() {
    LOG.info("-----unit接口文档开始构建----");
    Multimap<String, UnitProxy> unitMultimap = filter.filter(buildUnits());
    if (unitMultimap == null || unitMultimap.isEmpty()) {
        LOG.info("-----unit接口没扫描到业务模块,退出构建");
        invokeCallback(null);
        return;
    }
    LOG.info(String.format("-----unit接口扫描到业务模块数量:%s", unitMultimap.size()));
    try {
        LOG.info("----unit接口开始生成API文档-----");
        // FileWriter fw = new FileWriter(storePath);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Writer wout = new OutputStreamWriter(bos);
        BufferedWriter bw = new BufferedWriter(wout);
        bw.write(String.format("# %s", StringUtil.isEmpty(docName) ? EnvUtil.getShortEnvName() + "业务接口文档" : docName));
        // 自定义描述
        if (!StringUtil.isEmpty(subDec)) {
            bw.newLine();
            bw.write(subDec);
        }
        bw.newLine();
        for (String groupName : unitMultimap.keySet()) {
            GroupProxy groupProxy = GroupDiscovery.singleton.newestDefinition(groupName);
            // todo it recommended to use a template to generate this MD fragment.
            bw.write("## " + String.format("%s\r\n", StringUtil.isEmpty(groupProxy.getDescription()) ? groupProxy.getName() : groupProxy.getDescription()));
            bw.newLine();
            bw.write(" 接口列表\r\n");
            Collection<UnitProxy> unitProxies = unitMultimap.get(groupName);
            for (UnitProxy unitBean : unitProxies) {
                if (!unitBean.getMeta().isPublic()) {
                    LOG.info(String.format(" ---api-doc-unit接口:%s/%s非公开访问的,跳过生成", groupProxy.getName(), unitBean.getName()));
                    continue;
                }
                LOG.info(String.format(" ---api-doc-unit接口开始生成:%s/%s", groupProxy.getName(), unitBean.getName()));
                Input io = unitBean.getInput();
                bw.write(String.format("### /%s/%s", groupProxy.getName(), unitBean.getName()));
                bw.newLine();
                bw.write(String.format(" * 接口描述: %s\r\n", StringUtil.isEmpty(unitBean.getMeta().getDescription()) ? "暂无" : unitBean.getMeta().getDescription()));
                bw.newLine();
                bw.write(" * 调用方式: POST");
                bw.newLine();
                bw.write(" * 入参数据结构说明\r\n");
                bw.newLine();
                bw.write(" <table border='1' class='table table-bordered table-striped table-condensed'>");
                bw.newLine();
                bw.write("<tr><td>名称</td><td>数据类型</td><td>参数说明</td><td>必须</td></tr>");
                bw.newLine();
                // |\r\n");
                if (io != null) {
                    List<Obj> objList = io.getList();
                    for (Obj obj : objList) {
                        bw.write("<tr>");
                        bw.newLine();
                        bw.write(String.format("<td>%s</td><td>%s</td><td>%s</td><td>%s</td>", obj.getName(), obj.getClazz().getName(), StringUtil.isEmpty(obj.getDescription()) ? "暂无" : obj.getDescription(), obj.isRequired() ? "是" : "否"));
                        bw.newLine();
                        bw.write("</tr>");
                    }
                }
                bw.write("</table>\r\n");
                bw.newLine();
                bw.write(" * 返回数据格式\r\n");
                bw.newLine();
                bw.write(String.format("````json\r\n%s\r\n````\r\n", unitBean.getMeta().getSuccessfulUnitResponse() == null ? "暂无" : unitBean.getMeta().getSuccessfulUnitResponse().toVoJSONString(true)));
                bw.write("&nbsp;&nbsp;\r\n");
            }
        }
        bw.write("&nbsp;&nbsp;\r\n");
        bw.flush();
        invokeCallback(bos.toByteArray());
        LOG.info("-----unit接口文档构建完成----");
    } catch (Exception e) {
        LOG.error(e);
    }
}
Also used : GroupProxy(info.xiancloud.core.distribution.GroupProxy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) Input(info.xiancloud.core.Input) Obj(info.xiancloud.core.Input.Obj) OutputStreamWriter(java.io.OutputStreamWriter) UnitProxy(info.xiancloud.core.distribution.UnitProxy) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with Input

use of info.xiancloud.core.Input in project xian by happyyangyuan.

the class ISequencer method build.

static ISequencer build(String group, String unit, JSONObject argMap) {
    Unit unit1 = LocalUnitsManager.getLocalUnit(group, unit);
    Input input = unit1.getInput();
    if (input != null && input.isSequential()) {
        LOG.info("sequential: " + group + "." + unit);
        return new DefaultSequencer(group, unit, argMap);
    } else {
        return new NoSequenceGuaranteeSequencer();
    }
}
Also used : Input(info.xiancloud.core.Input) DefaultSequencer(info.xiancloud.core.sequence.default_sequencer.DefaultSequencer) NoSequenceGuaranteeSequencer(info.xiancloud.core.sequence.sequence_no_garantee.NoSequenceGuaranteeSequencer) Unit(info.xiancloud.core.Unit)

Aggregations

Input (info.xiancloud.core.Input)2 Obj (info.xiancloud.core.Input.Obj)1 Unit (info.xiancloud.core.Unit)1 GroupProxy (info.xiancloud.core.distribution.GroupProxy)1 UnitProxy (info.xiancloud.core.distribution.UnitProxy)1 DefaultSequencer (info.xiancloud.core.sequence.default_sequencer.DefaultSequencer)1 NoSequenceGuaranteeSequencer (info.xiancloud.core.sequence.sequence_no_garantee.NoSequenceGuaranteeSequencer)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1