예제 #1
0
def get_cmis_client() -> Union[CMISDRCClient, SOAPCMISClient]:
    """Build the CMIS client with the binding specified in the configuration"""
    config = CMISConfig.get_solo()
    if config.binding == "WEBSERVICE":
        return SOAPCMISClient()
    else:
        return CMISDRCClient()
예제 #2
0
    def test_retrieve_oio_no_url_mapping(self):
        config = CMISConfig.get_solo()
        UrlMapping.objects.create(
            long_pattern="https://externe.catalogus.nl",
            short_pattern="https://xcat.nl",
            config=config,
        )
        Service.objects.create(
            api_type=APITypes.zrc,
            api_root="https://externe.catalogus.nl/api/v1/",
            label="external zaken",
            auth_type=AuthTypes.no_auth,
        )

        zaak = "https://externe.catalogus.nl/api/v1/zaken/1c8e36be-338c-4c07-ac5e-1adf55bec04a"
        zaaktype = "https://externe.catalogus.nl/api/v1/zaaktypen/b71f72ef-198d-44d8-af64-ae1932df830a"
        catalogus = "https://externe.catalogus.nl/api/v1/catalogussen/5c4c492b-3548-4258-b17f-0e2e31dcfe25"

        mock_service_oas_get(self.adapter, APITypes.zrc,
                             "https://externe.catalogus.nl/api/v1/")

        self.adapter.get(zaak, json=get_zaak_response(zaak, zaaktype))
        self.adapter.get(zaaktype, json=get_zaak_response(catalogus, zaaktype))

        eio1 = EnkelvoudigInformatieObjectFactory.create()
        oio1 = ObjectInformatieObject.objects.create(
            informatieobject=f"http://testserver{reverse(eio1)}",
            zaak=zaak,
            object_type="zaak",
        )

        eio2 = EnkelvoudigInformatieObjectFactory.create()
        ObjectInformatieObject.objects.create(
            informatieobject=f"http://testserver{reverse(eio2)}",
            zaak=zaak,
            object_type="zaak",
        )

        # Remove all available mappings
        UrlMapping.objects.all().delete()

        response = self.client.get(reverse(oio1))

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.data)
        self.assertEqual(
            response.data["detail"],
            "CMIS-adapter could not shrink one of the URL fields.",
        )
예제 #3
0
    def test_shorten_url(self):
        config = CMISConfig.get_solo()

        UrlMapping.objects.create(
            long_pattern="https://openzaak.utrechtproeftuin.nl/zaken/",
            short_pattern="https://oz.nl/",
            config=config,
        )

        long_url = "https://openzaak.utrechtproeftuin.nl/zaken/api/v1/zaakinformatieobjecten/fc345347-3115-4f0a-8808-e392d66e1886"
        short_url = shrink_url(long_url)

        self.assertEqual(
            short_url,
            "https://oz.nl/api/v1/zaakinformatieobjecten/fc345347-3115-4f0a-8808-e392d66e1886",
        )
예제 #4
0
def find_matching_pattern(url: str, field: str = None) -> str:
    from drc_cmis.models import CMISConfig

    if field is None:
        field = "long_pattern"

    config = CMISConfig.get_solo()

    patterns = config.urlmapping_set.values_list(field, flat=True)

    matching_patterns = []
    for pattern in patterns:
        if pattern in url:
            matching_patterns.append(pattern)

    if len(matching_patterns) == 0:
        raise NoURLMappingException
    elif len(matching_patterns) > 1:
        return sorted(matching_patterns, key=len, reverse=True)[0]
    else:
        return matching_patterns[0]