<commit_before>/* eslint-disable global-require, import/no-dynamic-require */
import moment from 'moment';
import invariant from 'invariant';
import Immutable from 'immutable';

function get(entity, key) {
  if (Immutable.Map.isMap(entity)) {
    return entity.get(key);
  }
  return entity[key];
}

export function getTitle(entity) {
  const title = get(entity, 'title') || get(entity, 'name');
  invariant(
    title != null,
    'Title for %s with id %s must not be null',
    entity.type, entity.id
  );
  return title;
}

export function getId(entity) {
  const id = get(entity, 'id');
  invariant(
    id != null,
    'Id for entity %s must not be null',
    getTitle(entity)
  );
  return id;
}

export function getType(entity) {
  const type = get(entity, 'type');
  invariant(
    ['dataset', 'visualisation', 'dashboard', 'raster'].indexOf(type) >= 0,
    'Entity %s (%s) unknown entity type %s',
    getTitle(entity), getId(entity), type
  );
  return type;
}

export function getSource(entity) {
  const source = get(entity, 'source');
  if (!source) return null;
  return source.toJS();
}

export function isUpdatable(entity) {
  const s = getSource(entity);
  const k = s ? s.kind : '';
  return (getType(entity) === 'dataset' && (k === 'LINK' || k === 'AKVO_FLOW'));
}

export function getAuthor(entity) {
  let author = get(entity, 'author');
  if (!author) return null;
  if (author.toJS) author = author.toJS();
  const result = author ?
    `${author.given_name ? `${author.given_name} ` : ''}${author.family_name ? author.family_name : ''}` :
    '';
  return result.length ? result : author.email;
}

export function isDataset(entity) {
  return getType(entity) === 'dataset';
}

export function isVisualisation(entity) {
  return getType(entity) === 'visualisation';
}

export function isDashboard(entity) {
  return getType(entity) === 'dashboard';
}

export function isRaster(entity) {<commit_msg>Revert isUpdatable logic<commit_after>/* eslint-disable global-require, import/no-dynamic-require */
import moment from 'moment';
import invariant from 'invariant';
import Immutable from 'immutable';

function get(entity, key) {
  if (Immutable.Map.isMap(entity)) {
    return entity.get(key);
  }
  return entity[key];
}

export function getTitle(entity) {
  const title = get(entity, 'title') || get(entity, 'name');
  invariant(
    title != null,
    'Title for %s with id %s must not be null',
    entity.type, entity.id
  );
  return title;
}

export function getId(entity) {
  const id = get(entity, 'id');
  invariant(
    id != null,
    'Id for entity %s must not be null',
    getTitle(entity)
  );
  return id;
}

export function getType(entity) {
  const type = get(entity, 'type');
  invariant(
    ['dataset', 'visualisation', 'dashboard', 'raster'].indexOf(type) >= 0,
    'Entity %s (%s) unknown entity type %s',
    getTitle(entity), getId(entity), type
  );
  return type;
}

export function getSource(entity) {
  const source = get(entity, 'source');
  if (!source) return null;
  return source.toJS();
}

export function isUpdatable(entity) {
/*
//  const s = getSource(entity);
// const k = s ? s.kind : '';
//return (getType(entity) === 'dataset' && (k === 'LINK' || k === 'AKVO_FLOW'));
*/
  return Boolean(entity);
}

export function getAuthor(entity) {
  let author = get(entity, 'author');
  if (!author) return null;
  if (author.toJS) author = author.toJS();
  const result = author ?
    `${author.given_name ? `${author.given_name} ` : ''}${author.family_name ? author.family_name : ''}` :
    '';
  return result.length ? result : author.email;
}

export function isDataset(entity) {
  return getType(entity) === 'dataset';
}

export function isVisualisation(entity) {
  return getType(entity) === 'visualisation';
}

export function isDashboard(entity) {
  return getType(entity) === 'dashboard';
}

export function isRaster(entity) {
{'fraction_non_alphanumeric': 0.1602366255144033, 'fraction_numerical': 0.00051440329218107, 'mean_word_length': 4.090314136125654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2458996', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1275, 'n_words': 352}