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 This file defines some internal methods related to the Trust class.
 18  * @see Trust
 19  * @name TrustImpl Class
 20  * @private
 21  */
 22 (function() {
 23 	function initialize() {
 24 		JSDataObject(TrustImpl, 
 25 				Packages.esecurity.db.object.TrustFactory.getInstance(), 
 26 				{
 27 					"Name": {
 28 						required: true
 29 					},
 30 					"Authority": {
 31 						required: true
 32 					},
 33 					"Description": {},
 34 					"CustomerId" : {
 35 						required: true
 36 					},
 37 					"SourceTrustID" : {}
 38 				}
 39 		);
 40 	}
 41 
 42 	/**
 43 	 * Constructs an instance of the TrustImpl class.
 44 	 * @class Internal Trust implementation.
 45 	 * @constructor
 46 	 * @param {Hash} properties Intial properties to define trust
 47 	 * @private
 48 	 * 
 49 	 */
 50 	TrustImpl = function(props){
 51 		try {
 52 			if (props && props.constructor != Object && props.constructor != TrustImpl) {
 53 				throw "Trust must be initialized with an object";
 54 			}
 55 			
 56 			if (props && ("Type" in props) && props["Type"]) {
 57 				this.Type = props["Type"];
 58 			} else if (props) {
 59 				throw "A Type property must be specified during initialization";
 60 			}
 61 			
 62 			if (!this.toDataObject) {
 63 				initialize();
 64 			}
 65 			
 66 			this.toDataObject(props);
 67 		} 
 68 		catch (e) {
 69 			throw String(e.toString());
 70 		}
 71 	}
 72 
 73 	/**
 74 	* Finds trust(s) that satisfy the filter passed in.
 75 	* @see Trust
 76 	* @private
 77 	*/
 78 	TrustImpl.find = function(params) {
 79 		initialize();
 80 		return TrustImpl.find(params);
 81 	}
 82 	
 83 	/**
 84 	 * Do not use this method directly - use the Trust class.
 85 	 * @param {Object} qcrit
 86 	 * @see Trust
 87 	 * @private
 88 	 */
 89 	TrustImpl.preFind = function(qcrit){
 90 		try {
 91 			var eqlCriterion = new Packages.esecurity.base.criteria.EqualToCriterion(Packages.esecurity.db.object.TrustFactory.getInstance().getStaticMetaData(), Packages.esecurity.db.object.Trust.CURRENT, true);
 92 			qcrit.addCriterion(eqlCriterion);
 93 			return qcrit;
 94 		} 
 95 		catch (e) {
 96 			throw String(e.toString());
 97 		}
 98 	};
 99 
100 	/**
101 	* Deletes an existing trust.
102 	* @see Trust
103 	* @private
104 	*/
105 	TrustImpl.prototype.elide = function() {
106 		var dobj = this.unwrap();
107 		dobj.elide();
108 	}
109 
110 	/**
111 	* Checks whether a trust is current or not.
112 	*@see Trust
113 	* @private
114 	*/
115 	TrustImpl.prototype.isCurrent = function() {
116 		var dobj = this.unwrap();
117 		return dobj.getCurrent();
118 	}
119 
120 	/**
121 	* Maps the trust type name into internal trust type ID and set the trustTypeId to the data object.
122 	*@see Trust
123 	*@private
124 	*
125 	*/
126 	TrustImpl.prototype.preSave = function(dobj) {
127 		var trustType = TrustType.find({"Name": this.Type});
128 		if (!trustType || trustType.length == 0) {
129 			throw "Could not find trust type " + this.Type;
130 		}
131 		dobj.setTrustTypeId(trustType[0].TrustTypeId);
132 	}
133 	
134 	/**
135 	* Retrieves the account(s) associated with the trust.
136 	*@see Trust
137 	*@private
138 	*/
139 	TrustImpl.prototype.getAccounts = function() {
140 	    var dobj = this.unwrap();
141         var ret = [];
142 
143         var list = dobj.getAccounts();
144         if (list && (list.size() > 0)) {
145             for(var i = 0; i < list.size(); ++i ) {
146                 ret[i] = AccountImpl.fromDataObject(list.get(i));
147             }
148         }		
149 
150         return ret;
151     }
152 
153 })();