diff --git a/requirements.txt b/requirements.txt index 2cea5a60..9e7b9f4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ Django>=1.11.18,<1.12 jpype1==0.6.3 numpy==1.15.2 djangorestframework==3.6.4 +django-ratelimit==2.0.0 bs4==0.0.1 requests==2.20.1 lxml==4.2.5 diff --git a/src/api/views.py b/src/api/views.py index 3772bfc0..bf61b404 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -277,12 +277,12 @@ def convert(request): message = jpype.JavaException.message(ex) returnstatus = status.HTTP_400_BAD_REQUEST httpstatus = 400 - jpype.detachThreadFromJVM() + jpype.detachThreadFromJVM() except : message = format_exc() returnstatus = status.HTTP_400_BAD_REQUEST httpstatus = 400 - jpype.detachThreadFromJVM() + jpype.detachThreadFromJVM() query.tagToRdfFormat=tagToRdfFormat query.message=message query.status = httpstatus @@ -473,10 +473,10 @@ def check_license(request): returnstatus = status.HTTP_400_BAD_REQUEST httpstatus = 400 jpype.detachThreadFromJVM() - + except jpype.JavaException as ex : """ Java exception raised without exiting the application """ - result = jpype.JavaException.message(ex) + result = jpype.JavaException.message(ex) returnstatus = status.HTTP_400_BAD_REQUEST httpstatus = 400 jpype.detachThreadFromJVM() @@ -496,4 +496,4 @@ def check_license(request): else: return Response( serializer.errors, status=status.HTTP_400_BAD_REQUEST - ) \ No newline at end of file + ) diff --git a/src/app/templates/app/check_license.html b/src/app/templates/app/check_license.html index 89e52e20..35eaadef 100644 --- a/src/app/templates/app/check_license.html +++ b/src/app/templates/app/check_license.html @@ -13,7 +13,7 @@ -{% include "app/modal.html" %} +{% include "app/modal.html" %} {% endblock %} {% block script_block %} @@ -59,7 +59,7 @@ $("#modal-body").html("

"+data.data+"

"); $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#checklicensebutton").text("Check License"); @@ -70,9 +70,17 @@ $("#modal-header").removeClass("green-modal"); try { var obj = JSON.parse(e.responseText); - $("#modal-header").addClass("red-modal"); - $("#modal-title").html("Error!"); - $("#modal-body").text(obj.data); + if (obj.type=="warning" || obj.type=="rate_limit"){ + $("#modal-header").removeClass("red-modal"); + $("#modal-header").addClass("yellow-modal"); + $("#modal-title").html("Warning!"); + } + else if (obj.type=="error"){ + $("#modal-header").removeClass("yellow-modal"); + $("#modal-header").addClass("red-modal"); + $("#modal-title").html("Error!"); + } + $("#modal-body").text(obj.data); } catch (e){ $("#modal-header").addClass("red-modal"); @@ -81,7 +89,7 @@ } $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#checklicensebutton").text("Check License"); diff --git a/src/app/templates/app/compare.html b/src/app/templates/app/compare.html index b46aae37..c1f2272d 100644 --- a/src/app/templates/app/compare.html +++ b/src/app/templates/app/compare.html @@ -27,11 +27,11 @@

Upload SPDX Documents using the button or by dragging and drop
-
+
-
+

@@ -50,7 +50,7 @@

Upload SPDX Documents using the button or by dragging and drop ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, preventDefaults, false) }); - + function preventDefaults (e) { e.preventDefault() e.stopPropagation() @@ -59,19 +59,19 @@

Upload SPDX Documents using the button or by dragging and drop ['dragenter', 'dragover'].forEach(eventName => { dropArea.addEventListener(eventName, highlight, false) }); - + ['dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, unhighlight, false) }); - + function highlight(e) { dropArea.classList.add('highlight') } - + function unhighlight(e) { dropArea.classList.remove('highlight') } - + dropArea.addEventListener('drop', handleDrop, false) function handleDrop(e) { @@ -83,7 +83,7 @@

Upload SPDX Documents using the button or by dragging and drop function handleFiles(files) { ([...files]).forEach(checkFile) } - + function checkFile(file){ if(file && selected_files.length<13){ if ($(".file-name").text() == "No file selected"){ @@ -153,7 +153,7 @@

Upload SPDX Documents using the button or by dragging and drop $("#modal-body").html('

Download file now

'); $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#comparebutton").text("Compare"); @@ -165,6 +165,12 @@

Upload SPDX Documents using the button or by dragging and drop $("#modal-header").removeClass("green-modal"); try{ var obj = JSON.parse(e.responseText); + if (obj.type=="rate_limit"){ + $("#modal-header").removeClass("red-modal"); + $("#modal-header").addClass("yellow-modal"); + $("#modal-title").html("Warning!"); + $("#modal-body").text(obj.data); + } if (obj.type=="warning"){ $("#modal-header").removeClass("red-modal"); $("#modal-header").addClass("yellow-modal"); @@ -208,7 +214,7 @@

Upload SPDX Documents using the button or by dragging and drop $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#comparebutton").text("Compare"); @@ -231,4 +237,4 @@

Upload SPDX Documents using the button or by dragging and drop }); -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/app/templates/app/convert.html b/src/app/templates/app/convert.html index c56c9e20..28e3c50b 100644 --- a/src/app/templates/app/convert.html +++ b/src/app/templates/app/convert.html @@ -55,20 +55,20 @@

Upload SPDX Document using the button or by dragging and dropp
-
+
-
+
-->
-
+
-
+

@@ -88,7 +88,7 @@

Upload SPDX Document using the button or by dragging and dropp ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, preventDefaults, false) }); - + function preventDefaults (e) { e.preventDefault() e.stopPropagation() @@ -97,19 +97,19 @@

Upload SPDX Document using the button or by dragging and dropp ['dragenter', 'dragover'].forEach(eventName => { dropArea.addEventListener(eventName, highlight, false) }); - + ['dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, unhighlight, false) }); - + function highlight(e) { dropArea.classList.add('highlight') } - + function unhighlight(e) { dropArea.classList.remove('highlight') } - + dropArea.addEventListener('drop', handleDrop, false) function handleDrop(e) { @@ -121,7 +121,7 @@

Upload SPDX Document using the button or by dragging and dropp function handleFiles(files) { ([...files]).forEach(checkFile) } - + function checkFile(file){ if(file){ $(".file-name").html("Selected File: "+file.name); @@ -264,7 +264,7 @@

Upload SPDX Document using the button or by dragging and dropp $("#modal-body").html('

Download file now

'); $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#convertbutton").text("Convert"); @@ -276,6 +276,12 @@

Upload SPDX Document using the button or by dragging and dropp $("#modal-body").text(""); try{ var obj = JSON.parse(e.responseText); + if (obj.type=="rate_limit"){ + $("#modal-header").removeClass("red-modal"); + $("#modal-header").addClass("yellow-modal"); + $("#modal-title").html("Warning!"); + $("#modal-body").text(obj.data); + } if (obj.type=="warning"){ $("#modal-header").removeClass("red-modal"); $("#modal-header").addClass("yellow-modal"); @@ -297,10 +303,10 @@

Upload SPDX Document using the button or by dragging and dropp $("#modal-title").html("Error!"); $("#modal-body").text("The application could not be connected. Please try later."); } - + $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#convertbutton").text("Convert"); @@ -319,4 +325,4 @@

Upload SPDX Document using the button or by dragging and dropp -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/app/templates/app/submit_new_license.html b/src/app/templates/app/submit_new_license.html index 4b1a8157..1b73c820 100644 --- a/src/app/templates/app/submit_new_license.html +++ b/src/app/templates/app/submit_new_license.html @@ -244,7 +244,7 @@ $("#modal-header").removeClass("green-modal"); try { var obj = JSON.parse(e.responseText); - if (obj.type=="warning"){ + if (obj.type=="warning" || obj.type=="rate_limit"){ $("#modal-header").removeClass("red-modal"); $("#modal-header").addClass("yellow-modal"); $("#modal-title").html("Warning!"); diff --git a/src/app/templates/app/validate.html b/src/app/templates/app/validate.html index d582f04c..6314873f 100644 --- a/src/app/templates/app/validate.html +++ b/src/app/templates/app/validate.html @@ -23,7 +23,7 @@

Upload file using the button or by dragging and dropping onto the dashed reg
- {% include "app/modal.html" %} + {% include "app/modal.html" %} @@ -40,7 +40,7 @@

Upload file using the button or by dragging and dropping onto the dashed reg ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, preventDefaults, false) }); - + function preventDefaults (e) { e.preventDefault() e.stopPropagation() @@ -49,19 +49,19 @@

Upload file using the button or by dragging and dropping onto the dashed reg ['dragenter', 'dragover'].forEach(eventName => { dropArea.addEventListener(eventName, highlight, false) }); - + ['dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, unhighlight, false) }); - + function highlight(e) { dropArea.classList.add('highlight') } - + function unhighlight(e) { dropArea.classList.remove('highlight') } - + dropArea.addEventListener('drop', handleDrop, false) function handleDrop(e) { @@ -73,7 +73,7 @@

Upload file using the button or by dragging and dropping onto the dashed reg function handleFiles(files) { ([...files]).forEach(checkFile) } - + function checkFile(file){ if(file){ $(".file-name").html("Selected File: "+file.name); @@ -125,7 +125,7 @@

Upload file using the button or by dragging and dropping onto the dashed reg $("#modal-body").html("

"+data.data+"

"); $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#validatebutton").text("Validate"); @@ -136,7 +136,7 @@

Upload file using the button or by dragging and dropping onto the dashed reg $("#modal-header").removeClass("green-modal"); try { var obj = JSON.parse(e.responseText); - if (obj.type=="warning"){ + if (obj.type=="warning" || obj.type=="rate_limit"){ $("#modal-header").removeClass("red-modal"); $("#modal-header").addClass("yellow-modal"); $("#modal-title").html("Warning!"); @@ -156,7 +156,7 @@

Upload file using the button or by dragging and dropping onto the dashed reg } $("#myModal").modal({ backdrop: 'static', - keyboard: true, + keyboard: true, show: true }); $("#validatebutton").text("Validate"); @@ -236,4 +236,4 @@

Upload file using the button or by dragging and dropping onto the dashed reg --> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/app/templates/app/xml_upload.html b/src/app/templates/app/xml_upload.html index 2726f337..e42ed7eb 100644 --- a/src/app/templates/app/xml_upload.html +++ b/src/app/templates/app/xml_upload.html @@ -28,7 +28,7 @@

Upload the XML File

- +
- {% include "app/modal.html" %} + {% include "app/modal.html" %}
{% endblock %} @@ -91,7 +91,7 @@

Make a new License XML file from scratch


['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, preventDefaults, false) }); - + function preventDefaults (e) { e.preventDefault() e.stopPropagation() @@ -100,19 +100,19 @@

Make a new License XML file from scratch


['dragenter', 'dragover'].forEach(eventName => { dropArea.addEventListener(eventName, highlight, false) }); - + ['dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, unhighlight, false) }); - + function highlight(e) { dropArea.classList.add('highlight') } - + function unhighlight(e) { dropArea.classList.remove('highlight') } - + dropArea.addEventListener('drop', handleDrop, false) function handleDrop(e) { @@ -124,7 +124,7 @@

Make a new License XML file from scratch


function handleFiles(files) { ([...files]).forEach(checkFile) } - + function checkFile(file){ if(file.type=="text/xml" || file.type=="application/xml"){ $(".file-name").html("Selected File: "+file.name); @@ -144,7 +144,7 @@

Make a new License XML file from scratch