com.logicbus.xscript.SvcScan Maven / Gradle / Ivy
package com.logicbus.xscript;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.alogic.xscript.plugins.Segment;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import com.anysoft.util.Settings;
import com.logicbus.backend.ServantFactory;
import com.logicbus.backend.ServantRegistry;
import com.logicbus.models.catalog.CatalogNode;
import com.logicbus.models.servant.ServantCatalog;
import com.logicbus.models.servant.ServantCatalogNode;
import com.logicbus.models.servant.ServiceDescription;
import org.apache.commons.lang3.StringUtils;
/**
* 遍历所有的服务描述
*
* @since 1.6.13.7 [20200812 duanyy]
*/
public class SvcScan extends Segment {
protected boolean doSwagger = false;
public SvcScan(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p){
super.configure(p);
doSwagger = PropertiesConstants.getBoolean(p,"swagger",doSwagger);
}
@Override
protected void onExecute(XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
Settings settings = Settings.get();
ServantFactory sf = (ServantFactory)settings.get("servantFactory");
ServantRegistry sm = sf.getServantRegistry();
ServantCatalog[] catalog = sm.getServantCatalog();
for (int i = 0 ; i < catalog.length ; i ++){
ServantCatalogNode node = (ServantCatalogNode) catalog[i].getRoot();
if (node != null){
scanCatalog(catalog[i],node,root,current,ctx,watcher);
}
}
}
protected void scanCatalog(ServantCatalog catalog,ServantCatalogNode catalogRoot,XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher){
ServiceDescription[] services = catalogRoot.getServices();
for (ServiceDescription sd:services){
LogicletContext childCtx = new LogicletContext(ctx);
childCtx.SetValue("$id",sd.getServiceID());
childCtx.SetValue("$name",sd.getName());
childCtx.SetValue("$note",sd.getNote());
childCtx.SetValue("$module",sd.getModule());
childCtx.SetValue("$visible",sd.getVisible());
childCtx.SetValue("$path",sd.getPath());
childCtx.SetValue("$log",sd.getLogType().toString());
childCtx.SetValue("$acGroup",sd.getAcGroup());
childCtx.SetValue("$privilege", StringUtils.isEmpty(sd.getPrivilege())?sd.getPath():sd.getPrivilege());
childCtx.SetValue("$desc",
String.format("%s\n\n**Module**:%s
\n\n**Visible**:%s
\n\n**Log Type**:%s
\n\n**Access Control Group**:%s
\n\n**Privilage**:%s
",
sd.getNote(),sd.getModule(),sd.getVisible(),sd.getLogType().toString(),sd.getAcGroup(),sd.getPrivilege()));
String swagger = "false";
if (doSwagger){
Logiclet onSwagger = sd.getSwaggerLogiclet();
if (onSwagger != null){
onSwagger.execute(root,current,childCtx,watcher);
swagger = "true";
}
}
childCtx.SetValue("$swagger",swagger);
super.onExecute(root, current, childCtx, watcher);
}
//迭代子节点
CatalogNode[] children = catalog.getChildren(catalogRoot);
if (children == null || children.length <= 0)
return ;
for (int i = 0 ; i < children.length ; i ++){
scanCatalog(catalog,(ServantCatalogNode)children[i],root,current,ctx,watcher);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy