-
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: handle Collections in CategoryFilmList
- Loading branch information
Showing
5 changed files
with
116 additions
and
35 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
42 changes: 42 additions & 0 deletions
42
src/main/java/mServer/crawler/sender/arte/ArteCollectionDeserializer.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,42 @@ | ||
package mServer.crawler.sender.arte; | ||
|
||
import com.google.gson.*; | ||
import mServer.crawler.sender.base.JsonUtils; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
public class ArteCollectionDeserializer implements JsonDeserializer<ArteCategoryFilmsDTO> { | ||
private static final String ATTRIBUTE_PROGRAM_ID = "programId"; | ||
private static final String ELEMENT_PROGRAMS = "programs"; | ||
private static final String ELEMENT_VIDEOS = "videos"; | ||
|
||
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_VIDEOS)) { | ||
programObject | ||
.get(ELEMENT_VIDEOS) | ||
.getAsJsonArray() | ||
.forEach( | ||
filmElement -> | ||
JsonUtils.getAttributeAsString(filmElement.getAsJsonObject(), ATTRIBUTE_PROGRAM_ID) | ||
.ifPresent(result::addProgramId)); | ||
} | ||
}); | ||
} | ||
} | ||
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