Skip to content

Commit

Permalink
修正决策树的解析与保存
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Sep 4, 2023
1 parent f320e24 commit f1f9d3a
Show file tree
Hide file tree
Showing 36 changed files with 835 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4635,6 +4635,12 @@
"java.lang.String"
]
},
{
"name": "isTextResource",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "isValidModuleId",
"parameterTypes": [
Expand All @@ -4659,6 +4665,10 @@
"io.nop.core.resource.IResource"
]
},
{
"name": "newDynamicPath",
"parameterTypes": []
},
{
"name": "normalizePath",
"parameterTypes": [
Expand Down
6 changes: 3 additions & 3 deletions nop-cli-core/src/main/resources/nop-vfs-index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@
/nop/templates/antlr/src/main/java/{parser.packagePath}/{parser.name}ParseTreeParser.java.xgen
/nop/templates/api-web/@init.xrun
/nop/templates/api-web/src/main/resources/_vfs/{moduleId}/auth/_{apiModelName}-api.action-auth.xml.xgen
/nop/templates/api-web/src/main/resources/_vfs/{moduleId}/pages/{serviceModel}/_{serviceModel.name}.view.xml.xgen
/nop/templates/api-web/src/main/resources/_vfs/{moduleId}/pages/{serviceModel}/main.page.yaml.xgen
/nop/templates/api-web/src/main/resources/_vfs/{moduleId}/pages/{serviceModel}/{serviceModel.name}.view.xml.xgen
/nop/templates/api-web/src/main/resources/_vfs/{moduleId}/pages/{serviceModel.name}/_{serviceModel.name}.view.xml.xgen
/nop/templates/api-web/src/main/resources/_vfs/{moduleId}/pages/{serviceModel.name}/main.page.yaml.xgen
/nop/templates/api-web/src/main/resources/_vfs/{moduleId}/pages/{serviceModel.name}/{serviceModel.name}.view.xml.xgen
/nop/templates/api/@init.xrun
/nop/templates/api/{apiModuleName}/src/main/java/{apiPackagePath}/beans/_gen/_{messageModel.name}.java.xgen
/nop/templates/api/{apiModuleName}/src/main/java/{apiPackagePath}/beans/{messageModel.name}.java.xgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
30 changes: 30 additions & 0 deletions nop-commons/src/main/java/io/nop/commons/util/StringHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4073,6 +4073,36 @@ public static String wrapExpr(@Name("expr") String expr) {
return "${" + expr + "}";
}

@Deterministic
public static String simplifyStdJavaType(String typeName) {
if (typeName == null)
return null;

StdDataType dataType = StdDataType.fromJavaClassName(typeName);
if (dataType != null) {
// 原始数据类型保持不变,例如int 与Integer都会返回StdDataType.INT
if (typeName.indexOf('.') < 0 && Character.isLowerCase(typeName.charAt(0)))
return typeName;

// 简单数据类型去除包名
if (dataType.ordinal() <= StdDataType.DURATION.ordinal())
return dataType.getSimpleClassName();
}

if (dataType == StdDataType.MAP)
return "Map";

if (dataType == StdDataType.LIST)
return "List";

if (typeName.startsWith("java.util.Map<"))
return typeName.substring("java.util.".length());

if (typeName.startsWith("java.util.List<"))
return typeName.substring("java.util.List<".length());
return typeName;
}

@Deterministic
public static String simplifyJavaType(String className) {
if (className == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public interface ResourceConstants {
//
String SUPER_NS = "super";

/**
* 仅用于标识在内存中直接创建的模型对象
*/
String DYNAMIC_NS = "dynamic";

String DYNAMIC_NS_PREFIX = "dynamic:";

String PLACEHOLDER_PROJECT_PATH = "{PROJECT_PATH}";

/**
Expand All @@ -65,9 +72,11 @@ public interface ResourceConstants {
String FILE_POSTFIX_YAML = ".yaml";
String FILE_POSTFIX_YML = ".yml";

List<String> JSON_FILE_EXTS = CollectionHelper.buildImmutableList("json","json5","yaml","yml");
List<String> JSON_FILE_EXTS = CollectionHelper.buildImmutableList("json", "json5", "yaml", "yml");

String FILE_POSTFIX_XML = ".xml";

String FILE_POSTFIX_BAK = ".bak";

String RESOURCE_PATH_TEXT = "text";
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.nop.core.lang.xml.XNode;
import io.nop.core.lang.xml.parse.XNodeParser;
import io.nop.core.resource.impl.ClassPathResource;
import io.nop.core.resource.impl.DynamicResource;
import io.nop.core.resource.impl.FileResource;
import io.nop.core.resource.impl.InMemoryTextResource;
import io.nop.core.resource.impl.URLResource;
Expand Down Expand Up @@ -272,6 +273,14 @@ public static boolean isTenantPath(String path) {
return path.startsWith(ResourceConstants.TENANT_PATH_PREFIX);
}

public static String newDynamicPath() {
return DynamicResource.newDynamicPath();
}

public static boolean isTextResource(String path) {
return ResourceConstants.RESOURCE_PATH_TEXT.equals(path);
}

/**
* 在父目录中的子路径名。如果是文件,则与getName()相同。如果是目录,则返回getName()+'/'
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ private IResourceReference resolveResource(String resourcePath) {

@Override
public <T> T collectDepends(String resourcePath, Supplier<T> task) {
if (dependsManager.currentDepends() == null || StringHelper.isEmpty(resourcePath))
if (dependsManager.currentDepends() == null || StringHelper.isEmpty(resourcePath)
|| ResourceConstants.RESOURCE_PATH_TEXT.equals(resourcePath))
return task.get();

IResourceReference resource = resolveResource(resourcePath);
Expand Down
106 changes: 106 additions & 0 deletions nop-core/src/main/java/io/nop/core/resource/impl/DynamicResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Copyright (c) 2017-2023 Nop Platform. All rights reserved.
* Author: [email protected]
* Blog: https://www.zhihu.com/people/canonical-entropy
* Gitee: https://gitee.com/canonical-entropy/nop-chaos
* Github: https://github.com/entropy-cloud/nop-chaos
*/
package io.nop.core.resource.impl;

import io.nop.api.core.exceptions.NopException;
import io.nop.api.core.util.Guard;
import io.nop.core.resource.IFile;
import io.nop.core.resource.IResource;
import io.nop.core.resource.ResourceConstants;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import static io.nop.core.CoreErrors.ARG_RESOURCE_PATH;
import static io.nop.core.CoreErrors.ERR_RESOURCE_UNKNOWN_RESOURCE_NOT_ALLOW_OPERATION;

/**
* IResourceStore解析resourcePath失败时,将会返回UnknownResource
*
* @author [email protected]
*/
public class DynamicResource extends AbstractResource implements IFile {

private static final long serialVersionUID = 3061171246553624932L;

private final static AtomicLong s_seq = new AtomicLong();

public DynamicResource(String path) {
super(path);
Guard.checkArgument(path.startsWith(ResourceConstants.DYNAMIC_NS_PREFIX));
}

public static String newDynamicPath() {
return ResourceConstants.DYNAMIC_NS_PREFIX + s_seq.incrementAndGet();
}

@Override
public boolean exists() {
return true;
}

@Override
protected Object internalObj() {
return getPath();
}

NopException error() {
return new NopException(ERR_RESOURCE_UNKNOWN_RESOURCE_NOT_ALLOW_OPERATION).param(ARG_RESOURCE_PATH, getPath());
}

@Override
public InputStream getInputStream() {
throw error();
}

@Override
public boolean isReadOnly() {
return true;
}

@Override
public OutputStream getOutputStream(boolean append) {
throw error();
}

@Override
public boolean mkdirs() {
return false;
}

@Override
public boolean createNewFile() {
return false;
}

@Override
public IFile createTempFile(String prefix, String postfix) {
throw error();
}

@Override
public boolean renameTo(IResource resource) {
return false;
}

@Override
public IFile getResource(String relativeName) {
return new DynamicResource(getPath() + relativeName);
}

@Override
public List<IFile> getChildren() {
return null;
}

@Override
public void deleteOnExit() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public DefaultVirtualFileSystem() {
registerNamespaceHandler(FileNamespaceHandler.INSTANCE);
registerNamespaceHandler(ClassPathNamespaceHandler.INSTANCE);
registerNamespaceHandler(ModuleNamespaceHandler.INSTANCE);
registerNamespaceHandler(DynamicNamespaceHandler.INSTANCE);

DeltaResourceStoreBuilder builder = new DeltaResourceStoreBuilder();
this.deltaResourceStore = builder.build(config);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2017-2023 Nop Platform. All rights reserved.
* Author: [email protected]
* Blog: https://www.zhihu.com/people/canonical-entropy
* Gitee: https://gitee.com/canonical-entropy/nop-chaos
* Github: https://github.com/entropy-cloud/nop-chaos
*/
package io.nop.core.resource.store;

import io.nop.core.resource.IResource;
import io.nop.core.resource.IResourceNamespaceHandler;
import io.nop.core.resource.IResourceStore;
import io.nop.core.resource.ResourceConstants;
import io.nop.core.resource.impl.DynamicResource;

public class DynamicNamespaceHandler implements IResourceNamespaceHandler {
public static final DynamicNamespaceHandler INSTANCE = new DynamicNamespaceHandler();

@Override
public String getNamespace() {
return ResourceConstants.DYNAMIC_NS;
}

@Override
public IResource getResource(String vPath, IResourceStore locator) {
return new DynamicResource(vPath);
}
}
Loading

0 comments on commit f1f9d3a

Please sign in to comment.