-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix/#191 #196
Merged
Merged
Hotfix/#191 #196
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
37a7151
Fix Exception bei Zugriff auf JsonNull
pidoubleyou b05b26b
Erstaustrahlungsdatum verwenden
pidoubleyou fec7236
Logik für Ermittlung des Datums anhand von catchupRights
pidoubleyou 4ce37c7
Auslagerung der Verarbeitung der Detail-Infos
pidoubleyou 50a46b5
Logik für Bestückung des Ausstrahlungsdatum angepasst
pidoubleyou a5d7a5b
SonarQube
pidoubleyou 3aaf786
SonarQube
pidoubleyou 42eb29e
SonarQube
pidoubleyou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions
16
src/main/java/mServer/crawler/sender/arte/ArteVideoDetailsDTO.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,16 @@ | ||
package mServer.crawler.sender.arte; | ||
|
||
public class ArteVideoDetailsDTO { | ||
private String broadcastBegin = ""; | ||
|
||
public ArteVideoDetailsDTO() { | ||
} | ||
|
||
public String getBroadcastBegin() { | ||
return this.broadcastBegin; | ||
} | ||
|
||
public void setBroadcastBegin(String aBroadcastBegin) { | ||
this.broadcastBegin = aBroadcastBegin; | ||
} | ||
} |
194 changes: 194 additions & 0 deletions
194
src/main/java/mServer/crawler/sender/arte/ArteVideoDetailsDeserializer.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,194 @@ | ||
package mServer.crawler.sender.arte; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParseException; | ||
import java.lang.reflect.Type; | ||
import java.text.ParseException; | ||
import java.util.Calendar; | ||
import mServer.tool.DateWithoutTimeComparer; | ||
import org.apache.commons.lang3.time.FastDateFormat; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class ArteVideoDetailsDeserializer implements JsonDeserializer<ArteVideoDetailsDTO> { | ||
|
||
/* | ||
* Grobe Struktur des Json's: | ||
* { | ||
* "meta": {} | ||
* "programs": [{ (JSON_ELEMENT_BROADCAST_ELTERNKNOTEN_1) | ||
"broadcastProgrammings": [{ (JSON_ELEMENT_BROADCAST_ELTERNKNOTEN_2) | ||
"broadcastBeginRounded": "2016-07-06T02:40:00Z", (JSON_ELEMENT_BROADCAST) | ||
"broadcastType": MAJOR_REBROADCAST, (JSON_ELEMENT_BROADCAST_TYPE) | ||
]} | ||
]} | ||
* } | ||
*/ | ||
private static final String JSON_ELEMENT_BROADCAST_ELTERNKNOTEN_1 = "programs"; | ||
private static final String JSON_ELEMENT_BROADCAST_ELTERNKNOTEN_2 = "broadcastProgrammings"; | ||
private static final String JSON_ELEMENT_BROADCAST = "broadcastBeginRounded"; | ||
private static final String JSON_ELEMENT_BROADCASTTYPE = "broadcastType"; | ||
private static final String JSON_ELEMENT_BROADCAST_CATCHUPRIGHTS_BEGIN = "catchupRightsBegin"; | ||
private static final String JSON_ELEMENT_BROADCAST_CATCHUPRIGHTS_END = "catchupRightsEnd"; | ||
private static final String BROADCASTTTYPE_FIRST = "FIRST_BROADCAST"; | ||
private static final String BROADCASTTTYPE_MINOR_RE = "MINOR_REBROADCAST"; | ||
private static final String BROADCASTTTYPE_MAJOR_RE = "MAJOR_REBROADCAST"; | ||
|
||
private static final Logger LOG = LogManager.getLogger(ArteVideoDeserializer.class); | ||
|
||
private final FastDateFormat broadcastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssX");//2016-10-29T16:15:00Z | ||
|
||
private final Calendar today; | ||
|
||
public ArteVideoDetailsDeserializer(Calendar aToday) { | ||
today = aToday; | ||
} | ||
|
||
@Override | ||
public ArteVideoDetailsDTO deserialize(JsonElement aJsonElement, Type aType, JsonDeserializationContext aContext) throws JsonParseException { | ||
ArteVideoDetailsDTO detailsDTO = new ArteVideoDetailsDTO(); | ||
|
||
if(aJsonElement.isJsonObject() && | ||
aJsonElement.getAsJsonObject().get(JSON_ELEMENT_BROADCAST_ELTERNKNOTEN_1).getAsJsonArray().size() > 0) { | ||
|
||
JsonObject programElement = aJsonElement.getAsJsonObject() | ||
.get(JSON_ELEMENT_BROADCAST_ELTERNKNOTEN_1).getAsJsonArray().get(0).getAsJsonObject(); | ||
JsonArray broadcastArray = programElement.get(JSON_ELEMENT_BROADCAST_ELTERNKNOTEN_2).getAsJsonArray(); | ||
|
||
if(broadcastArray.size() > 0) { | ||
String broadcastBeginFirst = ""; | ||
String broadcastBeginMajor = ""; | ||
String broadcastBeginMinor = ""; | ||
|
||
// nach Priorität der BroadcastTypen den relevanten Eintrag suchen | ||
// FIRST_BROADCAST => MAJOR_REBROADCAST => MINOR_REBROADCAST | ||
// dabei die "aktuellste" Ausstrahlung verwenden | ||
for(int i = 0; i < broadcastArray.size(); i++) { | ||
JsonObject broadcastObject = broadcastArray.get(i).getAsJsonObject(); | ||
|
||
if(broadcastObject.has(JSON_ELEMENT_BROADCASTTYPE) && | ||
broadcastObject.has(JSON_ELEMENT_BROADCAST)) { | ||
String value = this.getBroadcastDate(broadcastObject); | ||
|
||
if(!value.isEmpty()) { | ||
String type = broadcastObject.get(JSON_ELEMENT_BROADCASTTYPE).getAsString(); | ||
switch(type) { | ||
case BROADCASTTTYPE_FIRST: | ||
broadcastBeginFirst = value; | ||
break; | ||
case BROADCASTTTYPE_MAJOR_RE: | ||
broadcastBeginMajor = value; | ||
break; | ||
case BROADCASTTTYPE_MINOR_RE: | ||
broadcastBeginMinor = value; | ||
break; | ||
default: | ||
LOG.debug("New broadcasttype: " + type); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if(!broadcastBeginFirst.isEmpty()) { | ||
detailsDTO.setBroadcastBegin(broadcastBeginFirst); | ||
} else if(!broadcastBeginMajor.isEmpty()) { | ||
detailsDTO.setBroadcastBegin(broadcastBeginMajor); | ||
} else if(!broadcastBeginMinor.isEmpty()) { | ||
detailsDTO.setBroadcastBegin(broadcastBeginMinor); | ||
} | ||
|
||
// wenn kein Ausstrahlungsdatum vorhanden, dann die erste Ausstrahlung nehmen | ||
// egal, wann die CatchupRights liegen, damit ein "sinnvolles" Datum vorhanden ist | ||
if(detailsDTO.getBroadcastBegin().isEmpty()) { | ||
detailsDTO.setBroadcastBegin(getFirstBroadcastDateIgnoringCatchupRights(broadcastArray)); | ||
} | ||
} else { | ||
// keine Ausstrahlungen verfügbar => catchupRightsBegin verwenden | ||
JsonElement elementBegin = programElement.get(JSON_ELEMENT_BROADCAST_CATCHUPRIGHTS_BEGIN); | ||
|
||
if(!elementBegin.isJsonNull()) { | ||
detailsDTO.setBroadcastBegin(elementBegin.getAsString()); | ||
} | ||
} | ||
} | ||
|
||
return detailsDTO; | ||
} | ||
|
||
/** | ||
* Liefert den Beginn der Ausstrahlung, | ||
* wenn | ||
* - heute im Zeitraum von CatchUpRights liegt | ||
* - oder heute vor dem Zeitraum liegt | ||
* - oder CatchUpRights nicht gesetzt ist und die Ausstrahlung in der Vergangenheit liegt | ||
* @param broadcastObject | ||
* @return der Beginn der Ausstrahlung oder "" | ||
*/ | ||
private String getBroadcastDate(JsonObject broadcastObject) { | ||
String broadcastDate = ""; | ||
|
||
JsonElement elementBegin = broadcastObject.get(JSON_ELEMENT_BROADCAST_CATCHUPRIGHTS_BEGIN); | ||
JsonElement elementEnd = broadcastObject.get(JSON_ELEMENT_BROADCAST_CATCHUPRIGHTS_END); | ||
|
||
if (!elementBegin.isJsonNull() && !elementEnd.isJsonNull()) { | ||
String begin = elementBegin.getAsString(); | ||
String end = elementEnd.getAsString(); | ||
|
||
try { | ||
Calendar beginDate = Calendar.getInstance(); | ||
beginDate.setTime(broadcastDateFormat.parse(begin)); | ||
Calendar endDate = Calendar.getInstance(); | ||
endDate.setTime(broadcastDateFormat.parse(end)); | ||
|
||
if(DateWithoutTimeComparer.compare(today, beginDate) >= 0 && DateWithoutTimeComparer.compare(today, endDate) <= 0) { | ||
// wenn das heutige Datum zwischen begin und end liegt, | ||
// dann ist es die aktuelle Ausstrahlung | ||
broadcastDate = broadcastObject.get(JSON_ELEMENT_BROADCAST).getAsString(); | ||
} else if(DateWithoutTimeComparer.compare(today, beginDate) < 0) { | ||
// ansonsten die zukünftige verwenden | ||
broadcastDate = broadcastObject.get(JSON_ELEMENT_BROADCAST).getAsString(); | ||
} | ||
|
||
} catch (ParseException ex) { | ||
LOG.debug(ex); | ||
} | ||
} else { | ||
String broadcast = broadcastObject.get(JSON_ELEMENT_BROADCAST).getAsString(); | ||
|
||
try { | ||
Calendar broadcastCal = Calendar.getInstance(); | ||
broadcastCal.setTime(broadcastDateFormat.parse(broadcast)); | ||
broadcastDate = broadcast; | ||
|
||
} catch (ParseException ex) { | ||
LOG.debug(ex); | ||
} | ||
} | ||
return broadcastDate; | ||
} | ||
|
||
private static String getFirstBroadcastDateIgnoringCatchupRights(JsonArray broadcastArray) { | ||
String broadcastDate = ""; | ||
|
||
for(int i = 0; i < broadcastArray.size(); i++) { | ||
JsonObject broadcastObject = broadcastArray.get(i).getAsJsonObject(); | ||
|
||
if(broadcastObject.has(JSON_ELEMENT_BROADCASTTYPE) && | ||
broadcastObject.has(JSON_ELEMENT_BROADCAST)) { | ||
String type = broadcastObject.get(JSON_ELEMENT_BROADCASTTYPE).getAsString(); | ||
|
||
switch(type) { | ||
case BROADCASTTTYPE_FIRST: | ||
broadcastDate = (broadcastObject.get(JSON_ELEMENT_BROADCAST).getAsString()); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return broadcastDate; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this package name to match the regular expression '^[a-z]+(.[a-z][a-z0-9])$'.