Beispiel #1
0
def create(request):
    if request.method == 'POST':
        if 'convert' in request.POST or 'randomize' in request.POST:
            graphml_str = request.POST["graphml"]
            filename = request.POST["filename"]
            provn_str, output = convert_graphml_string(graphml_str)
            output_list = output.splitlines()
            output_list.sort()
 
            valid, validation_url = validate(provn_str)
            if valid:
                json_str = provn_str.get_provjson()
            else:
                json_str={}
                
            if 'randomize' in request.POST:
                json_str = json.dumps(get_random_graph(json.loads(json_str)))
            
            return render_to_response('provmanager/create.html', {"output_list":output_list, "filename":filename, "graphml_str": graphml_str, "json_str": json_str, "valid":valid, "validation_url":validation_url}, context_instance=RequestContext(request))

        elif 'save' in request.POST:
            graphml_str = request.POST["graphml"]
            provn_str, output = convert_graphml_string(graphml_str)
            valid, validation_url = validate(provn_str)
            if valid:
                name = request.POST["filename"]
                if name=="":
                    name = "PLEASE ENTER A NAME"
                
                inconsistencies_list, clean_graph = get_inconsistencies(json.loads(provn_str.get_provjson()))

                if inconsistencies_list:
                    attribute1 = json.dumps(inconsistencies_list[0])
                    attribute2 = json.dumps(inconsistencies_list[1])
                    type = Provenance.TYPE_CRON
                else:
                    attribute1 = None
                    attribute2 = None
                    #TODO: is there a better way to check the type?
                    #if there are no inconsistencies, then we assume it is a MOP_TEMPLATE provenance document
                    type = Provenance.TYPE_MOP_TEMPLATE
  
                bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
                
                store_id = API.submit_document(bundle, name, public=False)

                provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=type)
                provenance.save()
                return HttpResponseRedirect(reverse('provmanager_index'))
            
            
    return render_to_response('provmanager/create.html', context_instance=RequestContext(request))
Beispiel #2
0
def view_randomize(request, id):
    provenance = Provenance.objects.get(id=id)
    json_str = getProvJsonStr(provenance)
    
    random_graph = get_random_graph(json.loads(json_str))
    inconsistencies_list, clean_graph = get_inconsistencies(random_graph)

    request.session['attribute1'] = json.dumps(inconsistencies_list[0])
    request.session['attribute2'] = json.dumps(inconsistencies_list[1])
    request.session['prov_id'] = provenance.id
    
            
    return render(request, 'provmanager/view_randomize.html', {'provenance_name':provenance.name, 'provenance_store_id':provenance.store_id, 'json_str':json.dumps(clean_graph) })
Beispiel #3
0
def randomize_document(mopDocument):
    #bundle = API.get_document(task.provenance.store_id)
    #TODO randomize provn/json
    json_graph = getProvJson(mopDocument.provenance)
    random_graph = get_random_graph(json_graph)
    inconsistencies_list, clean_graph = get_inconsistencies(random_graph)

    attribute1 = json.dumps(inconsistencies_list[0])
    attribute2 = json.dumps(inconsistencies_list[1])

    bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
    name = "%s (randomized)" % (mopDocument.provenance.name)
    store_id = API.submit_document(bundle, name, public=False)
    provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=Provenance.TYPE_MOP_INSTANCE)
    provenance.save()
        
    randomizedDocument = RandomizedDocument.objects.create(mopDocument=mopDocument, provenance=provenance)
    return randomizedDocument
Beispiel #4
0
def view_randomize(request, id):
    provenance = Provenance.objects.get(id=id)
    json_str = getProvJsonStr(provenance)
    
    random_graph = get_random_graph(json.loads(json_str))
    inconsistencies_list, clean_graph = get_inconsistencies(random_graph)
    
    if inconsistencies_list:
        request.session['attribute1'] = json.dumps(inconsistencies_list[0])
        request.session['attribute2'] = json.dumps(inconsistencies_list[1])
    else:
        request.session['attribute1'] = None
        request.session['attribute2'] = None
    request.session['prov_id'] = provenance.id
    
    try:
        guide = provenance.document.guide
    except:
        guide = None
        
    json_str = json.dumps(clean_graph, sort_keys=True, indent=4, separators=(',', ': '))
    return render(request, 'provmanager/view_randomize.html', {'inconsistencies_list':inconsistencies_list, 'provenance_name':provenance.name, 'provenance_store_id':provenance.store_id, 'json_str':json_str, 'guide':guide })
Beispiel #5
0
def create(request):
    if request.method == 'POST':
        if 'convertMop' in request.POST or 'convertCron' in request.POST or 'randomize' in request.POST:
            if 'convertCron' in request.POST:
                isCron = True
                isMop = False
            else:
                isCron = False
                isMop = True
            #graphml_str = request.POST["graphml"]
            filename, graphml_str = getStuff(request)
            
            
            provn_str, output = convert_graphml_string(graphml_str)
            output_list = output.splitlines()
            output_list.sort()

            valid = True
            validation_url = "bla"
            #valid, validation_url = validate(provn_str)
            if valid:
                json_str = provn_str.get_provjson()
            else:
                json_str={}
            
            #print json_str
                
            inconsistencies_list = None
            spoilers = False
            if 'randomize' in request.POST:
                print request.POST
                random_graph = get_random_graph(json.loads(json_str))
                json_str = json.dumps(random_graph)
                inconsistencies_list, clean_graph = get_inconsistencies(random_graph)
                if 'spoilers' in request.POST: 
                    spoilers = True
                else:
                    spoilers = False
                    json_str = json.dumps(clean_graph)
                print spoilers
                
                
            return render(request, 'provmanager/create.html', {"inconsistencies_list":inconsistencies_list, "spoilers":spoilers, "output_list":output_list, "filename":filename, "json_str": json_str, "isMop":isMop, "isCron":isCron, "valid":valid, "validation_url":validation_url})

        elif 'saveMop' in request.POST or 'saveCron' in request.POST:
            if 'saveCron' in request.POST:
                type = Provenance.TYPE_CRON
            else:
                type = Provenance.TYPE_MOP_TEMPLATE
            
            filename, graphml_str = getStuff(request)
            provn_str, output = convert_graphml_string(graphml_str)
            
            valid = True
            validation_url = "bla"
            #valid, validation_url = validate(provn_str)
            if valid:
                name = request.POST["filename"]
                if name=="":
                    name = "PLEASE ENTER A NAME"
                
                inconsistencies_list, clean_graph = get_inconsistencies(json.loads(provn_str.get_provjson()))

                if inconsistencies_list:
                    attribute1 = json.dumps(inconsistencies_list[0])
                    attribute2 = json.dumps(inconsistencies_list[1])
                else:
                    attribute1 = None
                    attribute2 = None
  
                bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
                
                store_id = API.submit_document(bundle, name, public=False)

                provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=type)
                provenance.save()
                return HttpResponseRedirect(reverse('provmanager_index'))
            
    try:
        filename = request.session['filename']
    except:
        filename = ""      
    return render(request, 'provmanager/create.html', {"filename":filename})