예제 #1
0
        protected virtual string InsertDocumentIntoDatabase(Type xmlDataType, NodeTransaction nodeTransaction, Document document)
        {
            if (_baseDao == null)
            {
                string noInsertMessage = "No data was inserted into the database since a data destination was not configured for the service";
                AppendAuditLogEvent(noInsertMessage);
                return(noInsertMessage);
            }
            AppendAuditLogEvent("Loading RCRA content from transaction document \"{0}\" ...",
                                document.DocumentName);
            string operation;
            object xmlData = GetHeaderDocumentContent(xmlDataType, nodeTransaction.Id, document.Id, _settingsProvider,
                                                      _serializationHelper, _compressionHelper, _documentManager,
                                                      out operation);

            AppendAuditLogEvent("Inserting RCRA content into database for document \"{0}\" ...",
                                document.DocumentName);

            try
            {
                Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(xmlData, _baseDao);
                string tableCountsString = string.Format("Successfully inserted RCRA content into database for document \"{0}\" with table counts: {1}",
                                                         document.DocumentName, CreateTableRowCountsString(tableRowCounts));
                AppendAuditLogEvent(tableCountsString);

                return(tableCountsString);
            }
            catch (Exception ex)
            {
                AppendAuditLogEvent("Failed to insert RCRA content into database for document \"{0}\" with exception: {1}",
                                    document.DocumentName, ExceptionUtils.GetDeepExceptionMessage(ex));
                throw;
            }
        }
        public static string StoreWqxDataToDatabase(IAppendAuditLogEvent appendAuditLogEvent, WQXDataType data, IObjectsToDatabase objectsToDatabase,
                                                    SpringBaseDao baseDao, string attachmentsFolderPath)
        {
            appendAuditLogEvent.AppendAuditLogEvent("Storing WQX data into the database ...");

            string countsString = string.Empty;

            baseDao.TransactionTemplate.Execute(delegate(Spring.Transaction.ITransactionStatus status)
            {
                OrganizationDataType org = data.Organization;

                appendAuditLogEvent.AppendAuditLogEvent("Storing WQX data into database for organization \"{0}\" ...", org.OrganizationDescription.OrganizationFormalName);

                appendAuditLogEvent.AppendAuditLogEvent(DatabaseHelper.GetWqxOrgCountsString(org));

                Dictionary <string, int> insertCounts = objectsToDatabase.SaveToDatabase(data, baseDao);

                DatabaseHelper.StoreAttachmentFilesFromFolder(objectsToDatabase, baseDao, data.Organization, attachmentsFolderPath);

                countsString += string.Format("Stored WQX data for organization \"{0}\" into the database with the following table row counts:{1}{2}",
                                              org.OrganizationDescription.OrganizationFormalName, Environment.NewLine, CreateTableRowCountsString(insertCounts));

                appendAuditLogEvent.AppendAuditLogEvent(countsString);

                return(null);
            });
            return(countsString);
        }
        protected virtual Dictionary <string, int> Insert(T dataToInsert)
        {
            Dictionary <string, int> tableRowCounts = null;

            if (dataToInsert != null)
            {
                tableRowCounts = _objectsToDatabase.SaveToDatabase(dataToInsert, _baseDao);
            }
            return(tableRowCounts);
        }
예제 #4
0
        public void ProcessTask(string requestId)
        {
            ProcessRequestInit(requestId);

            if (!File.Exists(_xmlFilePath))
            {
                throw new FileNotFoundException(string.Format("The file \"{0}\" was not found", _xmlFilePath));
            }

            AppendAuditLogEvent("Loading file \"{0}\" into the database", _xmlFilePath);

            XmlElement  element = null;
            XmlDocument doc     = new XmlDocument();

            using (Stream fileStream = File.OpenRead(_xmlFilePath))
            {
                using (XmlReader reader = new XmlTextReader(fileStream))
                {
                    doc.Load(reader);
                    XmlNodeList list = doc.GetElementsByTagName("Payload");
                    if (!CollectionUtils.IsNullOrEmpty(list))
                    {
                        XmlNode node = list.Item(0);
                        element = node.FirstChild as XmlElement;
                    }
                    if (element == null)
                    {
                        element = doc.DocumentElement;
                    }
                }
            }

            object objectToSave = TryLoadObject <FacilityDetailsDataType>(element);

            if (objectToSave == null)
            {
                throw new InvalidDataException(string.Format("The file \"{0}\" does not contain any valid FACID30 types", _xmlFilePath));
            }

            AppendAuditLogEvent("Loaded object of type \"{0}\" from xml file", objectToSave.GetType().Name);

            AppendAuditLogEvent("Validating database staging tables ...");
            _objectsToDatabase.BuildDatabase(objectToSave.GetType(), _baseDao);

            AppendAuditLogEvent("Loading object into database staging tables ...");
            Dictionary <string, int> insertCounts = _objectsToDatabase.SaveToDatabase(objectToSave, _baseDao);

            AppendAuditLogEvent(GetRowCountsAuditString(insertCounts));

            AppendAuditLogEvent("Success, primary key: {0}!", ReflectionUtils.GetFieldOrPropertyValueByName <string>(objectToSave, "PK"));
        }
예제 #5
0
        protected virtual string InsertDocumentIntoDatabase(Type xmlDataType, NodeTransaction nodeTransaction, Document document)
        {
            if (_baseDao == null)
            {
                string noInsertMessage = "No data was inserted into the database since a data destination was not configured for the service";
                AppendAuditLogEvent(noInsertMessage);
                return(noInsertMessage);
            }
            AppendAuditLogEvent("Loading FACID content from transaction document \"{0}\" ...",
                                document.DocumentName);
            string operation;
            object xmlData = GetHeaderDocumentContent(xmlDataType, nodeTransaction.Id, document.Id, _settingsProvider,
                                                      _serializationHelper, _compressionHelper, _documentManager,
                                                      out operation);

            AppendAuditLogEvent("Inserting FACID content into database for document \"{0}\" ...",
                                document.DocumentName);

            try
            {
                if (_deleteExistingDataBeforeInsert)
                {
                    AppendAuditLogEvent("Deleting existing FACID data of type \"{0}\" from the data store ...", xmlDataType.Name);
                    int numRowsDeleted = _objectsToDatabase.DeleteAllFromDatabase(xmlDataType, _baseDao);

                    if (numRowsDeleted > 0)
                    {
                        AppendAuditLogEvent("Deleted {0} existing FACID data rows from the data store", numRowsDeleted.ToString());
                    }
                    else
                    {
                        AppendAuditLogEvent("Did not find any existing FACID data to delete from the data store");
                    }
                }
                Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(xmlData, _baseDao);
                string tableCountsString = string.Format("Successfully inserted FACID content into database for document \"{0}\" with table counts: {1}",
                                                         document.DocumentName, CreateTableRowCountsString(tableRowCounts));
                AppendAuditLogEvent(tableCountsString);

                return(tableCountsString);
            }
            catch (Exception ex)
            {
                AppendAuditLogEvent("Failed to insert FACID content into database for document \"{0}\" with exception: {1}",
                                    document.DocumentName, ExceptionUtils.GetDeepExceptionMessage(ex));
                throw;
            }
        }
예제 #6
0
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            try
            {
                // Load the submission data from the xml file
                Organization data = GetSubmitDocumentData(transactionId, docId);

                int numRowsDeleted = 0;
                Dictionary <string, int> tableRowCounts = null;

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteBeforeInsert)
                    {
                        // Delete existing data from the database
                        numRowsDeleted = _objectsToDatabase.DeleteAllFromDatabase(data.GetType(), _baseDao, typeof(MappingAttributes));
                    }

                    // Insert data into the database
                    tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao, typeof(MappingAttributes));

                    return(null);
                });

                if (numRowsDeleted > 0)
                {
                    AppendAuditLogEvent("Deleted {0} existing ATTAINS elements from the data store",
                                        numRowsDeleted.ToString());
                }
                else
                {
                    AppendAuditLogEvent("Did not delete any existing ATTAINS data from the data store");
                }
                var pk = _objectsToDatabase.GetPrimaryKeyValueForObject(data, typeof(MappingAttributes));
                AppendAuditLogEvent("Stored ATTAINS data content with primary key \"{0}\" into data store with the following table row counts: {1}",
                                    pk, CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
        }
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            try
            {
                // Load the submission data from the xml file
                StateAssessmentDetailsDataType data = GetSubmitDocumentData(transactionId, docId);

                int numRowsDeleted = 0;
                Dictionary <string, int> tableRowCounts = null;

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteBeforeInsert)
                    {
                        // Delete existing data from the database
                        string parentTableName = _objectsToDatabase.GetTableNameForType(data.GetType());
                        numRowsDeleted         = _baseDao.DoSimpleDelete(parentTableName, null, null);
                    }

                    // Insert data into the database
                    tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao);

                    return(null);
                });

                if (numRowsDeleted > 0)
                {
                    AppendAuditLogEvent("Deleted {0} existing OWIR-ATT elements from the data store",
                                        numRowsDeleted.ToString());
                }
                else
                {
                    AppendAuditLogEvent("Did not delete any existing OWIR-ATT data from the data store");
                }
                AppendAuditLogEvent("Stored OWIR-ATT data content with primary key \"{0}\" into data store with the following table row counts: {1}",
                                    data._PK, CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
        }
예제 #8
0
        protected override void ProcessSubmitDocument(string transactionId, string docId)
        {
            try {
                CERSDataType data = GetSubmitDocumentData(transactionId, docId);

                int numRowsDeleted = 0;
                Dictionary <string, int> tableRowCounts = null;

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    numRowsDeleted = _baseDao.DoSimpleDelete("CERS_CERS", "DATA_CATEGORY;EMIS_YEAR", data.DataCategory.ToString(),
                                                             data.EmissionsYear);

                    tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao);

                    return(null);
                });

                if (numRowsDeleted > 0)
                {
                    AppendAuditLogEvent("Deleted {0} existing CERS data from the data store for data category \"{1}\" and emissions year \"{2}\"",
                                        numRowsDeleted.ToString(), data.DataCategory, data.EmissionsYear);
                }
                else
                {
                    AppendAuditLogEvent("Did not delete any existing CERS data from the data store");
                }
                AppendAuditLogEvent("Stored CERS data content with primary key \"{0}\" into data store with the following table row counts: {1}",
                                    data._PK, CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
        }
        protected virtual bool DoProcessResponseDocuments(string localTransactionId, IList <string> documentNames, out Windsor.Node2008.WNOSDomain.Document zipResponseFile)
        {
            AppendAuditLogEvent("Attempting to process response documents for ICIS submission with transaction id \"{0}\"", _submissionTrackingDataType.SubmissionTransactionId);

            string responseZipFileName = FindResponseZipFileName(documentNames);

            AppendAuditLogEvent("Extracting response document content ...");

            zipResponseFile = _documentManager.GetDocumentByName(localTransactionId, responseZipFileName, true);

            string tempFolder = _settingsProvider.CreateNewTempFolderPath();

            _compressionHelper.UncompressDirectory(zipResponseFile.Content, tempFolder);

            string[] responseFiles = Directory.GetFiles(tempFolder);

            string responseAcceptedFilePath = FindResponseAcceptedFilePath(responseFiles);
            string responseRejectedFilePath = FindResponseRejectedFilePath(responseFiles);

            AppendAuditLogEvent("Loading response document content ...");

            AppendAuditLogEvent("Transforming accepted response file ...");
            string responseAcceptedTransformedFilePath = TransformResponseFile50(responseAcceptedFilePath);
            SubmissionResultList acceptedList          = _serializationHelper.Deserialize <SubmissionResultList>(responseAcceptedTransformedFilePath);

#if INCLUDE_TEST_SUBMIT_PROCESSOR
            if (DebugUtils.IsDebugging)
            {
                foreach (var submissionResultsDataType in acceptedList.SubmissionResult)
                {
                    if (string.IsNullOrEmpty(submissionResultsDataType.SubmissionTransactionId))
                    {
                        throw new ArgException("submissionResultsDataType.SubmissionTransactionId is null");
                    }
                }
            }
#endif // INCLUDE_TEST_SUBMIT_PROCESSOR

            AppendAuditLogEvent("Transforming rejected response file ...");
            string responseRejectedTransformedFilePath = TransformResponseFile50(responseRejectedFilePath);
            SubmissionResultList rejectedList          = _serializationHelper.Deserialize <SubmissionResultList>(responseRejectedTransformedFilePath);
#if INCLUDE_TEST_SUBMIT_PROCESSOR
            if (DebugUtils.IsDebugging)
            {
                foreach (var submissionResultsDataType in rejectedList.SubmissionResult)
                {
                    if (string.IsNullOrEmpty(submissionResultsDataType.SubmissionTransactionId))
                    {
                        throw new ArgException("submissionResultsDataType.SubmissionTransactionId is null");
                    }
                }
            }
#endif // INCLUDE_TEST_SUBMIT_PROCESSOR

            List <SubmissionResultsDataType> saveList = new List <SubmissionResultsDataType>(CollectionUtils.Count(acceptedList.SubmissionResult) +
                                                                                             CollectionUtils.Count(rejectedList.SubmissionResult));

            DateTime now = DateTime.Now;
            CollectionUtils.ForEach(acceptedList.SubmissionResult, delegate(SubmissionResultsDataType result)
            {
                //DebugUtils.AssertDebuggerBreak(result.SubmissionTransactionId == _submissionTrackingDataType.SubmissionTransactionId);
                result.CreatedDateTime = now;
                saveList.Add(result);
            });
            CollectionUtils.ForEach(rejectedList.SubmissionResult, delegate(SubmissionResultsDataType result)
            {
                //DebugUtils.AssertDebuggerBreak(result.SubmissionTransactionId == _submissionTrackingDataType.SubmissionTransactionId);
                result.CreatedDateTime = now;
                saveList.Add(result);
            });


            _baseDao.TransactionTemplate.Execute(delegate(Spring.Transaction.ITransactionStatus status)
            {
                try
                {
                    AppendAuditLogEvent("Saving response data to database ...");
                    Type mappingAttributesType = typeof(Windsor.Node2008.WNOSPlugin.ICISNPDES_50.MappingAttributes);

                    Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(saveList, _baseDao, false, mappingAttributesType);

                    AppendAuditLogEvent("Response data saved to database with the following insert row counts: {0}", CreateTableRowCountsString(tableRowCounts));
                }
                catch (Exception ex1)
                {
                    AppendAuditLogEvent("Failed to save response data to database, rolling back transaction: {0}", ExceptionUtils.GetDeepExceptionMessage(ex1));
                    throw;
                }

                ExecuteStoredProc();

                return(null);
            });

            return(true);
        }
예제 #10
0
        protected virtual CommonTransactionStatusCode ProcessSubmitDocument(string transactionId, string docId, out string statusDetail)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (_compressionHelper.IsCompressed(document.Content))
                {
                    AppendAuditLogEvent("Decompressing document to temporary file");
                    _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath);
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                if (_validateXml)
                {
                    ValidateXmlFileAndAttachErrorsAndFileToTransaction(tempXmlFilePath, "xml_schema.xml_schema.zip",
                                                                       null, transactionId);
                }

                AppendAuditLogEvent("Deserializing document data to ICIS data");
                XmlReader reader = new NamespaceSpecifiedXmlTextReader("http://www.exchangenetwork.net/schema/icis/4", tempXmlFilePath);
                Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document data =
                    _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document>(reader);

                //Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document data =
                //    _serializationHelper.Deserialize<Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document>(tempXmlFilePath);

                if (CollectionUtils.IsNullOrEmpty(data.Payload))
                {
                    statusDetail = "Deserialized ICIS does not contain any payload elements, exiting processing thread.";
                    AppendAuditLogEvent(statusDetail);
                    return(CommonTransactionStatusCode.Completed);
                }
                AppendAuditLogEvent("ICIS data contains {0} payloads", data.Payload.Length.ToString());

                Type mappingAttributesType = typeof(Windsor.Node2008.WNOSPlugin.ICISAIR_54.MappingAttributes);

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteExistingDataBeforeInsert)
                    {
                        AppendAuditLogEvent("Deleting all existing ICIS payload data from the data store");

                        int numRowsDeleted = _objectsToDatabase.DeleteAllFromDatabase(typeof(Windsor.Node2008.WNOSPlugin.ICISAIR_54.Payload),
                                                                                      _baseDao, mappingAttributesType);
                        if (numRowsDeleted > 0)
                        {
                            AppendAuditLogEvent("Deleted {0} existing ICIS payload data rows from the data store",
                                                numRowsDeleted.ToString());
                        }
                        else
                        {
                            AppendAuditLogEvent("Did not find any existing ICIS payload data to delete from the data store");
                        }
                    }

                    AppendAuditLogEvent("Storing ICIS payload data into database");

                    foreach (Windsor.Node2008.WNOSPlugin.ICISAIR_54.Payload payload in data.Payload)
                    {
                        Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(payload, _baseDao, mappingAttributesType);

                        AppendAuditLogEvent("Stored ICIS payload data for operation \"{0}\" into data store with the following table row counts: {1}",
                                            payload.Operation.ToString(), CreateTableRowCountsString(tableRowCounts));
                    }

                    return(null);
                });

                AttachSubmissionResponseToTransaction(transactionId);

                statusDetail = "Successfully processed the submitted ICIS document.";
                return(CommonTransactionStatusCode.Completed);
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}\" with error: {1}",
                                    docId.ToString(), ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
예제 #11
0
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (document.IsZipFile)
                {
                    AppendAuditLogEvent("Decompressing document to temporary file");
                    _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath);
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                AppendAuditLogEvent("Deserializing document data to BEACHES data");
                Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachDataSubmissionDataType data =
                    _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachDataSubmissionDataType>(tempXmlFilePath);
                data.BeforeSaveToDatabase();

                AppendAuditLogEvent("Storing BEACHES data into database");

                AppendAuditLogEvent("BEACHES data contains {0} Organization Details, {0} Beach Details, and {0} Beach Procedure Details",
                                    CollectionUtils.Count(data.OrganizationDetail).ToString(),
                                    CollectionUtils.Count(data.BeachDetail).ToString(),
                                    CollectionUtils.Count(data.BeachProcedureDetail).ToString());

                AppendAuditLogEvent("Deleting existing BEACHES data from the data store ...");

                int numRowsDeleted = 0;
                Dictionary <string, int> tableRowCounts = null;

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_YEARCOMPLETION");
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_PROCEDURE");
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_BEACH");
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_ORGANIZATION");

                    CollectionUtils.ForEach(data.OrganizationDetail, delegate(Windsor.Node2008.WNOSPlugin.BEACHES_24.OrganizationDetailDataType organizationDetailDataType)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(organizationDetailDataType, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    });
                    CollectionUtils.ForEach(data.BeachDetail, delegate(Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachDetailDataType beachDetail)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(beachDetail, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    });
                    CollectionUtils.ForEach(data.BeachProcedureDetail, delegate(Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachProcedureDetailDataType beachProcedureDetail)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(beachProcedureDetail, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    });
                    if (data.YearCompletionIndicators != null)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(data.YearCompletionIndicators, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    }

                    return(null);
                });

                if (numRowsDeleted > 0)
                {
                    AppendAuditLogEvent("Deleted {0} existing BEACHES data rows from the data store",
                                        numRowsDeleted.ToString());
                }
                else
                {
                    AppendAuditLogEvent("Did not find any existing BEACHES data to delete from the data store");
                }
                AppendAuditLogEvent("Stored BEACHES data content into the data store with the following table row counts: {0}",
                                    CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
예제 #12
0
        protected virtual void ProcessSubmitDocument(string transactionId, string docId)
        {
            string attachmentsFolderPath = null;

            try
            {
                WQXDataType       data       = null;
                WQXDeleteDataType deleteData = null;
                Windsor.Node2008.WNOSPlugin.WQX1XsdOrm.WQXDataType data1 = null;

                data = GetWQXData(transactionId, docId, out data1, out deleteData, out attachmentsFolderPath);

                AppendAuditLogEvent("Storing WQX data into database");

                string orgId;
                object addObject;

                if (data != null)
                {
                    if (data.Organization == null)
                    {
                        throw new InvalidDataException("Deserialized WQX data does not contain an Organization element");
                    }
                    if ((data.Organization.OrganizationDescription == null) ||
                        string.IsNullOrEmpty(data.Organization.OrganizationDescription.OrganizationIdentifier))
                    {
                        throw new InvalidDataException("WQX data does not contain an OrganizationIdentifier element");
                    }
                    orgId     = data.Organization.OrganizationDescription.OrganizationIdentifier;
                    addObject = data;

                    AppendAuditLogEvent("WQX data contains {0} Projects, {1} Activities, {2} Biological Habitat Indexes, {3} Monitoring Locations, and {4} Activity Groups for Organization Id \"{5}\"",
                                        CollectionUtils.Count(data.Organization.Project).ToString(),
                                        CollectionUtils.Count(data.Organization.Activity).ToString(),
                                        CollectionUtils.Count(data.Organization.BiologicalHabitatIndex).ToString(),
                                        CollectionUtils.Count(data.Organization.MonitoringLocation).ToString(),
                                        CollectionUtils.Count(data.Organization.ActivityGroup).ToString(),
                                        orgId);
                }
                else if (data1 != null)
                {
                    if (data1.Organization == null)
                    {
                        throw new InvalidDataException("Deserialized WQX data does not contain an Organization element");
                    }
                    if ((data1.Organization.OrganizationDescription == null) ||
                        string.IsNullOrEmpty(data1.Organization.OrganizationDescription.OrganizationIdentifier))
                    {
                        throw new InvalidDataException("WQX data does not contain an OrganizationIdentifier element");
                    }

                    orgId     = data1.Organization.OrganizationDescription.OrganizationIdentifier;
                    addObject = data1;

                    AppendAuditLogEvent("WQX data contains {0} Projects, {1} Activities, {2} Biological Habitat Indexes, {3} Monitoring Locations, and {4} Activity Groups for Organization Id \"{5}\"",
                                        CollectionUtils.Count(data1.Organization.Project).ToString(),
                                        CollectionUtils.Count(data1.Organization.Activity).ToString(),
                                        "0",
                                        CollectionUtils.Count(data1.Organization.MonitoringLocation).ToString(),
                                        CollectionUtils.Count(data1.Organization.ActivityGroup).ToString(),
                                        data1.Organization.OrganizationDescription.OrganizationIdentifier);
                }
                else
                {
                    if (deleteData.OrganizationDelete == null)
                    {
                        throw new InvalidDataException("Deserialized WQX data does not contain an Organization element");
                    }
                    if (string.IsNullOrEmpty(deleteData.OrganizationDelete.OrganizationIdentifier))
                    {
                        throw new InvalidDataException("WQX data does not contain an OrganizationIdentifier element");
                    }

                    orgId     = deleteData.OrganizationDelete.OrganizationIdentifier;
                    addObject = deleteData;

                    AppendAuditLogEvent("WQX delete data contains {0} Projects, {1} Activities, {2} Biological Habitat Indexes, {3} Monitoring Locations, and {4} Activity Groups for Organization Id \"{5}\"",
                                        CollectionUtils.Count(deleteData.OrganizationDelete.ProjectIdentifier).ToString(),
                                        CollectionUtils.Count(deleteData.OrganizationDelete.ActivityIdentifier).ToString(),
                                        CollectionUtils.Count(deleteData.OrganizationDelete.IndexIdentifier).ToString(),
                                        CollectionUtils.Count(deleteData.OrganizationDelete.MonitoringLocationIdentifier).ToString(),
                                        CollectionUtils.Count(deleteData.OrganizationDelete.ActivityGroupIdentifier).ToString(),
                                        deleteData.OrganizationDelete.OrganizationIdentifier);
                }
                if (_authorizedWqxUsers != null)
                {
                    AppendAuditLogEvent("Validating that User \"{0}\" is authorized to submit WQX data for Organization Id \"{1}\" ...", _submitUsername, orgId);
                    List <string> usernames = null;
                    if (_authorizedWqxUsers.TryGetValue(orgId.ToUpper(), out usernames))
                    {
                        if (!usernames.Contains("*") && !usernames.Contains(_submitUsername.ToUpper()))
                        {
                            string orgName = _settingsProvider.NodeOrganizationName;
                            throw new UnauthorizedAccessException(string.Format("The User \"{0}\" is not authorized to provide data to the {1} for the Organization ID \"{2}.\"  If you feel you have received this message in error, please contact the {1} for further assistance.",
                                                                                _submitUsername, orgName, orgId));
                        }
                    }
                    else if (_authorizedWqxUsers.TryGetValue("*", out usernames))
                    {
                        if (!usernames.Contains("*") && !usernames.Contains(_submitUsername.ToUpper()))
                        {
                            string orgName = _settingsProvider.NodeOrganizationName;
                            throw new UnauthorizedAccessException(string.Format("The User \"{0}\" is not authorized to provide data to the {1} for the Organization ID \"{2}.\"  If you feel you have received this message in error, please contact the {1} for further assistance.",
                                                                                _submitUsername, orgName, orgId));
                        }
                    }
                    else
                    {
                        string orgName = _settingsProvider.NodeOrganizationName;
                        throw new UnauthorizedAccessException(string.Format("Organization ID \"{0}\" has not been authorized to provide data to the {1}.  If you feel you have received this message in error, please contact the {1} for further assistance.",
                                                                            orgId, orgName));
                    }
                }
                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteExistingDataBeforeInsert)
                    {
                        AppendAuditLogEvent("Deleting existing WQX data from the data store for organization \"{0}\" ...", orgId);
                        int numRowsDeleted = 0;

                        string groupWhere = string.Format("PARENTID IN (SELECT RECORDID FROM WQX_ORGANIZATION WHERE UPPER(ORGID) = UPPER('{0}'))",
                                                          orgId);
                        _baseDao.DoSimpleDelete("WQX_ACTIVITYGROUP", groupWhere, null);
                        numRowsDeleted = _baseDao.DoSimpleDelete("WQX_ORGANIZATION", "ORGID", orgId);

                        if (numRowsDeleted > 0)
                        {
                            AppendAuditLogEvent("Deleted {0} existing WQX data rows from the data store for organization \"{1}\"",
                                                numRowsDeleted.ToString(), orgId);
                        }
                        else
                        {
                            AppendAuditLogEvent("Did not find any existing WQX data to delete from the data store for organization \"{0}\"",
                                                orgId);
                        }
                    }
                    AppendAuditLogEvent("Storing WQX data for organization \"{0}\" into data store ...",
                                        orgId);
                    Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(addObject, _baseDao);

                    if (attachmentsFolderPath != null)
                    {
                        DatabaseHelper.StoreAttachmentFilesFromFolder(_objectsToDatabase, _baseDao, data.Organization, attachmentsFolderPath);
                    }

                    string recordId = ReflectionUtils.GetFieldOrPropertyValueByName <string>(addObject, "RecordId");

                    AppendAuditLogEvent("Stored WQX data content with organization primary key \"{0}\" into data store with the following table row counts: {1}",
                                        recordId, CreateTableRowCountsString(tableRowCounts));
                    return(null);
                });
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteAllFilesAndFoldersInFolder(attachmentsFolderPath);
            }
        }
예제 #13
0
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (document.IsZipFile)
                {
                    AppendAuditLogEvent("Decompressing document to temporary file");
                    _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath);
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                IHeaderDocumentHelper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                XmlElement loadElement = null;
                try
                {
                    AppendAuditLogEvent("Attempting to load document with Exchange Header");
                    headerDocumentHelper.Load(tempXmlFilePath);
                    string operation;
                    loadElement = headerDocumentHelper.GetFirstPayload(out operation);
                    if (loadElement == null)
                    {
                        throw new ArgumentException("The submitted document does not contain a payload");
                    }
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Document does not contain an Exchange Header", ex);
                }
                if (string.IsNullOrEmpty(headerDocumentHelper.Organization))
                {
                    throw new ArgumentException("Document does not contain an Organization element in the Exchange Header");
                }
                if (headerDocumentHelper.Organization.Length < 4)
                {
                    throw new ArgumentException("Document does not contain an valid Organization element in the Exchange Header");
                }
                string orgId = headerDocumentHelper.Organization.Substring(0, 4);
                AppendAuditLogEvent("Submitted document contains data for data organization \"{0}\"",
                                    orgId);

                AppendAuditLogEvent("Deserializing document data to UIC data");
                UICDataType data = null;
                if (loadElement != null)
                {
                    data = _serializationHelper.Deserialize <UICDataType>(loadElement);
                }
                else
                {
                    data = _serializationHelper.Deserialize <UICDataType>(tempXmlFilePath);
                }
                data.OrgId = orgId;

                int numRowsDeleted = 0;
                Dictionary <string, int> tableRowCounts = null;

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteExistingDataBeforeInsert)
                    {
                        AppendAuditLogEvent("Deleting existing UIC data from the data store for organization \"{0}\" ...", data.OrgId);
                        numRowsDeleted = _baseDao.DoSimpleDelete("UIC_ORG", "ORG_ID", data.OrgId);
                    }

                    tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao);

                    return(null);
                });

                if (_deleteExistingDataBeforeInsert)
                {
                    if (numRowsDeleted > 0)
                    {
                        AppendAuditLogEvent("Deleted {0} existing WQX data rows from the data store for organization \"{1}\"",
                                            numRowsDeleted.ToString(), data.OrgId);
                    }
                    else
                    {
                        AppendAuditLogEvent("Did not find any existing UIC data to delete from the data store for data organization \"{0}\"",
                                            data.OrgId);
                    }
                }
                AppendAuditLogEvent("Stored UIC data content with data organization \"{0}\" into data store with the following table row counts: {1}",
                                    data.OrgId, CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }