Skip to content

Commit

Permalink
add currentRootPluginValidator for root plugin bind to threadLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Apr 22, 2024
1 parent a404128 commit 8861ca4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private static void notifyPluginUpdate2AssembleNode(String applyParams, String t
@Override
public Void p(int status, InputStream stream, Map<String, List<String>> headerFields) {
logger.info("has apply clean " + targetResource + " cache by " + applyParams);

return null;
}
});
Expand Down Expand Up @@ -603,10 +604,14 @@ public void run() {
}
updateCenter.persistInstallStatus();
if (!failures) {

InstallUtil.proceedToNextStateFrom(InstallState.INITIAL_PLUGINS_INSTALLING);
try {
// 为了使Assemble 节点有时间初始化
Thread.sleep(2000);
} catch (InterruptedException e) {
}
// 为了让Assemble等节点的uberClassLoader重新加载一次,需要主动向Assemble等节点发送一个指令
notifyPluginUpdate2AssembleNode(TIS.KEY_ACTION_CLEAN_TIS + "=true", "TIS");
InstallUtil.proceedToNextStateFrom(InstallState.INITIAL_PLUGINS_INSTALLING);
}
}
}.start();
Expand Down
19 changes: 12 additions & 7 deletions tis-console/src/main/java/com/qlangtech/tis/util/PluginItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
* @date 2020-02-10 12:24
*/
public class PluginItems {

private final IPluginEnum heteroEnum;
private final UploadPluginMeta pluginMeta;
private final IPluginContext pluginContext;
Expand All @@ -90,6 +89,7 @@ public void setBizResult(Context context, Object result) {
} : pluginContext;
}


/**
* 校验提交的表单
*
Expand All @@ -111,12 +111,17 @@ public PluginAction.PluginItemsParser validate(BasicModule module, Context conte

for (int itemIndex = 0; itemIndex < this.items.size(); itemIndex++) {
attrValMap = this.items.get(itemIndex);
Descriptor.PluginValidateResult.setValidateItemPos(context, pluginIndex, itemIndex);
if (!(validateResult = attrValMap.validate(module, context, verify)).isValid()) {
parseResult.faild = true;
} else {
validateResult.setDescriptor(attrValMap.descriptor);
items.add(validateResult);
try {
AttrValMap.setCurrentRootPluginValidator(attrValMap.descriptor);
Descriptor.PluginValidateResult.setValidateItemPos(context, pluginIndex, itemIndex);
if (!(validateResult = attrValMap.validate(module, context, verify)).isValid()) {
parseResult.faild = true;
} else {
validateResult.setDescriptor(attrValMap.descriptor);
items.add(validateResult);
}
} finally {
AttrValMap.removeCurrentRootPluginValidator();
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,10 @@ private List<FieldError> getFieldsError(Context context, Stack<FieldIndex> field

List<FieldError> fieldsErrorList = null;
if (subItemDetiledPk.isPresent()) {
// List<List<Map<String /**detail Id Name*/, List<FieldError>>>>
SubFromDetailedItemsErrors multiDetailed
= (SubFromDetailedItemsErrors) getFieldErrors(itemIndex, itemsErrorList, () -> new SubFromDetailedItemsErrors());

fieldsErrorList = multiDetailed.getDetailedFormError(subItemDetiledPk.get());

// fieldsErrorList = multiDetailed.get(subItemDetiledPk.get());
// if (fieldsErrorList == null) {
// fieldsErrorList = Lists.newArrayList();
// multiDetailed.put(subItemDetiledPk.get(), fieldsErrorList);
// }

} else {
// /**
// * item
// */
//
// pluginErrorList = (List<List<ItemsErrors>>) context.get(ACTION_ERROR_FIELDS);
// if (pluginErrorList == null) {
// pluginErrorList = Lists.newArrayList();
// context.put(ACTION_ERROR_FIELDS, pluginErrorList);
// }
// /**item*/
// List<List<FieldError>>
// itemsErrorList = getFieldErrors(pluginIndex, pluginErrorList, () -> Lists.newArrayList());

ListDetailedItemsErrors fieldErrors = (ListDetailedItemsErrors) getFieldErrors(itemIndex, itemsErrorList, () -> new ListDetailedItemsErrors());
fieldsErrorList = fieldErrors.fieldsErrorList;
}
Expand Down Expand Up @@ -240,26 +218,10 @@ private static class ListDetailedItemsErrors extends ItemsErrors {

@Override
public JSON serial2JSON() {
// JSONArray ferrs = new JSONArray();
// JSONObject o = null;
// for (FieldError ferr : fieldsErrorList) {
// o = new JSONObject();
// o.put("name", ferr.getFieldName());
// if ((ferr.getMsg()) != null) {
// o.put("content", ferr.getMsg());
// }
// if (ferr.itemsErrorList != null) {
// o.put(IAjaxResult.KEY_ERROR_FIELDS, this.serial2JSONArray(ferr.itemsErrorList));
// }
// ferrs.add(o);
// }
// return ferrs;
return convertItemsErrorList((fieldsErrorList));
}

private static JSONArray convertItemsErrorList(List<FieldError> fieldErrors) {
// JSONArray itemErrs = new JSONArray();
// for (FieldError fieldErrors : itemsErrorList) {
JSONArray ferrs = new JSONArray();
JSONObject o = null;
for (FieldError ferr : fieldErrors) {
Expand All @@ -278,9 +240,6 @@ private static JSONArray convertItemsErrorList(List<FieldError> fieldErrors) {
ferrs.add(o);
}
return ferrs;
// itemErrs.add(ferrs);
// }
// return itemErrs;
}
}

Expand Down Expand Up @@ -347,9 +306,6 @@ public JSONFieldErrorMsg(JSONObject content) {

@Override
public Object getContent() {
// return Objects.requireNonNull(content.get(primaryKeyName), "primaryKeyName:" +
// primaryKeyName + " " +
// "relevant property can not be null");
for (Map.Entry<String, Object> entry : content.entrySet()) {
return entry.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* @author: 百岁([email protected]
* @create: 2024-03-25 12:41
* @ses DescriptorsJSON
* @seee DescriptorsJSON
**/
public class DescriptorsJSONResult {
public static final ThreadLocal<Object> rootDescriptorLocal = new ThreadLocal<Object>();
Expand Down
16 changes: 14 additions & 2 deletions tis-plugin/src/main/java/com/qlangtech/tis/util/AttrValMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
Expand All @@ -43,9 +44,20 @@ public class AttrValMap {

public static final String PLUGIN_EXTENSION_IMPL = "impl";
public static final String PLUGIN_EXTENSION_VALS = "vals";
private static final ThreadLocal<Descriptor> currentRootPluginValidator = new ThreadLocal<>();

// private final Map<String, com.alibaba.fastjson.JSON> /*** attrName*/
// attrValMap;
public static void setCurrentRootPluginValidator(Descriptor descriptor) {
currentRootPluginValidator.set(descriptor);
}

public static Descriptor getCurrentRootPluginValidator() {
return Objects.requireNonNull(currentRootPluginValidator.get()
, "currentRootPluginValidator must be present");
}

public static void removeCurrentRootPluginValidator() {
currentRootPluginValidator.remove();
}

private final AttrVals attrValMap;

Expand Down

0 comments on commit 8861ca4

Please sign in to comment.