internal XmlDocument ToXml(string group, ITestResultSerializerFactory serializerFactory) { XmlDocument doc = new XmlDocument(); //Check Metadata for xml serializer type, TDS is default value MetaDataEntry entry = ServiceLocator.Resolve <ConfigurationHolder>().GetFromMetaData(this.ProjectID, group, "XMLVersion"); XMLAdapter.AdapterType xmlType = XMLAdapter.AdapterType.TDS; if (entry != null) { xmlType = Utilities.Utility.Value(entry.TextVal, XMLAdapter.AdapterType.TDS); } // if set to 1/true, any demographics in the file will be preserved // Used only in the OSS environment to minimize configuration entry = ServiceLocator.Resolve <ConfigurationHolder>().GetFromMetaData(this.ProjectID, group, "IncludeAllDemographics"); SerializationConfig config = null; if (entry != null && Convert.ToBoolean(entry.IntVal)) { config = new SerializationConfigIncludeAllDemographics(); } else { //get the serialization config from the project metadata config = new SerializationConfig(/*ConfigurationHolder.IncludeAccommodations(ProjectID, group),*/ ServiceLocator.Resolve <ConfigurationHolder>().GetRTSAttributes(this.projectID, group)); } doc.LoadXml(serializerFactory.CreateSerializer(xmlType.ToString(), this).Serialize(config)); return(doc); }
/// <summary> /// Returns an inflated TestResult instance given a TDS-format XML string /// </summary> /// <param name="testXml"></param> /// <returns></returns> private TestResult InflateTestResult(XmlDocument testXml, ITestResultSerializerFactory serializerFactory) { XMLAdapter xmlAdaptor = serializerFactory.CreateDeserializer(testXml); bool isValid; TestResult tr = xmlAdaptor.CreateTestResult(null, out isValid, false); if (!isValid) { tr = null; } return(tr); }
/// <summary> /// Current a current QASystemDataSet.TestOpportunityStatusRow, returns an inflated TestResult instance. /// Refactored from UpdateStatus /// </summary> /// <param name="currentStatus"></param> /// <returns></returns> public TestResult GetTestResult(DataRow currentStatus, ITestResultSerializerFactory serializerFactory) { XmlDocument testXml = XmlRepositoryBL.GetXmlContent(Convert.ToInt64(currentStatus["_fk_XMLRepository"])); if (testXml == null) { throw new ApplicationException(String.Format("Could not locate XML for OppId: {0}, FileID: (1).", this.OppID, Convert.ToInt64(currentStatus["_fk_XMLRepository"]))); } // create the TestResult instance from the xml file TestResult testResult = InflateTestResult(testXml, serializerFactory); if (testResult == null) { throw new ApplicationException(String.Format("Could not inflate TestResult for OppId: {0}, FileID: {1}.", this.OppID, Convert.ToInt64(currentStatus["_fk_XMLRepository"]))); } return(testResult); }
/// <summary> /// returns the test result as a serialized and transformed (if configured) string /// </summary> /// <param name="testResult"></param> /// <returns></returns> protected string GetPayloadAsString(TestResult testResult) { ITestResultSerializerFactory serializerFactory = ServiceLocator.Resolve <ITestResultSerializerFactory>(); if (serializerFactory == null) { throw new ApplicationException("There is no ITestResultSerializerFactory registered with the ServiceLocator."); } XmlDocument doc = testResult.ToXml(Name, serializerFactory); if (TransformSpec != null) { return(TransformSpec.Transform(doc, testResult, TransformArgs.MakeArgumentList(testResult, this))); } else { return(Utilities.Serialization.XmlDocumentToString(doc)); } }
/// <summary> /// returns the test result as a serialized and transformed (if configured) XmlDocument /// </summary> /// <param name="testResult"></param> /// <returns></returns> protected XmlDocument GetPayloadAsXmlDocument(TestResult testResult) { ITestResultSerializerFactory serializerFactory = ServiceLocator.Resolve <ITestResultSerializerFactory>(); if (serializerFactory == null) { throw new ApplicationException("There is no ITestResultSerializerFactory registered with the ServiceLocator."); } XmlDocument doc = testResult.ToXml(Name, serializerFactory); if (TransformSpec == null) { return(doc); } doc = new XmlDocument(); doc.LoadXml(TransformSpec.Transform(doc, testResult, TransformArgs.MakeArgumentList(testResult, this))); return(doc); }
/// <summary> /// /// </summary> /// <param name="xml"></param> /// <param name="senderType"></param> /// <param name="fileID"></param> /// <param name="updateRB"></param> /// <param name="updateDoR"></param> /// <param name="sendToHandScoring"></param> /// <param name="ignoreHandscoringDuplicates"></param> /// <param name="emailAlertForWarnings"></param> /// <returns></returns> public QAResult ReceiveTestResult(XmlDocument xml, XmlRepositoryItem xmlRepoItem) { DateTime startDateTime = DateTime.Now; QAResult result = QAResult.Success; ArchiveDB ar = new ArchiveDB(); TestResult tr = null; bool isFatal = false; bool isValid = false; XMLAdapter adapter; SendToModifiers sendToModifiers = null; long? archivedFileID = null; long? dorRecordId = null; // these config settings may be overridden or modified below for this test. ProjectMetaData projectMetaData = new ProjectMetaData(); ITISExtender tisExtender = ServiceLocator.Resolve <ITISExtender>() ?? new NullTISExtender(); ITISExtenderState tisExtenderState = tisExtender.CreateStateContainer(); ITestResultSerializerFactory serializerFactory = ServiceLocator.Resolve <ITestResultSerializerFactory>(); if (serializerFactory == null) { throw new ApplicationException("Must register an ITestResultSerializerFactory with the ServiceLocator."); } try { xmlRepositoryBL = new BL.XmlRepository(QASystemConfigSettings.Instance.LongDbCommandTimeout); adapter = serializerFactory.CreateDeserializer(xml); tr = adapter.CreateTestResult(_tc, out isValid, true); if (tr != null) { // set the project metadata based on the current project (set in the parser) projectMetaData.SetProjectMetaData(tr.ProjectID); // if the opp is null, we can't process the file if (tr.Opportunity == null) { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } //merge item scores from outside vendor if necessary bool qaProjectChanged = false; if (projectMetaData.mergeItemScores && adapter.MergeScores(tr, out qaProjectChanged)) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } // if the project changed, refresh the metadata if (qaProjectChanged) { projectMetaData.SetProjectMetaData(tr.ProjectID); } //PRESCORE: tisExtender.PreScore(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); //SCORE: if (tisExtender.ShouldScore(this, adapter, tr, projectMetaData, tisExtenderState)) { if (tr.AddScores(_tc)) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } } //COMPLETENESS STATUS: tr.Opportunity.Completeness = !tr.IsComplete() ? "Partial" : "Complete"; // Validation section. This checks the xml file against several business rules. // If validation fails, the file is moved to a failed files directory. List <ValidationRecord> vrs = new List <ValidationRecord>(); tr.ValidationRecords = adapter.ValidationRecords; if (tr.ValidationRecords.Count == 0) { //POSTSCORE: tisExtender.PostScore(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); // if the startdate is null in the file, it will be set to the statusDate. // Make sure we archive it so that we have a record of the unmodified file. if (tr.Opportunity.OriginalStartDate == DateTime.MinValue) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } switch (archiveStrategy) { case ArchiveStrategy.ArchiveAndInsert: //Change the status of old XML file to Arcvhive //insert the new XML file with status as Pprocessing //get the new File id archivedFileID = xmlRepoItem.FileID; xmlRepoItem.FileID = xmlRepositoryBL.InsertAndArchiveXML(xmlRepoItem.FileID, BL.XmlRepository.Location.processing, tr.ToXml(serializerFactory)); break; case ArchiveStrategy.UpdateOriginalFile: // just update the contents of the existing file w/o archiving xmlRepositoryBL.UpdateFileContent(xmlRepoItem.FileID, tr.ToXml(serializerFactory)); break; } vrs = tisExtender.Validate(this, tr, xmlRepoItem, projectMetaData, tisExtenderState, out isFatal, out sendToModifiers); tr.Acknowledged = true; if (((tr.Testee.EntityKey < 0 || tr.Opportunity.OpportunityNumber < 0) && !tr.Opportunity.IsDiscrepancy) || tr.Opportunity.StatusDate == null || tr.ValidationRecords.Count > 0 || isFatal) { // Update db with message messages... ar.SaveResultExceptions(tr, tr.ValidationRecords, xmlRepoItem.FileID); // If fatal then save exception and move to failed folder if (isFatal) { result = QAResult.FailValidation; //AM 8/13/2010: changed this; 1 email will be sent at the end with all // warnings (and errors too if there were any) if emailAlertForWarnings = true // and there were warnings to send. ar.SaveResultExceptions(tr, vrs, xmlRepoItem.FileID); //ar.SaveResultExceptions(tr, vrs, destinationFile, fileName, emailAlertForWarnings); return(result); } } //AM 8/13/2010: same comment as above ar.SaveResultExceptions(tr, vrs, xmlRepoItem.FileID); //ar.SaveResultExceptions(tr, vrs, destinationFile, fileName, emailAlertForWarnings); } else // If there are some XML validation errors then save exception and move to exception folder { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } } else // tr == null { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } // Update the test results after validation has been completed. try { if (isValid) { //PREROUTE: tisExtender.PreRoute(this, adapter, tr, xmlRepoItem, projectMetaData, sendToModifiers, tisExtenderState); // Update XML destinations in case some business rule modified it if (sendToModifiers != null) { foreach (KeyValuePair <SendTo, bool> sendInfo in (SendToModifiersTyped)sendToModifiers) { switch (sendInfo.Key) { case SendTo.DoR: projectMetaData.updateDoR = sendInfo.Value; break; case SendTo.Handscoring: projectMetaData.sendToHandScoring = sendInfo.Value; break; case SendTo.RB: projectMetaData.updateRB = sendInfo.Value; break; } } } if (projectMetaData.updateDoR) { try { List <Target> dorTarget = Target.GetOrderedTargets(tr.ProjectID, Target.TargetClass.DoR); if (dorTarget != null && dorTarget.Count == 1) { dorTarget[0].Send(tr, delegate(object o) { dorRecordId = (long)o; }, projectMetaData.doRAdminID); } } catch (Exception ex) { throw new QAException(String.Format("DoR update failed for fileId: {0}, Message: {1}", xmlRepoItem.FileID, ex.Message), QAException.ExceptionType.General, ex); } } //send to configured Handscoring targets ItemScoringManager.Instance.Send(tr, sendToModifiers); // send to configured targets in order (incl RB) foreach (Target t in Target.GetOrderedTargets(tr.ProjectID, Target.TargetClass.General)) { if (!sendToModifiers.ShouldSend(t.Name)) { continue; } ITargetResult targetResult = t.Send(tr); if (targetResult.Sent) { Logger.Log(true, String.Format("Sent data for FileId: {0} to Target: {1} ({2}).", xmlRepoItem.FileID, t.Name, targetResult.ID ?? "<unspecified>"), EventLogEntryType.Information, false, true); } } //POSTROUTE: tisExtender.PostRoute(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); } // Check if this test need to be merged with something else try { TDSQASystemAPI.TestMerge.TestMerge testMerge = TestMergeConfiguration.Instance.GetTestMerge(tr.Name); if (testMerge != null) { testMerge.CreateCombinedTest(_tc, tr, serializerFactory); } } catch (Exception ex) { throw new QAException(String.Format("TestMerge operation failed for fileId: {0}, Message: {1}", xmlRepoItem.FileID, ex.Message), QAException.ExceptionType.General, ex); } } catch (QAException qae) { //TODO: result = QAResult.FailUpdate; string message = qae.GetExceptionMessage(true); if (message.StartsWith("DoR")) { ar.SaveResultExceptions(tr, "DoR update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("Handscoring")) { ar.SaveResultExceptions(tr, "Handscoring update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("TestMerge")) { ar.SaveResultExceptions(tr, "Test merge operation failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("AutoAppeal")) { ar.SaveResultExceptions(tr, "AutoAppeal failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else { ar.SaveResultExceptions(tr, "Response Bank update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } return(result); } catch (Exception ex) { result = QAResult.FailUpdate; string message = ex.GetExceptionMessage(true); ar.SaveResultExceptions(tr, "Response Bank update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); return(result); } // Log to TestOpportunityStatus, Update the TDS_QC database, and possibly send to TIS if (tr != null) { try { // Log to TestOpportunityStatus, Update the TDS_QC database ar.SaveResultInfo(tr, xmlRepoItem.FileID, tr.Testee.IsDemo, dorRecordId, archivedFileID, projectMetaData.updateRB); } catch (Exception ex) { result = QAResult.FailUpdate; string message = ex.GetExceptionMessage(true); ar.SaveResultExceptions(tr, "Archive ", ex.Message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); return(result); } //POSTSAVE: tisExtender.PostSave(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); } result = QAResult.Success; } catch (Exception ex) { result = QAResult.Unknown; string message = ex.GetExceptionMessage(true); if (tr != null) { ar.SaveResultExceptions(tr, "QA System Exception:", message, xmlRepoItem.FileID); } else { ar.SaveResultExceptions("QA System Exception:", message, xmlRepoItem.FileID); } Logger.Log(true, message, EventLogEntryType.Error, false, true); } finally { if (!(tr == null || tr.Opportunity == null)) { // We don't want to call back to TDS for scanned paper tests, since they did not originate from TDS. // Just skip w/o logging. if (!tr.Mode.Equals("scanned")) { Boolean accepted = true; string message = null; if (result == QAResult.FailUpdate || result == QAResult.FailValidation || result == QAResult.Unknown || !(tr.PassedAllValidations())) { accepted = false; if (result == QAResult.FailUpdate) { message = "failed validation"; } else if (result == QAResult.FailValidation) { message = "failed while either updating the Response Bank, storing data into the DoR, or invoking the Handscoring webservice"; } else if (result == QAResult.Unknown) { message = "An unknown exception occurred"; } else if (!(tr.PassedAllValidations())) { message = "Failed rules validation"; } } IAcknowledgementTargetFactory ackTargetFactory = AIR.Common.ServiceLocator.Resolve <IAcknowledgementTargetFactory>(); if (ackTargetFactory != null) // ok not to acknowledge I suppose { IAcknowledgementTarget ackTarget = ackTargetFactory.SelectTarget(xmlRepoItem); try { if (ackTarget == null || !ackTarget.Send(new Message(tr.Opportunity.Key, accepted, message), xmlRepoItem)) { Logger.Log(true, String.Format("Acknowledgement not sent for fileID: {0}", xmlRepoItem.FileID), EventLogEntryType.Information, false, true); } } catch (Exception ex) { // allow these to be treated as warnings or errors. If TreatAcknowledgementFailureAsError is set to true, // a failure to send an ACK will result in the file being dumped into the reject bin. // Default behavior is to treat these as warnings. We generally don't want to fail a file just because // we can't send the ACK. Note also that a combo may already have been created (if applicable). bool treatAckfailureAsError = false; if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["TreatAcknowledgementFailureAsError"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["TreatAcknowledgementFailureAsError"])) { treatAckfailureAsError = true; } // if the file would have otherwise succeeded and there was an exception while attempting to send the ACK and // we're not treating these as warnings, fail the file. if (treatAckfailureAsError && result == QAResult.Success) { result = QAResult.Unknown; } Logger.Log(true, String.Format("Could not send acknowledgement for fileID: {0}, Exception: {1}", xmlRepoItem.FileID, ex.GetExceptionMessage(true)), treatAckfailureAsError ? EventLogEntryType.Error : EventLogEntryType.Warning, false, true); } } } } //Move file to appropriate folder based on the QAResult and log the status accordingly. LogAndCleanup(result, xmlRepoItem.FileID, tr, startDateTime); } return(result); }
/// <summary> /// Updates the status of a paper test and writes it back out to the QA /// system for processing. /// </summary> /// <param name="newSatus"></param> /// <param name="destinationEnvironment"></param> public void UpdateStatus(TestResult testResult, string newStatus, long?appealRequestId, ITestResultSerializerFactory serializerFactory) { // if there's an appeal requestId gen var, remove it. A fresh one will be added below if // appealRequestId is not null. This is done to handle resets and invalidations through the DoR website. // Those are not appeals and therefore should not have a requestId. If a rescore appeal is reset through // the DoR website, the appeal request id that will be found here is that of the rescore appeal. // This will cause confusion downstream, since the status would be "reset". //TODO: consider making resets/invalidations through the DoR website appeals as well. GenericVariable appealRequestIdGenVar = testResult.Opportunity.GetGenericVariableByContextName(GenericVariable.VariableContext.APPEAL, GenericVariable.APPEAL_REQUEST_ID_VAR_NAME); if (appealRequestIdGenVar != null) { testResult.Opportunity.GenericVariables.Remove(appealRequestIdGenVar); } // if an appeal requestid was provided, embed it in the file as a generic variable if (appealRequestId != null) { testResult.Opportunity.AddGenericVariable(GenericVariable.VariableContext.APPEAL, GenericVariable.APPEAL_REQUEST_ID_VAR_NAME, appealRequestId.Value.ToString()); } // set the status of the TestResult to the new one // also set the status date to reflect when this action was taken testResult.Opportunity.Status = newStatus; testResult.Opportunity.StatusDate = DateTime.Now; // also clear out any qaLevel. Currently, the only one we're using is "BatchReport". // If a test was batch-reported but is being resubmitted with a different status, the // resubmitted opp should be considered a new version which has not been reported yet. //TODO: as other uses of qaLevel arise, revisit this. testResult.Opportunity.QALevel = null; // now write the test to the XmlRepositoryBL.InsertXml(XmlRepository.Location.source, testResult, serializerFactory); }
//public long InsertXml(Location location, XmlDocument contents, string callbackURL) //{ // ITestResultSerializerFactory f = AIR.Common.ServiceLocator.Resolve<ITestResultSerializerFactory>(); // if(f == null) // throw new ApplicationException("Cannot insert XML. Must register a ITestResultSerializerFactory with the ServiceLocator."); // return InsertXml(location, contents, callbackURL, f); //} public long InsertXml(Location location, XmlDocument contents, string callbackURL, ITestResultSerializerFactory serializerFactory) { string testName = null; long testeeKey, oppId; bool isDemo = false; DateTime statusDate; if (serializerFactory == null) { throw new ApplicationException("Cannot insert XML. ITestResultSerializerFactory cannot be null."); } XMLAdapter adapter = serializerFactory.CreateDeserializer(contents); adapter.GetKeyValues(out testName, out oppId, out testeeKey, out statusDate, out isDemo); return(InsertXml(location, testName, oppId.ToString(), testeeKey, statusDate, isDemo, contents, callbackURL)); }
public long InsertXml(Location location, XmlDocument contents, ITestResultSerializerFactory serializerFactory) { return(InsertXml(location, contents, null, serializerFactory)); }
public long InsertXml(Location location, TestResult tr, ITestResultSerializerFactory serializerFactory) { return(InsertXml(location, tr.Name, tr.Opportunity.OpportunityID, tr.Testee.EntityKey, tr.Opportunity.StatusDate, tr.Testee.IsDemo, tr.ToXml(serializerFactory))); }
internal XmlDocument ToXml(MetaDataEntry.GroupName group, ITestResultSerializerFactory serializerFactory) { return(ToXml(group.ToString(), serializerFactory)); }
/// <summary> /// default groupname = DoR /// </summary> /// <returns></returns> internal XmlDocument ToXml(ITestResultSerializerFactory serializerFactory) { return(ToXml(MetaDataEntry.GroupName.DoR, serializerFactory)); }