Exemplo n.º 1
0
        public static CustomField2 Execute(CorrigoService service, CorrigoEntity entity,
                                           CustomFieldDescriptor customFieldDescriptor)
        {
            string label    = "IFS-1119";
            string href     = "https://jira.qa.corrigo.com:55445/browse/IFS-1119";
            string urlValue = $"<a href=\"{href}\">{label}</a>";

            var customField = new CustomField2
            {
                Descriptor = new CustomFieldDescriptor {
                    Id = customFieldDescriptor.Id
                },
                ObjectId     = entity.Id,
                ObjectTypeId = customFieldDescriptor.ActorTypeId,
                Value        = urlValue
            };
            var command = new CreateCommand {
                Entity = customField
            };
            var response = service.Execute(command) as OperationCommandResponse;

            customField.Id = response?.EntitySpecifier?.Id ?? 0;

            return(customField);
        }
Exemplo n.º 2
0
        public static CustomField2 Retrieve(CorrigoService service, CorrigoEntity entity,
                                            CustomFieldDescriptor customFieldDescriptor)
        {
            var list = service.RetrieveMultiple(
                new QueryExpression
            {
                Count       = 1,
                EntityType  = EntityType.CustomField2,
                PropertySet = new PropertySet
                {
                    Properties = new string[]
                    {
                        "Id",
                        "ObjectId",
                        "ObjectTypeId",
                        "Value",
                    }
                },
                Criteria = new FilterExpression
                {
                    Conditions = new ConditionExpression[]
                    {
                        new ConditionExpression
                        {
                            PropertyName = "ObjectId",
                            Operator     = ConditionOperator.Equal,
                            Values       = new object[] { entity.Id }
                        },
                        new ConditionExpression
                        {
                            PropertyName = "Descriptor.Id",
                            Operator     = ConditionOperator.Equal,
                            Values       = new object[] { customFieldDescriptor.Id }
                        }
                    },
                    FilterOperator = LogicalOperator.And
                }
            });

            return(list.FirstOrDefault() as CustomField2);
        }
Exemplo n.º 3
0
        /// <summary>
        /// For creation of new Custom Field is used latest WorkOrder.
        /// By default creation, update, deletion of Custom Fields is disabled.
        /// To enable creation, update, deletion mode for Custom Fields set isCreateUpdateDelete = true.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="isCreateUpdateDelete">by default is false</param>
        public static void CRUDExample(CorrigoService service,
                                       bool isCreateUpdateDelete = false)
        {
            if (service == null)
            {
                return;
            }

            //
            // Get Custom Field Descriptor with properties (Custom Field: JIRA LINK; Domain: Work Order; Data Type : URL)
            //
            CustomFieldDescriptor customFieldDescriptor = GetCustomFieldDescriptor(service, "JIRA LINK", ActorType.WO, CfType.Url);

            if (customFieldDescriptor == null || !(customFieldDescriptor.Id > 0))
            {
                Console.WriteLine("Custom Field Descriptor is undefined");
                return;
            }

            //Get latest WO
            CorrigoEntity[] latestWO = GetLatestWOs(service, 1);
            if (!latestWO.Any())
            {
                Console.WriteLine("No existing Work Order was found");
                return;
            }

            //
            // Retrieve Custom field specified by descriptor for given Work Order.
            //
            CustomField2 cf = Read.Retrieve(service, latestWO[0], customFieldDescriptor);

            if (cf == null && isCreateUpdateDelete)
            {
                //
                // Create Custom field specified by descriptor for given Work Order.
                //
                cf = Create.Execute(service, latestWO[0], customFieldDescriptor);
            }

            if (cf != null && isCreateUpdateDelete)
            {
                cf = Read.Retrieve(service, latestWO[0], customFieldDescriptor);

                //
                // Update Custom field
                //
                Update.Execute(service, cf);

                //
                // Delete Custom Field
                //
                Delete.Execute(service, cf.Id);

                //Update.Restore(service, cf); // CustomField2 is not restorable.
            }

            //
            // Retrive 10 Custom Fields with Data Type : URL
            //
            Read.RetrieveByQuery(service); // retrieve is limited to 10 records
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get Custom Field Descriptor by specified field name, domain(entity) object type, and Custom Field Type.
        /// When Custom Field Descriptor by specified parameters is not found, the new descriptor is going to be created.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="fieldName"></param>
        /// <param name="actorType"></param>
        /// <param name="cfType"></param>
        /// <returns>CustomFieldDescriptor</returns>
        private static CustomFieldDescriptor GetCustomFieldDescriptor(CorrigoService service, string fieldName,
                                                                      ActorType actorType, CfType cfType)
        {
            var list = service.RetrieveMultiple(
                new QueryExpression
            {
                Count       = 1,
                EntityType  = EntityType.CustomFieldDescriptor,
                PropertySet = new PropertySet
                {
                    Properties = new string[]
                    {
                        "*"
                    }
                },
                Criteria = new FilterExpression
                {
                    Conditions = new ConditionExpression[]
                    {
                        new ConditionExpression
                        {
                            PropertyName = "Type",
                            Operator     = ConditionOperator.Equal,
                            Values       = new object[] { cfType }
                        },
                        new ConditionExpression
                        {
                            PropertyName = "ActorTypeId",
                            Operator     = ConditionOperator.Equal,
                            Values       = new object[] { actorType }
                        },
                        new ConditionExpression
                        {
                            PropertyName = "Name",
                            Operator     = ConditionOperator.Equal,
                            Values       = new object[] { fieldName }
                        },
                        new ConditionExpression
                        {
                            PropertyName = "IsRemoved",
                            Operator     = ConditionOperator.Equal,
                            Values       = new object[] { false }
                        }
                    },
                    FilterOperator = LogicalOperator.And
                },
                Orders = new[]
                {
                    new OrderExpression
                    {
                        OrderType    = OrderType.Descending,
                        PropertyName = "Id"
                    }
                },
            });

            if (list.Any())
            {
                return(list[0] as CustomFieldDescriptor);
            }

            var entity = new CustomFieldDescriptor
            {
                ActorTypeId = actorType,
                Name        = fieldName,
                Type        = cfType
            };
            var command = new CreateCommand {
                Entity = entity
            };
            var response = service.Execute(command) as OperationCommandResponse;

            entity.Id = response?.EntitySpecifier?.Id ?? 0;

            return(entity);
        }
 public CustomFieldDescriptorAdapter(CustomFieldDescriptor descriptor)
 {
     _descriptor = descriptor;
 }