### Eclipse Workspace Patch 1.0
#P fluid-engage-core
Index: tests/component-tests/codeEntry/js/CodeEntryTests.js
===================================================================
--- tests/component-tests/codeEntry/js/CodeEntryTests.js	(revision 9309)
+++ tests/component-tests/codeEntry/js/CodeEntryTests.js	(working copy)
@@ -18,12 +18,21 @@
     var tests = {};
     var component;
 
+
+	/**
+	 * For test purposes - only even numbers are valid codes.
+	 */
+	var simulateCheck = function() {
+		return !(component.code[1] % 2) ? "#" : null;
+	};
+    
     var setup = function () {
         tests.fetchTemplate(
                 "../../../../components/codeEntry/html/codeEntry.html",
                 ".flc-codeEntry");
         
-        component = fluid.engage.codeEntry(".flc-codeEntry", {testMode: true});
+        component = fluid.engage.codeEntry(".flc-codeEntry",
+        	{getArtifactUrlForCode: simulateCheck});
     };
     
     tests = jqUnit.testCase("Code Entry Tests", setup);
@@ -97,8 +106,7 @@
             jqUnit.assertEquals("First digit blank.", "", firstDigitField.text());
             jqUnit.assertEquals("Second digit blank.", "", secondDigitField.text());
             jqUnit.assertEquals("Invalid code message shown.",
-            		"<img src=\"../../../../fluid-engage-core/components/codeEntry/images/invalid-code.png\" alt=\"Invalid code.\">",
-            		headBlock.html());
+            		component.options.strings.invalidCode, headBlock.text());
             
 
             // Enter one digit - the error message persists
@@ -106,8 +114,7 @@
             jqUnit.assertEquals("First digit is 2.", "2", firstDigitField.text());
             jqUnit.assertEquals("Second digit blank.", "", secondDigitField.text());
             jqUnit.assertEquals("Invalid code message shown.",
-            		"<img src=\"../../../../fluid-engage-core/components/codeEntry/images/invalid-code.png\" alt=\"Invalid code.\">",
-            		headBlock.html());
+            		component.options.strings.invalidCode, headBlock.text());
             
             // Enter second digit - the code fields are shown until redirection
             // happens
Index: components/codeEntry/js/CodeEntryView.js
===================================================================
--- components/codeEntry/js/CodeEntryView.js	(revision 9341)
+++ components/codeEntry/js/CodeEntryView.js	(working copy)
@@ -7,7 +7,7 @@
 
 You may obtain a copy of the ECL 2.0 License and BSD License at
 https://source.fluidproject.org/svn/LICENSE.txt
-*/
+ */
 
 /*global jQuery, fluid, document, window*/
 "use strict";
@@ -15,250 +15,249 @@
 fluid = fluid || {};
 fluid.engage = fluid.engage || {};
 
-(function ($) {
-    
-    // TODO: get the relevant museum
-    var museum = "mccord";
-    
-    /**
-     * Clears the digit entry fields and allows input.
-     * 
-     * @param {Object} that, the component.
-     */
-    var resetEntry = function (that) {
-        that.locate("firstDigitField").text("");
-        that.locate("secondDigitField").text("");
-    };
-    
-    /**
-     * Toggles the style of the head div to invalid code message style and off
-     * 
-     * @param {Object} that, the component.
-     */
-    var toggleHeadMessageStyle = function (that) {
-        that.locate("headMessage").toggleClass(that.options.styles.invalidCode);
-    };
-    
-    /**
-     * Redirects the browser to the given URL.
-     * 
-     * @param {Object} that, the component.
-     * @param url, the URL to redirect to.
-     */
-    var redirectToArtifactPage = function (that, url) {
-        // Do some cleanup before leaving the page
-        resetEntry(that);
-        that.code = "";
-        that.atDigit = 0;
-        
-        if (!that.options.testMode) {
-            window.location = url;
-        }
-    };
-    
-    /**
-     * Display a message and redirect to artifact page after some delay.
-     * 
-     * @param {Object} that, the component
-     * @param url, the URL to redirect to.
-     */
-    var redirectSequence = function (that, url) {
-        var redirectFunction = function () {
-            redirectToArtifactPage(that, url);
-        };
+(function($) {
+
+	/**
+	 * Clears the digit entry fields and allows input.
+	 * 
+	 * @param {Object}
+	 *            that, the component.
+	 */
+	var resetEntry = function(that) {
+		that.locate("firstDigitField").text("");
+		that.locate("secondDigitField").text("");
+	};
+
+	/**
+	 * Redirects the browser to the given URL.
+	 * 
+	 * @param {Object}
+	 *            that, the component.
+	 * @param url,
+	 *            the URL to redirect to.
+	 */
+	var redirectToArtifactPage = function(that, url) {
+		// Do some cleanup before leaving the page
+		resetEntry(that);
+		that.code = "";
+		that.atDigit = 0;
+
+		window.location = url;
+	};
+
+	/**
+	 * Display a message and redirect to artifact page after some delay.
+	 * 
+	 * @param {Object}
+	 *            that, the component
+	 * @param url,
+	 *            the URL to redirect to.
+	 */
+	var redirectSequence = function(that, url) {
+		var redirectFunction = function() {
+			redirectToArtifactPage(that, url);
+		};
+
+		// Replace the invalid code message with something...
+		that.locate("headMessage").text(that.options.strings.redirecting);
+
+		that.locate("headMessage").removeClass(that.options.styles.invalidCode);
+
+		setTimeout(redirectFunction, that.options.redirectDelay);
+	};
+
+	/**
+	 * Displays an warning message for invalid code and resets the entry fields.
+	 * 
+	 * @param {Object}
+	 *            that, the component.
+	 */
+	var wrongCodeSequence = function(that) {
+		var invalidCodeBlock = that.locate("headMessage");
+		invalidCodeBlock.text(that.options.strings.invalidCode);
+		that.locate("headMessage").addClass(that.options.styles.invalidCode);
+
+		var wrongCodeFunction = function() {
+			resetEntry(that);
+			that.code = "";
+			that.atDigit = 0;
+		};
+		
+		invalidCodeBlock.show(250, function() {
+			setTimeout(wrongCodeFunction, that.options.wrongCodeCleanupDelay);	
+		});
+	};
+
+	/**
+	 * Issues a Ajax call to verify if the entered code corresponds to an
+	 * artifact and returns the artifact page URL or null if the code is invalid.
+	 * 
+	 * @param {Object}
+	 *            that, the component.
+	 */
+	var getArtifactUrlForCode = function(that) {
+		var url = fluid.stringTemplate(
+				decodeURIComponent(that.options.codeCheckUrlTemplate), {
+					objectCode : that.code
+				});
 
-        // Replace the invalid code message with something...
-        that.locate("headMessage").text(that.options.strings.redirecting);
+		var error = function(XMLHttpRequest, textStatus, errorThrown) {
+			fluid.log("Status: " + textStatus);
+			fluid.log("Error: " + errorThrown);
+		};
 
-        toggleHeadMessageStyle(that);
+		
+		var data; 
+		var success = function(returnedData) {
+			data = JSON.parse(returnedData);
+		};
 
-        setTimeout(redirectFunction, that.options.redirectDelay);
-    };
-    
-    /**
-     * Displays an warning message for invalid code and resets the entry fields.
-     * 
-     * @param {Object} that, the component. 
-     */
-    var wrongCodeSequence = function (that) {
-        var invalidCodeBlock = that.locate("headMessage");
-        invalidCodeBlock.text(that.options.strings.invalidCode);
-        toggleHeadMessageStyle(that);
-        
-        invalidCodeBlock.show(250, function () {
-            resetEntry(that);
-            that.code = "";
-            that.atDigit = 0;
-        });
-    };
-    
-    /**
-     * Issues a Ajax call to verify if the entered code corresponds to an
-     * artifact and depending on that either redirects to the artifact page
-     * or displays a warning.
-     * 
-     * @param {Object} that, the component.
-     */
-    var checkCode = function (that) {
-        var url = location.pathname;
-        url = "http://" + location.host + url.substring(0, url.lastIndexOf("/"));
-        url += "/codeEntryService.js?code=" + that.code + "&db=" + museum;
-        
-        var error = function (XMLHttpRequest, textStatus, errorThrown) {
-            fluid.log("Status: " + textStatus);
-            fluid.log("Error: " + errorThrown);
-        };
-        
-        var success = function (returnedData) {
-            
-            var data = JSON.parse(returnedData);
-            
-            if (data.artifactFound) {
-                redirectSequence(that, data.artifactLink);
-            } else {
-                wrongCodeSequence(that);
-            }
-        };
-        
-        $.ajax({
-            url: url,
-            async: true,
-            error: error,
-            success: success
-        });
-    };
+		$.ajax( {
+			url : url,
+			async : false,
+			error : error,
+			success : success
+		});
+		
+		if (data && data.artifactFound) {
+			return data.artifactLink;
+		}
+		
+		return null;
+	};
 
-    /**
-     * For test purposes - only even numbers are valid codes.
-     * 
-     * @param {Object} that, the component.
-     */
-    var simulateCheck = function (that) {
-        if (!(that.code[1] % 2)) {
-            redirectSequence(that);
-        } else {
-            wrongCodeSequence(that);
-        }
-    };
-    
-    /**
-     * Return the current digit dom element - if no digit has been entered
-     * this is the first one, otherwise it is the second one.
-     */
-    var getCurrentDigitField = function (that) {
-        return that.atDigit === 0 ?
-                that.locate("firstDigitField") : that.locate("secondDigitField");
-    };
-    
-    /**
-     * Initialize a handler for a digit or delete entry button.
-     * For digit handlers if the second digit is entered the whole code is
-     * checked and relevant actions are taken.
-     * 
-     *  @param {Object} that, the component.
-     *  @param button, the DOM element for buttons from 0 to 9 and delete
-     *  @param number, the number that will be displayed if the user clicks
-     *      on the button, from 1 to 10 for digits and 11 for delete
-     */
-    var attachButtonHandler = function (that, button, number) {
-        if (number < 11) {
-            var num = number % 10;
-            $(button).click(function () {
-                that.enterDigit(num);
-            });
-        } else {
-            $(button).click(function () {
-                that.deleteLastDigit();
-            });
-        }
-    };
-    
-    /**
-     * Initializes the component view.
-     * 
-     * @param that, the component.
-     */
-    var setup = function (that) {  
-        // Initialize the navigation bar.
-        that.navBar = fluid.initSubcomponent(that, "navigationBar", [that.container, fluid.COMPONENT_OPTIONS]);
-              
-        // Init heading
-        that.locate("heading").text(that.options.strings.header);
-        
-        // Init instruction text        
-        that.locate("headMessage").text(that.options.strings.instruction);
-        
-        // Initialize numpad
-        that.atDigit = 0;
-        that.code = "";
-        
-        // Initialize entry buttons
-        var buttons = that.locate("entryButtons");
-        
-        for (var i = 0; i < buttons.length; i++) {
-            attachButtonHandler(that, buttons[i], i + 1);
-        }
-    };  
-    
-    /**
-     * Component's creator function.
-     * 
-     * @param {Object} container, DOM element that will correspond to the component.
-     * @param {Object} options, the component's options.
-     */
-    fluid.engage.codeEntry = function (container, options) {
-        var that = fluid.initView("fluid.codeEntry", container, options);       
-        
-        that.enterDigit = function (digit) {
-            getCurrentDigitField(that).text(digit);
-            if (that.atDigit === 0) {
-                that.code += digit;
-                that.atDigit++;
-            } else {
-                that.code += digit;
-                if (!that.options.testMode) {
-                    checkCode(that);
-                } else {
-                    simulateCheck(that);
-                }
-            }
-        };
-        
-        that.deleteLastDigit = function () {
-            if (that.atDigit === 1) {
-                that.atDigit--;
-                that.code = "";
-                getCurrentDigitField(that).text("");
-            }
-        };
-        
-        setup(that);
-        
-        return that;
-    };
-    
-    fluid.defaults("fluid.codeEntry", {
-        navigationBar: {
-            type: "fluid.engage.navigationBar"
-        },
-        selectors : {
-            heading: ".flc-heading",
-            headMessage: ".flc-head-message",
-            firstDigitField: ".flc-first-digit",
-            secondDigitField: ".flc-second-digit",
-            entryButtons: "img[class*=flc-button]"
-        },
-        styles : {
-            invalidCode: "fl-invalid-code"
-        },
-        strings : {
-            title: "Enter object code",
-            header: "Enter object code",
-            instruction: "Enter code from the object's label to learn more about the object.",
-            invalidCode: "Invalid code. Please try again",
-            redirecting: "Opening artifact page."
-        },
-        redirectDelay: 1000,
-        testMode: false
-    });
+	/**
+	 * Return the current digit dom element - if no digit has been entered this
+	 * is the first one, otherwise it is the second one.
+	 */
+	var getCurrentDigitField = function(that) {
+		return that.atDigit === 0 ? that.locate("firstDigitField") : that
+				.locate("secondDigitField");
+	};
+
+	/**
+	 * Initialize a handler for a digit or delete entry button. For digit
+	 * handlers if the second digit is entered the whole code is checked and
+	 * relevant actions are taken.
+	 * 
+	 * @param {Object}
+	 *            that, the component.
+	 * @param button,
+	 *            the DOM element for buttons from 0 to 9 and delete
+	 * @param number,
+	 *            the number that will be displayed if the user clicks on the
+	 *            button, from 1 to 10 for digits and 11 for delete
+	 */
+	var attachButtonHandler = function(that, button, number) {
+		if (number < 11) {
+			var num = number % 10;
+			$(button).click(function() {
+				that.enterDigit(num);
+			});
+		} else {
+			$(button).click(function() {
+				that.deleteLastDigit();
+			});
+		}
+	};
+
+	/**
+	 * Initializes the component view.
+	 * 
+	 * @param that,
+	 *            the component.
+	 */
+	var setup = function(that) {
+		// Initialize the navigation bar.
+		that.navBar = fluid.initSubcomponent(that, "navigationBar", [
+				that.container, fluid.COMPONENT_OPTIONS ]);
+
+		// Init heading
+		that.locate("heading").text(that.options.strings.header);
+
+		// Init instruction text
+		that.locate("headMessage").text(that.options.strings.instruction);
+
+		// Initialize numpad
+		that.atDigit = 0;
+		that.code = "";
+
+		// Initialize entry buttons
+		var buttons = that.locate("entryButtons");
+
+		for ( var i = 0; i < buttons.length; i++) {
+			attachButtonHandler(that, buttons[i], i + 1);
+		}
+	};
+
+	/**
+	 * Component's creator function.
+	 * 
+	 * @param {Object}
+	 *            container, DOM element that will correspond to the component.
+	 * @param {Object}
+	 *            options, the component's options.
+	 */
+	fluid.engage.codeEntry = function(container, options) {
+		var that = fluid.initView("fluid.codeEntry", container, options);
+
+		that.enterDigit = function(digit) {
+			getCurrentDigitField(that).text(digit);
+			if (that.atDigit === 0) {
+				if (digit !== 0) {
+					that.code += digit;
+				}
+				that.atDigit++;
+			} else {
+				that.code += digit;
+				var url = that.options.getArtifactUrlForCode(that);
+				if (url) {
+					redirectSequence(that, url);
+				} else {
+					wrongCodeSequence(that);
+				}
+			}
+		};
+
+		that.deleteLastDigit = function() {
+			if (that.atDigit === 1) {
+				that.atDigit--;
+				that.code = "";
+				getCurrentDigitField(that).text("");
+			}
+		};
+
+		setup(that);
+
+		return that;
+	};
+
+	fluid
+			.defaults(
+					"fluid.codeEntry",
+					{
+						navigationBar : {
+							type : "fluid.engage.navigationBar"
+						},
+						selectors : {
+							heading : ".flc-heading",
+							headMessage : ".flc-head-message",
+							firstDigitField : ".flc-first-digit",
+							secondDigitField : ".flc-second-digit",
+							entryButtons : "img[class*=flc-button]"
+						},
+						styles : {
+							invalidCode : "fl-invalid-code"
+						},
+						strings : {
+							title : "Enter object code",
+							header : "Enter object code",
+							instruction : "Enter code from the object's label to learn more about the object.",
+							invalidCode : "Invalid code. Please try again",
+							redirecting : "Opening artifact page."
+						},
+						redirectDelay : 1000,
+						wrongCodeCleanupDelay : 1000,
+						getArtifactUrlForCode: getArtifactUrlForCode
+					});
 })(jQuery);
Index: tests/component-tests/codeEntry/html/CodeEntryView-test.html
===================================================================
--- tests/component-tests/codeEntry/html/CodeEntryView-test.html	(revision 9309)
+++ tests/component-tests/codeEntry/html/CodeEntryView-test.html	(working copy)
@@ -14,6 +14,7 @@
         <script type="text/javascript" src="../../../../../fluid-infusion/src/webapp/tests/lib/qunit/js/testrunner.js"></script>
         <script type="text/javascript" src="../../../../../fluid-infusion/src/webapp/tests/test-core/jqUnit/js/jqUnit.js"></script>
 
+        <script type="text/javascript" src="../../../../../fluid-engage-core/components/navigationBar/js/NavigationBar.js"></script>
 		<script type="text/javascript" src="../../../../../fluid-engage-core/components/codeEntry/js/CodeEntryView.js"></script>
 
 		<script type="text/javascript" src="../../../../../fluid-engage-core/tests/component-tests/codeEntry/js/CodeEntryTests.js"></script>
#P fluid-engage-kettle
Index: src/main/webapp/services/codeEntry/js/codeEntryService.js
===================================================================
--- src/main/webapp/services/codeEntry/js/codeEntryService.js	(revision 9350)
+++ src/main/webapp/services/codeEntry/js/codeEntryService.js	(working copy)
@@ -22,10 +22,11 @@
      * @param {Object} artifact, the artifact retrieved from CouchDB
      * @param dbName, the name of the database the artifact comes from
      */
-    var compileTargetUrl = function (artifact, dbName) {
+    var compileTargetUrl = function (artifact, dbName, lang) {
         var baseArtifactUrl = "../artifacts/view.html";
         
-        return baseArtifactUrl + "?" + $.param({q: artifact.linkTarget, db: dbName});        
+        return baseArtifactUrl + "?" +
+        	$.param({accessNumber: artifact.artifactAccessionNumber, db: dbName, lang: lang});        
     };
     
     /**
@@ -37,15 +38,28 @@
      * @param {Object} params, URL parameters passed to this handler.
      */
     var getArtifactLink = function (config, params) {
-        var url = fluid.stringTemplate(config.codeEntryQueryURLTemplate, {
+    	var keyTemplate = "{\"objectCode\":\"%objectCode\",\"lang\":\"%lang\"}";
+    	
+    	var key = fluid.stringTemplate(keyTemplate, {
+    		objectCode: params.code,
+    		lang: params.lang
+    	});
+    	
+        var url = fluid.stringTemplate(config.viewURLTemplateWithKey, {
             dbName: params.db,
             view: config.views.byObjectCode,
-            query: params.code
+            key: key
         });
-        
+
         var artifact = {};
         
         var success = function (data) {
+        	// Workaround for '\n' character inserted at the end of the
+        	// returned data
+        	if (data.charAt(data.length - 1) === "\n") {
+        		data = data.substring(0, data.length - 1);
+        	}
+        	
             artifact = JSON.parse(data);
         };
         
@@ -61,13 +75,13 @@
             error: error
         });
         
-        if (artifact.total_rows > 0) {
-            var mappedArtifact =  fluid.engage.mapModel(artifact.rows[0].doc,
+        if (artifact.rows.length > 0) {
+            var mappedArtifact =  fluid.engage.mapModel(artifact.rows[0],
                     params.db);
             
             return {
                 artifactFound: true,
-                artifactLink: compileTargetUrl(mappedArtifact, params.db)
+                artifactLink: compileTargetUrl(mappedArtifact, params.db, params.lang)
             };
         } else {
             return {artifactFound: false};
@@ -121,6 +135,14 @@
             if (strings) {
             	options.strings = strings;
             }        	 
+            
+            var requestUri = env.REQUEST_URI;
+            options.codeCheckUrlTemplate = requestUri.substring(0, requestUri.lastIndexOf("/"));
+            options.codeCheckUrlTemplate += "/codeEntryService.js?" + $.param({
+            	db: context.urlState.params.db,
+            	lang: context.urlState.params.lang,
+            	code: "%objectCode"
+            });
         	
             var initBlock = {
             		ID: "initBlock",
Index: src/main/webapp/application/engageConfig.json
===================================================================
--- src/main/webapp/application/engageConfig.json	(revision 9309)
+++ src/main/webapp/application/engageConfig.json	(working copy)
@@ -7,7 +7,6 @@
 queryURLTemplate: "http://142.150.154.59:5984/%dbName/_fti/lucene/%view?include_docs=true&q=%query",
 viewURLTemplate: "http://142.150.154.59:5984/%dbName/%view",
 viewURLTemplateWithKey: "http://142.150.154.59:5984/%dbName/%view?key=%key",
-codeEntryQueryURLTemplate: "http://142.150.154.59:5984/%dbName/_fti/lucene/%view?include_docs=true&q=%query",
 initServices: [
     "fluid.engage.initHomeService",
     "fluid.artifactView.initMarkupFeed", 
@@ -36,7 +35,7 @@
     catalogueArtifacts: "_design/catalogue/_view/browse",
     exhibitions: "_design/exhibitions/_view/browse",
     artifactByAccession: "_design/artifacts/_view/view",
-    byObjectCode: "by_object_code"
+    byObjectCode: "_design/artifacts/_view/viewByObjectCode"
 },
 mount: {
     infusion: {
Index: src/main/webapp/application/engageStandaloneConfig.json
===================================================================
--- src/main/webapp/application/engageStandaloneConfig.json	(revision 9309)
+++ src/main/webapp/application/engageStandaloneConfig.json	(working copy)
@@ -7,7 +7,6 @@
 queryURLTemplate: "http://142.150.154.59:5984/%dbName/_fti/lucene/%view?include_docs=true&q=%query",
 viewURLTemplate: "http://142.150.154.59:5984/%dbName/%view",
 viewURLTemplateWithKey: "http://142.150.154.59:5984/%dbName/%view?key=%key",
-codeEntryQueryURLTemplate: "http://142.150.154.59:5984/%dbName/_fti/lucene/%view?include_docs=true&q=%query",
 initServices: [
     "fluid.engage.initHomeService",
     "fluid.artifactView.initMarkupFeed", 
@@ -34,7 +33,7 @@
     catalogueArtifacts: "_design/catalogue/_view/browse",
     exhibitions: "_design/exhibitions/_view/browse",
     artifactByAccession: "_design/artifacts/_view/view",
-    byObjectCode: "by_object_code"
+    byObjectCode: "_design/artifacts/_view/viewByObjectCode"
 },
 mount: {
     infusion: {
