# Entities

**1. When a value in a specific language is requested, a "null" value is returned**

* Check whether the HTTP request associated with the entity on which the request was made, failed (review the REST traffic log)
* Is the specified language part of the "desired languages" / "supported languages"?
* Was the language passed to the method used to retrieve the entity higher in the hierarchy tree? e.g. requesting a language for the outcome name from the market that was requested for a different language will return a null outcome name.
* There are cases where the requested entity does not exist on the server. e.g. requesting a tournament schedule for the tournament which currently does not have an associated schedule.

**2. When retrieving a property on an entity constructed from data return from the Sports API a null is returned**

Some entities (sport hierarchy (sports, categories, tournaments, sport events), market names, outcome names, ....) are constructed from data obtained via an HTTP request (one of the endpoints found on iodocs). A null value will be returned to the associated method call if the request fails. For failed HTTP requests review the REST traffic log. (See:  [SDK - Error Handling](https://docs.sportradar.com/uof/error-handling))

**3. A SportEvent entity passed to SDK callbacks/events does not contain a method to retrieve information which should be there**

A SportEvent entity is a "base" for more specific entities (match, race, tournament, ...). If the SportEvent entity does not contain the required method, the SportEvent entity must be "type-casted" to a more specific type. For more details on the sport event derived types see the diagram in the (See:  [Java SDK - SportEvent](https://docs.sportradar.com/uof/sdk/languages/java/class-hierarchies/sportevent) and  [.Net SDK - SportEvent](https://docs.sportradar.com/uof/sdk/languages/.net/class-hierarchies/sportevent))

**4. How to access the EventTimeline in the context of oddsChange?**

The following is the code snippet (java and .net respectively) that can help log the EventTimeline information.

{% tabs %}
{% tab title="Java" %}

```java
if(oddsChange.getEvent() instanceof Match){
        Match match = (Match) oddsChange.getEvent();
        EventTimeline eventTimeline = match.getEventTimeline(Locale.ENGLISH);
        if (match.getEventTimelineIfPresent(Locale.ENGLISH).isPresent()) {
            logger.info("scoreHistory: ");
            for (TimelineEvent timelineEvent : eventTimeline.getTimelineEvents()) {
                logger.info("scoreHistory Entry (id): " + timelineEvent.getId());
                logger.info("scoreHistory Entry (sequenceNo): --------");
                logger.info("scoreHistory Entry (matchTime): " + timelineEvent.getMatchClock());
                logger.info("scoreHistory Entry (player): " + timelineEvent.getPlayer().getName(Locale.ENGLISH));
                logger.info("scoreHistory Entry (scoringTeam): " + timelineEvent.getTeam());
                logger.info("scoreHistory Entry (Score Home): " + timelineEvent.getHomeScore());
                logger.info("scoreHistory Entry (Score Away): " + timelineEvent.getAwayScore());
                logger.info("scoreHistory Entry (canceled): " + timelineEvent.getMatchStatusCode());
            }
        }
    }
```

{% endtab %}

{% tab title=".Net" %}

```aspnet
if (oddsChange.GetOddsChange().Event is IMatch match){
    var eventTimeline = match.GetEventTimelineAsync().GetAwaiter().GetResult();
    if (eventTimeline != null)
    {
        _log.LogInformation("scoreHistory: ");
        foreach (var timelineEvent in eventTimeline.TimelineEvents)
        {
            _log.LogInformation("scoreHistory Entry (id): " + timelineEvent.Id);
            _log.LogInformation("scoreHistory Entry (sequenceNo): --------");
            _log.LogInformation("scoreHistory Entry (matchTime): " + timelineEvent.MatchClock);
            _log.LogInformation("scoreHistory Entry (player): " + timelineEvent.Player.GetName(_defaultCulture));
            _log.LogInformation("scoreHistory Entry (scoringTeam): " + timelineEvent.Team);
            _log.LogInformation("scoreHistory Entry (Score Home): " + timelineEvent.HomeScore);
            _log.LogInformation("scoreHistory Entry (Score Away): " + timelineEvent.AwayScore);
            _log.LogInformation("scoreHistory Entry (canceled): " + timelineEvent.MatchStatusCode);
        }
    }
}
```

{% endtab %}
{% endtabs %}

**5. How to get Soccer Statistics from SoccerEvent in context of oddsChange?**

You should add the following code snippet to your EventListener implementation.

{% tabs %}
{% tab title="Java" %}

```java
if(oddsChange.getEvent() instanceof SoccerEvent){
            SoccerEvent soccerEvent1 = (SoccerEvent) oddsChange.getEvent();
            SoccerStatus soccerStatus = soccerEvent1.getStatus();
            SoccerStatistics soccerStatusStatistics = soccerStatus.getStatistics();
            List<PeriodStatistics> periodStatistics = soccerStatusStatistics.getPeriodStatistics ();
            List<TeamStatistics> totalStatistics = soccerStatusStatistics.getTotalStatistics();
}
```

{% endtab %}

{% tab title=".Net" %}

```
if (oddsChange.GetOddsChange().Event is ISoccerEvent soccerEvent){
    var soccerStatus = soccerEvent.GetStatusAsync().GetAwaiter().GetResult();
    var soccerStatusStatistics = soccerStatus.Statistics;
    var periodStatistics = soccerStatusStatistics.PeriodStatistics;
    var totalStatistics = soccerStatusStatistics.TotalStatistics;
}
```

{% endtab %}
{% endtabs %}

**6. How to access the fixtureChange API endpoint via the SDK and get fixtureChanges?**

Inorder to access and get fixtureChanges, use the following

{% tabs %}
{% tab title="Java" %}

```java
SportsInfoManager sportsInfoManager = oddsFeed.getSportsInfoManager();
 
List<FixtureChange> fixtureChanges = sportsInfoManager.getFixtureChanges();
for (FixtureChange fixtureChange : fixtureChanges){
 
    Urn sportEventId = fixtureChange.getSportEventId();
    Date updateTime = fixtureChange.getUpdateTime();
    Competition competition = sportsInfoManager.getCompetition(sportEventId);
 
    if(competition instanceof Match){
        Match match = (Match) competition;
 
        Fixture fixture = match.getFixture();
        MatchStatus status = match.getStatus();
 
    }
}
```

{% endtab %}

{% tab title=".Net" %}

```
var sportDataProvider = uofSdk.SportDataProvider;
 
var fixtureChanges = sportDataProvider.GetFixtureChangesAsync().GetAwaiter().GetResult();
foreach (IFixtureChange fixtureChange in fixtureChanges)
{
    var sportEventId = fixtureChange.SportEventId;
    var updateTime = fixtureChange.UpdateTime;
    var competition = sportDataProvider.GetCompetition(sportEventId);
 
    if (competition is IMatch match){
        var fixture = match.GetFixtureAsync().GetAwaiter().GetResult();
        var status = match.GetStatusAsync().GetAwaiter().GetResult();
    }
}
```

{% endtab %}
{% endtabs %}

**7. How to get an event score via feed message (e.g. odds\_change)?**<br>

The following depicts the code snippet to get the event score via odds\_change messages. You can use this as a base to write code to get the same via other feed messages.

{% tabs %}
{% tab title="Java " %}

```
if(oddsChanges.getEvent() instanceof Match) {
    Match match = (Match)oddsChanges.getEvent();
    MatchStatus matchStatus = match.getStatus();
    BigDecimal awayScore = matchStatus.getAwayScore();
    BigDecimal homeScore = matchStatus.getHomeScore();
    List<PeriodScore> periodScores = matchStatus.getPeriodScores();
}
```

{% endtab %}

{% tab title=".Net" %}

```aspnet
var baseEntity = oddsChangeEventArgs.GetOddsChange();
var sportEvent = baseEntity.Event;
IMatch match = null;
  
if(sportEvent is IMatch)
{
    match = sportEvent as IMatch;
    var matchStatus = match.GetStatusAsync().Result;
    var awayScore = matchStatus.AwayScore;
    var homeScore = matchStatus.HomeScore;
    var periodScores = matchStatus.PeriodScores;
}
```

{% endtab %}
{% endtabs %}

**8. How to get match status?**

{% tabs %}
{% tab title="Java" %}

```
LocalizedNamedValue matchStatus = match.getStatus().getMatchStatus();
```

{% endtab %}

{% tab title=".Net" %}

```
var matchEventStatus = match.GetStatusAsync().GetAwaiter().GetResult();
var matchStatus = matchEventStatus.GetMatchStatusAsync(configuration.DefaultLanguage).GetAwaiter().GetResult();
```

{% endtab %}
{% endtabs %}

**9. How to get current\_server?**<br>

Most common properties recieved in the sport event status are directly exposed on the status object via a dedicated method. All others can be obtained through properties list.&#x20;

{% tabs %}
{% tab title="Java" %}

```
match.getStatus().getPropertyValue("CurrentServer")
```

{% endtab %}

{% tab title=".Net" %}

```
var matchEventStatus = match.GetStatusAsync().GetAwaiter().GetResult();
var currentServer = matchEventStatus.GetPropertyValue("CurrentServer");
```

{% endtab %}
{% endtabs %}

**10. How to check if a match is Pre-match only or Live?**

To check if a match is pre-match only or live, you'll need to consider the bookingStatus availability

{% tabs %}
{% tab title="Java" %}

```java
BookingStatus bookingStatus = match.getBookingStatus();
if(bookingStatus.equals(BookingStatus.Unavailable)) {
    // this match is pre-match only (at least for now)
}
else {
    // this match will be covered by live
}
```

{% endtab %}

{% tab title=".Net" %}

```aspnet
var book = match.GetBookingStatusAsync().GetAwaiter().GetResult();
if(book.Equals(BookingStatus.Unavailable))
{
    // this match is pre-match only (at least for now)
}
else
{
    // this match will be covered in live
}
```

{% endtab %}
{% endtabs %}

**11. How do I book live events for the following hour?**

{% tabs %}
{% tab title="Java" %}

```java
SportDataProvider sportDataProvider = uofSdk.getSportsDataProvider();
BookingManager bookingManager = uofSdk.getBookingManager();
 
Date today = new Date();
List<Competition> competitionsToday = sportDataProvider.getCompetitionsFor(today);
for (Competition competition : competitionsToday) {
    Date scheduledTime = competition.getScheduledTime();
    Instant scheduledTimeInstant = scheduledTime.toInstant();
 
    // if difference is negative, the event is scheduled before now
    long hoursDifference = Duration.between(Instant.now(), scheduledTimeInstant).toHours();
 
    if(hoursDifference <= 1 && hoursDifference > -1) {
        boolean booked = bookingManager.bookLiveOddsEvent(competition.getId());
        if(booked) {
            logger.info(competition.getId().toString() + "Scheduled at: " + scheduledTime.toString());
        }
    }
}
```

{% endtab %}

{% tab title=".Net" %}

```aspnet
var sportDataProvider = uofSdk.SportDataProvider;
var bookingManager = uofSdk.BookingManager;
 
var today = DateTime.Now;
var competitionsToday = sportDataProvider.GetSportEventsByDateAsync(today).GetAwaiter().GetResult();
foreach (ICompetition competition in competitionsToday)
{
    var scheduledTime = competition.GetScheduledTimeAsync().GetAwaiter().GetResult();
                 
    if (scheduledTime > DateTime.Now.AddHours(-1))
    {
        var booked = bookingManager.BookLiveOddsEvent(competition.Id);
        if (booked)
        {
            _log.LogInformation(competition.Id + "Scheduled at: " + scheduledTime.ToString(CultureInfo.InvariantCulture));
        }
    }
}
```

{% endtab %}
{% endtabs %}

**12. How to get referenceIDs for events and competitors (e.g. AAMS id)?**

{% tabs %}
{% tab title="Java" %}

```java
SportDataProvider sportDataProvider = uofSdk.SportDataProvider();
 
Competition comp = sportDataProvider.getCompetition(Urn.parse("sr:match:15160287"));
if(comp instanceof Match) {
    Match match = (Match) comp;
    Fixture fixture = match.getFixture();
    Reference fixtureReferences = fixture.getReferences();
    Integer fixtureAamsId = fixtureReferences.getAamsId();
 
    TeamCompetitor homeCompetitor = match.getHomeCompetitor();
    Reference homeCompetitorReferences = homeCompetitor.getReferences();
    Integer homeCompetitorsAamsId = homeCompetitorReferences.getAamsId();
}
```

{% endtab %}

{% tab title=".Net" %}

```aspnet
var sportDataProvider = uofSdk.SportDataProvider;
 
var sportEvent = sportDataProvider.GetCompetition(Urn.Parse("sr:match:15160287"), Urn.Parse("sr:match:1"));
if(sportEvent is IMatch)
{
    var match = sportEvent as IMatch;
    var fixture = match.GetFixtureAsync().GetAwaiter().GetResult();
    var matchReferences = (IReference)fixture.References;
    var matchAamsId = matchReferences.AamsId;
  
    var homeCompetitor = match.GetHomeCompetitorAsync().GetAwaiter().GetResult();
    var competitorReferences = (IReference)homeCompetitor.References;
    var homeCompetitorAamsId = competitorReferences.AamsId;
  
}
```

{% endtab %}
{% endtabs %}
