Beispiel #1
0
def reingest_aip(request, package_uuid):
    form = forms.ReingestAIPForm(request.POST or None)
    if form.is_valid():
        # POST to SS for reingest
        response = storage_service.request_reingest(
            package_uuid, form.cleaned_data['reingest_type'])
        error = response.get('error', True)
        message = response.get('message', 'An unknown error occurred.')
        if error:
            messages.error(request, 'Error re-ingesting package: {}'.format(message))
        else:
            messages.success(request, message)
        return redirect('archival_storage_index')
    return render(request, 'archival_storage/reingest_request.html', locals())
Beispiel #2
0
def view_aip(request, uuid):
    es_client = es.get_client()
    try:
        es_aip_doc = es.get_aip_data(
            es_client, uuid, fields="name,size,created,status,filePath,encrypted"
        )
    except IndexError:
        raise Http404

    source = es_aip_doc["_source"]
    name = source.get("name")
    active_tab = None

    form_upload = forms.UploadMetadataOnlyAtomForm(prefix="upload")
    form_reingest = forms.ReingestAIPForm(prefix="reingest")
    form_delete = forms.DeleteAIPForm(prefix="delete", uuid=uuid)

    # Process metadata-only DIP upload form
    if request.POST and "submit-upload-form" in request.POST:
        form_upload = forms.UploadMetadataOnlyAtomForm(request.POST, prefix="upload")
        active_tab = "upload"
        if form_upload.is_valid():
            try:
                file_slug = upload_dip_metadata_to_atom(
                    name, uuid, form_upload.cleaned_data["slug"]
                )
            except AtomMetadataUploadError:
                messages.error(
                    request,
                    _(
                        "Metadata-only DIP upload failed, check the logs for more details"
                    ),
                )
                logger.error(
                    "Unexepected error during metadata-only DIP upload (UUID: %s)",
                    uuid,
                    exc_info=True,
                )
            else:
                messages.success(
                    request,
                    _(
                        "Metadata-only DIP upload has been completed successfully. New resource has slug: %(slug)s"
                    )
                    % {"slug": file_slug},
                )
            form_upload = forms.UploadMetadataOnlyAtomForm(
                prefix="upload"
            )  # Reset form

    # Process reingest form
    if request.POST and "submit-reingest-form" in request.POST:
        form_reingest = forms.ReingestAIPForm(request.POST, prefix="reingest")
        active_tab = "reingest"
        if form_reingest.is_valid():
            response = storage_service.request_reingest(
                uuid,
                form_reingest.cleaned_data["reingest_type"],
                form_reingest.cleaned_data["processing_config"],
            )
            error = response.get("error", True)
            message = response.get("message", "An unknown error occurred.")
            if error:
                messages.error(
                    request,
                    _("Error re-ingesting package: %(message)s") % {"message": message},
                )
            else:
                messages.success(request, message)
            return redirect("archival_storage:archival_storage_index")

    # Process delete form
    if request.POST and "submit-delete-form" in request.POST:
        form_delete = forms.DeleteAIPForm(request.POST, prefix="delete", uuid=uuid)
        active_tab = "delete"
        if form_delete.is_valid():
            response = storage_service.request_file_deletion(
                uuid,
                request.user.id,
                request.user.email,
                form_delete.cleaned_data["reason"],
            )
            messages.info(request, response["message"])
            es_client = es.get_client()
            es.mark_aip_deletion_requested(es_client, uuid)
            return redirect("archival_storage:archival_storage_index")

    context = {
        "uuid": uuid,
        "name": name,
        "created": source.get("created"),
        "status": AIP_STATUS_DESCRIPTIONS[source.get("status", es.STATUS_UPLOADED)],
        "encrypted": source.get("encrypted", False),
        "size": "{0:.2f} MB".format(source.get("size", 0)),
        "location_basename": os.path.basename(source.get("filePath")),
        "active_tab": active_tab,
        "forms": {
            "upload": form_upload,
            "reingest": form_reingest,
            "delete": form_delete,
        },
    }

    return render(request, "archival_storage/view.html", context)
Beispiel #3
0
def view_aip(request, uuid):
    es_client = elasticSearchFunctions.get_client()
    try:
        es_aip_doc = elasticSearchFunctions.get_aip_data(es_client, uuid, fields='name,size,created,status,filePath,encrypted')
    except IndexError:
        raise Http404

    name = _get_es_field(es_aip_doc['fields'], 'name')
    active_tab = None

    form_upload = forms.UploadMetadataOnlyAtomForm(prefix='upload')
    form_reingest = forms.ReingestAIPForm(prefix='reingest')
    form_delete = forms.DeleteAIPForm(prefix='delete', uuid=uuid)

    # Process metadata-only DIP upload form
    if request.POST and 'submit-upload-form' in request.POST:
        form_upload = forms.UploadMetadataOnlyAtomForm(request.POST, prefix='upload')
        active_tab = 'upload'
        if form_upload.is_valid():
            try:
                file_slug = upload_dip_metadata_to_atom(name, uuid, form_upload.cleaned_data['slug'])
            except AtomMetadataUploadError:
                messages.error(request, _('Metadata-only DIP upload failed, check the logs for more details'))
                logger.error('Unexepected error during metadata-only DIP upload (UUID: %s)', uuid, exc_info=True)
            else:
                messages.success(request, _('Metadata-only DIP upload has been completed successfully. New resource has slug: %(slug)s') % {'slug': file_slug})
            form_upload = forms.UploadMetadataOnlyAtomForm(prefix='upload')  # Reset form

    # Process reingest form
    if request.POST and 'submit-reingest-form' in request.POST:
        form_reingest = forms.ReingestAIPForm(request.POST, prefix='reingest')
        active_tab = 'reingest'
        if form_reingest.is_valid():
            response = storage_service.request_reingest(uuid, form_reingest.cleaned_data['reingest_type'], form_reingest.cleaned_data['processing_config'])
            error = response.get('error', True)
            message = response.get('message', 'An unknown error occurred.')
            if error:
                messages.error(request, _('Error re-ingesting package: %(message)s') % {'message': message})
            else:
                messages.success(request, message)
            return redirect('archival_storage_index')

    # Process delete form
    if request.POST and 'submit-delete-form' in request.POST:
        form_delete = forms.DeleteAIPForm(request.POST, prefix='delete', uuid=uuid)
        active_tab = 'delete'
        if form_delete.is_valid():
            response = storage_service.request_file_deletion(uuid, request.user.id, request.user.email, form_delete.cleaned_data['reason'])
            messages.info(request, response['message'])
            es_client = elasticSearchFunctions.get_client()
            elasticSearchFunctions.mark_aip_deletion_requested(es_client, uuid)
            return redirect('archival_storage_index')

    context = {
        'uuid': uuid,
        'name': name,
        'created': _get_es_field(es_aip_doc['fields'], 'created'),
        'status': AIP_STATUS_DESCRIPTIONS[_get_es_field(es_aip_doc['fields'], 'status', 'UPLOADED')],
        'encrypted': _get_es_field(es_aip_doc['fields'], 'encrypted', False),
        'size': '{0:.2f} MB'.format(_get_es_field(es_aip_doc['fields'], 'size', 0)),
        'location_basename': os.path.basename(_get_es_field(es_aip_doc['fields'], 'filePath')),
        'active_tab': active_tab,
        'forms': {
            'upload': form_upload,
            'reingest': form_reingest,
            'delete': form_delete,
        },
    }

    return render(request, 'archival_storage/view.html', context)