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

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;

import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardContainerDto;
import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardScoreBucketDto;
import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardScoringDto;
import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardScoringManagerService;
import org.waterforpeople.mapping.app.util.DtoMarshaller;
import org.waterforpeople.mapping.domain.AccessPoint.AccessPointType;
import org.waterforpeople.mapping.domain.AccessPoint.LocationType;

import com.gallatinsystems.common.util.ClassAttributeUtil;
import com.gallatinsystems.common.util.StringUtil;
import com.gallatinsystems.framework.dao.BaseDAO;
import com.gallatinsystems.framework.gwt.dto.client.ResponseDto;
import com.gallatinsystems.standards.dao.DistanceStandardDao;
import com.gallatinsystems.standards.dao.StandardDao;
import com.gallatinsystems.standards.dao.StandardScoringDao;
import com.gallatinsystems.standards.domain.DistanceStandard;
import com.gallatinsystems.standards.domain.Standard;
import com.gallatinsystems.standards.domain.Standard.StandardScope;
import com.gallatinsystems.standards.domain.Standard.StandardType;
import com.gallatinsystems.standards.domain.Standard.StandardValueType;
import com.gallatinsystems.standards.domain.StandardScoreBucket;
import com.gallatinsystems.standards.domain.StandardScoring;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class StandardScoringServiceImpl extends RemoteServiceServlet implements
		StandardScoringManagerService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6828550495789554024L;

	@Override
	public ResponseDto<ArrayList<StandardScoringDto>> listStandardScoring(
			Long scoreBucketId, String cursorString) {
		// StandardScoringDao ssDao = new StandardScoringDao();
		// List<StandardScoring> ssList = null;
		// if (scoreBucketId != null) {
		// ssList = ssDao.listStandardScoring(scoreBucketId);
		// } else {
		// ssList = ssDao.list(cursorString);
		// }
		ArrayList<StandardScoringDto> ssDtoList = new ArrayList<StandardScoringDto>();
		// for (StandardScoring item : ssList) {
		// StandardScoringDto dto = new StandardScoringDto();
		// DtoMarshaller.copyToDto(item, dto);
		// ssDtoList.add(dto);
		// }
		StandardDao standardDao = new StandardDao();
		DistanceStandardDao distanceStandardDao = new DistanceStandardDao();
		
		StandardType standardType = null;
		if (scoreBucketId == 0) {
			standardType = StandardType.WaterPointLevelOfService;
		} else {
			standardType = StandardType.WaterPointSustainability;
		}
		List<Standard> sList = standardDao
				.listByAccessPointTypeAndStandardType(
						AccessPointType.WATER_POINT, standardType);
		List<DistanceStandard> distanceList = distanceStandardDao.listDistanceStandard(StandardType.WaterPointLevelOfService,null);
		for(DistanceStandard dsItem : distanceList){
			StandardScoringDto dtoDist = new StandardScoringDto();
			dtoDist.setGlobalStandard(false);
			dtoDist.setCountryCode(dsItem.getCountryCode());
			dtoDist.setDisplayName(dsItem.getLocationType().toString());
			dtoDist.addPositiveCriteria(dsItem.getMaxDistance().toString());
			dtoDist.setPositiveOperator("<");
			dtoDist.setCriteriaType("Distance");
			dtoDist.setPointType("WaterPoint");
			dtoDist.setKeyId(dsItem.getKey().getId());
			dtoDist.setEffectiveStartDate(dsItem.getEffectiveStartDate());
			dtoDist.setEffectiveEndDate(dsItem.getEffectiveEndDate());
			ssDtoList.add(dtoDist);
		}
		for (Standard item : sList) {
			StandardScoringDto dto = new StandardScoringDto();
			dto.setCountryCode(item.getCountry());
			dto.setDisplayName(item.getStandardDescription());
			dto.setEvaluateField(item.getAccessPointAttribute());
			if (item.getCountry()==null)
				dto.setGlobalStandard(true);
			else
				dto.setGlobalStandard(false);
			dto.setKeyId(item.getKey().getId());
			if (item.getStandardComparison().equals(
					Standard.StandardComparisons.equal)) {
				dto.setPositiveOperator("==");
			} else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.greaterthan)) {
				dto.setPositiveOperator(">");
			}else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.lessthan)) {
				dto.setPositiveOperator("<");
			}else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.greaterthanorequal)) {
				dto.setPositiveOperator(">=");
			}else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.lessthanorequal)) {
				dto.setPositiveOperator("<=");
			}else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.notequal)) {
				dto.setPositiveOperator("!=");
			}
			dto.setMapToObject("AccessPoint");
			dto.setPositiveCriteria(item.getPositiveValues());
			dto.setPositiveScore(1);
			dto.setPointType("WaterPoint");
			
			if(item.getAcessPointAttributeType().equals(StandardValueType.Boolean)){
				dto.setCriteriaType("Boolean");
			}else if (item.getAcessPointAttributeType().equals(StandardValueType.Number)){
				dto.setCriteriaType("Number");
			}else if(item.getAccessPointType().equals(StandardValueType.String)){
				dto.setCriteriaType("String");
			}
			dto.setEffectiveEndDate(item.getEffectiveEndDate());
			dto.setEffectiveStartDate(item.getEffectiveStartDate());
			ssDtoList.add(dto);
		}
		
		ResponseDto<ArrayList<StandardScoringDto>> response = new ResponseDto<ArrayList<StandardScoringDto>>();
		response.setCursorString(StandardScoringDao.getCursor(sList));
		response.setPayload(ssDtoList);
		return response;
	}

	@Override
	public StandardScoringDto save(StandardScoringDto item) {
		StandardScoringDao ssDao = new StandardScoringDao();
		StandardScoring canonical = new StandardScoring();
		DtoMarshaller.copyToCanonical(canonical, item);
		ssDao.save(canonical);
		DtoMarshaller.copyToDto(canonical, item);
		return item;
	}

	@Override
	public void delete(Long id) {
		StandardScoringDao ssDao = new StandardScoringDao();
		ssDao.delete(ssDao.getByKey(id));<commit_msg>fixed serialization issue with arraylist<commit_after>package org.waterforpeople.mapping.app.gwt.server.standardscoring;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;

import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardContainerDto;
import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardScoreBucketDto;
import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardScoringDto;
import org.waterforpeople.mapping.app.gwt.client.standardscoring.StandardScoringManagerService;
import org.waterforpeople.mapping.app.util.DtoMarshaller;
import org.waterforpeople.mapping.domain.AccessPoint.AccessPointType;
import org.waterforpeople.mapping.domain.AccessPoint.LocationType;

import com.gallatinsystems.common.util.ClassAttributeUtil;
import com.gallatinsystems.common.util.StringUtil;
import com.gallatinsystems.framework.dao.BaseDAO;
import com.gallatinsystems.framework.gwt.dto.client.ResponseDto;
import com.gallatinsystems.standards.dao.DistanceStandardDao;
import com.gallatinsystems.standards.dao.StandardDao;
import com.gallatinsystems.standards.dao.StandardScoringDao;
import com.gallatinsystems.standards.domain.DistanceStandard;
import com.gallatinsystems.standards.domain.Standard;
import com.gallatinsystems.standards.domain.Standard.StandardScope;
import com.gallatinsystems.standards.domain.Standard.StandardType;
import com.gallatinsystems.standards.domain.Standard.StandardValueType;
import com.gallatinsystems.standards.domain.StandardScoreBucket;
import com.gallatinsystems.standards.domain.StandardScoring;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class StandardScoringServiceImpl extends RemoteServiceServlet implements
		StandardScoringManagerService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6828550495789554024L;

	@Override
	public ResponseDto<ArrayList<StandardScoringDto>> listStandardScoring(
			Long scoreBucketId, String cursorString) {
		// StandardScoringDao ssDao = new StandardScoringDao();
		// List<StandardScoring> ssList = null;
		// if (scoreBucketId != null) {
		// ssList = ssDao.listStandardScoring(scoreBucketId);
		// } else {
		// ssList = ssDao.list(cursorString);
		// }
		ArrayList<StandardScoringDto> ssDtoList = new ArrayList<StandardScoringDto>();
		// for (StandardScoring item : ssList) {
		// StandardScoringDto dto = new StandardScoringDto();
		// DtoMarshaller.copyToDto(item, dto);
		// ssDtoList.add(dto);
		// }
		StandardDao standardDao = new StandardDao();
		DistanceStandardDao distanceStandardDao = new DistanceStandardDao();

		StandardType standardType = null;
		if (scoreBucketId == 0) {
			standardType = StandardType.WaterPointLevelOfService;
		} else {
			standardType = StandardType.WaterPointSustainability;
		}
		List<Standard> sList = standardDao
				.listByAccessPointTypeAndStandardType(
						AccessPointType.WATER_POINT, standardType);
		List<DistanceStandard> distanceList = distanceStandardDao
				.listDistanceStandard(StandardType.WaterPointLevelOfService,
						null);
		for (DistanceStandard dsItem : distanceList) {
			StandardScoringDto dtoDist = new StandardScoringDto();
			dtoDist.setGlobalStandard(false);
			dtoDist.setCountryCode(dsItem.getCountryCode());
			dtoDist.setDisplayName(dsItem.getLocationType().toString());
			dtoDist.addPositiveCriteria(dsItem.getMaxDistance().toString());
			dtoDist.setPositiveOperator("<");
			dtoDist.setCriteriaType("Distance");
			dtoDist.setPointType("WaterPoint");
			dtoDist.setKeyId(dsItem.getKey().getId());
			dtoDist.setEffectiveStartDate(dsItem.getEffectiveStartDate());
			dtoDist.setEffectiveEndDate(dsItem.getEffectiveEndDate());
			ssDtoList.add(dtoDist);
		}
		for (Standard item : sList) {
			StandardScoringDto dto = new StandardScoringDto();
			dto.setCountryCode(item.getCountry());
			dto.setDisplayName(item.getStandardDescription());
			dto.setEvaluateField(item.getAccessPointAttribute());
			if (item.getCountry() == null)
				dto.setGlobalStandard(true);
			else
				dto.setGlobalStandard(false);
			dto.setKeyId(item.getKey().getId());
			if (item.getStandardComparison().equals(
					Standard.StandardComparisons.equal)) {
				dto.setPositiveOperator("==");
			} else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.greaterthan)) {
				dto.setPositiveOperator(">");
			} else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.lessthan)) {
				dto.setPositiveOperator("<");
			} else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.greaterthanorequal)) {
				dto.setPositiveOperator(">=");
			} else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.lessthanorequal)) {
				dto.setPositiveOperator("<=");
			} else if (item.getStandardComparison().equals(
					Standard.StandardComparisons.notequal)) {
				dto.setPositiveOperator("!=");
			}
			dto.setMapToObject("AccessPoint");
			for (String crit : item.getPositiveValues()) {
				dto.addPositiveCriteria(crit);
			}
			dto.setPositiveScore(1);
			dto.setPointType("WaterPoint");

			if (item.getAcessPointAttributeType().equals(
					StandardValueType.Boolean)) {
				dto.setCriteriaType("Boolean");
			} else if (item.getAcessPointAttributeType().equals(
					StandardValueType.Number)) {
				dto.setCriteriaType("Number");
			} else if (item.getAccessPointType().equals(
					StandardValueType.String)) {
				dto.setCriteriaType("String");
			}
			dto.setEffectiveEndDate(item.getEffectiveEndDate());
			dto.setEffectiveStartDate(item.getEffectiveStartDate());
			ssDtoList.add(dto);
		}

		ResponseDto<ArrayList<StandardScoringDto>> response = new ResponseDto<ArrayList<StandardScoringDto>>();
		response.setCursorString(StandardScoringDao.getCursor(sList));
		response.setPayload(ssDtoList);
		return response;
	}

	@Override
	public StandardScoringDto save(StandardScoringDto item) {
		StandardScoringDao ssDao = new StandardScoringDao();
		StandardScoring canonical = new StandardScoring();
		DtoMarshaller.copyToCanonical(canonical, item);
		ssDao.save(canonical);
		DtoMarshaller.copyToDto(canonical, item);
		return item;
	}

	@Override
	public void delete(Long id) {
		StandardScoringDao ssDao = new StandardScoringDao();
		ssDao.delete(ssDao.getByKey(id));
{'fraction_non_alphanumeric': 0.11333594055533829, 'fraction_numerical': 0.0032850997262416893, 'mean_word_length': 5.900161899622234, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, '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': '3408378', 'n_tokens_mistral': 4350, 'n_tokens_neox': 3950, 'n_words': 530}