Exemple #1
0
        /// <summary>
        /// Checks if a document from the drop off library exists in its respective destination library
        /// </summary>
        /// <param name="item">The SPListItem to check</param>
        /// <param name="existingDocId">If a duplicate is found, writes out the existing document's ID</param>
        /// <param name="existingDocIdUrl">If a duplicate is found, writes out the existing document's ID URL</param>
        /// <returns></returns>
        public static GuidewireOperationType SPDocExistsInDestinationLibrary(SPListItem item, out string existingDocId, out string existingDocIdUrl)
        {
            // Assumed that this document doesn't exist yet, and that the operation type is 'New'
            GuidewireOperationType operation = GuidewireOperationType.New;

            existingDocId    = null;
            existingDocIdUrl = null;

            // Split up the document name and extension so it can be formatted using a proper naming convention
            string fileExtension      = "." + item[SPBuiltInFieldId.File_x0020_Type].ToString().ToLower();
            string fileBaseName       = item.File.Name.Substring(0, item.File.Name.ToLower().LastIndexOf(fileExtension));
            string newFileName        = fileBaseName;
            string destinationListUrl = item.Web.Url + "/";
            string statusField;

            switch (item.ContentType.Name)
            {
            case "Guidewire Work Matter Document":
                newFileName        += " - " + item[Resource.FieldWorkMatter].ToString() + fileExtension;
                destinationListUrl += item.Web.Lists[Resource.WorkMatterDocumentsLibrary].RootFolder.Url;
                statusField         = Resource.FieldBCSWorkMatterDocumentStatus;
                break;

            case "Guidewire Vendor Document":
                newFileName        += " - " + item[Resource.FieldVendor].ToString() + fileExtension;
                destinationListUrl += item.Web.Lists[Resource.VendorDocumentsLibrary].RootFolder.Url;
                statusField         = Resource.FieldBCSVendorDocumentStatus;
                break;

            default:
                throw new SPException("Document was not an accepted content type");
            }

            // Try to get the possible existing file at the expected destination
            SPFile existingFile = item.Web.GetFile(destinationListUrl + "/" + newFileName);

            if (existingFile.Exists)
            {
                // Throw an exception if the document exists and it's marked as final
                if ((existingFile.Item.Fields.ContainsField(statusField) && existingFile.Item[statusField] != null && existingFile.Item[statusField].ToString() == "Final") || Records.IsRecord(existingFile.Item))
                {
                    throw new Exception(string.Format("Document named {0} has already been uploaded to SharePoint and has been declared as a record. It cannot be overwritten.", newFileName));
                }
                else
                {
                    // Document exists but it's not marked as final. We should be able to overwrite it
                    operation        = GuidewireOperationType.Update;
                    existingDocId    = existingFile.Item["_dlc_DocId"].ToString();
                    existingDocIdUrl = existingFile.Item["_dlc_DocIdUrl"].ToString();
                }
            }

            return(operation);
        }
Exemple #2
0
        /// <summary>
        /// Checks if a given item has a duplicate that is marked as final in either SharePoint or ClaimCenter.
        /// </summary>
        /// <param name="item">The SPListItem to check</param>
        /// <param name="existingDocId">If a duplicate is found in SharePoint, writes out the document ID</param>
        /// <param name="existingDocIdUrl">f a duplicate is found in SharePoint, writes out the document ID URL</param>
        /// <returns></returns>
        public static GuidewireOperationType CheckDuplicate(SPListItem item, out string existingDocId, out string existingDocIdUrl)
        {
            // Check if the document exists in SharePoint. If there is a duplicate, and the duplicate is already final, an exception is thrown
            GuidewireOperationType operation = SPDocExistsInDestinationLibrary(item, out existingDocId, out existingDocIdUrl);

            thisItem = item;
            string docIdToCheck = item["_dlc_DocId"].ToString();

            // If there was a document found in SharePoint, we will be checking that document's ID
            if (existingDocId != null)
            {
                docIdToCheck = existingDocId;
            }
            switch (item["Content Type"].ToString())
            {
            case "Guidewire Work Matter Document":
                // Check if the document exists in Guidewire. Throw an exception if it already exists and is marked as final
                GWBCS.WorkMatterDocument wmDoc = GetGWWorkMatterDocById(docIdToCheck);
                if (wmDoc != null)
                {
                    if (wmDoc.Status == "Final")
                    {
                        throw new Exception(string.Format("Document with ID {0} already exists in ClaimCenter and is marked as Final. It cannot be overwritten.", item["_dlc_DocId"].ToString()));
                    }
                    else
                    {
                        operation = GuidewireOperationType.Update;
                    }
                }
                break;

            case "Guidewire Vendor Document":
                // Check if the document exists in Guidewire. Throw an exception if it already exists and is marked as final
                GWBCS.VendorDocument vendorDoc = GetGWVendorDocById(docIdToCheck);
                if (vendorDoc != null)
                {
                    if (vendorDoc.Status == "Final")
                    {
                        throw new Exception(string.Format("Document with ID {0} already exists in ContactManager and is marked as Final. It cannot be overwritten.", item["_dlc_DocId"].ToString()));
                    }
                    else
                    {
                        operation = GuidewireOperationType.Update;
                    }
                }
                break;

            default:
                throw new SPException("Content type was not recognized");
            }

            return(operation);
        }
Exemple #3
0
        /// <summary>
        /// Call the Guidewire Update Metadata service for a SPListItem and an operation type
        /// </summary>
        /// <param name="item">The SPListItem to send to ClaimCenter</param>
        /// <param name="type">The Guidewire Operation Type</param>
        /// <param name="manualDocId">Optional. An overridable document ID in the case that the original document ID is changing</param>
        /// <returns></returns>
        public static Boolean CallGuideWire(SPListItem item, GuidewireOperationType type, string manualDocId = null)
        {
            Boolean success = false;
            // Create the Guidewire WS Client
            EndpointAddress endpointAddress = new EndpointAddress(Configuration.GetConfigurationValue(item.ParentList.ParentWeb, Resource.ConfigGWWsEndpoint));

            System.ServiceModel.Channels.Binding            binding = CreateBinding();
            GuidewireWS.trg_UpdateMetadataAPIPortTypeClient client  = new GuidewireWS.trg_UpdateMetadataAPIPortTypeClient(binding, endpointAddress);
            // Create authentication
            GuidewireWS.authentication authentication = CreateAuthentication(item.ParentList.ParentWeb);
            GuidewireWS.locale         locale         = new GuidewireWS.locale();
            locale.Value = "en_US"; //CultureInfo.CurrentCulture.ToString(); //
            // Create document info
            GuidewireWS.trg_DocumentInfo documentInfo = new GuidewireWS.trg_DocumentInfo();
            documentInfo.operation = (int)type;
            if (manualDocId != null)
            {
                documentInfo.documentID = manualDocId;
            }
            else
            {
                documentInfo.documentID = Util.GetDocumentId(item);
            }
            List <GuidewireWS.trg_MetadataPair> metadata = CreateMetadata(item);

            if (metadata != null)
            {
                documentInfo.metadata = metadata.ToArray();
                // Call Guidewire
                try
                {
                    success = client.updateMetadata(authentication, locale, documentInfo);
                    if (!success)
                    {
                        Util.LogError("Call to Guidewire was unsuccessful operation type = " + type.ToString());
                    }
                }
                catch (Exception e)
                {
                    success = false;
                    LogError("CallGuidewire failed with exception:  " + e.Message);
                }
            }
            else
            {
                return(false);
            }

            return(success);
        }
Exemple #4
0
        public static Boolean CallGuidewire(SPListItem item, GuidewireOperationType type)
        {
            Boolean         success         = false;
            EndpointAddress endpointAddress = new EndpointAddress(ConfigurationManager.AppSettings["GuidewireEndpoint"]);
            Binding         binding         = CreateBinding();

            GuidewireWS.trg_UpdateMetadataAPIPortTypeClient client = new GuidewireWS.trg_UpdateMetadataAPIPortTypeClient(binding, endpointAddress);
            GuidewireWS.authentication   authentication            = CreateAuthentication();
            GuidewireWS.locale           locale       = new GuidewireWS.locale();
            GuidewireWS.trg_DocumentInfo documentInfo = new GuidewireWS.trg_DocumentInfo();
            documentInfo.operation  = (int)type;
            documentInfo.documentID = Util.GetDocumentId(item);
            List <GuidewireWS.trg_MetadataPair> metadata = CreateMetadata(item);

            if (metadata != null)
            {
                documentInfo.metadata = metadata.ToArray();
                try
                {
                    success = client.updateMetadata(authentication, locale, documentInfo);
                    if (!success)
                    {
                        Util.LogError("Call to Guidewire was unsuccessful. Operation type = " + type.ToString());
                        Console.WriteLine("Call to Guidewire was unsuccessful. Operation type = " + type.ToString());
                    }
                }
                catch (Exception e)
                {
                    success = false;
                    Util.LogError("CallGuidewire failed with exception:  " + e.Message);
                    Console.WriteLine("CallGuidewire failed with exception:  " + e.Message);
                }
            }
            else
            {
                return(false);
            }

            return(success);
        }