using System; using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI; using TestFramework; namespace Tests.resource { /// <summary> /// Summary description for ResourceOrganization. /// /// this samples creates an organization /// and assigns it to a resource in RPM repository /// </summary> public class ResourceOrganization { public ResourceOrganization() { } //All these variables are used in this sample public static String resourceName = "IBM_testABCDEF"; public static String orgName = "IBMORGANIZATION"; public static String orgDesc = "ABCDEF123"; public static String groupName = "IBMGROUP"; public static String groupDesc = "ABCDEF123"; public static String depName = "IBMDEPARTMENT"; public static String depDesc = "ABCDEF123"; public static String officeName = "IBMOFFICE"; public static String officeDesc = "ABCDEF123"; //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 resource wich we are going to use Resource res = null; // create a resourceScope to keep track of the relation // between the resource and the industry experience ResourceScope rScope = new ResourceScope(); // adjust resource scope to keep relation rScope.organizationalAssignment = true; // create organisationals Organization org = new Organization(); Group group = new Group(); Department dep = new Department(); Office office = new Office(); // create an organizational scope OrganizationalScope oScope = new OrganizationalScope(); // initialise the organizationals with default values // adjust the scope each time org.name = orgName; org.description = orgDesc; oScope.organizations = new OrganizationalScope(); group.name = groupName; group.description = groupDesc; org.groups = new Group[] {group}; oScope.groups = new OrganizationalScope(); dep.name = depName; dep.description = depDesc; group.departments = new Department[] {dep}; oScope.groups.departments = new OrganizationalScope(); office.name = officeName; office.description = officeDesc; dep.offices = new Office[] {office}; oScope.groups.departments.offices = new OrganizationalScope(); // after this step // Find the resource in RPM using XPath. // take resource in RPM repository by // its fullname or externalid res = (Resource)APISetup.application. loadFromXpath(sessionid, "/Resource[fullname='" + resourceName + "']", rScope ).rpmObjectList[0]; // save the calendar in the RPM repository SaveResult save = APISetup.application.save(sessionid, org, oScope, ReloadType.SavedResult ); APISetup.checkForErrors( save ); // reload organizational to use with actual ID org = (Organization)APISetup.application.loadFromXpath( sessionid, "/Organization[name='" + orgName + "']", oScope ).rpmObjectList[0]; // assign the organizational to the ressource res.organizationalAssignment.organizational = org; // save the resource in the RPM repository // use the sessionid acquired in the setUp // use a scope save = APISetup.application.save(sessionid, res, rScope, ReloadType.SavedResult ); APISetup.checkForErrors( save ); // end the communication with the api. APISetup.CleanUp(sessionid); } } }