protected virtual void CheckToDeleteExistingData(SpringBaseDao baseDao, Type xmlDataType) { if (_deleteExistingDataBeforeInsert) { string tableName = null; if (xmlDataType == typeof(HazardousWasteHandlerSubmissionDataType)) { tableName = "RCRA_HD_SUBM"; } else if (xmlDataType == typeof(HazardousWasteReportUnivDataType)) { tableName = "RCRA_RU_SUBM"; } else if (xmlDataType == typeof(HazardousWasteCMESubmissionDataType)) { tableName = "RCRA_CME_SUBM"; } else if (xmlDataType == typeof(HazardousWasteCorrectiveActionDataType)) { tableName = "RCRA_CA_SUBM"; } else if (xmlDataType == typeof(GeographicInformationSubmissionDataType)) { tableName = "RCRA_GIS_SUBM"; } else if (xmlDataType == typeof(HazardousWastePermitDataType)) { tableName = "RCRA_PRM_SUBM"; } else if (xmlDataType == typeof(FinancialAssuranceSubmissionDataType)) { tableName = "RCRA_FA_SUBM"; } else if (xmlDataType == typeof(HazardousWasteEmanifestsDataType)) { tableName = "RCRA_EM_SUBM"; } else { throw new ArgException("CheckToDeleteExistingData() was passed an invalid type: {0}", xmlDataType.FullName); } AppendAuditLogEvent("Attempting to delete existing RCRA data from the data store table \"{0}\" ...", tableName); var numRowsDeleted = baseDao.DoSimpleDelete(tableName, null, null); if (numRowsDeleted > 0) { AppendAuditLogEvent("Deleted {0} existing RCRA data rows from the data store table \"{1}\"", numRowsDeleted.ToString(), tableName); } else { AppendAuditLogEvent("Did not find any existing RCRA data to delete from the data store table \"{0}\".", tableName); } } }
public static void ExecuteMetaDataValidation(SpringBaseDao baseDao, bool clearMetadataBeforeRun) { try { if (clearMetadataBeforeRun) { baseDao.DoSimpleDelete("AQS_METADATA", null, null); } baseDao.DoStoredProc("AQS_CHECK_METADATA"); } catch (Exception ex) { throw new Exception("Error while executing AQS metadata populate procedure: " + ExceptionUtils.ToLongString(ex)); } }
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; } }
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 void CheckToDeleteExistingData() { if (_deleteExistingDataBeforeInsert) { AppendAuditLogEvent("Deleting existing RCRA data from the data store ..."); int numRowsDeleted = _baseDao.DoSimpleDelete("RCRA_HD_SUBM", null, null); numRowsDeleted += _baseDao.DoSimpleDelete("RCRA_CME_SUBM", null, null); numRowsDeleted += _baseDao.DoSimpleDelete("RCRA_CA_SUBM", null, null); numRowsDeleted += _baseDao.DoSimpleDelete("RCRA_GIS_SUBM", null, null); numRowsDeleted += _baseDao.DoSimpleDelete("RCRA_PRM_SUBM", null, null); numRowsDeleted += _baseDao.DoSimpleDelete("RCRA_FA_SUBM", null, null); numRowsDeleted += _baseDao.DoSimpleDelete("RCRA_RU_SUBM", null, null); if (numRowsDeleted > 0) { AppendAuditLogEvent("Deleted {0} existing RCRA data rows from the data store", numRowsDeleted.ToString()); } else { AppendAuditLogEvent("Did not find any existing RCRA data to delete from the data store"); } } }
public virtual int DeleteAllFromDatabase(Type objectToDeleteType, SpringBaseDao baseDao, Type mappingAttributesType) { MappingContext mappingContext = MappingContext.GetMappingContext(objectToDeleteType, mappingAttributesType); List <Table> deleteFirstFromTables = null; foreach (Table table in mappingContext.Tables.Values) { if (table.ForeignKeys.Count > 1) { CollectionUtils.Add(table, ref deleteFirstFromTables); } } if (deleteFirstFromTables != null) { // Need to order tables in dependency deletion order bool didSwapAny; int maxIterationCount = 20; do { didSwapAny = false; for (int i = deleteFirstFromTables.Count - 1; i >= 0; --i) { Table checkPossibleSwapTable = deleteFirstFromTables[i]; int swapBeforeIndex = -1; for (int j = i - 1; j >= 0; --j) { Table checkPossibleParentTable = deleteFirstFromTables[j]; foreach (ForeignKeyColumn foreignKeyColumn in checkPossibleSwapTable.ForeignKeys) { if (foreignKeyColumn.ForeignTable == checkPossibleParentTable) { swapBeforeIndex = j; } } } if (swapBeforeIndex != -1) { didSwapAny = true; deleteFirstFromTables.RemoveAt(i); deleteFirstFromTables.Insert(swapBeforeIndex, checkPossibleSwapTable); } } } while ((--maxIterationCount > 0) && didSwapAny); if (maxIterationCount == 0) { throw new MappingException("Failed to order tables in dependency deletion order"); } } int deleteCount = 0; baseDao.TransactionTemplate.Execute(delegate { if (deleteFirstFromTables != null) { foreach (Table table in deleteFirstFromTables) { baseDao.DoSimpleDelete(table.TableName, null, null); } } deleteCount = baseDao.DoSimpleDelete(mappingContext.GetTableNameForType(objectToDeleteType), null, null); return(null); }); return(deleteCount); }
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); } }
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); } }
private void DoSimpleDelete(IDbCommand dbCommand, string tableName, string semicolonSeparatedWhereColumnNames, params object[] whereValues) { _dao.DoSimpleDelete(tableName, semicolonSeparatedWhereColumnNames, whereValues); }