Skip to content

Commit 9370ab3

Browse files
committed
lib(net.bndy.lib): upgrade to v1.0.5
1 parent 7c6b6e1 commit 9370ab3

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<dependency>
112112
<groupId>net.bndy</groupId>
113113
<artifactId>lib</artifactId>
114-
<version>1.0.4</version>
114+
<version>1.0.5</version>
115115
</dependency>
116116
<dependency>
117117
<groupId>org.webjars</groupId>

src/main/java/net/bndy/wf/modules/cms/services/ArticleService.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import javax.transaction.Transactional;
88

9+
import net.bndy.lib.CollectionHelper;
910
import net.bndy.lib.IOHelper;
1011
import net.bndy.lib.StringHelper;
1112
import net.bndy.wf.ApplicationContext;
@@ -19,10 +20,8 @@
1920
import net.bndy.wf.modules.cms.models.*;
2021
import net.bndy.wf.modules.cms.services.repositories.*;
2122

22-
import java.io.IOException;
2323
import java.util.ArrayList;
2424
import java.util.List;
25-
import java.util.stream.Collectors;
2625

2726
@Service
2827
@Transactional
@@ -47,19 +46,14 @@ public Article save(Article entity) {
4746
List<File> filesToDelete = new ArrayList<>();
4847
if (origin != null && origin.getAttachments() != null) {
4948
for (File f: origin.getAttachments()) {
50-
if (entity.getAttachments() == null || !entity.getAttachments().stream().anyMatch((item) -> item.getId() == f.getId())) {
49+
if (entity.getAttachments() == null || !CollectionHelper.contains(entity.getAttachments(),(item) -> item.getId() == f.getId())) {
5150
filesToDelete.add(f);
5251
}
5352
}
5453
}
5554

5655
for (File f: filesToDelete) {
57-
try {
58-
IOHelper.forceDelete(ApplicationContext.getFileFullPath(f.getPath()));
59-
} catch (IOException ex) {
60-
// TODO: exception handling
61-
ex.printStackTrace();
62-
}
56+
IOHelper.forceDelete(ApplicationContext.getFileFullPath(f.getPath()));
6357
this.fileService.delete(f.getId());
6458
}
6559
}
@@ -72,7 +66,10 @@ public Article save(Article entity) {
7266
complexKey = false;
7367
}
7468
entity = super.save(entity);
75-
this.fileService.setRef(entity.getAttachments().stream().map(x -> x.getId()).collect(Collectors.toList()));
69+
70+
if (!CollectionHelper.isNullOrEmpty(entity.getAttachments())) {
71+
this.fileService.setRef(CollectionHelper.convert(entity.getAttachments(), (x -> x.getId())));
72+
}
7673

7774
if (complexKey) {
7875
entity.setTitleKey(key + "-" + entity.getId());

src/main/java/net/bndy/wf/modules/cms/services/PageService.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import javax.transaction.Transactional;
88

9+
import net.bndy.lib.CollectionHelper;
910
import net.bndy.lib.IOHelper;
1011
import net.bndy.wf.ApplicationContext;
1112
import net.bndy.wf.modules.core.models.File;
@@ -16,10 +17,8 @@
1617
import net.bndy.wf.modules.cms.models.*;
1718
import net.bndy.wf.modules.cms.services.repositories.*;
1819

19-
import java.io.IOException;
2020
import java.util.ArrayList;
2121
import java.util.List;
22-
import java.util.stream.Collectors;
2322

2423
@Service
2524
@Transactional
@@ -69,24 +68,21 @@ public Page save(Page entity) {
6968
List<File> filesToDelete = new ArrayList<>();
7069
if (origin != null && origin.getAttachments() != null) {
7170
for (File f: origin.getAttachments()) {
72-
if (entity.getAttachments() == null || !entity.getAttachments().stream().anyMatch((item) -> item.getId() == f.getId())) {
71+
if (entity.getAttachments() == null || !CollectionHelper.contains(entity.getAttachments(), (item) -> item.getId() == f.getId())) {
7372
filesToDelete.add(f);
7473
}
7574
}
7675
}
7776

7877
for (File f: filesToDelete) {
79-
try {
80-
IOHelper.forceDelete(ApplicationContext.getFileFullPath(f.getPath()));
81-
} catch (IOException ex) {
82-
// TODO: exception handling
83-
ex.printStackTrace();
84-
}
78+
IOHelper.forceDelete(ApplicationContext.getFileFullPath(f.getPath()));
8579
this.fileService.delete(f.getId());
8680
}
8781
}
8882

89-
this.fileService.setRef(entity.getAttachments().stream().map(x -> x.getId()).collect(Collectors.toList()));
83+
if (!CollectionHelper.isNullOrEmpty(entity.getAttachments())) {
84+
this.fileService.setRef(CollectionHelper.convert(entity.getAttachments(), (x -> x.getId())));
85+
}
9086

9187
return super.save(entity);
9288
}

src/test/java/net/bndy/wf/test/InitDataTest.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)