Esempio n. 1
0
    def _create_dublin_core_summary_elem(self, md: Metadata):
        """ Creates the SummaryRecord in Dublin core syntax

        Args:
            md (Metadata): The metadata object providing the data
        Returns:
             elem (_Element): The lxml element
        """
        record_elem = Element(
            "{}SummaryRecord".format(self.csw_ns),
            nsmap=self.dc_ns_map,
        )

        # Perform xml creation for simple elements
        attribute_element_map = OrderedDict()
        attribute_element_map[IDENTIFIER_TEMPLATE.format(
            self.dc_ns)] = md.identifier
        attribute_element_map[TITLE_TEMPLATE.format(self.dc_ns)] = md.title
        attribute_element_map[TYPE_TEMPLATE.format(
            self.dc_ns
        )] = md.metadata_type if md.metadata_type == MetadataEnum.DATASET.value else MetadataEnum.SERVICE.value
        kws = md.keywords.all()
        formats = md.get_formats()
        attribute_element_map["{}subject".format(
            self.dc_ns)] = [kw.keyword for kw in kws]
        attribute_element_map["{}format".format(
            self.dc_ns)] = [format.mime_type for format in formats]
        attribute_element_map["{}modified".format(
            self.dct_ns)] = md.last_modified.strftime(DATE_STRF)
        attribute_element_map["{}abstract".format(self.dct_ns)] = md.abstract

        # Create xml elements from mapped information
        self._create_xml_from_map(record_elem, attribute_element_map)

        return record_elem
Esempio n. 2
0
    def _create_dublin_core_full_elem(self, md: Metadata):
        """ Creates the default (full) record in Dublin core syntax

        Args:
            md (Metadata): The metadata object providing the data
        Returns:
             elem (_Element): The lxml element
        """
        record_elem = Element(
            "{}Record".format(self.csw_ns),
            nsmap=self.dc_ns_map,
        )

        # Perform xml creation for simple elements
        attribute_element_map = OrderedDict()
        attribute_element_map[IDENTIFIER_TEMPLATE.format(
            self.dc_ns)] = md.identifier
        attribute_element_map["{}date".format(
            self.dc_ns)] = md.created.strftime(DATE_STRF)
        attribute_element_map[TITLE_TEMPLATE.format(self.dc_ns)] = md.title
        attribute_element_map["{}abstract".format(self.dct_ns)] = md.abstract
        attribute_element_map["{}description".format(self.dc_ns)] = md.abstract
        attribute_element_map[TYPE_TEMPLATE.format(
            self.dc_ns
        )] = md.metadata_type if md.metadata_type == MetadataEnum.DATASET.value else MetadataEnum.SERVICE.value
        kws = md.keywords.all()
        formats = md.get_formats()
        attribute_element_map["{}subject".format(
            self.dc_ns)] = [kw.keyword for kw in kws]
        attribute_element_map["{}format".format(
            self.dc_ns)] = [format.mime_type for format in formats]
        attribute_element_map["{}modified".format(
            self.dct_ns)] = md.last_modified.strftime(DATE_STRF)
        attribute_element_map["{}rights".format(self.dc_ns)] = "ToDo"  # ToDo

        # Create xml elements from mapped information
        self._create_xml_from_map(record_elem, attribute_element_map)

        # Perform xml creation for more complex elements
        # URI
        elem = xml_helper.create_subelement(record_elem,
                                            "{}URI".format(self.dc_ns),
                                            attrib={
                                                "protocol": "",
                                                "name": md.identifier or "",
                                                "description": md.abstract
                                                or "",
                                            })
        elem.text = md.capabilities_uri

        return record_elem