Beispiel #1
0
def _get_request_uri_has_no_service_parameter(value):
    from service.helper import service_helper
    url_dict = service_helper.split_service_uri(value)

    if "service" not in url_dict or url_dict["service"] is None:
        return ValidationError(
            _('The given uri is not valid cause there is no service parameter.'
              ))
Beispiel #2
0
def _get_request_uri_has_no_request_parameter(value):
    from service.helper import service_helper
    url_dict = service_helper.split_service_uri(value)

    if "request" in url_dict and url_dict["request"] is not None:
        if url_dict["request"].lower() != "getcapabilities":
            # not allowed!
            return ValidationError(
                _('The given requested method is not GetCapabilities.'), )
    else:
        return ValidationError(
            _('The given uri is not valid cause there is no request parameter.'
              ))
Beispiel #3
0
    def get_form_initial(self, step):
        initial = self.initial_dict.get(step, {})

        if step == SECOND_STEP_ID:
            service_url_data = self.storage.get_step_data(FIRST_STEP_ID)
            uri = service_url_data.get('{}-get_request_uri'.format(FIRST_STEP_ID))
            url_dict = service_helper.split_service_uri(uri)
            is_reachable, needs_authentication, status_code = check_uri_is_reachable(uri)
            initial.update({
                'ogc_request': url_dict["request"],
                'ogc_service': url_dict["service"].value,
                'ogc_version': url_dict["version"],
                'uri': url_dict["base_uri"],
                'service_needs_authentication': needs_authentication,
            })
        return initial
Beispiel #4
0
    def create(self, validated_data, request: HttpRequest = None):
        """ Creates a new service

        Starts the regular registration process

        Args:
            validated_data (dict): The validated data from a POST request
        Returns:
             None
        """
        # Writing of .get("xy", None) or None makes sure that empty strings will be mapped to None
        user = user_helper.get_user(request=request)
        get_capabilities_uri = validated_data.get("uri", None) or None
        registering_with_group = validated_data.get("group", None) or None
        registering_for_org = validated_data.get("for-org", None) or None
        has_ext_auth = validated_data.get("ext-auth", False) or False
        ext_auth_username = validated_data.get("ext-username", None) or None
        ext_auth_password = validated_data.get("ext-password", None) or None
        ext_auth_type = validated_data.get("ext-auth-type", None) or None

        # Split uri in components as it is done with RegisterNewServiceWizardPage1
        url_dict = service_helper.split_service_uri(get_capabilities_uri)
        ogc_request = url_dict["request"]
        ogc_service = url_dict["service"].value
        ogc_version = url_dict["version"]
        uri = url_dict["base_uri"]

        init_data = {
            "ogc_request": ogc_request,
            "ogc_service": ogc_service,
            "ogc_version": ogc_version,
            "uri": uri,
            "registering_with_group": registering_with_group,
            "registering_for_other_organization": registering_for_org,
            "service_needs_authentication": has_ext_auth,
            "username": ext_auth_username,
            "password": ext_auth_password,
            "authentication_type": ext_auth_type,
        }

        # Use RegisterNewResourceWizardPage2 workflow as for frontend registration
        form = RegisterNewResourceWizardPage2(data=init_data, request=request)
        if form.is_valid():
            pending_task = service_helper.create_new_service(form, user)
            return pending_task
        return form
Beispiel #5
0
def _get_request_uri_has_no_version_parameter(value):
    from service.helper import service_helper
    url_dict = service_helper.split_service_uri(value)
    # currently supported version for wms 1.3.0, 1.1.1, 1.1.0, 1.0.0
    # currently supported version for wfs 2.0.2, 2.0.0, 1.1.0, 1.0.0
    supported_wms_versions = ['1.3.0', '1.1.1', '1.1.0', '1.0.0']
    supported_wfs_versions = ['2.0.2', '2.0.0', '1.1.0', '1.0.0']
    # Todo: append all versions
    supported_csw_versions = [
        '2.0.2',
    ]

    if "version" in url_dict and url_dict["version"] is not None:
        if "service" in url_dict or url_dict["service"] is not None:
            if url_dict["service"] == OGCServiceEnum.WMS:
                service_type = OGCServiceEnum.WMS.value
                supported_versions = supported_wms_versions
            elif url_dict["service"] == OGCServiceEnum.WFS:
                service_type = OGCServiceEnum.WFS.value
                supported_versions = supported_wfs_versions
            elif url_dict["service"] == OGCServiceEnum.CSW:
                service_type = OGCServiceEnum.CSW.value
                supported_versions = supported_csw_versions
            else:
                return ValidationError(
                    _('The given service typ is not supported from Mr. Map.'),
                )

            is_supported = False
            for version in supported_versions:
                if url_dict["version"] == version:
                    is_supported = True

            if not is_supported:
                return ValidationError(
                    _('The given {} version {} is not supported from Mr. Map.'.
                      format(service_type, url_dict["version"])), )

    else:
        return ValidationError(
            _('The given uri is not valid cause there is no version parameter.'
              ))
Beispiel #6
0
 def render_goto_step(self, goto_step, **kwargs):
     # if the current step is the first and step two has initial data, we have to overwrite the initial stored data
     # This is necessary for the following case:
     # The user inserts an url at step 1. The wizard initialize step two with the url_dict above.
     # The user decides to goto the step 1 backward and insert a new url with different data.
     # For that case the wizard doesn't get's his data from the initial data.
     # He will get his data from the storage. For that we have to store the new found initial data for step 2!
     if self.steps.current == FIRST_STEP_ID and self.storage.get_step_data(SECOND_STEP_ID):
         # initial data found for step two
         service_url_data = self.storage.get_step_data(FIRST_STEP_ID)
         uri = service_url_data.get('{}-get_request_uri'.format(FIRST_STEP_ID))
         url_dict = service_helper.split_service_uri(uri)
         is_reachable, needs_authentication, status_code = check_uri_is_reachable(uri)
         self.storage.set_step_data(SECOND_STEP_ID, {
                 'ogc_request': url_dict["request"],
                 'ogc_service': url_dict["service"].value,
                 'ogc_version': url_dict["version"],
                 'uri': url_dict["base_uri"],
                 'service_needs_authentication': needs_authentication,
             })
     return super().render_goto_step(goto_step=goto_step)
Beispiel #7
0
    def clean(self):
        cleaned_data = super(UpdateServiceCheckForm, self).clean()

        if "get_capabilities_uri" in cleaned_data:
            uri = cleaned_data.get("get_capabilities_uri")
            self.url_dict = service_helper.split_service_uri(uri)
            new_service_type = self.url_dict.get("service")

            if self.current_service.service_type.name != new_service_type.value:
                self.add_error(None, SERVICE_UPDATE_WRONG_TYPE)

        has_update_candidate_for_service = None
        try:
            # Get service object from db
            has_update_candidate_for_service = Service.objects.get(
                is_update_candidate_for=self.current_service)
        except ObjectDoesNotExist:
            pass

        if has_update_candidate_for_service:
            user = has_update_candidate_for_service.created_by_user \
                if has_update_candidate_for_service.created_by_user is not None \
                else 'unknown'

            self.add_error(
                None,
                _("There are still pending update requests from user '{}' for this service."
                  ).format(user))

            if self.requesting_user == user:
                self.add_error(
                    None,
                    format_html(
                        "See your pending update request <a href={}>here.</a>",
                        reverse_lazy(
                            'resource:pending-update',
                            args=(self.current_service.metadata.id, ))))
                # ToDo: check if user is in group of created_by field of update_cadidate

        return cleaned_data
Beispiel #8
0
    def get_service_metadata_from_capabilities(self, xml_obj):
        """ Parse the capability document <Service> metadata into the self object

        Args:
            xml_obj: A minidom object which holds the xml content
        Returns:
             Nothing
        """
        service_xml = xml_helper.try_get_single_element_from_xml(
            "//" + GENERIC_NAMESPACE_TEMPLATE.format("ServiceIdentification"),
            xml_obj
        )
        self.service_identification_title = xml_helper.try_get_text_from_xml_element(
            xml_elem=service_xml,
            elem="./" + GENERIC_NAMESPACE_TEMPLATE.format("Title")
        )
        if current_task:
            current_task.update_state(
                state=states.STARTED,
                meta={'service': self.service_identification_title, 'phase': 'Parsing main capabilities'}
            )

        self.service_identification_abstract = xml_helper.try_get_text_from_xml_element(
            xml_elem=service_xml,
            elem="./" + GENERIC_NAMESPACE_TEMPLATE.format("Abstract")
        )

        self.service_identification_fees = xml_helper.try_get_text_from_xml_element(
            xml_elem=service_xml,
            elem="./" + GENERIC_NAMESPACE_TEMPLATE.format("Fees")
        )

        self.service_identification_accessconstraints = xml_helper.try_get_text_from_xml_element(
            xml_elem=service_xml,
            elem="./" + GENERIC_NAMESPACE_TEMPLATE.format("AccessConstraints")
        )

        keywords = xml_helper.try_get_element_from_xml(
            xml_elem=service_xml,
            elem="./" + GENERIC_NAMESPACE_TEMPLATE.format("Keywords") +
                 "/" + GENERIC_NAMESPACE_TEMPLATE.format("Keyword")
        )
        kw = []
        for keyword in keywords:
            text = keyword.text
            if text is None:
                continue
            try:
                kw.append(text)
            except AttributeError:
                pass
        self.service_identification_keywords = kw

        self.service_provider_providername = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("ProviderName")
        )

        provider_site_elem = xml_helper.try_get_single_element_from_xml(
            "//" + GENERIC_NAMESPACE_TEMPLATE.format("ProviderSite"),
            xml_obj
        )
        self.service_provider_url = xml_helper.get_href_attribute(xml_elem=provider_site_elem)
        self.service_provider_responsibleparty_individualname = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("IndividualName")
        )
        self.service_provider_responsibleparty_positionname = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("PositionName")
        )
        self.service_provider_telephone_voice = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("Voice")
        )
        self.service_provider_telephone_facsimile = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("Facsimile")
        )
        self.service_provider_address = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("DeliveryPoint")
        )
        self.service_provider_address_city = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("City")
        )
        self.service_provider_address_state_or_province = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("AdministrativeArea")
        )
        self.service_provider_address_postalcode = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("PostalCode")
        )
        self.service_provider_address_country = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("Country")
        )
        self.service_provider_address_electronicmailaddress = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("ElectronicMailAddress")
        )
        online_resource_elem = xml_helper.try_get_single_element_from_xml(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("OnlineResource")
        )
        self.service_provider_onlineresource_linkage = xml_helper.get_href_attribute(online_resource_elem)
        if self.service_provider_onlineresource_linkage is None or self.service_provider_onlineresource_linkage == "":
            # There are metadatas where no online resource link is given. We need to generate it manually therefore...
            self.service_provider_onlineresource_linkage = service_helper.split_service_uri(self.service_connect_url).get("base_uri")
            self.service_provider_onlineresource_linkage = service_helper.prepare_original_uri_stump(self.service_provider_onlineresource_linkage)

        self.service_provider_contact_hoursofservice = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("HoursOfService")
        )
        self.service_provider_contact_contactinstructions = xml_helper.try_get_text_from_xml_element(
            xml_elem=xml_obj,
            elem="//" + GENERIC_NAMESPACE_TEMPLATE.format("ContactInstructions")
        )