forked from organicmaps/organicmaps
[promo][jni] client-server protocol is changed + test + jni
This commit is contained in:
parent
b0d143fe80
commit
faca8e61fc
7 changed files with 176 additions and 22 deletions
|
@ -14,10 +14,12 @@ namespace
|
|||
{
|
||||
jclass g_galleryClass = nullptr;
|
||||
jclass g_itemClass = nullptr;
|
||||
jclass g_placeClass = nullptr;
|
||||
jclass g_authorClass = nullptr;
|
||||
jclass g_categoryClass = nullptr;
|
||||
jmethodID g_galleryConstructor = nullptr;
|
||||
jmethodID g_itemConstructor = nullptr;
|
||||
jmethodID g_placeConstructor = nullptr;
|
||||
jmethodID g_authorConstructor = nullptr;
|
||||
jmethodID g_categoryConstructor = nullptr;
|
||||
jclass g_promoClass = nullptr;
|
||||
|
@ -42,9 +44,14 @@ void PrepareClassRefs(JNIEnv * env)
|
|||
g_itemConstructor =
|
||||
jni::GetConstructorID(env, g_itemClass,
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
|
||||
"Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
|
||||
"Ljava/lang/String;Ljava/lang/String;"
|
||||
"Lcom/mapswithme/maps/promo/PromoCityGallery$Place;"
|
||||
"Lcom/mapswithme/maps/promo/PromoCityGallery$Author;"
|
||||
"Lcom/mapswithme/maps/promo/PromoCityGallery$LuxCategory;)V");
|
||||
g_placeClass =
|
||||
jni::GetGlobalClassRef(env, "com/mapswithme/maps/promo/PromoCityGallery$Place");
|
||||
g_placeConstructor =
|
||||
jni::GetConstructorID(env, g_placeClass, "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
g_authorClass =
|
||||
jni::GetGlobalClassRef(env, "com/mapswithme/maps/promo/PromoCityGallery$Author");
|
||||
g_authorConstructor =
|
||||
|
@ -65,6 +72,7 @@ void PrepareClassRefs(JNIEnv * env)
|
|||
g_afterBookingConstructor =
|
||||
jni::GetConstructorID(env, g_afterBooking,
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
jni::HandleJavaException(env);
|
||||
}
|
||||
|
||||
void OnSuccess(uint64_t requestId, promo::CityGallery const & gallery)
|
||||
|
@ -103,24 +111,26 @@ jobject MakeCityGallery(JNIEnv * env, promo::CityGallery const & gallery)
|
|||
{
|
||||
jni::TScopedLocalRef name(env, jni::ToJavaString(env, item.m_name));
|
||||
jni::TScopedLocalRef url(env, jni::ToJavaString(env, item.m_url));
|
||||
jni::TScopedLocalRef description(env, jni::ToJavaString(env, item.m_description));
|
||||
jni::TScopedLocalRef imageUrl(env, jni::ToJavaString(env, item.m_imageUrl));
|
||||
jni::TScopedLocalRef access(env, jni::ToJavaString(env, item.m_access));
|
||||
jni::TScopedLocalRef tier(env, jni::ToJavaString(env, item.m_tier));
|
||||
jni::TScopedLocalRef placeName(env, jni::ToJavaString(env, item.m_place.m_name));
|
||||
jni::TScopedLocalRef placeDescription(env, jni::ToJavaString(env, item.m_place.m_description));
|
||||
jni::TScopedLocalRef authorId(env, jni::ToJavaString(env, item.m_author.m_id));
|
||||
jni::TScopedLocalRef authorName(env, jni::ToJavaString(env, item.m_author.m_name));
|
||||
jni::TScopedLocalRef luxCategoryName(env, jni::ToJavaString(env, item.m_luxCategory.m_name));
|
||||
jni::TScopedLocalRef luxCategoryColor(env, jni::ToJavaString(env, item.m_luxCategory.m_color));
|
||||
|
||||
jni::TScopedLocalRef place(
|
||||
env, env->NewObject(g_placeClass, g_placeConstructor, placeName.get(), placeDescription.get()));
|
||||
jni::TScopedLocalRef author(
|
||||
env, env->NewObject(g_authorClass, g_authorConstructor, authorId.get(), authorName.get()));
|
||||
jni::TScopedLocalRef luxCategory(
|
||||
env, env->NewObject(g_categoryClass, g_categoryConstructor, luxCategoryName.get(),
|
||||
luxCategoryColor.get()));
|
||||
|
||||
return env->NewObject(g_itemClass, g_itemConstructor, name.get(), url.get(),
|
||||
description.get(), imageUrl.get(), access.get(), tier.get(),
|
||||
author.get(), luxCategory.get());
|
||||
return env->NewObject(g_itemClass, g_itemConstructor, name.get(), url.get(), imageUrl.get(),
|
||||
access.get(), tier.get(), place.get(), author.get(), luxCategory.get());
|
||||
};
|
||||
|
||||
jni::TScopedLocalObjectArrayRef items(env, jni::ToJavaArray(env, g_itemClass, gallery.m_items,
|
||||
|
|
|
@ -37,28 +37,28 @@ public final class PromoCityGallery
|
|||
@NonNull
|
||||
private final String mUrl;
|
||||
@NonNull
|
||||
private final String mDescription;
|
||||
@NonNull
|
||||
private final String mImageUrl;
|
||||
@NonNull
|
||||
private final String mAccess;
|
||||
@NonNull
|
||||
private final String mTier;
|
||||
@NonNull
|
||||
private final Place mPlace;
|
||||
@NonNull
|
||||
private final Author mAuthor;
|
||||
@Nullable
|
||||
private final LuxCategory mLuxCategory;
|
||||
|
||||
public Item(@NonNull String name, @NonNull String url, @NonNull String description,
|
||||
@NonNull String imageUrl, @NonNull String access, @NonNull String tier,
|
||||
public Item(@NonNull String name, @NonNull String url, @NonNull String imageUrl,
|
||||
@NonNull String access, @NonNull String tier, @NonNull Place place,
|
||||
@NonNull Author author, @Nullable LuxCategory luxCategory)
|
||||
{
|
||||
mName = name;
|
||||
mUrl = url;
|
||||
mDescription = description;
|
||||
mImageUrl = imageUrl;
|
||||
mAccess = access;
|
||||
mTier = tier;
|
||||
mPlace = place;
|
||||
mAuthor = author;
|
||||
mLuxCategory = luxCategory;
|
||||
}
|
||||
|
@ -75,12 +75,6 @@ public final class PromoCityGallery
|
|||
return mUrl;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getDescription()
|
||||
{
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getImageUrl()
|
||||
{
|
||||
|
@ -99,6 +93,12 @@ public final class PromoCityGallery
|
|||
return mTier;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Place getPlace()
|
||||
{
|
||||
return mPlace;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Author getAuthor()
|
||||
{
|
||||
|
@ -113,6 +113,33 @@ public final class PromoCityGallery
|
|||
|
||||
}
|
||||
|
||||
public static final class Place
|
||||
{
|
||||
@NonNull
|
||||
private String mName;
|
||||
|
||||
@NonNull
|
||||
private String mDescription;
|
||||
|
||||
Place(@NonNull String name, @NonNull String description)
|
||||
{
|
||||
mName = name;
|
||||
mDescription = description;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getDescription()
|
||||
{
|
||||
return mDescription;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Author
|
||||
{
|
||||
@NonNull
|
||||
|
|
|
@ -99,3 +99,46 @@ UNIT_CLASS_TEST(ScopedEyeWithAsyncGuiThread, Promo_GetCityGallery)
|
|||
TEST_EQUAL(result.m_items.size(), 2, ());
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(ScopedEyeWithAsyncGuiThread, Promo_GetCityGallerySingleItem)
|
||||
{
|
||||
{
|
||||
promo::Api api("http://localhost:34568/single/empty/");
|
||||
api.SetDelegate(std::make_unique<DelegateForTesting>());
|
||||
auto const lang = "en";
|
||||
|
||||
promo::CityGallery result{};
|
||||
api.GetCityGallery({}, lang, UTM::None, [&result](promo::CityGallery const & gallery)
|
||||
{
|
||||
result = gallery;
|
||||
testing::Notify();
|
||||
},
|
||||
[]
|
||||
{
|
||||
testing::Notify();
|
||||
});
|
||||
|
||||
testing::Wait();
|
||||
TEST_EQUAL(result.m_items.size(), 0, ());
|
||||
}
|
||||
{
|
||||
promo::Api api("http://localhost:34568/single/");
|
||||
api.SetDelegate(std::make_unique<DelegateForTesting>());
|
||||
auto const lang = "en";
|
||||
|
||||
promo::CityGallery result{};
|
||||
m2::PointD pt;
|
||||
api.GetCityGallery(pt, lang, UTM::None, [&result](promo::CityGallery const & gallery)
|
||||
{
|
||||
result = gallery;
|
||||
testing::Notify();
|
||||
},
|
||||
[]
|
||||
{
|
||||
testing::Notify();
|
||||
});
|
||||
|
||||
testing::Wait();
|
||||
TEST_EQUAL(result.m_items.size(), 1, ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#include "partners_api/promo_api.hpp"
|
||||
|
||||
#include "indexer/classificator.hpp"
|
||||
#include "indexer/ftypes_matcher.hpp"
|
||||
|
||||
#include "platform/http_client.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "platform/preferred_languages.hpp"
|
||||
|
@ -65,10 +62,16 @@ void ParseCityGallery(std::string const & src, UTM utm, promo::CityGallery & res
|
|||
FromJSONObject(obj, "url", item.m_url);
|
||||
item.m_url = InjectUTM(url::Join(BOOKMARKS_CATALOG_FRONT_URL, item.m_url), utm);
|
||||
FromJSONObject(obj, "access", item.m_access);
|
||||
FromJSONObjectOptionalField(obj, "description", item.m_description);
|
||||
FromJSONObjectOptionalField(obj, "image_url", item.m_imageUrl);
|
||||
FromJSONObjectOptionalField(obj, "tier", item.m_tier);
|
||||
|
||||
auto const placeObj = json_object_get(obj, "place");
|
||||
if (json_is_object(placeObj))
|
||||
{
|
||||
FromJSONObject(placeObj, "name", item.m_place.m_name);
|
||||
FromJSONObject(placeObj, "description", item.m_place.m_description);
|
||||
}
|
||||
|
||||
auto const authorObj = json_object_get(obj, "author");
|
||||
FromJSONObject(authorObj, "key_id", item.m_author.m_id);
|
||||
FromJSONObject(authorObj, "name", item.m_author.m_name);
|
||||
|
|
|
@ -16,6 +16,13 @@
|
|||
|
||||
namespace promo
|
||||
{
|
||||
struct Place
|
||||
{
|
||||
bool IsEmpty() const { return m_name.empty() || m_description.empty(); }
|
||||
|
||||
std::string m_name;
|
||||
std::string m_description;
|
||||
};
|
||||
struct Author
|
||||
{
|
||||
std::string m_id;
|
||||
|
@ -33,17 +40,17 @@ struct CityGallery
|
|||
{
|
||||
std::string m_name;
|
||||
std::string m_url;
|
||||
std::string m_description;
|
||||
std::string m_imageUrl;
|
||||
std::string m_access;
|
||||
std::string m_tier;
|
||||
Place m_place;
|
||||
Author m_author;
|
||||
LuxCategory m_luxCategory;
|
||||
};
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return m_items.empty() || (m_items.size() == 1 && m_items.back().m_description.empty());
|
||||
return m_items.empty() || (m_items.size() == 1 && m_items.back().m_place.IsEmpty());
|
||||
}
|
||||
|
||||
std::string m_moreUrl;
|
||||
|
|
|
@ -148,6 +148,8 @@ class ResponseProvider:
|
|||
"/partners/get-offers-in-bbox/": self.partners_rent_nearby,
|
||||
"/partners/CalculateByCoords": self.partners_calculate_by_coords,
|
||||
"/gallery/v1/search/": self.promo_gallery_city,
|
||||
"/single/empty/gallery/v1/search/": self.promo_gallery_city_single_empty,
|
||||
"/single/gallery/v1/search/": self.promo_gallery_city_single,
|
||||
}[url]()
|
||||
except:
|
||||
return self.test_404()
|
||||
|
@ -243,6 +245,12 @@ class ResponseProvider:
|
|||
def promo_gallery_city(self):
|
||||
return Payload(jsons.PROMO_GALLERY_CITY)
|
||||
|
||||
def promo_gallery_city_single_empty(self):
|
||||
return Payload(jsons.PROMO_GALLERY_CITY_SINGLE_EMPTY)
|
||||
|
||||
def promo_gallery_city_single(self):
|
||||
return Payload(jsons.PROMO_GALLERY_CITY_SINGLE)
|
||||
|
||||
def kill(self):
|
||||
logging.debug("Kill called in ResponseProvider")
|
||||
self.delegate.kill()
|
||||
|
|
|
@ -551,3 +551,59 @@ PROMO_GALLERY_CITY = """
|
|||
}
|
||||
}
|
||||
"""
|
||||
|
||||
PROMO_GALLERY_CITY_SINGLE_EMPTY = """
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"url": "bundle/73af3f02-b8e3-4f60-8ef0-1c3c5cff43ca",
|
||||
"name": "По Виа Рипетта до мавзолея Августа и Алтаря мира",
|
||||
"author": {
|
||||
"key_id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "The Village"
|
||||
},
|
||||
"image_url": "http://localhost:8000/images/73af3f02-b8e3-4f60-8ef0-1c3c5cff43ca.jpg",
|
||||
"access": "public",
|
||||
"lux_category": {
|
||||
"name": "LUX",
|
||||
"color": "666666"
|
||||
},
|
||||
"tier": "price.tier"
|
||||
}
|
||||
],
|
||||
"errors": [],
|
||||
"meta": {
|
||||
"more": "search?city=888"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
PROMO_GALLERY_CITY_SINGLE = """
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"url": "bundle/73af3f02-b8e3-4f60-8ef0-1c3c5cff43ca",
|
||||
"name": "По Виа Рипетта до мавзолея Августа и Алтаря мира",
|
||||
"author": {
|
||||
"key_id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "The Village"
|
||||
},
|
||||
"image_url": "http://localhost:8000/images/73af3f02-b8e3-4f60-8ef0-1c3c5cff43ca.jpg",
|
||||
"access": "public",
|
||||
"lux_category": {
|
||||
"name": "LUX",
|
||||
"color": "666666"
|
||||
},
|
||||
"tier": "price.tier",
|
||||
"place": {
|
||||
"name": "Bookmark name",
|
||||
"description": "Bookmark description"
|
||||
}
|
||||
}
|
||||
],
|
||||
"errors": [],
|
||||
"meta": {
|
||||
"more": "search?city=888"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue