resource-watch/dataset

View on GitHub

Showing 122 of 122 total issues

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

        koaObj.checkBody('data').optional().check((data) => {
            if (DatasetValidator.isArray(data) || DatasetValidator.isObject(data)) {
                return true;
            }
            return false;
Severity: Major
Found in src/validators/dataset.validator.js and 1 other location - About 1 hr to fix
src/validators/dataset.validator.js on lines 273..278

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 66.

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 4 locations. Consider refactoring.
Open

    static async deleteWidgets(datasetId, apiKey) {
        logger.info('Deleting widgets of dataset', datasetId);
        await RWAPIMicroservice.requestToMicroservice({
            uri: `/v1/dataset/${datasetId}/widget`,
            method: 'DELETE',
Severity: Major
Found in src/services/dataset.service.js and 3 other locations - About 1 hr to fix
src/services/dataset.service.js on lines 496..505
src/services/dataset.service.js on lines 507..516
src/services/dataset.service.js on lines 518..527

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 66.

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 4 locations. Consider refactoring.
Open

    static async deleteMetadata(datasetId, apiKey) {
        logger.info('Deleting metadata of dataset', datasetId);
        await RWAPIMicroservice.requestToMicroservice({
            uri: `/v1/dataset/${datasetId}/metadata`,
            method: 'DELETE',
Severity: Major
Found in src/services/dataset.service.js and 3 other locations - About 1 hr to fix
src/services/dataset.service.js on lines 485..494
src/services/dataset.service.js on lines 496..505
src/services/dataset.service.js on lines 518..527

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 66.

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

        koaObj.checkBody('data').optional().check((data) => {
            if (DatasetValidator.isArray(data) || DatasetValidator.isObject(data)) {
                return true;
            }
            return false;
Severity: Major
Found in src/validators/dataset.validator.js and 1 other location - About 1 hr to fix
src/validators/dataset.validator.js on lines 226..231

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 66.

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 4 locations. Consider refactoring.
Open

    static async deleteVocabularies(datasetId, apiKey) {
        logger.info('Deleting vocabularies of dataset', datasetId);
        await RWAPIMicroservice.requestToMicroservice({
            uri: `/v1/dataset/${datasetId}/vocabulary`,
            method: 'DELETE',
Severity: Major
Found in src/services/dataset.service.js and 3 other locations - About 1 hr to fix
src/services/dataset.service.js on lines 485..494
src/services/dataset.service.js on lines 496..505
src/services/dataset.service.js on lines 507..516

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 66.

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 4 locations. Consider refactoring.
Open

    static async deleteLayers(datasetId, apiKey) {
        logger.info('Deleting layers of dataset', datasetId);
        await RWAPIMicroservice.requestToMicroservice({
            uri: `/v1/dataset/${datasetId}/layer`,
            method: 'DELETE',
Severity: Major
Found in src/services/dataset.service.js and 3 other locations - About 1 hr to fix
src/services/dataset.service.js on lines 485..494
src/services/dataset.service.js on lines 507..516
src/services/dataset.service.js on lines 518..527

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 66.

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

            const result = await RWAPIMicroservice.requestToMicroservice({
                uri: `/v1/favourite/find-by-user`,
                method: 'POST',
                json: true,
                body: {
Severity: Major
Found in src/services/relationships.service.js and 1 other location - About 1 hr to fix
src/services/relationships.service.js on lines 251..262

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 65.

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

            const result = await RWAPIMicroservice.requestToMicroservice({
                uri: `/v1/collection/find-by-ids`,
                method: 'POST',
                json: true,
                body: {
Severity: Major
Found in src/services/relationships.service.js and 1 other location - About 1 hr to fix
src/services/relationships.service.js on lines 271..282

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 65.

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

Function clone has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async clone(id, dataset, user, apiKey, fullCloning = false) {
        logger.debug(`[DatasetService]: Getting dataset with id:  ${id}`);
        logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
        const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
            slug: id
Severity: Minor
Found in src/services/dataset.service.js - About 1 hr to fix

    Function authorizationMiddleware has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const authorizationMiddleware = async (ctx, next) => {
        logger.info(`[DatasetRouter] Checking authorization`);
        // Get user from query (delete) or body (post-patch)
        const newDatasetCreation = ctx.request.path === '/dataset' && ctx.request.method === 'POST';
        const uploadDataset = ctx.request.path.indexOf('upload') >= 0 && ctx.request.method === 'POST';
    Severity: Minor
    Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

      Function checkSecureDeleteResources has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async checkSecureDeleteResources(id, apiKey) {
              logger.info('Checking if it is safe to delete the associated resources (layer, widget) of the dataset');
              try {
                  const layers = await RWAPIMicroservice.requestToMicroservice({
                      uri: `/v1/dataset/${id}/layer?protected=true`,
      Severity: Minor
      Found in src/services/dataset.service.js - About 1 hr to fix

        Function serialize has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static serialize(data, link = null) {
                const result = {};
                if (data && Array.isArray(data) && data.length === 0) {
                    result.data = [];
                    return result;
        Severity: Minor
        Found in src/serializers/dataset.serializer.js - About 1 hr to fix

          Function update has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static async update(ctx) {
                  const id = ctx.params.dataset;
                  logger.info(`[DatasetRouter] Updating dataset with id: ${id}`);
                  try {
                      const user = DatasetRouter.getUser(ctx);
          Severity: Minor
          Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

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

                            try {
                                logger.debug('[DatasetService]: Creating relations in graph');
                                await GraphService.associateTags(newDataset._id, dataset.vocabularies, apiKey);
                            } catch (err) {
                                newDataset.errorMessage = err.message;
            Severity: Major
            Found in src/services/dataset.service.js and 1 other location - About 1 hr to fix
            src/services/dataset.service.js on lines 314..322

            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 62.

            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 (
                        sort.indexOf('most-favorited') >= 0
                        || sort.indexOf('most-viewed') >= 0
                        || sort.indexOf('relevance') >= 0
                        || sort.indexOf('metadata') >= 0
            Severity: Major
            Found in src/services/dataset.service.js and 1 other location - About 1 hr to fix
            src/services/dataset.service.js on lines 685..693

            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 62.

            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

                        try {
                            await RelationshipsService.createVocabularies(newDataset._id, dataset.vocabularies, apiKey);
                        } catch (err) {
                            newDataset.errorMessage = err.message;
                            const result = await DatasetService.update(newDataset._id, newDataset, {
            Severity: Major
            Found in src/services/dataset.service.js and 1 other location - About 1 hr to fix
            src/services/dataset.service.js on lines 303..312

            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 62.

            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 (
                        sort.indexOf('most-favorited') >= 0
                        || sort.indexOf('most-viewed') >= 0
                        || sort.indexOf('relevance') >= 0
                        || sort.indexOf('metadata') >= 0
            Severity: Major
            Found in src/services/dataset.service.js and 1 other location - About 1 hr to fix
            src/services/dataset.service.js on lines 697..710

            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 62.

            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

            Consider simplifying this complex logical expression.
            Open

                        if (
                            search
                            || serializeObjToQuery(query).indexOf('concepts[0][0]') >= 0
                            || sort.indexOf('most-favorited') >= 0
                            || sort.indexOf('most-viewed') >= 0
            Severity: Critical
            Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

              Function getRelationships has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static async getRelationships(datasets, includes, apiKey, query = '', isAdmin = false) {
                      logger.info(`Getting relationships of datasets`, isAdmin);
                      datasets.unshift({});
                      const map = datasets.reduce((acc, val) => {
                          acc[val._id] = val;
              Severity: Minor
              Found in src/services/relationships.service.js - About 1 hr to fix

                Function notifyAdapterCreate has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static async notifyAdapterCreate(ctx, dataset) {
                        const { connectorType, provider } = dataset;
                        const clonedDataset = { ...dataset.toObject() };
                
                        clonedDataset.id = dataset._id;
                Severity: Minor
                Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language