Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    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