content: /*
   *  Copyright (C) 2010-2017,2020 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 org.waterforpeople.mapping.app.web.dto;
  
  import java.util.logging.Logger;
  
  import javax.servlet.http.HttpServletRequest;
  
  import com.gallatinsystems.framework.rest.RestError;
  import com.gallatinsystems.framework.rest.RestRequest;
  
  public class SurveyInstanceRequest extends RestRequest {
  
      private static final Logger log = Logger.getLogger(SurveyInstanceRequest.class.getName());
      private static final long serialVersionUID = 6642806619258697157L;
      private static final String FIELD_NAME_PARAM = "fieldName";
      private static final String VALUE_NAME_PARAM = "value";
      private static final String DATA_POINT_IDENTIFIER_PARAM = "identifier";
      private static final String ANDROID_ID_PARAM = "androidId";
      public static final String GET_INSTANCE_DATA_ACTION = "getInstanceData";
      public static final String GET_FORM_INSTANCES_ACTION = "getFormInstances";
      public static final String SURVEY_INSTANCE_ID_PARAM = "surveyInstanceId";
  
      private String fieldName = null;
      public Long surveyInstanceId;
  
      private String dataPointIdentifier;
  
      private String androidId;
  
      public String getAndroidId() {
          return androidId;
      }
  
      public void setAndroidId(String androidId) {
          this.androidId = androidId;
      }
  
      public String getDataPointIdentifier() {
          return dataPointIdentifier;
      }
  
      public void setDataPointIdentifier(String dataPointIdentifier) {
          this.dataPointIdentifier = dataPointIdentifier;
      }
  
      public String getFieldName() {
          return fieldName;
      }
  
      public void setFieldName(String fieldName) {
          this.fieldName = fieldName;
      }
  
      public String getValue() {
          return value;
      }
  
      public void setValue(String value) {
          this.value = value;
      }
  
      private String value = null;
  
      @Override
      protected void populateFields(HttpServletRequest req) throws Exception {
          if (req.getParameter(FIELD_NAME_PARAM) != null) {
              setFieldName(req.getParameter(FIELD_NAME_PARAM));
          }
          if (req.getParameter(VALUE_NAME_PARAM) != null) {
              setValue(req.getParameter(VALUE_NAME_PARAM));
          }
  
          if (req.getParameter(ANDROID_ID_PARAM) != null) {
              setAndroidId(req.getParameter(ANDROID_ID_PARAM));
          }
  
          if (req.getParameter(SURVEY_INSTANCE_ID_PARAM) != null) {
              try {
                  this.surveyInstanceId = Long.parseLong(req.getParameter(SURVEY_INSTANCE_ID_PARAM));
              } catch (NumberFormatException e) {
                  log.warning("Could not convert survey instance id: " + req.getParameter(SURVEY_INSTANCE_ID_PARAM));
              }
          } else {
              addError(new RestError(RestError.MISSING_PARAM_ERROR_CODE, RestError.MISSING_PARAM_ERROR_MESSAGE, "Missing form instance id"));
          }
  
          if (req.getParameter(DATA_POINT_IDENTIFIER_PARAM) != null) {
              setDataPointIdentifier(req.getParameter(DATA_POINT_IDENTIFIER_PARAM));
          }
      }
  
      @Override
      protected void populateErrors() {
          // TODO Auto-generated method stub
  
      }
  
  }
  