-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARTE: fix collections with multiple children
- Loading branch information
Showing
5 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/mServer/crawler/sender/arte/ArteCollectionParentDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package mServer.crawler.sender.arte; | ||
|
||
|
||
import com.google.gson.*; | ||
import mServer.crawler.sender.base.JsonUtils; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Optional; | ||
|
||
public class ArteCollectionParentDeserializer implements JsonDeserializer<ArteCategoryFilmsDTO> { | ||
private static final String ATTRIBUTE_KIND = "kind"; | ||
private static final String ATTRIBUTE_PROGRAM_ID = "programId"; | ||
private static final String ELEMENT_PROGRAMS = "programs"; | ||
private static final String ELEMENT_CHILDREN = "children"; | ||
|
||
public ArteCategoryFilmsDTO deserialize(final JsonElement aJsonElement, final Type aType, final JsonDeserializationContext aJsonDeserializationContext) throws JsonParseException { | ||
final ArteCategoryFilmsDTO result = new ArteCategoryFilmsDTO(); | ||
if (aJsonElement.isJsonObject()) { | ||
final JsonObject mainObj = aJsonElement.getAsJsonObject(); | ||
|
||
if (JsonUtils.checkTreePath(mainObj, ELEMENT_PROGRAMS)) { | ||
final JsonArray programs = mainObj.get(ELEMENT_PROGRAMS).getAsJsonArray(); | ||
programs.forEach(program -> { | ||
final JsonObject programObject = program.getAsJsonObject(); | ||
if (JsonUtils.checkTreePath(programObject, ELEMENT_CHILDREN)) { | ||
programObject.get(ELEMENT_CHILDREN).getAsJsonArray().forEach(filmElement -> { | ||
final JsonObject filmObject = filmElement.getAsJsonObject(); | ||
final Optional<String> kind = JsonUtils.getAttributeAsString(filmObject, ATTRIBUTE_KIND); | ||
final Optional<String> programId = JsonUtils.getAttributeAsString(filmObject, ATTRIBUTE_PROGRAM_ID); | ||
|
||
if (kind.isPresent() && kind.get().equalsIgnoreCase("TV_SERIES") && programId.isPresent()) { | ||
result.addCollection(programId.get()); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters