<commit_before>/*
 Copyright 2017 <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

'use strict';

const { appConfig, dbConfig } = require('../config/defaults/config');
const authenticator = require('../helpers/authenticator');
const errorCreator = require('../error/errorCreator');
const dbPosition = require('../db/connectors/position');
const mapCreator = require('../utils/mapCreator');
const managerHelper = require('../helpers/manager');

/**
 * Get position.
 * @param {Object} params - Parameter.
 * @param {string} params.token - jwt.
 * @param {Function} params.callback - Callback.
 * @param {string} [params.positionId] - Id of the position.
 * @param {Object} [params.internalCallUser] - User to use on authentication. It will bypass token authentication.
 */
function getPositionById({
  token,
  positionId,
  callback,
  needsAccess,
  internalCallUser,
}) {
  managerHelper.getObjectById({
    token,
    internalCallUser,
    callback,
    needsAccess,
    objectId: positionId,
    objectType: 'position',
    objectIdType: 'positionId',
    dbCallFunc: dbPosition.getPositionById,
    commandName: dbConfig.apiCommands.GetPositions.name,
  });
}

// TODO Should update if the position already exist
/**
 * Retrieve and store positions from a Google Maps collaborative map.
 * @param {Object} params - Parameters.
 * @param {Function} params.callback - Callback.
 */
function getAndStoreGooglePositions({
  io,
  callback = () => {},
}) {
  if (!appConfig.mapLayersPath) {
    callback({ error: new errorCreator.InvalidData({ name: 'Map layer is not set' }) });

    return;
  }

  mapCreator.getGooglePositions({
    callback: (googleData) => {
      if (googleData.error) {
        callback({ error: googleData.error });

        return;
      }

      dbPosition.removePositionsByOrigin({
        origin: dbConfig.PositionOrigins.GOOGLE,
        callback: (removeData) => {
          if (removeData.error) {
            callback({ error: removeData.error });

            return;
          }

          const { positions } = googleData.data;
          const positionAmount = positions.length;<commit_msg>Corrected error message on unset map layer path<commit_after>/*
 Copyright 2017 <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

'use strict';

const { appConfig, dbConfig } = require('../config/defaults/config');
const authenticator = require('../helpers/authenticator');
const errorCreator = require('../error/errorCreator');
const dbPosition = require('../db/connectors/position');
const mapCreator = require('../utils/mapCreator');
const managerHelper = require('../helpers/manager');

/**
 * Get position.
 * @param {Object} params - Parameter.
 * @param {string} params.token - jwt.
 * @param {Function} params.callback - Callback.
 * @param {string} [params.positionId] - Id of the position.
 * @param {Object} [params.internalCallUser] - User to use on authentication. It will bypass token authentication.
 */
function getPositionById({
  token,
  positionId,
  callback,
  needsAccess,
  internalCallUser,
}) {
  managerHelper.getObjectById({
    token,
    internalCallUser,
    callback,
    needsAccess,
    objectId: positionId,
    objectType: 'position',
    objectIdType: 'positionId',
    dbCallFunc: dbPosition.getPositionById,
    commandName: dbConfig.apiCommands.GetPositions.name,
  });
}

// TODO Should update if the position already exist
/**
 * Retrieve and store positions from a Google Maps collaborative map.
 * @param {Object} params - Parameters.
 * @param {Function} params.callback - Callback.
 */
function getAndStoreGooglePositions({
  io,
  callback = () => {},
}) {
  if (!appConfig.mapLayersPath) {
    callback({ error: new errorCreator.InvalidData({ expected: 'Map layer is not set' }) });

    return;
  }

  mapCreator.getGooglePositions({
    callback: (googleData) => {
      if (googleData.error) {
        callback({ error: googleData.error });

        return;
      }

      dbPosition.removePositionsByOrigin({
        origin: dbConfig.PositionOrigins.GOOGLE,
        callback: (removeData) => {
          if (removeData.error) {
            callback({ error: removeData.error });

            return;
          }

          const { positions } = googleData.data;
          const positionAmount = positions.length;
{'fraction_non_alphanumeric': 0.11338642396662875, 'fraction_numerical': 0.0030337504740235114, 'mean_word_length': 3.4327731092436973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3586095', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1418, 'n_words': 462}