	private void ingestSurveyInstance(SurveyInstance instance) {
		SurveyedLocale locale = null;
		if (instance != null) {
			List<QuestionAnswerStore> answers = surveyInstanceDao
					.listQuestionAnswerStore(instance.getKey().getId(), null);
			QuestionAnswerStore geoQ = null;
			SurveyDAO surveyDao = new SurveyDAO();
			Survey survey = surveyDao.getByKey(instance.getSurveyId());
			String pointType = null;
			if (survey != null) {
				pointType = survey.getPointType();
			}
			if (answers != null) {
				for (QuestionAnswerStore q : answers) {
					if (QuestionType.GEO.toString().equals(q.getType())) {
						geoQ = q;
						break;
					}
				}
			}
			if (instance.getSurveyedLocaleId() != null) {
				locale = surveyedLocaleDao.getByKey(instance
						.getSurveyedLocaleId());
			}
			GeoPlace geoPlace = null;
			if (geoQ != null && geoQ.getValue() != null) {
				double lat = UNSET_VAL;
				double lon = UNSET_VAL;
				boolean ambiguousFlag = false;
				String code = null;
				String[] tokens = geoQ.getValue().split("\\|");
				if (tokens.length >= 2) {
					lat = Double.parseDouble(tokens[0]);
					lon = Double.parseDouble(tokens[1]);
					if (tokens.length >= 4) {
						code = tokens[tokens.length - 1];
					}
				}
				if (code == null) {
					Long codeNum = Long
							.parseLong((int) ((Math.abs(lat) * 10000d)) + ""
									+ (int) ((Math.abs(lon) * 10000d)));
					code = Long.toString(codeNum, 36);
				}
				if (lat == UNSET_VAL || lon == UNSET_VAL) {
					throw new RuntimeException(
							"Could not parse lat/lon from Geo Question "
									+ geoQ.getQuestionID());
				} else if (mergeNearby && locale == null) {
					List<SurveyedLocale> candidates = surveyedLocaleDao
							.listLocalesByCoordinates(pointType, lat, lon,
									TOLERANCE);
					if (candidates != null && candidates.size() == 1) {
						locale = candidates.get(0);
					} else if (candidates != null && candidates.size() > 1) {
						log.log(Level.WARNING,
								"Geo based lookup of surveyed locale returned more than one candidate so we are creating a new one");
						ambiguousFlag = true;
					}
				}
				geoPlace = getGeoPlace(lat, lon);
				if (locale == null) {
					locale = new SurveyedLocale();
					locale.setAmbiguous(ambiguousFlag);
					locale.setLatitude(lat);
					locale.setLongitude(lon);
					setGeoData(geoPlace, locale);
					if (survey != null) {
						locale.setLocaleType(survey.getPointType());
					}
					locale.setIdentifier(code);
					if (locale.getOrganization() == null) {
						locale.setOrganization(PropertyUtil
								.getProperty(DEFAULT_ORG_PROP));
					}
					locale = surveyedLocaleDao.save(locale);
				} else {
					if (survey.getPointType() != null
							&& !survey.getPointType().equals(
									locale.getLocaleType())) {
						locale.setLocaleType(survey.getPointType());
					}
				}
			}
			if (instance != null && geoPlace != null) {
				instance.setCountryCode(geoPlace.getCountryCode());
				instance.setSublevel1(geoPlace.getSub1());
				instance.setSublevel2(geoPlace.getSub2());
				instance.setSublevel3(geoPlace.getSub3());
				instance.setSublevel4(geoPlace.getSub4());
				instance.setSublevel5(geoPlace.getSub5());
				instance.setSublevel6(geoPlace.getSub6());
				if (answers != null) {
					List<Metric> metrics = metricDao.listMetrics(
							COMMUNITY_METRIC_NAME, null, null, null, null);
					if (metrics != null) {
						List<SurveyMetricMapping> mappings = new ArrayList<SurveyMetricMapping>();
						for (Metric m : metrics) {
							List<SurveyMetricMapping> temp = metricMappingDao
									.listMetricsBySurveyAndMetric(m.getKey()
											.getId(), instance.getSurveyId());
							if (temp != null) {
								mappings.addAll(temp);
							}
						}
						for (SurveyMetricMapping mapping : mappings) {
							for (QuestionAnswerStore ans : answers) {
								if (ans.getQuestionID().equals(
										mapping.getSurveyQuestionId().toString())) {
									instance.setCommunity(ans.getValue());
									break;
								}
							}
						}
					}
				}
			}
			if (locale != null && locale.getKey() != null && answers != null) {
				locale.setLastSurveyedDate(instance.getCollectionDate());
				locale.setLastSurveyalInstanceId(instance.getKey().getId());
				instance.setSurveyedLocaleId(locale.getKey().getId());
				List<SurveyalValue> values = constructValues(locale, answers);
				if (values != null) {
					surveyedLocaleDao.save(values);
					if (!useConfigStatusScore) {
						boolean found = false;
						for (SurveyalValue val : values) {
							if (isStatus(val.getMetricName())
									&& val.getStringValue() != null) {
								found = true;
								locale.setCurrentStatus(val.getStringValue());
								break;
							}
						}
						if (!found) {
							for (SurveyalValue val : values) {
								if (isStatus(val.getQuestionText())
										&& val.getStringValue() != null) {
									found = true;
									locale.setCurrentStatus(val
											.getStringValue());
									break;
								}
							}
						}
					} else if (useDynamicScoring) {
					} else {
						for (SurveyalValue val : values) {
							if (val.getQuestionText() != null
									&& val.getQuestionText().toLowerCase()
											.contains(statusFragment)) {
								String scoredField = scoredVals.get(val
										.getStringValue());
								if (scoredField == null) {
									scoredField = scoredVals.get(DEFAULT);
								}
								locale.setCurrentStatus(scoredField);
							}
						}
					}
				}
			}
		}
	}

	private void ingestSurveyInstance(SurveyInstance instance) {
		SurveyedLocale locale = null;
		if (instance != null) {
			List<QuestionAnswerStore> answers = surveyInstanceDao
					.listQuestionAnswerStore(instance.getKey().getId(), null);
			QuestionAnswerStore geoQ = null;
			SurveyDAO surveyDao = new SurveyDAO();
			Survey survey = surveyDao.getByKey(instance.getSurveyId());
			String pointType = null;
			if (survey != null) {
				pointType = survey.getPointType();
			}
			if (answers != null) {
				for (QuestionAnswerStore q : answers) {
					if (QuestionType.GEO.toString().equals(q.getType())) {
						geoQ = q;
						break;
					}
				}
			}
			if (instance.getSurveyedLocaleId() != null) {
				locale = surveyedLocaleDao.getByKey(instance
						.getSurveyedLocaleId());
			}
			GeoPlace geoPlace = null;
			if (geoQ != null && geoQ.getValue() != null && geoQ.getValue().length() > 0) {
				double lat = UNSET_VAL;
				double lon = UNSET_VAL;
				boolean ambiguousFlag = false;
				String code = null;
				String[] tokens = geoQ.getValue().split("\\|");
				if (tokens.length >= 2) {
					lat = Double.parseDouble(tokens[0]);
					lon = Double.parseDouble(tokens[1]);
					if (tokens.length >= 4) {
						code = tokens[tokens.length - 1];
					}
				}
				if (code == null) {
					Long codeNum = Long
							.parseLong((int) ((Math.abs(lat) * 10000d)) + ""
									+ (int) ((Math.abs(lon) * 10000d)));
					code = Long.toString(codeNum, 36);
				}
				if (lat == UNSET_VAL || lon == UNSET_VAL) {
					throw new RuntimeException(
							"Could not parse lat/lon from Geo Question "
									+ geoQ.getQuestionID());
				} else if (mergeNearby && locale == null) {
					List<SurveyedLocale> candidates = surveyedLocaleDao
							.listLocalesByCoordinates(pointType, lat, lon,
									TOLERANCE);
					if (candidates != null && candidates.size() == 1) {
						locale = candidates.get(0);
					} else if (candidates != null && candidates.size() > 1) {
						log.log(Level.WARNING,
								"Geo based lookup of surveyed locale returned more than one candidate so we are creating a new one");
						ambiguousFlag = true;
					}
				}
				geoPlace = getGeoPlace(lat, lon);
				if (locale == null) {
					locale = new SurveyedLocale();
					locale.setAmbiguous(ambiguousFlag);
					locale.setLatitude(lat);
					locale.setLongitude(lon);
					setGeoData(geoPlace, locale);
					if (survey != null) {
						locale.setLocaleType(survey.getPointType());
					}
					locale.setIdentifier(code);
					if (locale.getOrganization() == null) {
						locale.setOrganization(PropertyUtil
								.getProperty(DEFAULT_ORG_PROP));
					}
					locale = surveyedLocaleDao.save(locale);
				} else {
					if (survey.getPointType() != null
							&& !survey.getPointType().equals(
									locale.getLocaleType())) {
						locale.setLocaleType(survey.getPointType());
					}
				}
			}
			if (instance != null && geoPlace != null) {
				instance.setCountryCode(geoPlace.getCountryCode());
				instance.setSublevel1(geoPlace.getSub1());
				instance.setSublevel2(geoPlace.getSub2());
				instance.setSublevel3(geoPlace.getSub3());
				instance.setSublevel4(geoPlace.getSub4());
				instance.setSublevel5(geoPlace.getSub5());
				instance.setSublevel6(geoPlace.getSub6());
				if (answers != null) {
					List<Metric> metrics = metricDao.listMetrics(
							COMMUNITY_METRIC_NAME, null, null, null, null);
					if (metrics != null) {
						List<SurveyMetricMapping> mappings = new ArrayList<SurveyMetricMapping>();
						for (Metric m : metrics) {
							List<SurveyMetricMapping> temp = metricMappingDao
									.listMetricsBySurveyAndMetric(m.getKey()
											.getId(), instance.getSurveyId());
							if (temp != null) {
								mappings.addAll(temp);
							}
						}
						for (SurveyMetricMapping mapping : mappings) {
							for (QuestionAnswerStore ans : answers) {
								if (ans.getQuestionID().equals(
										mapping.getSurveyQuestionId().toString())) {
									instance.setCommunity(ans.getValue());
									break;
								}
							}
						}
					}
				}
			}
			if (locale != null && locale.getKey() != null && answers != null) {
				locale.setLastSurveyedDate(instance.getCollectionDate());
				locale.setLastSurveyalInstanceId(instance.getKey().getId());
				instance.setSurveyedLocaleId(locale.getKey().getId());
				List<SurveyalValue> values = constructValues(locale, answers);
				if (values != null) {
					surveyedLocaleDao.save(values);
					if (!useConfigStatusScore) {
						boolean found = false;
						for (SurveyalValue val : values) {
							if (isStatus(val.getMetricName())
									&& val.getStringValue() != null) {
								found = true;
								locale.setCurrentStatus(val.getStringValue());
								break;
							}
						}
						if (!found) {
							for (SurveyalValue val : values) {
								if (isStatus(val.getQuestionText())
										&& val.getStringValue() != null) {
									found = true;
									locale.setCurrentStatus(val
											.getStringValue());
									break;
								}
							}
						}
					} else if (useDynamicScoring) {
					} else {
						for (SurveyalValue val : values) {
							if (val.getQuestionText() != null
									&& val.getQuestionText().toLowerCase()
											.contains(statusFragment)) {
								String scoredField = scoredVals.get(val
										.getStringValue());
								if (scoredField == null) {
									scoredField = scoredVals.get(DEFAULT);
								}
								locale.setCurrentStatus(scoredField);
							}
						}
					}
				}
			}
		}
	}
