/*
 *  Copyright (C) 2016 Stichting Akvo (Akvo Foundation)
 *
 *  This file is part of Akvo Flow.
 *
 *  Akvo Flow is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo FLOW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included below for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */

package com.gallatinsystems.survey.dao;

import java.util.Collections;
import java.util.List;

import javax.jdo.PersistenceManager;

import com.gallatinsystems.framework.dao.BaseDAO;
import com.gallatinsystems.framework.servlet.PersistenceFilter;
import com.gallatinsystems.survey.domain.DataPointApproval;

public class DataPointApprovalDAO extends BaseDAO<DataPointApproval> {

    public DataPointApprovalDAO() {
        super(DataPointApproval.class);
    }

    public List<DataPointApproval> listBySurveyedLocaleId(Long surveyedLocaleId) {
        return this.listByProperty("surveyedLocaleId", surveyedLocaleId, "Long");
    }

    public List<DataPointApproval> listBySurveyedLocaleIds(List<Long> surveyedLocaleIds) {
        if (surveyedLocaleIds == null || surveyedLocaleIds.isEmpty()) {
            return Collections.emptyList();
        }
        PersistenceManager pm = PersistenceFilter.getManager();
        String queryString = ":p2.contains(surveyedLocaleId)";
        javax.jdo.Query query = pm.newQuery(DataPointApproval.class, queryString);
        return (List<DataPointApproval>) query.execute(surveyedLocaleIds);
    }
}

@@ -21,9 +21,9 @@
  201
-6
+7
  Sti
@@ -1252,22 +1252,51 @@
         
-return
+List%3CDataPointApproval%3E approvals =
  this.li
@@ -1327,16 +1327,32 @@
 caleId%22,
+%0A               
  surveye
@@ -1371,16 +1371,129 @@
 Long%22);%0A
+        if (approvals == null) %7B%0A            return Collections.emptyList();%0A        %7D%0A        return approvals;%0A
     %7D%0A%0A 

Refactor `DataPointApproalDAO.listBySurveyedLocaleId()` to return empty list of no results found