Skip to content

Commit

Permalink
修正transformIn被重复调用的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Jul 31, 2024
1 parent b3f9232 commit fbdf2cd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.nop.auth.service;

import io.nop.api.core.annotations.autotest.NopTestConfig;
import io.nop.api.core.beans.ApiRequest;
import io.nop.autotest.junit.JunitBaseTestCase;
import io.nop.graphql.core.IGraphQLExecutionContext;
import io.nop.graphql.core.engine.IGraphQLEngine;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

@NopTestConfig(localDb = true, initDatabaseSchema = true)
public class TestTransformIn extends JunitBaseTestCase {

@Inject
IGraphQLEngine graphQLEngine;

@Test
public void testTransformIn() {
ApiRequest<Map<String, Object>> req = new ApiRequest<>();
Map<String, Object> data = new HashMap<>();
data.put("name", "a");
data.put("remark", "B");

Map<String, Object> m = new HashMap<>();
m.put("data", data);
req.setData(m);

IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null,
"NopAuthPosition__save", req);

Map<String, Object> map = (Map<String, Object>) graphQLEngine.executeRpc(gqlCtx).get();
assertEquals("BEXT", map.get("remark"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<meta x:schema="/nop/schema/xmeta.xdef" xmlns:x="/nop/schema/xdsl.xdef" x:extends="super">
<props>
<prop name="remark">
<transformIn>
return value + 'EXT'
</transformIn>
</prop>
</props>
</meta>
16 changes: 8 additions & 8 deletions nop-biz/src/main/java/io/nop/biz/crud/ObjMetaBasedValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ private boolean isRefPrimary(IBizObject bizObject, String propName) {

private Object convertValue(IObjPropMeta propMeta, Object value, Map<String, Object> data,
Map<String, Object> ret) {
IEvalAction action = propMeta.getTransformIn();
if (action != null) {
IEvalScope scope = XLang.newEvalScope();
scope.setLocalValue(null, BizConstants.VAR_DATA, data);
scope.setLocalValue(null, BizConstants.VAR_TRNAS_DATA, ret);
scope.setLocalValue(null, BizConstants.VAR_VALUE, value);
value = action.invoke(scope);
}
// IEvalAction action = propMeta.getTransformIn();
// if (action != null) {
// IEvalScope scope = XLang.newEvalScope();
// scope.setLocalValue(null, BizConstants.VAR_DATA, data);
// scope.setLocalValue(null, BizConstants.VAR_TRNAS_DATA, ret);
// scope.setLocalValue(null, BizConstants.VAR_VALUE, value);
// value = action.invoke(scope);
// }

StdDataType type = propMeta.getStdDataType();
if (type == null)
Expand Down

0 comments on commit fbdf2cd

Please sign in to comment.