| 19 | REGISTER_URLHANDLER("/v1/objects", ObjectQueryHandler); |
| 20 | |
| 21 | Dictionary::Ptr ObjectQueryHandler::SerializeObjectAttrs(const Object::Ptr& object, |
| 22 | const String& attrPrefix, const Array::Ptr& attrs, bool isJoin, bool allAttrs) |
| 23 | { |
| 24 | Type::Ptr type = object->GetReflectionType(); |
| 25 | |
| 26 | std::vector<int> fids; |
| 27 | |
| 28 | if (isJoin && attrs) { |
| 29 | ObjectLock olock(attrs); |
| 30 | for (String attr : attrs) { |
| 31 | if (attr == attrPrefix) { |
| 32 | allAttrs = true; |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if (!isJoin && !attrs) |
| 39 | allAttrs = true; |
| 40 | |
| 41 | if (allAttrs) { |
| 42 | for (int fid = 0; fid < type->GetFieldCount(); fid++) { |
| 43 | fids.push_back(fid); |
| 44 | } |
| 45 | } else if (attrs) { |
| 46 | ObjectLock olock(attrs); |
| 47 | for (String attr : attrs) { |
| 48 | String userAttr; |
| 49 | |
| 50 | if (isJoin) { |
| 51 | String::SizeType dpos = attr.FindFirstOf("."); |
| 52 | if (dpos == String::NPos) |
| 53 | continue; |
| 54 | |
| 55 | String userJoinAttr = attr.SubStr(0, dpos); |
| 56 | if (userJoinAttr != attrPrefix) |
| 57 | continue; |
| 58 | |
| 59 | userAttr = attr.SubStr(dpos + 1); |
| 60 | } else |
| 61 | userAttr = attr; |
| 62 | |
| 63 | int fid = type->GetFieldId(userAttr); |
| 64 | |
| 65 | if (fid < 0) |
| 66 | BOOST_THROW_EXCEPTION(ScriptError("Invalid field specified: " + userAttr)); |
| 67 | |
| 68 | fids.push_back(fid); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | DictionaryData resultAttrs; |
| 73 | resultAttrs.reserve(fids.size()); |
| 74 | |
| 75 | for (int fid : fids) { |
| 76 | Field field = type->GetFieldInfo(fid); |
| 77 | |
| 78 | Value val = object->GetField(fid); |
nothing calls this directly
no test coverage detected