Skip to content

Commit 9aa0a2b

Browse files
committed
Fixed importing comics with too long of a volume value [#2303]
1 parent ab0a434 commit 9aa0a2b

File tree

3 files changed

+92
-7
lines changed

3 files changed

+92
-7
lines changed

comixed-adaptors/src/main/java/org/comixedproject/adaptors/content/ComicInfoXmlFilenameContentAdaptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.comixedproject.adaptors.content;
2020

2121
import static org.apache.commons.lang3.StringUtils.trim;
22+
import static org.apache.commons.lang3.StringUtils.truncate;
2223

2324
import com.fasterxml.jackson.databind.DeserializationFeature;
2425
import java.io.ByteArrayInputStream;
@@ -75,7 +76,7 @@ public void loadContent(
7576
log.trace("Setting comic metadata");
7677
comicBook.getComicDetail().setPublisher(trim(comicInfo.getPublisher()));
7778
comicBook.getComicDetail().setSeries(trim(comicInfo.getSeries()));
78-
comicBook.getComicDetail().setVolume(trim(comicInfo.getVolume()));
79+
comicBook.getComicDetail().setVolume(truncate(trim(comicInfo.getVolume()), 0, 4));
7980
comicBook.getComicDetail().setIssueNumber(trim(comicInfo.getIssueNumber()));
8081
if (comicInfo.getYear() != null && comicInfo.getMonth() != null) {
8182
GregorianCalendar gc =

comixed-adaptors/src/test/java/org/comixedproject/adaptors/content/ComicInfoXmlFilenameContentAdaptorTest.java

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

1919
package org.comixedproject.adaptors.content;
2020

21-
import static junit.framework.TestCase.assertEquals;
22-
import static junit.framework.TestCase.assertFalse;
23-
import static junit.framework.TestCase.assertNull;
24-
import static junit.framework.TestCase.assertTrue;
21+
import static junit.framework.TestCase.*;
2522

2623
import java.io.IOException;
2724
import org.comixedproject.model.archives.ArchiveType;
@@ -37,6 +34,8 @@
3734
public class ComicInfoXmlFilenameContentAdaptorTest extends BaseContentAdaptorTest {
3835
private static final String TEST_COMICINFO_FILE_COMPLETE =
3936
"src/test/resources/ComicInfo-complete.xml";
37+
private static final String TEST_COMICINFO_FILE_LONG_VOLUME =
38+
"src/test/resources/ComicInfo-long-volume.xml";
4039
private static final String TEST_COMICINFO_FILE_NOT_XML =
4140
"src/test/resources/application.properties";
4241
private static final String TEST_PUBLISHER_NAME = "Test Publisher";
@@ -61,7 +60,7 @@ public void setup() {
6160
}
6261

6362
@Test(expected = ContentAdaptorException.class)
64-
public void testLoadComicInfoXmlNotXml() throws IOException, ContentAdaptorException {
63+
public void testLoadComicInfoXml_notXml() throws IOException, ContentAdaptorException {
6564
adaptor.loadContent(
6665
comicBook,
6766
TEST_COMICINFO_FILE_COMPLETE,
@@ -92,7 +91,7 @@ public void testLoadComicInfoXml() throws IOException, ContentAdaptorException {
9291
}
9392

9493
@Test
95-
public void testLoadComicInfoXmlSkipMetadata() throws IOException, ContentAdaptorException {
94+
public void testLoadComicInfoXml_skipMetadata() throws IOException, ContentAdaptorException {
9695
contentAdaptorRules.setSkipMetadata(true);
9796

9897
adaptor.loadContent(
@@ -110,4 +109,16 @@ public void testLoadComicInfoXmlSkipMetadata() throws IOException, ContentAdapto
110109
assertNull(comicBook.getComicDetail().getTitle());
111110
assertNull(comicBook.getComicDetail().getDescription());
112111
}
112+
113+
@Test
114+
public void testLoadComicInfoXml_volumeTooLong() throws IOException, ContentAdaptorException {
115+
adaptor.loadContent(
116+
comicBook,
117+
TEST_COMICINFO_FILE_LONG_VOLUME,
118+
loadFile(TEST_COMICINFO_FILE_LONG_VOLUME),
119+
contentAdaptorRules);
120+
121+
assertNotNull(comicBook.getComicDetail().getVolume());
122+
assertEquals(4, comicBook.getComicDetail().getVolume().length());
123+
}
113124
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0"?>
2+
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<Title> Test Title </Title>
5+
<Series> Test Series </Series>
6+
<AlternateSeries> Test Alternate Series </AlternateSeries>
7+
<Number> 24 </Number>
8+
<Volume> 201123 </Volume>
9+
<Summary> Test summary &lt;em&gt;inner tag&lt;/em&gt; </Summary>
10+
<Notes> Test notes </Notes>
11+
<Year>2013</Year>
12+
<Month>12</Month>
13+
<Writer> Test Writer1 , Test Writer2 </Writer>
14+
<Penciller> Test Penciller1 , Test Penciller2 </Penciller>
15+
<Inker> Test Inker1 , Test Inker2 </Inker>
16+
<Colorist> Test Colorist1 , Test Colorist2 </Colorist>
17+
<Letterer> Test Letterer1 , Test Letterer2 </Letterer>
18+
<CoverArtist> Test CoverArtist1 , Test CoverArtist2 </CoverArtist>
19+
<Editor> Test Editor1 , Test Editor2 </Editor>
20+
<Publisher> Test Publisher </Publisher>
21+
<Web>http://comicvine.gamespot.com/foo/71765-12971/</Web>
22+
<PageCount>20</PageCount>
23+
<Characters> Chareacter1 , Character2 </Characters>
24+
<Teams> Test Team 1 , Test Team 2 </Teams>
25+
<Locations> Test Location 1 , Test Location 2 </Locations>
26+
<MetadataSource>
27+
<Name>ComicVine</Name>
28+
<ReferenceId> 12971 </ReferenceId>
29+
</MetadataSource>
30+
<Pages>
31+
<Page Image="0" ImageSize="762694" ImageWidth="1440"
32+
ImageHeight="2214" Type="FrontCover" />
33+
<Page Image="1" ImageSize="736690" ImageWidth="1440"
34+
ImageHeight="2214" />
35+
<Page Image="2" ImageSize="713093" ImageWidth="1440"
36+
ImageHeight="2214" />
37+
<Page Image="3" ImageSize="620017" ImageWidth="1440"
38+
ImageHeight="2214" />
39+
<Page Image="4" ImageSize="1379962" ImageWidth="2880"
40+
ImageHeight="2213" />
41+
<Page Image="5" ImageSize="748871" ImageWidth="1440"
42+
ImageHeight="2214" />
43+
<Page Image="6" ImageSize="863017" ImageWidth="1440"
44+
ImageHeight="2214" />
45+
<Page Image="7" ImageSize="1597046" ImageWidth="2880"
46+
ImageHeight="2213" />
47+
<Page Image="8" ImageSize="640363" ImageWidth="1440"
48+
ImageHeight="2214" />
49+
<Page Image="9" ImageSize="597280" ImageWidth="1440"
50+
ImageHeight="2214" />
51+
<Page Image="10" ImageSize="565942" ImageWidth="1440"
52+
ImageHeight="2214" />
53+
<Page Image="11" ImageSize="626838" ImageWidth="1440"
54+
ImageHeight="2214" />
55+
<Page Image="12" ImageSize="809706" ImageWidth="1440"
56+
ImageHeight="2214" />
57+
<Page Image="13" ImageSize="665441" ImageWidth="1440"
58+
ImageHeight="2214" />
59+
<Page Image="14" ImageSize="668657" ImageWidth="1440"
60+
ImageHeight="2214" />
61+
<Page Image="15" ImageSize="695300" ImageWidth="1440"
62+
ImageHeight="2214" />
63+
<Page Image="16" ImageSize="1021125" ImageWidth="2880"
64+
ImageHeight="2213" />
65+
<Page Image="17" ImageSize="972152" ImageWidth="1440"
66+
ImageHeight="2214" />
67+
<Page Image="18" ImageSize="510149" ImageWidth="1440"
68+
ImageHeight="2214" />
69+
<Page Image="19" ImageSize="672544" ImageWidth="1440"
70+
ImageHeight="2214" />
71+
</Pages>
72+
</ComicInfo>
73+

0 commit comments

Comments
 (0)