mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 13:16:52 +00:00
get data from webpage and sent the data to OBP-API side
This commit is contained in:
parent
48f447ba42
commit
2509ae0e7d
@ -1,56 +0,0 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
class MethodRouting(models.Model):
|
||||
|
||||
method = models.CharField(
|
||||
max_length=255,
|
||||
verbose_name="Operation id ",
|
||||
help_text="Test endpoint opreation id",
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
bank_id_pattern = models.CharField(
|
||||
max_length=255,
|
||||
verbose_name="bank_id_pattern id ",
|
||||
help_text="bank_id_pattern",
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
parameters = models.CharField(
|
||||
max_length=255,
|
||||
verbose_name="parameters ",
|
||||
help_text="parameters",
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
value = models.CharField(
|
||||
max_length=255,
|
||||
verbose_name="value",
|
||||
help_text="value",
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
select2 = models.CharField(
|
||||
max_length=255,
|
||||
verbose_name="select2",
|
||||
help_text="select2",
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
select1 = models.CharField(
|
||||
max_length=255,
|
||||
verbose_name="select1",
|
||||
help_text="select1",
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Test Profile Operation'
|
||||
verbose_name_plural = 'Test Profile Operation'
|
||||
@ -1,45 +1,19 @@
|
||||
$(document).ready(function($) {
|
||||
function syntaxHighlight(json) {
|
||||
if (typeof json != 'string') {
|
||||
json = JSON.stringify(json, undefined, 2);
|
||||
}
|
||||
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
|
||||
var cls = 'number';
|
||||
if (/^"/.test(match)) {
|
||||
if (/:$/.test(match)) {
|
||||
cls = 'key';
|
||||
} else {
|
||||
cls = 'string';
|
||||
}
|
||||
} else if (/true|false/.test(match)) {
|
||||
cls = 'boolean';
|
||||
} else if (/null/.test(match)) {
|
||||
cls = 'null';
|
||||
}
|
||||
return '<span class="' + cls + '">' + match + '</span>';
|
||||
});
|
||||
}
|
||||
|
||||
$('#config-json').html((syntaxHighlight(ConfigJson)));
|
||||
|
||||
$('.runner button.forSave').click(function() {
|
||||
$('.runner button#forSave').click(function() {
|
||||
var t = $(this);
|
||||
var runner = $(this).parent().parent().parent();
|
||||
select1 = $(runner).find('#select1').val();
|
||||
select2 = $(runner).find('#select2').val();
|
||||
method = $(runner).find('#method_name').innerHTML;
|
||||
method_name = $(runner).find('#method_name').html();
|
||||
connector_name = $(runner).find('#connector_name').val();
|
||||
bank_id_pattern = $(runner).find('textarea[name="bank_id_pattern"]').val();
|
||||
is_bank_id_exact_match = $(runner).find('#is_bank_id_exact_match').val();
|
||||
parameters = $(runner).find('textarea[name="parameters"]').val();
|
||||
|
||||
$.post('/methodrouting/save/method', {
|
||||
'method': method,
|
||||
'value': value,
|
||||
'select1': select1,
|
||||
'select2': select2,
|
||||
$.post('methodrouting/save/method', {
|
||||
'method_name': method_name,
|
||||
'connector_name': connector_name,
|
||||
'bank_id_pattern': bank_id_pattern,
|
||||
'parameters': parameters,
|
||||
'csrfmiddlewaretoken': window.CSRF
|
||||
'is_bank_id_exact_match': is_bank_id_exact_match,
|
||||
'parameters': parameters
|
||||
}, function (response) {
|
||||
t.next().show().fadeOut(1000);
|
||||
});
|
||||
|
||||
@ -1,77 +1,72 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block page_title %}{{ block.super }} / Users{% endblock page_title %}
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'methodrouting/js/methodrouting.js' %}"></script>
|
||||
{% endblock extrajs %}
|
||||
{% block extracss %}
|
||||
<link href="{% static 'methodrouting/css/methodrouting.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
|
||||
{% block content %}
|
||||
<div id="methodrouting">
|
||||
<div id="methodrouting_list">
|
||||
<h1>Method Routing</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group" >Method Name:</label> <br>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group" >Connector Name:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<label class="form-group" >Bank Id Pattern:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<label class="form-group" >Is Bank Id Exact Match:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<label class="form-group" >parameters:</label> <br>
|
||||
</div>
|
||||
<h1>Method Routing</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">Method Name:</label> <br>
|
||||
</div>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% for method_routhing in method_routhings %}
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">Connector Name:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<label class="form-group">Bank Id Pattern:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<label class="form-group">Is Bank Id Exact Match:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<label class="form-group">Parameters:</label> <br>
|
||||
</div>
|
||||
</div>
|
||||
{% for method_routhing in method_routhings %}
|
||||
<div class="row">
|
||||
<div class="runner">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1" id="method_name"><strong>{{ method_routhing.method_name }}</strong></div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2" >
|
||||
<select id="select1">
|
||||
<option value="LocalMapped">LocalMapped</option>
|
||||
<option value="kafka_vSept2018">kafka_vSept2018</option>
|
||||
<option value="akka_vDec2018">akka_vDec2018</option>
|
||||
<option value="rest_vMar2019">rest_vMar2019</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<textarea class="form-group" rows="1" name="bank_id_pattern">{{ method_routhing.bank_id_pattern }}</textarea>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<select id="select2">
|
||||
<option value="False">False</option>
|
||||
<option value="True">True</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<textarea cols="40" rows="1" class="form-control" name="parameters">{{ method_routhing.parameters }}</textarea>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<div class="form-group">
|
||||
<button id="forSave" class="btn btn-primary btn-green">Save</button>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1" >
|
||||
<strong id="method_name">{{ method_routhing.method_name }}</strong></div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<select id="connector_name">
|
||||
<option value="LocalMapped">LocalMapped</option>
|
||||
<option value="kafka_vSept2018">kafka_vSept2018</option>
|
||||
<option value="akka_vDec2018">akka_vDec2018</option>
|
||||
<option value="rest_vMar2019">rest_vMar2019</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<textarea class="form-group"
|
||||
rows="1"
|
||||
name="bank_id_pattern">{{ method_routhing.bank_id_pattern }}</textarea>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2" align="center">
|
||||
<select id="is_bank_id_exact_match" >
|
||||
<option value="False">False</option>
|
||||
<option value="True">True</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<textarea cols="40"
|
||||
rows="1"
|
||||
class="form-control"
|
||||
name="parameters">{{ method_routhing.parameters }}</textarea>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<div class="form-group">
|
||||
<button id="forSave" class="btn btn-primary btn-green">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'methodrouting/js/methodrouting.js' %}"></script>
|
||||
|
||||
{% endblock extrajs %}
|
||||
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'methodrouting/css/methodrouting.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
@ -12,7 +12,7 @@ from django.views.generic import FormView
|
||||
from obp.api import API, APIError
|
||||
from .forms import MethodRoutingForm
|
||||
from django.urls import reverse_lazy
|
||||
from .models import MethodRouting
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
def error_once_only(request, err):
|
||||
"""
|
||||
@ -31,10 +31,6 @@ class IndexView(LoginRequiredMixin, FormView):
|
||||
form_class = MethodRoutingForm
|
||||
success_url = reverse_lazy('methodrouting-index')
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.api = API(request.session.get('obp'))
|
||||
return super(IndexView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
method_routhings=json.loads("""{
|
||||
@ -214,69 +210,36 @@ class IndexView(LoginRequiredMixin, FormView):
|
||||
context.update({'method_routhings': method_routhings["method_routings"]})
|
||||
return context
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
form = super(IndexView, self).get_form(*args, **kwargs)
|
||||
# Cannot add api in constructor: super complains about unknown kwarg
|
||||
fields = form.fields
|
||||
form.api = self.api
|
||||
try:
|
||||
fields['method_routing_body'].initial = ""
|
||||
|
||||
except APIError as err:
|
||||
messages.error(self.request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
except Exception as err:
|
||||
messages.error(self.request, "Unknown Error. Details: "+ str(err))
|
||||
|
||||
return form
|
||||
|
||||
def form_valid(self, form):
|
||||
try:
|
||||
data = form.cleaned_data
|
||||
urlpath = '/management/method_routings'
|
||||
payload = json.loads(data["method_routing_body"])
|
||||
result = self.api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
error_once_only(self.request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
return super(IndexView, self).form_invalid(form)
|
||||
except Exception as err:
|
||||
error_once_only(self.request, "Unknown Error. Details: "+ str(err))
|
||||
return super(IndexView, self).form_invalid(form)
|
||||
if 'code' in result and result['code']>=400:
|
||||
error_once_only(self.request, result['message'])
|
||||
return super(IndexView, self).form_valid(form)
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(self.request, msg)
|
||||
return super(IndexView, self).form_valid(form)
|
||||
|
||||
@csrf_exempt
|
||||
def methodrouting_save(request):
|
||||
method = request.POST.get('method')
|
||||
value = request.POST.get('value')
|
||||
select1 = request.POST.get('select1')
|
||||
select2 = request.POST.get('select2')
|
||||
method_name = request.POST.get('method_name')
|
||||
connector_name = request.POST.get('connector_name')
|
||||
bank_id_pattern = request.POST.get('bank_id_pattern')
|
||||
is_bank_id_exact_match = request.POST.get('is_bank_id_exact_match')
|
||||
parameters = request.POST.get('parameters')
|
||||
|
||||
#if not re.match("^{.*}$", json_body):
|
||||
# json_body = "{{{}}}".format(json_body)
|
||||
|
||||
data = {
|
||||
'method' : method,
|
||||
'value': value,
|
||||
'select1': select1,
|
||||
'select2': select2,
|
||||
payload = {
|
||||
'method_name' : method_name,
|
||||
'connector_name': connector_name,
|
||||
'is_bank_id_exact_match': bool(is_bank_id_exact_match),
|
||||
'bank_id_pattern':bank_id_pattern,
|
||||
'parameters':parameters
|
||||
'parameters':eval(parameters)
|
||||
}
|
||||
|
||||
profile_list = MethodRouting.objects.update_or_create(
|
||||
method=method,
|
||||
value=value,
|
||||
select1=select1,
|
||||
select2=select2,
|
||||
bank_id_pattern=bank_id_pattern,
|
||||
parameters=parameters
|
||||
)
|
||||
api = API(request.session.get('obp'))
|
||||
|
||||
try:
|
||||
urlpath = '/management/method_routings'
|
||||
result = api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
error_once_only(request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
except Exception as err:
|
||||
error_once_only(request, "Unknown Error. Details: " + str(err))
|
||||
if 'code' in result and result['code'] >= 400:
|
||||
error_once_only(request, result['message'])
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(request, msg)
|
||||
return JsonResponse({'state': True})
|
||||
Loading…
Reference in New Issue
Block a user