Browse Source

REPORT-73800【设计器环境监测】windows下没有finedb权限,设计器报错脏数据

把脏数据的逻辑修改后,导致即便只是锁住、没权限也会出现这个问题。
所以,这里添加一个检测链,前一个检测后,后一个才能继续检测。
并在对具体的类型检测时,保持原来的逻辑
release/11.0
Harrison 2 years ago
parent
commit
455d06000b
  1. 11
      designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java
  2. 33
      designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java
  3. 46
      designer-base/src/main/java/com/fr/env/detect/impl/DetectorChain.java
  4. 12
      designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java
  5. 45
      designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java

11
designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java vendored

@ -2,6 +2,7 @@ package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.impl.DetectorChain;
import com.fr.env.detect.impl.FineDbDirtyDetector;
import com.fr.env.detect.impl.FineDbLockedDetector;
import com.fr.env.detect.impl.FineDbPermissionDetector;
@ -41,10 +42,12 @@ public class DetectorBridge {
protected @NotNull DetectorManager compute() {
DetectorManager manager = new DetectorManager();
manager.register(new FineDbDirtyDetector());
manager.register(new FineDbPermissionDetector());
manager.register(new FineDbLockedDetector());
// 按照顺序构造检测链
manager.register(DetectorChain.construct(
new FineDbLockedDetector(),
new FineDbPermissionDetector(),
new FineDbDirtyDetector()));
manager.register(new JarInconsistentDetector());
manager.register(new JarLackDetector());

33
designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java vendored

@ -2,8 +2,10 @@ package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.impl.DetectorChain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@ -17,8 +19,23 @@ import java.util.stream.Stream;
**/
class DetectorManager {
/**
* 检测链的列表
*/
private List<DetectorChain> chains = new ArrayList<>();
/**
* 单纯的检测器的列表
*/
private List<ExceptionDetector> detectors = new ArrayList<>();
public void register(DetectorChain chain) {
if (chain != null) {
chains.add(chain);
}
}
public void register(ExceptionDetector detector) {
if (detector != null) {
@ -32,7 +49,13 @@ class DetectorManager {
.map(ExceptionDetector::detect)
.filter(Objects::nonNull);
List<DetectorResult> resultList = results.collect(Collectors.toList());
Stream<DetectorResult> chainResults = chains.stream()
.map(DetectorChain::detect)
.filter(Objects::nonNull);
List<DetectorResult> resultList = Stream.concat(results, chainResults)
.collect(Collectors.toList());
resultList.forEach(DetectorResult::log);
return resultList.stream();
@ -40,7 +63,13 @@ class DetectorManager {
public DetectorResult detect(DetectorType type) {
Optional<DetectorResult> result = detectors.stream()
Stream<ExceptionDetector> chainDetectors = chains.stream()
.map(DetectorChain::getDetectors)
.flatMap(Collection::stream);
Stream<ExceptionDetector> allDetectors = Stream.concat(detectors.stream(), chainDetectors);
Optional<DetectorResult> result = allDetectors
.filter((detector -> type == detector.type()))
.findFirst()
.map(ExceptionDetector::detect);

46
designer-base/src/main/java/com/fr/env/detect/impl/DetectorChain.java vendored

@ -0,0 +1,46 @@
package com.fr.env.detect.impl;
import com.fr.env.detect.base.ExceptionDetector;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorStatus;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 检测链
* 责任链模式 有先后顺序哪一个先获得哪一个先终止
*
* created by Harrison on 2022/06/16
**/
public class DetectorChain {
private List<ExceptionDetector> detectors = new ArrayList<>();
public static DetectorChain construct(ExceptionDetector... detectors) {
DetectorChain detectorChain = new DetectorChain();
detectorChain.detectors = Arrays.stream(detectors).collect(Collectors.toList());
return detectorChain;
}
@Nullable
public DetectorResult detect() {
for (ExceptionDetector detector : detectors) {
DetectorResult result = detector.detect();
if (result != null && result.getStatus() == DetectorStatus.EXCEPTION) {
return result;
}
}
return null;
}
public List<ExceptionDetector> getDetectors() {
return this.detectors;
}
}

12
designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java vendored

@ -7,6 +7,7 @@ import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.thowable.ThrowableConverter;
import com.fr.third.org.apache.commons.lang3.StringUtils;
import com.fr.third.org.hsqldb.HsqlException;
import com.fr.workspace.WorkContext;
/**
* created by Harrison on 2022/05/24
@ -36,12 +37,21 @@ public class FineDbLockedConverter implements ThrowableConverter {
*/
@Override
public DetectorResult convert(Throwable throwable) {
// 远程不执行
if (!WorkContext.getCurrent().isLocal()) {
return null;
}
Throwable sign = throwable;
while (sign.getClass() != HsqlException.class) {
while (sign != null && sign.getClass() != HsqlException.class) {
sign = sign.getCause();
}
if (sign == null) {
return null;
}
DetectorType type = DetectorType.FINE_DB_LOCKED;
String message = sign.getMessage();

45
designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java vendored

@ -5,17 +5,24 @@ import com.fr.env.detect.base.DetectorConstants;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.thowable.ThrowableConverter;
import com.fr.third.org.apache.commons.lang3.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.third.org.hsqldb.HsqlException;
import com.fr.workspace.WorkContext;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.util.Collection;
/**
* HSQL 下的权限检测
*
* <p>
* created by Harrison on 2022/05/24
**/
public class FineDbPermissionConverter implements ThrowableConverter {
public static final String PERMISSION = "permission";
public static final String EMBED_DB_NAME = "finedb";
@Override
public boolean accept(Throwable throwable) {
@ -33,15 +40,37 @@ public class FineDbPermissionConverter implements ThrowableConverter {
@Override
public DetectorResult convert(Throwable throwable) {
// 远程不执行
if (!WorkContext.getCurrent().isLocal()) {
return null;
}
Throwable sign = throwable;
while (sign.getClass() != HsqlException.class) {
while (sign != null && sign.getClass() != HsqlException.class) {
sign = sign.getCause();
}
if (sign == null) {
return null;
}
DetectorType type = DetectorType.FINE_DB_PERMISSION;
String message = sign.getMessage();
if (StringUtils.containsIgnoreCase(message, PERMISSION)) {
String fineDbDirectory = WorkContext.getCurrent().getPath() + File.separator + ProjectConstants.EMBED_DB_DIRECTORY + File.separator + EMBED_DB_NAME;
Collection<File> files = FileUtils.listFiles(new File(fineDbDirectory), null, true);
Boolean isPermitted = files.stream()
.map((file -> {
try {
// 进行权限判断
new RandomAccessFile(file, "rw");
return true;
} catch (FileNotFoundException e) {
return false;
}
}))
.reduce((a, b) -> a & b)
.orElse(Boolean.FALSE);
if (!isPermitted) {
DetectorType type = DetectorType.FINE_DB_PERMISSION;
return DetectorResult.builder()
.withType(type)
.withTips(Toolkit.i18nText(type.getTipsLocale()))

Loading…
Cancel
Save