use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.
the class AllApisNavToolWindow method refreshFilterModule.
public void refreshFilterModule(List<String> selectModule, List<String> selectMethodType) {
DumbService.getInstance(myProject).smartInvokeLater(() -> {
Task.Backgroundable task = new Task.Backgroundable(myProject, "Reload apis...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(false);
ApplicationManager.getApplication().runReadAction(() -> {
if (allApiList == null) {
return;
}
List<ApiService> filterList = allApiList.stream().filter(q -> selectModule.contains(q.getModuleName())).collect(Collectors.toList());
indicator.setText("Rendering");
List<ApiService.ApiMethod> filterMethodList = new ArrayList<>();
filterList.stream().map(ApiService::getApiMethodList).filter(CollectionUtil::isNotEmpty).forEach(filterMethodList::addAll);
long count = filterMethodList.stream().filter(q -> selectMethodType.contains(q.getMethodType())).count();
RootNode root = new RootNode(count + " apis") {
};
NodeUtil.convertToRoot(root, NodeUtil.convertToMap(filterList.stream().filter(q -> CollectionUtil.isNotEmpty(q.getApiMethodList())).filter(q -> q.getApiMethodList().stream().anyMatch(p -> selectMethodType.contains(p.getMethodType()))).collect(Collectors.toList())), selectMethodType);
apiTree.setModel(new DefaultTreeModel(root));
});
}
};
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
});
}
use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.
the class NodeUtil method getAllApiList.
public static List<ApiService> getAllApiList(Collection<PsiClass> controller) {
SpringMethodUrlGenerator springMethodUrlGenerator = ApplicationManager.getApplication().getService(SpringMethodUrlGenerator.class);
JaxRsGenerator jaxRsGenerator = ApplicationManager.getApplication().getService(JaxRsGenerator.class);
List<ApiService> apiServiceList = new ArrayList<>();
for (PsiClass psiClass : controller) {
Module module = ModuleUtil.findModuleForPsiElement(psiClass);
if (module == null) {
continue;
}
String moduleName = module.getName();
String className = psiClass.getName();
PsiMethod[] methods = psiClass.getMethods();
List<ApiService.ApiMethod> apiMethodList = new ArrayList<>();
for (PsiMethod method : methods) {
Constant.FrameworkType frameworkType = FrPsiUtil.calcFrameworkType(method);
if (frameworkType.equals(Constant.FrameworkType.SPRING)) {
for (Constant.SpringMappingConfig value : Constant.SpringMappingConfig.values()) {
if (method.getAnnotation(value.getCode()) != null) {
String methodDescription = springMethodUrlGenerator.getMethodDescription(method);
String name = method.getName();
String methodUrl = springMethodUrlGenerator.getMethodRequestMappingUrl(method);
String classUrl = springMethodUrlGenerator.getClassRequestMappingUrl(method);
String originUrl = classUrl + "/" + methodUrl;
originUrl = (originUrl.startsWith("/") ? "" : "/") + originUrl.replace("//", "/");
String methodType = springMethodUrlGenerator.getMethodType(method);
ApiService.ApiMethod apiMethod = new ApiService.ApiMethod(method, originUrl, methodDescription, name, methodType);
apiMethodList.add(apiMethod);
break;
}
}
} else {
for (Constant.JaxRsMappingConfig value : Constant.JaxRsMappingConfig.values()) {
if (method.getAnnotation(value.getCode()) != null) {
String methodDescription = jaxRsGenerator.getMethodDescription(method);
String name = method.getName();
String methodUrl = jaxRsGenerator.getMethodRequestMappingUrl(method);
String classUrl = jaxRsGenerator.getClassRequestMappingUrl(method);
String originUrl = classUrl + "/" + methodUrl;
originUrl = (originUrl.startsWith("/") ? "" : "/") + originUrl.replace("//", "/");
String methodType = jaxRsGenerator.getMethodType(method);
ApiService.ApiMethod apiMethod = new ApiService.ApiMethod(method, originUrl, methodDescription, name, methodType);
apiMethodList.add(apiMethod);
break;
}
}
}
}
String packageName = getPackageName(psiClass);
if (packageName == null) {
packageName = "";
}
ApiService apiService = new ApiService(moduleName, packageName, className, apiMethodList);
apiServiceList.add(apiService);
}
return apiServiceList;
}
use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.
the class NodeUtil method convertToRoot.
public static void convertToRoot(DefaultMutableTreeNode root, LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, List<ApiService>>>> dataMap, List<String> selectMethodType) {
List<ModuleNode> moduleNodeList = new ArrayList<>();
for (Map.Entry<String, LinkedHashMap<String, LinkedHashMap<String, List<ApiService>>>> moduleEntry : dataMap.entrySet()) {
String moduleName = moduleEntry.getKey();
ModuleNode moduleNode = new ModuleNode(moduleName);
LinkedHashMap<String, LinkedHashMap<String, List<ApiService>>> packageMap = moduleEntry.getValue();
Map<String, PackageNode> packageNodeMap = new LinkedHashMap<>();
for (Map.Entry<String, LinkedHashMap<String, List<ApiService>>> packageEntry : packageMap.entrySet()) {
String packageName = packageEntry.getKey();
LinkedHashMap<String, List<ApiService>> classMap = packageEntry.getValue();
for (Map.Entry<String, List<ApiService>> classEntry : classMap.entrySet()) {
String className = classEntry.getKey();
ClassNode classNode = new ClassNode(className);
for (ApiService apiService : classEntry.getValue()) {
List<ApiService.ApiMethod> apiMethodList = apiService.getApiMethodList();
List<ApiService.ApiMethod> filterMethodList = apiMethodList.stream().filter(q -> selectMethodType.contains(q.getMethodType())).collect(Collectors.toList());
filterMethodList.forEach(apiMethod -> classNode.add(new MethodNode(apiMethod)));
}
customPending(packageNodeMap, packageName).add(classNode);
}
}
List<PackageNode> nodes = new ArrayList<>();
packageNodeMap.forEach((key, rootNode) -> {
if ("".equals(key)) {
return;
}
while (true) {
List<PackageNode> list = findChildren(rootNode);
if (list.size() == 1) {
PackageNode newEle = list.get(0);
rootNode.remove(newEle);
String value = rootNode.getSource() + "." + newEle.getSource();
newEle.setSource(value);
newEle.setUserObject(value);
rootNode = newEle;
} else {
break;
}
}
sortChildNode(rootNode);
nodes.add(rootNode);
});
nodes.forEach(moduleNode::add);
PackageNode noPackageNode = packageNodeMap.get("");
if (noPackageNode != null) {
ArrayList<ClassNode> nodeList = (ArrayList<ClassNode>) IteratorUtils.toList(noPackageNode.children().asIterator());
nodeList.sort(Comparator.comparing(ClassNode::toString));
nodeList.forEach(moduleNode::add);
}
moduleNodeList.add(moduleNode);
}
moduleNodeList.sort(Comparator.comparing(ModuleNode::toString));
moduleNodeList.forEach(root::add);
}
use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.
the class AllApisNavToolWindow method rendingTree.
private void rendingTree(List<String> moduleNameList) {
Task.Backgroundable task = new Task.Backgroundable(myProject, "Reload apis...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(false);
ApplicationManager.getApplication().runReadAction(() -> {
Query<PsiClass> query = AllClassesSearch.search(ProjectScope.getContentScope(myProject), myProject);
Collection<PsiClass> controller = query.filtering(cls -> cls.getAnnotation("org.springframework.web.bind.annotation.RestController") != null || cls.getAnnotation("org.springframework.stereotype.Controller") != null || cls.getAnnotation("org.springframework.web.bind.annotation.RequestMapping") != null || cls.getAnnotation("javax.ws.rs.Path") != null).filtering(cls -> {
if (moduleNameList == null) {
return true;
}
Module module = ModuleUtil.findModuleForFile(cls.getContainingFile());
if (module == null) {
return false;
}
return moduleNameList.contains(module.getName());
}).allowParallelProcessing().findAll();
allApiList = NodeUtil.getAllApiList(controller);
indicator.setText("Rendering");
List<String> selectMethodType = methodTypeFilter.getSelectedElementList();
List<ApiService.ApiMethod> filterMethodList = new ArrayList<>();
allApiList.stream().map(ApiService::getApiMethodList).forEach(filterMethodList::addAll);
long count = filterMethodList.stream().filter(q -> selectMethodType.contains(q.getMethodType())).count();
RootNode root = new RootNode(count + " apis");
NodeUtil.convertToRoot(root, NodeUtil.convertToMap(allApiList.stream().filter(q -> CollectionUtil.isNotEmpty(q.getApiMethodList())).collect(Collectors.toList())), methodTypeFilter.getSelectedElementList());
apiTree.setModel(new DefaultTreeModel(root));
NotificationGroupManager.getInstance().getNotificationGroup("toolWindowNotificationGroup").createNotification("Reload apis complete", MessageType.INFO).notify(myProject);
});
}
};
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
}
Aggregations