Unexpected runtime error

The runtime has encountered an unexpected error.

Error source

Page Name:/index.xsp
Control Id: _id94

Exception

Error while executing JavaScript computed expression
Script interpreter error, line=33, col=63: [ReferenceError] 'AnswerMap' not found
   at [/elenchusServer.jss].(231A81D67DCC7036852576A3000B87F4)

Javascript code

   1: importPackage(com.timtripcony.xsp.elenchus);
   2: 
   3: var Elenchus = function() {
   4: 	var controllerKey:string = "com.timtripcony.xsp.elenchus";
   5: 	if (!(requestScope.containsKey(controllerKey))) {
   6: 		var hashCache:java.util.HashMap = new java.util.HashMap();
   7: 		var controller = {
   8: 			addKarma: function(userName:string, howMuch:int) {
   9: 				var profile:NotesDocument = this.getProfile(userName);
  10: 				profile.replaceItemValue("karma", this.getKarma(userName) + howMuch);
  11: 				profile.save(true, true);
  12: 			},
  13: 			castVote: function(postUnid:string, score:int) {
  14: 				var voteDoc:NotesDocument = this.getDocumentByPrimaryKey(database, postUnid + this.getMyName());
  15: 				if (voteDoc.isNewNote()) {
  16: 					voteDoc.replaceItemValue("Form","vote");
  17: 					voteDoc.replaceItemValue("postUnid", postUnid);
  18: 					voteDoc.replaceItemValue("documentCreator", this.getMyName());
  19: 					this.addKarma(this.getMyName(), 1);
  20: 					var postAuthor:string = database.getDocumentByUNID(postUnid).getItemValueString("documentCreator");
  21: 					this.addKarma(postAuthor, score);
  22: 				}
  23: 				var newScore:int = (score == voteDoc.getItemValueInteger("score")) ? 0 : score;
  24: 				voteDoc.replaceItemValue("score", newScore);
  25: 				voteDoc.save(true, true);
  26: 				var postDoc:NotesDocument = database.getDocumentByUNID(postUnid);
  27: 				var questionUnid:string = (postDoc.getItemValueString("Form") == "question") ? postDoc.getUniversalID() : postDoc.getItemValueString("questionUnid");
  28: 				//facesContext.getExternalContext().redirect("answer.xsp?questionId=" + questionUnid);
  29: 			},
  30: 			getAnswers: function(questionUnid:string) {
  31: 				var entries:NotesViewEntryCollection = database.getView("answers").getAllEntriesByKey(questionUnid, true);
  32: 				var entryArray = [];
  33: 				var answerMap:AnswerMap = new AnswerMap();
  34: 				var entry:NotesViewEntry = entries.getFirstEntry();
  35: 				while (entry != null) {
  36: 					var score:int = this.getScore(entry.getUniversalID());
  37: 					var karma:int = this.getKarma(entry.getDocument().getItemValueString("documentCreator"));
  38: 					var data:AnswerData = new AnswerData(entry, karma, score);
  39: 					
  40: 					answerMap.add(data);
  41: 					entry = entries.getNextEntry(entry);
  42: 				}
  43: 				var answers = answerMap.getEntries();
  44: 				/*for (var i:int = 0; i < answers.length; i++) {
  45: 					entryArray.push(answers[i].getEntry());
  46: 				}
  47: 				return entryArray;*/
  48: 				return answers.values().toArray();
  49: 				//return entries;
  50: 			},
  51: 			getScore: function(postUnid:string) {
  52: 				return @Sum(@DbLookup("","votes",postUnid, 2) || 0);
  53: 			},
  54: 			getDocumentByPrimaryKey: function(dbFrom:NotesDatabase, primaryKey:string) {
  55: 				var unid:string = "";
  56: 				var docTarget:NotesDocument = null;
  57: 				try {
  58: 					unid = this.getHash(primaryKey);
  59: 					docTarget = dbFrom.getDocumentByUNID(unid);
  60: 				} catch(e) {
  61: 					docTarget = dbFrom.createDocument();
  62: 					docTarget.setUniversalID(unid);
  63: 					var created:NotesDateTime = session.createDateTime("Today");
  64: 					created.setNow();
  65: 					docTarget.replaceItemValue("created", created);
  66: 					docTarget.replaceItemValue("primaryKey", primaryKey);
  67: 				}
  68: 				return docTarget;
  69: 			},
  70: 			getHash: function(clearText:string) {
  71: 				if (!(hashCache.containsKey(clearText))) {
  72: 					var formula:string = "@Middle(@Password(\"" + clearText + "\"); \"(\"; \")\")";
  73: 					hashCache.put(clearText, session.evaluate(formula).firstElement().toString());
  74: 				}
  75: 				return hashCache.get(clearText);
  76: 			},
  77: 			getKarma: function(userName:string) {
  78: 				return this.getProfile(userName).getItemValueInteger("karma");
  79: 			},
  80: 			getMyName: function() {
  81: 				return context.getUser().getDistinguishedName();
  82: 			},
  83: 			getMyProfile: function() {
  84: 				return this.getProfile(this.getMyName());
  85: 			},
  86: 			getPageViews: function(postUnid:string) {
  87: 				return database.getView("pageviews").getAllEntriesByKey(postUnid, true);
  88: 			},
  89: 			getProfile: function(userName:string) {
  90: 				var dnUserName:string = session.createName(userName).getCanonical();
  91: 				var profile:NotesDocument = this.getDocumentByPrimaryKey(database, dnUserName);
  92: 				if (profile.isNewNote()) {
  93: 					profile.replaceItemValue("Form", "user");
  94: 					profile.replaceItemValue("karma", 0);
  95: 					profile.replaceItemValue("userName", dnUserName);
  96: 					profile.save(true, true);
  97: 				}
  98: 				return profile;
  99: 			},
 100: 			logPageView: function (postUnid:string) {
 101: 				if (database.getCurrentAccessLevel() > 3) {
 102: 				var logEntry:NotesDocument = database.createDocument();
 103: 				logEntry.replaceItemValue("Form", "pageview");
 104: 				logEntry.replaceItemValue("postUnid", postUnid);
 105: 				logEntry.replaceItemValue("documentCreator", this.getMyName());
 106: 				logEntry.save(true, true);
 107: 			}
 108: 			}
 109: 		};
 110: 		requestScope.put(controllerKey, controller);
 111: 	}
 112: 	return requestScope.get(controllerKey);
 113: };

Stack Trace