Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Document Helpers #85

Open
dvbarnes opened this issue Jan 20, 2020 · 2 comments
Open

Document Helpers #85

dvbarnes opened this issue Jan 20, 2020 · 2 comments

Comments

@dvbarnes
Copy link
Contributor

dvbarnes commented Jan 20, 2020

Creating new Test helpers for the document object, currently we have a lot of Tests that run against the document object and to be able to create a document would be very helpful

  • Create a document with no file location set (we default to txt), but also allows for me to set the file type when creating
  • Delete document (please ensure the list is not empty and filter out null and 0 ids)
@jake-martin
Copy link
Contributor

Hey @dvbarnes, if you have any existing code that does this that we could integrate into TestHelpers, feel free to share it here.

@dvbarnes
Copy link
Contributor Author

just seeing this,

Here is a good example of what we do:

var file = string.Empty;
            if (!doc.Artifact.Fields.Any(x => x.Name == DocumentFieldNames.RelativityNativeFileLocation))
            {
                doc.Artifact.Fields.Add(new FieldValue(DocumentFieldNames.RelativityNativeFileLocation, string.Empty));
            }
            string fileType = string.Empty;
            if (doc.Artifact.Fields.Any(x => x.Name == DocumentFieldNames.RelativityNativeType || x.Guids.Contains(Guid.Parse(DocumentFieldGuids.RelativityNativeType))))
            {
                fileType = doc.RelativityNativeType;
                var field = doc.Artifact.Fields.Single(x => x.Name == DocumentFieldNames.RelativityNativeType || x.Guids.Contains(Guid.Parse(DocumentFieldGuids.RelativityNativeType)));
                doc.Artifact.Fields.Remove(field);
            }
            if (string.IsNullOrWhiteSpace(doc.Artifact.RelativityNativeFileLocation))
            {
                file = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".txt");
                File.WriteAllText(file, "nothing");
                doc.Artifact.RelativityNativeFileLocation = file;
            }
            if (!doc.Artifact.Fields.Any(x => x.Name == DocumentFieldNames.TextIdentifier))
            {
                var identifier = Guid.NewGuid().ToString();
                if (doc.Artifact.Fields.Any(x => x.Guids.Contains(Guid.Parse(DocumentFieldGuids.ControlNumber))))
                {
                    var fieldToRemove = doc.Artifact[Guid.Parse(DocumentFieldGuids.ControlNumber)];
                    identifier = fieldToRemove.ValueAsFixedLengthText;
                    doc.Artifact.Fields.Remove(fieldToRemove);
                }
                doc.Artifact.Fields.Add(new FieldValue(DocumentFieldNames.TextIdentifier, identifier));
            }
            try
            {
                var container = ContainerConfig.GetContainer(helper);
                var repo = container.GetInstance<IDocumentRepository>();
                var id = repo.AddRange(workspaceId, new List<kCura.Relativity.Client.DTOs.Document>
                {
                    doc.Artifact
                }).Single().ArtifactId;
                if (!string.IsNullOrWhiteSpace(fileType))
                {
                    UpdateNativeType(helper, workspaceId, id, fileType);
                }
                return id;
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(file))
                {
                    File.Delete(file);
                }
            }

The repo.AddRange calls rsapi.Repositores.Document.Create() + update since create doesn't set all fields, just a few

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants