Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Jan 12, 2025
2 parents 547b6a5 + a5ba7a6 commit 2b393e3
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 16 deletions.
4 changes: 4 additions & 0 deletions nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public IDaoProvider daoProvider() {
return daoProvider;
}

public IBizObjectManager bizObjectManager() {
return bizObjectManager;
}

@Inject
public void setDaoProvider(IDaoProvider daoProvider) {
this.daoProvider = daoProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ public static <K, V> Map<K, V> toNonEmptyKeyMap(Collection<? extends K> keyList,

while (kIt.hasNext() && vIt.hasNext()) {
K key = kIt.next();
V value = vIt.next();
if (StringHelper.isEmptyObject(key))
continue;
V value = vIt.next();
ret.put(key, value);
}
return ret;
Expand Down Expand Up @@ -1071,4 +1071,4 @@ public static <T> List<T> prepend(List<T> list, T item) {
list.add(0, item);
return list;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import java.util.function.BiFunction;

public class HeaderListRecordOutput<R> implements IRecordOutput<List<Object>> {
private List<String> headers;

private final List<R> records = new ArrayList<>();
private final BiFunction<List<String>, List<Object>, R> rowBuilder;
private boolean headersWritten;
private long writeCount;
private int headerRowCount;
private List<String> headers;
private List<String> headerLabels;
private IEvalFunction headersNormalizer;

Expand All @@ -34,6 +35,10 @@ public HeaderListRecordOutput(int headerRowCount, BiFunction<List<String>, List<
this.rowBuilder = rowBuilder;
}

public void setHeaders(List<String> headers) {
this.headers = headers;
}

public void setHeaderLabels(List<String> headerLabels) {
this.headerLabels = headerLabels;
}
Expand Down Expand Up @@ -98,4 +103,4 @@ public void flush() {
@Override
public void close() {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public void initRpcContext(IGraphQLExecutionContext context, GraphQLOperationTyp
field.setFieldDefinition(action);
}

private GraphQLFieldSelection initForReturnType(IGraphQLExecutionContext context,
public GraphQLFieldSelection initForReturnType(IGraphQLExecutionContext context,
GraphQLOperationType operationType, String operationName, Object request,
GraphQLType returnType, FieldSelectionBean selectionBean) {
GraphQLDocument doc = new GraphQLDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private CompletionStage<Void> _invokeOperations(DataFetchingEnvironment baseEnv,
return FutureHelper.waitAll(promises);
}

private Object fetchSelections(Object source, GraphQLSelectionSet selectionSet, DataFetchingEnvironment env) {
protected Object fetchSelections(Object source, GraphQLSelectionSet selectionSet, DataFetchingEnvironment env) {
Map<String, Object> ret = new LinkedHashMap<>();

List<CompletionStage<?>> promises = _fetchSelections(null, ret, source, selectionSet, env);
Expand Down Expand Up @@ -399,7 +399,7 @@ Object hookFetch(IDataFetcher fetcher, DataFetchingEnvironment env) {
// return env;
// }

private Object fetchNext(Object value, DataFetchingEnvironment env) {
protected Object fetchNext(Object value, DataFetchingEnvironment env) {
if (isEmpty(value))
return value;

Expand All @@ -423,7 +423,7 @@ private boolean isEmpty(Object value) {
return false;
}

private Object fetchList(Collection<?> c, GraphQLSelectionSet selectionSet, DataFetchingEnvironment env) {
protected Object fetchList(Collection<?> c, GraphQLSelectionSet selectionSet, DataFetchingEnvironment env) {
List<Object> list = new ArrayList<>(c.size());
List<CompletionStage<?>> promises = null;

Expand Down
10 changes: 10 additions & 0 deletions nop-orm/src/main/java/io/nop/orm/OrmConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,14 @@ public interface OrmConstants {
String PROP_FILE_STATUS_LIST = "fileStatusList";

String EXT_AUTO_UPGRADE_DATABASE = "ext:auto-upgrade-database";

String PRE_SAVE = "pre-save";
String PRE_UPDATE = "pre-update";
String PRE_DELETE = "pre-delete";
String PRE_RESET = "pre-reset";
String POST_SAVE = "post-save";
String POST_UPDATE = "post-update";
String POST_DELETE = "post-delete";
String POST_LOAD = "post-load";

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ public class XplOrmInterceptor implements IOrmInterceptor {
private List<IEvalAction> postFlushActions;

public void setActions(String event, Map<String, List<IEvalAction>> actions) {
if ("pre-save".equals(event)) {
if (OrmConstants.PRE_SAVE.equals(event)) {
setPreSaveActions(actions);
} else if ("pre-update".equals(event)) {
} else if (OrmConstants.PRE_UPDATE.equals(event)) {
setPreUpdateActions(actions);
} else if ("pre-delete".equals(event)) {
} else if (OrmConstants.PRE_DELETE.equals(event)) {
setPreDeleteActions(actions);
} else if ("pre-reset".equals(event)) {
} else if (OrmConstants.PRE_RESET.equals(event)) {
setPreResetActions(actions);
} else if ("post-save".equals(event)) {
} else if (OrmConstants.POST_SAVE.equals(event)) {
setPostSaveActions(actions);
} else if ("post-update".equals(event)) {
} else if (OrmConstants.POST_UPDATE.equals(event)) {
setPostUpdateActions(actions);
} else if ("post-delete".equals(event)) {
} else if (OrmConstants.POST_DELETE.equals(event)) {
setPostDeleteActions(actions);
} else if ("post-load".equals(event)) {
} else if (OrmConstants.POST_LOAD.equals(event)) {
setPostLoadActions(actions);
} else {
throw new IllegalArgumentException("nop.err.orm.unsupported-event:" + event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void close() throws IOException {
@Override
public void beforeRead(Map<String, Object> map) {
HeaderListRecordOutput<Map<String, Object>> collector = new HeaderListRecordOutput<>(config.getHeaderRowCount(), CollectionHelper::toNonEmptyKeyMap);
collector.setHeaders(headers);
collector.setHeaderLabels(headerLabels);
collector.setHeadersNormalizer(headersNormalizer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;

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

public class TestExcelResourceIO extends BaseTestCase {

Expand All @@ -44,6 +45,50 @@ public void testRead() throws IOException {
input.close();
}

@Test
public void testReadSpecifiedHeader() throws IOException {
ExcelResourceIO<Map<String, Object>> io = new ExcelResourceIO<>();
ExcelIOConfig config = new ExcelIOConfig();
io.setIOConfig(config);
// 指定 headers
io.setHeaders(Arrays.asList("a","b","c"));

IRecordInput<Map<String, Object>> input = io.openInput(new ClassPathResource("classpath:io/nop/report/core/excel-input.xlsx"), null);
input.beforeRead(new HashMap<>());

List<Map<String, Object>> list = input.readAll();
System.out.println(JSON.serialize(list, true));
assertEquals(1, list.get(0).get("a"));
assertEquals(1, list.get(0).get("b"));
assertEquals(1, list.get(0).get("c"));
assertEquals(10, list.get(9).get("a"));
assertEquals(901, list.get(9).get("b"));
assertEquals(9001, list.get(9).get("c"));
input.close();
}

@Test
public void testReadHeaderWithNull() throws IOException {
ExcelResourceIO<Map<String, Object>> io = new ExcelResourceIO<>();
ExcelIOConfig config = new ExcelIOConfig();
// header 为空的列,就不会处理
io.setHeaders(Arrays.asList("a",null/*b*/,"c",null/*d*/,null/*e*/,"f"));
io.setIOConfig(config);

IRecordInput<Map<String, Object>> input = io.openInput(new ClassPathResource("classpath:io/nop/report/core/excel-input.xlsx"), null);
input.beforeRead(new HashMap<>());

List<Map<String, Object>> list = input.readAll();
System.out.println(JSON.serialize(list, true));
assertEquals(1, list.get(0).get("a"));
assertNull(list.get(0).get("b"));
assertEquals(1, list.get(0).get("c"));
assertNull(list.get(0).get("d"));
assertNull(list.get(0).get("e"));
assertEquals(11, list.get(0).get("f"));
input.close();
}

@Test
public void testReadMultiHeader() throws IOException {
ExcelResourceIO<Map<String, Object>> io = new ExcelResourceIO<>();
Expand Down
Binary file not shown.

0 comments on commit 2b393e3

Please sign in to comment.