fix(metadata): support multiple roles for the same creator in EPUB metadata extraction (#561)
This commit is contained in:
+6
-4
@@ -184,7 +184,7 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
|||||||
NodeList children = metadata.getChildNodes();
|
NodeList children = metadata.getChildNodes();
|
||||||
|
|
||||||
Map<String, String> creatorsById = new HashMap<>();
|
Map<String, String> creatorsById = new HashMap<>();
|
||||||
Map<String, String> creatorRoleById = new HashMap<>();
|
Map<String, List<String>> creatorRolesById = new HashMap<>();
|
||||||
Map<String, List<String>> creatorsByRole = new HashMap<>();
|
Map<String, List<String>> creatorsByRole = new HashMap<>();
|
||||||
creatorsByRole.put("aut", new ArrayList<>());
|
creatorsByRole.put("aut", new ArrayList<>());
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("role".equals(prop) && StringUtils.isNotBlank(refines)) {
|
if ("role".equals(prop) && StringUtils.isNotBlank(refines)) {
|
||||||
creatorRoleById.put(refines.substring(1), content.toLowerCase());
|
creatorRolesById.computeIfAbsent(refines.substring(1), k -> new ArrayList<>()).add(content.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("rendition:layout".equals(prop) && "pre-paginated".equals(content)) {
|
if ("rendition:layout".equals(prop) && "pre-paginated".equals(content)) {
|
||||||
@@ -394,8 +394,10 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
|||||||
for (Map.Entry<String, String> entry : creatorsById.entrySet()) {
|
for (Map.Entry<String, String> entry : creatorsById.entrySet()) {
|
||||||
String id = entry.getKey();
|
String id = entry.getKey();
|
||||||
String value = entry.getValue();
|
String value = entry.getValue();
|
||||||
String role = creatorRoleById.getOrDefault(id, "aut");
|
List<String> roles = creatorRolesById.getOrDefault(id, List.of("aut"));
|
||||||
creatorsByRole.computeIfAbsent(role, k -> new ArrayList<>()).add(value);
|
for (String role : roles) {
|
||||||
|
creatorsByRole.computeIfAbsent(role, k -> new ArrayList<>()).add(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builderMeta.authors(creatorsByRole.get("aut"));
|
builderMeta.authors(creatorsByRole.get("aut"));
|
||||||
|
|||||||
+13
@@ -477,6 +477,19 @@ class EpubMetadataExtractorTest {
|
|||||||
|
|
||||||
assertThat(metadata.getAuthors()).containsExactlyInAnyOrder("Author One", "Author Two");
|
assertThat(metadata.getAuthors()).containsExactlyInAnyOrder("Author One", "Author Two");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void multipleRolesForSameCreator() throws IOException {
|
||||||
|
String opf = wrapOpf("""
|
||||||
|
<dc:title>Book</dc:title>
|
||||||
|
<dc:creator id="author">Charles Dickens</dc:creator>
|
||||||
|
<meta property="role" refines="#author">aut</meta>
|
||||||
|
<meta property="role" refines="#author">waw</meta>
|
||||||
|
""");
|
||||||
|
BookMetadata metadata = extractor.extractMetadata(createEpub(opf));
|
||||||
|
|
||||||
|
assertThat(metadata.getAuthors()).containsExactly("Charles Dickens");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
Reference in New Issue
Block a user