Пример #1
0
        /**
         * Reserve Revision IDs
         *
         * @param items       Array of Items to reserve Ids for
         *
         * @return Map of RevisionIds
         *
         * @throws ServiceException  If any partial errors are returned
         */
        public Hashtable generateRevisionIds(Item[] items) //throws ServiceException
        {
            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());

            GenerateRevisionIdsResponse response = null;

            GenerateRevisionIdsProperties[] input = null;
            input = new GenerateRevisionIdsProperties[items.Length];

            for (int i = 0; i < items.Length; i++)
            {
                GenerateRevisionIdsProperties property = new GenerateRevisionIdsProperties();
                property.Item     = items[i];
                property.ItemType = "";
                input[i]          = property;
            }

            // *****************************
            // Execute the service operation
            // *****************************
            response = dmService.GenerateRevisionIds(input);

            // The AppXPartialErrorListener is logging the partial errors returned
            // In this simple example if any partial errors occur we will throw a
            // ServiceException
            if (response.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.generateRevisionIds returned a partial error.");
            }

            return(response.OutputRevisionIds);
        }
Пример #2
0
        public ExampleForm()
        {
            InitializeComponent();

            MyFormAppSession session = new MyFormAppSession("http://192.168.0.51/tc");
            HomeFolder       home    = new HomeFolder(this);
            Query            query   = new Query(this);
            DataManagement   dm      = new DataManagement(this);

            User user = session.login();

            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());

            String[] attributes = { "os_username" };

            dmService.GetProperties(new ModelObject[] { user }, attributes);

            appendTxt("User name: " + user.Os_username);

            home.listHomeFolder(user);
            query.queryItems();
            dm.createReviseAndDelete();

            session.logout();
        }
Пример #3
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);
        }
Пример #4
0
        /**
         * Delete the Items
         *
         * @param items     Array of Items to delete
         *
         * @throws ServiceException    If any partial errors are returned
         */
        public void deleteItems(Item[] items) //throws ServiceException
        {
            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());

            // *****************************
            // Execute the service operation
            // *****************************
            ServiceData serviceData = dmService.DeleteObjects(items);

            // The AppXPartialErrorListener is logging the partial errors returned
            // In this simple example if any partial errors occur we will throw a
            // ServiceException
            if (serviceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.deleteObjects returned a partial error.");
            }
        }
Пример #5
0
        private void getUsers(ModelObject[] objects)
        {
            if (objects == null)
            {
                return;
            }

            DataManagementService dmService    = DataManagementService.getService(MyFormAppSession.getConnection());
            ArrayList             unKnownUsers = new ArrayList();

            for (int i = 0; i < objects.Length; i++)
            {
                if (!(objects[i] is WorkspaceObject))
                {
                    continue;
                }

                WorkspaceObject wo = (WorkspaceObject)objects[i];

                User owner = null;
                try
                {
                    owner = (User)wo.Owning_user;
                    String userName = owner.User_name;
                }
                catch (NotLoadedException /*e*/)
                {
                    if (owner != null)
                    {
                        unKnownUsers.Add(owner);
                    }
                }
            }

            User[] users = new User[unKnownUsers.Count];
            unKnownUsers.CopyTo(users);
            String[] attributes = { "user_name" };

            dmService.GetProperties(users, attributes);
        }
Пример #6
0
        /**
         * Reserve a number Item and Revision Ids
         *
         * @param numberOfIds      Number of IDs to generate
         * @param type             Type of IDs to generate
         *
         * @return An array of Item and Revision IDs. The size of the array is equal
         *         to the input numberOfIds
         *
         * @throws ServiceException   If any partial errors are returned
         */
        public ItemIdsAndInitialRevisionIds[] generateItemIds(int numberOfIds, String type)
        //        throws ServiceException
        {
            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());

            GenerateItemIdsAndInitialRevisionIdsProperties[] properties = new GenerateItemIdsAndInitialRevisionIdsProperties[1];
            GenerateItemIdsAndInitialRevisionIdsProperties   property   = new GenerateItemIdsAndInitialRevisionIdsProperties();

            property.Count    = numberOfIds;
            property.ItemType = type;
            property.Item     = null; // Not used
            properties[0]     = property;

            // *****************************
            // Execute the service operation
            // *****************************
            GenerateItemIdsAndInitialRevisionIdsResponse response = dmService.GenerateItemIdsAndInitialRevisionIds(properties);



            // The AppXPartialErrorListener is logging the partial errors returned
            // In this simple example if any partial errors occur we will throw a
            // ServiceException
            if (response.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.generateItemIdsAndInitialRevisionIds returned a partial error.");
            }

            // The return is a map of ItemIdsAndInitialRevisionIds keyed on the
            // 0-based index of requested IDs. Since we only asked for IDs for one
            // data type, the map key is '0'
            Int32     bIkey     = 0;
            Hashtable allNewIds = response.OutputItemIdsAndInitialRevisionIds;

            ItemIdsAndInitialRevisionIds[] myNewIds = (ItemIdsAndInitialRevisionIds[])allNewIds[bIkey];

            return(myNewIds);
        }
Пример #7
0
        /**
         * Create ItemMasterForm and ItemRevisionMasterForm
         *
         * @param IMFormName      Name of ItemMasterForm
         * @param IMFormType      Type of ItemMasterForm
         * @param IRMFormName     Name of ItemRevisionMasterForm
         * @param IRMFormType     Type of ItemRevisionMasterForm
         * @param parent          The container object that two
         *                        newly-created forms will be added into.
         * @return ModelObject[]  Array of forms
         *
         * @throws ServiceException         If any partial errors are returned
         */
        public ModelObject[] createForms(String IMFormName, String IMFormType,
                                         String IRMFormName, String IRMFormType,
                                         ModelObject parent, bool saveDB) //throws ServiceException
        {
            //Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());

            FormInfo[] inputs = new FormInfo[2];
            inputs[0]              = new FormInfo();
            inputs[0].ClientId     = "1";
            inputs[0].Description  = "";
            inputs[0].Name         = IMFormName;
            inputs[0].FormType     = IMFormType;
            inputs[0].SaveDB       = saveDB;
            inputs[0].ParentObject = parent;
            inputs[1]              = new FormInfo();
            inputs[1].ClientId     = "2";
            inputs[1].Description  = "";
            inputs[1].Name         = IRMFormName;
            inputs[1].FormType     = IRMFormType;
            inputs[1].SaveDB       = saveDB;
            inputs[1].ParentObject = parent;
            CreateOrUpdateFormsResponse response = dmService.CreateOrUpdateForms(inputs);

            if (response.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.createForms returned a partial error.");
            }

            ModelObject[] forms = new ModelObject [inputs.Length];

            for (int i = 0; i < inputs.Length; ++i)
            {
                forms[i] = response.Outputs[i].Form;
            }

            return(forms);
        }
Пример #8
0
        /**
         * Revise Items
         *
         * @param revisionIds     Map of Revsion IDs
         * @param itemRevs        Array of ItemRevisons
         *
         * @return Map of Old ItemRevsion(key) to new ItemRevision(value)
         *
         * @throws ServiceException         If any partial errors are returned
         */
        public void reviseItems(Hashtable revisionIds, ItemRevision[] itemRevs) //throws ServiceException
        {
            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());

            ReviseInfo[] reviseInfo = new ReviseInfo[itemRevs.Length];
            for (int i = 0; i < itemRevs.Length; i++)
            {
                RevisionIds rev = (RevisionIds)revisionIds[i];

                reviseInfo[i] = new ReviseInfo();
                reviseInfo[i].BaseItemRevision = itemRevs[i];
                reviseInfo[i].ClientId         = itemRevs[i].Uid + "--" + i;
                reviseInfo[i].Description      = "describe testRevise";
                reviseInfo[i].Name             = "testRevise";
                reviseInfo[i].NewRevId         = rev.NewRevId;
            }

            // *****************************
            // Execute the service operation
            // *****************************
            ReviseResponse2 revised = dmService.Revise2(reviseInfo);

            // before control is returned the ChangedHandler will be called with
            // newly created Item and ItemRevisions



            // The AppXPartialErrorListener is logging the partial errors returned
            // In this simple example if any partial errors occur we will throw a
            // ServiceException
            if (revised.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.revise returned a partial error.");
            }
        }
Пример #9
0
        /**
         * Create Items
         *
         * @param itemIds        Array of Item and Revision IDs
         * @param itemType       Type of item to create
         *
         * @return Set of Items and ItemRevisions
         *
         * @throws ServiceException  If any partial errors are returned
         */
        public CreateItemsOutput[] createItems(ItemIdsAndInitialRevisionIds[] itemIds, String itemType)
        //       throws ServiceException
        {
            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());
            // Populate form type
            GetItemCreationRelatedInfoResponse relatedResponse = dmService.GetItemCreationRelatedInfo(itemType, null);

            String[] formTypes = new String[0];
            if (relatedResponse.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.getItemCretionRelatedInfo returned a partial error.");
            }

            formTypes = new String[relatedResponse.FormAttrs.Length];
            for (int i = 0; i < relatedResponse.FormAttrs.Length; i++)
            {
                FormAttributesInfo attrInfo = relatedResponse.FormAttrs[i];
                formTypes[i] = attrInfo.FormType;
            }

            ItemProperties[] itemProps = new ItemProperties[itemIds.Length];
            for (int i = 0; i < itemIds.Length; i++)
            {
                // Create form in cache for form property population
                ModelObject[] forms = createForms(itemIds[i].NewItemId, formTypes[0],
                                                  itemIds[i].NewRevId, formTypes[1],
                                                  null, false);
                ItemProperties itemProperty = new ItemProperties();

                itemProperty.ClientId    = "AppX-Test";
                itemProperty.ItemId      = itemIds[i].NewItemId;
                itemProperty.RevId       = itemIds[i].NewRevId;
                itemProperty.Name        = "AppX-Test";
                itemProperty.Type        = itemType;
                itemProperty.Description = "Test Item for the SOA AppX sample application.";
                itemProperty.Uom         = "";

                // Retrieve one of form attribute value from Item master form.
                ServiceData serviceData = dmService.GetProperties(forms, new String[] { "project_id" });
                if (serviceData.sizeOfPartialErrors() > 0)
                {
                    throw new ServiceException("DataManagementService.getProperties returned a partial error.");
                }
                Property property = null;
                try
                {
                    property = forms[0].GetProperty("project_id");
                }
                catch (NotLoadedException /*ex*/) {}


                // Only if value is null, we set new value
                if (property == null || property.StringValue == null || property.StringValue.Length == 0)
                {
                    itemProperty.ExtendedAttributes = new ExtendedAttributes[1];
                    ExtendedAttributes theExtendedAttr = new ExtendedAttributes();
                    theExtendedAttr.Attributes = new Hashtable();
                    theExtendedAttr.ObjectType = formTypes[0];
                    theExtendedAttr.Attributes["project_id"] = "project_id";
                    itemProperty.ExtendedAttributes[0]       = theExtendedAttr;
                }
                itemProps[i] = itemProperty;
            }


            // *****************************
            // Execute the service operation
            // *****************************
            CreateItemsResponse response = dmService.CreateItems(itemProps, null, "");

            // before control is returned the ChangedHandler will be called with
            // newly created Item and ItemRevisions



            // The AppXPartialErrorListener is logging the partial errors returned
            // In this simple example if any partial errors occur we will throw a
            // ServiceException
            if (response.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.createItems returned a partial error.");
            }

            return(response.Output);
        }
Пример #10
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;
            }
        }