Esempio n. 1
0
        private void ProcessJob(IServicesMgr servicesMgr, int workspaceArtifactId, int jobArtifactId)
        {
            try
            {
                //Update job status to In Progress
                RsapiHelper.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.IN_PROGRESS);

                //Update job metrics
                RDO jobRdo = RsapiHelper.RetrieveJob(servicesMgr, workspaceArtifactId, jobArtifactId);
                RaiseMessage("Calculating metrics for the job", 10);
                ProcessAllMetrics(servicesMgr, workspaceArtifactId, jobArtifactId, jobRdo);
                RaiseMessage("Calculated metrics for the job", 10);

                //Update job status to Completed
                RsapiHelper.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.COMPLETED);
            }
            catch (Exception ex)
            {
                //Update job status to Error
                string errorMessage = ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex);
                RsapiHelper.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.ERROR);
                RsapiHelper.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Errors_LongText, errorMessage);
            }
        }
Esempio n. 2
0
        private static Response <bool> RetrieveRdoByGuidAndArtifactTypeName(IServicesMgr svcMgr, ExecutionIdentity identity, Int32 workspaceArtifactId, Guid guid)
        {
            ResultSet <RDO> results;

            using (var client = (RSAPIClient)svcMgr.CreateProxy <IRSAPIClient>(identity))
            {
                client.APIOptions.WorkspaceID = workspaceArtifactId;
                var relApp = new RDO(guid)
                {
                    ArtifactTypeName = "Tab"
                };

                results = client.Repositories.RDO.Read(relApp);
            }

            var res = new Response <bool>
            {
                Results = results.Success,
                Success = results.Success,
                Message = MessageFormatter.FormatMessage(results.Results.Select(x => x.Message).ToList(), results.Message, results.Success)
            };

            return(res);
        }
Esempio n. 3
0
        // TODO: Scope a US to replace the usage of kCura.Relativity.Client.FieldType with our own enum for only our usages
        public static T ToHydratedDto <T>(this RDO rdo)
            where T : BaseDto, new()
        {
            T returnDto = new T();

            returnDto.ArtifactId = rdo.ArtifactID;

            foreach (PropertyInfo property in typeof(T).GetPublicProperties())
            {
                RelativityObjectFieldAttribute fieldAttribute = property.GetCustomAttribute <RelativityObjectFieldAttribute>();
                object newValueObject = null;
                if (fieldAttribute != null)
                {
                    FieldValue theFieldValue = rdo[fieldAttribute.FieldGuid];

                    switch ((int)fieldAttribute.FieldType)
                    {
                    case (int)RdoFieldType.Currency:
                        newValueObject = theFieldValue.ValueAsCurrency;
                        break;

                    case (int)RdoFieldType.Date:
                        newValueObject = theFieldValue.ValueAsDate;
                        break;

                    case (int)RdoFieldType.Decimal:
                        newValueObject = theFieldValue.ValueAsDecimal;
                        break;

                    case (int)RdoFieldType.Empty:
                        newValueObject = null;
                        break;

                    case (int)RdoFieldType.File:
                        if (theFieldValue.Value != null)
                        {
                            RelativityFile fileData = new RelativityFile(theFieldValue.ArtifactID);
                            newValueObject = fileData;
                        }
                        break;

                    case (int)RdoFieldType.FixedLengthText:
                        newValueObject = theFieldValue.ValueAsFixedLengthText;
                        break;

                    case (int)RdoFieldType.LongText:
                        newValueObject = theFieldValue.ValueAsLongText;
                        break;

                    case (int)RdoFieldType.MultipleChoice:
                        // Means we have IList<some_enum> here, in fieldAttribute.ObjectDTOType
                        var valueAsMultipleChoice = theFieldValue.ValueAsMultipleChoice;
                        if (valueAsMultipleChoice != null)
                        {
                            var listOfEnumValuesDoNotUse = typeof(List <>).MakeGenericType(fieldAttribute.ObjectFieldDTOType);
                            var listOfEnumValuesInstance = (IList)Activator.CreateInstance(listOfEnumValuesDoNotUse);
                            foreach (var choice in valueAsMultipleChoice)
                            {
                                string       choiceNameTrimmed = choice.Name.Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", "");
                                System.Array enumValues        = System.Enum.GetValues(fieldAttribute.ObjectFieldDTOType);
                                for (int i = 0; i < enumValues.Length; i++)
                                {
                                    object theValueObject = enumValues.GetValue(i);
                                    if (theValueObject.ToString().Equals(choiceNameTrimmed, StringComparison.OrdinalIgnoreCase) == true)
                                    {
                                        listOfEnumValuesInstance.Add(theValueObject);
                                    }
                                }
                            }

                            // Now we have a List<object> and we need it to be List<fieldAttribute.ObjectFieldDTOType>
                            newValueObject = listOfEnumValuesInstance;
                        }
                        break;

                    case (int)RdoFieldType.MultipleObject:
                        newValueObject = theFieldValue.GetValueAsMultipleObject <kCura.Relativity.Client.DTOs.Artifact>()
                                         .Select <kCura.Relativity.Client.DTOs.Artifact, int>(artifact => artifact.ArtifactID).ToList();
                        break;

                    case (int)RdoFieldType.SingleChoice:
                        kCura.Relativity.Client.DTOs.Choice theChoice = theFieldValue.ValueAsSingleChoice;
                        if (theChoice != null)
                        {
                            string       choiceNameTrimmed = theChoice.Name.Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", "");
                            System.Array enumValues        = System.Enum.GetValues(fieldAttribute.ObjectFieldDTOType);
                            for (int i = 0; i < enumValues.Length; i++)
                            {
                                object theValueObject = enumValues.GetValue(i);
                                if (theValueObject.ToString().Equals(choiceNameTrimmed, StringComparison.OrdinalIgnoreCase) == true)
                                {
                                    newValueObject = theValueObject;
                                    break;
                                }
                            }
                        }
                        break;

                    case (int)RdoFieldType.SingleObject:
                        if (theFieldValue != null && theFieldValue.ValueAsSingleObject != null && theFieldValue.ValueAsSingleObject.ArtifactID > 0)
                        {
                            newValueObject = theFieldValue.ValueAsSingleObject.ArtifactID;
                        }
                        break;

                    case (int)RdoFieldType.User:
                        if (theFieldValue.Value != null)
                        {
                            if (property.PropertyType == typeof(User))
                            {
                                newValueObject = theFieldValue.Value as User;
                            }
                        }
                        break;

                    case (int)RdoFieldType.WholeNumber:
                        newValueObject = theFieldValue.ValueAsWholeNumber;
                        break;

                    case (int)RdoFieldType.YesNo:
                        newValueObject = theFieldValue.ValueAsYesNo;
                        break;

                    case SharedConstants.FieldTypeCustomListInt:
                        newValueObject = theFieldValue.ValueAsLongText.ToListInt(SharedConstants.ListIntSeparatorChar);
                        break;

                    case SharedConstants.FieldTypeByteArray:
                        if (theFieldValue.ValueAsLongText != null)
                        {
                            newValueObject = Convert.FromBase64String(theFieldValue.ValueAsLongText);
                        }
                        break;
                    }

                    property.SetValue(returnDto, newValueObject);
                }
            }

            return(returnDto);
        }
        public void Valid_Gravity_RelativityObject_Read_Field_Type <T>(string objectPropertyName, T sampleData)
        {
            void Inner()
            {
                //Arrange
                LogStart($"Arrangement for property {objectPropertyName}");

                GravityLevelOne testObject = new GravityLevelOne()
                {
                    Name = $"TestObjectRead_{objectPropertyName}{Guid.NewGuid()}"
                };

                Guid         testObjectTypeGuid = testObject.GetObjectLevelCustomAttribute <RelativityObjectAttribute>().ObjectTypeGuid;
                Guid         nameFieldGuid      = testObject.GetCustomAttribute <RelativityObjectFieldAttribute>("Name").FieldGuid;
                var          testFieldAttribute = testObject.GetCustomAttribute <RelativityObjectFieldAttribute>(objectPropertyName);
                Guid         testFieldGuid      = testFieldAttribute.FieldGuid;
                RdoFieldType fieldType          = testObject.GetCustomAttribute <RelativityObjectFieldAttribute>(objectPropertyName).FieldType;

                _client.APIOptions.WorkspaceID = _workspaceId;

                object expectedData = sampleData;

                var dto = new RDO()
                {
                    ArtifactTypeGuids = new List <Guid> {
                        testObjectTypeGuid
                    }
                };
                int newArtifactId = -1;

                dto.Fields.Add(new FieldValue(nameFieldGuid, testObject.Name));

                int objectToAttachID;

                //need this mess because when passing in tests for decimal and currency System wants to use double and causes problems
                switch (fieldType)
                {
                case RdoFieldType.SingleChoice:
                    Enum   singleChoice      = (Enum)Enum.ToObject(sampleData.GetType(), sampleData);
                    Guid   singleChoiceGuid  = singleChoice.GetRelativityObjectAttributeGuidValue();
                    Choice singleChoiceToAdd = new Choice(singleChoiceGuid);
                    dto.Fields.Add(new FieldValue(testFieldGuid, singleChoiceToAdd));
                    break;

                case RdoFieldType.SingleObject:
                    int objectToAttach =
                        _testObjectHelper.CreateTestObjectWithGravity <GravityLevel2>(sampleData as GravityLevel2);
                    dto.Fields.Add(new FieldValue(testFieldGuid, objectToAttach));
                    expectedData = (sampleData as GravityLevel2).Name;
                    break;

                case RdoFieldType.MultipleObject:
                    IList <GravityLevel2>     gravityLevel2s = (IList <GravityLevel2>)sampleData;
                    FieldValueList <Artifact> objects        = new FieldValueList <Artifact>();
                    expectedData = new Dictionary <int, string>();
                    foreach (GravityLevel2 child in gravityLevel2s)
                    {
                        objectToAttachID =
                            _testObjectHelper.CreateTestObjectWithGravity <GravityLevel2>(child);
                        objects.Add(new Artifact(objectToAttachID));
                        (expectedData as Dictionary <int, string>).Add(objectToAttachID, child.Name);
                    }
                    dto.Fields.Add(new FieldValue(testFieldGuid, objects));
                    break;

                default:
                    dto.Fields.Add(new FieldValue(testFieldGuid, sampleData));
                    break;
                }

                WriteResultSet <RDO> writeResults = _client.Repositories.RDO.Create(dto);

                if (writeResults.Success)
                {
                    newArtifactId = writeResults.Results[0].Artifact.ArtifactID;
                    Console.WriteLine($"Object was created with Artifact ID {newArtifactId}.");
                }
                else
                {
                    Console.WriteLine($"An error occurred creating object: {writeResults.Message}");
                    foreach (var result in
                             writeResults.Results
                             .Select((item, index) => new { rdoResult = item, itemNumber = index })
                             .Where(x => x.rdoResult.Success == false))
                    {
                        Console.WriteLine($"An error occurred in create request {result.itemNumber}: {result.rdoResult.Message}");
                    }
                }

                LogEnd("Arrangement");

                //Act
                LogStart("Act");

                object gravityFieldValue = null;

                if (newArtifactId > 0)
                {
                    GravityLevelOne testGravityObject = _testObjectHelper.ReturnTestObjectWithGravity <GravityLevelOne>(newArtifactId);
                    gravityFieldValue = testGravityObject.GetPropertyValue(objectPropertyName);
                    if (gravityFieldValue != null)
                    {
                        switch (fieldType)
                        {
                        case RdoFieldType.SingleObject:
                            gravityFieldValue = ((GravityLevel2)gravityFieldValue).Name;
                            break;

                        case RdoFieldType.MultipleObject:
                            gravityFieldValue = ((List <GravityLevel2>)gravityFieldValue).ToDictionary(x => x.ArtifactId, x => x.Name);
                            break;
                        }
                    }
                }

                LogEnd("Act");

                //Assert
                LogStart("Assertion");

                if (newArtifactId > 0)
                {
                    Assert.AreEqual(expectedData, gravityFieldValue);
                }
                else
                {
                    Assert.Fail("Could not create object to test with through RSAPI. This is not a Gravity failure.");
                }

                LogEnd("Assertion");
            }

            TestWrapper(Inner);
        }
Esempio n. 5
0
 public WriteResultSet <RDO> MassEdit(RDO templateArtifact, List <int> artifactIDs) => InvokeRepositoryWithRetry(x => x.MassEdit(templateArtifact, artifactIDs));
Esempio n. 6
0
 public WriteResultSet <RDO> MassCreate(RDO templateArtifact, List <RDO> artifacts) => InvokeRepositoryWithRetry(x => x.MassCreate(templateArtifact, artifacts));
Esempio n. 7
0
 public int CreateSingle(RDO artifact) => InvokeRepositoryWithRetry(x => x.CreateSingle(artifact));
Esempio n. 8
0
 public void UpdateSingle(RDO artifact) => InvokeRepositoryWithRetry(x => x.UpdateSingle(artifact));
Esempio n. 9
0
        public RDO ToRdo()
        {
            RelativityObjectAttribute objectTypeAttribute = this.GetType().GetCustomAttribute <RelativityObjectAttribute>(false);
            RDO rdo = new RDO(objectTypeAttribute.ObjectTypeGuid, ArtifactId);

            var parentProperty = this.GetParentArtifactIdProperty();

            if (parentProperty != null)
            {
                var parentId = parentProperty.GetValue(this, null);
                if (parentId != null)
                {
                    rdo.ParentArtifact = new kCura.Relativity.Client.DTOs.Artifact((int)parentId);
                }
            }

            foreach (PropertyInfo property in this.GetType().GetPublicProperties())
            {
                object theFieldValue = null;

                RelativityObjectFieldAttribute fieldAttribute = property.GetCustomAttribute <RelativityObjectFieldAttribute>();

                if (fieldAttribute != null)
                {
                    object propertyValue = property.GetValue(this);
                    if (propertyValue != null && fieldAttribute.FieldType != (int)RdoFieldType.File)
                    {
                        switch (fieldAttribute.FieldType)
                        {
                        case (int)RdoFieldType.Currency:
                        case (int)RdoFieldType.Date:
                        case (int)RdoFieldType.Decimal:
                        case (int)RdoFieldType.Empty:
                        case (int)RdoFieldType.LongText:
                        case (int)RdoFieldType.WholeNumber:
                        case (int)RdoFieldType.YesNo:
                        case (int)RdoFieldType.User:
                            theFieldValue = propertyValue;
                            break;

                        case (int)RdoFieldType.FixedLengthText:
                            int stringLenght;
                            stringLenght = property.GetCustomAttribute <RelativityObjectFieldAttribute>().Length != null?
                                           property.GetCustomAttribute <RelativityObjectFieldAttribute>().Length.Value:
                                           3000;

                            string theString = propertyValue as string;
                            if (string.IsNullOrEmpty(theString) == false && theString.Length > stringLenght)
                            {
                                theString  = theString.Substring(0, (stringLenght - 3));
                                theString += "...";
                            }

                            theFieldValue = theString;
                            break;

                        case (int)RdoFieldType.MultipleChoice:
                            // We have IList<Enum> values here
                            var multiChoiceFieldValueList = new MultiChoiceFieldValueList();

                            IEnumerable enumEnumerable = propertyValue as IEnumerable;
                            Type        entryType      = enumEnumerable.AsQueryable().ElementType;

                            var enumValues = Enum.GetValues(entryType);
                            foreach (var enumValueObject in enumEnumerable)
                            {
                                var memberInfo = entryType.GetMember(enumValueObject.ToString());
                                var relativityObjectAttribute = memberInfo[0].GetCustomAttribute <RelativityObjectAttribute>();
                                multiChoiceFieldValueList.Add(new kCura.Relativity.Client.DTOs.Choice(relativityObjectAttribute.ObjectTypeGuid));
                            }

                            theFieldValue = multiChoiceFieldValueList;
                            break;

                        case (int)RdoFieldType.MultipleObject:
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (int artifactId in (IList <int>)propertyValue)
                            {
                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact(artifactId));
                            }

                            theFieldValue = listOfObjects;
                            break;

                        case (int)RdoFieldType.SingleChoice:

                            bool isEnumDefined = Enum.IsDefined(propertyValue.GetType(), propertyValue);

                            if (isEnumDefined == true)
                            {
                                var choiceGuid = propertyValue.GetType().GetMember(propertyValue.ToString())[0].GetCustomAttribute <RelativityObjectAttribute>().ObjectTypeGuid;
                                theFieldValue = new kCura.Relativity.Client.DTOs.Choice(choiceGuid);
                            }
                            break;

                        case (int)RdoFieldType.SingleObject:
                            if ((int)propertyValue > 0)
                            {
                                theFieldValue = new kCura.Relativity.Client.DTOs.Artifact((int)propertyValue);
                            }
                            break;

                        case SharedConstants.FieldTypeCustomListInt:
                            theFieldValue = ((IList <int>)propertyValue).ToSeparatedString(SharedConstants.ListIntSeparatorChar);
                            break;

                        case SharedConstants.FieldTypeByteArray:
                            theFieldValue = Convert.ToBase64String((byte[])propertyValue);
                            break;
                        }

                        rdo.Fields.Add(new FieldValue(fieldAttribute.FieldGuid, theFieldValue));
                    }
                }
            }

            foreach (PropertyInfo property in this.GetType().GetPublicProperties())
            {
                object theFieldValue = null;
                RelativitySingleObjectAttribute   singleObjectAttribute   = property.GetCustomAttribute <RelativitySingleObjectAttribute>();
                RelativityMultipleObjectAttribute multipleObjectAttribute = property.GetCustomAttribute <RelativityMultipleObjectAttribute>();

                if (singleObjectAttribute != null)
                {
                    int fieldsWithSameGuid = rdo.Fields.Where(c => c.Guids.Contains(singleObjectAttribute.FieldGuid)).Count();

                    if (fieldsWithSameGuid == 0)
                    {
                        object propertyValue = property.GetValue(this);
                        if (propertyValue != null)
                        {
                            int artifactId = (int)propertyValue.GetType().GetProperty("ArtifactId").GetValue(propertyValue, null);
                            if (artifactId != 0)
                            {
                                theFieldValue = new kCura.Relativity.Client.DTOs.Artifact(artifactId);
                                rdo.Fields.Add(new FieldValue(singleObjectAttribute.FieldGuid, theFieldValue));
                            }
                            else
                            {
                                theFieldValue = null;
                                rdo.Fields.Add(new FieldValue(singleObjectAttribute.FieldGuid, theFieldValue));
                            }
                        }
                    }
                }

                if (multipleObjectAttribute != null)
                {
                    int fieldsWithSameGuid = rdo.Fields.Where(c => c.Guids.Contains(multipleObjectAttribute.FieldGuid)).Count();

                    if (fieldsWithSameGuid == 0)
                    {
                        object propertyValue = property.GetValue(this);
                        if (propertyValue != null)
                        {
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (var objectValue in propertyValue as IList)
                            {
                                int artifactId = (int)objectValue.GetType().GetProperty("ArtifactId").GetValue(objectValue, null);

                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact(artifactId));
                            }

                            theFieldValue = listOfObjects;
                            rdo.Fields.Add(new FieldValue(multipleObjectAttribute.FieldGuid, theFieldValue));
                        }
                    }
                }
            }

            return(rdo);
        }
Esempio n. 10
0
        public static T ToHydratedDto <T>(this RDO rdo)
            where T : BaseDto, new()
        {
            T returnDto = new T();

            returnDto.ArtifactId = rdo.ArtifactID;
            returnDto.GetParentArtifactIdProperty()?.SetValue(returnDto, rdo.ParentArtifact?.ArtifactID);

            foreach ((PropertyInfo property, RelativityObjectFieldAttribute fieldAttribute)
                     in typeof(T).GetPropertyAttributeTuples <RelativityObjectFieldAttribute>())
            {
                object     newValueObject = null;
                FieldValue theFieldValue  = rdo[fieldAttribute.FieldGuid];

                switch (fieldAttribute.FieldType)
                {
                case RdoFieldType.SingleObject:
                case RdoFieldType.MultipleObject:
                    break;

                case RdoFieldType.Currency:
                    newValueObject = theFieldValue.ValueAsCurrency;
                    break;

                case RdoFieldType.Date:
                    newValueObject = theFieldValue.ValueAsDate;
                    break;

                case RdoFieldType.Decimal:
                    newValueObject = theFieldValue.ValueAsDecimal;
                    break;

                case RdoFieldType.Empty:
                    newValueObject = null;
                    break;

                case RdoFieldType.File:
                    if (theFieldValue.Value != null)                             // value is file name string
                    {
                        newValueObject = new RelativityFile(theFieldValue.ArtifactID);
                    }
                    break;

                case RdoFieldType.FixedLengthText:
                    newValueObject = theFieldValue.ValueAsFixedLengthText;
                    break;

                case RdoFieldType.LongText:
                    newValueObject = theFieldValue.ValueAsLongText;
                    break;

                case RdoFieldType.User:
                    if (theFieldValue.Value is User user && property.PropertyType == typeof(User))
                    {
                        newValueObject = user;
                    }
                    break;

                case RdoFieldType.WholeNumber:
                    newValueObject = theFieldValue.ValueAsWholeNumber;
                    break;

                case RdoFieldType.YesNo:
                    newValueObject = theFieldValue.ValueAsYesNo;
                    break;
                }

                property.SetValue(returnDto, newValueObject);
            }

            return(returnDto);
        }
Esempio n. 11
0
        //need object fields, could get a little more difficult
        public void Valid_Gravity_RelativityObject_Create_Field_Type <T>(string objectPropertyName, T sampleData)
        {
            void Inner()
            {
                //Arrange
                LogStart($"for property{objectPropertyName}");

                GravityLevelOne testObject = new GravityLevelOne()
                {
                    Name = $"TestObjectCreate_{objectPropertyName}{Guid.NewGuid()}"
                };

                var          testFieldAttribute = testObject.GetCustomAttribute <RelativityObjectFieldAttribute>(objectPropertyName);
                Guid         testFieldGuid      = testFieldAttribute.FieldGuid;
                RdoFieldType fieldType          = testFieldAttribute.FieldType;


                //need this mess because when passing in tests for decimal and currency System wants to use double and causes problems
                switch (fieldType)
                {
                case RdoFieldType.Currency:
                case RdoFieldType.Decimal:
                    testObject.SetValueByPropertyName(objectPropertyName, Convert.ToDecimal(sampleData));
                    break;

                default:
                    testObject.SetValueByPropertyName(objectPropertyName, sampleData);
                    break;
                }

                _client.APIOptions.WorkspaceID = _workspaceId;

                LogEnd("Arrangement");

                //Act
                LogStart("Act");

                var newRdoArtifactId = _testObjectHelper.CreateTestObjectWithGravity <GravityLevelOne>(testObject);

                //read artifactID from RSAPI
                RDO newObject = _client.Repositories.RDO.ReadSingle(newRdoArtifactId);

                FieldValue field = newObject.Fields.Get(testFieldGuid);

                object newObjectValue = null;
                object expectedData   = sampleData;

                switch (fieldType)
                {
                case RdoFieldType.LongText:
                    newObjectValue = field.ValueAsLongText;
                    break;

                case RdoFieldType.FixedLengthText:
                    newObjectValue = field.ValueAsFixedLengthText;
                    break;

                case RdoFieldType.WholeNumber:
                    newObjectValue = field.ValueAsWholeNumber;
                    break;

                case RdoFieldType.YesNo:
                    newObjectValue = field.ValueAsYesNo;
                    break;

                case RdoFieldType.Currency:
                    newObjectValue = field.ValueAsCurrency;
                    break;

                case RdoFieldType.Decimal:
                    newObjectValue = field.ValueAsDecimal;
                    break;

                case RdoFieldType.SingleChoice:
                    int choiceArtifactId = field.ValueAsSingleChoice.ArtifactID;
                    if (choiceArtifactId > 0)
                    {
                        Choice choice           = _client.Repositories.Choice.ReadSingle(choiceArtifactId);
                        Enum   singleChoice     = (Enum)Enum.ToObject(sampleData.GetType(), sampleData);
                        Guid   singleChoiceGuid = singleChoice.GetRelativityObjectAttributeGuidValue();
                        newObjectValue = choice.Guids.SingleOrDefault(x => x == singleChoiceGuid);
                        expectedData   = singleChoiceGuid;
                    }
                    break;

                case RdoFieldType.SingleObject:
                    newObjectValue = field.ValueAsSingleObject.ArtifactID;
                    expectedData   = testObject.GravityLevel2Obj.ArtifactId > 0
                                                        ? (object)testObject.GravityLevel2Obj.ArtifactId
                                                        : null;
                    break;

                case RdoFieldType.MultipleObject:
                    var  rawNewObjectValue  = field.GetValueAsMultipleObject <Artifact>();
                    var  resultData         = new List <GravityLevel2>();
                    Guid childFieldNameGuid = new GravityLevel2().GetCustomAttribute <RelativityObjectFieldAttribute>("Name").FieldGuid;

                    foreach (Artifact child in rawNewObjectValue)
                    {
                        //'Read' - need to get name.
                        RDO childRdo = new RDO()
                        {
                            Fields = new List <FieldValue>()
                            {
                                new FieldValue(childFieldNameGuid)
                            }
                        };
                        childRdo = _client.Repositories.RDO.ReadSingle(child.ArtifactID);
                        string childNameValue = childRdo.Fields.Where(x => x.Guids.Contains(childFieldNameGuid)).FirstOrDefault().ToString();

                        resultData.Add(new GravityLevel2()
                        {
                            ArtifactId = child.ArtifactID, Name = childNameValue
                        });
                    }
                    newObjectValue = resultData.ToDictionary(x => x.ArtifactId, x => x.Name);
                    expectedData   = ((IEnumerable <GravityLevel2>)expectedData).ToDictionary(x => x.ArtifactId, x => x.Name);

                    break;
                }

                LogEnd("Act");

                //Assert
                LogStart("Assertion");

                //Assert
                Assert.AreEqual(expectedData, newObjectValue);

                LogEnd("Assertion");
            }

            TestWrapper(Inner);
        }
        private void ProcessAllMetrics(IServicesMgr servicesMgr, int workspaceArtifactId, int jobArtifactId, RDO jobRdo)
        {
            try
            {
                MultiChoiceFieldValueList metricMultipleChoices = jobRdo.Fields.Get(Constants.Guids.Fields.InstanceMetricsJob.Metrics_MultipleChoice).ValueAsMultipleChoice;
                List <int>  metricArtifactIdsToCollect          = metricMultipleChoices.Select(x => x.ArtifactID).ToList();
                List <Guid> metricGuidsToCollect = ConvertChoiceArtifactIdsToGuids(servicesMgr, workspaceArtifactId, metricArtifactIdsToCollect);

                foreach (Guid metricGuid in metricGuidsToCollect)
                {
                    ProcessSingleMetric(servicesMgr, workspaceArtifactId, jobArtifactId, metricGuid);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(Constants.ErrorMessages.PROCESS_ALL_JOB_METRICS_ERROR, ex);
            }
        }
Esempio n. 13
0
        public ExtractorSet(IArtifactQueries artifactQueries, IServicesMgr servicesMgr, ExecutionIdentity executionIdentity, Int32 workspaceArtifactId, ExtractorSetReporting extractorSetReporting, RDO extractorSetRdo)
        {
            ServicesMgr           = servicesMgr;
            ExtractorSetReporting = extractorSetReporting;
            ArtifactQueries       = artifactQueries;
            WorkspaceArtifactId   = workspaceArtifactId;
            ExecutionIdentity     = executionIdentity;

            SetMyProperties(extractorSetRdo);
        }
Esempio n. 14
0
        public ExtractorProfile(IArtifactFactory artifactFactory, Int32 workspaceArtifactId, RDO extractorProfileRdo, ErrorLogModel errorLogModel)
        {
            WorkspaceArtifactId  = workspaceArtifactId;
            ArtifactFactory      = artifactFactory;
            ExtractorTargetTexts = new List <IExtractorTargetText>();
            ErrorLogModel        = errorLogModel;

            SetMyProperties(extractorProfileRdo);
        }
        public ExtractorTargetText(IArtifactQueries artifactQueries, IServicesMgr servicesMgr, ExecutionIdentity executionIdentity, Int32 workspaceArtifactId, RDO extractorTargetTextRdo, ErrorLogModel errorLogModel)
        {
            //ErrorQueue = errorQueue;
            ServicesMgr           = servicesMgr;
            ExecutionIdentity     = executionIdentity;
            WorkspaceArtifactId   = workspaceArtifactId;
            ArtifactQueries       = artifactQueries;
            TextExtractionUtility = new TextExtractionUtility(new TextExtractionValidator());
            TargetRule            = new TargetRule(extractorTargetTextRdo);
            ErrorLogModel         = errorLogModel;

            SetMyProperties(extractorTargetTextRdo);
        }
        public void SetMyProperties(RDO extractorTargetTextRdo)
        {
            try
            {
                ArtifactId = extractorTargetTextRdo.ArtifactID;
                if (ArtifactId < 1)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_ARTIFACT_ID_CANNOT_BE_LESS_THAN_OR_EQUAL_TO_ZERO);
                }

                TargetName = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.TargetName).ValueAsFixedLengthText;
                if (TargetName == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_TARGET_NAME_IS_EMPTY);
                }

                switch (TargetRule.MarkerEnum)
                {
                case Constant.MarkerEnum.RegEx:
                    RegeExStartMarkerArtifact = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.RegularExpressionStartMarker).ValueAsSingleObject;
                    if (RegeExStartMarkerArtifact == null)
                    {
                        throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_REGULAR_EXPRESSION_IS_EMPTY);
                    }

                    ArtifactFactory artifactFactory = new ArtifactFactory(ArtifactQueries, ServicesMgr, ErrorLogModel);
                    RegExStartMarker = artifactFactory.GetInstanceOfExtractorRegullarExpression(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, RegeExStartMarkerArtifact.ArtifactID);

                    StartMarker = RegExStartMarker.RegularExpression;

                    RegeExStopMarkerArtifact = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.RegularExpressionStopMarker).ValueAsSingleObject;
                    if (RegeExStopMarkerArtifact == null || RegeExStopMarkerArtifact.ArtifactID < 1)
                    {
                        RegExStopMarker = null;
                    }
                    else
                    {
                        RegExStopMarker = artifactFactory.GetInstanceOfExtractorRegullarExpression(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, RegeExStopMarkerArtifact.ArtifactID);

                        StopMarker = RegExStopMarker.RegularExpression;
                    }
                    break;

                case Constant.MarkerEnum.PlainText:
                    PlainTextStartMarker = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.PlainTextStartMarker).ValueAsFixedLengthText;
                    if (PlainTextStartMarker == null)
                    {
                        throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_PLAIN_TEXT_MARKER_IS_EMPTY);
                    }

                    StartMarker = PlainTextStartMarker;

                    PlainTextStopMarker = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.PlainTextStopMarker).ValueAsFixedLengthText;
                    StopMarker          = PlainTextStopMarker;
                    break;
                }

                if (StartMarker == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_START_MARKER_IS_EMPTY);
                }

                if (StopMarker != null)
                {
                    TargetRule.DirectionEnum = Constant.DirectionEnum.RightToStopMarker;
                }

                DestinationField = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.DestinationField).ValueAsSingleObject;
                if (DestinationField == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_DESTINATION_FIELD_IS_EMPTY);
                }
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.DEFAULT_CONVERT_TO_EXTRACTOR_TARGET_TEXT_ERROR_MESSAGE + ". " + ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex), ex);
            }
        }
Esempio n. 17
0
 protected void UpdateRdo(RDO theRdo)
 {
     rsapiProvider.UpdateSingle(theRdo);
 }
Esempio n. 18
0
        internal void PopulateChildrenRecursively <T>(BaseDto baseDto, RDO objectRdo, ObjectFieldsDepthLevel depthLevel)
        {
            foreach (var objectPropertyInfo in BaseDto.GetRelativityMultipleObjectPropertyInfos <T>())
            {
                var propertyInfo = objectPropertyInfo.Key;
                var theMultipleObjectAttribute = objectPropertyInfo.Value;

                Type childType = objectPropertyInfo.Value.ChildType;

                int[] childArtifactIds = objectRdo[objectPropertyInfo.Value.FieldGuid].GetValueAsMultipleObject <kCura.Relativity.Client.DTOs.Artifact>()
                                         .Select <kCura.Relativity.Client.DTOs.Artifact, int>(artifact => artifact.ArtifactID).ToArray();

                MethodInfo method = GetType().GetMethod("GetDTOs", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                var allObjects = method.Invoke(this, new object[] { childArtifactIds, depthLevel }) as IEnumerable;

                var   listType   = typeof(List <>).MakeGenericType(theMultipleObjectAttribute.ChildType);
                IList returnList = (IList)Activator.CreateInstance(listType);

                foreach (var item in allObjects)
                {
                    returnList.Add(item);
                }

                propertyInfo.SetValue(baseDto, returnList);
            }

            foreach (var ObjectPropertyInfo in BaseDto.GetRelativitySingleObjectPropertyInfos <T>())
            {
                var propertyInfo = ObjectPropertyInfo.Key;

                Type objectType   = ObjectPropertyInfo.Value.ChildType;
                var  singleObject = Activator.CreateInstance(objectType);

                int childArtifactId = objectRdo[ObjectPropertyInfo.Value.FieldGuid].ValueAsSingleObject.ArtifactID;

                MethodInfo method = GetType().GetMethod("GetDTO", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { objectType });

                if (childArtifactId != 0)
                {
                    singleObject = method.Invoke(this, new object[] { childArtifactId, depthLevel });
                }

                propertyInfo.SetValue(baseDto, singleObject);
            }

            foreach (var childPropertyInfo in BaseDto.GetRelativityObjectChildrenListInfos <T>())
            {
                var propertyInfo      = childPropertyInfo.Key;
                var theChildAttribute = childPropertyInfo.Value;

                Type       childType = childPropertyInfo.Value.ChildType;
                MethodInfo method    = GetType().GetMethod("GetAllChildDTOs", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                Guid parentFieldGuid = childType.GetRelativityObjectGuidForParentField();

                var allChildObjects = method.Invoke(this, new object[] { parentFieldGuid, baseDto.ArtifactId, depthLevel }) as IEnumerable;

                var   listType   = typeof(List <>).MakeGenericType(theChildAttribute.ChildType);
                IList returnList = (IList)Activator.CreateInstance(listType);

                foreach (var item in allChildObjects)
                {
                    returnList.Add(item);
                }

                propertyInfo.SetValue(baseDto, returnList);
            }

            foreach (var filePropertyInfo in baseDto.GetType().GetPublicProperties().Where(prop => prop.PropertyType == typeof(RelativityFile)))
            {
                var filePropertyValue = filePropertyInfo.GetValue(baseDto, null) as RelativityFile;

                if (filePropertyValue != null)
                {
                    filePropertyValue = GetFile(filePropertyValue.ArtifactTypeId, baseDto.ArtifactId);
                }

                filePropertyInfo.SetValue(baseDto, filePropertyValue);
            }
        }
Esempio n. 19
0
        public void UpdateField <T>(int rdoID, Guid fieldGuid, object value)
            where T : BaseDto, new()
        {
            RDO theRdo = new RDO(rdoID);

            theRdo.ArtifactTypeGuids.Add(BaseDto.GetObjectTypeGuid <T>());

            Type fieldType = typeof(T).GetProperties().Where(p => p.GetFieldGuidValueFromAttribute() == fieldGuid).FirstOrDefault().PropertyType;

            if (fieldType.IsGenericType)
            {
                if (fieldType.GetGenericTypeDefinition() == typeof(IList <>))
                {
                    if ((value as IList).HeuristicallyDetermineType().IsEnum)
                    {
                        MultiChoiceFieldValueList choices = new MultiChoiceFieldValueList();
                        List <Guid> choiceValues          = new List <Guid>();
                        foreach (var enumValue in (value as IList))
                        {
                            choices.Add(new kCura.Relativity.Client.DTOs.Choice(((Enum)enumValue).GetRelativityObjectAttributeGuidValue()));
                        }

                        theRdo.Fields.Add(new FieldValue(fieldGuid, choices));
                    }

                    if (value.GetType().GetGenericArguments() != null && value.GetType().GetGenericArguments().Length != 0)
                    {
                        if (value.GetType().GetGenericArguments()[0].IsSubclassOf(typeof(BaseDto)))
                        {
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (var objectValue in value as IList)
                            {
                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact((int)objectValue.GetType().GetProperty("ArtifactId").GetValue(objectValue, null)));
                            }

                            theRdo.Fields.Add(new FieldValue(fieldGuid, listOfObjects));
                        }

                        if (value.GetType().GetGenericArguments()[0].IsEquivalentTo(typeof(int)))
                        {
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (var objectValue in value as IList)
                            {
                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact((int)objectValue));
                            }

                            theRdo.Fields.Add(new FieldValue(fieldGuid, listOfObjects));
                        }
                    }
                }
                else if (value == null)
                {
                    theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                }
                else if (value.GetType() == typeof(string) ||
                         value.GetType() == typeof(int) ||
                         value.GetType() == typeof(bool) ||
                         value.GetType() == typeof(decimal) ||
                         value.GetType() == typeof(DateTime))
                {
                    theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                }

                UpdateRdo(theRdo);
            }
            else
            {
                RelativityObjectFieldAttribute fieldAttributeValue = typeof(T).GetProperties().Where(p => p.GetFieldGuidValueFromAttribute() == fieldGuid).FirstOrDefault().GetCustomAttribute <RelativityObjectFieldAttribute>();

                if (fieldAttributeValue != null)
                {
                    if (fieldAttributeValue.FieldType == (int)RdoFieldType.File)
                    {
                        if (value.GetType().BaseType != null)
                        {
                            if (value.GetType().BaseType.IsAssignableFrom(typeof(RelativityFile)))
                            {
                                InsertUpdateFileField(value as RelativityFile, rdoID);
                            }
                        }
                    }

                    if (fieldAttributeValue.FieldType == (int)RdoFieldType.User)
                    {
                        if (value.GetType() == typeof(User))
                        {
                            theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                            UpdateRdo(theRdo);
                        }
                    }

                    if (value.GetType().IsEnum)
                    {
                        var choice = new kCura.Relativity.Client.DTOs.Choice(((Enum)value).GetRelativityObjectAttributeGuidValue());

                        theRdo.Fields.Add(new FieldValue(fieldGuid, choice));
                        UpdateRdo(theRdo);
                    }

                    if (value.GetType() == typeof(string) ||
                        value.GetType() == typeof(int) ||
                        value.GetType() == typeof(bool) ||
                        value.GetType() == typeof(decimal) ||
                        value.GetType() == typeof(DateTime))
                    {
                        theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                        UpdateRdo(theRdo);
                    }
                }
            }
        }
Esempio n. 20
0
        public void CreateExtractorSetHistoryRecord(IServicesMgr svcMgr, ExecutionIdentity identity, Int32 workspaceArtifactId, Int32?extractorSetArtifactId, Int32?documentArtifactId, String status, String details)
        {
            var errorContext = String.Format("An error occured when creating Extractor Set History Record. [WorkspaceArtifactId: {0}, DocumentArtifactId: {1}, TextExtractorSetArtifactId: {2}]", workspaceArtifactId, documentArtifactId, extractorSetArtifactId);

            try
            {
                using (var proxy = svcMgr.CreateProxy <IRSAPIClient>(identity))
                {
                    proxy.APIOptions.WorkspaceID = workspaceArtifactId;

                    var jobHistoryDto = new RDO();
                    jobHistoryDto.ArtifactTypeGuids.Add(Constant.Guids.ObjectType.ExtractorSetHistory);
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.Name)
                    {
                        Value = Guid.NewGuid().ToString()
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.DocumentIdentifier)
                    {
                        Value = GetDocumentIdentifierValue(svcMgr, identity, workspaceArtifactId, Convert.ToInt32(documentArtifactId))
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.DestinationField)
                    {
                        Value = String.Empty
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.Status)
                    {
                        Value = status
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.Details)
                    {
                        Value = details
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.TargetName)
                    {
                        Value = String.Empty
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.MarkerType)
                    {
                        Value = String.Empty
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.StartMarker)
                    {
                        Value = String.Empty
                    });
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.StopMarker)
                    {
                        Value = String.Empty
                    });
                    var jobRdo = extractorSetArtifactId != null ? new RDO(Convert.ToInt32(extractorSetArtifactId)) : null;
                    jobHistoryDto.Fields.Add(new FieldValue(Constant.Guids.Fields.ExtractorSetHistory.ExtractorSet)
                    {
                        Value = jobRdo
                    });

                    try
                    {
                        proxy.Repositories.RDO.CreateSingle(jobHistoryDto);
                    }
                    catch (Exception ex)
                    {
                        throw new CustomExceptions.TextExtractorException(errorContext, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException(errorContext, ex);
            }
        }
Esempio n. 21
0
        public ExtractorRegullarExpression(IArtifactQueries artifactQueries, Int32 workspaceArtifactId, RDO extractorRegullarExpressionRdo, ErrorLogModel errorLogModel)
        {
            WorkspaceArtifactId = workspaceArtifactId;
            ArtifactQueries     = artifactQueries;
            ErrorLogModel       = errorLogModel;

            SetMyProperties(extractorRegullarExpressionRdo);
        }