1 /*
  2  * Copyright © [2008-2009] Novell, Inc.  All Rights Reserved.
  3  * 
  4  * USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE DEVELOPER LICENSE AGREEMENT
  5  * OR OTHER AGREEMENT THROUGH WHICH NOVELL, INC. MAKES THE WORK AVAILABLE.  THIS WORK 
  6  * MAY NOT BE ADAPTED WITHOUT NOVELL'S PRIOR WRITTEN CONSENT.
  7  * 
  8  * NOVELL PROVIDES THE WORK "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, 
  9  * INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR 
 10  * A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  NOVELL, THE AUTHORS OF THE WORK, AND THE 
 11  * OWNERS OF COPYRIGHT IN THE WORK ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER 
 12  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, 
 13  * OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE WORK.
 14  */
 15 
 16 /**
 17 * @fileoverview 
 18 * This file defines the Trust class, which represents a trust (role + realm)
 19 * @name Trust Class
 20 */
 21 
 22 /**
 23  * Constructs an instance of the Trust class based on passed-in properties.
 24  * @class
 25  * The class accepts a pre-defined set of Trust attributes, four of them are required: Name, 
 26  * Authority, CustomerId,  Type, the ID will be generated automatically; The Description and SourceTrustID
 27  * are optional.
 28  * <ul>
 29  * <li>Name: The trust name.
 30  * <li>Description: The description of the trust.
 31  *	<li>CustomerId: The ID of the customer this trust belongs to.
 32  *	<li>Authority: The user's surname
 33  *	<li>Type: The name of the trust type. Although in the actual trust object, it refers the trust type by ID, when
 34  *            the users gives the trust type, they give the trust type name, and the system will translate it into a system
 35  *            trust type ID.
 36  *	<li>SourceTrustID: The system trust ID in the original source.
 37  * </ul>
 38  * 
 39  * @constructor
 40  * @param {Hash} properties Initial properties (JSON notation) to define trust
 41  */
 42 
 43 function Trust(properties) {
 44  	this.impl =  new TrustImpl(properties);
 45  	return this.impl; 
 46 };
 47 
 48 /**
 49 * The save methods saves the trust object synchronously.
 50 * <p>Example:
 51 * <pre>
 52 * var trust1 = new Trust({
 53 *				Name:"Developer", 
 54 *				Authority:"SAP", 
 55 *				Description:"SAP Role", 
 56 *				Type:"Role", 
 57 *				CustomerId:"345"
 58 *				});
 59 * trust1.save();
 60 * </pre>
 61 * @return {Boolan}	Result
 62 * @throws {String} Throws an string exception describing the error.
 63 */
 64 Trust.prototype.save = function() {
 65 	return this.impl.save();
 66 };
 67 
 68 /**
 69 *  Deletes an existing trust. The actual trust object is never physically deleted from the database, it is
 70 * actually flagged as not-current in the system. After it's deleted, a trust can not be associated with
 71 * an account any more.
 72 */
 73 Trust.prototype.elide = function() {
 74 	this.impl.elide();
 75 };
 76 
 77 /**
 78 * Checks whether a trust object is current or not.
 79 *@return {Boolean} returns true when the trust is current.
 80 */
 81 Trust.prototype.isCurrent = function() {
 82 	this.impl.isCurrent();
 83 };
 84 
 85 /**
 86 * Retrieves all the accounts that are currently associated with this trust. If no accounts are
 87 * attached, an empty array ([]) will be returned.
 88 *@return {Account[]} Returns an array of accounts.
 89 */
 90 Trust.prototype.getAccounts = function() {
 91     return this.impl.getAccounts();
 92 }
 93 
 94 /**
 95 * Finds the trust(s) with the same attributes as the passed-in filter.
 96 * All attributes are matched as with an AND operator. You can pass in a string in JSON
 97 * notation or a prototype Trust object.
 98 * <p>Example:
 99 * <pre>
100 * var myTrusts = Trust.find({Name: "Developer"});
101 * </pre>
102 * @param {JSON} params notation of the trust attributes
103 * @return {Trust[]}	Returns an array of Trusts found. Only trusts that are currently 
104 * active will be returned. The array could be of size 0 if no trusts match the search criteria.
105 * @throws {String} Throws an string exception describing the error.
106 */
107 Trust.find = function(params){
108 	return TrustImpl.find(params);
109 };
110 
111 /**
112 * Checks whether the Trust API is supported or not.
113 *@return {Boolean}
114 */
115 Trust.isSupported = function() {
116 	return (typeof Packages.esecurity.db.object.TrustFactory["getInstance"] == "function");
117 };
118 
119