diff --git a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java index c1676d879..7484c964e 100644 --- a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java +++ b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java @@ -41,17 +41,19 @@ public ArteCategoryFilmsDTO deserialize(JsonElement aJsonElement, Type aType, Js final JsonObject contentObject = jsonElement.getAsJsonObject().get(JSON_ELEMENT_CONTENT).getAsJsonObject(); if (contentObject.has(JSON_ELEMENT_DATA)) { for(JsonElement dataElement : contentObject.get(JSON_ELEMENT_DATA).getAsJsonArray()) { - String programId = dataElement.getAsJsonObject().get(JSON_ELEMENT_PROGRAMID).getAsString(); - if (programId != null) { - if (programId.startsWith("RC-")) { - try { - long collectionId = Long.parseLong(programId.replace("RC-", "")); - dto.addCollection(String.format("RC-%06d", collectionId)); - } catch (NumberFormatException e) { - Log.errorLog(12834939, "Invalid collection id: " + programId); + if (!dataElement.getAsJsonObject().get(JSON_ELEMENT_PROGRAMID).isJsonNull()) { + String programId = dataElement.getAsJsonObject().get(JSON_ELEMENT_PROGRAMID).getAsString(); + if (programId != null) { + if (programId.startsWith("RC-")) { + try { + long collectionId = Long.parseLong(programId.replace("RC-", "")); + dto.addCollection(String.format("RC-%06d", collectionId)); + } catch (NumberFormatException e) { + Log.errorLog(12834939, "Invalid collection id: " + programId); + } + } else { + dto.addProgramId(programId); } - } else { - dto.addProgramId(programId); } } } diff --git a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmsDTO.java b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmsDTO.java index 3d85200de..7cd40a628 100644 --- a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmsDTO.java +++ b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmsDTO.java @@ -1,11 +1,12 @@ package mServer.crawler.sender.arte; -import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; public class ArteCategoryFilmsDTO { - private final ArrayList programIds = new ArrayList<>(); - private final ArrayList collectionIds = new ArrayList<>(); + private final Set programIds = new HashSet<>(); + private final Set collectionIds = new HashSet<>(); private boolean hasNextPage; @@ -16,10 +17,10 @@ public void addCollection(String aCollectionId) { collectionIds.add(aCollectionId); } - public ArrayList getProgramIds() { + public Set getProgramIds() { return programIds; } - public ArrayList getCollectionIds() { + public Set getCollectionIds() { return collectionIds; } diff --git a/src/test/developTest/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializerTest.java b/src/test/developTest/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializerTest.java index 94682da9c..f2c219568 100644 --- a/src/test/developTest/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializerTest.java +++ b/src/test/developTest/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializerTest.java @@ -7,9 +7,9 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Set; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; @@ -45,7 +45,7 @@ public void testDeserialize() { assertThat(actual, notNullValue()); assertThat(actual.hasNextPage(), equalTo(expectedHasNextPage)); - ArrayList actualProgramIds = actual.getProgramIds(); + Set actualProgramIds = actual.getProgramIds(); assertThat(actualProgramIds, Matchers.containsInAnyOrder(expectedProgramIds)); } }