Exemplo n.º 1
0
        public static void ArchiveDocument(Application app, string documentsDir, string documentTypeGroup)
        {
            logger.Info("Archive (upload) documents...");
            try
            {
                string filePath = documentsDir + "\\archive.json";
                if (File.Exists(filePath))
                {
                    logger.Info("Archive config file found: " + filePath);
                    string inputJSON = File.ReadAllText(filePath);

                    logger.Info("Get Document Type Group: " + documentTypeGroup);
                    DocumentTypeGroup docTypeGroup = app.Core.DocumentTypeGroups.Find(documentTypeGroup);
                    if (docTypeGroup == null)
                    {
                        throw new Exception("Document Type Group not found: " + documentTypeGroup);
                    }
                    logger.Info("Document Type Group found: " + documentTypeGroup);

                    IList <JToken> jTokens = JToken.Parse(inputJSON)["contents"].Children().ToList();
                    foreach (JToken jToken in jTokens)
                    {
                        Content content = jToken.ToObject <Content>();
                        logger.Info("");
                        logger.Info("Get Document Type: " + content.documentType);
                        DocumentType docType = docTypeGroup.DocumentTypes.Find(content.documentType);
                        if (docType == null)
                        {
                            throw new Exception("Document type was not found");
                        }

                        logger.Info("Get File Type: " + content.fileTypes[0]);
                        FileType fType = app.Core.FileTypes.Find(content.fileTypes[0]);
                        if (fType == null)
                        {
                            throw new Exception("File type was not found");
                        }

                        KeywordRecordType keywordRecordType = docType.KeywordRecordTypes[0];

                        string fileUploadPath = documentsDir + "\\" + content.file;
                        if (File.Exists(fileUploadPath))
                        {
                            logger.Info("Archive document found: " + fileUploadPath);
                            List <string> fileList = new List <string>();
                            fileList.Add(fileUploadPath);

                            StoreNewDocumentProperties storeDocumentProperties = app.Core.Storage.CreateStoreNewDocumentProperties(docType, fType);
                            foreach (var kt in keywordRecordType.KeywordTypes)
                            {
                                if (content.keywords.ContainsKey(kt.Name))
                                {
                                    logger.Info("Add Keyword: " + kt.Name + " = " + content.keywords[kt.Name]);

                                    switch (kt.DataType)
                                    {
                                    case KeywordDataType.AlphaNumeric:
                                        storeDocumentProperties.AddKeyword(kt.CreateKeyword(content.keywords[kt.Name]));
                                        break;

                                    case KeywordDataType.Currency:
                                    case KeywordDataType.SpecificCurrency:
                                    case KeywordDataType.Numeric20:
                                        storeDocumentProperties.AddKeyword(kt.CreateKeyword(decimal.Parse(content.keywords[kt.Name])));
                                        break;

                                    case KeywordDataType.Date:
                                    case KeywordDataType.DateTime:
                                        storeDocumentProperties.AddKeyword(kt.CreateKeyword(DateTime.Parse(content.keywords[kt.Name])));
                                        break;

                                    case KeywordDataType.FloatingPoint:
                                        storeDocumentProperties.AddKeyword(kt.CreateKeyword(double.Parse(content.keywords[kt.Name])));
                                        break;

                                    case KeywordDataType.Numeric9:
                                        storeDocumentProperties.AddKeyword(kt.CreateKeyword(long.Parse(content.keywords[kt.Name])));
                                        break;
                                    }
                                }
                            }

                            storeDocumentProperties.DocumentDate = DateTime.Now;
                            storeDocumentProperties.Comment      = "RSI OnBase Unity Application";
                            storeDocumentProperties.Options      = StoreDocumentOptions.SkipWorkflow;

                            Document newDocument = app.Core.Storage.StoreNewDocument(fileList, storeDocumentProperties);

                            logger.Info(string.Format("Document Archive was successful. New Document ID: {0}", newDocument.ID.ToString()));
                        }
                        else
                        {
                            logger.Info("Archive document file not found: " + fileUploadPath);
                        }
                    }
                }
                else
                {
                    logger.Info("Archive config file not found: " + filePath);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

            logger.Info("");
        }
Exemplo n.º 2
0
        IHttpActionResult ListDocs <T>(DocListFilter filter, Func <Document, DataResource <T> > resourceFactory)
        {
            // We bundle the bad requests in one response.
            var badRequestErrors = new List <Error>();

            //
            // Read the keywords.
            //
            var filterKeywords = new Dictionary <string, string>();

            if (!string.IsNullOrWhiteSpace(filter.KeywordsHasAll))
            {
                foreach (var kw in filter.KeywordsHasAll.Split('|'))
                {
                    var parts = kw.Split(':');
                    if (parts.Length == 2)
                    {
                        filterKeywords[parts[0]] = parts[1];
                    }
                    else
                    {
                        badRequestErrors.Add(BadRequestError("The filter[keywords][hasAll] parameter is not valid."));
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(filter.IndexKey) && string.IsNullOrWhiteSpace(filter.DocType))
            {
                badRequestErrors.Add(BadRequestError("One of filter[indexKey] or filter[type] parameters is required."));
            }

            var config = Global.Config;

            return(TryHandleRequest(app =>
            {
                DocumentTypeGroup docTypeGroup = null;
                if (!string.IsNullOrWhiteSpace(filter.DocTypeGroup))
                {
                    docTypeGroup = app.Core.DocumentTypeGroups.Find(filter.DocTypeGroup);
                    if (docTypeGroup == null)
                    {
                        badRequestErrors.Add(BadRequestError($"The document type group '{filter.DocTypeGroup}' could not be found."));
                    }
                }

                DocumentType docType = null;
                if (!string.IsNullOrWhiteSpace(filter.DocType))
                {
                    docType = app.Core.DocumentTypes.Find(filter.DocType);
                    if (docType == null)
                    {
                        badRequestErrors.Add(BadRequestError($"The document type '{filter.DocType}' could not be found."));
                    }
                }

                var query = app.Core.CreateDocumentQuery();
                if (query == null)
                {
                    badRequestErrors.Add(BadRequestError("Unable to create document query."));
                }

                // Check if there are any bad request errors. If there are then return them.
                if (badRequestErrors.Any())
                {
                    return BadRequestResult(badRequestErrors);
                }

                if (docTypeGroup != null)
                {
                    query.AddDocumentTypeGroup(docTypeGroup);
                }
                if (docType != null)
                {
                    query.AddDocumentType(docType);
                }
                if (!string.IsNullOrWhiteSpace(filter.IndexKey))
                {
                    query.AddKeyword(config.DocIndexKeyName, filter.IndexKey);
                }

                // Add the keywords to the query.
                foreach (var keyword in filterKeywords)
                {
                    query.AddKeyword(keyword.Key, keyword.Value);
                }

                // The OnBase API does not support a method for paging. The closest
                // we can get is to use a starting document ID.
                query.AddSort(DocumentQuery.SortAttribute.DocumentID, true);
                query.AddDocumentRange(filter.StartDocId, long.MaxValue);
                var queryResults = query.Execute(filter.PageSize);
                if (queryResults == null)
                {
                    return InternalErrorResult("Document query returned null.");
                }

                var docs = new List <DataResource <T> >();
                foreach (var doc in queryResults)
                {
                    docs.Add(resourceFactory(doc));
                }

                // Generate the query string for this request.
                var builder = new QueryStringBuilder();
                builder.Add("filter[indexKey]", filter.IndexKey, DefaultIndexKey);
                builder.Add("filter[docTypeGroup]", filter.DocTypeGroup, DefaultTypeGroup);
                builder.Add("filter[docType]", filter.DocType, DefaultDocType);
                builder.Add("filter[startDocId]", filter.StartDocId, DefaultStartDocId);
                builder.Add("filter[pageSize]", filter.PageSize, DefaultPageSize);
                builder.Add("filter[keywords][hasAll]", filter.KeywordsHasAll, DefaultKeywords);
                var queryStr = builder.ToString();

                return Ok(new ListResult <T>
                {
                    Data = docs,
                    Links = new DataLinks
                    {
                        Self = $"{config.ApiHost}/{config.ApiBasePath}{queryStr}",
                    }
                });
            }));
        }