Ejemplo n.º 1
0
def _import_file_from_fsentry(cmd, fsentry, transfer_uuid):
    premis_events = fsentry.get_premis_events()

    ingestion_date = None
    for evt in fsentry.get_premis_events():
        if evt.event_type == "ingestion":
            ingestion_date = evt.event_date_time
            break

    file_obj = addFileToTransfer(
        "%transferDirectory%{}".format(fsentry.path),
        fsentry.file_uuid,
        transfer_uuid,
        None,
        ingestion_date,
        sourceType="ingestion",
        use="original",
    )

    for rights_statement in fsentry.get_premis_rights():
        load_rights(file_obj, rights_statement)

    for event in premis_events:
        _load_event(file_obj, event)

    try:
        premis_object = fsentry.get_premis_objects()[0]
    except IndexError:
        return

    # Populate extra attributes in the File object.
    file_obj.checksum = premis_object.message_digest
    file_obj.checksumtype = _convert_checksum_algo(
        premis_object.message_digest_algorithm
    )
    file_obj.size = premis_object.size
    file_obj.save()

    # Populate format details of the File object.
    if premis_object.format_registry_name != "PRONOM":
        return
    try:
        format_version = FormatVersion.active.get(
            pronom_id=premis_object.format_registry_key
        )
    except FormatVersion.DoesNotExist:
        return
    FileFormatVersion.objects.create(file_uuid=file_obj, format_version=format_version)
    FileID.objects.create(
        file=file_obj,
        format_name=format_version.format.description,
        format_version=format_version.version or "",
        format_registry_name=premis_object.format_registry_name,
        format_registry_key=premis_object.format_registry_key,
    )
Ejemplo n.º 2
0
def test_load_rights_with_basis_other(file, rights_statement_with_basis_other):
    stmt = load.load_rights(file, rights_statement_with_basis_other)

    assert stmt.rightsbasis == "Other"
    otherrights = stmt.rightsstatementotherrightsinformation_set.all()
    assert len(otherrights) == 1
    assert otherrights[0].otherrightsbasis == "Foobar"
    assert (
        otherrights[0]
        .rightsstatementotherrightsinformationnote_set.all()[0]
        .otherrightsnote
        == "Dummy note 1"
    )
    assert (
        otherrights[0]
        .rightsstatementotherrightsdocumentationidentifier_set.all()[0]
        .otherrightsdocumentationidentifiertype
        == "UUID"
    )
    assert (
        otherrights[0]
        .rightsstatementotherrightsdocumentationidentifier_set.all()[0]
        .otherrightsdocumentationidentifiervalue
        == "a59b5006-23c4-4195-bc1e-7d1855d555cc"
    )
    assert (
        otherrights[0]
        .rightsstatementotherrightsdocumentationidentifier_set.all()[0]
        .otherrightsdocumentationidentifierrole
        == "role"
    )
Ejemplo n.º 3
0
def test_load_rights_with_basis_statute(file, rights_statement_with_basis_statute):
    stmt = load.load_rights(file, rights_statement_with_basis_statute)

    assert stmt.rightsbasis == "Statute"
    statute = stmt.rightsstatementstatuteinformation_set.all()
    assert len(statute) == 1
    assert statute[0].statutejurisdiction == "Jurisdiction"
    assert statute[0].statutecitation == "Citation"
    assert statute[0].statutedeterminationdate == "2015"
    assert (
        statute[0].rightsstatementstatuteinformationnote_set.all()[0].statutenote
        == "Dummy note 1"
    )
    assert (
        statute[0]
        .rightsstatementstatutedocumentationidentifier_set.all()[0]
        .statutedocumentationidentifiertype
        == "UUID"
    )
    assert (
        statute[0]
        .rightsstatementstatutedocumentationidentifier_set.all()[0]
        .statutedocumentationidentifiervalue
        == "a59b5006-23c4-4195-bc1e-7d1855d555cc"
    )
    assert (
        statute[0]
        .rightsstatementstatutedocumentationidentifier_set.all()[0]
        .statutedocumentationidentifierrole
        == "role"
    )
Ejemplo n.º 4
0
def test_load_rights_with_basis_license(file, rights_statement_with_basis_license):
    stmt = load.load_rights(file, rights_statement_with_basis_license)

    assert stmt.rightsbasis == "License"
    license = stmt.rightsstatementlicense_set.all()
    assert len(license) == 1
    assert license[0].licenseterms == "Dummy license terms"
    assert (
        license[0].rightsstatementlicensenote_set.all()[0].licensenote == "Dummy note 1"
    )
    assert (
        license[0]
        .rightsstatementlicensedocumentationidentifier_set.all()[0]
        .licensedocumentationidentifiertype
        == "UUID"
    )
    assert (
        license[0]
        .rightsstatementlicensedocumentationidentifier_set.all()[0]
        .licensedocumentationidentifiervalue
        == "a59b5006-23c4-4195-bc1e-7d1855d555cc"
    )
    assert (
        license[0]
        .rightsstatementlicensedocumentationidentifier_set.all()[0]
        .licensedocumentationidentifierrole
        == "role"
    )
Ejemplo n.º 5
0
def test_load_rights_with_basis_copyright(file, rights_statement_with_basis_copyright):
    stmt = load.load_rights(file, rights_statement_with_basis_copyright)

    assert stmt.rightsbasis == "Copyright"
    copyrights = stmt.rightsstatementcopyright_set.all()
    assert len(copyrights) == 1
    assert copyrights[0].copyrightstatus == "under copyright"
    assert copyrights[0].copyrightjurisdiction == "CA"
    assert copyrights[0].copyrightstatusdeterminationdate == "2015"
    assert (
        copyrights[0].rightsstatementcopyrightnote_set.all()[0].copyrightnote
        == "Dummy note 1"
    )
    assert (
        copyrights[0]
        .rightsstatementcopyrightdocumentationidentifier_set.all()[0]
        .copyrightdocumentationidentifiertype
        == "UUID"
    )
    assert (
        copyrights[0]
        .rightsstatementcopyrightdocumentationidentifier_set.all()[0]
        .copyrightdocumentationidentifiervalue
        == "a59b5006-23c4-4195-bc1e-7d1855d555cc"
    )
    assert (
        copyrights[0]
        .rightsstatementcopyrightdocumentationidentifier_set.all()[0]
        .copyrightdocumentationidentifierrole
        == "role"
    )
Ejemplo n.º 6
0
def test_load_rights(file, rights_statement_with_basis_copyright):
    stmt = load.load_rights(file, rights_statement_with_basis_copyright)
    assert stmt.metadataappliestotype.description == "File"
    assert stmt.metadataappliestoidentifier == file.uuid
    assert stmt.rightsstatementidentifiertype == "UUID"
    assert stmt.rightsstatementidentifiervalue == "3a9838ac-ebe9-4ecb-ba46-c31ee1d6e7c2"

    rights_granted = stmt.rightsstatementrightsgranted_set.all()
    assert len(rights_granted) == 2
    assert rights_granted[0].act == "Disseminate"
    assert rights_granted[0].restrictions.all()[0].restriction == "Allow"
    assert rights_granted[0].notes.all(
    )[0].rightsgrantednote == "Attribution required"
    assert rights_granted[0].startdate == "2000"
    assert rights_granted[0].enddate is None
    assert rights_granted[0].enddateopen is True
    assert rights_granted[1].act == "Access"
    assert rights_granted[1].restrictions.all()[0].restriction == "Allow"
    assert (rights_granted[1].notes.all()[0].rightsgrantednote ==
            "Access one year before dissemination")
    assert rights_granted[1].startdate == "1999"
    assert rights_granted[1].enddate is None
    assert rights_granted[1].enddateopen is True