コード例 #1
0
        /**
         * List the contents of the Home folder.
         *
         */
        public void listHomeFolder(User user)
        {
            Folder home = null;

            WorkspaceObject[] contents = null;

            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());

            try
            {
                // User was a primary object returned from the login command
                // the Object Property Policy should be configured to include the
                // 'home_folder' property. However the actuall 'home_folder' object
                // was a secondary object returned from the login request and
                // therefore does not have any properties associated with it. We will need to
                // get those properties explicitly with a 'getProperties' service request.
                home = user.Home_folder;
            }
            catch (NotLoadedException e)
            {
                exampleForm.appendTxt(e.Message);
                exampleForm.appendTxt("The Object Property Policy ($TC_DATA/soa/policies/Default.xml) is not configured with this property.");
                return;
            }

            try
            {
                ModelObject[] objects    = { home };
                String[]      attributes = { "contents" };

                // *****************************
                // Execute the service operation
                // *****************************
                dmService.GetProperties(objects, attributes);


                // The above getProperties call returns a ServiceData object, but it
                // just has pointers to the same object we passed into the method, so the
                // input object have been updated with new property values
                contents = home.Contents;
            }
            // This should never be thrown, since we just explicitly asked for this
            // property
            catch (NotLoadedException /*e*/) {}

            exampleForm.appendTxt("");
            exampleForm.appendTxt("Home Folder:");
            exampleForm.printObjects(contents);
        }
コード例 #2
0
        /**
         * Perform a simple query of the database
         *
         */
        public void queryItems()
        {
            ImanQuery query = null;

            // Get the service stub
            SavedQueryService     queryService = SavedQueryService.getService(MyFormAppSession.getConnection());
            DataManagementService dmService    = DataManagementService.getService(MyFormAppSession.getConnection());

            try
            {
                // *****************************
                // Execute the service operation
                // *****************************
                GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();


                if (savedQueries.Queries.Length == 0)
                {
                    exampleForm.appendTxt("There are no saved queries in the system.");
                    return;
                }

                // Find one called 'Item Name'
                for (int i = 0; i < savedQueries.Queries.Length; i++)
                {
                    if (savedQueries.Queries[i].Name.Equals("Item Name"))
                    {
                        query = savedQueries.Queries[i].Query;
                        break;
                    }
                }
            }
            catch (ServiceException e)
            {
                exampleForm.appendTxt("GetSavedQueries service request failed.");
                exampleForm.appendTxt(e.Message);
                return;
            }

            if (query == null)
            {
                exampleForm.appendTxt("There is not an 'Item Name' query.");
                return;
            }

            try
            {
                // Search for all Items, returning a maximum of 25 objects
                QueryInput[] savedQueryInput = new QueryInput[1];
                savedQueryInput[0]                = new QueryInput();
                savedQueryInput[0].Query          = query;
                savedQueryInput[0].MaxNumToReturn = 25;
                savedQueryInput[0].LimitList      = new Teamcenter.Soa.Client.Model.ModelObject[0];
                savedQueryInput[0].Entries        = new String[] { "Item Name" };
                savedQueryInput[0].Values         = new String[1];
                savedQueryInput[0].Values[0]      = "*";

                //*****************************
                //Execute the service operation
                //*****************************
                SavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
                QueryResults         found            = savedQueryResult.ArrayOfResults[0];


                exampleForm.appendTxt("");
                exampleForm.appendTxt("Found Items:");
                // Page through the results 10 at a time
                for (int i = 0; i < found.ObjectUIDS.Length; i += 10)
                {
                    int pageSize = (i + 10 < found.ObjectUIDS.Length) ? 10 : found.ObjectUIDS.Length - i;

                    String[] uids = new String[pageSize];
                    for (int j = 0; j < pageSize; j++)
                    {
                        uids[j] = found.ObjectUIDS[i + j];
                    }
                    ServiceData   sd        = dmService.LoadObjects(uids);
                    ModelObject[] foundObjs = new ModelObject[sd.sizeOfPlainObjects()];
                    for (int k = 0; k < sd.sizeOfPlainObjects(); k++)
                    {
                        foundObjs[k] = sd.GetPlainObject(k);
                    }

                    exampleForm.printObjects(foundObjs);
                }
            }
            catch (ServiceException e)
            {
                exampleForm.appendTxt("ExecuteSavedQuery service request failed.");
                exampleForm.appendTxt(e.Message);
                return;
            }
        }