コード例 #1
0
    private IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(_iamApikey))
        {
            throw new WatsonException("Plesae provide IAM ApiKey for the service.");
        }

        //  Create credential and instantiate service
        Credentials credentials = null;
        //  Authenticate using iamApikey
        TokenOptions tokenOptions = new TokenOptions()
        {
            IamApiKey = _iamApikey
        };

        credentials = new Credentials(tokenOptions, _serviceUrl);

        //  Wait for tokendata
        while (!credentials.HasIamTokenData())
        {
            yield return(null);
        }

        compareComply             = new CompareComply(credentials);
        compareComply.VersionDate = _versionDate;

        Runnable.Run(Examples());
    }
コード例 #2
0
        public override IEnumerator RunTest()
        {
            LogSystem.InstallDefaultReactors();

            contractAFilepath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/compare-comply/contract_A.pdf";
            contractBFilepath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/compare-comply/contract_B.pdf";
            tableFilepath     = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/compare-comply/TestTable.pdf";

            string objectStorageCredentialsInputFilepath  = "../sdk-credentials/cloud-object-storage-credentials-input.json";
            string objectStorageCredentialsOutputFilepath = "../sdk-credentials/cloud-object-storage-credentials-output.json";

            #region Get Credentials
            VcapCredentials vcapCredentials = new VcapCredentials();
            fsData          data            = null;

            string result = null;
            string credentialsFilepath = "../sdk-credentials/credentials.json";

            //  Load credentials file if it exists. If it doesn't exist, don't run the tests.
            if (File.Exists(credentialsFilepath))
            {
                result = File.ReadAllText(credentialsFilepath);
            }
            else
            {
                yield break;
            }

            //  Add in a parent object because Unity does not like to deserialize root level collection types.
            result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");

            //  Convert json to fsResult
            fsResult r = fsJsonParser.Parse(result, out data);
            if (!r.Succeeded)
            {
                throw new WatsonException(r.FormattedMessages);
            }

            //  Convert fsResult to VcapCredentials
            object obj = vcapCredentials;
            r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
            if (!r.Succeeded)
            {
                throw new WatsonException(r.FormattedMessages);
            }

            //  Set credentials from imported credntials
            Credential credential = vcapCredentials.GetCredentialByname("compare-comply-sdk")[0].Credentials;
            _url = credential.Url.ToString();

            //  Create credential and instantiate service
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey = credential.IamApikey
            };
            #endregion

            Credentials credentials = new Credentials(tokenOptions, credential.Url);

            //  Wait for tokendata
            while (!credentials.HasIamTokenData())
            {
                yield return(null);
            }

            compareComply             = new CompareComply(credentials);
            compareComply.VersionDate = versionDate;

            byte[] contractA = File.ReadAllBytes(contractAFilepath);
            byte[] contractB = File.ReadAllBytes(contractBFilepath);
            byte[] table     = File.ReadAllBytes(tableFilepath);

            byte[] objectStorageCredentialsInputData  = File.ReadAllBytes(objectStorageCredentialsInputFilepath);
            byte[] objectStorageCredentialsOutputData = File.ReadAllBytes(objectStorageCredentialsOutputFilepath);

            compareComply.ConvertToHtml(OnConvertToHtml, OnFail, contractA, fileContentType: "application/pdf");
            while (!convertToHtmlTested)
            {
                yield return(null);
            }

            compareComply.ClassifyElements(OnClassifyElements, OnFail, contractA);
            while (!classifyElementsTested)
            {
                yield return(null);
            }

            compareComply.ExtractTables(OnExtractTables, OnFail, table);
            while (!extractTablesTested)
            {
                yield return(null);
            }

            compareComply.CompareDocuments(OnCompareDocuments, OnFail, contractA, contractB, file1ContentType: "application/pdf", file2ContentType: "application/pdf");
            while (!compareDocumentsTested)
            {
                yield return(null);
            }

            DateTime before = new DateTime(2018, 11, 15);
            DateTime after  = new DateTime(2018, 11, 14);
            compareComply.ListFeedback(
                successCallback: OnListFeedback,
                failCallback: OnFail,
                feedbackType: "element_classification",
                before: before,
                after: after,
                documentTitle: "unity-test-feedback-doc",
                modelId: "contracts",
                modelVersion: "2.0.0",
                categoryRemoved: "Responsibilities",
                categoryAdded: "Amendments",
                categoryNotChanged: "Audits",
                typeRemoved: "End User:Exclusion",
                typeAdded: "Disclaimer:Buyer",
                typeNotChanged: "Obligation:IBM",
                pageLimit: 1
                );
            while (!listFeedbackTested)
            {
                yield return(null);
            }


            #region Feedback Data
            FeedbackInput feedbackData = new FeedbackInput()
            {
                UserId       = "user_id_123x",
                Comment      = "Test feedback comment",
                FeedbackData = new FeedbackDataInput()
                {
                    FeedbackType = "element_classification",
                    Document     = new ShortDoc()
                    {
                        Hash  = "",
                        Title = "doc title"
                    },
                    ModelId      = "contracts",
                    ModelVersion = "11.00",
                    Location     = new Location()
                    {
                        Begin = 241,
                        End   = 237
                    },
                    Text           = "1. IBM will provide a Senior Managing Consultant / expert resource, for up to 80 hours, to assist Florida Power & Light (FPL) with the creation of an IT infrastructure unit cost model for existing infrastructure.",
                    OriginalLabels = new OriginalLabelsIn()
                    {
                        Types = new List <TypeLabel>()
                        {
                            new TypeLabel()
                            {
                                Label = new Label()
                                {
                                    Nature = "Obligation",
                                    Party  = "IBM"
                                },
                                ProvenanceIds = new List <string>()
                                {
                                    "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                    "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                                }
                            },
                            new TypeLabel()
                            {
                                Label = new Label()
                                {
                                    Nature = "End User",
                                    Party  = "Exclusion"
                                },
                                ProvenanceIds = new List <string>()
                                {
                                    "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                    "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                                }
                            }
                        },
                        Categories = new List <Category>()
                        {
                            new Category()
                            {
                                Label         = "Responsibilities",
                                ProvenanceIds = new List <string>()
                                {
                                }
                            },
                            new Category()
                            {
                                Label         = "Amendments",
                                ProvenanceIds = new List <string>()
                                {
                                }
                            }
                        }
                    },
                    UpdatedLabels = new UpdatedLabelsIn()
                    {
                        Types = new List <TypeLabel>()
                        {
                            new TypeLabel()
                            {
                                Label = new Label()
                                {
                                    Nature = "Obligation",
                                    Party  = "IBM"
                                }
                            },
                            new TypeLabel()
                            {
                                Label = new Label()
                                {
                                    Nature = "Disclaimer",
                                    Party  = "buyer"
                                }
                            }
                        },
                        Categories = new List <Category>()
                        {
                            new Category()
                            {
                                Label = "Responsibilities",
                            },
                            new Category()
                            {
                                Label = "Audits"
                            }
                        }
                    }
                }
            };
            #endregion

            compareComply.AddFeedback(
                successCallback: OnAddFeedback,
                failCallback: OnFail,
                feedbackData: feedbackData
                );
            while (!addFeedbackTested)
            {
                yield return(null);
            }

            //  temporary fix for a bug requiring `x-watson-metadata` header
            Dictionary <string, object> customData    = new Dictionary <string, object>();
            Dictionary <string, string> customHeaders = new Dictionary <string, string>();
            customHeaders.Add("x-watson-metadata", "customer_id=sdk-test-customer-id");
            customData.Add(Constants.String.CUSTOM_REQUEST_HEADERS, customHeaders);

            compareComply.GetFeedback(
                successCallback: OnGetFeedback,
                failCallback: OnFail,
                feedbackId: feedbackId,
                modelId: "contracts",
                customData: customData
                );
            while (!getFeedbackTested)
            {
                yield return(null);
            }

            compareComply.DeleteFeedback(
                successCallback: OnDeleteFeedback,
                failCallback: OnFail,
                feedbackId: feedbackId,
                modelId: "contracts"
                );
            while (!deleteFeedbackTested)
            {
                yield return(null);
            }

            compareComply.ListBatches(
                successCallback: OnListBatches,
                failCallback: OnFail
                );
            while (!listBatchesTested)
            {
                yield return(null);
            }

            compareComply.CreateBatch(
                successCallback: OnCreateBatch,
                failCallback: OnFail,
                function: "html_conversion",
                inputCredentialsFile: objectStorageCredentialsInputData,
                inputBucketLocation: "us-south",
                inputBucketName: "compare-comply-integration-test-bucket-input",
                outputCredentialsFile: objectStorageCredentialsOutputData,
                outputBucketLocation: "us-south",
                outputBucketName: "compare-comply-integration-test-bucket-output"
                );
            while (!createBatchTested)
            {
                yield return(null);
            }

            compareComply.GetBatch(
                successCallback: OnGetBatch,
                failCallback: OnFail,
                batchId: batchId
                );
            while (!getBatchTestsed)
            {
                yield return(null);
            }

            compareComply.UpdateBatch(
                successCallback: OnUpdateBatch,
                failCallback: OnFail,
                batchId: batchId,
                action: "rescan",
                modelId: "contracts"
                );
            while (!updateBatchTested)
            {
                yield return(null);
            }

            Log.Debug("TestCompareComplyV1.RunTests()", "Compare and Comply integration tests complete!");
        }