Returns a Mongo Collection and AssessmentPart given a AssessmentPart Id
964337
def _get_assessment_part_collection(self, assessment_part_id):
        """"""
        collection = JSONClientValidated('assessment_authoring',
                                         collection='AssessmentPart',
                                         runtime=self._runtime)
        assessment_part_map = collection.find_one({'_id': ObjectId(assessment_part_id.get_identifier())})
        if 'itemIds' not in assessment_part_map:
            raise errors.NotFound('no Items are assigned to this AssessmentPart')
        return assessment_part_map, collection
1265338
def get_collection(self, collection_id):
        """"""
        sql = """SELECT collection.collection_id, collection.type,
                        collection.name, collection.path,
                        collection.doc,
                        collection.version, collection.scope,
                        collection.namedargs,
                        collection.doc_format
                 FROM collection_table as collection
                 WHERE collection_id == ? OR collection.name like ?
        """
        cursor = self._execute(sql, (collection_id, collection_id))
        # need to handle the case where we get more than one result...
        sql_result = cursor.fetchone()
        return {
            "collection_id": sql_result[0],
            "type": sql_result[1],
            "name": sql_result[2],
            "path": sql_result[3],
            "doc":  sql_result[4],
            "version": sql_result[5],
            "scope":   sql_result[6],
            "namedargs": sql_result[7],
            "doc_format": sql_result[8]
        }
        return sql_result
657696
function getCollectionsCompact(forEntity, includeNew) {
  let associations = forEntity.getMeta().fetch('associations');
  let collections  = {};

  Object.getOwnPropertyNames(associations).forEach(index => {
    let association = associations[index];

    if (association.type !== 'collection') {
      return;
    }

    collections[index] = [];
    if (!Array.isArray(forEntity[index])) {
      return;
    }

    forEntity[index].forEach(entity => {
      if (typeof entity === 'number') {
        collections[index].push(entity);

        return;
      }

      if (!(entity instanceof Entity)) {
        return;
      }

      if (entity.getId()) {
        collections[index].push(entity.getId());

        return;
      }

      if (includeNew) {
        collections[index].push(entity);

        return;
      }
    });
  });

  return collections;
}
864813
def save_assessment_part(self, assessment_part_form, *args, **kwargs):
        """"""
        # Implemented from kitosid template for -
        # osid.resource.ResourceAdminSession.update_resource
        if assessment_part_form.is_for_update():
            return self.update_assessment_part(assessment_part_form, *args, **kwargs)
        else:
            return self.create_assessment_part(assessment_part_form, *args, **kwargs)
1147937
def get_id(self):
        """"""

        # Check first to make sure no one else has claimed authority on my object.
        # This will likely occur when an AssessmentSection returns a Question
        # During an AssessmentSession
        if self.my_osid_object._authority != MAGIC_AUTHORITY:
            return self.my_osid_object._item_id
            # raise AttributeError

        # If not, go ahead and build magic Id:
        choices = self.my_osid_object._my_map['choices']
        choice_ids = [c['id'] for c in choices]
        magic_identifier = quote('{0}?{1}'.format(self.my_osid_object._my_map['_id'],
                                                  json.dumps(choice_ids)))
        return Id(namespace='assessment.Item',
                  identifier=magic_identifier,
                  authority=MAGIC_AUTHORITY)
597340
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'collection_id' in _dict:
            args['collection_id'] = _dict.get('collection_id')
        if 'name' in _dict:
            args['name'] = _dict.get('name')
        if 'description' in _dict:
            args['description'] = _dict.get('description')
        if 'created' in _dict:
            args['created'] = string_to_datetime(_dict.get('created'))
        if 'updated' in _dict:
            args['updated'] = string_to_datetime(_dict.get('updated'))
        if 'status' in _dict:
            args['status'] = _dict.get('status')
        if 'configuration_id' in _dict:
            args['configuration_id'] = _dict.get('configuration_id')
        if 'language' in _dict:
            args['language'] = _dict.get('language')
        if 'document_counts' in _dict:
            args['document_counts'] = DocumentCounts._from_dict(
                _dict.get('document_counts'))
        if 'disk_usage' in _dict:
            args['disk_usage'] = CollectionDiskUsage._from_dict(
                _dict.get('disk_usage'))
        if 'training_status' in _dict:
            args['training_status'] = TrainingStatus._from_dict(
                _dict.get('training_status'))
        if 'source_crawl' in _dict:
            args['source_crawl'] = SourceStatus._from_dict(
                _dict.get('source_crawl'))
        return cls(**args)
674762
function get_associated_collections(collection) {
  const map = new Map()

  get_association_keys(collection)
    // Return the identity to the related resource.
    .forEach(key => {
      // Get the attributes
      const collection_attributes = collection._attributes[key]

      // Most of the time, it's a one to one
      // relationship so it's not an array.
      let is_array = false

      // But sometimes, it's a one to many
      // so array must be true.
      if (collection_attributes.hasOwnProperty("collection")) {
        is_array = true
      }

      // Set the values.
      map.set(key, { is_array, collection })
    })

  return map
}
315105
def _get_part_map(self, part_id):
        
        return [p for p in self._my_map['assessmentParts']
                if p['assessmentPartId'] == str(part_id)][0]
876883
def get_assessment_part(self):
        
        if self._magic_parent_id is None:
            assessment_part_id = Id(self.my_osid_object._my_map['assessmentPartId'])
        else:
            assessment_part_id = self._magic_parent_id
        if self._assessment_section is not None:
            return self._assessment_section._get_assessment_part(assessment_part_id)
        # else:
        apls = get_assessment_part_lookup_session(runtime=self.my_osid_object._runtime,
                                                  proxy=self.my_osid_object._proxy,
                                                  section=self._assessment_section)
        apls.use_federated_bank_view()
        apls.use_unsequestered_assessment_part_view()
        return apls.get_assessment_part(assessment_part_id)
181173
function queryCriteriaToMongo(query, options) {
    var hash = {}, p, v, deep
    options = options || {}

    for (var key in query) {
        if (Object.prototype.hasOwnProperty.call(query, key) && (!options.ignore || options.ignore.indexOf(key) == -1)) {
            deep = (typeof query[key] === 'object' && !hasOrdinalKeys(query[key]))

            if (deep) {
                p = {
                    key: key,
                    value: queryCriteriaToMongo(query[key])
                }
            } else {
                p = comparisonToMongo(key, query[key])
            }

            if (p) {
                if (!hash[p.key]) {
                    hash[p.key] = p.value;
                } else {
                    hash[p.key] = Object.assign(hash[p.key], p.value);
                }
            }
        }
    }
    return hash
}
1278339
def _update_from_database(self):
        
        collection = JSONClientValidated('assessment',
                                         collection='AssessmentSection',
                                         runtime=self._runtime)
        self._my_map = collection.find_one({'_id': self._my_map['_id']})
1171811
def _get_assessment_part_lookup_session(self):
        """"""
        section = getattr(self, '_assessment_section', None)
        session = get_assessment_part_lookup_session(self._runtime,
                                                     self._proxy,
                                                     section)
        session.use_unsequestered_assessment_part_view()
        session.use_federated_bank_view()
        return session
1291293
def find(self, collection, selector={}):
        """"""
        results = []
        for _id, doc in self.collection_data.data.get(collection, {}).items():
            doc.update({'_id': _id})
            if selector == {}:
                results.append(doc)
            for key, value in selector.items():
                if key in doc and doc[key] == value:
                    results.append(doc)
        return results
1240431
def _get_assessment_taken(self, assessment_taken_id):
        """"""
        if assessment_taken_id not in self._assessments_taken:
            mgr = self._get_provider_manager('ASSESSMENT')
            lookup_session = mgr.get_assessment_taken_lookup_session(proxy=self._proxy)  # Should this be _for_bank?
            lookup_session.use_federated_bank_view()
            self._assessments_taken[assessment_taken_id] = (
                lookup_session.get_assessment_taken(assessment_taken_id))
        return self._assessments_taken[assessment_taken_id]
402286
def get_by_id(self, process_name, db_id):
        
        collection_name = self._get_job_collection_name(process_name)
        collection = self.ds.connection(collection_name)
        document = collection.find_one({'_id': ObjectId(db_id)})

        if document is None:
            raise LookupError('MongoDB has no job record in collection {0} for {1}'
                              .format(collection, db_id))
        return Job.from_json(document)
847916
def _get_collection_item(collection_id, dataset_id):
    
    collection_item = db.DBSession.query(DatasetCollectionItem).\
            filter(DatasetCollectionItem.collection_id==collection_id,
                   DatasetCollectionItem.dataset_id==dataset_id).first()
    return collection_item
1090919
def get_assessment_form(self, *args, **kwargs):
        """"""
        # Implemented from kitosid template for -
        # osid.resource.ResourceAdminSession.get_resource_form_for_update
        # This method might be a bit sketchy. Time will tell.
        if isinstance(args[-1], list) or 'assessment_record_types' in kwargs:
            return self.get_assessment_form_for_create(*args, **kwargs)
        else:
            return self.get_assessment_form_for_update(*args, **kwargs)