Skip to content

Commit

Permalink
规范化file-list的格式解析和序列化
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Jul 22, 2024
1 parent fc6bbf5 commit 75b6732
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import static io.nop.core.CoreErrors.ARG_CELL_POS;
import static io.nop.core.CoreErrors.ARG_VALUE;
import static io.nop.excel.ExcelErrors.ARG_ALLOWED_NAMES;
import static io.nop.excel.ExcelErrors.ARG_ALLOWED_VALUES;
import static io.nop.excel.ExcelErrors.ARG_DISPLAY_NAME;
import static io.nop.excel.ExcelErrors.ARG_FIELD_LABEL;
Expand Down Expand Up @@ -308,7 +309,8 @@ private void validateMandatory(Map<String, ImportFieldModel> fieldMap, DynamicOb
if (field.isMandatory()) {
if (isPropEmpty(obj, field.getPropOrName()))
throw new NopException(ERR_IMPORT_MISSING_MANDATORY_FIELD).param(ARG_SHEET_NAME, sheetName)
.param(ARG_FIELD_NAME, field.getName()).param(ARG_FIELD_LABEL, field.getFieldLabel());
.param(ARG_FIELD_NAME, field.getName()).param(ARG_FIELD_LABEL, field.getFieldLabel())
.param(ARG_ALLOWED_NAMES,fieldMap.keySet());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.nop.orm.IOrmEntity;
import io.nop.orm.IOrmEntityFileStore;
import io.nop.orm.OrmConstants;
import io.nop.orm.support.OrmEntityHelper;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -32,11 +33,11 @@ public void setFilePath(String value) {
}

public List<String> getFilePaths() {
return StringHelper.split(getFilePath(), ',');
return OrmEntityHelper.parseFileList(getFilePath());
}

public void setFilePaths(List<String> filePaths) {
setFilePath(StringHelper.join(filePaths, ","));
setFilePath(OrmEntityHelper.joinFileList(filePaths));
}


Expand Down Expand Up @@ -110,8 +111,8 @@ public void onEntityFlush() {
IOrmEntityFileStore fileStore = (IOrmEntityFileStore) beanProvider.getBean(OrmConstants.BEAN_ORM_ENTITY_FILE_STORE);
String oldValue = (String) entity.orm_propOldValue(propId);

List<String> paths = StringHelper.split(getFilePath(), ',');
List<String> oldPaths = StringHelper.split(oldValue, ',');
List<String> paths = getFilePaths();
List<String> oldPaths = OrmEntityHelper.parseFileList(oldValue);
if (paths == null)
paths = new ArrayList<>();
if (oldPaths == null)
Expand Down Expand Up @@ -154,7 +155,7 @@ public void onEntityDelete(boolean logicalDelete) {
IBeanProvider beanProvider = entity.orm_enhancer().getBeanProvider();
IOrmEntityFileStore fileStore = (IOrmEntityFileStore) beanProvider.getBean(OrmConstants.BEAN_ORM_ENTITY_FILE_STORE);

List<String> paths = StringHelper.split(getFilePath(), ',');
List<String> paths = getFilePaths();
if (paths == null || paths.isEmpty())
return;

Expand Down
16 changes: 16 additions & 0 deletions nop-orm/src/main/java/io/nop/orm/support/OrmEntityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.nop.commons.type.StdDataType;
import io.nop.commons.util.MathHelper;
import io.nop.commons.util.StringHelper;
import io.nop.core.lang.json.JsonTool;
import io.nop.core.reflect.bean.BeanTool;
import io.nop.orm.IOrmCompositePk;
import io.nop.orm.IOrmEntity;
Expand Down Expand Up @@ -49,6 +50,21 @@ public static boolean isFileListComponent(IEntityComponentModel comp) {
return comp.getClassName().equals(OrmFileListComponent.class.getName());
}

@SuppressWarnings("unchecked")
public static List<String> parseFileList(String filePath) {
if (StringHelper.isEmpty(filePath))
return null;
if (filePath.startsWith("[") && filePath.endsWith("]"))
return (List<String>) JsonTool.parseNonStrict(filePath);
return StringHelper.stripedSplit(filePath, ',');
}

public static String joinFileList(List<String> filePaths) {
if (filePaths == null || filePaths.isEmpty())
return null;
return StringHelper.join(filePaths, ",");
}

public static void copyRefProps(IOrmEntity entity, IEntityRelationModel rel, IOrmEntity relatedEntity) {
for (IEntityJoinConditionModel cond : rel.getJoin()) {
IEntityPropModel leftCol = cond.getLeftPropModel();
Expand Down

0 comments on commit 75b6732

Please sign in to comment.