Skip to content

Commit

Permalink
added get for namerequest prototype (#1044)
Browse files Browse the repository at this point in the history
Signed-off-by: Kial Jinnah <[email protected]>
  • Loading branch information
kialj876 authored Mar 5, 2021
1 parent c46a6e7 commit 7305cd1
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions api/namex/resources/document_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def validate_content(self, value):
raise ValidationError('Document Content must have more than 1 character.')


@cors_preflight("POST")
@api.route(':<string:analysis>', methods=['POST', 'OPTIONS'])
@cors_preflight("POST, GET")
@api.route(':<string:analysis>', methods=['POST', 'GET', 'OPTIONS'])
class DocumentAnalysis(Resource):
"""
:param analysis (str): the type of analysis to perform
Expand Down Expand Up @@ -88,3 +88,40 @@ def post(analysis=None, *args, **kwargs):
if code:
return jsonify(message=msg), code
return jsonify(results), code

@staticmethod
@cors.crossdomain(origin='*')
@jwt.requires_auth
def get(analysis=None, *args, **kwargs):
# added because namerequest has no token and auto generated can't be allowed to POST
# (would have updated above post to get but corresponding UI change in namex-fe-caddy couldn't be built at the time)
start = request.args.get('start', DocumentAnalysis.START)
rows = request.args.get('rows', DocumentAnalysis.ROWS)

if not analysis or analysis.lower() not in VALID_ANALYSIS:
current_app.logger.info('requested analysis:{} is not valid'.format(analysis.lower()))
return jsonify(message='{analysis} is not a valid analysis'.format(analysis=analysis)), 404

json_input = {
'content': request.args.get('content'),
'type': request.args.get('type', 'plain_text')
}
if not json_input:
return jsonify(message='No JSON data provided'), 400

err = DocumentSchema().validate(json_input)
if err:
return jsonify(err), 400

content = json_input['content']

if analysis in RestrictedWords.RESTRICTED_WORDS:
results, msg, code = RestrictedWords.get_restricted_words_conditions(content)

else:
current_app.logger.debug('Solr Search: {}'.format(content))
results, msg, code = SolrQueries.get_results(analysis.lower(), content, start=start, rows=rows)

if code:
return jsonify(message=msg), code
return jsonify(results), code

0 comments on commit 7305cd1

Please sign in to comment.