def _create_service_record(self, group: MrMapGroup, orga_published_for: Organization, md: Metadata, is_update_candidate_for: Service): """ Creates a Service object from the OGCWebFeatureService object Args: group (MrMapGroup): The owner/creator group orga_published_for (Organization): The organization for which the service is published orga_publisher (Organization): THe organization that publishes md (Metadata): The describing metadata Returns: service (Service): The persisted service object """ service = Service() service_type = ServiceType.objects.get_or_create( name=self.service_type.value.lower(), version=self.service_version.value)[0] service.service_type = service_type service.created_by = group service.published_for = orga_published_for service.availability = 0.0 service.is_available = False service.is_root = True md.service = service service.is_update_candidate_for = is_update_candidate_for # Save record to enable M2M relations service.save() operation_urls = [] for operation, parsed_operation_url, method in self.operation_urls: # todo: optimize as bulk create try: operation_urls.append( ServiceUrl.objects.get_or_create(operation=operation, url=getattr( self, parsed_operation_url), method=method)[0]) except IntegrityError: # empty/None url values will be ignored pass service.operation_urls.add(*operation_urls) # Persist capabilities document service.persist_original_capabilities_doc( self.service_capabilities_xml) return service
def _create_service_record(self, group: MrMapGroup, orga_published_for: Organization, md: Metadata, is_update_candidate_for: Service): """ Creates a Service object from the OGCWebFeatureService object Args: group (MrMapGroup): The owner/creator group orga_published_for (Organization): The organization for which the service is published orga_publisher (Organization): THe organization that publishes md (Metadata): The describing metadata Returns: service (Service): The persisted service object """ service = Service() service_type = ServiceType.objects.get_or_create( name=self.service_type.value.lower(), version=self.service_version.value)[0] service.service_type = service_type service.created_by = group service.published_for = orga_published_for service.availability = 0.0 service.is_available = False service.is_root = True md.service = service service.is_update_candidate_for = is_update_candidate_for # Save record to enable M2M relations service.save() operation_urls = [ ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.GET_CAPABILITIES.value, method="Get", url=self.get_capabilities_uri.get("get", None))[0], ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.GET_CAPABILITIES.value, method="Post", url=self.get_capabilities_uri.get("post", None))[0], ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.DESCRIBE_RECORD.value, method="Get", url=self.describe_record_uri.get("get", None))[0], ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.DESCRIBE_RECORD.value, method="Post", url=self.describe_record_uri.get("post", None))[0], ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.GET_RECORDS.value, method="Get", url=self.get_records_uri.get("get", None))[0], ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.GET_RECORDS.value, method="Post", url=self.get_records_uri.get("post", None))[0], ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.GET_RECORD_BY_ID.value, method="Get", url=self.get_record_by_id_uri.get("get", None))[0], ServiceUrl.objects.get_or_create( operation=OGCOperationEnum.GET_RECORD_BY_ID.value, method="Post", url=self.get_record_by_id_uri.get("post", None))[0], ] service.operation_urls.add(*operation_urls) # Persist capabilities document service.persist_original_capabilities_doc( self.service_capabilities_xml) return service