|
|
|
@ -99,10 +99,13 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ
|
|
|
|
List<DataObject> divided = divideFiles(fileList);
|
|
|
|
List<DataObject> divided = divideFiles(fileList);
|
|
|
|
resp.set("divided", divided.size());
|
|
|
|
resp.set("divided", divided.size());
|
|
|
|
|
|
|
|
|
|
|
|
List<DataObject> errors = divided.stream().filter(info -> info.get("metaInfo") == null).toList();
|
|
|
|
List<DataObject> errors = divided.stream()
|
|
|
|
|
|
|
|
.filter(info -> info.get("metaInfo") == null)
|
|
|
|
|
|
|
|
.distinct()
|
|
|
|
|
|
|
|
.toList();
|
|
|
|
divided.removeAll(errors); // 오류 항목 제외
|
|
|
|
divided.removeAll(errors); // 오류 항목 제외
|
|
|
|
resp.set("normal", divided.size())
|
|
|
|
resp.set("normal", divided.size())
|
|
|
|
.set("malformed", errors.size());
|
|
|
|
.set("malformed", errors.size());
|
|
|
|
log().debug("Before creating Crdns: {}", resp);
|
|
|
|
log().debug("Before creating Crdns: {}", resp);
|
|
|
|
|
|
|
|
|
|
|
|
Map<Crdn, DataObject> crdnMap = divided.stream()
|
|
|
|
Map<Crdn, DataObject> crdnMap = divided.stream()
|
|
|
|
@ -185,14 +188,18 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ
|
|
|
|
//3.등록
|
|
|
|
//3.등록
|
|
|
|
List<DataProc> dataProcs = crdnBean.create(crdns, excludeExempted);
|
|
|
|
List<DataProc> dataProcs = crdnBean.create(crdns, excludeExempted);
|
|
|
|
LinkedHashMap<String, List<File>> fileMap = new LinkedHashMap<>();
|
|
|
|
LinkedHashMap<String, List<File>> fileMap = new LinkedHashMap<>();
|
|
|
|
String[] strs = {"success", "duplicate"};
|
|
|
|
String[] strs = {"success", "duplicates"};
|
|
|
|
for (DataProc dataProc: dataProcs) {
|
|
|
|
for (DataProc dataProc: dataProcs) {
|
|
|
|
Crdn crdn = dataProc.getTarget();
|
|
|
|
Crdn crdn = dataProc.getTarget();
|
|
|
|
|
|
|
|
crdn.clearAttachments();
|
|
|
|
DataObject info = crdnMap.get(crdn);
|
|
|
|
DataObject info = crdnMap.get(crdn);
|
|
|
|
List<DataObject> files = (List<DataObject>)info.get("files");
|
|
|
|
List<DataObject> files = (List<DataObject>)info.get("files");
|
|
|
|
if (isEmpty(files)) continue;
|
|
|
|
if (isEmpty(files)) continue;
|
|
|
|
|
|
|
|
|
|
|
|
List<File> extracted = files.stream().map(file -> (File)file.get("file")).toList();
|
|
|
|
List<File> extracted = files.stream()
|
|
|
|
|
|
|
|
.map(file -> (File)file.get("file"))
|
|
|
|
|
|
|
|
.distinct()
|
|
|
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
|
|
for (String str: strs) {
|
|
|
|
for (String str: strs) {
|
|
|
|
List<File> list = fileMap.get(str);
|
|
|
|
List<File> list = fileMap.get(str);
|
|
|
|
@ -200,33 +207,47 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ
|
|
|
|
fileMap.put(str, list = new ArrayList<>());
|
|
|
|
fileMap.put(str, list = new ArrayList<>());
|
|
|
|
if ("success".equals(str) && dataProc.isSuccess())
|
|
|
|
if ("success".equals(str) && dataProc.isSuccess())
|
|
|
|
list.addAll(extracted);
|
|
|
|
list.addAll(extracted);
|
|
|
|
if ("duplicates".equals(str) && "duplicate".equals(dataProc.getInfo("reason")))
|
|
|
|
else if ("duplicates".equals(str) && "duplicate".equals(dataProc.getInfo("reason"))) {
|
|
|
|
list.addAll(extracted);
|
|
|
|
list.addAll(extracted);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fileMap.put("fail", errors.stream().flatMap(info -> {
|
|
|
|
fileMap.put("fail", errors.stream().flatMap(info -> {
|
|
|
|
List<DataObject> tmp = ((List<DataObject>)info.get("files"));
|
|
|
|
List<DataObject> tmp = (List<DataObject>)info.get("files");
|
|
|
|
return tmp.stream().map(file -> (File)file.get("file"));
|
|
|
|
return tmp.stream().map(file -> (File)file.get("file"));
|
|
|
|
}).toList());
|
|
|
|
}).toList());
|
|
|
|
resp.set("success", dataProcs.stream().filter(DataProc::isSuccess).count())
|
|
|
|
resp.set("success", dataProcs.stream().filter(DataProc::isSuccess).count())
|
|
|
|
.set("duplicates", dataProcs.stream().filter(dp -> "duplicate".equals(dp.getInfo("reason"))).count());
|
|
|
|
.set("duplicates", dataProcs.stream().filter(dp -> "duplicate".equals(dp.getInfo("reason"))).count());
|
|
|
|
|
|
|
|
|
|
|
|
if (!isEmpty(workPath))
|
|
|
|
if (!cctv)
|
|
|
|
fileList.forEach(delInfo -> crdnBean.removeEquipmentLinkFile(workPath, delInfo.string("FILE_NAME")));
|
|
|
|
for (DataObject delInfo: fileList) {
|
|
|
|
|
|
|
|
crdnBean.removeEquipmentLinkFile(workPath, delInfo.string("FILE_NAME"));
|
|
|
|
String dir = null;
|
|
|
|
}
|
|
|
|
for (Map.Entry<String, List<File>> entry: fileMap.entrySet()) {
|
|
|
|
else {
|
|
|
|
String key = entry.getKey();
|
|
|
|
String dir = null;
|
|
|
|
List<File> files = entry.getValue();
|
|
|
|
for (Map.Entry<String, List<File>> entry: fileMap.entrySet()) {
|
|
|
|
for (File file: files) {
|
|
|
|
String key = entry.getKey();
|
|
|
|
String srcDir = file.getParentFile().getAbsolutePath(),
|
|
|
|
List<File> files = entry.getValue();
|
|
|
|
destDir = srcDir.replace(File.separator + "work", File.separator + key);
|
|
|
|
for (File file: files) {
|
|
|
|
if (!equals(dir, destDir))
|
|
|
|
String srcDir = file.getParent(),
|
|
|
|
ensureDir(dir = destDir);
|
|
|
|
destDir = srcDir.replace(File.separator + "work", File.separator + key);
|
|
|
|
|
|
|
|
if (!equals(dir, destDir))
|
|
|
|
file.renameTo(new File(destDir + File.separator + file.getName()));
|
|
|
|
ensureDir(dir = destDir);
|
|
|
|
|
|
|
|
String destPath = destDir + File.separator + file.getName();
|
|
|
|
|
|
|
|
boolean moved = file.renameTo(new File(destPath));
|
|
|
|
|
|
|
|
if (!moved)
|
|
|
|
|
|
|
|
log().debug("Failed to move {} -> {}", file.getPath(), destPath);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Files.move(file.toPath(), Paths.get(destDir, file.getName()));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log().debug("process result: {}", resp);
|
|
|
|
return resp;
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -285,6 +306,7 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
.distinct()
|
|
|
|
.collect(Collectors.toCollection(ArrayList::new));
|
|
|
|
.collect(Collectors.toCollection(ArrayList::new));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|