示例#1
0
    def create_service_model_instance(self, user: MrMapUser, register_group,
                                      register_for_organization, external_auth,
                                      is_update_candidate_for):
        """ Map all data from the OGCCatalogueService class to their database models

        Args:
            user (MrMapUser): The user which performs the action
            register_group (Group): The group which is used to register this service
            register_for_organization (Organization): The organization for which this service is being registered
            external_auth (ExternalAuthentication): The external authentication object
        Returns:
             service (Service): Service instance, contains all information, ready for persisting!
        """
        if current_task:
            current_task.update_state(state=states.STARTED,
                                      meta={
                                          'current':
                                          PROGRESS_STATUS_AFTER_PARSING,
                                          'phase': 'Persisting...',
                                      })

        md = Metadata()
        md_type = MetadataEnum.CATALOGUE.value
        md.metadata_type = md_type
        md.title = self.service_identification_title
        md.identifier = self.service_file_identifier
        md.abstract = self.service_identification_abstract
        md.online_resource = self.service_provider_onlineresource_linkage

        md.contact = self._create_contact_organization_record()
        md.authority_url = self.service_provider_url
        md.access_constraints = self.service_identification_accessconstraints
        md.fees = self.service_identification_fees
        md.created_by = register_group
        md.capabilities_original_uri = self.service_connect_url
        if self.service_bounding_box is not None:
            md.bounding_geometry = self.service_bounding_box

        # Save metadata record so we can use M2M or id of record later
        md.save()
        md.identifier = str(md.id) if md.identifier is None else md.identifier

        # Keywords
        for kw in self.service_identification_keywords:
            if kw is None:
                continue
            keyword = Keyword.objects.get_or_create(keyword=kw)[0]
            md.keywords.add(keyword)

        md.formats.add(*self.formats_list)
        md.save()

        service = self._create_service_record(register_group,
                                              register_for_organization, md,
                                              is_update_candidate_for)

        return service
示例#2
0
    def _create_metadata_record(self, contact: Organization,
                                group: MrMapGroup):
        """ Creates a Metadata record from the OGCWebMapService

        Args:
            contact (Organization): The contact organization for this metadata record
            group (MrMapGroup): The owner/creator group
        Returns:
             metadata (Metadata): The persisted metadata record
        """
        metadata = Metadata()
        md_type = MetadataEnum.SERVICE.value
        metadata.metadata_type = md_type
        if self.service_file_iso_identifier is None:
            # We didn't found any file identifier in the document -> we create one
            self.service_file_iso_identifier = uuid.uuid4()
        metadata.title = self.service_identification_title
        metadata.abstract = self.service_identification_abstract
        metadata.online_resource = self.service_provider_onlineresource_linkage
        metadata.capabilities_original_uri = self.service_connect_url
        metadata.access_constraints = self.service_identification_accessconstraints
        metadata.fees = self.service_identification_fees
        if self.service_bounding_box is not None:
            metadata.bounding_geometry = self.service_bounding_box
        metadata.identifier = self.service_file_identifier
        metadata.is_active = False
        metadata.created_by = group
        metadata.contact = contact

        # Save metadata instance to be able to add M2M entities
        metadata.save()

        return metadata
示例#3
0
    def _fill_metadata_db_model(self, metadata: Metadata):
        """ Fills a Metadata db record from the ISOMetadata data

        Args:
            metadata (Metadata): The old/empty object
        Returns:
             metadata (Metadata): The metadata object
        """
        metadata.identifier = self.file_identifier
        metadata.abstract = self.abstract
        metadata.access_constraints = self.access_constraints

        # Take the polygon with the largest area as bounding geometry
        if len(self.polygonal_extent_exterior) > 0:
            max_area_poly = None
            for poly in self.polygonal_extent_exterior:
                if max_area_poly is None:
                    max_area_poly = poly
                if max_area_poly.area < poly.area:
                    max_area_poly = poly
            metadata.bounding_geometry = max_area_poly

        try:
            metadata.contact = Organization.objects.get_or_create(
                organization_name=self.responsible_party,
                email=self.contact_email,
            )[0]
        except MultipleObjectsReturned:
            # okay, we need to create a unique organization
            # "unique" since it will only be identified using organization_name and email
            metadata.contact = Organization.objects.get_or_create(
                organization_name="{}#1".format(self.responsible_party),
                email=self.contact_email,
            )[0]

        metadata.is_inspire_conform = self.inspire_interoperability
        metadata.metadata_url = self.uri
        metadata.last_remote_change = self.last_change_date
        metadata.spatial_res_type = self.spatial_res_type
        metadata.spatial_res_value = self.spatial_res_val
        if self.title is None:
            self.title = "BROKEN"
        metadata.title = self.title
        metadata.origin = self.origin
        metadata.is_broken = self.is_broken
        metadata.save()

        # save legal dates and reports
        for report in self.legal_reports:
            report.date.save()
            report.save()
            metadata.legal_reports.add(report)
        for date in self.legal_dates:
            date.save()
            metadata.legal_dates.add(date)

        metadata.save()

        return metadata
示例#4
0
文件: layer.py 项目: majo72/mrmap
    def _create_metadata_record(self, parent_service: Service,
                                group: MrMapGroup):
        """ Creates a Metadata record from the OGCLayer object

        Args:
            self (OGCLayer): The OGCLayer object (result of parsing)
            parent_service (Service): The parent Service object 
            group (MrMapGroup): The creator/owner group
        Returns:
             metadata (Metadata): The persisted metadata object
        """
        metadata = Metadata()
        md_type = MetadataEnum.LAYER.value
        metadata.metadata_type = md_type
        metadata.title = self.title
        metadata.abstract = self.abstract
        metadata.online_resource = parent_service.metadata.online_resource
        metadata.capabilities_original_uri = parent_service.metadata.capabilities_original_uri
        metadata.identifier = self.identifier
        metadata.contact = parent_service.metadata.contact
        metadata.access_constraints = parent_service.metadata.access_constraints
        metadata.is_active = False
        metadata.created_by = group

        # Save metadata to use id afterwards
        metadata.save()

        # create bounding box polygon
        bounding_points = ((float(self.capability_bbox_lat_lon["minx"]),
                            float(self.capability_bbox_lat_lon["miny"])),
                           (float(self.capability_bbox_lat_lon["minx"]),
                            float(self.capability_bbox_lat_lon["maxy"])),
                           (float(self.capability_bbox_lat_lon["maxx"]),
                            float(self.capability_bbox_lat_lon["maxy"])),
                           (float(self.capability_bbox_lat_lon["maxx"]),
                            float(self.capability_bbox_lat_lon["miny"])),
                           (float(self.capability_bbox_lat_lon["minx"]),
                            float(self.capability_bbox_lat_lon["miny"])))
        metadata.bounding_geometry = Polygon(bounding_points)

        metadata.save()

        return metadata