Code coverage report for api/corpus/Corpora.js

Statements: 100% (29 / 29)      Branches: 83.33% (10 / 12)      Functions: 100% (5 / 5)      Lines: 100% (29 / 29)      Ignored: none     

All files » api/corpus/ » Corpora.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 771 1                         1 69 69   69 69     1             697     21                       4 4 1 1   3 3 1 1   2 2 1 1   1 1 1 1             185         1 1  
var Collection = require("./../Collection").Collection;
var Connection = require("./Connection").Connection;
 
/**
 * @class Connection
 * @name  Connection
 * @description The Corpora is a minimal customization of the Collection
 * to add an internal model of a corpus Connection.
 *
 * Collection of Corpuses in the form of Connection which are the conneciton part of CorpusMasks
 *
 * @extends Collection
 * @constructs
 */
var Corpora = function Corpora(options) {
  Eif (!this._fieldDBtype) {
    this._fieldDBtype = "Corpora";
  }
  this.debug("Constructing Corpora ", options);
  Collection.apply(this, arguments);
};
 
Corpora.prototype = Object.create(Collection.prototype, /** @lends Corpora.prototype */ {
  constructor: {
    value: Corpora
  },
 
  primaryKey: {
    get: function() {
      return this._primaryKey || "dbname";
    },
    set: function(value) {
      this._primaryKey = value;
    }
  },
 
  INTERNAL_MODELS: {
    value: {
      item: Connection
    }
  },
 
  findCorpusConnectionFromTitleAsUrl: {
    value: function(titleOrCorpusIdentifier, optionalOwnersUsername) {
      var potentialMatches = this.find(titleOrCorpusIdentifier);
      if (potentialMatches.length > 0) {
        this.debug("Found a corpus connection using the dbname: " + titleOrCorpusIdentifier, potentialMatches);
        return potentialMatches[0];
      }
      potentialMatches = this.find(optionalOwnersUsername + "-" + titleOrCorpusIdentifier);
      if (potentialMatches.length > 0) {
        this.debug("Found a corpus connection using the owner's username: " + optionalOwnersUsername + " and the dbname: " + titleOrCorpusIdentifier, potentialMatches);
        return potentialMatches[0];
      }
      potentialMatches = this.find("title", titleOrCorpusIdentifier, "fuzzy");
      if (potentialMatches.length > 0) {
        this.debug("Found a corpus connection using the title: " + titleOrCorpusIdentifier, potentialMatches);
        return potentialMatches[0];
      }
      potentialMatches = this.find("titleAsUrl", titleOrCorpusIdentifier, "fuzzy");
      Eif (potentialMatches.length > 0) {
        this.debug("Found a corpus connection using the titleAsUrl: " + titleOrCorpusIdentifier, potentialMatches);
        return potentialMatches[0];
      }
    }
  },
 
  sanitizeStringForPrimaryKey: {
    value: function(value) {
      return value;
    }
  }
 
});
exports.Corpora = Corpora;
exports.Connections = Corpora;