Exemple #1
0
  public static Location locationFrom(
      String uri,
      String locationId,
      Map<String, String> lookup,
      Set<Country> availableCountries,
      DateTime lastUpdated,
      Platform platform) {
    Location location = new Location();
    location.setUri(uri);

    if (locationId != null) {
      // TODO new alias
      location.addAliasUrl(locationId);
    }
    location.setTransportType(TransportType.LINK);
    location.setLastUpdated(lastUpdated);

    // The feed only contains available content
    location.setAvailable(true);

    String availability = lookup.get(DC_TERMS_AVAILABLE);

    if (availability != null) {
      Matcher matcher = AVAILABILTY_RANGE_PATTERN.matcher(availability);
      if (!matcher.matches()) {
        throw new IllegalStateException(
            "Availability range format not recognised, was " + availability);
      }
      String txDate = lookup.get(DC_TX_DATE);
      Policy policy =
          new Policy()
              .withAvailabilityStart(
                  new DateTime(Strings.isNullOrEmpty(txDate) ? matcher.group(1) : txDate))
              .withAvailabilityEnd(new DateTime(matcher.group(2)));

      if (availableCountries != null) {
        policy.setAvailableCountries(availableCountries);
      }

      if (platform != null) {
        policy.setPlatform(platform);
      }

      location.setPolicy(policy);
    }
    return location;
  }