Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect processing of PackageMatchFields in rest client #1659

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ nonexistentsetting
NONINFRINGEMENT
norestart
normalizednameandpublisher
normalizedpackagenameandpublisher
NOTHROW
NOTIMPL
NOTNULL
Expand All @@ -352,6 +353,8 @@ OUTOFDISKSPACE
OUTOFMEMORY
OWC
packagefamilyname
packageidentifier
packagename
PACKAGESSCHEMA
Params
params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<web::json::value> requestMatchJson = GetRequestMatchJsonObject(requestMatch);
std::optional<web::json::value> requestMatchJson = GetRequestMatchJsonObject(packageMatchFilter);

if (!requestMatchJson)
{
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1
SearchResult GetSearchResult(const web::json::value& searchResponseObject) const override;
std::vector<Manifest::Manifest> GetParsedManifests(const web::json::value& manifestsResponseObject) const override;

PackageMatchField ConvertStringToPackageMatchField(std::string_view field) const;

private:
IRestClient::Information m_information;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }))
{
Expand All @@ -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)
{
Expand All @@ -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; }))
Expand Down Expand Up @@ -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;
}
}