### Eclipse Workspace Patch 1.0
#P fluid-engage-kettle
Index: src/main/webapp/application/engageConfig.json
===================================================================
--- src/main/webapp/application/engageConfig.json	(revision 9461)
+++ src/main/webapp/application/engageConfig.json	(working copy)
@@ -6,6 +6,7 @@
 loaderFunction: "fluid.engage.initEngageApp",
 couchDBBaseUrl: "http://142.150.154.59:5984",
 queryURLTemplate: "http://142.150.154.59:5984/%dbName/_fti/lucene/%view?include_docs=true&q=%query",
+queryURLTemplateHighLimit: "http://142.150.154.59:5984/%dbName/_fti/lucene/%view?include_docs=true&limit=256&q=%query",
 viewURLTemplate: "http://142.150.154.59:5984/%dbName/%view",
 viewURLTemplateWithKey: "http://142.150.154.59:5984/%dbName/%view?key=%key",
 querySingleDocumentURLTemplate: "http://142.150.154.59:5984/%dbName/%id",
Index: src/main/webapp/services/myCollection/js/myCollectionService.js
===================================================================
--- src/main/webapp/services/myCollection/js/myCollectionService.js	(revision 9461)
+++ src/main/webapp/services/myCollection/js/myCollectionService.js	(working copy)
@@ -48,29 +48,25 @@
             if (!museums[artifact.museum]) {
                 museums[artifact.museum] = [];
             }
-            museums[artifact.museum].push(artifact.id);
+            museums[artifact.museum].push(artifact.artifactId);
         });
         
         return museums;
     };
     
-    /**
-     * Returns an array of objects containing the database and the URL to query artifact data by.
-     * 
-     *  @param {Object} config, the JSON config file for Engage.
-     *  @param user, the user document from Couch
-     */
-    var buildArtifactURLsByMuseum = function (urlTemplate, view, user) {
+    var buildArtifactURLsByMuseum = function (urlTemplate, view, user, lang) {
         var artifactsByMuseum = groupArtifactsByMuseum(user);
         var urlsByMuseum = [];
         
         // Go through the artifacts in each museum and compile up a giant OR query for Couch.
         for (var museum in artifactsByMuseum) {
-            var artifacts = artifactsByMuseum[museum];            
+            var artifacts = artifactsByMuseum[museum];
             if (artifacts && artifacts.length > 0) {
                 var query = "";
                 for (var i = 0; i < artifacts.length; i++) {
-                    query += artifacts[i];
+                    query += encodeURIComponent("(" + artifacts[i]);
+                    query += encodeURIComponent(" AND ");
+                    query += encodeURIComponent(lang + ")");
                     if (i < artifacts.length - 1) {
                         query += encodeURIComponent(" OR ");
                     }
@@ -177,12 +173,33 @@
         return fluid.transform(dataRows, function (row) {
             var artifact = preMap(row.doc, database);
             var mappedModel = fluid.engage.mapModel(artifact, database);
-            mappedModel.artifactId = artifact.value.artifactId; // Another ugly walkaround that should be dealt with
             return mappedModel;
         });
     };
     
     /**
+     * Restores the original order of the artifacts as recorded in the user object.
+     * 
+     * @param {Object} artifacts, the artifacts to sort;
+     * @param {Object} user, the user object.
+     */
+    var restoreArtifactsOrder = function (artifacts, user) {
+        var result = [];
+        
+        var originalArtifacts = user.collection.artifacts;
+
+        for (var i = 0; i < originalArtifacts.length; i++) {
+            for (var j = 0; j < artifacts.length; j++) {
+                if (artifacts[j].artifactId === originalArtifacts[i].artifactId) {
+                    result.push(artifacts[j]);
+                }
+            }
+        }
+        
+        return result;
+    };
+    
+    /**
      *  Fetches data from Couch and returns a NavList-friendly array of artifact data.
      
      *  @param {Object} params, the parameters passed to the service.
@@ -197,7 +214,7 @@
         // TODO: Despite being called getCollection(), this function actually returns user documents.
         // TODO: We should replace this with the user dataSource defined in userService.
         var user = fluid.myCollection.common.getCollection(userID, config);
-        var urls = buildArtifactURLsByMuseum(config.queryURLTemplate, config.views.artifactsByID, user);
+        var urls = buildArtifactURLsByMuseum(config.queryURLTemplateHighLimit, config.views.artifactsByID, user, params.lang);
 
         var collectedArtifacts = [];
         
@@ -208,8 +225,8 @@
             collectedArtifacts = collectedArtifacts.concat(mappedArtifactsForMuseum);
         });
         
-        // My Collection displays artifact data in reverse order of collection--newest first, so flip the array around.
-        return collectedArtifacts.reverse();
+        // CouchDB returns the artifacts ordered by their UUID so we need to restore their original order
+        return restoreArtifactsOrder(collectedArtifacts, user);
     };
 
     /**
Index: src/main/webapp/services/myCollection/js/collectOperations.js
===================================================================
--- src/main/webapp/services/myCollection/js/collectOperations.js	(revision 9461)
+++ src/main/webapp/services/myCollection/js/collectOperations.js	(working copy)
@@ -29,7 +29,7 @@
             collection: pathInfo[length - 4],
             museumID: pathInfo[length -  3],
             artifacts: pathInfo[length - 2],
-            artifactUUID: pathInfo[length - 1]
+            artifactId: pathInfo[length - 1]
         };
     };
     
@@ -41,7 +41,7 @@
     var compileArtifactData = function (pathInfo) {
         var pathSegs = parsePathInfo(pathInfo);
         return {
-            id: pathSegs.artifactUUID,
+            artifactId: pathSegs.artifactId,
             museum: pathSegs.museumID,
             uuid: pathSegs.userUUID
         };
@@ -53,7 +53,7 @@
      * @param {Object} artifactData, the artifact object.
      */
     var addArtifact = function (userCollection, artifactData) {    
-        userCollection.collection.artifacts.push({"museum": artifactData.museum, "id": artifactData.id});
+        userCollection.collection.artifacts.push({"museum": artifactData.museum, "artifactId": artifactData.artifactId});
     };
     
     /**
@@ -64,7 +64,7 @@
     var removeArtifact = function (userCollection, artifactData) {
         userCollection.collection.artifacts = $.makeArray(
             $(userCollection.collection.artifacts).filter(function () {
-                return this.id !== artifactData.id;
+                return this.artifactId !== artifactData.artifactId;
             })
         );
     };
#P fluid-engage-core
Index: framework/js/Engage.js
===================================================================
--- framework/js/Engage.js	(revision 9461)
+++ framework/js/Engage.js	(working copy)
@@ -124,7 +124,8 @@
                 "artifactRelated": "value.relatedArtifacts",
                 "artifactRelatedCount": "value.relatedArtifactsCount",
                 "id": "value.accessnumber",
-                "uuid": "id"
+                "uuid": "id",
+                "artifactId": "value.artifactId"
             },
             mappers: {
                 getImage: function (value) {
@@ -133,9 +134,9 @@
                         if (value) {
                             $.each($.makeArray(value), function (index, image) {
                                 if (image.primarydisplay === "yes" && image.imagesfiles) {
-                                     $.each(image.imagesfiles.imagefile, function (index, imagefile) {
-                                         images[imagefile.format] = imagefile.nodetext;
-                                     });
+                                    $.each(image.imagesfiles.imagefile, function (index, imagefile) {
+                                        images[imagefile.format] = imagefile.nodetext;
+                                    });
                                 }
                             });
                         }
Index: components/artifactView/js/ArtifactCollectView.js
===================================================================
--- components/artifactView/js/ArtifactCollectView.js	(revision 9461)
+++ components/artifactView/js/ArtifactCollectView.js	(working copy)
@@ -10,7 +10,7 @@
 
  */
 
-/*global jQuery, fluid*/
+/*global jQuery, fluid, setTimeout*/
 "use strict";
 
 fluid = fluid || {};
@@ -51,7 +51,7 @@
         var artifacts = user.collection.artifacts;
         for (var i = 0; i < artifacts.length; i++) {
             var artifact = artifacts[i];
-            if (artifact.id === artifactId) {
+            if (artifact.artifactId === artifactId) {
                 return true;
             }
         }
@@ -62,7 +62,7 @@
         that.model.user = fluid.engage.user.currentUser(that);
         
         // Setup the collect/uncollect link and status.
-        that.isCollected = isArtifactInUserCollection(that.model.artifact.uuid, that.model.user);
+        that.isCollected = isArtifactInUserCollection(that.model.artifact.artifactId, that.model.user);
         that.collectLink = that.locate("collectLink");
         that.collectLink.text(that.isCollected ? that.options.strings.uncollect : 
                                                  that.options.strings.collect);
@@ -94,7 +94,7 @@
         
         that.collectArtifact = function () {
             $.ajax({
-                url: buildCollectURL(that.model.user._id, that.model.museumID, that.model.artifact.uuid),
+                url: buildCollectURL(that.model.user._id, that.model.museumID, that.model.artifact.artifactId),
                 type: "POST"
             });
             confirmCollect(that, that.options.strings.collectedMessage, that.options.strings.uncollect);
@@ -103,7 +103,7 @@
         
         that.uncollectArtifact = function () {
             $.ajax({
-                url: buildCollectURL(that.model.user._id, that.model.museumID, that.model.artifact.uuid),
+                url: buildCollectURL(that.model.user._id, that.model.museumID, that.model.artifact.artifactId),
                 type: "DELETE"
             });
             confirmCollect(that, that.options.strings.uncollectedMessage, that.options.strings.collect);
