Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private CreateItemsOutput[] createECNItems(ItemIdsAndInitialRevisionIds[] itemIds, string itemType)
        //       throws ServiceException
        {
            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(Session.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++)
            {
                CreateIn itemInput = new CreateIn();

                itemInput.Data.BoName = "A9_AutoCN";
                VecStruct PropValueVec1 = new VecStruct();
                PropValueVec1.StringVec = new String[] { "Synopsis_name" };
                itemInput.Data.StringProps.Add("object_name", PropValueVec1);

                CreateInput itemRevisionInput = new CreateInput();
                itemRevisionInput.BoName = "A9_AutoCNRevision";

                VecStruct PropValueVec2 = new VecStruct();
                PropValueVec2.StringVec = new String[] { "test revision desc" };

                itemRevisionInput.StringProps.Add("object_desc", PropValueVec2);

                DateTime currentdate      = DateTime.Now;
                DateTime SyncStartdate    = new DateTime(currentdate.Year, currentdate.Month, currentdate.Day, currentdate.Hour, currentdate.Minute, currentdate.Second);
                String   SyncStartdateStr = SyncStartdate.ToString("yyyyMMMddHHmmsssss");

                VecStruct PropValueVec4 = new VecStruct();
                PropValueVec4.StringVec = new String[] { SyncStartdateStr };
                itemRevisionInput.DateProps.Add("a9_EstImpDate", PropValueVec4);


                itemInput.Data.CompoundCreateInput.Add("revision", itemRevisionInput);

                CreateIn[] itemInputarray = new CreateIn[1];
                itemInputarray[0] = itemInput;

                CreateResponse cresponse = dmService.CreateObjects(itemInputarray);

                if (cresponse.ServiceData.sizeOfPartialErrors() > 0)
                {
                    throw new ServiceException("DataManagementService.CreateObjects returned a partial error." + cresponse.ServiceData.GetPartialError(0));
                }

                //---------------------------------------------------------------------------------
                //// 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.");
            CreateItemsResponse response = null;

            return(response.Output);
        }