Skip to content

Instantly share code, notes, and snippets.

@jimklo
Created Dec 21, 2011
Embed
What would you like to do?
// a library for resource_data validation
exports.init = function (newDoc, oldDoc, userCtx, secObj) {
var a = {};
a.is_resource_data = function() {
return newDoc.doc_type === "resource_data_distributable" && newDoc.resource_data && newDoc.resource_locator;
};
a.has_dct_conformsTo = function() {
try {
var nsdl = eval(newDoc.resource_data);
var dct = new Namespace("http://purl.org/dc/terms/");
var stds = nsdl..dct::conformsTo
if (stds.length > 0) {
return true;
}
} catch (error) {
log("error:"+error);
return false;
}
};
a.is_lr_paradata = function() {
try {
if (newDoc.resource_data_type === "paradata" && newDoc.payload_schema) {
for(var i=0; i<newDoc.payload_schema.length; i++) {
if (newDoc.payload_schema[i] === "LR Paradata 1.0") {
log("We have Paradata!");
return true;
}
}
}
return false;
} catch (error) {
return false;
}
};
a.has_oer_commons_rubric = function() {
try {
} catch (error) {
return false;
}
};
return a;
};
function (newDoc, oldDoc, userCtx, secObj) {
try {
var v = require("lib/validate").init(newDoc, oldDoc, userCtx, secObj);
var a = require("lib/alignment").init(newDoc, oldDoc, userCtx, secObj);
log("validating for alignment.");
if (a.is_resource_data()) {
if (a.has_dct_conformsTo()) {
log(newDoc._id +" is good resource for alignment.");
return true;
}
if (a.is_lr_paradata()) {
log(newDoc._id + " is a valid paradata resource.");
return true;
}
}
} catch (error) {
log("ERROR: "+ error);
throw { "error": error };
}
log(newDoc._id + " is NOT being replicated.");
throw v.forbidden(newDoc._id + " does not contain common core standards alignment metadata or paradata.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment