Search in sources :

Example 6 with CountryCode

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;
}
Also used : CountryCode(com.neovisionaries.i18n.CountryCode) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with CountryCode

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());
}
Also used : ModuleEntry(de.notecho.spotify.database.user.entities.module.ModuleEntry) CountryCode(com.neovisionaries.i18n.CountryCode) Track(se.michaelthelin.spotify.model_objects.specification.Track) SneakyThrows(lombok.SneakyThrows)

Example 8 with CountryCode

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);
}
Also used : Address(io.sphere.sdk.models.Address) LocalizedString(io.sphere.sdk.models.LocalizedString) ZonedDateTime(java.time.ZonedDateTime) CountryCode(com.neovisionaries.i18n.CountryCode) MonetaryAmount(javax.money.MonetaryAmount) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) CustomerGroup(io.sphere.sdk.customergroups.CustomerGroup) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) Test(org.junit.Test)

Example 9 with CountryCode

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);
}
Also used : CountryCode(com.neovisionaries.i18n.CountryCode) SphereTestUtils.consumerToFunction(io.sphere.sdk.test.SphereTestUtils.consumerToFunction) ShippingMethodQueryModel(io.sphere.sdk.shippingmethods.queries.ShippingMethodQueryModel) ShippingMethodQuery(io.sphere.sdk.shippingmethods.queries.ShippingMethodQuery) ShippingMethodDeleteCommand(io.sphere.sdk.shippingmethods.commands.ShippingMethodDeleteCommand) SphereInternalUtils.setOf(io.sphere.sdk.utils.SphereInternalUtils.setOf) ZoneCreateCommand(io.sphere.sdk.zones.commands.ZoneCreateCommand) Set(java.util.Set) Function(java.util.function.Function) BlockingSphereClient(io.sphere.sdk.client.BlockingSphereClient) Consumer(java.util.function.Consumer) SphereException(io.sphere.sdk.models.SphereException) ZoneQuery(io.sphere.sdk.zones.queries.ZoneQuery) ZoneDeleteCommand(io.sphere.sdk.zones.commands.ZoneDeleteCommand) ZoneQuery(io.sphere.sdk.zones.queries.ZoneQuery) CountryCode(com.neovisionaries.i18n.CountryCode) SphereException(io.sphere.sdk.models.SphereException)

Example 10 with CountryCode

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()));
}
Also used : CountryCode(com.neovisionaries.i18n.CountryCode) io.sphere.sdk.zones(io.sphere.sdk.zones) IntegrationTest(io.sphere.sdk.test.IntegrationTest) SphereTestUtils(io.sphere.sdk.test.SphereTestUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SphereJsonUtils(io.sphere.sdk.json.SphereJsonUtils) Set(java.util.Set) Test(org.junit.Test) NotThreadSafe(net.jcip.annotations.NotThreadSafe) SphereInternalUtils.asSet(io.sphere.sdk.utils.SphereInternalUtils.asSet) ZoneFixtures.withZone(io.sphere.sdk.zones.ZoneFixtures.withZone) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) ZoneFixtures.withZone(io.sphere.sdk.zones.ZoneFixtures.withZone) CountryCode(com.neovisionaries.i18n.CountryCode) IntegrationTest(io.sphere.sdk.test.IntegrationTest) Test(org.junit.Test)

Aggregations

CountryCode (com.neovisionaries.i18n.CountryCode)12 Test (org.junit.Test)3 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2 AchievementItemController (com.faforever.client.achievements.AchievementItemController)1 AchievementService (com.faforever.client.achievements.AchievementService)1 AchievementState (com.faforever.client.achievements.AchievementService.AchievementState)1 UNLOCKED (com.faforever.client.achievements.AchievementService.AchievementState.UNLOCKED)1 AchievementDefinition (com.faforever.client.api.dto.AchievementDefinition)1 PlayerAchievement (com.faforever.client.api.dto.PlayerAchievement)1 PlayerEvent (com.faforever.client.api.dto.PlayerEvent)1 RatingHistoryDataPoint (com.faforever.client.domain.RatingHistoryDataPoint)1 EventService (com.faforever.client.events.EventService)1 EVENT_AEON_PLAYS (com.faforever.client.events.EventService.EVENT_AEON_PLAYS)1 EVENT_AEON_WINS (com.faforever.client.events.EventService.EVENT_AEON_WINS)1 EVENT_BUILT_AIR_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_AIR_UNITS)1 EVENT_BUILT_LAND_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_LAND_UNITS)1 EVENT_BUILT_NAVAL_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_NAVAL_UNITS)1 EVENT_BUILT_TECH_1_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_TECH_1_UNITS)1 EVENT_BUILT_TECH_2_UNITS (com.faforever.client.events.EventService.EVENT_BUILT_TECH_2_UNITS)1