using System; using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI; using TestFramework; namespace Tests.resource { /// <summary> /// Summary description for ResourceCCC. /// /// this sample creates an instance of a client cost center, /// queries it and then assigns it to a resource in /// the RPM epository /// </summary> public class ResourceCCC { public ResourceCCC() { } //All these variables are used in this sample public static String resourceName = "IBM_testABCDEF"; public static String cccName = "IBMCLIENTCOSTCENTER"; public static String cccDesc = "ABCDEF123"; public static String folderName = "IBMFOLDER"; public static String folderDesc = "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 client cost center ResourceScope rScope = new ResourceScope(); // assign the scope so it keeps the link // with the client cost center rScope.resourceCostCenterAssignments = true; // create a client cost center ClientCostCenter ccc = new ClientCostCenter(); // 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]; // create a client folder and division (if needed) // those are the parents of the client cost center ClientFolder folder = new ClientFolder(); folder.name = folderName; folder.description = folderDesc; // initialise the client cost center with default values ccc.description = cccDesc; ccc.name = cccName; // assign the folder as a parent // of the client cost center ccc.parent = folder; // assign the client cost center to the folder folder.clientCostCenters = new ClientCostCenter[] {ccc}; // create a client cost center scope // and adjust it so it saves the client cost center ClientCostCenterScope cScope = new ClientCostCenterScope(); cScope.clientCostCenters = new ClientCostCenterScope(); // save the folder and client // cost center in the RPM repository // use a reload type that enables // you to use the saved data SaveResult save = APISetup.application.save(sessionid, folder, cScope, ReloadType.SavedResult ); APISetup.checkForErrors( save ); // load the client cost center to use it ccc = (ClientCostCenter)APISetup.application. loadFromXpath(sessionid, "/ClientCostCenter[name='" + cccName + "']", cScope ).rpmObjectList[0]; // create a resource cost center assignment ResourceCostCenterAssignment assign = new ResourceCostCenterAssignment(); // initialize the assignment with default values assign.finishDate = new DateTime(2005,11,10,10,10,10,10); assign.startDate = new DateTime(2005,10,10,10,10,10,10); // assign the client cost center to the assignment assign.clientCostCenter = ccc; // assign the resource as a parent of the assignment assign.parent = res; // assign the client cost center // assignment to the ressource res.resourceCostCenterAssignments = new ResourceCostCenterAssignment[] {assign}; // save the resource in the RPM repository // use the sessionid acquired in the setUp // use the resource scope save = APISetup.application.save(sessionid, res, rScope, ReloadType.SavedResult ); APISetup.checkForErrors( save ); // end the communication with the api. APISetup.CleanUp(sessionid); } } }