/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteDocumentResponse response = new DeleteDocumentResponse();


            return response;
        }
Exemple #2
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteDocumentResponse response = new DeleteDocumentResponse();


            return(response);
        }
Exemple #3
0
    private void OnDeleteDocument(DeleteDocumentResponse resp, Dictionary <string, object> customData)
    {
        Log.Debug("ExampleDiscovery.OnDeleteDocument()", "Discovery - Delete document Response: deleted:{0}", customData["json"].ToString());
        _createdDocumentID = default(string);

        _deleteDocumentTested = true;
    }
Exemple #4
0
        public IHttpActionResult DeleteDocument(Guid documentId, string version = null)
        {
            Guid messageId;
            Dictionary <string, dynamic> keyValuePairs;

            //Retrieve the header parameters from request object
            RetrieveHeaders(out keyValuePairs, out messageId);
            DeleteDocumentRequest  deleteDocumentRequest  = new DeleteDocumentRequest();
            DeleteDocumentResponse deleteDocumentResponse = new DeleteDocumentResponse();

            try
            {
                Log.DebugFormat("In api/DeleteDocument method for MessageId - {0}", messageId.ToString());
                //Assign the documentid to request model
                deleteDocumentRequest.DocumentId = documentId;
                //Assign the version number to request model
                deleteDocumentRequest.Version = version;
                Log.DebugFormat("In api/DeleteDocument for MessageId - {0} before calling DDMSDelete DocumentId :{1}", messageId.ToString(), deleteDocumentRequest.DocumentId.ToString());
                //Call Delete method
                deleteDocumentResponse = ddmsDeleteDocument.DDMSDelete(deleteDocumentRequest, messageId.ToString());
                Log.DebugFormat("In api/DeleteDocument for MessageId - {0} after calling DDMSDelete DocumentId :{1}", messageId.ToString(), deleteDocumentRequest.DocumentId.ToString());

                if (string.IsNullOrEmpty(deleteDocumentResponse.ErrorMessage))
                {
                    //Add response headers
                    keyValuePairs.Add(HeaderConstants.ErrorCode, (int)HttpStatusCode.OK);
                    keyValuePairs.Add(HeaderConstants.Status, HeaderValueConstants.Success);
                    foreach (var field in keyValuePairs)
                    {
                        if (!string.IsNullOrEmpty(field.Value.ToString()) && !string.IsNullOrWhiteSpace(field.Value.ToString()))
                        {
                            HttpContext.Current.Response.Headers.Add(field.Key, field.Value.ToString());
                        }
                    }
                    return(Content(HttpStatusCode.OK, deleteDocumentResponse));
                }
                //If file is not found based on documentId
                if (deleteDocumentResponse.ErrorMessage == ErrorMessage.FileNotFound)
                {
                    AddErrorResponseHeaders(keyValuePairs, (int)HttpStatusCode.NotFound, ErrorMessage.FileNotFound);
                    return(Content(HttpStatusCode.NotFound, deleteDocumentResponse));
                }
                else
                {
                    AddErrorResponseHeaders(keyValuePairs, (int)HttpStatusCode.InternalServerError, deleteDocumentResponse.ErrorMessage);
                    return(Content(HttpStatusCode.InternalServerError, deleteDocumentResponse));
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Error in api/DeleteDocument DDMSDelete method for MessageId - {0} :{1}", messageId.ToString(), ex.Message);
                deleteDocumentResponse.ErrorMessage = ex.Message;
                AddErrorResponseHeaders(keyValuePairs, (int)HttpStatusCode.InternalServerError, deleteDocumentResponse.ErrorMessage);
                return(Content(HttpStatusCode.InternalServerError, deleteDocumentResponse));
            }
        }
Exemple #5
0
        public IEnumerator TestDeleteDocument()
        {
            Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to DeleteDocument...");
            DeleteDocumentResponse deleteDocumentResponse = null;

            service.DeleteDocument(
                callback: (DetailedResponse <DeleteDocumentResponse> response, IBMError error) =>
            {
                Log.Debug("DiscoveryServiceV2IntegrationTests", "DeleteDocument result: {0}", response.Response);
                deleteDocumentResponse = response.Result;
                Assert.IsNotNull(deleteDocumentResponse);
                Assert.IsNull(error);
            },
                projectId: projectId,
                collectionId: collectionId,
                documentId: documentId
                );

            while (deleteDocumentResponse == null)
            {
                yield return(null);
            }
        }
Exemple #6
0
        public DeleteDocumentResponse DeleteDocument(string environmentId, string collectionId, string documentId)
        {
            if (string.IsNullOrEmpty(environmentId))
            {
                throw new ArgumentNullException(nameof(environmentId));
            }
            if (string.IsNullOrEmpty(collectionId))
            {
                throw new ArgumentNullException(nameof(collectionId));
            }
            if (string.IsNullOrEmpty(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }

            if (string.IsNullOrEmpty(VersionDate))
            {
                throw new ArgumentNullException("versionDate cannot be null. Use 'DISCOVERY_VERSION_DATE_2016_12_01'");
            }

            DeleteDocumentResponse result = null;

            try
            {
                result = this.Client.WithAuthentication(this.UserName, this.Password)
                         .DeleteAsync($"{this.Endpoint}/v1/environments/{environmentId}/collections/{collectionId}/documents/{documentId}")
                         .WithArgument("version", VersionDate)
                         .As <DeleteDocumentResponse>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
        //[UnityTest, Order(103)]
        public IEnumerator TestDeleteTrainingQuery()
        {
            Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to DeleteTrainingQuery...");

            DocumentAccepted addDocumentResponse = null;
            string           documentId          = "";
            string           queryId             = "";

            using (FileStream fs = File.OpenRead(addDocumentFile))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    service.AddDocument(
                        callback: (DetailedResponse <DocumentAccepted> response, IBMError error) =>
                    {
                        Log.Debug("DiscoveryServiceV1IntegrationTests", "AddDocument result: {0}", response.Response);
                        addDocumentResponse = response.Result;
                        documentId          = addDocumentResponse.DocumentId;
                        Assert.IsNotNull(addDocumentResponse);
                        Assert.IsNotNull(documentId);
                        Assert.IsNull(error);
                    },
                        projectId: projectId,
                        collectionId: collectionId,
                        file: ms,
                        fileContentType: Utility.GetMimeType(Path.GetExtension(addDocumentFile)),
                        filename: Path.GetFileName(addDocumentFile)
                        );

                    while (addDocumentResponse == null)
                    {
                        yield return(null);
                    }
                }
            }

            TrainingExample trainingExample = new TrainingExample()
            {
                CollectionId = collectionId,
                DocumentId   = documentId,
                Relevance    = 1L
            };
            TrainingQuery trainingQueryResponse = null;

            service.CreateTrainingQuery(
                callback: (DetailedResponse <TrainingQuery> response, IBMError error) =>
            {
                Log.Debug("DiscoveryServiceV2IntegrationTests", "CreateTrainingQuery result: {0}", response.Response);
                trainingQueryResponse = response.Result;
                queryId = trainingQueryResponse.QueryId;
                Assert.IsNotNull(trainingQueryResponse);
                Assert.IsNull(error);
            },
                projectId: projectId,
                examples: new List <TrainingExample>()
            {
                trainingExample
            },
                filter: "entities.text:IBM",
                naturalLanguageQuery: "This is an example of a query"
                );

            while (trainingQueryResponse == null)
            {
                yield return(null);
            }

            bool deleteTrainingQueryResponse = false;

            service.DeleteTrainingQuery(
                callback: (DetailedResponse <object> response, IBMError error) =>
            {
                Assert.IsNull(error);
                deleteTrainingQueryResponse = true;
            },
                projectId: projectId,
                queryId: queryId
                );

            while (!deleteTrainingQueryResponse)
            {
                yield return(null);
            }

            DeleteDocumentResponse deleteDocumentResponse = null;

            service.DeleteDocument(
                callback: (DetailedResponse <DeleteDocumentResponse> response, IBMError error) =>
            {
                Log.Debug("DiscoveryServiceV2IntegrationTests", "DeleteDocument result: {0}", response.Response);
                deleteDocumentResponse = response.Result;
                Assert.IsNotNull(deleteDocumentResponse);
                Assert.IsNull(error);
            },
                projectId: projectId,
                collectionId: collectionId,
                documentId: documentId
                );

            while (deleteDocumentResponse == null)
            {
                yield return(null);
            }
        }
Exemple #8
0
        /// <summary>
        /// Method to delete a document
        /// </summary>
        /// <param name="deleteDocumentRequest">Request model for Delete Operation</param>
        /// <param name="LoggerId">Message Id used for Logging</param>
        /// <returns></returns>
        public DeleteDocumentResponse DDMSDelete(DeleteDocumentRequest deleteDocumentRequest, string LoggerId)
        {
            DeleteDocumentResponse deleteDocumentResponse = new DeleteDocumentResponse();
            SecureString           secureString           = null;

            try
            {
                //If documentid is not empty in request model
                if (deleteDocumentRequest.DocumentId != Guid.Empty)
                {
                    Log.DebugFormat("In DDMSDelete method for MessageId - {0} DocumentId :{1}", LoggerId, deleteDocumentRequest.DocumentId.ToString());
                    using (ClientContext clientContext = new ClientContext(ConfigurationManager.AppSettings.Get(ConfigurationConstants.SPOSiteURL)))
                    {
                        //Get SPO Credentials
                        secureString = new NetworkCredential("", CommonHelper.Decrypt(ConfigurationManager.AppSettings.Get(ConfigurationConstants.SPOPassword),
                                                                                      ConfigurationManager.AppSettings.Get(ConfigurationConstants.SPOPasswordKey),
                                                                                      ConfigurationManager.AppSettings.Get(ConfigurationConstants.SPOPasswordIv))).SecurePassword;
                        //Decrypt the user name and password information
                        String username = CommonHelper.Decrypt(ConfigurationManager.AppSettings.Get(ConfigurationConstants.SPOUserName),
                                                               ConfigurationManager.AppSettings.Get(ConfigurationConstants.SPOUserNameKey),
                                                               ConfigurationManager.AppSettings.Get(ConfigurationConstants.SPOUserNameIv));

                        clientContext.Credentials = new SharePointOnlineCredentials(username, secureString);
                        if (!(string.IsNullOrEmpty(deleteDocumentRequest.Version) || string.IsNullOrWhiteSpace(deleteDocumentRequest.Version)))
                        {
                            //Invoke method to delete a specific version
                            DeleteByVersion(clientContext, deleteDocumentRequest, LoggerId);
                        }
                        if ((string.IsNullOrEmpty(deleteDocumentRequest.Version) || string.IsNullOrWhiteSpace(deleteDocumentRequest.Version)))
                        {
                            //Invoke method to delete entire document
                            DeleteAllversions(clientContext, deleteDocumentRequest, LoggerId);
                        }
                    }
                    Log.DebugFormat("Out of DDMSDelete method for MessageId - {0} DocumentId :{1}", LoggerId, deleteDocumentRequest.DocumentId.ToString());
                }
                else
                {
                    deleteDocumentResponse.ErrorMessage = string.Format(ErrorMessage.ValueEmpty, SpoConstants.DocumentId);
                }
            }
            catch (WebException e) when(e.Status == WebExceptionStatus.NameResolutionFailure)
            {
                Log.ErrorFormat("WebException in DDMSDelete method for MessageId - {0} :{1}", LoggerId, e.Message);
                deleteDocumentResponse.ErrorMessage = ErrorMessage.RemoteName;
            }
            catch (ServerException ex)
            {
                Log.ErrorFormat("ServerException in DDMSDelete method for MessageId - {0} :{1}", LoggerId, ex.Message);
                if (ex.ServerErrorTypeName == ErrorException.SystemIoFileNotFound)
                {
                    deleteDocumentResponse.ErrorMessage = ErrorMessage.FileNotFound;
                }
                else
                {
                    deleteDocumentResponse.ErrorMessage = ex.Message;
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Exception in DDMSDelete method for MessageId - {0} :{1}", LoggerId, ex.Message);
                deleteDocumentResponse.ErrorMessage = ex.Message;
            }
            return(deleteDocumentResponse);
        }