Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support premium list updating in Cloud SQL (#422)
* Support premium list updating in Cloud SQL This also removes the requirement to specify --also_cloud_sql in nomulus premium list tooling, instead always persisting to Cloud SQL. It removes a non-USD premium label in the global test premium list (the Cloud SQL schema doesn't support a mix of currency units in a single premium list). And it adds a method to PremiumListDao to grab the most recent version of a given list. * Merge branch 'master' into premium-lists-always-cloud-sql * Revert test change * Create new PremiumListUtils class and refactor out existing method * Fix tests and update an existing premium price
- Loading branch information
Showing
18 changed files
with
199 additions
and
165 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
61 changes: 61 additions & 0 deletions
61
core/src/main/java/google/registry/schema/tld/PremiumListUtils.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,61 @@ | ||
// Copyright 2019 The Nomulus Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package google.registry.schema.tld; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
|
||
import com.google.common.base.Splitter; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.ImmutableSortedSet; | ||
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.Maps; | ||
import google.registry.model.registry.label.PremiumList.PremiumListEntry; | ||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.joda.money.CurrencyUnit; | ||
|
||
/** Static utility methods for {@link PremiumList}. */ | ||
public class PremiumListUtils { | ||
|
||
public static PremiumList parseToPremiumList(String name, String inputData) { | ||
List<String> inputDataPreProcessed = | ||
Splitter.on('\n').omitEmptyStrings().splitToList(inputData); | ||
|
||
ImmutableMap<String, PremiumListEntry> prices = | ||
new google.registry.model.registry.label.PremiumList.Builder() | ||
.setName(name) | ||
.build() | ||
.parse(inputDataPreProcessed); | ||
ImmutableSet<CurrencyUnit> currencies = | ||
prices.values().stream() | ||
.map(e -> e.getValue().getCurrencyUnit()) | ||
.distinct() | ||
.collect(toImmutableSet()); | ||
checkArgument( | ||
currencies.size() == 1, | ||
"The Cloud SQL schema requires exactly one currency, but got: %s", | ||
ImmutableSortedSet.copyOf(currencies)); | ||
CurrencyUnit currency = Iterables.getOnlyElement(currencies); | ||
|
||
Map<String, BigDecimal> priceAmounts = | ||
Maps.transformValues(prices, ple -> ple.getValue().getAmount()); | ||
return google.registry.schema.tld.PremiumList.create(name, currency, priceAmounts); | ||
} | ||
|
||
private PremiumListUtils() {} | ||
} |
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
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
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
Oops, something went wrong.