Skip to content

Commit

Permalink
fix ARTE.FR problems
Browse files Browse the repository at this point in the history
  • Loading branch information
pidoubleyou committed Sep 18, 2023
1 parent 70dbde2 commit 3dd3ac8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> programIds = new ArrayList<>();
private final ArrayList<String> collectionIds = new ArrayList<>();
private final Set<String> programIds = new HashSet<>();
private final Set<String> collectionIds = new HashSet<>();

private boolean hasNextPage;

Expand All @@ -16,10 +17,10 @@ public void addCollection(String aCollectionId) {
collectionIds.add(aCollectionId);
}

public ArrayList<String> getProgramIds() {
public Set<String> getProgramIds() {
return programIds;
}
public ArrayList<String> getCollectionIds() {
public Set<String> getCollectionIds() {
return collectionIds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,7 +45,7 @@ public void testDeserialize() {

assertThat(actual, notNullValue());
assertThat(actual.hasNextPage(), equalTo(expectedHasNextPage));
ArrayList<String> actualProgramIds = actual.getProgramIds();
Set<String> actualProgramIds = actual.getProgramIds();
assertThat(actualProgramIds, Matchers.containsInAnyOrder(expectedProgramIds));
}
}

0 comments on commit 3dd3ac8

Please sign in to comment.