From Aqua Dove, 9 Years ago, written in Plain Text.
Embed
  1. function (doc, meta) {
  2.  
  3.   var varSync = doc._sync;
  4.   var varDeleted = doc._deleted;
  5.  
  6.   var varKey;
  7.   var varValue;
  8.  
  9.  
  10.   /*
  11.     We do not want the view to fetch sync specific documents that are stored in the bucket.
  12.     The below if condition will ignore those documents
  13.   */
  14.   if (varSync === undefined || meta.id.substring(0,6) == "_sync:")
  15.     return;
  16.  
  17.   /*
  18.     We do not want the view to fetch deleted documents that are stored in the bucket.
  19.     The below if condition will ignore deleted documents
  20.   */
  21.   if (varDeleted)
  22.     return;
  23.  
  24.   varKey = [
  25.     doc.activityId,
  26.     doc.stateId,
  27.     doc.agent,
  28.     doc.agentMbox,
  29.     doc.agentName,
  30.     doc.agentOpenId,
  31.     doc.agentAccountName,
  32.     doc.agentAccountHomePage,
  33.     doc.agentMbox_sha1sum,
  34.     doc.registration,
  35.     doc.documentName,
  36.     doc.className
  37.   ];
  38.  
  39.   varValue = {
  40.     id: meta.id,
  41.     rev: varSync.rev,
  42.     activityId: doc.activityId,
  43.     stateId: doc.stateId,
  44.     agent: doc.agent,
  45.     agentMbox: doc.agentMbox,
  46.     agentName: doc.agentName,
  47.     agentOpenId: doc.agentOpenId,
  48.     agentAccountName:  doc.agentAccountName,
  49.     agentAccountHomePage: doc.agentAccountHomePage,
  50.     agentMbox_sha1sum: doc.agentMbox_sha1sum,
  51.     registration: doc.registration,
  52.     create_date: doc.create_date,
  53.     update_date: doc.update_date,
  54.     jsonPayload: doc.jsonPayload,
  55.     documentName: doc.documentName,
  56.     className: doc.className};
  57.  
  58.   if(meta.type == "json") {
  59.     if(doc.className && doc.className == "org.apereo.openlrs.model.event.v2.ActivityStateEvent") {
  60.      
  61.       if (doc.activityId, doc.agentAccountName, doc.registration) {
  62.         emit(varKey, varValue);
  63.       }
  64.  
  65.     }
  66.   }
  67. }