PoolAttribute

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.pool { 	/// <summary>
	/// Summary description for PoolAttribute.
	/// 
	/// This sample loads a pool from RPM repository.
	/// It creates a pool attribute, assigns it
	/// to an existing pool. It also updates the attribute
	/// and queries it.
	/// </summary>
	public class PoolAttribute
	{
		public PoolAttribute()
		{

		}

		//All these variables are used in this sample
		public static String poolName = "IBMPOOL_ABC";
		public static String catName = "IBMCATEGORY";
		public static String catDesc = "ABCDEF_123";
		public static String className = "IBMCLASSIFICATION";
		public static String classDesc = "ABCDEF_123";
		public static String attName = "IBMATTRIBUTE";
		public static String attDesc = "ABCDEF_123";
		InputType[] attType = new InputType[6] {InputType.Date ,
										InputType.None ,
										InputType.Numeric,
										InputType.RiskAppetite ,
										InputType.RiskTolerance ,
										InputType.Text };

		//Session ID is use for all transaction and is get from the 
		//Authenticate.login function. The session ID will replace 
		// the User password while transacting
		public static String sessionid = "";

		public void sampleTest()
		{


			// start the communication with the api
			sessionid = APISetup.SetUp();


			// Declare the pool wich we are going to use
			Pool pool = null;

			// create a poolscope to keep track 
			// of the relation between 
			// the pool and its attribute
			PoolScope pScope = new PoolScope();

			//assign the scope to link with its attribute
			pScope.attributeAssignments = true;

			// declare a save result object
			SaveResult pSave = null;

			// Find the pool in RPM using XPath. 
			pool = (Pool)APISetup.application.loadFromXpath
				(sessionid, "/Pool[name='" + poolName + "']",
				pScope).rpmObjectList[0];

			// create a pool attribute scope
			AttributeScope aScope = new AttributeScope();

			// create a pool attribute, 
			// classification and its category
			AttributeCategory attCat = new AttributeCategory();
			AttributeClassification attClass = 
				new AttributeClassification();
			TestFramework.ApplicationAPI.Attribute att = 
				new TestFramework.ApplicationAPI.Attribute(); 

			// initialize the pool attribute category
			attCat.name = catName;
			attCat.description = catDesc;
			attCat.contextName = "Pool";
			attCat.deleted = false;
			aScope.category = new AttributeScope();

			// initialize the pool attribute classification
			attClass.name = className;
			attClass.description = classDesc;
			attClass.parent = attCat;
			attCat.classifications = 
				new AttributeClassification[] {attClass};
			aScope.classification = new AttributeScope();

			aScope.classification.attribute = new AttributeScope();

			//initialize the pool attribute
			attClass.attributes = 
				new TestFramework.ApplicationAPI.Attribute[6];

			// for logic enables creation of many attributes
			// in this case, we create an 
			// attribute for each attribute type
			for (int i = 0 ; i < 6 ; i ++)
			{
				att = new TestFramework.ApplicationAPI.Attribute();

				att.description = attDesc;
				att.parent = attClass;

				att.name = attName + i;
				att.inputType = attType[i];
				attClass.attributes[i] = att;

			}

			// save the attribute category in the RPM repository
			// use the sessionid acquired in the setUp
			// a scope is necessary to save the category, 
			// classification and the attributes
			// use a reloadType that alows you to continue 
			// working with the saved objects
			pSave = new SaveResult();
			pSave = APISetup.application.save(
				sessionid, attCat, aScope, ReloadType.SavedResult );

			// method showing the detail of any error in the save
			APISetup.checkForErrors( pSave );

			// initialize attribute scope so that 
			// you can load a classification with its attributes
			aScope = new AttributeScope();
			aScope.attribute = new AttributeScope();
			
			// create a pool attribute assignment
			AttributeAssignment assign = null;

			pool.attributeAssignments = new AttributeAssignment[6];

			for (int i = 0 ; i < 6 ; i ++)
			{
				// load the classification
				// use a scope to load all attributes as well
				att= (TestFramework.ApplicationAPI.Attribute)APISetup
					.application.loadFromXpath(sessionid, 
					"/Attribute[name = '" + attName + i + "']", 
					null).rpmObjectList[0];

				// initialize the pool attribute assignment
				assign = new AttributeAssignment();
				assign.attribute = att;
				assign.parent = pool;

				// assign the assignment to the pool
				pool.attributeAssignments[i] = assign;

			}

			// save the pool in the RPM repository
			// use the sessionid acquired in the setUp
			// a scope is necessary because we keep the attributes
			pSave = new SaveResult();
			pSave = APISetup.application.save(sessionid, pool, pScope
				, ReloadType.SavedResult );

			// method showing the detail of any error in the save
			APISetup.checkForErrors( pSave );

			// end the communication with the api.
			APISetup.CleanUp(sessionid);

		}
	}
}