use of com.neovisionaries.i18n.CountryCode in project steve by RWTH-i5-IDSG.
the class CountryCodesProvider method getCountryCodes.
public static Map<String, String> getCountryCodes() {
CountryCode[] codes = CountryCode.values();
Arrays.sort(codes, Comparator.comparing(CountryCode::getName));
Map<String, String> map = new LinkedHashMap<>(codes.length + 1);
map.put("", EMPTY_OPTION);
for (CountryCode c : codes) {
if (shouldInclude(c)) {
map.put(c.getAlpha2(), c.getName());
}
}
return map;
}
use of com.neovisionaries.i18n.CountryCode in project spotifybot by NotEchoDE.
the class PlayAddCommand method exec.
@SneakyThrows
@Override
public void exec(String userName, String id, UserLevel userLevel, String[] args) {
ModuleEntry sPlayAdd = getModule().getEntry("sPlayAdd");
if (!userLevel.isHigherOrEquals(sPlayAdd.getUserLevel())) {
sendMessage(getModule(ModuleType.SYSTEM).getEntry("noPerms"), "$USER", userName, "$ROLE", sPlayAdd.getUserLevel().getPrettyName());
return;
}
StringBuilder searchQuery = new StringBuilder();
if (args.length >= 1)
for (int i = 0; i < args.length; i++) if (i != 0)
searchQuery.append(" ");
else
searchQuery.append(args[i]);
else {
sendMessage(getModule(ModuleType.SYSTEM).getEntry("syntax"), "$USER", userName, "$USAGE", "!sPlayAdd [song]");
return;
}
Paging<Track> search = getRoot().getSpotifyApi().searchTracks(searchQuery.toString()).build().execute();
if (search.getTotal() == 0) {
sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notFound"), "$USER", userName);
return;
}
String uri = search.getItems()[0].getUri();
CountryCode country = getRoot().getSpotifyApi().getCurrentUsersProfile().build().execute().getCountry();
Track track = getRoot().getSpotifyApi().getTrack(uri.replace("spotify:track:", "")).build().execute();
if (Arrays.stream(track.getAvailableMarkets()).noneMatch(countryCode -> countryCode.equals(CountryCode.DE))) {
sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notAvailable"), "$USER", userName, "$SONG", track.getName());
return;
}
getRoot().getSpotifyApi().addItemToUsersPlaybackQueue(uri).build().execute();
sendMessage(sPlayAdd, "$USER", userName, "$SONG", track.getName());
}
use of com.neovisionaries.i18n.CountryCode in project commercetools-jvm-sdk by commercetools.
the class OrderImportDraftBuilderTest method constructWithAllValuesSet.
@Test
public void constructWithAllValuesSet() {
final LocalizedEnumValue yellow = LocalizedEnumValue.of("yellow", LocalizedString.of(ENGLISH, "yellow").plus(GERMAN, "gelb"));
final ProductVariantImportDraft productVariantImportDraft = ProductVariantImportDraftBuilder.of("product-id", 1).attributes(AttributeImportDraft.of("attributecolor", yellow), AttributeImportDraft.of("attributerrp", EURO_30)).build();
final LineItemImportDraft lineItemImportDraft = LineItemImportDraftBuilder.of(productVariantImportDraft, 1, Price.of(EURO_1), en("product name")).build();
final Reference<TaxCategory> taxCategoryReference = TaxCategory.referenceOfId("reference-tax-category-id");
final CustomLineItemImportDraft customLineItemImportDraft = CustomLineItemImportDraftBuilder.of(en("custom line"), 2, EURO_5, taxCategoryReference).build();
final Reference<CustomerGroup> customerGroupReference = CustomerGroup.referenceOfId("customer-group-id");
final CustomFieldsDraft custom = CustomFieldsDraftBuilder.ofTypeId("type-id").build();
final MonetaryAmount lineItemsTotalPrice = EURO_20;
final OrderState lineItemsOrderState = OrderState.COMPLETE;
final List<LineItemImportDraft> lineItems = asList(lineItemImportDraft);
final String orderNumber = "order-123";
final String customerId = "customer-id";
final String customerEmail = "customer@email.com";
final List<CustomLineItemImportDraft> customLineItems = asList(customLineItemImportDraft);
final MonetaryAmount totalPrice = EURO_10;
final TaxedPrice taxedPrice = TaxedPrice.of(EURO_15, EURO_20, asList(TaxPortion.of(1.5, EURO_1)));
final Address shippingAddress = Address.of(CountryCode.DE);
final Address billingAddress = Address.of(CountryCode.DE);
final CountryCode country = CountryCode.DE;
final OrderState orderState = OrderState.COMPLETE;
final ShipmentState shipmentState = ShipmentState.SHIPPED;
final PaymentState paymentState = PaymentState.PAID;
final ZonedDateTime completedAt = ZonedDateTime.now();
final RoundingMode taxRoundingMode = RoundingMode.HALF_UP;
final InventoryMode inventoryMode = InventoryMode.NONE;
final TaxCalculationMode taxCalculationMode = TaxCalculationMode.LINE_ITEM_LEVEL;
final CartOrigin cartOrigin = CartOrigin.MERCHANT;
final OrderImportDraftBuilder orderImportDraftBuilder = OrderImportDraftBuilder.ofLineItems(lineItemsTotalPrice, lineItemsOrderState, lineItems).orderNumber(orderNumber).customerId(customerId).customerEmail(customerEmail).customLineItems(customLineItems).totalPrice(totalPrice).taxedPrice(taxedPrice).shippingAddress(shippingAddress).billingAddress(billingAddress).customerGroup(customerGroupReference).country(country).orderState(orderState).shipmentState(shipmentState).paymentState(paymentState).completedAt(completedAt).custom(custom).taxRoundingMode(taxRoundingMode).inventoryMode(inventoryMode).taxCalculationMode(taxCalculationMode).origin(cartOrigin);
final OrderImportDraft orderImportDraft = orderImportDraftBuilder.build();
assertThat(orderImportDraft.getLineItems()).isEqualTo(lineItems);
assertThat(orderImportDraft.getOrderNumber()).isEqualTo(orderNumber);
assertThat(orderImportDraft.getCustomerId()).isEqualTo(customerId);
assertThat(orderImportDraft.getCustomerEmail()).isEqualTo(customerEmail);
assertThat(orderImportDraft.getCustomLineItems()).isEqualTo(customLineItems);
assertThat(orderImportDraft.getTotalPrice()).isEqualTo(totalPrice);
assertThat(orderImportDraft.getTaxedPrice()).isEqualTo(taxedPrice);
assertThat(orderImportDraft.getShippingAddress()).isEqualTo(shippingAddress);
assertThat(orderImportDraft.getBillingAddress()).isEqualTo(billingAddress);
assertThat(orderImportDraft.getCustomerGroup()).isEqualTo(customerGroupReference);
assertThat(orderImportDraft.getCountry()).isEqualTo(country);
assertThat(orderImportDraft.getOrderState()).isEqualTo(orderState);
assertThat(orderImportDraft.getShipmentState()).isEqualTo(shipmentState);
assertThat(orderImportDraft.getPaymentState()).isEqualTo(paymentState);
assertThat(orderImportDraft.getCompletedAt()).isEqualTo(completedAt);
assertThat(orderImportDraft.getCustom()).isEqualTo(custom);
assertThat(orderImportDraft.getTaxRoundingMode()).isEqualTo(taxRoundingMode);
assertThat(orderImportDraft.getInventoryMode()).isEqualTo(inventoryMode);
assertThat(orderImportDraft.getTaxCalculationMode()).isEqualTo(taxCalculationMode);
assertThat(orderImportDraft.getOrigin()).isEqualTo(cartOrigin);
}
use of com.neovisionaries.i18n.CountryCode in project commercetools-jvm-sdk by commercetools.
the class ZoneFixtures method deleteZonesForCountries.
public static void deleteZonesForCountries(final BlockingSphereClient client, final CountryCode country, final CountryCode... moreCountries) {
final Set<CountryCode> countries = setOf(country, moreCountries);
final ZoneQuery query = ZoneQuery.of();
final Consumer<Zone> action = zone -> {
try {
client.executeBlocking(ZoneDeleteCommand.of(zone));
} catch (final SphereException e) {
client.executeBlocking(ShippingMethodQuery.of().withPredicates(ShippingMethodQueryModel.of().zoneRates().zone().is(zone))).head().ifPresent(sm -> {
client.executeBlocking(ShippingMethodDeleteCommand.of(sm));
client.executeBlocking(ZoneDeleteCommand.of(zone));
});
}
};
client.executeBlocking(query).getResults().stream().filter(zone -> countries.stream().anyMatch(zone::contains)).forEach(action);
}
use of com.neovisionaries.i18n.CountryCode in project commercetools-jvm-sdk by commercetools.
the class ZoneCreateCommandIntegrationTest method execution.
@Test
public void execution() throws Exception {
// not complete, but you get the idea
final Set<CountryCode> euAndSwissCountries = asSet(AT, BE, CH);
final String key = randomKey();
final Set<Location> locations = euAndSwissCountries.stream().map(country -> Location.of(country)).collect(toSet());
final ZoneDraft draft = ZoneDraftBuilder.of("zone1", locations).description("EU and Swiss").key(key).build();
final ZoneCreateCommand createCommand = ZoneCreateCommand.of(draft);
final Zone zone = client().executeBlocking(createCommand);
assertThat(zone.getKey()).isEqualTo(key);
// end example parsing here
client().executeBlocking(ZoneDeleteCommand.ofKey(zone.getKey(), zone.getVersion()));
}
Aggregations