diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index 037a1e6be2..020afbeebe 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -326,6 +326,7 @@ nonexistentsetting NONINFRINGEMENT norestart normalizednameandpublisher +normalizedpackagenameandpublisher NOTHROW NOTIMPL NOTNULL @@ -352,6 +353,8 @@ OUTOFDISKSPACE OUTOFMEMORY OWC packagefamilyname +packageidentifier +packagename PACKAGESSCHEMA Params params diff --git a/src/AppInstallerRepositoryCore/Rest/Schema/1_0/Json/SearchRequestSerializer_1_0.cpp b/src/AppInstallerRepositoryCore/Rest/Schema/1_0/Json/SearchRequestSerializer_1_0.cpp index f79edfd4a8..7e0b2a1930 100644 --- a/src/AppInstallerRepositoryCore/Rest/Schema/1_0/Json/SearchRequestSerializer_1_0.cpp +++ b/src/AppInstallerRepositoryCore/Rest/Schema/1_0/Json/SearchRequestSerializer_1_0.cpp @@ -144,8 +144,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_0::Json } filter[JsonHelper::GetUtilityString(PackageMatchField)] = web::json::value::string(JsonHelper::GetUtilityString(matchField.value())); - AppInstaller::Repository::RequestMatch requestMatch{ packageMatchFilter.Type, packageMatchFilter.Value }; - std::optional requestMatchJson = GetRequestMatchJsonObject(requestMatch); + std::optional requestMatchJson = GetRequestMatchJsonObject(packageMatchFilter); if (!requestMatchJson) { diff --git a/src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h b/src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h index babf7f1349..f074c60290 100644 --- a/src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h +++ b/src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h @@ -29,6 +29,8 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1 SearchResult GetSearchResult(const web::json::value& searchResponseObject) const override; std::vector GetParsedManifests(const web::json::value& manifestsResponseObject) const override; + PackageMatchField ConvertStringToPackageMatchField(std::string_view field) const; + private: IRestClient::Information m_information; }; diff --git a/src/AppInstallerRepositoryCore/Rest/Schema/1_1/RestInterface_1_1.cpp b/src/AppInstallerRepositoryCore/Rest/Schema/1_1/RestInterface_1_1.cpp index 613dac173d..494055110b 100644 --- a/src/AppInstallerRepositoryCore/Rest/Schema/1_1/RestInterface_1_1.cpp +++ b/src/AppInstallerRepositoryCore/Rest/Schema/1_1/RestInterface_1_1.cpp @@ -88,7 +88,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1 for (auto const& field : m_information.RequiredPackageMatchFields) { - PackageMatchField matchField = StringToPackageMatchField(field); + PackageMatchField matchField = ConvertStringToPackageMatchField(field); if (searchRequest.Filters.end() == std::find_if(searchRequest.Filters.begin(), searchRequest.Filters.end(), [&](const PackageMatchFilter& filter) { return filter.Field == matchField; })) { @@ -105,7 +105,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1 for (auto const& field : m_information.UnsupportedPackageMatchFields) { - PackageMatchField matchField = StringToPackageMatchField(field); + PackageMatchField matchField = ConvertStringToPackageMatchField(field); if (matchField == PackageMatchField::Unknown) { @@ -116,8 +116,11 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1 { AICLI_LOG(Repo, Info, << "Search request Inclusions contains package match field not supported by the rest source. Ignoring the field. Unsupported package match field: " << field); - auto itr = std::find_if(resultSearchRequest.Inclusions.begin(), resultSearchRequest.Inclusions.end(), [&](const PackageMatchFilter& inclusion) { return inclusion.Field == matchField; }); - resultSearchRequest.Inclusions.erase(itr); + resultSearchRequest.Inclusions.erase( + std::remove_if( + resultSearchRequest.Inclusions.begin(), resultSearchRequest.Inclusions.end(), + [&](const PackageMatchFilter& inclusion) { return inclusion.Field == matchField; }), + resultSearchRequest.Inclusions.end()); } if (searchRequest.Filters.end() != std::find_if(searchRequest.Filters.begin(), searchRequest.Filters.end(), [&](const PackageMatchFilter& filter) { return filter.Field == matchField; })) @@ -169,4 +172,48 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1 return result; } + + PackageMatchField Interface::ConvertStringToPackageMatchField(std::string_view field) const + { + std::string toLower = Utility::ToLower(field); + + if (toLower == "command") + { + return PackageMatchField::Command; + } + else if (toLower == "packageidentifier") + { + return PackageMatchField::Id; + } + else if (toLower == "moniker") + { + return PackageMatchField::Moniker; + } + else if (toLower == "packagename") + { + return PackageMatchField::Name; + } + else if (toLower == "tag") + { + return PackageMatchField::Tag; + } + else if (toLower == "packagefamilyname") + { + return PackageMatchField::PackageFamilyName; + } + else if (toLower == "productcode") + { + return PackageMatchField::ProductCode; + } + else if (toLower == "normalizedpackagenameandpublisher") + { + return PackageMatchField::NormalizedNameAndPublisher; + } + else if (toLower == "market") + { + return PackageMatchField::Market; + } + + return PackageMatchField::Unknown; + } }