SkillCompRessSample

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.resource  { 	/// <summary>
	/// Summary description for SkillCompRessSample.
	/// 
	/// In this sample, we create a skill and 
	/// competency resource attributes.
	/// </summary>
	public class SkillCompRessSample
	{
		public SkillCompRessSample()
		{

		}

		//All these variables are used in this sample
		public static String category = "IBMCATEGORY";
		public static String classification = "IBMCLASSIFICATION";
		public static String proficiency = "IBMPROFICIENCY";
		public static String skillName = "IBMSKILL";
		public static String compName = "IBMCOMPETENCY";

		// 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();
	

			// proficiency level object contained by :
			// - ResourceAttributeCompetencyProficiencyLevel,
			// - ResourceAttributeSkillProficiencyLevel.
			ProficiencyLevel level = (ProficiencyLevel)APISetup.
				application.loadFromXpath(
				sessionid, "/Proficiencylevel[value='Acquired']", 
				null ).rpmObjectList[0];

			/**
			 * Competency
			 **/
			// declare the objects you need to create a resource 
			// competency you need a proficiency level with a 
			// competency as parent
			// the competency needs a classification as parent
			// and the classification needs a category as parent.
			ResourceAttributeCompetencyCategory  compCat = 
				new ResourceAttributeCompetencyCategory();
			ResourceAttributeCompetencyClassification compClassi = 
				new ResourceAttributeCompetencyClassification();
			ResourceAttributeCompetency comp = 
				new ResourceAttributeCompetency();
			ResourceAttributeCompetencyProficiencyLevel compProf = 
				new ResourceAttributeCompetencyProficiencyLevel();

			// create a SaveResult object to save resource 
			// competency and skill
			SaveResult save = new SaveResult();

			// scope is necessary since many 
			// elements are saved at a time
			ResourceAttributeScope cScope = 
				new ResourceAttributeScope();
			
			// initialise every Resource Attribute with default 
			// values adjust scope to keep links between objects
			compCat.name = category; 
			cScope.categories = new ResourceAttributeScope();

			compClassi.parent = compCat;
			compClassi.name = classification;
			compCat.classifications = 
				new ResourceAttributeCompetencyClassification[] 
				{compClassi};
			cScope.classifications = new ResourceAttributeScope();

			comp.parent = compClassi;
			comp.name = compName; 
			compClassi.resourceAttributes = 
				new ResourceAttributeCompetency[] {comp};
			cScope.classifications.attributes = 
				new ResourceAttributeScope();

			
			compProf.parent = comp;
			compProf.name = level.value; 
			compProf.proficiencyLevel = level;
			comp.proficiencyLevels = new 
				ResourceAttributeCompetencyProficiencyLevel[] 
				{compProf};
			cScope.classifications.attributes.proficiencyLevels = 
				new ResourceAttributeScope();
			
			// after the creation of the objects
			// save the Resource Attribute Competency
			// use a scope to include all the elements
			save = APISetup.application.save(
				sessionid, compCat, cScope, ReloadType.SavedResult );
			APISetup.checkForErrors( save );

			/**
			 * Skill
			 **/
			// declare the objects you need to create a resource skill
			// you need a proficiency level with a skill as parent
			// the skill needs a classification as parent
			// and the classification needs a category as parent.
			ResourceAttributeSkillCategory skillCat = 
				new ResourceAttributeSkillCategory();
			ResourceAttributeSkillClassification skillClassi = 
				new ResourceAttributeSkillClassification();
			ResourceAttributeSkill skill = 
				new ResourceAttributeSkill();
			ResourceAttributeSkillProficiencyLevel skillProf = 
				new ResourceAttributeSkillProficiencyLevel();
			
			// scope is necessary since many 
			// elements are saved at a time
			ResourceAttributeScope sScope = 
				new ResourceAttributeScope();

			// initialise every Resource Attribute 
			// with default values
			// adjust scope to keep links between objects
			skillCat.name = category; 
			sScope.categories = new ResourceAttributeScope();

			skillClassi.parent = skillCat;
			skillClassi.name = classification;
			skillCat.classifications = 
				new ResourceAttributeSkillClassification[] 
				{skillClassi};
			sScope.classifications = new ResourceAttributeScope();

			skill.parent = skillClassi;
			skill.name = skillName; 
			skillClassi.resourceAttributes = 
				new ResourceAttributeSkill[] {skill};
			sScope.classifications.attributes = 
				new ResourceAttributeScope();

			skillProf.parent = skill;
			skillProf.name = level.value; 
			skillProf.proficiencyLevel = level;
			skill.proficiencyLevels = 
				new ResourceAttributeSkillProficiencyLevel[] 
				{skillProf};
			sScope.classifications.attributes.proficiencyLevels = 
				new ResourceAttributeScope();
			
			// after the creation of the objects
			// save the Resource Attribute skill
			// use a scope to include all the elements
			save = APISetup.application.save(
				sessionid,skillCat,sScope,ReloadType.SavedResult );
			APISetup.checkForErrors( save );


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

	}
}