adsabs/biblib-service

View on GitHub
biblib/views/document_view.py

Summary

Maintainability
F
1 wk
Test Coverage

File document_view.py has 559 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Document view
"""

from biblib.utils import err, get_post_data, get_GET_params
Severity: Major
Found in biblib/views/document_view.py - About 1 day to fix

    Function post has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self, library):
            """
            HTTP POST request that adds a document to a library for a given user
            :param library: library ID
    
    
    Severity: Minor
    Found in biblib/views/document_view.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function post has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self, library):
            """
            HTTP POST request that adds a document to a library for a given user
            :param library: library ID
    
    
    Severity: Minor
    Found in biblib/views/document_view.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function add_document_to_library has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def add_document_to_library(cls, library_id, document_data):
            """
            Adds a document to a user's library
            :param library_id: the library id to update
            :param document_data: the meta data of the document
    Severity: Minor
    Found in biblib/views/document_view.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function put has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def put(self, library):
            """
            HTTP PUT request that updates the meta-data of the library
            :param library: library ID
    
    
    Severity: Minor
    Found in biblib/views/document_view.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function delete has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def delete(self, library):
            """
            HTTP DELETE request that deletes a library defined by the number passed
            :param library: library ID
    
    
    Severity: Minor
    Found in biblib/views/document_view.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid too many return statements within this function.
    Open

                    return err(dict(body=output.get("error"), number=output.get("status_code", 400)))
    Severity: Major
    Found in biblib/views/document_view.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return {}, 400
      Severity: Major
      Found in biblib/views/document_view.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return response, 200
        Severity: Major
        Found in biblib/views/document_view.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return err(dict(body=output_dict.get("error"), number=output_dict.get("status")))
          Severity: Major
          Found in biblib/views/document_view.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return err(MISSING_LIBRARY_ERROR)
            Severity: Major
            Found in biblib/views/document_view.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return {'number_added': output.get("number_added")}, 200
              Severity: Major
              Found in biblib/views/document_view.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return err(WRONG_TYPE_ERROR)
                Severity: Major
                Found in biblib/views/document_view.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return err(dict(body=output_dict.get("error"), number=output_dict.get("status")))
                  Severity: Major
                  Found in biblib/views/document_view.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return err(DUPLICATE_LIBRARY_NAME_ERROR)
                    Severity: Major
                    Found in biblib/views/document_view.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return {}, 200
                      Severity: Major
                      Found in biblib/views/document_view.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return {'number_added': output_dict.get('number_added'), "bibcodes": output_dict.get('bibcodes')}, 200
                        Severity: Major
                        Found in biblib/views/document_view.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                              return {"invalid_identifiers": output.get("invalid_bibcodes"), "number_added": output.get('number_added')}, 200
                          Severity: Major
                          Found in biblib/views/document_view.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                                return err(INVALID_BIBCODE_SPECIFIED_ERROR(output))
                            Severity: Major
                            Found in biblib/views/document_view.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                              return err(dict(body=output_dict.get("error"), number=output_dict.get("status")))
                              Severity: Major
                              Found in biblib/views/document_view.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return err(NO_PERMISSION_ERROR)
                                Severity: Major
                                Found in biblib/views/document_view.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                              return {'number_added': output_dict.get('number_added'), "bibcodes": output_dict.get('bibcodes')}, 200
                                  Severity: Major
                                  Found in biblib/views/document_view.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return {}, 400
                                    Severity: Major
                                    Found in biblib/views/document_view.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                  return err(NO_PERMISSION_ERROR)
                                      Severity: Major
                                      Found in biblib/views/document_view.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                    return {'number_removed': output_dict.get('number_removed'), "bibcodes": output_dict.get('bibcodes')}, 200
                                        Severity: Major
                                        Found in biblib/views/document_view.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                      return output_dict, 200
                                          Severity: Major
                                          Found in biblib/views/document_view.py - About 30 mins to fix

                                            Function get has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                def get(self, library):
                                                    """
                                                    HTTP GET request that adds documents to a library for a given user
                                                    :param library: library ID based on a /search query.
                                            
                                            
                                            Severity: Minor
                                            Found in biblib/views/document_view.py - About 25 mins to fix

                                            Cognitive Complexity

                                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                            A method's cognitive complexity is based on a few simple rules:

                                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                            • Code is considered more complex for each "break in the linear flow of the code"
                                            • Code is considered more complex when "flow breaking structures are nested"

                                            Further reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                        if "error" in solr_resp.keys():
                                                            #If SOLR request fails, pass the error back to the user
                                                            current_app.logger.error("Failed to retrieve bibcodes with error: {}".format(solr_resp.get("error")))
                                                            valid_bibcodes = []
                                                            output_dict = {"error": solr_resp.get("error"), "number_added": 0, "status": status_code}
                                            Severity: Major
                                            Found in biblib/views/document_view.py and 1 other location - About 1 day to fix
                                            biblib/views/document_view.py on lines 529..539

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 142.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                    if "error" in solr_resp.keys():
                                                        #If SOLR request fails, pass the error back to the user
                                                        current_app.logger.error("Failed to retrieve bibcodes with error: {}".format(solr_resp.get("error")))
                                                        valid_bibcodes = []
                                                        output_dict = {"error": solr_resp.get("error"), "number_removed": 0, "status": status_code}
                                            Severity: Major
                                            Found in biblib/views/document_view.py and 1 other location - About 1 day to fix
                                            biblib/views/document_view.py on lines 479..489

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 142.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                    elif data['action'] == 'remove':
                                                        current_app.logger.info('User requested to remove documents by query')
                                                        output_dict = self.remove_query_from_library(
                                                            library_id=library,
                                                            document_data=data
                                            Severity: Major
                                            Found in biblib/views/document_view.py and 1 other location - About 7 hrs to fix
                                            biblib/views/document_view.py on lines 624..637

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 120.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                    if data['action'] == 'add':
                                                        current_app.logger.info('User requested to add documents from query')
                                                        output_dict = self.add_query_to_library(
                                                            library_id=library,
                                                            document_data=data
                                            Severity: Major
                                            Found in biblib/views/document_view.py and 1 other location - About 7 hrs to fix
                                            biblib/views/document_view.py on lines 639..652

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 120.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 3 locations. Consider refactoring.
                                            Open

                                                    try:
                                                        data = get_post_data(
                                                            request,
                                                            types=dict(params=dict, action=str)
                                                        )
                                            Severity: Major
                                            Found in biblib/views/document_view.py and 2 other locations - About 2 hrs to fix
                                            biblib/views/document_view.py on lines 229..237
                                            biblib/views/permission_view.py on lines 470..481

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 58.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Similar blocks of code found in 3 locations. Consider refactoring.
                                            Open

                                                    try:
                                                        data = get_post_data(
                                                            request,
                                                            types=dict(bibcode=list, action=str)
                                                        )
                                            Severity: Major
                                            Found in biblib/views/document_view.py and 2 other locations - About 2 hrs to fix
                                            biblib/views/document_view.py on lines 614..622
                                            biblib/views/permission_view.py on lines 470..481

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 58.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Identical blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                        if number_removed != 0:
                                                            output_dict = {"number_removed": number_removed, "bibcodes": bibcodes_removed}
                                                        else:
                                                            output_dict = {"number_removed": number_removed, "bibcodes": ""}
                                            Severity: Minor
                                            Found in biblib/views/document_view.py and 1 other location - About 35 mins to fix
                                            biblib/views/document_view.py on lines 554..557

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 33.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Identical blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                        if number_removed != 0:
                                                            output_dict = {"number_removed": number_removed, "bibcodes": bibcodes_removed}
                                                        else:
                                                            output_dict = {"number_removed": number_removed, "bibcodes": ""}
                                            Severity: Minor
                                            Found in biblib/views/document_view.py and 1 other location - About 35 mins to fix
                                            biblib/views/document_view.py on lines 130..133

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 33.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            There are no issues that match your filters.

                                            Category
                                            Status