Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isValidSetMember method to core API. #154

Merged
merged 2 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/client/gmeNodeGetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,16 @@ define([], function () {
}
};

GMENode.prototype.isValidSetMemberOf = function (setOwnerPath, name) {
var setOwner = _getNode(this._state.nodes, setOwnerPath);

if (setOwner) {
return this._state.core.isValidSetMemberOf(this._state.nodes[this._id].node, setOwner, name);
} else {
return false;
}
};

GMENode.prototype.getValidAspectNames = function () {
return this._state.core.getValidAspectNames(this._state.nodes[this._id].node);
};
Expand Down Expand Up @@ -666,4 +676,4 @@ define([], function () {
}

return getNode;
});
});
22 changes: 22 additions & 0 deletions src/common/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,28 @@ define([
return core.isValidTargetOf(node, source, name);
};

/**
* Checks if the node can be a member of the given set at the provided set-owner node. This does not take
* cardinality rules into account.
* @param {module:Core~Node} node - the node in question.
* @param {module:Core~Node} setOwner - the owner of the set.
* @param {string} name - the name of the set.
*
* @return {bool} The function returns true if according to the META rules, the given node is a valid
* member of set of the given set-owner.
*
* @throws {CoreIllegalArgumentError} If some of the parameters don't match the input criteria.
* @throws {CoreInternalError} If some internal error took place inside the core layers.
*/
this.isValidSetMemberOf = function (node, setOwner, name) {
ensureNode(node, 'node');
ensureNode(setOwner, 'setOwner');
ensureType(name, 'name', 'string');

// This is not a typo - the isValidTargetOf method can be reused.
return core.isValidTargetOf(node, setOwner, name);
};

/**
* Returns the list of the META defined attribute names of the node.
* @param {module:Core~Node} node - the node in question.
Expand Down
9 changes: 8 additions & 1 deletion test/client/js/client/gmeNodeGetter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,13 @@ describe('gmeNodeGetter', function () {
expect(node.isValidTargetOf('/1303043463/1448030591', 'setPtr')).to.eql(false);
});

it('should check if the node is a valid member of the given set', function () {
var node = getNode('/1303043463/1044885565', logger, basicState, basicStoreNode);

expect(node.isValidSetMemberOf('/1303043463/2119137141', 'setPtr')).to.eql(true);
expect(node.isValidSetMemberOf('/1303043463', 'setPtr')).to.eql(false);
});


it('should return the common base', function () {
var node = getNode('/175547009/871430202', logger, basicState, basicStoreNode);
Expand Down Expand Up @@ -896,4 +903,4 @@ describe('gmeNodeGetter', function () {

expect(node.getLibraryRootId('mope')).to.equal(null);
});
});
});
33 changes: 32 additions & 1 deletion test/common/core/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('core', function () {
'setMemberRegistry', 'delMemberRegistry', 'isMemberOf', 'getGuid',
'setGuid', 'getConstraint', 'setConstraint', 'delConstraint', 'getConstraintNames',
'getOwnConstraintNames', 'isTypeOf', 'isValidChildOf', 'getValidPointerNames',
'getValidSetNames', 'isValidTargetOf', 'getValidAttributeNames',
'getValidSetNames', 'isValidTargetOf', 'isValidSetMemberOf', 'getValidAttributeNames',
'getOwnValidAttributeNames', 'isValidAttributeValueOf', 'getValidAspectNames',
'getOwnValidAspectNames', 'getAspectMeta', 'getJsonMeta', 'getOwnJsonMeta',
'clearMetaRules', 'setAttributeMeta', 'delAttributeMeta', 'getAttributeMeta',
Expand Down Expand Up @@ -2841,6 +2841,37 @@ describe('core', function () {
}
});

it('should throw @isValidSetMemberOf if not valid parameters are given', function () {
var myError;

try {
core.isValidSetMemberOf('string');
} catch (e) {
myError = e;
} finally {
expect(myError.name).to.eql('CoreIllegalArgumentError');
myError = null;
}

try {
core.isValidSetMemberOf(rootNode, 'notnode');
} catch (e) {
myError = e;
} finally {
expect(myError.name).to.eql('CoreIllegalArgumentError');
myError = null;
}

try {
core.isValidSetMemberOf(rootNode, rootNode, {});
} catch (e) {
myError = e;
} finally {
expect(myError.name).to.eql('CoreIllegalArgumentError');
myError = null;
}
});

it('should throw @getValidAttributeNames if not valid node is given', function () {
var myError;

Expand Down