kopia lustrzana https://gitlab.com/tomaszg/geostat
				
				
				
			Simplify a bit conditions in json checks
							rodzic
							
								
									0fbdd6e3e9
								
							
						
					
					
						commit
						6e6330975f
					
				
							
								
								
									
										34
									
								
								ocdb.cpp
								
								
								
								
							
							
						
						
									
										34
									
								
								ocdb.cpp
								
								
								
								
							|  | @ -110,25 +110,25 @@ bool OCdb::update(const Okapi& oc) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool OCdb::parse_item(const json& j) { | bool OCdb::parse_item(const json& j) { | ||||||
| 	if (j.count("object_type") > 0 && j["object_type"] == "geocache") { | 	if (j.count("object_type") && j["object_type"] == "geocache") { | ||||||
| 		if (j.count("change_type") > 0 && j["change_type"] == "replace") { | 		if (j.count("change_type") && j["change_type"] == "replace") { | ||||||
| 			Debug(5) << "Inserting/updating cache " << j["object_key"]["code"].get<std::string>() << ".\n"; | 			Debug(5) << "Inserting/updating cache " << j["object_key"]["code"].get<std::string>() << ".\n"; | ||||||
| 			// if (j["object_key"]["code"] != j["data"]["code"]) {
 | 			// if (j["object_key"]["code"] != j["data"]["code"]) {
 | ||||||
| 			// 	Debug(1) << "Code change " << j["object_key"]["code"] << " -> " << j["data"]["code"] <<'\n';
 | 			// 	Debug(1) << "Code change " << j["object_key"]["code"] << " -> " << j["data"]["code"] <<'\n';
 | ||||||
| 			// }
 | 			// }
 | ||||||
| 			update_cache(j); | 			update_cache(j); | ||||||
| 		} else if (j.count("change_type") > 0 && j["change_type"] == "delete") { | 		} else if (j.count("change_type") && j["change_type"] == "delete") { | ||||||
| 			Debug(2) << "Deleting cache " << j["object_key"]["code"].get<std::string>() << ".\n"; | 			Debug(2) << "Deleting cache " << j["object_key"]["code"].get<std::string>() << ".\n"; | ||||||
| 			std::string sql = "DELETE FROM caches WHERE code='" + j["object_key"]["code"].get<std::string>() + "';"; | 			std::string sql = "DELETE FROM caches WHERE code='" + j["object_key"]["code"].get<std::string>() + "';"; | ||||||
| 			request(sql); | 			request(sql); | ||||||
| 		} else { | 		} else { | ||||||
| 			Debug(1) << "Incorrect change type: " << j["change_type"] << ".\n"; | 			Debug(1) << "Incorrect change type: " << j["change_type"] << ".\n"; | ||||||
| 		} | 		} | ||||||
| 	} else if (j.count("object_type") > 0 && j["object_type"] == "log") { | 	} else if (j.count("object_type") && j["object_type"] == "log") { | ||||||
| 		if (j["change_type"] == "replace") { | 		if (j["change_type"] == "replace") { | ||||||
| 			Debug(3) << "Updating log " << j["object_key"]["uuid"] << ".\n"; | 			Debug(3) << "Updating log " << j["object_key"]["uuid"] << ".\n"; | ||||||
| 			update_log(j); | 			update_log(j); | ||||||
| 		} else if (j.count("change_type") > 0 && j["change_type"] == "delete") { | 		} else if (j.count("change_type") && j["change_type"] == "delete") { | ||||||
| 			Debug(2) << "Deleting log " << j["object_key"]["uuid"] << ".\n"; | 			Debug(2) << "Deleting log " << j["object_key"]["uuid"] << ".\n"; | ||||||
| 			std::string sql = "DELETE FROM logs WHERE uuid='" + j["object_key"]["uuid"].get<std::string>() + "';"; | 			std::string sql = "DELETE FROM logs WHERE uuid='" + j["object_key"]["uuid"].get<std::string>() + "';"; | ||||||
| 			request(sql); | 			request(sql); | ||||||
|  | @ -154,23 +154,23 @@ bool OCdb::update_cache(const json& j) { | ||||||
| 		fields["name"] = j["data"]["names"]["pl"].get<std::string>(); | 		fields["name"] = j["data"]["names"]["pl"].get<std::string>(); | ||||||
| 	else if (j["data"].count("names") && j["data"]["names"].count("en") && !j["data"]["names"]["en"].is_null()) | 	else if (j["data"].count("names") && j["data"]["names"].count("en") && !j["data"]["names"]["en"].is_null()) | ||||||
| 		fields["name"] = j["data"]["names"]["en"].get<std::string>(); | 		fields["name"] = j["data"]["names"]["en"].get<std::string>(); | ||||||
| 	if (j["data"].count("location") > 0 && !j["data"]["location"].is_null()) | 	if (j["data"].count("location") && !j["data"]["location"].is_null()) | ||||||
| 		fields["location"] = j["data"]["location"].get<std::string>(); | 		fields["location"] = j["data"]["location"].get<std::string>(); | ||||||
| 	if (j["data"].count("type") > 0 && !j["data"]["type"].is_null()) | 	if (j["data"].count("type") && !j["data"]["type"].is_null()) | ||||||
| 		fields["type"] = j["data"]["type"].get<std::string>(); | 		fields["type"] = j["data"]["type"].get<std::string>(); | ||||||
| 	if (j["data"].count("status") > 0 && !j["data"]["status"].is_null()) | 	if (j["data"].count("status") && !j["data"]["status"].is_null()) | ||||||
| 		fields["status"] = j["data"]["status"].get<std::string>(); | 		fields["status"] = j["data"]["status"].get<std::string>(); | ||||||
| 	if (j["data"].count("size2") > 0 && !j["data"]["size2"].is_null()) | 	if (j["data"].count("size2") && !j["data"]["size2"].is_null()) | ||||||
| 		fields["size"] = j["data"]["size2"].get<std::string>(); | 		fields["size"] = j["data"]["size2"].get<std::string>(); | ||||||
| 	if (j["data"].count("difficulty") > 0 && !j["data"]["difficulty"].is_null()) | 	if (j["data"].count("difficulty") && !j["data"]["difficulty"].is_null()) | ||||||
| 		fields2["difficulty"] = 2*j["data"]["difficulty"].get<float>(); | 		fields2["difficulty"] = 2*j["data"]["difficulty"].get<float>(); | ||||||
| 	if (j["data"].count("terrain") > 0 && !j["data"]["terrain"].is_null()) | 	if (j["data"].count("terrain") && !j["data"]["terrain"].is_null()) | ||||||
| 		fields2["terrain"] = 2*j["data"]["terrain"].get<float>(); | 		fields2["terrain"] = 2*j["data"]["terrain"].get<float>(); | ||||||
| 	if (j["data"].count("country") > 0 && !j["data"]["country"].is_null()) | 	if (j["data"].count("country") && !j["data"]["country"].is_null()) | ||||||
| 		fields["country"] = j["data"]["country"].get<std::string>(); | 		fields["country"] = j["data"]["country"].get<std::string>(); | ||||||
| 	if (j["data"].count("region") > 0 && !j["data"]["region"].is_null()) | 	if (j["data"].count("region") && !j["data"]["region"].is_null()) | ||||||
| 		fields["region"] = j["data"]["region"].get<std::string>(); | 		fields["region"] = j["data"]["region"].get<std::string>(); | ||||||
| 	else if (j["data"].count("state") > 0 && !j["data"]["state"].is_null()) | 	else if (j["data"].count("state") && !j["data"]["state"].is_null()) | ||||||
| 		fields["region"] = j["data"]["state"].get<std::string>(); | 		fields["region"] = j["data"]["state"].get<std::string>(); | ||||||
| 	if (j["data"].count("owner") && j["data"]["owner"].count("uuid") && !j["data"]["owner"]["uuid"].is_null()) | 	if (j["data"].count("owner") && j["data"]["owner"].count("uuid") && !j["data"]["owner"]["uuid"].is_null()) | ||||||
| 		fields["owner"] = j["data"]["owner"]["uuid"].get<std::string>(); | 		fields["owner"] = j["data"]["owner"]["uuid"].get<std::string>(); | ||||||
|  | @ -230,13 +230,13 @@ bool OCdb::update_log(const json& j) { | ||||||
| 	if (!j.count("object_key") || !j["object_key"].count("uuid") || !j.count("data")) return 0; | 	if (!j.count("object_key") || !j["object_key"].count("uuid") || !j.count("data")) return 0; | ||||||
| 
 | 
 | ||||||
| 	std::string uuid = j["object_key"]["uuid"].get<std::string>(); | 	std::string uuid = j["object_key"]["uuid"].get<std::string>(); | ||||||
| 	if (j["data"].count("cache_code") > 0 && !j["data"]["cache_code"].is_null()) | 	if (j["data"].count("cache_code") && !j["data"]["cache_code"].is_null()) | ||||||
| 		fields["cache_code"] = j["data"]["cache_code"].get<std::string>(); | 		fields["cache_code"] = j["data"]["cache_code"].get<std::string>(); | ||||||
| 	if (j["data"].count("date") > 0 && !j["data"]["date"].is_null()) | 	if (j["data"].count("date") && !j["data"]["date"].is_null()) | ||||||
| 		fields["date"] = j["data"]["date"].get<std::string>(); | 		fields["date"] = j["data"]["date"].get<std::string>(); | ||||||
| 	if (j["data"].count("user") && j["data"]["user"].count("uuid") && !j["data"]["user"]["uuid"].is_null()) | 	if (j["data"].count("user") && j["data"]["user"].count("uuid") && !j["data"]["user"]["uuid"].is_null()) | ||||||
| 		fields["user"] = j["data"]["user"]["uuid"].get<std::string>(); | 		fields["user"] = j["data"]["user"]["uuid"].get<std::string>(); | ||||||
| 	if (j["data"].count("type") > 0 && !j["data"]["type"].is_null()) { | 	if (j["data"].count("type") && !j["data"]["type"].is_null()) { | ||||||
| 		if (j["data"]["type"].get<std::string>() == "Didn't find it") | 		if (j["data"]["type"].get<std::string>() == "Didn't find it") | ||||||
| 			fields2["type"] = 0; | 			fields2["type"] = 0; | ||||||
| 		else if (j["data"]["type"].get<std::string>() == "Found it") | 		else if (j["data"]["type"].get<std::string>() == "Found it") | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Tomasz Golinski
						Tomasz Golinski