Extract a list of data sources from forms
@param forms
168157
function getDataSourceIds(forms) {
    var dataSources = _.map(forms, function(form) {
      return _.map(form.dataSources.formDataSources, function(dataSourceMeta) {
        return dataSourceMeta._id.toString();
      });
    });

    dataSources = _.flatten(dataSources);

    //Only want unique data source Ids as multiple forms may use the same data source.

    return _.uniq(dataSources);
  }
1329546
def forms_valid(self, forms):
        
        for form in six.itervalues(forms):
            form.save()
        return super(MultiModelFormView, self).forms_valid(forms)
59898
public List<FormField> retrieveFormFields() throws NoResponseException, XMPPErrorException, NotConnectedException,
                    InterruptedException, NotLoggedInException {
        return retrieveFormFields(null);
    }
1098431
function asyncifyFunctions(forms) {
  // for each subexpression form...
  forms.forEach(function(form) {
    if (sl.isList(form)) {
      if(sl.typeOf(form[0]) === 'symbol' &&
        sl.valueOf(form[0]) === 'function' &&
        asyncNeeded(form)) {
          form.unshift(sl.atom("async"));
          asyncifyFunctions(form);
      }
      else {
        asyncifyFunctions(form);
      }
    }
  });
}
1252826
public function getFormElements(&$form, &$data)
    {
        $element = $form->createElement('multiCheckbox', 'format');
        $element->setLabel($this->_('Excel options'))
                ->setMultiOptions(array(
                    'formatVariable'=> $this->_('Export labels instead of field names'),
                    'formatAnswer'  => $this->_('Format answers'),
                    'formatDate'    => $this->_('Format dates as Excel numbers easily convertable to date')
                ))
                ->setBelongsTo($this->getName())
                ->setSeparator('');
        $elements['format'] = $element;

        return $elements;
    }
91621
public void extractValues(HashMap<String, String> values) {
        for (MultipleSyntaxElements l : childContainers) {
            l.extractValues(values);
        }
    }
415628
function(form, options) {
      var values = {}
        , i
        , j
        , input
        , inputs
        , option
        , value;

      if (v.isJqueryElement(form)) {
        form = form[0];
      }

      if (!form) {
        return values;
      }

      options = options || {};

      inputs = form.querySelectorAll("input[name], textarea[name]");
      for (i = 0; i < inputs.length; ++i) {
        input = inputs.item(i);

        if (v.isDefined(input.getAttribute("data-ignored"))) {
          continue;
        }

        var name = input.name.replace(/\./g, "\\\\.");
        value = v.sanitizeFormValue(input.value, options);
        if (input.type === "number") {
          value = value ? +value : null;
        } else if (input.type === "checkbox") {
          if (input.attributes.value) {
            if (!input.checked) {
              value = values[name] || null;
            }
          } else {
            value = input.checked;
          }
        } else if (input.type === "radio") {
          if (!input.checked) {
            value = values[name] || null;
          }
        }
        values[name] = value;
      }

      inputs = form.querySelectorAll("select[name]");
      for (i = 0; i < inputs.length; ++i) {
        input = inputs.item(i);
        if (v.isDefined(input.getAttribute("data-ignored"))) {
          continue;
        }

        if (input.multiple) {
          value = [];
          for (j in input.options) {
            option = input.options[j];
             if (option && option.selected) {
              value.push(v.sanitizeFormValue(option.value, options));
            }
          }
        } else {
          var _val = typeof input.options[input.selectedIndex] !== 'undefined' ? input.options[input.selectedIndex].value : /* istanbul ignore next */ '';
          value = v.sanitizeFormValue(_val, options);
        }
        values[input.name] = value;
      }

      return values;
    }
1296472
public function retrieveAll()
    {
        if (empty($this->forms)) {
            $data        = $this->getModel()->get();
            $this->forms = $this->processRetrievedData($data);
        }
        return $this->forms;
    }
916625
def remove_forms(self, form_names):
        
        for form in form_names:
            try:
                self.parentApp.removeForm(form)
            except Exception as e:  # pragma: no cover
                pass
        return
189182
public static <T> Source<T> from(T... items) {
        return from(Arrays.asList(items));
    }
944541
function findMatchingDocuments(type, documentIDs, modelToSearch, cb) {

    var errorTextDataType = type === models.MODELNAMES.DATA_SOURCE ? "Data Sources" : "Data Targets";

    //If the form contains no data sources, then no need to verify
    if (documentIDs.length === 0) {
      return cb(undefined, []);
    }

    var query = {_id: {
      "$in": documentIDs
    }};

    modelToSearch.find(query).exec(function(err, foundModels) {
      if (err) {
        return cb(buildErrorResponse({
          error: err,
          userDetail: "Unexpected Error Finding " + errorTextDataType
        }));
      }

      //There should be the same number of data source documents
      if (documentIDs.length !== foundModels.length) {

        var missingDocumentId = _.find(documentIDs, function(documentId) {
          return !_.findWhere(foundModels, {_id: documentId});
        });

        //If there is no missing data source, then something is wrong..
        if (!missingDocumentId) {
          return cb(buildErrorResponse({
            error: new Error("Unexpected Error When Finding " + errorTextDataType),
            systemDetail: "Expected A Missing " + errorTextDataType + " But Could Not Find It"
          }));
        }

        return cb(buildErrorResponse({
          userDetail: "A " + errorTextDataType + " Contained In The Form Could Not Be Found",
          systemDetail: "Expected " + errorTextDataType + " With ID " + missingDocumentId + " To Be Found",
          code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS
        }));
      }

      //All documents found -- checking for cache if needed
      if (options.expectDataSourceCache && type === models.MODELNAMES.DATA_SOURCE) {
        var missingCache = _.find(foundModels, function(dataSource) {
          return dataSource.cache.length === 0;
        });

        if (missingCache) {
          return cb(buildErrorResponse({
            error: new Error("Expected " + errorTextDataType + " Cached Data To Be Set"),
            systemDetail: "Expected Cache For " + errorTextDataType + " ID " + missingCache._id + " To Be Set",
            code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS
          }));
        }
      }

      //Checking that only one real time data target is assigned.
      if (type === models.MODELNAMES.DATA_TARGET) {
        var realTimeDataTargets = _.filter(foundModels, function(foundModel) {
          return foundModel.type === models.CONSTANTS.DATA_TARGET_TYPE_REAL_TIME;
        });

        if (realTimeDataTargets.length > 1) {
          return cb(buildErrorResponse({
            error: new Error("Only One Real Time Data Target Can Be Assigned To A Form"),
            code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS
          }
                                      ));
        }
      }

      return cb(undefined, foundModels);
    });
  }
1278032
private function resolveDataSource(FormInterface $form)
    {
        if ($form->isRoot()) {
            // Nothing to do if root
            $dataForm = $form->getData();
        } else {
            $dataForm = $form;
            while ($dataForm->getConfig()->getDataClass() === null) {
                $dataForm = $form->getParent();
            }
        }

        $data = $dataForm->getData();
        return array(
            $data,
            $data === null ? $dataForm->getConfig()->getDataClass() : get_class($data)
        );
    }
920570
function populateFieldDataFromDataSources(populatedForms, cb) {
    logger.debug("populateFieldDataFromDataSources", populatedForms);
    var DataSource = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_SOURCE);
    //If no data source cache data is expected, then there is no need to load the Data Source Cache Data.

    if (!options.expectDataSourceCache) {
      return cb(undefined, populatedForms);
    }
    var dataSourceIds = getDataSourceIds(populatedForms);

    logger.debug("populateFieldDataFromDataSources", {dataSourceIds: dataSourceIds});

    //If none of the forms refer to any data sources, then no need to search
    if (dataSourceIds.length === 0) {
      return cb(undefined, populatedForms);
    }

    var query = {
      _id: {
        "$in": dataSourceIds
      }
    };

    //One query to populate all data sources
    DataSource.find(query).exec(function(err, dataSources) {
      if (err) {
        logger.error("Error Finding Data Sources", {error: err, dataSourceIds:dataSourceIds});
        return cb(err);
      }

      logger.debug("populateFieldDataFromDataSources", {dataSources: dataSources});

      var validatonError = _validateReturnedDataSources(dataSourceIds, dataSources);

      if (validatonError) {
        logger.error("Error Getting Form With Data Sources", {error: validatonError});
        return cb(validatonError);
      }

      var cacheEntries = {};

      //Assigning a lookup for cache entries
      _.each(dataSources, function(dataSource) {
        cacheEntries[dataSource._id] = dataSource.cache[0].data;
      });

      //Overriding field options for a field with data source data if the field is defined as being sourced from a data source.
      populatedForms = _.map(populatedForms, function(populatedForm) {
        populatedForm.pages = _.map(populatedForm.pages, function(page) {
          page.fields =  _.map(page.fields, function(field) {
            //If it is a data source type field, then return the data source data
            if (field.dataSourceType === models.FORM_CONSTANTS.DATA_SOURCE_TYPE_DATA_SOURCE) {
              //No guarantee these are set
              field.fieldOptions = field.fieldOptions || {};
              field.fieldOptions.definition = field.fieldOptions.definition || {};

              //Setting the data source data
              field.fieldOptions.definition.options = models.convertDSCacheToFieldOptions(field.type, cacheEntries[field.dataSource]);
            }
            return field;
          });
          return page;
        });

        return populatedForm;
      });

      logger.debug("populateFieldDataFromDataSources", {populatedForms: JSON.stringify(populatedForms)});

      //Finished, return the merged forms
      return cb(undefined, populatedForms);
    });

  }
1047497
def get_formset(self, form, name):
        
        kwargs = self.get_kwargs(form, name)
        formset_class = self.get_formset_class(form, name)
        formset = formset_class(
            form.data if form.is_bound else None,
            form.files if form.is_bound else None,
            **kwargs)
        return formset
798124
private File[] getSources(final List<File> sourceList) {
    final File[] sortedSources = new File[sourceList.size()];
    sourceList.toArray(sortedSources);
    Arrays.sort(sortedSources, new Comparator<File>() {
      @Override
      public int compare(final File o1, final File o2) {
        return o1.getName().compareTo(o2.getName());
      }
    });
    return sortedSources;
  }
1319808
function updateForms(params, validDataSources, invalidDataSources, cb) {
  //Only interested In Data Sources Where Data Was Actually Updated. If the data set is still the same, then no need to mark the form as updated the form.
  var dataSoucesUpdated = _.filter(validDataSources, function(dataSourceData) {
    return dataSourceData.dataChanged === true;
  });

  //Updating Any Forms That Reference Updated Data Sources
  var updatedDataSourceIds = _.map(dataSoucesUpdated, function(validDataSourceData) {
    return validDataSourceData._id;
  });

  //Need to find and update any forms associated with the data sources.
  var Form = models.get(params.connections.mongooseConnection, models.MODELNAMES.FORM);

  //Flagging Any Forms That Are Using The Updated Data Sources As Being Updated. This is useful for client/cloud apps that need to determine if they need to load the entire form again.
  Form.update({
    "dataSources.formDataSources": {"$in": updatedDataSourceIds}
  }, {
    "$set": {
      "dataSources.lastRefresh": params.currentTime
    }
  }, { multi: true }, function(err) {
    if (err) {
      return cb(buildErrorResponse({
        error: new Error("Error Updating Forms Refresh Fields"),
        code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
      }));
    }

    //No error, forms updated, moving on
    cb(undefined, validDataSources, invalidDataSources);
  });
}
1232962
public void setSources(java.util.Collection<InputSource> sources) {
        if (sources == null) {
            this.sources = null;
            return;
        }

        this.sources = new java.util.ArrayList<InputSource>(sources);
    }