Skip to content

Commit

Permalink
[New] Support or condition
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Mar 23, 2021
1 parent c77867f commit 96d2122
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/constants/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export default class Constants {
static HAS_PRECEDING_VALUE = 'http://onto.fel.cvut.cz/ontologies/form/has-preceding-value';
static HAS_MEDIA_CONTENT = 'http://onto.fel.cvut.cz/ontologies/form/has-media-content';
static CONDITION = 'http://onto.fel.cvut.cz/ontologies/form/condition';
static OR_CONDITION = 'http://onto.fel.cvut.cz/ontologies/form/or-condition';
static HAS_SUB_CONDITION = 'http://onto.fel.cvut.cz/ontologies/form/has-sub-condition';
static HAS_PATTERN = 'http://onto.fel.cvut.cz/ontologies/form-lt/has-pattern';
static HAS_DECLARED_PREFIX = 'http://onto.fel.cvut.cz/ontologies/form-spin/has-declared-prefix';
static PREFIX = 'http://www.w3.org/ns/shacl#prefix';
Expand Down
18 changes: 18 additions & 0 deletions src/util/FormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,30 @@ export default class FormUtils {
return true;
}

static testOrCondition(condition) {
const hasSubCondition = condition[Constants.HAS_SUB_CONDITION];
if (! hasSubCondition) {
console.warn('Or condition does not have any sub-condition !');
}
for (const subCond of Utils.asArray(hasSubCondition)) {
if (this.testCondition(JsonLdObjectMap.getObject(subCond['@id']))){
return true;
}
}
return false;
}

static testCondition(condition) {
const isOrCondition = condition[Constants.HAS_SUB_CONDITION];
const acceptedValidationsValues = condition[Constants.ACCEPTS_VALIDATION_VALUE];
const acceptedAnswerValues = condition[Constants.ACCEPTS_ANSWER_VALUE];
const testedQuestions = condition[Constants.HAS_TESTED_QUESTION];
let question;

if (isOrCondition) {
return this.testOrCondition(condition);
}

if (acceptedValidationsValues && acceptedAnswerValues) {
console.warn('Support for validation and requirement constraints at same time is not implemented !');
}
Expand Down

0 comments on commit 96d2122

Please sign in to comment.