예제 #1
0
def reingest_approve(request):
    """Approve an AIP partial re-ingest.

    - Method:      POST
    - URL:         api/ingest/reingest/approve
    - POST params:
                   - username -- AM username
                   - api_key  -- AM API key
                   - uuid     -- SIP UUID

    TODO: this is just a temporary way of getting the API to do the
    equivalent of clicking "Approve AIP reingest" in the dashboard when faced
    with "Approve AIP reingest". This is non-dry given
    ``approve_transfer_via_mcp`` above and should probably me made congruent
    with that function and ``approve_transfer``.
    """
    sip_uuid = request.POST.get('uuid')
    if sip_uuid is None:
        response = {'error': True, 'message': '"uuid" is required.'}
        return helpers.json_response(response, status_code=400)
    job = models.Job.objects.filter(
        sipuuid=sip_uuid,
        microservicegroup='Reingest AIP',
        currentstep=models.Job.STATUS_AWAITING_DECISION).first()
    if job:
        chain = models.MicroServiceChainChoice.objects.filter(
            choiceavailableatlink__currenttask__description=
            'Approve AIP reingest',
            chainavailable__description='Approve AIP reingest').first()

        if chain:
            approve_aip_reingest_choice_uuid = chain.chainavailable.pk
            client = MCPClient()
            client.execute(job.pk, approve_aip_reingest_choice_uuid,
                           request.user.id)

            response = {'message': 'Approval successful.'}
        else:
            # No choice was found.
            response = {
                'error': True,
                'message': 'Could not find choice for approve AIP reingest'
            }
            return helpers.json_response(response, status_code=400)

        return helpers.json_response(response)
    else:
        # No job to be found.
        response = {
            'error':
            True,
            'message': ('There is no "Reingest AIP" job awaiting a'
                        ' decision for SIP {}'.format(sip_uuid))
        }
        return helpers.json_response(response, status_code=400)
예제 #2
0
def approve_transfer_via_mcp(directory, type, user_id):
    error = None

    if (directory != ''):
        # assemble transfer path
        modified_transfer_path = get_modified_standard_transfer_path(type)

        if modified_transfer_path == None:
            error = 'Invalid transfer type.'
        else:
            transfer_path = os.path.join(modified_transfer_path, directory) + '/'

            # look up job UUID using transfer path
            try:
                job = models.Job.objects.filter(directory=transfer_path, currentstep='Awaiting decision')[0]

                # approve transfer
                client = MCPClient()

                # 3rd arg should be uid?
                result = client.execute(job.pk, 'Approve', user_id)

            except:
                error = 'Unable to find unapproved transfer directory.'

    else:
        error = 'Please specify a transfer directory.'

    return error
예제 #3
0
def approve_transfer_via_mcp(directory, type, user_id):
    error = None

    if (directory != ''):
        # assemble transfer path
        modified_transfer_path = get_modified_standard_transfer_path(type)

        if modified_transfer_path == None:
            error = 'Invalid transfer type.'
        else:
            transfer_path = os.path.join(modified_transfer_path,
                                         directory) + '/'

            # look up job UUID using transfer path
            try:
                job = models.Job.objects.filter(
                    directory=transfer_path,
                    currentstep='Awaiting decision')[0]

                # approve transfer
                client = MCPClient()

                # 3rd arg should be uid?
                result = client.execute(job.pk, 'Approve', user_id)

            except:
                error = 'Unable to find unapproved transfer directory.'

    else:
        error = 'Please specify a transfer directory.'

    return error
예제 #4
0
def execute(request):
    result = ''
    if 'uuid' in request.REQUEST:
        client = MCPClient()
        uuid = request.REQUEST.get('uuid', '')
        choice = request.REQUEST.get('choice', '')
        result = client.execute(uuid, choice)
    return HttpResponse(result, mimetype = 'text/plain')
예제 #5
0
def execute(request):
    result = ""
    if "uuid" in request.REQUEST:
        client = MCPClient()
        uuid = request.REQUEST.get("uuid", "")
        choice = request.REQUEST.get("choice", "")
        result = client.execute(uuid, choice)
    return HttpResponse(result, mimetype="text/plain")
예제 #6
0
def execute(request):
    result = ""
    if request.POST.get("uuid"):
        client = MCPClient(request.user)
        result = client.execute(
            request.POST.get("uuid"), request.POST.get("choice", "")
        )
    return HttpResponse(result, content_type="text/plain")
예제 #7
0
def approve_transfer_via_mcp(directory, type, user_id):
    error = None

    if (directory != ''):
        # assemble transfer path
        modified_transfer_path = get_modified_standard_transfer_path(type)

        if modified_transfer_path == None:
            error = 'Invalid transfer type.'
        else:
            if type == 'zipped bag':
                transfer_path = os.path.join(modified_transfer_path, directory)
            else:
                transfer_path = os.path.join(modified_transfer_path, directory) + '/'

            # look up job UUID using transfer path
            try:
                job = models.Job.objects.filter(directory=transfer_path, currentstep='Awaiting decision')[0]

                type_task_config_descriptions = {
                    'standard':     'Approve standard transfer',
                    'unzipped bag': 'Approve bagit transfer',
                    'zipped bag':   'Approve zipped bagit transfer',
                    'dspace':       'Approve DSpace transfer',
                    'maildir':      'Approve maildir transfer',
                    'TRIM':         'Approve TRIM transfer'
                }

                type_description = type_task_config_descriptions[type]

                # use transfer type to fetch possible choices to execute
                task = models.TaskConfig.objects.get(description=type_description)
                link = models.MicroServiceChainLink.objects.get(currenttask=task.pk)
                choices = models.MicroServiceChainChoice.objects.filter(choiceavailableatlink=link.pk)

                # attempt to find appropriate choice
                chain_to_execute = None
                for choice in choices:
                    chain = models.MicroServiceChain.objects.get(pk=choice.chainavailable)
                    if chain.description == 'Approve transfer':
                        chain_to_execute=chain.pk

                # execute choice if found
                if chain_to_execute != None:
                    client = MCPClient()

                    result = client.execute(job.pk, chain_to_execute, user_id)
                else:
                    error = 'Error: could not find MCP choice to execute.'

            except:
                error = 'Unable to find unapproved transfer directory.'

    else:
        error = 'Please specify a transfer directory.'

    return error
예제 #8
0
def execute(request):
    result = ''
    if request.POST.get('uuid'):
        client = MCPClient(request.user)
        result = client.execute(
            request.POST.get('uuid'),
            request.POST.get('choice', ''),
        )
    return HttpResponse(result, content_type='text/plain')
예제 #9
0
def execute(request):
    result = ''
    if 'uuid' in request.REQUEST:
        client = MCPClient()
        uuid = request.REQUEST.get('uuid', '')
        choice = request.REQUEST.get('choice', '')
        uid = request.REQUEST.get('uid', '')
        result = client.execute(uuid, choice, uid)
    return HttpResponse(result, mimetype='text/plain')
예제 #10
0
def approve_transfer_via_mcp(directory, transfer_type, user_id):
    error = None
    unit_uuid = None
    if (directory != ''):
        # assemble transfer path
        modified_transfer_path = get_modified_standard_transfer_path(
            transfer_type)

        if modified_transfer_path is None:
            error = 'Invalid transfer type.'
        else:
            db_transfer_path = os.path.join(modified_transfer_path, directory)
            transfer_path = db_transfer_path.replace('%sharedPath%',
                                                     SHARED_DIRECTORY_ROOT, 1)
            # Ensure directories end with /
            if os.path.isdir(transfer_path):
                db_transfer_path = os.path.join(db_transfer_path, '')
            # look up job UUID using transfer path
            try:
                job = models.Job.objects.filter(
                    directory=db_transfer_path,
                    currentstep='Awaiting decision')[0]
                unit_uuid = job.sipuuid

                type_task_config_descriptions = {
                    'standard': 'Approve standard transfer',
                    'unzipped bag': 'Approve bagit transfer',
                    'zipped bag': 'Approve zipped bagit transfer',
                    'dspace': 'Approve DSpace transfer',
                    'maildir': 'Approve maildir transfer',
                    'TRIM': 'Approve TRIM transfer'
                }

                type_description = type_task_config_descriptions[transfer_type]

                # use transfer type to fetch possible choices to execute
                choices = models.MicroServiceChainChoice.objects.filter(
                    choiceavailableatlink__currenttask__description=
                    type_description)

                # attempt to find appropriate choice
                chain_to_execute = None
                for choice in choices:
                    if choice.chainavailable.description == 'Approve transfer':
                        chain_to_execute = choice.chainavailable.pk

                # execute choice if found
                if chain_to_execute is not None:
                    client = MCPClient()
                    client.execute(job.pk, chain_to_execute, user_id)
                else:
                    error = 'Error: could not find MCP choice to execute.'

            except Exception:
                error = 'Unable to find unapproved transfer directory.'
                # logging.exception(error)

    else:
        error = 'Please specify a transfer directory.'

    return error, unit_uuid