Fix: /v1/objects/<type> returns an HTTP error when there are no objects of that type

fixes #10253
This commit is contained in:
Gunnar Beutner 2015-09-30 13:26:19 +02:00
parent 08ccb4e323
commit f3fdcb0f6b

View File

@ -34,15 +34,21 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName)
String uname = pluralName; String uname = pluralName;
boost::algorithm::to_lower(uname); boost::algorithm::to_lower(uname);
BOOST_FOREACH(const ConfigType::Ptr& dtype, ConfigType::GetTypes()) { {
Type::Ptr type = Type::GetByName(dtype->GetName()); Dictionary::Ptr globals = ScriptGlobal::GetGlobals();
ASSERT(type); ObjectLock olock(globals);
BOOST_FOREACH(const Dictionary::Pair& kv, globals) {
if (!kv.second.IsObjectType<Type>())
continue;
String pname = type->GetPluralName(); Type::Ptr type = kv.second;
boost::algorithm::to_lower(pname);
if (uname == pname) String pname = type->GetPluralName();
return type; boost::algorithm::to_lower(pname);
if (uname == pname)
return type;
}
} }
return Type::Ptr(); return Type::Ptr();
@ -51,10 +57,11 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName)
void ConfigObjectTargetProvider::FindTargets(const String& type, const boost::function<void (const Value&)>& addTarget) const void ConfigObjectTargetProvider::FindTargets(const String& type, const boost::function<void (const Value&)>& addTarget) const
{ {
ConfigType::Ptr dtype = ConfigType::GetByName(type); ConfigType::Ptr dtype = ConfigType::GetByName(type);
ASSERT(dtype);
BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) { if (dtype) {
addTarget(object); BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) {
addTarget(object);
}
} }
} }
@ -70,7 +77,12 @@ Value ConfigObjectTargetProvider::GetTargetByName(const String& type, const Stri
bool ConfigObjectTargetProvider::IsValidType(const String& type) const bool ConfigObjectTargetProvider::IsValidType(const String& type) const
{ {
return ConfigType::GetByName(type) != ConfigType::Ptr(); Type::Ptr ptype = Type::GetByName(type);
if (!ptype)
return false;
return ConfigObject::TypeInstance->IsAssignableFrom(ptype);
} }
String ConfigObjectTargetProvider::GetPluralName(const String& type) const String ConfigObjectTargetProvider::GetPluralName(const String& type) const