Fix bug in vc builder when a failing matchop blocks the vc
Change-Id: Iad46e92a7e3c5b57f016cff0f0cdfb67c8b9d0a1
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index 24b24a7..4f7c7dc 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -156,13 +156,13 @@
// No valid string
doc = stringFactory.create({
- value : { "foo" : "bar" }
+ value : { "foo" : "bar" }
});
expect(doc).toBeUndefined();
// Change match type
doc = stringFactory.create({
- "match" : "match:ne"
+ "match" : "match:ne"
});
expect(doc.matchop()).toEqual('ne');
@@ -172,7 +172,7 @@
// Invalid match type
doc = stringFactory.create({
- "match" : { "foo" : "bar" }
+ "match" : { "foo" : "bar" }
});
expect(doc).toBeUndefined();
});
@@ -186,19 +186,21 @@
// change matcher
doc = regexFactory.create({
- match : "match:ne"
+ match : "match:ne"
});
expect(doc.matchop()).toEqual('ne');
+ expect(doc.rewrites()).toBeUndefined();
// Invalid matcher
doc = regexFactory.create({
- match : "match:chook"
+ match : "match:chook"
});
- expect(doc).toBeUndefined();
+ expect(doc.matchop()).toEqual('eq');
+ expect(doc.rewrites()).toBeDefined();
// Invalid regex
doc = regexFactory.create({
- value : "[^b"
+ value : "[^b"
});
expect(doc).toBeUndefined();
});
@@ -215,7 +217,7 @@
// Short date 1
doc = dateFactory.create({
- "value" : "2014-11"
+ "value" : "2014-11"
});
expect(doc.matchop()).toEqual('eq');
@@ -225,7 +227,7 @@
// Short date 2
doc = dateFactory.create({
- "value" : "2014"
+ "value" : "2014"
});
expect(doc.matchop()).toEqual('eq');
@@ -235,15 +237,17 @@
// Invalid date!
doc = dateFactory.create({
- "value" : "2014-11-050"
+ "value" : "2014-11-050"
});
expect(doc).toBeUndefined();
// Invalid matcher!
doc = dateFactory.create({
- "match" : "match:ne",
+ "match" : "match:ne",
});
- expect(doc).toBeUndefined();
+ expect(doc).toBeDefined();
+ expect(doc.rewrites()).toBeDefined();
+ expect(doc.matchop()).toEqual('eq');
});
it('should be serializale to JSON', function () {
@@ -285,11 +289,11 @@
doc = dateFactory.create();
expect(doc.toJson()).toEqual(jasmine.objectContaining({
- "@type" : "koral:doc",
- "type" : "type:date",
- "value" : "2014-11-05",
- "match" : "match:eq",
- "key" : 'pubDate'
+ "@type" : "koral:doc",
+ "type" : "type:date",
+ "value" : "2014-11-05",
+ "match" : "match:eq",
+ "key" : 'pubDate'
}));
doc = dateFactory.create({
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 6a44fa8..67bf37a 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -195,6 +195,8 @@
return;
};
+ var rewrite;
+
// There is a defined key
if (json["key"] !== undefined &&
typeof json["key"] === 'string') {
@@ -221,7 +223,10 @@
// Check match type
if (!KorAP._validStringMatchRE.test(this.matchop())) {
KorAP.log(802, "Match type is not supported by value type");
- return;
+
+ // Rewrite method
+ this.matchop('eq');
+ rewrite = 'modification';
};
// Set string value
@@ -237,7 +242,10 @@
if (!KorAP._validDateMatchRE.test(this.matchop())) {
KorAP.log(802, "Match type is not supported by value type");
- return;
+
+ // Rewrite method
+ this.matchop('eq');
+ rewrite = 'modification';
};
// Set value
@@ -260,7 +268,10 @@
if (!_validRegexMatchRE.test(this.matchop())) {
KorAP.log(802, "Match type is not supported by value type");
- return;
+
+ // Rewrite method
+ this.matchop('eq');
+ rewrite = 'modification';
};
this.value(json["value"]);
@@ -279,10 +290,16 @@
};
};
+ // Rewrite coming from the server
if (json["rewrites"] !== undefined) {
- this._rewrites = rewriteListClass.create(json["rewrites"]);
+ this.rewrite(json["rewrites"]);
+ }
+
+ // Rewrite coming from Kalamar
+ else if (rewrite !== undefined) {
+ this.rewrite(rewrite);
};
-
+
return this;
},
@@ -494,21 +511,29 @@
return this._rewrites;
},
+ rewrite : function (value) {
+ if (typeof value === 'string') {
+ value = [{
+ "@type" : "koral:rewrite",
+ "operation" : "operation:" + value,
+ "src" : "Kalamar"
+ }];
+ };
+ this._rewrites = rewriteListClass.create(value);
+ },
+
+ // Remove rewrite marker when the data changes
_changed : function () {
this.__changed = true;
-
- /*
- if (this._parent) {
- };
- */
if (this._rewrites === undefined)
return;
- delete this["_rewrites"];
+ delete this["_rewrites"];
if (this._element === undefined)
return;
+
this._element.classList.remove("rewritten");
},