Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
 private Policy policyFor(WsAudioItem audioItem) {
   Policy policy = new Policy();
   for (String date :
       ImmutableList.of(
           audioItem.getAllowDownloadFrom(),
           audioItem.getInputDatetime(),
           audioItem.getLastAmendTimestamp())) {
     DateTime parsed = parse(date);
     if (parsed != null) {
       policy.setAvailabilityStart(parsed);
       break;
     }
   }
   policy.setAvailableCountries(ImmutableSet.of(Countries.ALL));
   policy.setRevenueContract(PRIVATE);
   return policy;
 }