bool WriteTagRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString auth_token = result["auth_token"].toString(); QString channel_name = result["channel"].toString(); QString title = result["title"].toString(); QString link = result["link"].toString(); QString description = result["description"].toString(); double altitude = result["altitude"].toDouble(&ok); if (!ok) return false; double longitude = result["longitude"].toDouble(&ok); if (!ok) return false; double latitude = result["latitude"].toDouble(&ok); if (!ok) return false; QDateTime time = QDateTime::fromString(result["time"].toString(), "dd MM yyyy HH:mm:ss.zzz"); Session session(auth_token, QDateTime::currentDateTime(), common::BasicUser()); Channel channel(channel_name, "unknown"); Tag tag(altitude, latitude, longitude, title, description, link, time); tag.setChannel(channel); //tag.setSession(session); m_channels.push_back(channel); m_token = auth_token; m_tags.push_back(tag); return true; }
bool GetBlobResponseJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse (data, &ok).toMap (); if (!ok) return false; /*result["errno"].toInt(&ok); if (!ok) return false;*/ int errno = result["errno"].toInt(); QString blob = result["blob"].toString (); /*if (blob.isEmpty()) { DEBUG() << "Some of the string fields are empty." << data; return false; }*/ m_errno = errno; m_blob = blob; return true; }
bool WriteTagRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString auth_token = result["auth_token"].toString(); QString channel_name = result["channel"].toString(); QString title = result["title"].toString(); QString link = result["link"].toString(); QString description = result["description"].toString(); double altitude = result["altitude"].toDouble(&ok); if (!ok) return false; double longitude = result["longitude"].toDouble(&ok); if (!ok) return false; double latitude = result["latitude"].toDouble(&ok); if (!ok) return false; QDateTime time = QDateTime::fromString(result["time"].toString(), "dd MM yyyy HH:mm:ss.zzz"); QSharedPointer<Session> session(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))); QSharedPointer<Channel> channel(new JsonChannel(channel_name, "unknown")); QSharedPointer<DataMark> tag(new JsonDataMark(altitude, latitude, longitude, title, description, link, time)); //tag->setChannel(channel); //tag->setSession(session); m_channelsContainer->push_back(channel); m_sessionsContainer->push_back(session); m_tagsContainer->push_back(tag); return true; }
bool FilterPolygonRequestJSON::parseJson(const QByteArray&data) { clearContainers(); FilterRequestJSON::parseJson(data); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString auth_token = result["auth_token"].toString(); setTimeFrom(QDateTime::fromString(result["time_from"].toString(), "dd MM yyyy HH:mm:ss.zzz")); setTimeTo(QDateTime::fromString(result["time_to"].toString(), "dd MM yyyy HH:mm:ss.zzz")); FShapePolygon * shape = new FShapePolygon(); QVariantList polygon = result["polygon"].toList(); for (int i = 0; i < polygon.size(); i++) { QVariantMap p = polygon.at(i).toMap(); int number = p["number"].toInt(&ok); if (!ok) return false; double lat = p["latitude"].toDouble(&ok); if (!ok) return false; double lon = p["longitude"].toDouble(&ok); if (!ok) return false; shape->addPoint(number, lat, lon); } setShape(QSharedPointer<FShape>(shape)); m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)))); return true; }
bool FilterSubstringRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if(!ok) return false; QString field = result["field"].toString(); QString substring = result["substring"].toString(); QString auth_token = result["auth_token"].toString(); qulonglong tagNumber = result["tag_number"].toULongLong(&ok); if (ok) m_tagNumber = tagNumber; if ( !Tag::isFieldNameValid(field) || substring.isEmpty() || auth_token.isEmpty()) return false; setField(field); setSubstring(substring); setSessionToken(auth_token); return true; }
bool FilterRectangleRequestJSON::parseJson(const QByteArray&data) { clearContainers(); FilterRequestJSON::parseJson(data); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString auth_token = result["auth_token"].toString(); setTimeFrom(QDateTime::fromString(result["time_from"].toString(), "dd MM yyyy HH:mm:ss.zzz")); setTimeTo(QDateTime::fromString(result["time_to"].toString(), "dd MM yyyy HH:mm:ss.zzz")); double lat1, lat2, lon1, lon2; QVariantMap latData = result["latitude_shift"].toMap(); lat1 = latData["latitude1"].toDouble(&ok); if (!ok) return false; lat2 = latData["latitude2"].toDouble(&ok); if (!ok) return false; QVariantMap lonData = result["longitude_shift"].toMap(); lon1 = lonData["longitude1"].toDouble(&ok); if (!ok) return false; lon2 = lonData["longitude2"].toDouble(&ok); if (!ok) return false; syslog(LOG_INFO, "rect %f ,%f ,%f ,%f ", lat1, lat2, lon2, lon2); FShapeRectangle * shape = new FShapeRectangle(lat1, lon1, lat2, lon2); setShape(QSharedPointer<FShape>(shape)); m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)))); return true; }
bool LoadTagsResponseJSON::parseJson(const QByteArray &data) { clearContainers(); qDebug () << "LoadTagsResponseJSON::parseJson(const QByteArray &data)"; QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; result["errno"].toInt(&ok); if (!ok) return false; m_errno = result["errno"].toInt(&ok); QVariantMap rss = result["rss"].toMap(); QVariantMap channelVariant = rss["channels"].toMap(); QVariantList channelsList = channelVariant["items"].toList(); int size = channelsList.size(); for (int i = 0; i < size; i++) { QVariantMap channelDesc = channelsList.at(i).toMap(); QVariantList markList = channelDesc["items"].toList(); QString channelName = channelDesc["name"].toString(); Channel channel(channelName,"dummy channel[LoadTagsResponse]"); for(int j=0; j<markList.size(); j++) { QVariantMap markMap = markList.at(j).toMap(); QString title = markMap["title"].toString(); QString link = markMap["link"].toString(); QString description = markMap["description"].toString(); double altitude = markMap["altitude"].toString().toDouble(&ok); if (!ok) return false; double latitude = markMap["latitude"].toString().toDouble(&ok); if (!ok) return false; double longitude = markMap["longitude"].toString().toDouble(&ok); if (!ok) return false; QString userName = markMap["user"].toString(); QString timeStr = markMap["pubDate"].toString(); QDateTime time = QDateTime::fromString(timeStr, "dd MM yyyy HH:mm:ss.zzz"); m_users.push_back(common::BasicUser(userName)); Tag tag(altitude, latitude, longitude, title, description, link, time); DEBUG() << "Tag:" << tag; qDebug () << "LoadTagsResponseJSON::parseJson(const QByteArray &data)"; m_tags << tag; } } return true; }
bool RestorePasswordRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString email = result["email"].toString(); m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("unknown", "unknown", email))); return true; }
bool VersionResponseJSON::parseJson(const QByteArray& data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) { return false ; } m_errno = result["errno"].toInt(); m_version = result["version"].toString(); return true; }
bool DefaultResponseJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; result["errno"].toInt(&ok); if (!ok) return false; m_errno = result["errno"].toInt(); return true; }
bool AddUserRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString email = result["email"].toString(); QString login = result["login"].toString(); QString password = result["password"].toString(); m_users.push_back(common::BasicUser(login, password, email)); return true; }
void LoginRequestJSON::parseJson(const QByteArray&data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) { qFatal("An error occured during parsing json with channel list"); } QString login = result["login"].toString(); QString password = result["password"].toString(); m_usersContainer->push_back(QSharedPointer<User>(new JsonUser(login,password))); }
bool FilterChannelRequestJSON::parseJson(const QByteArray&data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString auth_token = result["auth_token"].toString(); m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)))); m_channel = result["channel"].toString(); m_amount = result["amount"].toInt(&ok); return ok; }
bool SubscribedChannelsRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString auth_token = result["auth_token"].toString(); Session session(auth_token); m_token = auth_token; return true; }
bool FilterChannelRequestJSON::parseJson(const QByteArray&data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString auth_token = result["auth_token"].toString(); if (auth_token.isEmpty()) return false; m_token = auth_token; m_channel = result["channel"].toString(); m_amount = result["amount"].toUInt(&ok); return ok; }
bool SetDbRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if(!ok) return false; QString dbName = result["db_name"].toString(); QString auth_token = result["auth_token"].toString(); if (dbName.isEmpty() || auth_token.isEmpty()) return false; m_dbName = dbName; m_token = auth_token; return true; }
void SetDefaultTimeSlotMarkRequestJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) { qFatal("An error occured during parsing json with channel list"); return; } QString token = result["auth_token"].toString(); qlonglong markId = result["mark_id"].toLongLong(); m_usersContainer->push_back(QSharedPointer<User>(new JsonUser("unknown","unknown", token))); JsonDataMark* jsonMark = new JsonDataMark(0,0,"unknown", "unknown", "unknown", QDateTime()); jsonMark->setId(markId); m_tagsContainer->push_back(QSharedPointer<DataMark> (jsonMark)); }
bool ChangePasswordRequestJSON::parseJson(const QByteArray& data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; QString newPassword = result["new_password"].toString(); QString password = result["password"].toString(); QString login = result["login"].toString(); if (login.isEmpty() || password.isEmpty() || newPassword.isEmpty()) { return false; } m_newPassword = newPassword; m_users.push_back(common::BasicUser(login,password)); return true; }
bool WriteTagResponseJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; result["errno"].toInt(&ok); if (!ok) return false; m_errno = result["errno"].toInt(); qlonglong markId = result["mark_id"].toLongLong(&ok); if (!ok) return false; JsonDataMark* jsonMark = new JsonDataMark(0,0,0,"unknown", "unknown", "unknown", QDateTime()); jsonMark->setId(markId); QSharedPointer<DataMark> mark(jsonMark); m_tagsContainer->push_back(mark); return true; }
bool AvailableChannelsResponseJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) { return false ; } m_errno = result["errno"].toInt(); QVariantList channels = result["channels"].toList(); int size = channels.size(); for (int i = 0; i < size; i++) { QVariantMap channelVariant = channels.at(i).toMap(); QString name = channelVariant["name"].toString(); QString description = channelVariant["description"].toString(); QString url = channelVariant["url"].toString(); QSharedPointer<Channel> channel(new JsonChannel(name, description, url)); m_channelsContainer->push_back(channel); } return true; }
void ChannelListResponseJSON::parseJson(const QByteArray &data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) { qFatal("An error occured during parsing json with channel list"); return; } QVariantList channels = result["channels"].toList(); int size = channels.size(); for (int i = 0; i < size; i++) { QVariantMap channelVariant = channels.at(i).toMap(); QString name = channelVariant["name"].toString(); QString description = channelVariant["description"].toString(); QSharedPointer<Channel> channel(new JsonChannel(name, description)); m_channelsContainer->push_back(channel); } }
bool WriteTagRequestJSON::parseJson(const QByteArray &data) { DEBUG() << "Parsing tag: " << data; clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok){ DEBUG() << "General parsing error - invalid json." << data; return false; } QString auth_token = result["auth_token"].toString(); QString channel_name = result["channel"].toString(); QString title = result["title"].toString(); QString link = result["link"].toString(); QString description = result["description"].toString(); if (auth_token.isEmpty() || channel_name.isEmpty() || title.isEmpty() || link.isEmpty() || description.isEmpty()) { DEBUG() << "Some of the string fields are empty." << data; return false; } double altitude = result["altitude"].toDouble(&ok); if (!ok) { DEBUG() << "Altitude parsing error." << data; return false; } double longitude = result["longitude"].toDouble(&ok); if (!ok){ DEBUG() << "Longitude parsing error." << data; return false; } double latitude = result["latitude"].toDouble(&ok); if (!ok){ DEBUG() << "Latitude parsing error." << data; return false; } QDateTime time = QDateTime::fromString(result["time"].toString(), "dd MM yyyy HH:mm:ss.zzz"); if (!time.isValid()){ DEBUG() << "Time parsing error." << data; return false; } Session session(auth_token, QDateTime::currentDateTime(), common::BasicUser()); Channel channel(channel_name, "unknown"); Tag tag(altitude, latitude, longitude, title, description, link, time); tag.setChannel(channel); //tag.setSession(session); m_channels.push_back(channel); m_token = auth_token; m_tags.push_back(tag); return true; }
bool FilterDefaultResponseJSON::parseJson(const QByteArray& data) { clearContainers(); QJson::Parser parser; bool ok; QVariantMap result = parser.parse(data, &ok).toMap(); if (!ok) return false; result["errno"].toInt(&ok); if (!ok) return false; m_errno = result["errno"].toInt(&ok); //QVariantMap channelVariant = result["channels"].toMap(); QVariantList channelsList = result["channels"].toList(); int size = channelsList.size(); for (int i = 0; i < size; i++) { QVariantMap channelDesc = channelsList.at(i).toMap(); QVariantMap channelInternal = channelDesc["channel"].toMap(); QVariantList markList = channelInternal["items"].toList(); QString channelName = channelInternal["name"].toString(); QSharedPointer<Channel> channel(new JsonChannel(channelName,"dummy channel[LoadTagsResponse]")); for(int j=0; j<markList.size(); j++) { QVariantMap markMap = markList.at(j).toMap(); int id = markMap["id"].toInt(); QString title = markMap["title"].toString(); QString link = markMap["link"].toString(); QString description = markMap["description"].toString(); double altitude = markMap["altitude"].toString().toDouble(&ok); if (!ok) return false; double latitude = markMap["latitude"].toString().toDouble(&ok); if (!ok) return false; double longitude = markMap["longitude"].toString().toDouble(&ok); if (!ok) return false; QString userName = markMap["user"].toString(); QString timeStr = markMap["pubDate"].toString(); QDateTime time = QDateTime::fromString(timeStr, "dd MM yyyy HH:mm:ss.zzz"); time.setTimeSpec(Qt::UTC); QVector<QSharedPointer<common::User> > v = m_usersContainer->vector(); QSharedPointer<common::User> user(new JsonUser(userName)); m_usersContainer->push_back(user); QSharedPointer<JsonDataMark> newMark(new JsonDataMark(altitude, latitude, longitude, title, description, link, time)); newMark->setId(id); newMark->setUser(user); m_hashMap.insert(channel, newMark); } } return true; }