Esempio n. 1
0
def resolve_ark(request, naan, noid, qual=''):
    '''Resolve an ARK or qualified ARK to the appropriate target URL.

    Sample ARK URLs:
        http://pid.emory.edu/ark:/25593/rg8kw     *(unqualified)*
        http://pid.emory.edu/ark:/25593/17s6q/PDF *(qualified)*
        `http://pid.emory.edu/ark:/25593/rg8kw? <http://pid.emory.edu/ark:/25593/rg8kw?>`_  *(metadata)*
        `http://pid.emory.edu/ark:/25593/rg8kw?? <http://pid.emory.edu/ark:/25593/rg8kw??>`_ *(commitment statement)*

    If there are no qualifiers and the URL ends with single question mark,
    returns minimal metadata about the ARK.  If the URL ends with two question
    marks, returns the commitment statement for the requested ARK.  See
    :meth:`ark_metadata` for more information.
    '''
    noid = normalize_ark(noid)
    if qual:
        qual = normalize_ark(qual)

    full_path = request.get_full_path()
    # if last letter is ? then metadata or preservation commitment should be displayed
    # NOTE: REQUEST_URI is *ONLY* available when running under mod_wsgi,
    # and full path only includes ? if there is a query string.
    # See README file for more details.
    if qual == '' and full_path[-1] == "?" or ('REQUEST_URI' in request.META.keys()
        and request.META['REQUEST_URI'][-1] == "?"):
        return ark_metadata(request, noid)
    return resolve_pid(noid, qual)
Esempio n. 2
0
    def save(self, force_insert=False, force_update=False, *args, **kwargs):
        """
        Custom save method.  When present, replace a special token string
        (configured in django settings as **PID_REPLACEMENT_TOKEN**) in the
        target uri with the noid.  Also ensures that pid and noid stay
        synchronized, check that qualifier does not contain any invalid characters,
        and normalizes ARK qualifier so it will be resolved correctly.
        """
        # a special token in target URI should be replaced with minted noid
        if (self.uri.find(settings.PID_REPLACEMENT_TOKEN) != -1):
            # Note: not using self.noid because it doesn't seem to be set yet
            self.uri = self.uri.replace(settings.PID_REPLACEMENT_TOKEN, self.pid.pid)

        #keep noid and pid in sync
        if(not self.noid):
            self.noid = self.pid.pid
        elif(self.noid != self.pid.pid):
            raise ValidationError("Target.noid(%s) and Pid(%s) do not match)"%(self.noid, self.pid.pid))

        # if qualifier is not valid, it should not be saved
        if not(valid_qualifier(self.qualify)):
            raise ValidationError("Qualifier '%s' contains invalid characters"%(self.qualify))

        # normalize so qualifier will be found by the resolver
        self.qualify = normalize_ark(self.qualify)
        return super(Target, self).save(force_insert=force_insert, force_update=force_update, *args, **kwargs)
Esempio n. 3
0
    def save(self, force_insert=False, force_update=False, *args, **kwargs):
        """
        Custom save method.  When present, replace a special token string
        (configured in django settings as **PID_REPLACEMENT_TOKEN**) in the
        target uri with the noid.  Also ensures that pid and noid stay
        synchronized, check that qualifier does not contain any invalid characters,
        and normalizes ARK qualifier so it will be resolved correctly.
        """
        # a special token in target URI should be replaced with minted noid
        if (self.uri.find(settings.PID_REPLACEMENT_TOKEN) != -1):
            # Note: not using self.noid because it doesn't seem to be set yet
            self.uri = self.uri.replace(settings.PID_REPLACEMENT_TOKEN,
                                        self.pid.pid)

        #keep noid and pid in sync
        if (not self.noid):
            self.noid = self.pid.pid
        elif (self.noid != self.pid.pid):
            raise ValidationError("Target.noid(%s) and Pid(%s) do not match)" %
                                  (self.noid, self.pid.pid))

        # if qualifier is not valid, it should not be saved
        if not (valid_qualifier(self.qualify)):
            raise ValidationError(
                "Qualifier '%s' contains invalid characters" % (self.qualify))

        # normalize so qualifier will be found by the resolver
        self.qualify = normalize_ark(self.qualify)
        return super(Target, self).save(force_insert=force_insert,
                                        force_update=force_update,
                                        *args,
                                        **kwargs)
Esempio n. 4
0
 def clean_qualify(self):
     # check for any characters not allowed in the qualifier
     invalid_chars = invalid_qualifier_characters(self.cleaned_data["qualify"])
     if invalid_chars:
         raise ValidationError("Not permitted: " + ', '.join(invalid_chars))
     # normalize according to how the ARK will be resolved
     return normalize_ark(self.cleaned_data["qualify"])
Esempio n. 5
0
 def clean_qualify(self):
     # check for any characters not allowed in the qualifier
     invalid_chars = invalid_qualifier_characters(
         self.cleaned_data["qualify"])
     if invalid_chars:
         raise ValidationError("Not permitted: " + ', '.join(invalid_chars))
     # normalize according to how the ARK will be resolved
     return normalize_ark(self.cleaned_data["qualify"])
Esempio n. 6
0
    def test_normalize_ark(self):
        # examples here are from the character repertoires section of ARK spec
        n = normalize_ark("65-4-xz-321")
        self.assertEqual(
            "654xz321", n,
            "65-4-xz-321 should be normalized to 654xz321, got '" + n + "'")
        n = normalize_ark("654--xz32-1")
        self.assertEqual(
            "654xz321", n,
            "654--xz32-1 should be normalized to 654xz321, got '" + n + "'")
        n = normalize_ark("654xz321")
        self.assertEqual(
            "654xz321", n,
            "654xz321 should be normalized to 654xz321, got '" + n + "'")

        # remove / or . as last char
        n = normalize_ark("654.")
        self.assertEqual("654", n,
                         "654. should be normalized to 654, got '" + n + "'")
        n = normalize_ark("654/")
        self.assertEqual("654", n,
                         "654/ should be normalized to 654, got '" + n + "'")
        n = normalize_ark("6-5-4.")
        self.assertEqual("654", n,
                         "6-5-4. should be normalized to 654, got '" + n + "'")
Esempio n. 7
0
    def test_normalize_ark(self):
        # examples here are from the character repertoires section of ARK spec
        n = normalize_ark("65-4-xz-321")
        self.assertEqual("654xz321", n,
            "65-4-xz-321 should be normalized to 654xz321, got '" + n + "'")
        n = normalize_ark("654--xz32-1")
        self.assertEqual("654xz321", n,
            "654--xz32-1 should be normalized to 654xz321, got '" + n + "'")
        n = normalize_ark("654xz321")
        self.assertEqual("654xz321", n,
            "654xz321 should be normalized to 654xz321, got '" + n + "'")

        # remove / or . as last char
        n = normalize_ark("654.")
        self.assertEqual("654", n, "654. should be normalized to 654, got '" + n + "'")
        n = normalize_ark("654/")
        self.assertEqual("654", n, "654/ should be normalized to 654, got '" + n + "'")
        n = normalize_ark("6-5-4.")
        self.assertEqual("654", n, "6-5-4. should be normalized to 654, got '" + n +"'")