<commit_before>package org.waterforpeople.mapping.app.gwt.server.accesspoint;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.waterforpeople.mapping.analytics.dao.AccessPointStatusSummaryDao;
import org.waterforpeople.mapping.analytics.domain.AccessPointStatusSummary;
import org.waterforpeople.mapping.app.gwt.client.accesspoint.AccessPointSummaryDto;
import org.waterforpeople.mapping.app.gwt.client.accesspoint.AccessPointSummaryService;

import com.gallatinsystems.device.app.web.DeviceManagerServlet;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * This service is responsible for returning access point summarization objects.
 * The fields within the summary DTO may be partially populated based on the
 * type of summarization being returned.
 * 
 * @author <NAME>
 * 
 */
public class AccessPointSummaryServiceImpl extends RemoteServiceServlet
		implements AccessPointSummaryService {

	private static final long serialVersionUID = -5722103696712574220L;
	@SuppressWarnings("unused")
	private static final Logger log = Logger
			.getLogger(DeviceManagerServlet.class.getName());

	/**
	 * returns an array of AccessPointSummaryDto objects that match the criteria
	 * passed in. The summary objects will have the status and count populated.
	 */
	public AccessPointSummaryDto[] listAccessPointStatusSummary(String country,
			String community, String type, String year, String status) {
		AccessPointStatusSummaryDao summaryDao = new AccessPointStatusSummaryDao();
		List<AccessPointStatusSummary> summaries = summaryDao
				.listByLocationAndYear(country, community, type, year, status);
		AccessPointSummaryDto[] dtoList = null;

		if (summaries != null) {
			Map<String, Long> countMap = new HashMap<String, Long>();
			if (status == null) {
				// if we're not selecting by status, collapse based on it
				for (int i = 0; i < summaries.size(); i++) {
					Long curVal = countMap.get(summaries.get(i).getStatus()
							.toString());
					if (curVal == null) {
						curVal = summaries.get(i).getCount() != null ? summaries
								.get(i).getCount()
								: new Long(1);
					} else {
						curVal = curVal
								+ (summaries.get(i).getCount() != null ? summaries
										.get(i).getCount()
										: new Long(1));
					}
					countMap.put(summaries.get(i).getStatus().toString(),
							curVal);
				}
			} else {
				// if we're selecting by status, collapse based on Country
				for (int i = 0; i < summaries.size(); i++) {
					Long curVal = countMap.get(summaries.get(i).getCountry());
					if (curVal == null) {
						curVal = summaries.get(i).getCount();
					} else {
						curVal = curVal + summaries.get(i).getCount();
					}
					countMap.put(summaries.get(i).getCountry(), curVal);
				}
			}
			dtoList = new AccessPointSummaryDto[countMap.keySet().size()];
			int i = 0;
			for (String key : countMap.keySet()) {
				AccessPointSummaryDto dto = new AccessPointSummaryDto();<commit_msg>fixed NPE in the event of less than complete access point objects<commit_after>package org.waterforpeople.mapping.app.gwt.server.accesspoint;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.waterforpeople.mapping.analytics.dao.AccessPointStatusSummaryDao;
import org.waterforpeople.mapping.analytics.domain.AccessPointStatusSummary;
import org.waterforpeople.mapping.app.gwt.client.accesspoint.AccessPointSummaryDto;
import org.waterforpeople.mapping.app.gwt.client.accesspoint.AccessPointSummaryService;

import com.gallatinsystems.device.app.web.DeviceManagerServlet;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * This service is responsible for returning access point summarization objects.
 * The fields within the summary DTO may be partially populated based on the
 * type of summarization being returned.
 * 
 * @author <NAME>
 * 
 */
public class AccessPointSummaryServiceImpl extends RemoteServiceServlet
		implements AccessPointSummaryService {

	private static final long serialVersionUID = -5722103696712574220L;
	@SuppressWarnings("unused")
	private static final Logger log = Logger
			.getLogger(DeviceManagerServlet.class.getName());

	/**
	 * returns an array of AccessPointSummaryDto objects that match the criteria
	 * passed in. The summary objects will have the status and count populated.
	 */
	public AccessPointSummaryDto[] listAccessPointStatusSummary(String country,
			String community, String type, String year, String status) {
		AccessPointStatusSummaryDao summaryDao = new AccessPointStatusSummaryDao();
		List<AccessPointStatusSummary> summaries = summaryDao
				.listByLocationAndYear(country, community, type, year, status);
		AccessPointSummaryDto[] dtoList = null;

		if (summaries != null) {
			Map<String, Long> countMap = new HashMap<String, Long>();
			if (status == null) {
				// if we're not selecting by status, collapse based on it
				for (int i = 0; i < summaries.size(); i++) {
					if (summaries.get(i).getStatus() != null) {
						Long curVal = countMap.get(summaries.get(i).getStatus()
								.toString());
						if (curVal == null) {
							curVal = summaries.get(i).getCount() != null ? summaries
									.get(i).getCount()
									: new Long(1);
						} else {
							curVal = curVal
									+ (summaries.get(i).getCount() != null ? summaries
											.get(i).getCount()
											: new Long(1));
						}
						countMap.put(summaries.get(i).getStatus().toString(),
								curVal);
					}
				}
			} else {
				// if we're selecting by status, collapse based on Country
				for (int i = 0; i < summaries.size(); i++) {
					if (summaries.get(i).getCountry() != null) {
						Long curVal = countMap.get(summaries.get(i)
								.getCountry());
						if (curVal == null) {
							curVal = summaries.get(i).getCount();
						} else {
							curVal = curVal + summaries.get(i).getCount();
						}
						countMap.put(summaries.get(i).getCountry(), curVal);
					}
				}
			}
			dtoList = new AccessPointSummaryDto[countMap.keySet().size()];
			int i = 0;
			for (String key : countMap.keySet()) {
				AccessPointSummaryDto dto = new AccessPointSummaryDto();
{'fraction_non_alphanumeric': 0.11366929640959587, 'fraction_numerical': 0.0077282241184994365, 'mean_word_length': 3.771121351766513, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '381749', 'n_tokens_mistral': 2226, 'n_tokens_neox': 1847, 'n_words': 459}