コード例 #1
0
 def _create_new_entity_doc(self, aggregation_paths, centroid, entity_type,
                            geometry, gr_id, id, location, short_code):
     doc = EntityDocument(id)
     self._set_document(doc)
     # add aggregation paths
     if is_string(entity_type):
         entity_type = [entity_type]
     doc.entity_type = entity_type
     if location is not None:
         doc.location = location
     if geometry is not None:
         doc.geometry = geometry
     if centroid is not None:
         doc.centroid = centroid
     if gr_id is not None:
         doc.gr_id = gr_id
     if short_code is not None:
         doc.short_code = short_code
     if aggregation_paths is not None:
         reserved_names = (attributes.TYPE_PATH, attributes.GEO_PATH)
         for name in aggregation_paths.keys():
             if name in reserved_names:
                 raise ValueError(
                     u'Attempted to add an aggregation path with a reserved name'
                 )
             self.set_aggregation_path(name, aggregation_paths[name])
コード例 #2
0
ファイル: entity.py プロジェクト: Ritesh-Yadav/mangrove
    def __init__(self, dbm, entity_type=None, location=None, aggregation_paths=None,
                 geometry=None, centroid=None, gr_id=None, id=None, short_code=None):
        """
        Construct a new entity.

        Note: _couch_document is used for 'protected' factory methods and
        should not be passed in standard construction.

        If _couch_document is passed, the other args are ignored

        entity_type may be a string (flat type) or sequence (hierarchical type)
        """
        assert isinstance(dbm, DatabaseManager)
        assert entity_type is None or is_sequence(entity_type) or is_string(entity_type)
        assert location is None or is_sequence(location)
        assert aggregation_paths is None or isinstance(aggregation_paths, dict)
        assert geometry is None or isinstance(geometry, dict)
        assert centroid is None or isinstance(centroid, list)
        assert gr_id is None or is_string(gr_id)
        DataObject.__init__(self, dbm)

        # Are we being constructed from an existing doc, in which case all the work is
        # in _set_document?
        if entity_type is None:
            return

        # Not made from existing doc, so create a new one
        doc = EntityDocument(id)
        self._set_document(doc)

        # add aggregation paths
        if is_string(entity_type):
            entity_type = [entity_type]
        doc.entity_type = entity_type

        if location is not None:
            doc.location = location

        if geometry is not None:
            doc.geometry = geometry

        if centroid is not None:
            doc.centroid = centroid

        if gr_id is not None:
            doc.gr_id = gr_id

        if short_code is not None:
            doc.short_code = short_code

        if aggregation_paths is not None:
            reserved_names = (attributes.TYPE_PATH, attributes.GEO_PATH)
            for name in aggregation_paths.keys():
                if name in reserved_names:
                    raise ValueError(u'Attempted to add an aggregation path with a reserved name')
                self.set_aggregation_path(name, aggregation_paths[name])
コード例 #3
0
ファイル: entity.py プロジェクト: Ritesh-Yadav/mangrove
    def __init__(self,
                 dbm,
                 entity_type=None,
                 location=None,
                 aggregation_paths=None,
                 geometry=None,
                 centroid=None,
                 gr_id=None,
                 id=None,
                 short_code=None):
        """
        Construct a new entity.

        Note: _couch_document is used for 'protected' factory methods and
        should not be passed in standard construction.

        If _couch_document is passed, the other args are ignored

        entity_type may be a string (flat type) or sequence (hierarchical type)
        """
        assert isinstance(dbm, DatabaseManager)
        assert entity_type is None or is_sequence(entity_type) or is_string(
            entity_type)
        assert location is None or is_sequence(location)
        assert aggregation_paths is None or isinstance(aggregation_paths, dict)
        assert geometry is None or isinstance(geometry, dict)
        assert centroid is None or isinstance(centroid, list)
        assert gr_id is None or is_string(gr_id)
        DataObject.__init__(self, dbm)

        # Are we being constructed from an existing doc, in which case all the work is
        # in _set_document?
        if entity_type is None:
            return

        # Not made from existing doc, so create a new one
        doc = EntityDocument(id)
        self._set_document(doc)

        # add aggregation paths
        if is_string(entity_type):
            entity_type = [entity_type]
        doc.entity_type = entity_type

        if location is not None:
            doc.location = location

        if geometry is not None:
            doc.geometry = geometry

        if centroid is not None:
            doc.centroid = centroid

        if gr_id is not None:
            doc.gr_id = gr_id

        if short_code is not None:
            doc.short_code = short_code

        if aggregation_paths is not None:
            reserved_names = (attributes.TYPE_PATH, attributes.GEO_PATH)
            for name in aggregation_paths.keys():
                if name in reserved_names:
                    raise ValueError(
                        u'Attempted to add an aggregation path with a reserved name'
                    )
                self.set_aggregation_path(name, aggregation_paths[name])