Skip to content

Commit 2b6b53f

Browse files
authored
Merge pull request #49 from jupiter-tools/fix/value-in-the-document-annotation
value in the document annotation
2 parents 14f311b + 5ad7c84 commit 2b6b53f

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.antkorwin</groupId>
77
<artifactId>spring-test-mongo</artifactId>
8-
<version>0.12</version>
8+
<version>0.13-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>spring-test-mongo</name>
@@ -25,7 +25,7 @@
2525
</developers>
2626

2727
<properties>
28-
<spring-boot.version>[2.0.3.RELEASE, 2.1.3.RELEASE]</spring-boot.version>
28+
<spring-boot.version>[2.0.3.RELEASE, 2.1.4.RELEASE]</spring-boot.version>
2929
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3030
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3131
<java.version>1.8</java.version>

src/main/java/com/jupiter/tools/spring/test/mongo/internal/exportdata/scanner/ReflectionsDocumentScanner.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.jupiter.tools.spring.test.mongo.internal.exportdata.scanner;
22

33
import org.reflections.Reflections;
4+
import org.springframework.core.annotation.AnnotationUtils;
45
import org.springframework.data.mongodb.core.mapping.Document;
56

67
import java.util.HashMap;
@@ -9,10 +10,10 @@
910

1011
/**
1112
* Created on 03.01.2019.
12-
*
13+
* <p>
1314
* Scans selected package on the MongoDB Documents and returns
1415
* a map with all founded collections with their class-types.
15-
*
16+
* <p>
1617
* Finds all classes which annotated by the Document annotation
1718
* and takes collection names from this annotation or takes a class
1819
* name if the collection name doesn't set by the Document annotation.
@@ -38,24 +39,23 @@ public Map<String, Class<?>> scan() {
3839
for (Class<?> doc : documents) {
3940

4041
Document annotation = doc.getAnnotation(Document.class);
42+
String value = (String) AnnotationUtils.getValue(annotation, "value");
4143

42-
if (notEmpty(annotation.value())) {
43-
result.put(annotation.value(), doc);
44-
continue;
44+
if (empty(value)) {
45+
value = annotation.collection();
4546
}
4647

47-
if (notEmpty(annotation.collection())) {
48-
result.put(annotation.collection(), doc);
49-
continue;
48+
if(empty(value)){
49+
value = doc.getSimpleName().toLowerCase();
5050
}
5151

52-
result.put(doc.getSimpleName().toLowerCase(), doc);
52+
result.put(value, doc);
5353
}
5454

5555
return result;
5656
}
5757

58-
private boolean notEmpty(String value) {
59-
return !("".equals(value));
58+
private boolean empty(String value) {
59+
return value == null || "".equals(value);
6060
}
6161
}

src/test/java/com/jupiter/tools/spring/test/mongo/internal/exportdata/scanner/ReflectionsDocumentScannerTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ private class AntkorwinTestDocFirst {
4040

4141
}
4242

43-
@Document(value = "antkorwin-test-doc-second")
43+
// since spring boot 2.1.x
44+
// you can use value instead of the attribute `collection`:
45+
@Document("antkorwin-test-doc-second")
4446
private class AntkorwinTestDocSecond {
4547

4648
}

0 commit comments

Comments
 (0)